Changeset 25023
- Timestamp:
- Mar 6, 2021, 7:11:41 PM (3 years ago)
- Location:
- ps/trunk/binaries/data/mods/public/gui/hotkeys
- Files:
-
- 8 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeyPicker.js
r24215 r25023 5 5 class HotkeyPicker 6 6 { 7 constructor( onClose, name, combinations)7 constructor(onClose, name, combinations) 8 8 { 9 9 10 this.name = name; 10 11 this.combinations = combinations; … … 14 15 this.enteringInput = -1; 15 16 16 Engine.GetGUIObjectByName("hotkeyPickerTitle").caption = translate(this.name); 17 if (this.metadata.hotkeys[name]) 18 { 19 Engine.GetGUIObjectByName("hotkeyPickerTitle").caption = translate(this.metadata.hotkeys[name].name); 20 Engine.GetGUIObjectByName("hotkeyPickerDescHotkey").caption = translate(this.metadata.hotkeys[name].desc); 21 } 22 else 23 { 24 Engine.GetGUIObjectByName("hotkeyPickerTitle").caption = this.name; 25 Engine.GetGUIObjectByName("hotkeyPickerDescHotkey").hidden = true; 26 } 17 27 18 28 this.setupCombinations(); … … 42 52 { 43 53 let s = Engine.GetGUIObjectByName("combination[" + i + "]").size; 44 s.top = +i * 60 + 90;45 s.bottom = +i * 60 + 1 20;54 s.top = +i * 60 + 0; 55 s.bottom = +i * 60 + 10; 46 56 Engine.GetGUIObjectByName("combination[" + i + "]").size = s; 47 57 Engine.GetGUIObjectByName("combNb[" + i + "]").caption = sprintf(translate("#%i"), i); -
ps/trunk/binaries/data/mods/public/gui/hotkeys/HotkeysPage.js
r24793 r25023 1 1 class HotkeysPage 2 2 { 3 constructor( )3 constructor() 4 4 { 5 6 5 7 Engine.GetGUIObjectByName("hotkeyList").onMouseLeftDoubleClickItem = () => { 6 8 let idx = Engine.GetGUIObjectByName("hotkeyList").selected; 7 9 let picker = new HotkeyPicker( 10 8 11 this.onHotkeyPicked.bind(this), 9 12 Engine.GetGUIObjectByName("hotkeyList").list_data[idx], … … 11 14 ); 12 15 }; 16 17 13 18 Engine.GetGUIObjectByName("hotkeyFilter").onSelectionChange = () => this.setupHotkeyList(); 19 20 21 22 23 24 25 26 27 28 29 30 14 31 15 32 Engine.GetGUIObjectByName("hotkeyTextFilter").onTextEdit = () => this.setupHotkeyList(); … … 30 47 } 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 32 76 setupFilters() 33 77 { … … 35 79 let names = []; 36 80 for (let cat in this.categories) 37 names.push(t his.categories[cat].label);81 names.push(t); 38 82 dropdown.list = [translate("All Hotkeys")].concat(names); 39 83 dropdown.list_data = [-1].concat(Object.keys(this.categories)); … … 46 90 hotkeyList.selected = -1; 47 91 let textFilter = Engine.GetGUIObjectByName("hotkeyTextFilter").caption; 92 93 48 94 let dropdown = Engine.GetGUIObjectByName("hotkeyFilter"); 49 95 if (dropdown.selected && dropdown.selected !== 0) 50 { 51 let category = this.categories[dropdown.list_data[dropdown.selected]]; 52 // This is inefficient but it seems fast enough. 53 let hotkeys = category.hotkeys.filter(x => translate(x[0]).indexOf(textFilter) !== -1); 54 hotkeyList.list_name = hotkeys.map(x => translate(x[0])); 55 hotkeyList.list_mapping = hotkeys.map(x => formatHotkeyCombinations(x[1])); 56 hotkeyList.list = hotkeys.map(() => 0); 57 hotkeyList.list_data = hotkeys.map(x => x[0]); 58 } 96 hotkeys = this.categories[dropdown.list_data[dropdown.selected]].hotkeys; 97 else 98 hotkeys = Object.values(this.categories).map(x => x.hotkeys).flat(); 99 hotkeys = hotkeys.filter(x => { 100 return x.indexOf(textFilter) !== -1 || 101 translate(this.metadata.hotkeys[x]?.name || x).indexOf(textFilter) !== -1; 102 }); 103 104 hotkeyList.list_name = hotkeys.map(x => translate(this.metadata.hotkeys[x]?.name || x)); 105 hotkeyList.list_mapping = hotkeys.map(x => formatHotkeyCombinations(this.hotkeys[x])); 106 hotkeyList.list = hotkeys.map(() => 0); 107 hotkeyList.list_data = hotkeys.map(x => x); 108 } 109 110 onHoverChange() 111 { 112 let hotkeyList = Engine.GetGUIObjectByName("hotkeyList"); 113 if (hotkeyList.hovered === -1) 114 hotkeyList.tooltip = ""; 59 115 else 60 116 { 61 // TODO SM62+ : refactor using flat() 62 let flattened = []; 63 for (let cat in this.categories) 64 flattened = flattened.concat(this.categories[cat].hotkeys); 65 flattened = flattened.filter(x => translate(x[0]).indexOf(textFilter) !== -1); 66 hotkeyList.list_name = flattened.map(x => translate(x[0])); 67 hotkeyList.list_mapping = flattened.map(x => formatHotkeyCombinations(x[1])); 68 hotkeyList.list = flattened.map(() => 0); 69 hotkeyList.list_data = flattened.map(x => x[0]); 117 let hotkey = hotkeyList.list_data[hotkeyList.hovered]; 118 let tooltip = this.metadata.hotkeys[hotkey]?.desc || markForTranslation("No tooltip available"); 119 hotkeyList.tooltip = translate(tooltip); 70 120 } 71 121 } … … 93 143 this.saveButton.enabled = true; 94 144 this.setupHotkeyList(); 95 }96 97 setupHotkeyData()98 {99 let hotkeydata = Engine.GetHotkeyMap();100 this.hotkeys = hotkeydata;101 102 let categories = {103 "other": {104 "label": translate("Other hotkeys"),105 "hotkeys": []106 }107 };108 let n_categories = 1;109 for (let hotkeyName in this.hotkeys)110 {111 let category = "other";112 let firstdot = hotkeyName.indexOf('.');113 if (firstdot !== -1)114 category = hotkeyName.substr(0, firstdot);115 if (!(category in categories))116 {117 if (n_categories > 18)118 category = "other";119 categories[category] = {120 "label": category,121 "hotkeys": []122 };123 }124 categories[category].hotkeys.push([hotkeyName, this.hotkeys[hotkeyName]]);125 }126 // Remove categories that are too small to deserve a tab.127 for (let cat of Object.keys(categories))128 if (categories[cat].hotkeys.length < 3)129 {130 categories.other.hotkeys = categories.other.hotkeys.concat(categories[cat].hotkeys);131 delete categories[cat];132 }133 for (let cat in categories)134 categories[cat].hotkeys = categories[cat].hotkeys.sort();135 136 this.categories = categories;137 145 } 138 146 … … 178 186 179 187 180 function init( data)188 function init() 181 189 { 182 let hotkeyPage = new HotkeysPage( data);190 let hotkeyPage = new HotkeysPage(); 183 191 } -
ps/trunk/binaries/data/mods/public/gui/hotkeys/hotkeys.xml
r24215 r25023 67 67 <object type="image" 68 68 style="ModernDialog" 69 size="50%-300 50%- 190 50%+300 50%+190"69 size="50%-300 50%-" 70 70 > 71 71 <object name="hotkeyPickerTitle" style="ModernLabelText" type="text" size="50%-128 -16 50%+128 16"> … … 73 73 </object> 74 74 75 <object name="hotkeyPickerDesc" style="ModernLabelText" type="text" size="8 20 100%-8 66"> 75 <object name="hotkeyPickerDescHotkey" style="ModernLabelText" type="text" size="8 30 100%-8 60"> 76 <translatableAttribute id="caption">Hotkey Description</translatableAttribute> 77 </object> 78 79 <object name="hotkeyPickerDesc" style="ModernLabelText" type="text" size="8 60 100%-8 120"> 76 80 <translatableAttribute id="caption">Click on any mapping to modify it.\n You may have up to 4 different hotkeys.</translatableAttribute> 77 81 </object>
Note:
See TracChangeset
for help on using the changeset viewer.