Permalink
Browse files

Hotkey cleanup and fixes

Edited addKeyHandler to allow "=" to also map to "+", and "enter" to "return", and vice versa on both possibilities.

Did same thing with removeKeyHandler.

The speed shift modifier is now a hotkey.

Adding clauses for input when assigning hotkey.

Modifiers will be removed from hotkey when assigning the scroll keys.

RemoveKeyHandler no longer uses table.unpack.

Fix accept then cancel hotkeys.

Other edits / fixes / cleanup.
  • Loading branch information...
leiget authored and TheCycoONE committed Jan 18, 2019
1 parent 1e8da8e commit 4b0140e41d2136a2f20d3fd6393838af95d4e43c
@@ -511,12 +511,10 @@ local hotkeys_filename = pathconcat(config_path, hotkeys_name)
-- Defaults for hotkeys.
local hotkeys_defaults = {
global_confirm = "return",
global_confirm_alt = "enter",
global_confirm_alt02 = "e",
global_confirm_alt = "e",
global_cancel = "escape",
global_cancel_alt = "q",
global_fullscreen_toggle = {"alt", "return"},
global_fullscreen_toggle_alt = {"alt", "keypad enter"},
global_exitApp = {"alt", "f4"},
global_resetApp = {"shift", "f10"},
global_captureMouse = {"ctrl", "f10"},
@@ -537,14 +535,13 @@ local hotkeys_defaults = {
ingame_gamespeed_max = "4",
ingame_gamespeed_thensome = "5",
ingame_gamespeed_speedup = "z",
ingame_scroll_up = "w",
ingame_scroll_down = "s",
ingame_scroll_left = "a",
ingame_scroll_right = "d",
ingame_scroll_up = "up",
ingame_scroll_down = "down",
ingame_scroll_left = "left",
ingame_scroll_right = "right",
ingame_scroll_shift = "shift",
ingame_zoom_in = "=",
ingame_zoom_in_more = {"shift", "="},
ingame_zoom_in_alt = "+",
ingame_zoom_in_more_alt = {"shift", "+"},
ingame_zoom_out = "-",
ingame_zoom_out_more = {"shift", "-"},
ingame_setTransparent = "x",
@@ -614,7 +611,6 @@ end

-- If the file opened succesfully...
if fi then

local file_contents = fi:read("*all")
fi:close()

@@ -657,11 +653,9 @@ if hotkeys_needs_rewrite then
--]=] .. '\n' ..
'global_confirm = ' .. hotkeys_values.global_confirm .. '\n' ..
'global_confirm_alt = ' .. hotkeys_values.global_confirm_alt .. '\n' ..
'global_confirm_alt02 = ' .. hotkeys_values.global_confirm_alt02 .. '\n' ..
'global_cancel = ' .. hotkeys_values.global_cancel .. '\n' ..
'global_cancel_alt = ' .. hotkeys_values.global_cancel_alt .. '\n' ..
'global_fullscreen_toggle = ' .. hotkeys_values.global_fullscreen_toggle .. '\n' ..
'global_fullscreen_toggle_alt = ' .. hotkeys_values.global_fullscreen_toggle_alt .. '\n' ..
'global_exitApp = ' .. hotkeys_values.global_exitApp .. '\n' ..
'global_resetApp = ' .. hotkeys_values.global_resetApp .. '\n' ..
'global_captureMouse = ' .. hotkeys_values.global_captureMouse .. '\n' ..
@@ -680,15 +674,14 @@ if hotkeys_needs_rewrite then
'ingame_scroll_up = ' .. hotkeys_values.ingame_scroll_up .. '\n' ..
'ingame_scroll_down = ' .. hotkeys_values.ingame_scroll_down .. '\n' ..
'ingame_scroll_left = ' .. hotkeys_values.ingame_scroll_left .. '\n' ..
'ingame_scroll_right = ' .. hotkeys_values.ingame_scroll_right .. '\n' .. [=[
'ingame_scroll_right = ' .. hotkeys_values.ingame_scroll_right .. '\n' ..
'ingame_scroll_shift = ' .. hotkeys_values.ingame_scroll_shift .. '\n' .. [=[
--------------------------------------Zoom--------------------------------------
-- These are keys used to zoom the camera in and out.
-- ]=] .. '\n' ..
'ingame_zoom_in = '.. hotkeys_values.ingame_zoom_in .. '\n' ..
'ingame_zoom_in_more = ' .. hotkeys_values.ingame_zoom_in_more .. '\n' ..
'ingame_zoom_in_alt = ' .. hotkeys_values.ingame_zoom_in_alt .. '\n' ..
'ingame_zoom_in_more_alt = '.. hotkeys_values.ingame_zoom_in_more_alt .. '\n' ..
'ingame_zoom_out = ' .. hotkeys_values.ingame_zoom_out .. '\n' ..
'ingame_zoom_out_more = ' .. hotkeys_values.ingame_zoom_out_more .. '\n' .. [=[
@@ -818,4 +811,4 @@ for k, str_val in pairs(hotkeys_values) do
end
end

return config_filename, config_values, hotkeys_filename, hotkeys_values
return config_filename, config_values, hotkeys_filename, hotkeys_values, hotkeys_defaults
@@ -103,7 +103,7 @@ function UIBottomPanel:registerKeyHandlers()
local ui = self.ui
local buttons = self.additional_buttons

-- original TH F-key shortcuts
-- The bottom panel hotkeys.
ui:addKeyHandler("ingame_panel_bankManager", self.bank_button, self.bank_button.handleClick, "left") -- bank manager
ui:addKeyHandler("ingame_panel_bankStats", self.bank_button, self.bank_button.handleClick, "right") -- bank stats
ui:addKeyHandler("ingame_panel_staffManage", buttons[1], buttons[1].handleClick, "left") -- staff management
@@ -113,32 +113,32 @@ function UIBottomPanel:registerKeyHandlers()
ui:addKeyHandler("ingame_panel_status", buttons[5], buttons[5].handleClick, "left") -- status
ui:addKeyHandler("ingame_panel_charts", buttons[6], buttons[6].handleClick, "left") -- charts
ui:addKeyHandler("ingame_panel_policy", buttons[7], buttons[7].handleClick, "left") -- policy
-- New bottom panel hotkeys for the first 4 buttons.
-- Hotkeys for building a room, furnishing the corridor, editing a room, and hiring staff.
ui:addKeyHandler("ingame_panel_buildRoom", self, self.dialogBuildRoom) -- Build room.
ui:addKeyHandler("ingame_panel_furnishCorridor", self, self.dialogFurnishCorridor) -- Furnish corridor.
ui:addKeyHandler("ingame_panel_editRoom", self, self.editRoom) -- Edit room.
ui:addKeyHandler("ingame_panel_hireStaff", self, self.dialogHireStaff) -- Hire staff.
ui:addKeyHandler("ingame_panel_hireStaff", self, self.dialogHireStaff) -- Hire staff.

-- "old" keyboard shortcuts for some of the fullscreen windows
ui:addKeyHandler("ingame_panel_map_alt", buttons[2], buttons[2].handleClick, "left") -- T for town map
ui:addKeyHandler("ingame_panel_research_alt", buttons[4], buttons[4].handleClick, "left") -- R for research
-- Alternate keyboard shortcuts for some of the fullscreen windows.
ui:addKeyHandler("ingame_panel_map_alt", buttons[2], buttons[2].handleClick, "left") -- town map
ui:addKeyHandler("ingame_panel_research_alt", buttons[4], buttons[4].handleClick, "left") -- research
local config = ui.app.config
if not config.volume_opens_casebook then
ui:addKeyHandler("ingame_panel_casebook_alt", buttons[3], buttons[3].handleClick, "left") -- C for casebook
ui:addKeyHandler("ingame_panel_casebook_alt", buttons[3], buttons[3].handleClick, "left") -- casebook
else
ui:addKeyHandler("ingame_panel_casebook_alt02", buttons[3], buttons[3].handleClick, "left") -- Shift + C for casebook
ui:addKeyHandler("ingame_panel_casebook_alt02", buttons[3], buttons[3].handleClick, "left") -- casebook
end
ui:addKeyHandler("ingame_loadMenu", self, self.openLoad) -- Shift + L for Load saved game menu
ui:addKeyHandler("ingame_saveMenu", self, self.openSave) -- Shift + S for Load create save menu
ui:addKeyHandler("ingame_restartLevel", self, self.restart) -- Shift + R for restart the level
ui:addKeyHandler("ingame_quitLevel", self, self.quit) -- Shift + Q quit the game and return to main menu
ui:addKeyHandler("ingame_quickSave", self, self.quickSave) -- Shift+Alt+S quick save
ui:addKeyHandler("ingame_quickLoad", self, self.quickLoad) -- Shift+Alt+L load last quick save
ui:addKeyHandler("ingame_loadMenu", self, self.openLoad) -- load saved game menu
ui:addKeyHandler("ingame_saveMenu", self, self.openSave) -- load create save menu
ui:addKeyHandler("ingame_restartLevel", self, self.restart) -- restart the level
ui:addKeyHandler("ingame_quitLevel", self, self.quit) -- quit the game and return to main menu
ui:addKeyHandler("ingame_quickSave", self, self.quickSave) -- quick save
ui:addKeyHandler("ingame_quickLoad", self, self.quickLoad) -- load last quick save

-- misc. keyhandlers
ui:addKeyHandler("ingame_openFirstMessage", self, self.openFirstMessage) -- M for message
ui:addKeyHandler("ingame_toggleInfo", self, self.toggleInformation) -- I for Information when you first build
ui:addKeyHandler("ingame_jukebox", self, self.openJukebox) -- open the jukebox
ui:addKeyHandler("ingame_openFirstMessage", self, self.openFirstMessage) -- message
ui:addKeyHandler("ingame_toggleInfo", self, self.toggleInformation) -- information when you first build
ui:addKeyHandler("ingame_jukebox", self, self.openJukebox) -- jukebox
end

function UIBottomPanel:openJukebox()
@@ -590,7 +590,7 @@ function UIBottomPanel:dialogBuildRoom()
if fullscreen then
fullscreen:close()
end

local dlg = UIBuildRoom(self.ui)
self.ui:setEditRoom(false)
self.ui:addWindow(dlg)
@@ -65,7 +65,6 @@ end
function UIConfirmDialog:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.ok)
self:addKeyHandler("global_confirm_alt", self.ok)
self:addKeyHandler("global_confirm_alt02", self.ok)
end

function UIConfirmDialog:cancel()
@@ -93,7 +93,6 @@ end
function UIEditRoom:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.confirm) -- UIPlaceObjects does not need this
self:addKeyHandler("global_confirm_alt", self.confirm)
self:addKeyHandler("global_confirm_alt02", self.confirm)
end

function UIEditRoom:close(...)
@@ -123,7 +123,6 @@ end
function UIFurnishCorridor:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.confirm)
self:addKeyHandler("global_confirm_alt", self.confirm)
self:addKeyHandler("global_confirm_alt02", self.confirm)
end

function UIFurnishCorridor:purchaseItem(index, quantity)
@@ -101,7 +101,6 @@ end
function UIHireStaff:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.hire)
self:addKeyHandler("global_confirm_alt", self.hire)
self:addKeyHandler("global_confirm_alt02", self.hire)
end

function UIHireStaff:updateTooltips()
@@ -72,7 +72,6 @@ end
function UIInformation:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.close)
self:addKeyHandler("global_confirm_alt", self.close)
self:addKeyHandler("global_confirm_alt02", self.close)
end

function UIInformation:onChangeLanguage()
Oops, something went wrong.

0 comments on commit 4b0140e

Please sign in to comment.