From 217f06a621f24e82a425d3e39d846c0ad7b04337 Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Mon, 8 Jun 2020 14:07:31 +0200 Subject: [PATCH] Make UI mentions of hotkeys dynamic --- src/002-config/mousetrapConfig.js | 27 +++++++++++++------------ src/arcologyBuilding/penthouse.js | 2 +- src/facilities/nursery/childInteract.tw | 8 ++++++-- src/gui/storyCaptionWidgets.tw | 14 +++++++++++-- src/interaction/main/mainLinks.js | 10 ++++----- src/js/main.js | 2 +- src/js/slaveListing.js | 12 +++++------ src/uncategorized/slaveInteract.tw | 8 ++++---- 8 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/002-config/mousetrapConfig.js b/src/002-config/mousetrapConfig.js index 7abaaf4731c..c82ac4be193 100644 --- a/src/002-config/mousetrapConfig.js +++ b/src/002-config/mousetrapConfig.js @@ -235,6 +235,7 @@ App.UI.Hotkeys = (function() { const save = SugarCube.storage.get("hotkeys"); for (const saveKey in save) { + // discard obsolete hotkeys if (actions[saveKey]) { actions[saveKey].combinations = save[saveKey]; } @@ -262,42 +263,42 @@ App.UI.Hotkeys = (function() { })(); // add hotkeys -App.UI.Hotkeys.add("Advance week", { +App.UI.Hotkeys.add("endWeek", { callback: function() { $("#story-caption #endWeekButton a.macro-link").trigger("click"); - }, combinations: ["enter"] + }, combinations: ["enter"], uiName: "Next Week" }); -App.UI.Hotkeys.add("Continue/Back", { +App.UI.Hotkeys.add("nextLink", { callback: function() { $("#story-caption #nextButton a.macro-link").trigger("click"); - }, combinations: ["space"] + }, combinations: ["space"], uiName: "Continue/Back" }); -App.UI.Hotkeys.add("Previous Slave", { +App.UI.Hotkeys.add("prevSlave", { callback: function() { $("#prevSlave a.macro-link").trigger("click"); - }, combinations: ["left", "q"] + }, combinations: ["left", "q"], uiName: "Previous Slave" }); -App.UI.Hotkeys.add("Next Slave", { +App.UI.Hotkeys.add("nextSlave", { callback: function() { $("#nextSlave a.macro-link").trigger("click"); - }, combinations: ["right", "e"] + }, combinations: ["right", "e"], uiName: "Next Slave" }); -App.UI.Hotkeys.add("Previous Child", { +App.UI.Hotkeys.add("prevChild", { callback: function() { $("#prevChild a.macro-link").trigger("click"); - }, combinations: ["left", "q"] + }, combinations: ["left", "q"], uiName: "Previous Child" }); -App.UI.Hotkeys.add("Next Child", { +App.UI.Hotkeys.add("nextChild", { callback: function() { $("#nextChild a.macro-link").trigger("click"); - }, combinations: ["right", "e"] + }, combinations: ["right", "e"], uiName: "Next Child" }); App.UI.Hotkeys.add("walkpast", { callback: function() { $("#walkpast a.macro-link").trigger("click"); }, combinations: ["f"] }); -App.UI.Hotkeys.add("Manage HG", { +App.UI.Hotkeys.add("HG Select", { callback: function() { $("#manageHG a").trigger("click"); }, combinations: ["h"] diff --git a/src/arcologyBuilding/penthouse.js b/src/arcologyBuilding/penthouse.js index f4d9e75ca14..89c31269931 100644 --- a/src/arcologyBuilding/penthouse.js +++ b/src/arcologyBuilding/penthouse.js @@ -25,7 +25,7 @@ App.Arcology.Cell.Penthouse = class extends App.Arcology.Cell.BaseCell { const fragment = document.createDocumentFragment(); const link = App.UI.DOM.passageLink("Penthouse", "Manage Penthouse"); - const hotkey = App.UI.DOM.makeElement("span", "[P]", "hotkey"); + const hotkey = App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Manage Penthouse"), "hotkey"); if (V.verticalizeArcologyLinks === 0) { const div = document.createElement("div"); div.append(link, " ", hotkey); diff --git a/src/facilities/nursery/childInteract.tw b/src/facilities/nursery/childInteract.tw index db203972cd3..eac1877bcd5 100644 --- a/src/facilities/nursery/childInteract.tw +++ b/src/facilities/nursery/childInteract.tw @@ -18,7 +18,9 @@ <</if>> <center> -@@.cyan;[â†,Q] @@ +<span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("prevChild")>> +</span> <span id="prevChild"> <b> <<link "Prev" "Previous Child In Line">><</link>> @@ -30,7 +32,9 @@ <<link "Next" "Next Child In Line">><</link>> </b> </span> -@@.cyan; [E,→]@@ +<span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("nextChild")>> +</span> </center> <br> diff --git a/src/gui/storyCaptionWidgets.tw b/src/gui/storyCaptionWidgets.tw index a8616c836cd..3242e2b91f5 100644 --- a/src/gui/storyCaptionWidgets.tw +++ b/src/gui/storyCaptionWidgets.tw @@ -7,7 +7,14 @@ <<if _Pass != "End Week">> <<if _Pass == "Main">> <strong> - <div id="endWeekButton"><<link "END WEEK">><<run endWeek()>><</link>> @@.cyan;[Ent]@@</div> + <div id="endWeekButton"> + <<link "END WEEK">> + <<run endWeek()>> + <</link>> + <span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("endWeek")>> + </span> + </div> </strong> <<if $rulesAssistantAuto == 1 && DefaultRulesError()>> <div>@@.yellow;WARNING: Rules Assistant has rules with errors!@@</div> @@ -17,7 +24,10 @@ <<if $nextButton != " ">> <<link "$nextButton">> <<goto $nextLink>> - <</link>> @@.cyan;[Space]@@ + <</link>> + <span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("nextLink")>> + </span> <</if>> </div></strong> <</if>> diff --git a/src/interaction/main/mainLinks.js b/src/interaction/main/mainLinks.js index a41eff26a9c..d2be8893bee 100644 --- a/src/interaction/main/mainLinks.js +++ b/src/interaction/main/mainLinks.js @@ -85,7 +85,7 @@ App.UI.View.mainLinks = function() { if (V.PC.health.shortDamage < 30) { const link = App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Change plans", "Personal Attention Select"), "major-link"); link.id = "managePA"; - fragment.append(" ", link, " ", App.UI.DOM.makeElement("span", "[A]", "hotkey")); + fragment.append(" ", link, " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Personal Attention"), "hotkey")); } if (V.useSlaveSummaryOverviewTab === 0) { @@ -97,7 +97,7 @@ App.UI.View.mainLinks = function() { } div.append(". ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Manage Head Girl", "HG Select"), "major-link"), - " ", App.UI.DOM.makeElement("span", "[H]", "hotkey")); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("HG Select"), "hotkey")); div.id = "manageHG"; } else if (V.slaves.length > 1) { div.append(`You have not selected a Head Girl`); @@ -106,7 +106,7 @@ App.UI.View.mainLinks = function() { } div.append(". ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select One", "HG Select"), "major-link"), - " ", App.UI.DOM.makeElement("span", "[H]", "hotkey")); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("HG Select"), "hotkey")); div.id = "manageHG"; } else { div.append(App.UI.DOM.makeElement("span", "You do not have enough slaves to keep a Head Girl", "note")); @@ -121,7 +121,7 @@ App.UI.View.mainLinks = function() { div.append("You have not selected a Recruiter. ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select one", "Recruiter Select"), "major-link")); } - div.append(" ", App.UI.DOM.makeElement("span", "[U]", "hotkey")); + div.append(" ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Recruiter Select"), "hotkey")); div.id = "manageRecruiter"; fragment.append(div); @@ -134,7 +134,7 @@ App.UI.View.mainLinks = function() { div.append("You have not selected a Bodyguard. ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select one", "BG Select"), "major-link")); } - div.append(" ", App.UI.DOM.makeElement("span", "[B]", "hotkey")); + div.append(" ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("BG Select"), "hotkey")); div.id = "manageBG"; fragment.append(div); } diff --git a/src/js/main.js b/src/js/main.js index 1854c4e6343..2dea7157fec 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -225,7 +225,7 @@ App.MainView.full = function() { const raLink = document.createElement("span"); raLink.id = "RAButton"; raLink.append(" | ", App.UI.DOM.passageLink("Rules Assistant Options", "Rules Assistant"), - " ", App.UI.DOM.makeElement("span", "[R]", ["clear-formatting", "hotkey"])); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Rules Assistant"), ["clear-formatting", "hotkey"])); span.append(raLink); if (V.rulesAssistantAuto !== 1) { diff --git a/src/js/slaveListing.js b/src/js/slaveListing.js index 09d47f01788..ee2d2088cd5 100644 --- a/src/js/slaveListing.js +++ b/src/js/slaveListing.js @@ -864,7 +864,7 @@ App.UI.SlaveList.penthousePage = function() { slaveWrapper.append(". "); const link = App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Manage Head Girl", "HG Select"), "major-link"); link.id = "manageHG"; - slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", "[H]", "hotkey")); + slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("HG Select"), "hotkey")); slaveWrapper.append(App.UI.SlaveList.render.listDOM([HG.ID], [], App.UI.SlaveList.SlaveInteract.penthouseInteract)); } else { @@ -874,7 +874,7 @@ App.UI.SlaveList.penthousePage = function() { slaveWrapper.append(" and Consort"); } slaveWrapper.append(". ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select One", "HG Select"), "major-link"), - " ", App.UI.DOM.makeElement("span", "[H]", "hotkey")); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("HG Select"), "hotkey")); slaveWrapper.id = "manageHG"; if (V.slavePanelStyle === 2) { slaveWrapper.classList.add("slaveSummary", "card"); @@ -907,13 +907,13 @@ App.UI.SlaveList.penthousePage = function() { slaveWrapper.append(". "); const link = App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Manage Recruiter", "Recruiter Select"), "major-link"); link.id = "manageRecruiter"; - slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", "[U]", "hotkey")); + slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Recruiter Select"), "hotkey")); slaveWrapper.append(App.UI.SlaveList.render.listDOM([RC.ID], [], App.UI.SlaveList.SlaveInteract.penthouseInteract)); } else { slaveWrapper.append("You have ", App.UI.DOM.makeElement("span", "not", "warning"), " selected a Recruiter. ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select one", "Recruiter Select"), "major-link"), - " ", App.UI.DOM.makeElement("span", "[U]", "hotkey")); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("Recruiter Select"), "hotkey")); slaveWrapper.id = "manageRecruiter"; if (V.slavePanelStyle === 2) { slaveWrapper.classList.add("slaveSummary", "card"); @@ -930,14 +930,14 @@ App.UI.SlaveList.penthousePage = function() { " is serving as your bodyguard. "); const link = App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Manage Bodyguard", "BG Select"), "major-link"); link.id = "manageBG"; - slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", "[B]", "hotkey")); + slaveWrapper.append(link, " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("BG Select"), "hotkey")); slaveWrapper.append(App.UI.SlaveList.render.listDOM([BG.ID], [], App.UI.SlaveList.SlaveInteract.penthouseInteract)); slaveWrapper.append(App.MainView.useGuard()); } else { slaveWrapper.append("You have ", App.UI.DOM.makeElement("span", "not", "warning"), " selected a Bodyguard. ", App.UI.DOM.makeElement("span", App.UI.DOM.passageLink("Select one", "BG Select"), "major-link"), - " ", App.UI.DOM.makeElement("span", "[B]", "hotkey")); + " ", App.UI.DOM.makeElement("span", App.UI.Hotkeys.hotkeys("BG Select"), "hotkey")); slaveWrapper.id = "manageBG"; if (V.slavePanelStyle === 2) { slaveWrapper.classList.add("slaveSummary", "card"); diff --git a/src/uncategorized/slaveInteract.tw b/src/uncategorized/slaveInteract.tw index 30529127934..ea3c2115bf8 100644 --- a/src/uncategorized/slaveInteract.tw +++ b/src/uncategorized/slaveInteract.tw @@ -62,8 +62,8 @@ [[Cheat Edit Slave Alternative|MOD_Edit Slave Cheat New][$cheater = 1]] </div> <</if>> - <span class="cyan"> - [â†,Q] + <span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("prevSlave")>> </span> <span id="prevSlave" style="font-weight:bold"> <<link "Prev" "Slave Interact">><<set $activeSlave = getSlave(_slavesInLine[0])>><</link>> @@ -76,8 +76,8 @@ <span id="nextSlave" style="font-weight:bold"> <<link "Next" "Slave Interact">><<set $activeSlave = getSlave(_slavesInLine[1])>><</link>> </span> - <span class="cyan"> - [E,→] + <span class="hotkey"> + <<print App.UI.Hotkeys.hotkeys("nextSlave")>> </span> </p> <div class="tabbar"> -- GitLab