Skip to content

Commit

Permalink
Hotkey cleanup and fixes
Browse files Browse the repository at this point in the history
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 4b0140e
Show file tree
Hide file tree
Showing 15 changed files with 800 additions and 413 deletions.
25 changes: 9 additions & 16 deletions CorsixTH/Lua/config_finder.lua
Expand Up @@ -511,12 +511,10 @@ local hotkeys_filename = pathconcat(config_path, hotkeys_name)
-- Defaults for hotkeys. -- Defaults for hotkeys.
local hotkeys_defaults = { local hotkeys_defaults = {
global_confirm = "return", global_confirm = "return",
global_confirm_alt = "enter", global_confirm_alt = "e",
global_confirm_alt02 = "e",
global_cancel = "escape", global_cancel = "escape",
global_cancel_alt = "q", global_cancel_alt = "q",
global_fullscreen_toggle = {"alt", "return"}, global_fullscreen_toggle = {"alt", "return"},
global_fullscreen_toggle_alt = {"alt", "keypad enter"},
global_exitApp = {"alt", "f4"}, global_exitApp = {"alt", "f4"},
global_resetApp = {"shift", "f10"}, global_resetApp = {"shift", "f10"},
global_captureMouse = {"ctrl", "f10"}, global_captureMouse = {"ctrl", "f10"},
Expand All @@ -537,14 +535,13 @@ local hotkeys_defaults = {
ingame_gamespeed_max = "4", ingame_gamespeed_max = "4",
ingame_gamespeed_thensome = "5", ingame_gamespeed_thensome = "5",
ingame_gamespeed_speedup = "z", ingame_gamespeed_speedup = "z",
ingame_scroll_up = "w", ingame_scroll_up = "up",
ingame_scroll_down = "s", ingame_scroll_down = "down",
ingame_scroll_left = "a", ingame_scroll_left = "left",
ingame_scroll_right = "d", ingame_scroll_right = "right",
ingame_scroll_shift = "shift",
ingame_zoom_in = "=", ingame_zoom_in = "=",
ingame_zoom_in_more = {"shift", "="}, ingame_zoom_in_more = {"shift", "="},
ingame_zoom_in_alt = "+",
ingame_zoom_in_more_alt = {"shift", "+"},
ingame_zoom_out = "-", ingame_zoom_out = "-",
ingame_zoom_out_more = {"shift", "-"}, ingame_zoom_out_more = {"shift", "-"},
ingame_setTransparent = "x", ingame_setTransparent = "x",
Expand Down Expand Up @@ -614,7 +611,6 @@ end


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

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


Expand Down Expand Up @@ -657,11 +653,9 @@ if hotkeys_needs_rewrite then
--]=] .. '\n' .. --]=] .. '\n' ..
'global_confirm = ' .. hotkeys_values.global_confirm .. '\n' .. 'global_confirm = ' .. hotkeys_values.global_confirm .. '\n' ..
'global_confirm_alt = ' .. hotkeys_values.global_confirm_alt .. '\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 = ' .. hotkeys_values.global_cancel .. '\n' ..
'global_cancel_alt = ' .. hotkeys_values.global_cancel_alt .. '\n' .. 'global_cancel_alt = ' .. hotkeys_values.global_cancel_alt .. '\n' ..
'global_fullscreen_toggle = ' .. hotkeys_values.global_fullscreen_toggle .. '\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_exitApp = ' .. hotkeys_values.global_exitApp .. '\n' ..
'global_resetApp = ' .. hotkeys_values.global_resetApp .. '\n' .. 'global_resetApp = ' .. hotkeys_values.global_resetApp .. '\n' ..
'global_captureMouse = ' .. hotkeys_values.global_captureMouse .. '\n' .. 'global_captureMouse = ' .. hotkeys_values.global_captureMouse .. '\n' ..
Expand All @@ -680,15 +674,14 @@ if hotkeys_needs_rewrite then
'ingame_scroll_up = ' .. hotkeys_values.ingame_scroll_up .. '\n' .. 'ingame_scroll_up = ' .. hotkeys_values.ingame_scroll_up .. '\n' ..
'ingame_scroll_down = ' .. hotkeys_values.ingame_scroll_down .. '\n' .. 'ingame_scroll_down = ' .. hotkeys_values.ingame_scroll_down .. '\n' ..
'ingame_scroll_left = ' .. hotkeys_values.ingame_scroll_left .. '\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-------------------------------------- --------------------------------------Zoom--------------------------------------
-- These are keys used to zoom the camera in and out. -- These are keys used to zoom the camera in and out.
-- ]=] .. '\n' .. -- ]=] .. '\n' ..
'ingame_zoom_in = '.. hotkeys_values.ingame_zoom_in .. '\n' .. 'ingame_zoom_in = '.. hotkeys_values.ingame_zoom_in .. '\n' ..
'ingame_zoom_in_more = ' .. hotkeys_values.ingame_zoom_in_more .. '\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 = ' .. hotkeys_values.ingame_zoom_out .. '\n' ..
'ingame_zoom_out_more = ' .. hotkeys_values.ingame_zoom_out_more .. '\n' .. [=[ 'ingame_zoom_out_more = ' .. hotkeys_values.ingame_zoom_out_more .. '\n' .. [=[
Expand Down Expand Up @@ -818,4 +811,4 @@ for k, str_val in pairs(hotkeys_values) do
end end
end end


return config_filename, config_values, hotkeys_filename, hotkeys_values return config_filename, config_values, hotkeys_filename, hotkeys_values, hotkeys_defaults
36 changes: 18 additions & 18 deletions CorsixTH/Lua/dialogs/bottom_panel.lua
Expand Up @@ -103,7 +103,7 @@ function UIBottomPanel:registerKeyHandlers()
local ui = self.ui local ui = self.ui
local buttons = self.additional_buttons 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_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_bankStats", self.bank_button, self.bank_button.handleClick, "right") -- bank stats
ui:addKeyHandler("ingame_panel_staffManage", buttons[1], buttons[1].handleClick, "left") -- staff management ui:addKeyHandler("ingame_panel_staffManage", buttons[1], buttons[1].handleClick, "left") -- staff management
Expand All @@ -113,32 +113,32 @@ function UIBottomPanel:registerKeyHandlers()
ui:addKeyHandler("ingame_panel_status", buttons[5], buttons[5].handleClick, "left") -- status 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_charts", buttons[6], buttons[6].handleClick, "left") -- charts
ui:addKeyHandler("ingame_panel_policy", buttons[7], buttons[7].handleClick, "left") -- policy 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_buildRoom", self, self.dialogBuildRoom) -- Build room.
ui:addKeyHandler("ingame_panel_furnishCorridor", self, self.dialogFurnishCorridor) -- Furnish corridor. ui:addKeyHandler("ingame_panel_furnishCorridor", self, self.dialogFurnishCorridor) -- Furnish corridor.
ui:addKeyHandler("ingame_panel_editRoom", self, self.editRoom) -- Edit room. 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 -- Alternate 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_map_alt", buttons[2], buttons[2].handleClick, "left") -- town map
ui:addKeyHandler("ingame_panel_research_alt", buttons[4], buttons[4].handleClick, "left") -- R for research ui:addKeyHandler("ingame_panel_research_alt", buttons[4], buttons[4].handleClick, "left") -- research
local config = ui.app.config local config = ui.app.config
if not config.volume_opens_casebook then 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 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 end
ui:addKeyHandler("ingame_loadMenu", self, self.openLoad) -- Shift + L for Load saved game menu ui:addKeyHandler("ingame_loadMenu", self, self.openLoad) -- load saved game menu
ui:addKeyHandler("ingame_saveMenu", self, self.openSave) -- Shift + S for Load create save menu ui:addKeyHandler("ingame_saveMenu", self, self.openSave) -- load create save menu
ui:addKeyHandler("ingame_restartLevel", self, self.restart) -- Shift + R for restart the level ui:addKeyHandler("ingame_restartLevel", self, self.restart) -- restart the level
ui:addKeyHandler("ingame_quitLevel", self, self.quit) -- Shift + Q quit the game and return to main menu ui:addKeyHandler("ingame_quitLevel", self, self.quit) -- quit the game and return to main menu
ui:addKeyHandler("ingame_quickSave", self, self.quickSave) -- Shift+Alt+S quick save ui:addKeyHandler("ingame_quickSave", self, self.quickSave) -- quick save
ui:addKeyHandler("ingame_quickLoad", self, self.quickLoad) -- Shift+Alt+L load last quick save ui:addKeyHandler("ingame_quickLoad", self, self.quickLoad) -- load last quick save
-- misc. keyhandlers -- misc. keyhandlers
ui:addKeyHandler("ingame_openFirstMessage", self, self.openFirstMessage) -- M for message ui:addKeyHandler("ingame_openFirstMessage", self, self.openFirstMessage) -- message
ui:addKeyHandler("ingame_toggleInfo", self, self.toggleInformation) -- I for Information when you first build ui:addKeyHandler("ingame_toggleInfo", self, self.toggleInformation) -- information when you first build
ui:addKeyHandler("ingame_jukebox", self, self.openJukebox) -- open the jukebox ui:addKeyHandler("ingame_jukebox", self, self.openJukebox) -- jukebox
end end
function UIBottomPanel:openJukebox() function UIBottomPanel:openJukebox()
Expand Down Expand Up @@ -590,7 +590,7 @@ function UIBottomPanel:dialogBuildRoom()
if fullscreen then if fullscreen then
fullscreen:close() fullscreen:close()
end end

local dlg = UIBuildRoom(self.ui) local dlg = UIBuildRoom(self.ui)
self.ui:setEditRoom(false) self.ui:setEditRoom(false)
self.ui:addWindow(dlg) self.ui:addWindow(dlg)
Expand Down
1 change: 0 additions & 1 deletion CorsixTH/Lua/dialogs/confirm_dialog.lua
Expand Up @@ -65,7 +65,6 @@ end
function UIConfirmDialog:registerKeyHandlers() function UIConfirmDialog:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.ok) self:addKeyHandler("global_confirm", self.ok)
self:addKeyHandler("global_confirm_alt", self.ok) self:addKeyHandler("global_confirm_alt", self.ok)
self:addKeyHandler("global_confirm_alt02", self.ok)
end end
function UIConfirmDialog:cancel() function UIConfirmDialog:cancel()
Expand Down
1 change: 0 additions & 1 deletion CorsixTH/Lua/dialogs/edit_room.lua
Expand Up @@ -93,7 +93,6 @@ end
function UIEditRoom:registerKeyHandlers() function UIEditRoom:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.confirm) -- UIPlaceObjects does not need this self:addKeyHandler("global_confirm", self.confirm) -- UIPlaceObjects does not need this
self:addKeyHandler("global_confirm_alt", self.confirm) self:addKeyHandler("global_confirm_alt", self.confirm)
self:addKeyHandler("global_confirm_alt02", self.confirm)
end end
function UIEditRoom:close(...) function UIEditRoom:close(...)
Expand Down
1 change: 0 additions & 1 deletion CorsixTH/Lua/dialogs/furnish_corridor.lua
Expand Up @@ -123,7 +123,6 @@ end
function UIFurnishCorridor:registerKeyHandlers() function UIFurnishCorridor:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.confirm) self:addKeyHandler("global_confirm", self.confirm)
self:addKeyHandler("global_confirm_alt", self.confirm) self:addKeyHandler("global_confirm_alt", self.confirm)
self:addKeyHandler("global_confirm_alt02", self.confirm)
end end
function UIFurnishCorridor:purchaseItem(index, quantity) function UIFurnishCorridor:purchaseItem(index, quantity)
Expand Down
1 change: 0 additions & 1 deletion CorsixTH/Lua/dialogs/hire_staff.lua
Expand Up @@ -101,7 +101,6 @@ end
function UIHireStaff:registerKeyHandlers() function UIHireStaff:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.hire) self:addKeyHandler("global_confirm", self.hire)
self:addKeyHandler("global_confirm_alt", self.hire) self:addKeyHandler("global_confirm_alt", self.hire)
self:addKeyHandler("global_confirm_alt02", self.hire)
end end
function UIHireStaff:updateTooltips() function UIHireStaff:updateTooltips()
Expand Down
1 change: 0 additions & 1 deletion CorsixTH/Lua/dialogs/information.lua
Expand Up @@ -72,7 +72,6 @@ end
function UIInformation:registerKeyHandlers() function UIInformation:registerKeyHandlers()
self:addKeyHandler("global_confirm", self.close) self:addKeyHandler("global_confirm", self.close)
self:addKeyHandler("global_confirm_alt", self.close) self:addKeyHandler("global_confirm_alt", self.close)
self:addKeyHandler("global_confirm_alt02", self.close)
end end
function UIInformation:onChangeLanguage() function UIInformation:onChangeLanguage()
Expand Down

0 comments on commit 4b0140e

Please sign in to comment.