| 1 |
--[[ Copyright (c) 2009 Peter "Corsix" Cawley |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
--! The multi-purpose panel for launching dialogs / screens and dynamic information. |
| 22 |
class "UIBottomPanel" (Window) |
| 23 |
|
| 24 |
---@type UIBottomPanel |
| 25 |
local UIBottomPanel = _G["UIBottomPanel"] |
| 26 |
|
| 27 |
local MESSAGE_DOOR_FULLY_OPEN = 0 |
| 28 |
local MESSAGE_DOOR_FULLY_SHUT = 22 |
| 29 |
local FACTORY_ICON_WIDTH = 30 |
| 30 |
|
| 31 |
function UIBottomPanel:UIBottomPanel(ui) |
| 32 |
self:Window() |
| 33 |
|
| 34 |
local app = ui.app |
| 35 |
|
| 36 |
self.ui = ui |
| 37 |
self.world = app.world |
| 38 |
self.on_top = false |
| 39 |
self:setSize(640, 48) |
| 40 |
self:setDefaultPosition(0.5, -0.1) |
| 41 |
self:_initFonts(app.gfx) |
| 42 |
|
| 43 |
self.message_door = { |
| 44 |
closed_amount = MESSAGE_DOOR_FULLY_SHUT, |
| 45 |
next_action_delay = 0 |
| 46 |
} |
| 47 |
|
| 48 |
-- Visible fax panels on the left side of the bottom panel |
| 49 |
self.message_windows = {} |
| 50 |
|
| 51 |
-- Queued fax panels waiting to be shown |
| 52 |
self.message_queue = {} |
| 53 |
|
| 54 |
self.default_button_sound = "selectx.wav" |
| 55 |
self.countdown = 0 |
| 56 |
|
| 57 |
self:drawPanels() |
| 58 |
|
| 59 |
self:registerKeyHandlers() |
| 60 |
end |
| 61 |
|
| 62 |
function UIBottomPanel:machineMenuButtonExists() |
| 63 |
local config = self.ui.app.config |
| 64 |
-- Minimal screen width for a case where machine menu button exists is 676 pixels |
| 65 |
if config.width / TheApp.config.ui_scale > 676 and config.machine_menu_button then |
| 66 |
return true |
| 67 |
end |
| 68 |
|
| 69 |
return false |
| 70 |
end |
| 71 |
|
| 72 |
function UIBottomPanel:onChangeResolution() |
| 73 |
Window.onChangeResolution(self) |
| 74 |
self:removeAllPanels() |
| 75 |
self:drawPanels() |
| 76 |
end |
| 77 |
|
| 78 |
function UIBottomPanel:drawPanels() |
| 79 |
self.bank_button = self:addPanel( 1, 0, 0):makeToggleButton(6, 6, 35, 36, 2, self.dialogBankManager, nil, self.dialogBankStats):setTooltip(_S.tooltip.toolbar.bank_button) |
| 80 |
self:addPanel( 3, 40, 0) -- Background for balance, rep and date |
| 81 |
self:addPanel( 4, 206, 0):makeButton(6, 6, 35, 36, 5, self.dialogBuildRoom):setTooltip(_S.tooltip.toolbar.rooms) |
| 82 |
self:addPanel( 6, 248, 0):makeButton(1, 6, 35, 36, 7, self.dialogFurnishCorridor):setTooltip(_S.tooltip.toolbar.objects) |
| 83 |
self:addPanel( 8, 285, 0):makeButton(1, 6, 35, 36, 9, self.editRoom) |
| 84 |
:setSound():setTooltip(_S.tooltip.toolbar.edit) -- Remove default sound for this button |
| 85 |
self:addPanel(10, 322, 0):makeButton(1, 6, 35, 36, 11, self.dialogHireStaff):setTooltip(_S.tooltip.toolbar.hire) |
| 86 |
-- The dynamic info bar |
| 87 |
self:addPanel(12, 364, 0) |
| 88 |
|
| 89 |
-- If there is a machine menu button, then lets adjust bottom panel width so it can fit |
| 90 |
if self:machineMenuButtonExists() then |
| 91 |
self.width = 676 |
| 92 |
for x = 377, 660, 10 do |
| 93 |
self:addPanel(13, x, 0) |
| 94 |
end |
| 95 |
self:addPanel(14, 665, 0) |
| 96 |
|
| 97 |
self.offset = 38 |
| 98 |
else |
| 99 |
self.width = 640 |
| 100 |
for x = 377, 630, 10 do |
| 101 |
self:addPanel(13, x, 0) |
| 102 |
end |
| 103 |
self:addPanel(14, 627, 0) |
| 104 |
|
| 105 |
self.offset = 0 |
| 106 |
end |
| 107 |
|
| 108 |
-- Buttons that are shown instead of the dynamic info bar when hovering over it. |
| 109 |
local panels = {} |
| 110 |
local buttons = {} |
| 111 |
local app = self.ui.app |
| 112 |
panels[1] = self:addPanel(15, 364, 0) -- Staff management button |
| 113 |
buttons[1] = panels[1]:makeToggleButton(6, 6, 35, 36, 16, self.dialogStaffManagement):setTooltip(_S.tooltip.toolbar.staff_list) |
| 114 |
if self:machineMenuButtonExists() then |
| 115 |
-- Sprites for machine menu button doesn't exist in original game. Let's import them from aux_ui.dat and draw |
| 116 |
local aux_sprites = app.gfx:loadSpriteTable("Bitmap", "aux_ui", true) |
| 117 |
self:addPanel(0, 407, 0):makeToggleButton(2, 6, 36, 36, 0, self.dialogMachineMenu) |
| 118 |
:setSound() -- override |
| 119 |
:setTooltip(_S.tooltip.toolbar.machine_menu) |
| 120 |
.panel_for_sprite.custom_draw = --[[persistable:machine_menu_buttons]] function(panel, canvas, x, y) |
| 121 |
local s = TheApp.config.ui_scale |
| 122 |
x = x + panel.x * s |
| 123 |
y = y + panel.y * s |
| 124 |
panel.window.panel_sprites:draw(canvas, panel.sprite_index, x, y, { scaleFactor = s }) |
| 125 |
local btn = panel.window.active_button |
| 126 |
if panels[1].visible then |
| 127 |
local w = self.ui:getWindow(UIMachineMenu) |
| 128 |
if w or btn and btn.panel_for_sprite == panel and btn.active then |
| 129 |
aux_sprites:draw(canvas, 23, x, y, { scaleFactor = s }) |
| 130 |
else |
| 131 |
aux_sprites:draw(canvas, 22, x, y, { scaleFactor = s }) |
| 132 |
end |
| 133 |
end |
| 134 |
end |
| 135 |
end |
| 136 |
panels[2] = self:addPanel(17, 407 + self.offset, 0) -- Town map button |
| 137 |
buttons[2] = panels[2]:makeToggleButton(1, 6, 35, 36, 18, self.dialogTownMap):setTooltip(_S.tooltip.toolbar.town_map) |
| 138 |
panels[3] = self:addPanel(19, 445 + self.offset, 0) -- Casebook button |
| 139 |
buttons[3] = panels[3]:makeToggleButton(1, 6, 35, 36, 20, self.dialogDrugCasebook):setTooltip(_S.tooltip.toolbar.casebook) |
| 140 |
panels[4] = self:addPanel(21, 483 + self.offset, 0) -- Research button |
| 141 |
buttons[4] = panels[4]:makeToggleButton(1, 6, 35, 36, 22, self.dialogResearch) |
| 142 |
:setSound():setTooltip(_S.tooltip.toolbar.research) -- Remove default sound for this button |
| 143 |
panels[5] = self:addPanel(23, 521 + self.offset, 0) -- Status button |
| 144 |
buttons[5] = panels[5]:makeToggleButton(1, 6, 35, 36, 24, self.dialogStatus):setTooltip(_S.tooltip.toolbar.status) |
| 145 |
panels[6] = self:addPanel(25, 559 + self.offset, 0) -- Charts button |
| 146 |
buttons[6] = panels[6]:makeToggleButton(1, 6, 35, 36, 26, self.dialogCharts):setTooltip(_S.tooltip.toolbar.charts) |
| 147 |
panels[7] = self:addPanel(27, 597 + self.offset, 0) -- Policy button |
| 148 |
buttons[7] = panels[7]:makeToggleButton(1, 6, 35, 36, 28, self.dialogPolicy):setTooltip(_S.tooltip.toolbar.policy) |
| 149 |
for _, panel in ipairs(panels) do |
| 150 |
panel.visible = false |
| 151 |
end |
| 152 |
self.additional_panels = panels |
| 153 |
self.additional_buttons = buttons |
| 154 |
|
| 155 |
self:makeTooltip(_S.tooltip.toolbar.balance, 41, 5, 137, 28) |
| 156 |
self:makeTooltip(_S.tooltip.toolbar.date, 140, 5, 200, 42) |
| 157 |
self:makeDynamicTooltip(--[[persistable:reputation_tooltip]] function() |
| 158 |
return _S.tooltip.toolbar.reputation .. " (" .. self.ui.hospital.reputation .. ")" |
| 159 |
end, 41, 30, 137, 42) |
| 160 |
|
| 161 |
end |
| 162 |
|
| 163 |
function UIBottomPanel:_initFonts(gfx) |
| 164 |
local date_label_color = { red = 175, green = 50, blue = 15 } |
| 165 |
local pause_label_color = { red = 35, green = 138, blue = 173 } |
| 166 |
self.panel_sprites = gfx:loadSpriteTable("Data", "Panel02V", true) |
| 167 |
self.money_font = gfx:loadFontAndSpriteTable("QData", "Font05V", nil, nil, { apply_ui_scale = true }) |
| 168 |
self.date_font = gfx:loadFontAndSpriteTable("QData", "Font16V", nil, nil, {ttf_color = date_label_color, apply_ui_scale = true}) |
| 169 |
self.white_font = gfx:loadFontAndSpriteTable("QData", "Font01V", nil, nil, {y_sep = -2, apply_ui_scale = true}) |
| 170 |
self.pause_font = gfx:loadFontAndSpriteTable("QData", "Font124V", nil, nil, {ttf_color = pause_label_color, apply_ui_scale = true}) |
| 171 |
end |
| 172 |
|
| 173 |
function UIBottomPanel:registerKeyHandlers() |
| 174 |
local ui = self.ui |
| 175 |
local buttons = self.additional_buttons |
| 176 |
|
| 177 |
-- The bottom panel hotkeys. |
| 178 |
ui:addKeyHandler("ingame_panel_bankManager", self.bank_button, self.bank_button.handleClick, "left") -- bank manager |
| 179 |
ui:addKeyHandler("ingame_panel_bankStats", self.bank_button, self.bank_button.handleClick, "right") -- bank stats |
| 180 |
ui:addKeyHandler("ingame_panel_staffManage", buttons[1], buttons[1].handleClick, "left") -- staff management |
| 181 |
ui:addKeyHandler("ingame_panel_townMap", buttons[2], buttons[2].handleClick, "left") -- town map |
| 182 |
ui:addKeyHandler("ingame_panel_casebook", buttons[3], buttons[3].handleClick, "left") -- casebook |
| 183 |
ui:addKeyHandler("ingame_panel_research", buttons[4], buttons[4].handleClick, "left") -- research |
| 184 |
ui:addKeyHandler("ingame_panel_status", buttons[5], buttons[5].handleClick, "left") -- status |
| 185 |
ui:addKeyHandler("ingame_panel_charts", buttons[6], buttons[6].handleClick, "left") -- charts |
| 186 |
ui:addKeyHandler("ingame_panel_policy", buttons[7], buttons[7].handleClick, "left") -- policy |
| 187 |
ui:addKeyHandler("ingame_panel_machineMenu", self, self.dialogMachineMenu) -- machine menu |
| 188 |
|
| 189 |
-- Hotkeys for building a room, furnishing the corridor, editing a room, and hiring staff. |
| 190 |
ui:addKeyHandler("ingame_panel_buildRoom", self, self.dialogBuildRoom) -- Build room. |
| 191 |
ui:addKeyHandler("ingame_panel_furnishCorridor", self, self.dialogFurnishCorridor) -- Furnish corridor. |
| 192 |
ui:addKeyHandler("ingame_panel_editRoom", self, self.editRoom) -- Edit room. |
| 193 |
ui:addKeyHandler("ingame_panel_hireStaff", self, self.dialogHireStaff) -- Hire staff. |
| 194 |
|
| 195 |
-- Alternate keyboard shortcuts for some of the fullscreen windows. |
| 196 |
ui:addKeyHandler("ingame_panel_map_alt", buttons[2], buttons[2].handleClick, "left") -- town map |
| 197 |
ui:addKeyHandler("ingame_panel_research_alt", buttons[4], buttons[4].handleClick, "left") -- research |
| 198 |
local config = ui.app.config |
| 199 |
if not config.volume_opens_casebook then |
| 200 |
ui:addKeyHandler("ingame_panel_casebook_alt", buttons[3], buttons[3].handleClick, "left") -- casebook |
| 201 |
else |
| 202 |
ui:addKeyHandler("ingame_panel_casebook_alt02", buttons[3], buttons[3].handleClick, "left") -- casebook |
| 203 |
end |
| 204 |
ui:addKeyHandler("ingame_loadMenu", self, self.openLoad) -- load saved game menu |
| 205 |
ui:addKeyHandler("ingame_saveMenu", self, self.openSave) -- load create save menu |
| 206 |
ui:addKeyHandler("ingame_restartLevel", self, self.restart) -- restart the level |
| 207 |
ui:addKeyHandler("ingame_quitLevel", self, self.quit) -- quit the game and return to main menu |
| 208 |
ui:addKeyHandler("ingame_quickSave", self, self.quickSave) -- quick save |
| 209 |
ui:addKeyHandler("ingame_quickLoad", self, self.quickLoad) -- load last quick save |
| 210 |
|
| 211 |
-- misc. keyhandlers |
| 212 |
ui:addKeyHandler("ingame_openFirstMessage", self, self.openFirstMessage) -- message |
| 213 |
ui:addKeyHandler("ingame_toggleInfo", self, self.toggleInformation) -- information when you first build |
| 214 |
ui:addKeyHandler("ingame_jukebox", self, self.openJukebox) -- jukebox |
| 215 |
ui:addKeyHandler("ingame_panel_adviserHistory", self, self.dialogAdviserHistory) -- adviser history |
| 216 |
end |
| 217 |
|
| 218 |
function UIBottomPanel:openJukebox() |
| 219 |
if self.ui.app.config.audio then |
| 220 |
self.ui:addWindow(UIJukebox(self.ui.app)) |
| 221 |
end |
| 222 |
end |
| 223 |
|
| 224 |
function UIBottomPanel:openSave() |
| 225 |
self.ui:addWindow(UISaveGame(self.ui)) |
| 226 |
end |
| 227 |
|
| 228 |
function UIBottomPanel:openLoad() |
| 229 |
self.ui:addWindow(UILoadGame(self.ui, "game")) |
| 230 |
end |
| 231 |
|
| 232 |
function UIBottomPanel:quickSave() |
| 233 |
self.ui.app:quickSave() |
| 234 |
end |
| 235 |
|
| 236 |
function UIBottomPanel:quickLoad() |
| 237 |
self.ui.app:quickLoad() |
| 238 |
end |
| 239 |
|
| 240 |
function UIBottomPanel:restart() |
| 241 |
self.ui.app:restart() |
| 242 |
end |
| 243 |
|
| 244 |
function UIBottomPanel:quit() |
| 245 |
self.ui:quit() |
| 246 |
end |
| 247 |
|
| 248 |
function UIBottomPanel:draw(canvas, x, y) |
| 249 |
Window.draw(self, canvas, x, y) |
| 250 |
|
| 251 |
-- Draw balance with temporary offset in unicode languages |
| 252 |
local s = TheApp.config.ui_scale |
| 253 |
x, y = x + self.x * s, y + self.y * s |
| 254 |
local offset_x, offset_y = 0, 0 |
| 255 |
if self.ui.app.gfx:drawNumbersFromUnicode() then |
| 256 |
offset_x = 4 |
| 257 |
offset_y = 2 |
| 258 |
end |
| 259 |
local balance = math.floor(self.ui.hospital.balance) |
| 260 |
local i = 7 - tostring(balance):len() -- Indent balances under 100k |
| 261 |
for digit in ("%7i"):format(balance):gmatch("[-0-9]") do |
| 262 |
self.money_font:draw(canvas, digit, x + offset_x * s + 44 * s + i * 13 * s, y + offset_y * s + 9 * s) |
| 263 |
i = i + 1 |
| 264 |
end |
| 265 |
local game_date = self.world:date() |
| 266 |
local month, day = game_date:monthOfYear(), game_date:dayOfMonth() |
| 267 |
self.date_font:draw(canvas, _S.date_format.daymonth:format(day, month), x + 140 * s, y + 20 * s, 60 * s, 0) |
| 268 |
|
| 269 |
-- Draw possible information in the dynamic info bar |
| 270 |
if not self.additional_panels[1].visible then |
| 271 |
self:drawDynamicInfo(canvas, x + 364 * s, y) |
| 272 |
end |
| 273 |
|
| 274 |
-- Draw the fax door if it is not fully open |
| 275 |
if self.message_door.closed_amount ~= MESSAGE_DOOR_FULLY_OPEN then |
| 276 |
self.panel_sprites:draw(canvas, 40, x + 177 * s, y + 1, { scaleFactor = s }) |
| 277 |
|
| 278 |
for dx = 0, self.message_door.closed_amount do |
| 279 |
self.panel_sprites:draw(canvas, 41, x + 179 * s + dx * s, y + 1 * s, { scaleFactor = s }) |
| 280 |
end |
| 281 |
|
| 282 |
if self.message_door.closed_amount == MESSAGE_DOOR_FULLY_SHUT then |
| 283 |
self.panel_sprites:draw(canvas, 42, x + 201 * s, y + 1 * s, { scaleFactor = s }) |
| 284 |
end |
| 285 |
end |
| 286 |
|
| 287 |
self:drawReputationMeter(canvas, x + 55 * s, y + 35 * s) |
| 288 |
end |
| 289 |
|
| 290 |
function UIBottomPanel:setPosition(x, y) |
| 291 |
-- Lock to bottom of screen |
| 292 |
return Window.setPosition(self, x, -0.1) |
| 293 |
end |
| 294 |
|
| 295 |
-- Draws the hospital reputation meter on canvas. |
| 296 |
-- x_left is the leftmost x-coordinate of the reputation meter |
| 297 |
-- y is the y-coordinate of the reputation meter |
| 298 |
function UIBottomPanel:drawReputationMeter(canvas, x_left, y) |
| 299 |
local s = TheApp.config.ui_scale |
| 300 |
local width = 65 * s -- Reputation meter width |
| 301 |
local step = width / (self.ui.hospital.reputation_max - self.ui.hospital.reputation_min) |
| 302 |
self.panel_sprites:draw(canvas, 36, x_left + math.floor(step * (self.ui.hospital.reputation - self.ui.hospital.reputation_min)), y, { scaleFactor = s }) |
| 303 |
end |
| 304 |
|
| 305 |
--! Adds dynamic text to the bottom panel based on cursor position |
| 306 |
--!param canvas |
| 307 |
--!param x (num) coordinate |
| 308 |
--!param y (num) coordinate |
| 309 |
function UIBottomPanel:drawDynamicInfo(canvas, x, y) |
| 310 |
local s = TheApp.config.ui_scale |
| 311 |
if self.world:isCurrentSpeed("Pause") then |
| 312 |
if not self.world.user_actions_allowed then |
| 313 |
-- Original pause behaviour, show pause text |
| 314 |
self.pause_font:drawWrapped(canvas, _S.misc.pause, x + 10 * s, y + 14 * s, 255 * s, "center") |
| 315 |
return |
| 316 |
elseif not (self.dynamic_info and self.dynamic_info["text"]) then |
| 317 |
-- User allows editing while paused, only show pause text where dynamic text not present |
| 318 |
self.pause_font:drawWrapped(canvas, _S.misc.pause, x + 10 * s, y + 14 * s, 255 * s, "center") |
| 319 |
return |
| 320 |
end |
| 321 |
end |
| 322 |
|
| 323 |
if not (self.dynamic_info and self.dynamic_info["text"]) then |
| 324 |
return |
| 325 |
end |
| 326 |
|
| 327 |
local info = self.dynamic_info |
| 328 |
local font = self.white_font |
| 329 |
|
| 330 |
local dynamic_info_panel_x = 364 |
| 331 |
local progress_bar_r_offset = 11 |
| 332 |
local progress_bar_width = 100 |
| 333 |
|
| 334 |
local w = x + (self.width - dynamic_info_panel_x) * s |
| 335 |
|
| 336 |
for i, text in ipairs(info["text"]) do |
| 337 |
font:drawWrapped(canvas, text, x + 20 * s, y + 10 * i * s, 240 * s) |
| 338 |
if i == #info["text"] and info["progress"] then |
| 339 |
local white = canvas:mapRGB(255, 255, 255) |
| 340 |
local black = canvas:mapRGB(0, 0, 0) |
| 341 |
local orange = canvas:mapRGB(221, 83, 0) |
| 342 |
canvas:drawRect(white, w - (progress_bar_width + progress_bar_r_offset + 1) * s, y + 10 * i * s, 100 * s, 10 * s) |
| 343 |
canvas:drawRect(black, w - (progress_bar_width + progress_bar_r_offset) * s, y + s + 10 * i * s, 98 * s, 8 * s) |
| 344 |
canvas:drawRect(orange, w - (progress_bar_width + progress_bar_r_offset) * s, y + s + 10 * i * s, math.floor(98 * info["progress"] * s), 8 * s) |
| 345 |
if info["dividers"] then |
| 346 |
for _, value in ipairs(info["dividers"]) do |
| 347 |
canvas:drawRect(white, w - (progress_bar_width+progress_bar_r_offset) * s + math.floor(value * 100 * s), y + 10 * i * s, s, 10 * s) |
| 348 |
end |
| 349 |
end |
| 350 |
end |
| 351 |
end |
| 352 |
end |
| 353 |
|
| 354 |
--! Update the information shown in the information box on the panel. |
| 355 |
--! |
| 356 |
--! If the info is nil then a cooldown timer is used before removing the |
| 357 |
--! information from the display. |
| 358 |
--! |
| 359 |
--!param info (table) A table containing the information to display. The text |
| 360 |
--! key is required and contains an array of lines to show. An optional |
| 361 |
--! progress key may be given to draw a progress bar, following the text and |
| 362 |
--! and an array of dividers may be provided to draw extra vertical lines in |
| 363 |
--! the progress bar. |
| 364 |
--! |
| 365 |
--! info = { |
| 366 |
--! text: { "He's not the saviour", "He's very naughty boy" }, |
| 367 |
--! progress: 50, |
| 368 |
--! dividers: { 25, 50, 75 } |
| 369 |
--! } |
| 370 |
function UIBottomPanel:setDynamicInfo(info) |
| 371 |
if info and not info["text"] then |
| 372 |
self.world:gameLog("") |
| 373 |
self.world:gameLog("Dynamic info is missing text!") |
| 374 |
self.world:gameLog("Please report this issue including the call stack below.") |
| 375 |
self.world:gameLog(debug.traceback()) |
| 376 |
|
| 377 |
return |
| 378 |
end |
| 379 |
|
| 380 |
if not info then |
| 381 |
-- dynamic info hide countdown value. 25 = ~1 second |
| 382 |
self.countdown = 25 |
| 383 |
else |
| 384 |
self.countdown = nil |
| 385 |
self.dynamic_info = info |
| 386 |
end |
| 387 |
end |
| 388 |
|
| 389 |
function UIBottomPanel:onMouseMove(x, y, dx, dy) |
| 390 |
local repaint = Window.onMouseMove(self, x, y, dx, dy) |
| 391 |
if self:showAdditionalButtons(x, y) then |
| 392 |
repaint = true |
| 393 |
end |
| 394 |
return repaint |
| 395 |
end |
| 396 |
|
| 397 |
function UIBottomPanel:showAdditionalButtons(x, y) |
| 398 |
local panels = self.additional_panels |
| 399 |
if self:hitTest(x, y) then -- Inside the panel |
| 400 |
if not panels[1].visible then -- Are the buttons already shown? |
| 401 |
for _, panel in ipairs(panels) do |
| 402 |
panel.visible = true |
| 403 |
end |
| 404 |
end |
| 405 |
else -- Outside the rectangle |
| 406 |
if panels[1].visible then -- Are the buttons already invisible? |
| 407 |
for _, panel in ipairs(panels) do |
| 408 |
panel.visible = false |
| 409 |
end |
| 410 |
end |
| 411 |
end |
| 412 |
end |
| 413 |
|
| 414 |
function UIBottomPanel:hitTest(x, y, x_offset) |
| 415 |
local s = TheApp.config.ui_scale |
| 416 |
return x >= (x_offset and x_offset * s or 0) and y >= 0 and x < self.width * s and y < self.height * s |
| 417 |
end |
| 418 |
|
| 419 |
--! Queue a fax notification message to appear. |
| 420 |
--! The arguments specify a message, which is added to a FIFO queue, and will |
| 421 |
-- appear on screen once there is space. |
| 422 |
--!param type (string) The type of message, can be: "emergency", "epidemy", "personality", "information", "disease", "report" or "strike" |
| 423 |
--!param message (table or number) If type == "strike", the amount of pay rise. Else a list of texts to display, including a "choices" table with choices. See below for structure. |
| 424 |
--!param owner (object or nil) Some messages are related to one staff or patient or epidemic. Otherwise this is nil. |
| 425 |
--!param timeout (number or nil) If given, the message will expire after that many world ticks and be removed. |
| 426 |
--!param default_choice (number or nil) If given, the choice with this number will be executed on expiration of the message. |
| 427 |
--!param callback (function or nil) If given, it will be called when the message is closed. |
| 428 |
--! Structure of message (except strike): |
| 429 |
-- message = { |
| 430 |
-- { text = "first line of text", offset (integer, optional) } |
| 431 |
-- { text = "second line of text", offset (integer, optional) } |
| 432 |
-- ... |
| 433 |
-- choices = { |
| 434 |
-- { text = "first choice", choice = "choice_type", enabled = true or false (optional, defaults to true) } |
| 435 |
-- ... |
| 436 |
-- } |
| 437 |
-- } |
| 438 |
function UIBottomPanel:queueMessage(type, message, owner, timeout, default_choice, callback) |
| 439 |
-- Show a helpful message if there has been no messages before - only in campaign though |
| 440 |
if not self.ui.hospital.message_popup and tonumber(self.world.map.level_number) then |
| 441 |
self.world.ui.adviser:say(_A.information.fax_received) |
| 442 |
self.ui.hospital.message_popup = true |
| 443 |
end |
| 444 |
|
| 445 |
local --[[persistable:bottom_panel_message_window_close]] function onClose(this_icon) |
| 446 |
local this_icon_index |
| 447 |
for i, icon in ipairs(self.message_windows) do |
| 448 |
-- If icon position found |
| 449 |
if this_icon_index ~= nil then |
| 450 |
-- Shift all icons that are on the right to the left |
| 451 |
-- The '_factoryIconWitdh()' call is used for compatibility with 0.69 saves and older |
| 452 |
-- where FACTORY_ICON_WIDTH was not yet declared when the closure was created. |
| 453 |
icon:setXLimit(1 + (i - 2) * self._factoryIconWitdh()) |
| 454 |
elseif icon == this_icon then |
| 455 |
this_icon_index = i |
| 456 |
end |
| 457 |
end |
| 458 |
if this_icon_index then |
| 459 |
table.remove(self.message_windows, this_icon_index) |
| 460 |
end |
| 461 |
self:deleteMessage(nil, this_icon) |
| 462 |
end |
| 463 |
|
| 464 |
local message_info = { |
| 465 |
type = type, |
| 466 |
message = message, |
| 467 |
owner = owner, |
| 468 |
timeout = timeout, |
| 469 |
default_choice = default_choice, |
| 470 |
callback = callback, |
| 471 |
} |
| 472 |
|
| 473 |
if self:canQueueFax(message_info) then |
| 474 |
self.message_queue[#self.message_queue + 1] = message_info |
| 475 |
-- Create the drawer message icon, note this does not show it to the player on creation. |
| 476 |
local drawer_icon = UIMessage(self.ui, 175, nil, |
| 477 |
onClose, message_info.type, message_info.message, message_info.owner, |
| 478 |
message_info.timeout, message_info.default_choice, message_info.callback) |
| 479 |
message_info["drawer_icon"] = drawer_icon |
| 480 |
-- Сreate reference to message in owner |
| 481 |
if owner then |
| 482 |
owner.message = message |
| 483 |
end |
| 484 |
else |
| 485 |
self:cancelFax(message_info.type) |
| 486 |
end |
| 487 |
end |
| 488 |
|
| 489 |
function UIBottomPanel:_factoryIconWitdh() |
| 490 |
return FACTORY_ICON_WIDTH |
| 491 |
end |
| 492 |
|
| 493 |
--[[ A fax can be queued if the event the fax causes does not affect |
| 494 |
an event caused by any other fax that is queued. i.e both emergency |
| 495 |
and epidemics use the timer, so both faxes cannot appear at the same time. |
| 496 |
@param fax (table) the fax we want to determine if can be queued. |
| 497 |
@return true if fax can be queued, false otherwise (boolean) ]] |
| 498 |
function UIBottomPanel:canQueueFax(fax) |
| 499 |
--[[ Determine if fax of a particular type is queued either in the |
| 500 |
message queue or the message window (ui) |
| 501 |
@param fax_type (string) the fax type to check if any queued |
| 502 |
@return true if any of fax_type is queued false otherwise (boolean) ]] |
| 503 |
local function isFaxTypeQueued(fax_type) |
| 504 |
-- Check the queued messages |
| 505 |
for _, fax_msg in ipairs(self.message_queue) do |
| 506 |
if fax_msg.type == fax_type then |
| 507 |
return true |
| 508 |
end |
| 509 |
end |
| 510 |
-- Then the messages displayed on the bottom bar |
| 511 |
for _, fax_msg in ipairs(self.message_windows) do |
| 512 |
if fax_msg.type == fax_type then |
| 513 |
return true |
| 514 |
end |
| 515 |
end |
| 516 |
return false |
| 517 |
end |
| 518 |
|
| 519 |
if fax.type == "epidemy" then |
| 520 |
if isFaxTypeQueued("emergency") then |
| 521 |
return false |
| 522 |
end |
| 523 |
elseif fax.type == "emergency" then |
| 524 |
if isFaxTypeQueued("epidemy") then |
| 525 |
return false |
| 526 |
end |
| 527 |
end |
| 528 |
return true |
| 529 |
end |
| 530 |
|
| 531 |
--[[ Cancels a fax of a particular type currently only "emergency" and "epidemy" |
| 532 |
Handles the cancelling of the event which the fax pertains to. |
| 533 |
@param fax_type (string) type of fax event to be cancelled]] |
| 534 |
function UIBottomPanel:cancelFax(fax_type) |
| 535 |
local hospital = self.ui.hospital |
| 536 |
if fax_type == "epidemy" then |
| 537 |
hospital.epidemic:clearAllInfectedPatients() |
| 538 |
hospital.epidemic = nil |
| 539 |
elseif fax_type == "emergency" then |
| 540 |
self.world:nextEmergency() |
| 541 |
end |
| 542 |
end |
| 543 |
|
| 544 |
-- Opens the last available message. Currently used to open the level completed message. |
| 545 |
function UIBottomPanel:openLastMessage() |
| 546 |
if #self.message_queue > 0 then |
| 547 |
self:_showMessageIcon(#self.message_queue) |
| 548 |
end |
| 549 |
self.message_windows[#self.message_windows]:openMessage() |
| 550 |
end |
| 551 |
|
| 552 |
-- Return the index of the first fax message in the queue that is suitable to be |
| 553 |
-- shown, and nil if there are none. A message is suitable to be shown if there |
| 554 |
-- are less than 5 currently shown messages, no message of the same type is |
| 555 |
-- already shown. |
| 556 |
function UIBottomPanel:_findMessageToShow() |
| 557 |
if #self.message_windows >= 5 then |
| 558 |
return nil |
| 559 |
end |
| 560 |
|
| 561 |
local shown_types = {} |
| 562 |
for _, fax_msg in ipairs(self.message_windows) do |
| 563 |
shown_types[fax_msg.type] = true |
| 564 |
end |
| 565 |
|
| 566 |
for i, fax_msg in ipairs(self.message_queue) do |
| 567 |
if not shown_types[fax_msg.type] then |
| 568 |
return i |
| 569 |
end |
| 570 |
end |
| 571 |
|
| 572 |
return nil |
| 573 |
end |
| 574 |
|
| 575 |
-- Opens the first available message in the list of message_windows. |
| 576 |
function UIBottomPanel:openFirstMessage() |
| 577 |
if #self.message_windows > 0 then |
| 578 |
self.message_windows[1]:openMessage() |
| 579 |
end |
| 580 |
end |
| 581 |
|
| 582 |
--! Removes a message from the message queue (for example if a room is built before the player |
| 583 |
-- says what to do with the patient. |
| 584 |
--!param owner (object) optional message owner |
| 585 |
--!param icon (object) optional drawer icon object |
| 586 |
--!return (boolean) true if message was removed |
| 587 |
function UIBottomPanel:deleteMessage(owner, icon) |
| 588 |
assert(owner or icon, "Both owner and icon are nil!") |
| 589 |
-- A message can only ever exist in either the message queue or in message windows. Once it |
| 590 |
-- is found, we don't need to check the other. |
| 591 |
for i, msg_info in ipairs(self.message_queue) do |
| 592 |
if (owner and msg_info.owner == owner) or |
| 593 |
(icon and msg_info.drawer_icon == icon) then |
| 594 |
table.remove(self.message_queue, i) |
| 595 |
|
| 596 |
-- TODO: restructure message_queue to contain UIMessage objects already, |
| 597 |
-- so this special handling isn't required. |
| 598 |
msg_info.drawer_icon.onClose = nil |
| 599 |
msg_info.drawer_icon = nil |
| 600 |
|
| 601 |
if msg_info.owner then |
| 602 |
msg_info.owner.message = nil |
| 603 |
end |
| 604 |
return true |
| 605 |
end |
| 606 |
end |
| 607 |
|
| 608 |
for _, drawer_icon in ipairs(self.message_windows) do |
| 609 |
if (owner and drawer_icon.owner == owner) or (icon and drawer_icon == icon) then |
| 610 |
drawer_icon:removeMessage() |
| 611 |
return true |
| 612 |
end |
| 613 |
end |
| 614 |
return false |
| 615 |
end |
| 616 |
|
| 617 |
--! Pop the message with the given index from the message queue and turn it into |
| 618 |
-- an actual message window; if no index is provided the first suitable message |
| 619 |
-- in the queue is popped. |
| 620 |
--!param index (integer|nil) the index in the message_queue to pop |
| 621 |
function UIBottomPanel:_showMessageIcon(index) |
| 622 |
if not index then |
| 623 |
index = self:_findMessageToShow() |
| 624 |
end |
| 625 |
local message_windows = self.message_windows |
| 626 |
local message_info = index and self.message_queue[index] |
| 627 |
if not message_info then |
| 628 |
return |
| 629 |
end |
| 630 |
local drawer_icon = message_info.drawer_icon |
| 631 |
drawer_icon:setXLimit(1 + #message_windows * FACTORY_ICON_WIDTH) |
| 632 |
message_windows[#message_windows + 1] = drawer_icon |
| 633 |
self:addWindow(drawer_icon) |
| 634 |
self.ui:playSound("NewFax.wav") |
| 635 |
table.remove(self.message_queue, index) -- Delete element of the queue |
| 636 |
end |
| 637 |
|
| 638 |
function UIBottomPanel:onTick() |
| 639 |
-- The dynamic info bar is there a while longer when hovering an entity has stopped |
| 640 |
if self.countdown then |
| 641 |
if self.countdown < 1 then |
| 642 |
self.dynamic_info = nil |
| 643 |
-- If there is no info to display, and the app is tracking FPS, show that |
| 644 |
local fps = self.ui.app:getFPS() |
| 645 |
if fps then |
| 646 |
self.dynamic_info = {text = { |
| 647 |
("FPS: %i"):format(math.floor(fps + 0.5) or 0), |
| 648 |
("Lua GC: %.1f Kb"):format(collectgarbage("count") or 0), |
| 649 |
("Entities: %i"):format(#self.ui.app.world.entities or 0), |
| 650 |
}} |
| 651 |
self.countdown = 1 |
| 652 |
end |
| 653 |
else |
| 654 |
self.countdown = self.countdown - 1 |
| 655 |
end |
| 656 |
end |
| 657 |
|
| 658 |
self:_messageDoorTick() |
| 659 |
|
| 660 |
Window.onTick(self) |
| 661 |
end |
| 662 |
|
| 663 |
function UIBottomPanel:_messageDoorTick() |
| 664 |
if self.message_door.next_action_delay > 0 then |
| 665 |
self.message_door.next_action_delay = self.message_door.next_action_delay - 1 |
| 666 |
return |
| 667 |
end |
| 668 |
|
| 669 |
local msg_to_show = self:_findMessageToShow() |
| 670 |
|
| 671 |
if msg_to_show and self.message_door.closed_amount == MESSAGE_DOOR_FULLY_OPEN then |
| 672 |
self:_showMessageIcon() |
| 673 |
self.message_door.next_action_delay = 9 |
| 674 |
return |
| 675 |
end |
| 676 |
|
| 677 |
if msg_to_show and self.message_door.closed_amount > MESSAGE_DOOR_FULLY_OPEN then |
| 678 |
self.message_door.closed_amount = self.message_door.closed_amount - 1 |
| 679 |
elseif not msg_to_show and self.message_door.closed_amount < MESSAGE_DOOR_FULLY_SHUT then |
| 680 |
self.message_door.closed_amount = self.message_door.closed_amount + 1 |
| 681 |
end |
| 682 |
end |
| 683 |
|
| 684 |
function UIBottomPanel:dialogBankManager(enable) |
| 685 |
self:dialogBankCommon(enable) |
| 686 |
end |
| 687 |
|
| 688 |
function UIBottomPanel:dialogBankStats(enable) |
| 689 |
self:dialogBankCommon(enable, true) |
| 690 |
end |
| 691 |
|
| 692 |
function UIBottomPanel:dialogBankCommon(enable, stats) |
| 693 |
if not self.world.user_actions_allowed then |
| 694 |
self:updateButtonStates() |
| 695 |
return |
| 696 |
end |
| 697 |
|
| 698 |
if enable then |
| 699 |
self:addDialog("UIBankManager", stats and "showStatistics") |
| 700 |
else |
| 701 |
local w = self.ui:getWindow(UIBankManager) |
| 702 |
if w then |
| 703 |
if not stats and w.showingStatistics then |
| 704 |
w:hideStatistics() |
| 705 |
elseif stats and not w.showingStatistics then |
| 706 |
w:showStatistics() |
| 707 |
else |
| 708 |
w:close() |
| 709 |
end |
| 710 |
self:updateButtonStates() |
| 711 |
end |
| 712 |
end |
| 713 |
end |
| 714 |
|
| 715 |
function UIBottomPanel:dialogBuildRoom() |
| 716 |
if self.world.user_actions_allowed then |
| 717 |
local w = self.ui:getWindow(UIBuildRoom) |
| 718 |
local fullscreen = self.ui:getWindow(UIFullscreen) |
| 719 |
|
| 720 |
if w then |
| 721 |
if fullscreen then |
| 722 |
fullscreen:close() |
| 723 |
else |
| 724 |
w:close() |
| 725 |
end |
| 726 |
else |
| 727 |
if fullscreen then |
| 728 |
fullscreen:close() |
| 729 |
end |
| 730 |
|
| 731 |
local dlg = UIBuildRoom(self.ui) |
| 732 |
self.ui:setEditRoom(false) |
| 733 |
self.ui:addWindow(dlg) |
| 734 |
self.ui:tutorialStep(3, 1, 2) |
| 735 |
end |
| 736 |
end |
| 737 |
end |
| 738 |
|
| 739 |
function UIBottomPanel:dialogFurnishCorridor() |
| 740 |
if self.world.user_actions_allowed then |
| 741 |
local w = self.ui:getWindow(UIFurnishCorridor) |
| 742 |
local fullscreen = self.ui:getWindow(UIFullscreen) |
| 743 |
|
| 744 |
if w then |
| 745 |
if fullscreen then |
| 746 |
fullscreen:close() |
| 747 |
else |
| 748 |
w:close() |
| 749 |
end |
| 750 |
else |
| 751 |
if fullscreen then |
| 752 |
fullscreen:close() |
| 753 |
end |
| 754 |
|
| 755 |
local dlg = UIFurnishCorridor(self.ui) |
| 756 |
self.ui:setEditRoom(false) |
| 757 |
self.ui:addWindow(dlg) |
| 758 |
self.ui:tutorialStep(1, 1, 2) |
| 759 |
end |
| 760 |
end |
| 761 |
end |
| 762 |
|
| 763 |
function UIBottomPanel:dialogHireStaff() |
| 764 |
if self.world.user_actions_allowed then |
| 765 |
local w = self.ui:getWindow(UIHireStaff) |
| 766 |
local fullscreen = self.ui:getWindow(UIFullscreen) |
| 767 |
|
| 768 |
if w then |
| 769 |
if fullscreen then |
| 770 |
fullscreen:close() |
| 771 |
else |
| 772 |
w:close() |
| 773 |
end |
| 774 |
else |
| 775 |
if fullscreen then |
| 776 |
fullscreen:close() |
| 777 |
end |
| 778 |
|
| 779 |
local dlg = UIHireStaff(self.ui) |
| 780 |
self.ui:setEditRoom(false) |
| 781 |
self.ui:addWindow(dlg) |
| 782 |
self.ui:tutorialStep(2, 1, 2) |
| 783 |
self.ui:tutorialStep(4, 1, 2) |
| 784 |
end |
| 785 |
end |
| 786 |
end |
| 787 |
|
| 788 |
function UIBottomPanel:dialogStaffManagement(enable) |
| 789 |
if not self.world.user_actions_allowed then |
| 790 |
self:updateButtonStates() |
| 791 |
return |
| 792 |
end |
| 793 |
if enable then |
| 794 |
self:addDialog("UIStaffManagement") |
| 795 |
else |
| 796 |
local w = self.ui:getWindow(UIStaffManagement) |
| 797 |
if w then |
| 798 |
w:close() |
| 799 |
end |
| 800 |
end |
| 801 |
end |
| 802 |
|
| 803 |
function UIBottomPanel:dialogTownMap(enable) |
| 804 |
if not self.world.user_actions_allowed then |
| 805 |
self:updateButtonStates() |
| 806 |
return |
| 807 |
end |
| 808 |
if enable then |
| 809 |
self:addDialog("UITownMap") |
| 810 |
else |
| 811 |
local w = self.ui:getWindow(UITownMap) |
| 812 |
if w then |
| 813 |
w:close() |
| 814 |
end |
| 815 |
end |
| 816 |
end |
| 817 |
|
| 818 |
function UIBottomPanel:dialogDrugCasebook(enable) |
| 819 |
if not self.world.user_actions_allowed then |
| 820 |
self:updateButtonStates() |
| 821 |
return |
| 822 |
end |
| 823 |
if enable then |
| 824 |
self:addDialog("UICasebook") |
| 825 |
else |
| 826 |
local w = self.ui:getWindow(UICasebook) |
| 827 |
if w then |
| 828 |
w:close() |
| 829 |
end |
| 830 |
end |
| 831 |
end |
| 832 |
|
| 833 |
function UIBottomPanel:dialogResearch(enable) |
| 834 |
if not self.world.user_actions_allowed then |
| 835 |
self:updateButtonStates() |
| 836 |
self.ui:playSound(self.ui.hospital.research_dep_built and |
| 837 |
"selectx.wav" or "wrong2.wav") |
| 838 |
return |
| 839 |
end |
| 840 |
if TheApp.using_demo_files then |
| 841 |
self.ui:addWindow(UIInformation(self.ui, {_S.errors.dialog_missing_graphics})) |
| 842 |
end |
| 843 |
if self.ui.hospital.research_dep_built then |
| 844 |
if enable then |
| 845 |
self:addDialog("UIResearch") |
| 846 |
else |
| 847 |
local w = self.ui:getWindow(UIResearch) |
| 848 |
if w then |
| 849 |
w:close() |
| 850 |
end |
| 851 |
end |
| 852 |
self.ui:playSound("selectx.wav") |
| 853 |
else |
| 854 |
self.ui:playSound("wrong2.wav") |
| 855 |
self:updateButtonStates() |
| 856 |
self:giveResearchAdvice() |
| 857 |
end |
| 858 |
end |
| 859 |
|
| 860 |
function UIBottomPanel:giveResearchAdvice() |
| 861 |
local can_build_research = false |
| 862 |
for _, room in ipairs(self.ui.app.world.available_rooms) do |
| 863 |
if room.class == "ResearchRoom" then |
| 864 |
can_build_research = true |
| 865 |
break |
| 866 |
end |
| 867 |
end |
| 868 |
local msg = can_build_research and _A.warnings.research_screen_open_1 or _A.warnings.research_screen_open_2 |
| 869 |
if not TheApp.using_demo_files then |
| 870 |
self.ui.adviser:say(msg) |
| 871 |
end |
| 872 |
end |
| 873 |
|
| 874 |
function UIBottomPanel:dialogStatus(enable) |
| 875 |
if not self.world.user_actions_allowed then |
| 876 |
self:updateButtonStates() |
| 877 |
return |
| 878 |
end |
| 879 |
if enable then |
| 880 |
self:addDialog("UIProgressReport") |
| 881 |
else |
| 882 |
local w = self.ui:getWindow(UIProgressReport) |
| 883 |
if w then |
| 884 |
w:close() |
| 885 |
end |
| 886 |
end |
| 887 |
end |
| 888 |
|
| 889 |
function UIBottomPanel:dialogCharts(enable) |
| 890 |
if not self.world.user_actions_allowed then |
| 891 |
self:updateButtonStates() |
| 892 |
return |
| 893 |
end |
| 894 |
if enable then |
| 895 |
self:addDialog("UIGraphs") |
| 896 |
else |
| 897 |
local w = self.ui:getWindow(UIGraphs) |
| 898 |
if w then |
| 899 |
w:close() |
| 900 |
end |
| 901 |
end |
| 902 |
end |
| 903 |
|
| 904 |
function UIBottomPanel:dialogPolicy(enable) |
| 905 |
if not self.world.user_actions_allowed then |
| 906 |
self:updateButtonStates() |
| 907 |
return |
| 908 |
end |
| 909 |
if enable then |
| 910 |
self:addDialog("UIPolicy") |
| 911 |
else |
| 912 |
local w = self.ui:getWindow(UIPolicy) |
| 913 |
if w then |
| 914 |
w:close() |
| 915 |
end |
| 916 |
end |
| 917 |
end |
| 918 |
|
| 919 |
function UIBottomPanel:dialogMachineMenu(enable) |
| 920 |
if not self.world.user_actions_allowed then |
| 921 |
self:updateButtonStates() |
| 922 |
self.ui:playSound("selectx.wav") |
| 923 |
return |
| 924 |
end |
| 925 |
local w = self.ui:getWindow(UIMachineMenu) |
| 926 |
if w then |
| 927 |
w:close() |
| 928 |
else |
| 929 |
self:addDialog("UIMachineMenu") |
| 930 |
end |
| 931 |
self.ui:playSound("selectx.wav") |
| 932 |
end |
| 933 |
|
| 934 |
function UIBottomPanel:dialogAdviserHistory(enable) |
| 935 |
local w = self.ui:getWindow(UIAdviserHistory) |
| 936 |
if w then |
| 937 |
w:close() |
| 938 |
else |
| 939 |
self:addDialog("UIAdviserHistory") |
| 940 |
end |
| 941 |
self.ui:playSound("selectx.wav") |
| 942 |
end |
| 943 |
|
| 944 |
function UIBottomPanel:toggleInformation() |
| 945 |
self.world:toggleInformation() |
| 946 |
end |
| 947 |
|
| 948 |
local fullscreen_dialogs = { |
| 949 |
"UIStaffManagement", |
| 950 |
"UITownMap", |
| 951 |
"UICasebook", |
| 952 |
"UIResearch", |
| 953 |
"UIProgressReport", |
| 954 |
"UIGraphs", |
| 955 |
"UIPolicy", |
| 956 |
"UIMachineMenu", |
| 957 |
} |
| 958 |
|
| 959 |
function UIBottomPanel:updateButtonStates() |
| 960 |
for i, button in ipairs(self.additional_buttons) do |
| 961 |
button:setToggleState(not not self.ui:getWindow(_G[fullscreen_dialogs[i]])) |
| 962 |
end |
| 963 |
self.bank_button:setToggleState(not not self.ui:getWindow(UIBankManager)) |
| 964 |
end |
| 965 |
|
| 966 |
function UIBottomPanel:addDialog(dialog_class, extra_function) |
| 967 |
local edit_window = self.ui:getWindow(UIEditRoom) |
| 968 |
-- If we are currently editing a room, ask for abortion before adding any dialog. |
| 969 |
if edit_window then |
| 970 |
self.ui:addWindow(UIConfirmDialog(self.ui, false, |
| 971 |
_S.confirmation.abort_edit_room, |
| 972 |
--[[persistable:abort_edit_room_confirm_dialog]]function() |
| 973 |
self.ui:setEditRoom(false) |
| 974 |
local dialog = _G[dialog_class](self.ui) |
| 975 |
if extra_function then |
| 976 |
_G[dialog_class][extra_function](dialog) |
| 977 |
end |
| 978 |
self.ui:addWindow(dialog) |
| 979 |
self:updateButtonStates() |
| 980 |
end |
| 981 |
)) |
| 982 |
self:updateButtonStates() |
| 983 |
else |
| 984 |
self.ui:setEditRoom(false) |
| 985 |
local dialog = _G[dialog_class](self.ui) |
| 986 |
self.ui:addWindow(dialog) |
| 987 |
if extra_function then |
| 988 |
_G[dialog_class][extra_function](dialog) |
| 989 |
end |
| 990 |
self:updateButtonStates() |
| 991 |
end |
| 992 |
end |
| 993 |
|
| 994 |
-- Do not remove, for savegame compatibility < r1878 |
| 995 |
local --[[persistable:abort_edit_room_cancel_dialog]]function stub() |
| 996 |
end |
| 997 |
|
| 998 |
function UIBottomPanel:editRoom() |
| 999 |
local ui = self.ui |
| 1000 |
if ui.editing_allowed then |
| 1001 |
self.ui:playSound("selectx.wav") |
| 1002 |
if ui.edit_room then |
| 1003 |
ui:setEditRoom(false) |
| 1004 |
else |
| 1005 |
ui:setEditRoom(true) |
| 1006 |
end |
| 1007 |
else |
| 1008 |
-- no editing is allowed when other dialogs are open |
| 1009 |
self.ui:playSound("wrong2.wav") |
| 1010 |
end |
| 1011 |
end |
| 1012 |
|
| 1013 |
function UIBottomPanel:afterLoad(old, new) |
| 1014 |
self:setSize(640, 48) |
| 1015 |
self:setDefaultPosition(0.5, -0.1) |
| 1016 |
self:removeAllPanels() |
| 1017 |
self:drawPanels() |
| 1018 |
self:updateButtonStates() |
| 1019 |
if old < 40 then |
| 1020 |
-- Find the graph dialog and enable it |
| 1021 |
for _, button in ipairs(self.buttons) do |
| 1022 |
if not button.on_click then |
| 1023 |
button.on_click = self.dialogCharts |
| 1024 |
button.enabled = true |
| 1025 |
end |
| 1026 |
end |
| 1027 |
end |
| 1028 |
if old < 58 then |
| 1029 |
self.pause_font = TheApp.gfx:loadFontAndSpriteTable("QData", "Font124V") |
| 1030 |
end |
| 1031 |
if old < 62 then |
| 1032 |
-- renamed additional_buttons to additional_panels |
| 1033 |
-- additional_buttons are now the actual buttons |
| 1034 |
self.additional_panels = self.additional_buttons |
| 1035 |
self.additional_buttons = {} |
| 1036 |
for i = 1, 7 do |
| 1037 |
self.additional_buttons[i] = self.buttons[5 + i]:makeToggle() -- made them toggle buttons |
| 1038 |
end |
| 1039 |
self.bank_button = self.buttons[1]:makeToggle() |
| 1040 |
end |
| 1041 |
if old < 236 then |
| 1042 |
self:_initFonts(self.ui.app.gfx) |
| 1043 |
end |
| 1044 |
if old < 244 then |
| 1045 |
-- ignore the delay logic for save games, minor |
| 1046 |
if self.factory_counter == nil or self.factory_counter > MESSAGE_DOOR_FULLY_SHUT then |
| 1047 |
self.factory_counter = MESSAGE_DOOR_FULLY_SHUT |
| 1048 |
elseif self.factory_counter < MESSAGE_DOOR_FULLY_OPEN then |
| 1049 |
self.factory_counter = MESSAGE_DOOR_FULLY_OPEN |
| 1050 |
end |
| 1051 |
self.message_door = { |
| 1052 |
closed_amount = self.factory_counter, |
| 1053 |
next_action_delay = 0 |
| 1054 |
} |
| 1055 |
self.factory_counter = nil |
| 1056 |
self.factory_direction = nil |
| 1057 |
self.show_animation = nil |
| 1058 |
end |
| 1059 |
-- Hotfix to force re-calculation of the money font (see issue #1193) |
| 1060 |
self.money_font = TheApp.gfx:loadFontAndSpriteTable("QData", "Font05V", nil, nil, { apply_ui_scale = true }) |
| 1061 |
self:registerKeyHandlers() |
| 1062 |
|
| 1063 |
Window.afterLoad(self, old, new) |
| 1064 |
end |