| 1 |
--[[ Copyright (c) 2010 Manuel "Roujin" Wolf |
| 2 |
Copyright (c) 2020 lewri |
| 3 |
|
| 4 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 |
this software and associated documentation files (the "Software"), to deal in |
| 6 |
the Software without restriction, including without limitation the rights to |
| 7 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 9 |
so, subject to the following conditions: |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in all |
| 12 |
copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 |
SOFTWARE. --]] |
| 21 |
|
| 22 |
|
| 23 |
--! A dialog for activating cheats |
| 24 |
class "UICheats" (UIResizable) |
| 25 |
|
| 26 |
---@type UICheats |
| 27 |
local UICheats = _G["UICheats"] |
| 28 |
|
| 29 |
local col_bg = { |
| 30 |
red = 154, |
| 31 |
green = 146, |
| 32 |
blue = 198, |
| 33 |
} |
| 34 |
|
| 35 |
local col_caption = { |
| 36 |
red = 174, |
| 37 |
green = 166, |
| 38 |
blue = 218, |
| 39 |
} |
| 40 |
|
| 41 |
local col_border = { |
| 42 |
red = 134, |
| 43 |
green = 126, |
| 44 |
blue = 178, |
| 45 |
} |
| 46 |
|
| 47 |
local col_cheated_no = { |
| 48 |
red = 36, |
| 49 |
green = 154, |
| 50 |
blue = 36, |
| 51 |
} |
| 52 |
|
| 53 |
local col_cheated_yes = { |
| 54 |
red = 224, |
| 55 |
green = 36, |
| 56 |
blue = 36, |
| 57 |
} |
| 58 |
|
| 59 |
--[[ Constructs the cheat dialog. |
| 60 |
!param ui (UI) The active ui. |
| 61 |
]] |
| 62 |
function UICheats:UICheats(ui) |
| 63 |
self.cheats = ui.hospital.hosp_cheats |
| 64 |
self.cheat_list = ui.hospital.hosp_cheats.cheat_list |
| 65 |
|
| 66 |
self:UIResizable(ui, 300, 560, col_bg) |
| 67 |
|
| 68 |
self.default_button_sound = "selectx.wav" |
| 69 |
|
| 70 |
self.modal_class = "cheats" |
| 71 |
self.esc_closes = true |
| 72 |
self.resizable = false |
| 73 |
|
| 74 |
local y = 10 |
| 75 |
self:addBevelPanel(100, y, 360, 20, col_caption):setLabel(_S.cheats_window.caption) |
| 76 |
.lowered = true |
| 77 |
|
| 78 |
y = y + 30 |
| 79 |
self:addColourPanel(100, y, 360, 40, col_bg.red, col_bg.green, col_bg.blue) |
| 80 |
:setLabel({_S.cheats_window.warning}) |
| 81 |
|
| 82 |
y = y + 40 |
| 83 |
self.cheated_panel = self:addBevelPanel(100, y, 360, 18, col_cheated_no, col_border, col_border) |
| 84 |
|
| 85 |
local function button_clicked(num) |
| 86 |
return --[[persistable:cheats_button]] function(window) |
| 87 |
window:buttonClicked(num) |
| 88 |
end |
| 89 |
end |
| 90 |
|
| 91 |
self.item_panels = {} |
| 92 |
self.item_buttons = {} |
| 93 |
|
| 94 |
y = y + 30 |
| 95 |
local num = 1 |
| 96 |
local function add_cheat_button(x, number) |
| 97 |
self.item_panels[number] = self:addBevelPanel(x, y, 260, 20, col_bg) |
| 98 |
:setLabel(_S.cheats_window.cheats[self.cheat_list[number].name]) |
| 99 |
self.item_buttons[number] = self.item_panels[number] |
| 100 |
:makeButton(0, 0, 260, 20, nil, button_clicked(number)) |
| 101 |
:setTooltip(_S.tooltip.cheats_window.cheats[self.cheat_list[number].name]) |
| 102 |
end |
| 103 |
while self.cheat_list[num] do |
| 104 |
add_cheat_button(20, num) |
| 105 |
num = num + 1 |
| 106 |
if self.cheat_list[num] then |
| 107 |
add_cheat_button(280, num) |
| 108 |
num = num + 1 |
| 109 |
end |
| 110 |
y = y + 20 |
| 111 |
end |
| 112 |
|
| 113 |
y = y + 20 |
| 114 |
self:addBevelPanel(100, y, 360, 40, col_bg):setLabel(_S.cheats_window.close) |
| 115 |
:makeButton(0, 0, 360, 40, nil, self.buttonBack):setTooltip(_S.tooltip.cheats_window.close) |
| 116 |
|
| 117 |
y = y + 60 |
| 118 |
self:setSize(560, y) |
| 119 |
-- Position should be set after all panels/buttons are made |
| 120 |
self:setDefaultPosition(0.2, 0.4) |
| 121 |
self:updateCheatedStatus() |
| 122 |
end |
| 123 |
|
| 124 |
function UICheats:updateCheatedStatus() |
| 125 |
local cheated = self.ui.hospital.cheated |
| 126 |
self.cheated_panel:setLabel(cheated and _S.cheats_window.cheated.yes or _S.cheats_window.cheated.no) |
| 127 |
self.cheated_panel:setColour(cheated and col_cheated_yes or col_cheated_no) |
| 128 |
end |
| 129 |
|
| 130 |
--! Handles the choice of a cheat from the dialog |
| 131 |
--!param num (number) the index in the cheat list |
| 132 |
function UICheats:buttonClicked(num) |
| 133 |
-- If the menu was opened by fax code, allow player to use it |
| 134 |
if self.ui.hospital.world:isUserActionProhibited() and not self.ui:getWindow(UIFax) then |
| 135 |
--TODO: Prevent selectx.wav playing with this |
| 136 |
return self.ui:playSound("wrong2.wav") |
| 137 |
end |
| 138 |
local success, message = self.cheats:performCheat(num) |
| 139 |
if success then |
| 140 |
self.cheats.announceCheat(self.ui) |
| 141 |
self:updateCheatedStatus() |
| 142 |
else -- cheat failed, make sure we provide feedback |
| 143 |
message = message or _S.information.cheat_not_possible |
| 144 |
end |
| 145 |
if message then |
| 146 |
self.ui:addWindow(UIInformation(self.ui, {message})) |
| 147 |
end |
| 148 |
end |
| 149 |
|
| 150 |
function UICheats:buttonBack() |
| 151 |
self:close() |
| 152 |
end |
| 153 |
|
| 154 |
function UICheats:afterLoad(old, new) |
| 155 |
-- Window must be closed for compatibility |
| 156 |
self:close() |
| 157 |
UIResizable.afterLoad(self, old, new) |
| 158 |
end |