Permalink
Browse files

Merge pull request #1486 from leiget

Added basic hotkey support and scroll speed and zoom speed options in Option menu.
  • Loading branch information...
TheCycoONE committed Jan 18, 2019
2 parents eb87957 + 4b0140e commit 138aa5b8b29d4935257908ec09106c3fa63270f8
Showing with 3,443 additions and 947 deletions.
  1. +4 −1 .luacheckrc
  2. +2 −1 CorsixTH/CorsixTH.lua
  3. +100 −4 CorsixTH/Lua/app.lua
  4. +321 −3 CorsixTH/Lua/config_finder.lua
  5. +96 −85 CorsixTH/Lua/dialogs/bottom_panel.lua
  6. +7 −9 CorsixTH/Lua/dialogs/confirm_dialog.lua
  7. +8 −9 CorsixTH/Lua/dialogs/edit_room.lua
  8. +14 −5 CorsixTH/Lua/dialogs/fullscreen/drug_casebook.lua
  9. +12 −4 CorsixTH/Lua/dialogs/fullscreen/staff_management.lua
  10. +7 −9 CorsixTH/Lua/dialogs/furnish_corridor.lua
  11. +7 −9 CorsixTH/Lua/dialogs/hire_staff.lua
  12. +7 −9 CorsixTH/Lua/dialogs/information.lua
  13. +54 −33 CorsixTH/Lua/dialogs/menu.lua
  14. +9 −1 CorsixTH/Lua/dialogs/patient.lua
  15. +11 −3 CorsixTH/Lua/dialogs/place_objects.lua
  16. +2 −1 CorsixTH/Lua/dialogs/resizables/directory_browser.lua
  17. +1,086 −0 CorsixTH/Lua/dialogs/resizables/hotkey_assign.lua
  18. +249 −2 CorsixTH/Lua/dialogs/resizables/options.lua
  19. +79 −41 CorsixTH/Lua/game_ui.lua
  20. +0 −33 CorsixTH/Lua/key_mapping.txt
  21. +31 −31 CorsixTH/Lua/languages/brazilian_portuguese.lua
  22. +32 −32 CorsixTH/Lua/languages/czech.lua
  23. +27 −27 CorsixTH/Lua/languages/danish.lua
  24. +31 −31 CorsixTH/Lua/languages/dutch.lua
  25. +171 −32 CorsixTH/Lua/languages/english.lua
  26. +28 −28 CorsixTH/Lua/languages/finnish.lua
  27. +27 −27 CorsixTH/Lua/languages/french.lua
  28. +21 −21 CorsixTH/Lua/languages/german.lua
  29. +28 −28 CorsixTH/Lua/languages/hungarian.lua
  30. +27 −27 CorsixTH/Lua/languages/iberic_portuguese.lua
  31. +31 −31 CorsixTH/Lua/languages/italian.lua
  32. +29 −29 CorsixTH/Lua/languages/korean.lua
  33. +30 −30 CorsixTH/Lua/languages/norwegian.lua
  34. +29 −29 CorsixTH/Lua/languages/polish.lua
  35. +29 −29 CorsixTH/Lua/languages/russian.lua
  36. +29 −29 CorsixTH/Lua/languages/simplified_chinese.lua
  37. +31 −31 CorsixTH/Lua/languages/spanish.lua
  38. +24 −24 CorsixTH/Lua/languages/swedish.lua
  39. +28 −28 CorsixTH/Lua/languages/traditional_chinese.lua
  40. +1 −1 CorsixTH/Lua/run_debugger.lua
  41. +1 −1 CorsixTH/Lua/strings.lua
  42. +256 −82 CorsixTH/Lua/ui.lua
  43. +125 −37 CorsixTH/Lua/utility.lua
  44. +178 −0 CorsixTH/Lua/window.lua
  45. +15 −20 CorsixTH/Lua/world.lua
  46. +109 −0 CorsixTH/Luatest/spec/utility_spec.lua
@@ -26,6 +26,7 @@ globals = { -- Globals
"lfs", "list_to_set", "loadfile_envcall", "loadstring_envcall",
"permanent", "print_table", "rangeMapLookup", "rnc",
"strict_declare_global", "table_length", "unpermanent", "values",
"serialize","array_join","shallow_clone",

-- Game classes
"AIHospital", "AnimationManager", "App", "Audio",
@@ -54,7 +55,9 @@ globals = { -- Globals
"UIQueue", "UIQueuePopup", "UIResizable", "UIResearch",
"UIResolution", "UISaveGame", "UISaveMap", "UIStaff",
"UIStaffManagement", "UIStaffRise", "UITipOfTheDay", "UITownMap",
"UIUpdate", "UIWatch",
"UIUpdate", "UIWatch", "UIHotkeyAssign", "UIScrollSpeed",
"UIShiftScrollSpeed", "UIZoomSpeed", "UIHotkeyAssign_Panels",
"UIHotkeyAssign_storeRecallPos",

-- Actions
"AnswerCallAction", "CallCheckPointAction", "CheckWatchAction",
@@ -128,7 +128,8 @@ strict_declare_global "TheApp"
TheApp = App()
TheApp:setCommandLine(
"--bitmap-dir=" ..base_dir.. "Bitmap",
"--config-file=" .. corsixth.require("config_finder"),
"--config-file=" .. select(1, corsixth.require("config_finder")),
"--hotkeys-file=" .. select(3, corsixth.require("config_finder")),
-- If a command line option is given twice, the later one is used, hence
-- if the user gave one of the above, that will be used instead.
...
@@ -28,7 +28,7 @@ local runDebugger = corsixth.require("run_debugger")
-- Increment each time a savegame break would occur
-- and add compatibility code in afterLoad functions

local SAVEGAME_VERSION = 131
local SAVEGAME_VERSION = 132

class "App"

@@ -38,6 +38,7 @@ local App = _G["App"]
function App:App()
self.command_line = {}
self.config = {}
self.hotkeys = {}
self.runtime_config = {}
self.running = false
self.key_modifiers = {}
@@ -235,6 +236,16 @@ function App:init()
self:dumpStrings()
end

-- Load/setup hotkeys.
local hotkeys_path = self.command_line["hotkeys-file"] or "hotkeys.txt"
local hotkeys_chunk, hotkeys_err = loadfile_envcall(hotkeys_path)
if not hotkeys_chunk then
error(_S.hotkeys_file_err.file_err_01 .. hotkeys_path .. _S.hotkeys_file_err.file_err_02 .. hotkeys_err )
else
hotkeys_chunk(self.hotkeys)
end
self:fixHotkeys()

-- Load map before world
corsixth.require("map")

@@ -292,6 +303,7 @@ function App:init()
return true
end


-- Load main menu (which creates UI)
local function callback_after_movie()
self:loadMainMenu()
@@ -798,7 +810,7 @@ end

function App:fixConfig()
-- Fill in default values for things which don't exist
local _, config_defaults = corsixth.require("config_finder")
local config_defaults = select(2, corsixth.require("config_finder"))
for k, v in pairs(config_defaults) do
if self.config[k] == nil then
self.config[k] = v
@@ -899,6 +911,91 @@ function App:saveConfig()
fi:close()
end

function App:fixHotkeys()
-- Fill in default values for things which don't exist
local hotkeys_defaults = select(4, corsixth.require("config_finder"))

for k, v in pairs(hotkeys_defaults) do
if self.hotkeys[k] == nil then
self.hotkeys[k] = v
end
end

for key, value in pairs(self.hotkeys) do
-- Trim whitespace from beginning and end string values - it shouldn't be
-- there (at least in any current configuration options).
if type(value) == "string" then
if value:match("^[%s]") or value:match("[%s]$") then
self.hotkeys[key] = value:match("^[%s]*(.-)[%s]*$")
end
end
end
end

function App:saveHotkeys()
-- Load lines from config file
local fi = io.open(self.command_line["hotkeys-file"] or "hotkeys.txt", "r")
local lines = {}
local handled_ids = {}

if fi then
for line in fi:lines() do
lines[#lines + 1] = line
if not (string.find(line, "^%s*$") or string.find(line, "^%s*%-%-")) then -- empty lines or comments
-- Look for identifiers we want to save
local _, _, identifier, value = string.find(line, "^%s*([_%a][_%w]*)%s*=%s*(.-)%s*$")
if identifier then
local _, temp
-- Trim possible trailing comment from value
_, _, temp = string.find(value, "^(.-)%s*%-%-.*")
value = temp or value
-- Remove enclosing [[]], if necessary
_, _, temp = string.find(value, "^%[%[(.*)%]%]$")
value = temp or value

-- If identifier also exists in runtime options, compare their values and
-- replace the line, if needed
handled_ids[identifier] = true

if value ~= serialize(self.hotkeys[identifier]) then
local new_value = self.hotkeys[identifier]
if type(new_value) == "string" then
new_value = string.format("[[%s]]", new_value)
else
new_value = serialize(new_value)
end
lines[#lines] = string.format("%s = %s", identifier, new_value)
end
end
end
end
fi:close()
end

-- Append options that were not found
for identifier, value in pairs(self.hotkeys) do
if not handled_ids[identifier] then
if type(value) == "string" then
value = string.format("[[%s]]", value)
else
value = tostring(value)
end
lines[#lines + 1] = string.format("%s = %s", identifier, value)
end
end
-- Trim trailing newlines
while lines[#lines] == "" do
lines[#lines] = nil
end

fi = io.open(self.command_line["hotkeys-file"] or "hotkeys.txt", "w")
for _, line in ipairs(lines) do
fi:write(line .. "\n")
end

fi:close()
end

function App:run()
-- The application "main loop" is an SDL event loop written in C, which calls
-- a coroutine whenever an event occurs. Initially it may seem odd to involve
@@ -1420,7 +1517,6 @@ function App:afterLoad()
self.world:gameLog("Savegame version is " .. new .. " (" .. self:getVersion() ..
"), originally it was " .. first .. " (" .. self:getVersion(first) .. ")")
self.world:playLoadedEntitySounds()
return
elseif new > old then
self.world:gameLog("Savegame version changed from " .. old .. " (" .. self:getVersion(old) ..
") to " .. new .. " (" .. self:getVersion() ..
@@ -1448,8 +1544,8 @@ function App:afterLoad()
end

self.map:afterLoad(old, new)
self.world:afterLoad(old, new)
self.ui:afterLoad(old, new)
self.world:afterLoad(old, new)
end

function App:checkForUpdates()
Oops, something went wrong.

0 comments on commit 138aa5b

Please sign in to comment.