1--[[ Copyright (c) 2010 Manuel "Roujin" Wolf 2Copyright (c) 2020 lewri 3 4Permission is hereby granted, free of charge, to any person obtaining a copy of 5this software and associated documentation files (the "Software"), to deal in 6the Software without restriction, including without limitation the rights to 7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8of the Software, and to permit persons to whom the Software is furnished to do 9so, subject to the following conditions: 10 11The above copyright notice and this permission notice shall be included in all 12copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20SOFTWARE. --]] 21 22 23--! A dialog for activating cheats 24class "UICheats" (UIResizable) 25 26---@type UICheats 27local UICheats = _G["UICheats"] 28 29local col_bg = { 30 red = 154, 31 green = 146, 32 blue = 198, 33} 34 35local col_caption = { 36 red = 174, 37 green = 166, 38 blue = 218, 39} 40 41local col_border = { 42 red = 134, 43 green = 126, 44 blue = 178, 45} 46 47local col_cheated_no = { 48 red = 36, 49 green = 154, 50 blue = 36, 51} 52 53local 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]] 62function 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, 200, 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 self:setDefaultPosition(0.2, 0.4) 74 75 local y = 10 76 self:addBevelPanel(20, y, 260, 20, col_caption):setLabel(_S.cheats_window.caption) 77 .lowered = true 78 79 y = y + 30 80 self:addColourPanel(20, y, 260, 40, col_bg.red, col_bg.green, col_bg.blue):setLabel({_S.cheats_window.warning}) 81 82 y = y + 40 83 self.cheated_panel = self:addBevelPanel(20, y, 260, 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 for num = 1, #self.cheat_list do 96 self.item_panels[num] = self:addBevelPanel(20, y, 260, 20, col_bg) 97 :setLabel(_S.cheats_window.cheats[self.cheat_list[num].name]) 98 self.item_buttons[num] = self.item_panels[num]:makeButton(0, 0, 260, 20, nil, button_clicked(num)) 99 :setTooltip(_S.tooltip.cheats_window.cheats[self.cheat_list[num].name]) 100 y = y + 20 101 end 102 103 y = y + 20 104 self:addBevelPanel(20, y, 260, 40, col_bg):setLabel(_S.cheats_window.close) 105 :makeButton(0, 0, 260, 40, nil, self.buttonBack):setTooltip(_S.tooltip.cheats_window.close) 106 107 y = y + 60 108 self:setSize(300, y) 109 self:updateCheatedStatus() 110end 111 112function UICheats:updateCheatedStatus() 113 local cheated = self.ui.hospital.cheated 114 self.cheated_panel:setLabel(cheated and _S.cheats_window.cheated.yes or _S.cheats_window.cheated.no) 115 self.cheated_panel:setColour(cheated and col_cheated_yes or col_cheated_no) 116end 117 118function UICheats:buttonClicked(num) 119 if self.ui.hospital.world:isUserActionProhibited() then 120 --TODO: Prevent selectx.wav playing with this 121 return self.ui:playSound("wrong2.wav") 122 end 123 if self.cheats:performCheat(num) then 124 self.cheats.announceCheat(self.ui) 125 self:updateCheatedStatus() 126 else 127 self.ui:addWindow(UIInformation(self.ui, {_S.information.cheat_not_possible})) 128 end 129end 130 131function UICheats:buttonBack() 132 self:close() 133end 134 135function UICheats:afterLoad(old, new) 136 if old < 145 then 137 -- Window must be closed if open for compatibility 138 local cheatWindow = self.ui:getWindow(UICheats) 139 if cheatWindow then 140 cheatWindow:close() 141 end 142 end 143 UIResizable.afterLoad(self, old, new) 144end 145