Differential D2734 Diff 12364 binaries/data/mods/public/gui/reference/common/Dropdowns/CivSelectDropdown.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/reference/common/Dropdowns/CivSelectDropdown.js
- This file was added.
class CivSelectDropdown | |||||
{ | |||||
constructor(civData) | |||||
{ | |||||
this.handlers = new Set(); | |||||
let civList = Object.keys(civData).map(civ => ({ | |||||
"name": civData[civ].Name, | |||||
"code": civ, | |||||
})).sort(sortNameIgnoreCase); | |||||
this.civSelectionHeading = Engine.GetGUIObjectByName("civSelectionHeading"); | |||||
this.civSelectionHeading.caption = this.Caption; | |||||
this.civSelection = Engine.GetGUIObjectByName("civSelection"); | |||||
this.civSelection.list = civList.map(c => c.name); | |||||
this.civSelection.list_data = civList.map(c => c.code); | |||||
this.civSelection.onSelectionChange = () => this.onSelectionChange(this); | |||||
} | |||||
onSelectionChange() | |||||
{ | |||||
let civCode = this.civSelection.list_data[this.civSelection.selected]; | |||||
Silier: this could be inlined | |||||
for (let handler of this.handlers) | |||||
handler(civCode); | |||||
} | |||||
registerHandler(handler) | |||||
{ | |||||
this.handlers.add(handler); | |||||
} | |||||
Done Inline Actionspossibly not needed, this.handlers is Set so adding same thing will not insert it into the set Silier: possibly not needed, this.handlers is Set so adding same thing will not insert it into the set | |||||
unregisterHandler(handler) | |||||
{ | |||||
this.handlers.delete(handler); | |||||
} | |||||
hasCivs() | |||||
{ | |||||
return this.civSelection.list.length != 0; | |||||
Done Inline ActionsI think you can call delete without previous if, nothing will happen if it is not there Silier: I think you can call delete without previous if, nothing will happen if it is not there | |||||
} | |||||
selectCiv(civCode) | |||||
{ | |||||
if (!civCode) | |||||
Done Inline Actions! could be moved to == and become != I think that would be cleaner to read Silier: ! could be moved to == and become != I think that would be cleaner to read | |||||
Not Done Inline ActionsI believe it does the left computation first then check == 0 so it should be changed indeed. js is weird. Stan: I believe it does the left computation first then check == 0 so it should be changed indeed. js… | |||||
return; | |||||
let index = this.civSelection.list_data.indexOf(civCode); | |||||
if (index == -1) | |||||
return; | |||||
this.civSelection.selected = index; | |||||
} | |||||
selectFirstCiv() | |||||
{ | |||||
this.civSelection.selected = 0; | |||||
} | |||||
} | |||||
CivSelectDropdown.prototype.Caption = | |||||
translate("Civilization:"); |
Wildfire Games · Phabricator
this could be inlined