-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3345 from wowsims/apl
Move shared unit selection UI into new UnitPicker class
- Loading branch information
Showing
7 changed files
with
122 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DropdownPicker, DropdownPickerConfig, DropdownValueConfig } from './dropdown_picker.js'; | ||
|
||
export interface UnitValueConfig<T> extends DropdownValueConfig<T> { | ||
text: string, | ||
iconUrl?: string, | ||
color?: string, | ||
} | ||
|
||
export interface UnitPickerConfig<ModObject, T> extends Omit<DropdownPickerConfig<ModObject, T>, 'values' | 'setOptionContent' | 'defaultLabel'> { | ||
values: Array<UnitValueConfig<T>>, | ||
} | ||
|
||
export class UnitPicker<ModObject, T> extends DropdownPicker<ModObject, T> { | ||
constructor(parent: HTMLElement, modObject: ModObject, config: UnitPickerConfig<ModObject, T>) { | ||
super(parent, modObject, { | ||
...config, | ||
defaultLabel: 'Unit', | ||
setOptionContent: (button: HTMLButtonElement, valueConfig: DropdownValueConfig<T>) => { | ||
const unitConfig = valueConfig as UnitValueConfig<T>; | ||
|
||
if (unitConfig.color) { | ||
button.style.backgroundColor = unitConfig.color; | ||
} | ||
|
||
if (unitConfig.iconUrl) { | ||
const icon = document.createElement('img'); | ||
icon.src = unitConfig.iconUrl; | ||
icon.classList.add('unit-filter-icon'); | ||
button.appendChild(icon); | ||
} | ||
|
||
if (unitConfig.text) { | ||
const label = document.createElement('span'); | ||
label.textContent = unitConfig.text; | ||
label.classList.add('unit-filter-label'); | ||
button.appendChild(label); | ||
} | ||
} | ||
}); | ||
this.rootElem.classList.add('unit-picker-root'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.unit-picker-root { | ||
border: 1px solid white; | ||
color: white; | ||
text-shadow: | ||
0 0 3px black, | ||
0 0 3px black, | ||
0 0 3px black; | ||
} | ||
|
||
.unit-filter-option { | ||
height: 30px; | ||
} | ||
|
||
.unit-filter-icon { | ||
margin: 2px; | ||
height: 25px; | ||
} | ||
|
||
.unit-filter-label { | ||
font-size: 14px; | ||
margin: 2px; | ||
} |
Oops, something went wrong.