Skip to content

Commit 71eaa82

Browse files
Merge pull request #90 from maximeBailly/harvestIndicator
[MODS][HarvestBar] Add mod harvestBar
2 parents 1d49f5d + df40713 commit 71eaa82

File tree

13 files changed

+225
-7
lines changed

13 files changed

+225
-7
lines changed

electron/settings/settings-default.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ export const SettingsDefault: SettingsInterface = {
161161
hidden_mount: false,
162162
party_info_pp: false,
163163
party_info_lvl: false,
164-
zaapsearchfilter: true
164+
zaapsearchfilter: true,
165+
harvest_indicator: true
165166
},
166167
auto_group: {
167168
active: false,

electron/settings/settings.interface.ts

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface SettingsInterface {
8787
party_info_pp: boolean;
8888
party_info_lvl: boolean;
8989
zaapsearchfilter: boolean;
90+
harvest_indicator: boolean;
9091
},
9192
auto_group: {
9293
active: boolean;

locale/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"estimator": "Estimating spell damage in battle",
6868
"hide-mount": "Hide mounts during fights",
6969
"fightchronometer" : "Show combats chronometer",
70-
"zaapsearchfilter" : "Show zaap search filter"
70+
"zaapsearchfilter" : "Show zaap search filter",
71+
"harvest-indicator" : "Activate the display of the remaining time below the ressources"
7172
},
7273
"groups": {
7374
"header": "Groups"

locale/es.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"fightchronometer" : "Mostrar peleas cronómetro",
6666
"zaapsearchfilter" : "Mostra filtro di ricerca zaap",
6767
"estimator": "Daño estimado de hechizo durante el combate",
68-
"hide-mount": "Ocultar monturas durante las peleas"
68+
"hide-mount": "Ocultar monturas durante las peleas",
69+
"harvest-indicator" : "Activar la visualización del tiempo restante debajo de los recursos"
6970
},
7071
"groups": {
7172
"header": "Grupo"

locale/fr.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"jobsxp": "Activer l'affichage de l'xp a obtenir pour monter de niveau (métier)",
6868
"hide-mount": "Cacher les montures pendant les combats",
6969
"fightchronometer": "Afficher le chronomètre de combats",
70-
"zaapsearchfilter" : "Afficher le filtre de recherche de zaap"
70+
"zaapsearchfilter" : "Afficher le filtre de recherche de zaap",
71+
"harvest-indicator" : "Barres de temps sous les récoltes"
7172
},
7273
"groups": {
7374
"header": "Groupe"

locale/it.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"fightchronometer": "Mostra combattimenti di cronometri",
6868
"zaapsearchfilter" : "Mostra filtro di ricerca zaap",
6969
"estimator": "Fai una stima dei danni da incantesimi in battaglia",
70-
"hide-mount": "Nascondi le cavalcature durante i combattimenti"
70+
"hide-mount": "Nascondi le cavalcature durante i combattimenti",
71+
"harvest-indicator" : "Attiva la visualizzazione del tempo rimanente sotto le risorse"
7172
},
7273
"groups": {
7374
"header": "Gruppi"

locale/pl.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"estimator": "Włącz przewidywanie obrażeń podczas walki",
6868
"hide-mount": "Nie pokazuj wierzchowców podczas walki",
6969
"fightchronometer" : "Pokaż czas trwania walki",
70-
"zaapsearchfilter" : "Pokaż filtr wyszukiwania zaap'ów"
70+
"zaapsearchfilter" : "Pokaż filtr wyszukiwania zaap'ów",
71+
"harvest-indicator" : "Aktywuj wyświetlanie pozostałego czasu poniżej zasobów"
7172
},
7273
"groups": {
7374
"header": "Grupy"

locale/tr.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"estimator": "Savaşta büyü hasarını tahmin etme",
6868
"hide-mount": "Savaş sırasında binekleri gizle",
6969
"fightchronometer" : "Savaş kronometresini göster",
70-
"zaapsearchfilter" : "Zaap arama filtresini göster"
70+
"zaapsearchfilter" : "Zaap arama filtresini göster",
71+
"harvest-indicator" : "Kaynakların altında kalan sürenin gösterimini etkinleştirin"
7172
},
7273
"groups": {
7374
"header": "Gruplar"
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { Logger } from "app/core/electron/logger.helper";
2+
3+
import { Mod } from "../mod";
4+
import { HarvestBar } from "./harvestBar";
5+
6+
export class Harvest extends Mod {
7+
private harvestBar: HarvestBar;
8+
private statedElements: Map<number, number> = new Map();
9+
private isInHarvest: boolean = false;
10+
11+
startMod(): void {
12+
this.params = this.settings.option.vip.general;
13+
14+
if (this.params._harvest_indicator) {
15+
16+
Logger.info('- enable Harvest indicator');
17+
18+
const harvestCss = document.createElement('style');
19+
harvestCss.id = 'harvestCss';
20+
harvestCss.innerHTML = `
21+
.harvestBarContainer {
22+
box-sizing: border-box;
23+
border: 1px gray solid;
24+
background-color: #222;
25+
height: 6px;
26+
width: 80px;
27+
position: absolute;
28+
border-radius: 3px;
29+
overflow: hidden;
30+
transition-duration: 500ms;
31+
margin-top: 10px;
32+
}
33+
.harvestBar {
34+
transition-duration: 300ms;
35+
height: 100%;
36+
width: 100%;
37+
background-color: orange;
38+
}
39+
.harvestTimeText {
40+
font-size: 11px;
41+
font-weight: bold;
42+
text-align: center;
43+
position: absolute;
44+
width: 80px;
45+
color: white;
46+
text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.9);
47+
transition-duration: 500ms;
48+
margin-top: 4px;
49+
}`;
50+
this.wGame.document.getElementsByTagName('head')[0].appendChild(harvestCss);
51+
52+
this.harvestBar = new HarvestBar(this.wGame);
53+
54+
this.removeOnFinish();
55+
this.displayOnStart();
56+
this.setHarvestStart();
57+
}
58+
}
59+
60+
private setHarvestStart(): void {
61+
this.on(this.wGame.dofus.connectionManager, 'StatedElementUpdatedMessage', (e: any) => {
62+
try {
63+
this.statedElements.set(e.statedElement.elementId, e.statedElement.elementCellId);
64+
} catch (ex) {
65+
Logger.info(ex);
66+
}
67+
});
68+
}
69+
70+
private displayOnStart(): void {
71+
this.on(this.wGame.dofus.connectionManager, 'InteractiveUsedMessage', (e: any) => {
72+
try {
73+
if (this.statedElements.has(e.elemId) && e.entityId == this.wGame.isoEngine.actorManager.userId) {
74+
this.harvestBar.harvestStarted(this.statedElements.get(e.elemId), e.duration);
75+
this.isInHarvest = true;
76+
this.statedElements.clear();
77+
}
78+
} catch (ex) {
79+
Logger.info(ex);
80+
}
81+
});
82+
}
83+
84+
private removeOnFinish(): void {
85+
this.on(this.wGame.dofus.connectionManager, 'InteractiveUseEndedMessage', (e: any) => {
86+
try {
87+
this.isInHarvest = !(this.harvestBar.destroy());
88+
} catch (ex) {
89+
Logger.info(ex);
90+
}
91+
});
92+
}
93+
94+
95+
public reset() {
96+
super.reset();
97+
if (this.params.harvest_indicator) {
98+
if (this.harvestBar) this.harvestBar.destroy();
99+
const bar = this.wGame.document.getElementById('harvestBarContainer');
100+
if (bar) bar.remove();
101+
const time = this.wGame.document.getElementById('harvestTime');
102+
if (time) time.remove();
103+
const harvestCss = this.wGame.document.getElementById('harvestCss');
104+
if (harvestCss && harvestCss.parentElement) harvestCss.parentElement.removeChild(harvestCss);
105+
}
106+
}
107+
108+
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
export class HarvestBar {
3+
private wGame: any | Window;
4+
private container: HTMLDivElement;
5+
private harvestBar: HTMLDivElement;
6+
private harvestTimeText: HTMLDivElement;
7+
private updateInterval: any;
8+
private interval: number = 200;
9+
10+
private cellId: number;
11+
private duration: number;
12+
private remainingTime: number;
13+
14+
constructor(wGame: Window | any) {
15+
this.wGame = wGame;
16+
}
17+
18+
private createContainer() {
19+
this.container = document.createElement('div');
20+
this.container.id = 'harvestBarContainer';
21+
this.container.className = 'harvestBarContainer';
22+
23+
this.wGame.foreground.rootElement.appendChild(this.container);
24+
}
25+
26+
private createBar() {
27+
this.createContainer();
28+
29+
let scenePos = this.wGame.isoEngine.mapRenderer.getCellSceneCoordinate(this.cellId);
30+
let pos = this.wGame.isoEngine.mapScene.convertSceneToCanvasCoordinate(scenePos.x, scenePos.y);
31+
32+
/* harvestBar */
33+
this.harvestBar = document.createElement('div');
34+
this.harvestBar.id = 'harvestBar';
35+
this.harvestBar.className = 'harvestBar';
36+
this.container.appendChild(this.harvestBar);
37+
38+
this.container.style.left = (pos.x - this.container.offsetWidth / 2) + 'px';
39+
this.container.style.top = (pos.y) + 'px';
40+
41+
/* harvestTimeText */
42+
this.harvestTimeText = document.createElement('div');
43+
this.harvestTimeText.id = 'harvestTime';
44+
this.harvestTimeText.className = 'harvestTimeText';
45+
this.wGame.foreground.rootElement.appendChild(this.harvestTimeText);
46+
47+
this.harvestTimeText.style.left = (pos.x - this.container.offsetWidth / 2) + 'px';
48+
this.harvestTimeText.style.top = (pos.y) + 'px';
49+
50+
this.update();
51+
}
52+
53+
private show() {
54+
this.createBar();
55+
this.container.style.visibility = 'visible';
56+
57+
this.updateInterval = setInterval(()=>{
58+
this.remainingTime -= this.interval;
59+
this.update();
60+
}, this.interval);
61+
}
62+
63+
private update() {
64+
/* Harvest Bar */
65+
let time: number = this.remainingTime / this.duration * 100;
66+
this.harvestBar.style.width = (time > 0 ? time : '0') + '%';
67+
68+
/* Harvest Text */
69+
this.harvestTimeText.innerHTML = (this.remainingTime > 0 ? (this.remainingTime / 1000) : '0') + 's';
70+
}
71+
72+
public harvestStarted(cellId: number, duration: number) {
73+
this.cellId = cellId;
74+
this.duration = duration * 100;
75+
this.remainingTime = duration * 100;
76+
this.show();
77+
}
78+
79+
public destroy(): boolean {
80+
clearInterval(this.updateInterval);
81+
if (this.container && this.container.parentElement) this.container.parentElement.removeChild(this.container);
82+
if (this.harvestTimeText && this.harvestTimeText.parentElement) this.harvestTimeText.parentElement.removeChild(this.harvestTimeText);
83+
84+
return true;
85+
}
86+
}

src/app/core/mods/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export { Notifications } from "app/core/mods/notifications/notifications";
1212
export { PartyInfo } from "app/core/mods/partyInfo/partyInfo";
1313
export { RapidExchange } from "app/core/mods/rapidExchange/rapidExchange";
1414
export { Shortcuts } from "app/core/mods/shortcuts/shortcuts";
15+
export { Harvest } from "app/core/mods/harvestBar/harvest";

src/app/core/service/settings.service.ts

+11
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ export module Option {
717717
private _hidden_mount: boolean;
718718
private _party_info_pp:boolean;
719719
private _party_info_lvl:boolean;
720+
private _harvest_indicator: boolean;
720721

721722
get party_info_pp():boolean{
722723
return this._party_info_pp;
@@ -808,6 +809,15 @@ export module Option {
808809
this._health_bar_shortcut = health_bar_shortcut;
809810
}
810811

812+
get harvest_indicator(): boolean {
813+
return this._harvest_indicator;
814+
}
815+
816+
set harvest_indicator(harvest_indicator: boolean) {
817+
this.settingsProvider.write('option.vip.general.harvest_indicator', harvest_indicator);
818+
this._harvest_indicator = harvest_indicator;
819+
}
820+
811821
constructor(private settingsProvider: SettingsProvider) {
812822
this.disable_inactivity = this.settingsProvider.read('option.vip.general.disable_inactivity');
813823
this.health_bar = this.settingsProvider.read('option.vip.general.health_bar');
@@ -819,6 +829,7 @@ export module Option {
819829
this.hidden_mount = this.settingsProvider.read('option.vip.general.hidden_mount');
820830
this.party_info_pp = this.settingsProvider.read('option.vip.general.party_info_pp');
821831
this.party_info_lvl = this.settingsProvider.read('option.vip.general.party_info_lvl');
832+
this.harvest_indicator = this.settingsProvider.read('option.vip.general.harvest_indicator');
822833
}
823834
}
824835

src/app/window/option/vip/general/general.component.html

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<mat-checkbox color="primary" [(ngModel)]="settingsService.option.vip.general.zaapsearchfilter">{{ 'app.window.options.features.general.zaapsearchfilter' | translate }}</mat-checkbox>
2525
</div>
2626

27+
<div class="col-xs-12">
28+
<mat-checkbox color="primary" [(ngModel)]="settingsService.option.vip.general.harvest_indicator">{{ 'app.window.options.features.general.harvest-indicator' | translate }}</mat-checkbox>
29+
</div>
30+
2731
<div class="col-xs-12">
2832
<mat-checkbox color="primary" [(ngModel)]="settingsService.option.vip.general.jobsxp">{{ 'app.window.options.features.general.jobsxp' | translate }}</mat-checkbox>
2933
</div>

0 commit comments

Comments
 (0)