Skip to content

Commit

Permalink
Fix hotkeys when loading save games
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCycoONE committed Oct 30, 2018
1 parent db9ad36 commit c78e59c
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 170 deletions.
54 changes: 10 additions & 44 deletions CorsixTH/Lua/dialogs/bottom_panel.lua
Expand Up @@ -97,6 +97,13 @@ function UIBottomPanel:UIBottomPanel(ui)
return _S.tooltip.toolbar.reputation .. " (" .. self.ui.hospital.reputation .. ")"
end, 41, 30, 137, 42)
self:registerKeyHandlers()
end
function UIBottomPanel:registerKeyHandlers()
local ui = self.ui
local buttons = self.additional_buttons
-- original TH F-key shortcuts
ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_bankManager"], self.bank_button, self.bank_button.handleClick, "left") -- bank manager
ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_bankStats"], self.bank_button, self.bank_button.handleClick, "right") -- bank stats
Expand Down Expand Up @@ -799,10 +806,6 @@ function UIBottomPanel:afterLoad(old, new)
end
end
end
if old < 47 then
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_toggleInfo"], self, self.toggleInformation)
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_toggleAdvisor"], self, self.toggleAdviser)
end
if old < 58 then
self.pause_font = TheApp.gfx:loadFont("QData", "Font124V")
end
Expand All @@ -815,47 +818,10 @@ function UIBottomPanel:afterLoad(old, new)
self.additional_buttons[i] = self.buttons[5 + i]:makeToggle() -- made them toggle buttons
end
self.bank_button = self.buttons[1]:makeToggle()

-- keyboard shortcuts have been added/changed
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_bankManager"], self.bank_button, self.bank_button.handleClick, "left") -- bank manager
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_bankStats"], self.bank_button, self.bank_button.handleClick, "right") -- bank manager
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_staffManage"], self.additional_buttons[1], self.additional_buttons[1].handleClick, "left") -- staff management
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_townMap"], self.additional_buttons[2], self.additional_buttons[2].handleClick, "left") -- town map
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook"], self.additional_buttons[3], self.additional_buttons[3].handleClick, "left") -- casebook
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_research"], self.additional_buttons[4], self.additional_buttons[4].handleClick, "left") -- research
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_status"], self.additional_buttons[5], self.additional_buttons[5].handleClick, "left") -- status
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_charts"], self.additional_buttons[6], self.additional_buttons[6].handleClick, "left") -- charts
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_policy"], self.additional_buttons[7], self.additional_buttons[7].handleClick, "left") -- policy
self.ui:removeKeyHandler(self.ui.app.hotkeys["ingame_panel_map_alt"], self)
self.ui:removeKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook_alt"], self)
self.ui:removeKeyHandler(self.ui.app.hotkeys["ingame_panel_research_alt"], self)
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_map_alt"], self.additional_buttons[2], self.additional_buttons[2].handleClick, "left") -- T for town map
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook_alt"], self.additional_buttons[3], self.additional_buttons[3].handleClick, "left") -- C for casebook
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_research_alt"], self.additional_buttons[4], self.additional_buttons[4].handleClick, "left") -- R for research
end
if old < 70 then
self.ui:removeKeyHandler("a", self)
end
if old < 71 then
self.ui:removeKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook_alt"], self.additional_buttons[3], self.additional_buttons[3].handleClick, "left") -- remove C for opening the Casebook
-- add choice for opening casebook as per chosen option in config
local config = self.ui.app.config
if not config.volume_opens_casebook then
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook_alt"], self.additional_buttons[3], self.additional_buttons[3].handleClick, "left") -- C for casebook
else
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_panel_casebook_alt02"], self.additional_buttons[3], self.additional_buttons[3].handleClick, "left") -- Shift + C for casebook
end
-- add new key handlers
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_jukebox"], self, self.openJukebox) -- open the jukebox
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_loadMenu"], self, self.openLoad) -- Shift + L for Load saved game menu
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_saveMenu"], self, self.openSave) -- Shift + S for Load create save menu
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_restartLevel"], self, self.restart) -- Shift + R for restart the level
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_quitLevel"], self, self.quit) -- Shift + Q quit the game and return to main menu
end
if old < 82 then
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_quickSave"], self, self.quickSave) -- Shift+Alt+S quick save
self.ui:addKeyHandler(self.ui.app.hotkeys["ingame_quickLoad"], self, self.quickLoad) -- Shift+Alt+L load last quick save
end

self:registerKeyHandlers()

Window.afterLoad(self, old, new)
end

12 changes: 5 additions & 7 deletions CorsixTH/Lua/dialogs/confirm_dialog.lua
Expand Up @@ -59,6 +59,10 @@ function UIConfirmDialog:UIConfirmDialog(ui, text, callback_ok, callback_cancel)
self:addPanel(362, 90, last_y + 10):makeButton(0, 10, 82, 34, 363, self.ok)
:setTooltip(_S.tooltip.window_general.confirm):setSound"YesX.wav"
self:registerKeyHandlers()
end
function UIConfirmDialog:registerKeyHandlers()
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.ok)
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.ok)
end
Expand Down Expand Up @@ -95,11 +99,5 @@ function UIConfirmDialog:draw(canvas, x, y)
end
function UIConfirmDialog:afterLoad(old, new)
if old < 101 then
self:removeKeyHandler(self.ui.app.hotkeys["global_confirm_alt"])
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.ok)
end
if old < 104 then
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.ok)
end
self:registerKeyHandlers()
end
17 changes: 8 additions & 9 deletions CorsixTH/Lua/dialogs/edit_room.lua
Expand Up @@ -30,8 +30,6 @@ function UIEditRoom:UIEditRoom(ui, room_type)
-- NB: UIEditRoom:onCursorWorldPositionChange is called by the UIPlaceObjects
-- constructor, hence the initialisation of required fields prior to the call.
self.UIPlaceObjects(self, ui)
self:addKeyHandler(app.hotkeys["global_confirm"], self.confirm) -- UIPlaceObjects does not need this
self:addKeyHandler(app.hotkeys["global_confirm_alt02"], self.confirm)
local app = ui.app
local blue_red_swap = self.anims.Alt32_BlueRedSwap
Expand Down Expand Up @@ -88,6 +86,13 @@ function UIEditRoom:UIEditRoom(ui, room_type)
self.mouse_down_y = false
self.mouse_cell_x = 0
self.mouse_cell_y = 0
self:registerKeyHandlers()
end
function UIEditRoom:registerKeyHandlers()
self:addKeyHandler(app.hotkeys["global_confirm"], self.confirm) -- UIPlaceObjects does not need this
self:addKeyHandler(app.hotkeys["global_confirm_alt02"], self.confirm)
end
function UIEditRoom:close(...)
Expand Down Expand Up @@ -1531,11 +1536,5 @@ function UIEditRoom:placeObject()
end
function UIEditRoom:afterLoad(old, new)
if old < 101 then
self:removeKeyHandler(app.hotkeys["global_confirm_alt"])
self:addKeyHandler(app.hotkeys["global_confirm"], self.confirm)
end
if old < 104 then
self:addKeyHandler(app.hotkeys["global_confirm_alt02"], self.confirm)
end
self:registerKeyHandlers()
end
18 changes: 13 additions & 5 deletions CorsixTH/Lua/dialogs/fullscreen/drug_casebook.lua
Expand Up @@ -55,11 +55,7 @@ function UICasebook:UICasebook(ui, disease_selection)
self:addPanel(0, 235, 400):makeButton(0, 0, 140, 20, 0, self.concentrateResearch)
:setTooltip(_S.tooltip.casebook.research)
-- Hotkeys
self:addKeyHandler(self.ui.app.config["ingame_scroll_up"], self.scrollUp)
self:addKeyHandler(self.ui.app.config["ingame_scroll_down"], self.scrollDown)
self:addKeyHandler(self.ui.app.config["ingame_scroll_left"], self.decreasePay)
self:addKeyHandler(self.ui.app.config["ingame_scroll_right"], self.increasePay)
self:registerKeyHandlers();
-- Icons representing cure effectiveness and other important information.
self.machinery = self:addPanel(6, 306, 352):setTooltip(_S.tooltip.casebook.cure_type.machine)
Expand Down Expand Up @@ -98,6 +94,14 @@ function UICasebook:UICasebook(ui, disease_selection)
end
end
function UICasebook:registerKeyHandlers()
-- Hotkeys
self:addKeyHandler(self.ui.app.config["ingame_scroll_up"], self.scrollUp)
self:addKeyHandler(self.ui.app.config["ingame_scroll_down"], self.scrollDown)
self:addKeyHandler(self.ui.app.config["ingame_scroll_left"], self.decreasePay)
self:addKeyHandler(self.ui.app.config["ingame_scroll_right"], self.increasePay)
end
function UICasebook:close()
UIFullscreen.close(self)
self.ui:getWindow(UIBottomPanel):updateButtonStates()
Expand Down Expand Up @@ -400,3 +404,7 @@ function UICasebook:onTick()
end
return UIFullscreen.onTick(self)
end

function UICasebook:afterLoad()
self:registerKeyHandlers()
end
8 changes: 8 additions & 0 deletions CorsixTH/Lua/dialogs/fullscreen/staff_management.lua
Expand Up @@ -133,6 +133,10 @@ function UIStaffManagement:UIStaffManagement(ui)
self:setCategory("Doctor")
self:registerKeyHandlers()
end
function UIStaffManagement:registerKeyHandlers()
-- Hotkeys.
self:addKeyHandler(self.ui.app.hotkeys["ingame_scroll_left"], self.previousCategory)
self:addKeyHandler(self.ui.app.hotkeys["ingame_scroll_right"], self.nextCategory)
Expand Down Expand Up @@ -563,3 +567,7 @@ function UIStaffManagement:close()
UIFullscreen.close(self)
self.ui:getWindow(UIBottomPanel):updateButtonStates()
end
function UIStaffManagement:afterLoad(old, new)
self:registerKeyHandlers()
end
12 changes: 5 additions & 7 deletions CorsixTH/Lua/dialogs/furnish_corridor.lua
Expand Up @@ -117,6 +117,10 @@ function UIFurnishCorridor:UIFurnishCorridor(ui, objects, edit_dialog)
self:makeTooltip(_S.tooltip.buy_objects_window.price, 20, 168, 127, 187)
self:makeTooltip(_S.tooltip.buy_objects_window.total_value, 20, 196, 127, 215)
self:registerKeyHandlers()
end
function UIFurnishCorridor:registerKeyHandlers()
self:addKeyHandler(app.hotkeys["global_confirm"], self.confirm)
self:addKeyHandler(app.hotkeys["global_confirm_alt02"], self.confirm)
end
Expand Down Expand Up @@ -234,11 +238,5 @@ function UIFurnishCorridor:onMouseMove(x, y, dx, dy)
end
function UIFurnishCorridor:afterLoad(old, new)
if old < 101 then
self:removeKeyHandler(app.hotkeys["global_confirm_alt"])
self:addKeyHandler(app.hotkeys["global_confirm"], self.confirm)
end
if old < 104 then
self:addKeyHandler(app.hotkeys["global_confirm_alt02"], self.confirm)
end
self:registerKeyHandlers()
end
16 changes: 7 additions & 9 deletions CorsixTH/Lua/dialogs/hire_staff.lua
Expand Up @@ -35,8 +35,6 @@ function UIHireStaff:UIHireStaff(ui)
self.panel_sprites = ui.app.gfx:loadSpriteTable("QData", "Req11V", true)
self.white_font = ui.app.gfx:loadFont("QData", "Font01V")
self.face_parts = ui.app.gfx:loadRaw("Face01V", 65, 1350, nil, "Data", "MPalette.dat")
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.hire)
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.hire)
-- Left hand side tab backgrounds
self:addPanel(253, 0, 0)
Expand Down Expand Up @@ -97,6 +95,12 @@ function UIHireStaff:UIHireStaff(ui)
self:makeTooltip(_S.tooltip.hire_staff_window.researcher, 164, 136, 191, 167)
self:updateTooltips()
self:registerKeyHandlers()
end
function UIHireStaff:registerKeyHandlers()
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.hire)
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.hire)
end
function UIHireStaff:updateTooltips()
Expand Down Expand Up @@ -268,11 +272,5 @@ function UIHireStaff:close()
end
function UIHireStaff:afterLoad(old, new)
if old < 101 then
self:removeKeyHandler(self.ui.app.hotkeys["global_confirm_alt"])
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.hire)
end
if old < 104 then
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.hire)
end
self:registerKeyHandlers()
end
12 changes: 5 additions & 7 deletions CorsixTH/Lua/dialogs/information.lua
Expand Up @@ -66,6 +66,10 @@ function UIInformation:UIInformation(ui, text, use_built_in_font)
self:onChangeLanguage()
-- Enter closes the window
self:registerKeyHandlers()
end
function UIInformation:registerKeyHandlers()
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.close)
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.close)
end
Expand Down Expand Up @@ -129,11 +133,5 @@ function UIInformation:close()
end
function UIInformation:afterLoad(old, new)
if old < 101 then
self:removeKeyHandler(self.ui.app.hotkeys["global_confirm_alt"])
self:addKeyHandler(self.ui.app.hotkeys["global_confirm"], self.close)
end
if old < 104 then
self:addKeyHandler(self.ui.app.hotkeys["global_confirm_alt02"], self.close)
end
self:registerKeyHandlers()
end
8 changes: 8 additions & 0 deletions CorsixTH/Lua/dialogs/patient.lua
Expand Up @@ -90,6 +90,10 @@ function UIPatient:UIPatient(ui, patient)
end
end, 17, 216, 92, 292)
self:registerKeyHandlers()
end
function UIPatient:registerKeyHandlers()
-- Always add this because of a race condition if the user clicks a patient
-- that's already going home, then clicks another, the handler is left empty. Bad.
-- Just do a going_home check when called.
Expand Down Expand Up @@ -343,3 +347,7 @@ end
function UIPatient:hitTest(x, y)
return Window.hitTest(self, x, y) or is_in_view_circle(x, y)
end
function UIPatient:afterLoad(old, new)
self:registerKeyHandlers()
end
13 changes: 10 additions & 3 deletions CorsixTH/Lua/dialogs/place_objects.lua
Expand Up @@ -67,7 +67,6 @@ function UIPlaceObjects:UIPlaceObjects(ui, object_list, pay_for)
end
self:addPanel(114, 0, 90) -- Dialog mid-piece
self:addPanel(115, 0, 100):makeButton(9, 8, 41, 42, 116, self.cancel):setSound("no4.wav"):setTooltip(_S.tooltip.place_objects_window.cancel)
self:addKeyHandler(self.ui.app.hotkeys["global_cancel"], self.cancel)
self.purchase_button =
self:addPanel(117, 50, 100):makeButton(1, 8, 41, 42, 118, self.purchaseItems):setTooltip(_S.tooltip.place_objects_window.buy_sell)
:setDisabledSprite(127):enable(false) -- Disabled purchase items button
Expand All @@ -86,9 +85,13 @@ function UIPlaceObjects:UIPlaceObjects(ui, object_list, pay_for)
self.num_slots = 0

self:addObjects(object_list, pay_for)
self:addKeyHandler(self.ui.app.hotkeys["ingame_rotateobject"], self.tryNextOrientation)

ui:setWorldHitTest(false)
self:registerKeyHandlers()
end

function UIPlaceObjects:registerKeyHandlers()
self:addKeyHandler(self.ui.app.hotkeys["global_cancel"], self.cancel)
self:addKeyHandler(self.ui.app.hotkeys["ingame_rotateobject"], self.tryNextOrientation)
end

-- changes the window size and buttons to num_slots slots
Expand Down Expand Up @@ -823,3 +826,7 @@ function UIPlaceObjects:selectObjectType(object_type)
end
end
end

function UIPlaceObjects:afterLoad(old, new)
self:registerKeyHandlers()
end
31 changes: 8 additions & 23 deletions CorsixTH/Lua/game_ui.lua
Expand Up @@ -49,8 +49,6 @@ function GameUI:GameUI(app, local_hospital, map_editor)
self:UI(app)
self.app = app
self.scroll_keys = {}
self.hospital = local_hospital
self.tutorial = { chapter = 0, phase = 0 }
if map_editor then
Expand Down Expand Up @@ -100,19 +98,19 @@ function GameUI:GameUI(app, local_hospital, map_editor)
self.announcer = Announcer(app)
-- Set the scrolling keys.
self.scroll_keys = {
[tostring(app.hotkeys["ingame_scroll_up"])] = {x = 0, y = -10},
[tostring(app.hotkeys["ingame_scroll_down"])] = {x = 0, y = 10},
[tostring(app.hotkeys["ingame_scroll_left"])] = {x = -10, y = 0},
[tostring(app.hotkeys["ingame_scroll_right"])] = {x = 10, y = 0},
}
end
function GameUI:setupGlobalKeyHandlers()
UI.setupGlobalKeyHandlers(self)
-- Set the scrolling keys.
self.scroll_keys = {
[tostring(self.app.hotkeys["ingame_scroll_up"])] = {x = 0, y = -10},
[tostring(self.app.hotkeys["ingame_scroll_down"])] = {x = 0, y = 10},
[tostring(self.app.hotkeys["ingame_scroll_left"])] = {x = -10, y = 0},
[tostring(self.app.hotkeys["ingame_scroll_right"])] = {x = 10, y = 0},
}
self:addKeyHandler(self.app.hotkeys["global_window_close"], self, self.setEditRoom, false)
self:addKeyHandler(self.app.hotkeys["ingame_showmenubar"], self, self.showMenuBar)
self:addKeyHandler(self.app.hotkeys["ingame_gamespeed_speedup"], self, self.keySpeedUp)
Expand Down Expand Up @@ -1143,21 +1141,13 @@ function GameUI:afterLoad(old, new)
self.adviser.frame = 1
self.adviser.number_frames = 4
end
if old < 70 then
self:addKeyHandler(app.hotkeys["ingame_toggleAdvisor"], self, self.toggleAdviser)
end
if old < 75 then
self.current_momentum = { x = 0, y = 0 }
self.momentum = self.app.config.scrolling_momentum
end
if old < 78 then
self.current_momentum = { x = 0, y = 0, z = 0}
end
if old < 81 then
self:removeKeyHandler(app.hotkeys["ingame_setTransparent"], self, self.toggleWallsTransparent)
self:addKeyHandler(app.hotkeys["ingame_gamespeed_speedup"], self, self.keySpeedUp)
self:addKeyHandler(app.hotkeys["ingame_setTransparent"], self, self.keyTransparent)
end
if old < 115 then
self.shake_screen_intensity = 0
end
Expand All @@ -1166,11 +1156,6 @@ function GameUI:afterLoad(old, new)
end
if old < 129 then
self.recallpositions = {}
-- snap to screen position
for i = 0, 9 do
self:addKeyHandler({self.app.hotkeys["ingame_storePosition"], tostring(i)}, self, self.setMapRecallPosition, i)
self:addKeyHandler({self.app.hotkeys["ingame_recallPosition"], tostring(i)}, self, self.recallMapPosition, i)
end
end
if old < 130 then
self.ticks_since_last_announcement = nil -- cleanup
Expand Down

0 comments on commit c78e59c

Please sign in to comment.