| 1 |
--[[ Copyright (c) 2013 Mark (Mark L) Lawlor |
| 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 |
--! Customise window used in the main menu and ingame. |
| 22 |
class "UICustomise" (UIResizable) |
| 23 |
|
| 24 |
---@type UICustomise |
| 25 |
local UICustomise = _G["UICustomise"] |
| 26 |
|
| 27 |
local col_bg = { |
| 28 |
red = 154, |
| 29 |
green = 146, |
| 30 |
blue = 198, |
| 31 |
} |
| 32 |
|
| 33 |
local col_shadow = { |
| 34 |
red = 134, |
| 35 |
green = 126, |
| 36 |
blue = 178, |
| 37 |
} |
| 38 |
|
| 39 |
local col_caption = { |
| 40 |
red = 174, |
| 41 |
green = 166, |
| 42 |
blue = 218, |
| 43 |
} |
| 44 |
|
| 45 |
function UICustomise:UICustomise(ui, mode) |
| 46 |
self:UIResizable(ui, 340, 375, col_bg) |
| 47 |
|
| 48 |
local app = ui.app |
| 49 |
self.mode = mode |
| 50 |
self.modal_class = mode == "menu" and "main menu" or "options" or "customise" |
| 51 |
self.on_top = mode == "menu" |
| 52 |
self.esc_closes = true |
| 53 |
self.resizable = false |
| 54 |
self:setDefaultPosition(0.5, 0.25) |
| 55 |
self.default_button_sound = "selectx.wav" |
| 56 |
self.app = app |
| 57 |
|
| 58 |
-- Window parts definition |
| 59 |
-- Title |
| 60 |
self:addBevelPanel(85, 10, 170, 20, col_caption):setLabel(_S.customise_window.caption) |
| 61 |
.lowered = true |
| 62 |
|
| 63 |
-- Movies, global switch |
| 64 |
self:addBevelPanel(15, 40, 165, 20, col_shadow, col_bg, col_bg) |
| 65 |
:setLabel(_S.customise_window.movies):setTooltip(_S.tooltip.customise_window.movies).lowered = true |
| 66 |
self.movies_panel = |
| 67 |
self:addBevelPanel(185, 40, 140, 20, col_bg):setLabel(app.config.movies and _S.customise_window.option_on or _S.customise_window.option_off) |
| 68 |
self.movies_button = self.movies_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonMoviesGlobal) |
| 69 |
:setToggleState(app.config.movies):setTooltip(_S.tooltip.customise_window.movies) |
| 70 |
|
| 71 |
-- Intro movie |
| 72 |
self:addBevelPanel(15, 65, 165, 20, col_shadow, col_bg, col_bg) |
| 73 |
:setLabel(_S.customise_window.intro):setTooltip(_S.tooltip.customise_window.intro).lowered = true |
| 74 |
self.intro_panel = |
| 75 |
self:addBevelPanel(185, 65, 140, 20, col_bg):setLabel(app.config.play_intro and _S.customise_window.option_on or _S.customise_window.option_off) |
| 76 |
self.intro_button = self.intro_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonIntro) |
| 77 |
:setToggleState(app.config.play_intro):setTooltip(_S.tooltip.customise_window.intro) |
| 78 |
|
| 79 |
-- Allow user actions when paused |
| 80 |
self:addBevelPanel(15, 90, 165, 20, col_shadow, col_bg, col_bg) |
| 81 |
:setLabel(_S.customise_window.paused):setTooltip(_S.tooltip.customise_window.paused).lowered = true |
| 82 |
self.paused_panel = |
| 83 |
self:addBevelPanel(185, 90, 140, 20, col_bg):setLabel(app.config.allow_user_actions_while_paused and _S.customise_window.option_on or _S.customise_window.option_off) |
| 84 |
self.paused_button = self.paused_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonPaused) |
| 85 |
:setToggleState(app.config.allow_user_actions_while_paused):setTooltip(_S.tooltip.customise_window.paused) |
| 86 |
|
| 87 |
-- Volume down is opening casebook |
| 88 |
self:addBevelPanel(15, 115, 165, 20, col_shadow, col_bg, col_bg) |
| 89 |
:setLabel(_S.customise_window.volume):setTooltip(_S.tooltip.customise_window.volume).lowered = true |
| 90 |
self.volume_panel = |
| 91 |
self:addBevelPanel(185, 115, 140, 20, col_bg):setLabel(app.config.volume_opens_casebook and _S.customise_window.option_on or _S.customise_window.option_off) |
| 92 |
self.volume_button = self.volume_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonVolume) |
| 93 |
:setToggleState(app.config.volume_opens_casebook):setTooltip(_S.tooltip.customise_window.volume) |
| 94 |
|
| 95 |
-- Alien DNA from emergencies only/must stand/can knock on doors |
| 96 |
self:addBevelPanel(15, 140, 165, 20, col_shadow, col_bg, col_bg) |
| 97 |
:setLabel(_S.customise_window.aliens):setTooltip(_S.tooltip.customise_window.aliens).lowered = true |
| 98 |
self.aliens_panel = |
| 99 |
self:addBevelPanel(185, 140, 140, 20, col_bg):setLabel(app.config.alien_dna_only_by_emergency and _S.customise_window.emergency_only or _S.customise_window.regular_patients) |
| 100 |
self.aliens_button = self.aliens_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonAliens) |
| 101 |
:setToggleState(app.config.alien_dna_only_by_emergency):setTooltip(_S.tooltip.customise_window.aliens) |
| 102 |
|
| 103 |
-- Allow female patients with Fractured Bones |
| 104 |
self:addBevelPanel(15, 165, 165, 20, col_shadow, col_bg, col_bg) |
| 105 |
:setLabel(_S.customise_window.fractured_bones):setTooltip(_S.tooltip.customise_window.fractured_bones).lowered = true |
| 106 |
self.fractured_bones_panel = |
| 107 |
self:addBevelPanel(185, 165, 140, 20, col_bg):setLabel(app.config.disable_fractured_bones_females and _S.customise_window.male_only or _S.customise_window.male_and_female) |
| 108 |
self.fractured_bones_button = self.fractured_bones_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonFractured_bones) |
| 109 |
:setToggleState(app.config.disable_fractured_bones_females):setTooltip(_S.tooltip.customise_window.fractured_bones) |
| 110 |
|
| 111 |
-- Allow average contents when building rooms |
| 112 |
self:addBevelPanel(15, 190, 165, 20, col_shadow, col_bg, col_bg) |
| 113 |
:setLabel(_S.customise_window.average_contents):setTooltip(_S.tooltip.customise_window.average_contents).lowered = true |
| 114 |
self.average_contents_panel = |
| 115 |
self:addBevelPanel(185, 190, 140, 20, col_bg):setLabel(app.config.enable_avg_contents and _S.customise_window.option_on or _S.customise_window.option_off) |
| 116 |
self.average_contents_button = self.average_contents_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonAverage_contents) |
| 117 |
:setToggleState(app.config.enable_avg_contents):setTooltip(_S.tooltip.customise_window.average_contents) |
| 118 |
|
| 119 |
-- Allow removal of destroyed rooms |
| 120 |
self:addBevelPanel(15, 215, 165, 20, col_shadow, col_bg, col_bg) |
| 121 |
:setLabel(_S.customise_window.remove_destroyed_rooms):setTooltip(_S.tooltip.customise_window.remove_destroyed_rooms).lowered = true |
| 122 |
self.destroyed_rooms_panel = |
| 123 |
self:addBevelPanel(185, 215, 140, 20, col_bg):setLabel(app.config.remove_destroyed_rooms and _S.customise_window.option_on or _S.customise_window.option_off) |
| 124 |
self.destroyed_rooms_button = self.destroyed_rooms_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonDestroyed_rooms) |
| 125 |
:setToggleState(app.config.remove_destroyed_rooms):setTooltip(_S.tooltip.customise_window.remove_destroyed_rooms) |
| 126 |
|
| 127 |
-- Allow machine menu button in a toolbar |
| 128 |
self:addBevelPanel(15, 240, 165, 20, col_shadow, col_bg, col_bg) |
| 129 |
:setLabel(_S.customise_window.machine_menu_button):setTooltip(_S.tooltip.customise_window.machine_menu_button).lowered = true |
| 130 |
self.machine_menu_panel = |
| 131 |
self:addBevelPanel(185, 240, 140, 20, col_bg):setLabel(app.config.machine_menu_button and _S.customise_window.option_on or _S.customise_window.option_off) |
| 132 |
self.machine_menu_button = self.machine_menu_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonMachine_menu) |
| 133 |
:setToggleState(app.config.machine_menu_button):setTooltip(_S.tooltip.customise_window.machine_menu_button) |
| 134 |
|
| 135 |
-- Allow user to disable screen shake during earthquakes |
| 136 |
self:addBevelPanel(15, 265, 165, 20, col_shadow, col_bg, col_bg) |
| 137 |
:setLabel(_S.customise_window.enable_screen_shake):setTooltip(_S.tooltip.customise_window.enable_screen_shake).lowered = true |
| 138 |
self.screen_shake_panel = |
| 139 |
self:addBevelPanel(185, 265, 140, 20, col_bg):setLabel(app.config.enable_screen_shake and _S.customise_window.option_on or _S.customise_window.option_off) |
| 140 |
self.screen_shake_button = self.screen_shake_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonScreen_shake) |
| 141 |
:setToggleState(app.config.enable_screen_shake):setTooltip(_S.tooltip.customise_window.enable_screen_shake) |
| 142 |
|
| 143 |
self:addBevelPanel(15, 290, 165, 20, col_shadow, col_bg, col_bg) |
| 144 |
:setLabel(_S.customise_window.enable_announcer_subtitles):setTooltip(_S.tooltip.customise_window.enable_announcer_subtitles).lowered = true |
| 145 |
self.announcer_subtitles_panel = |
| 146 |
self:addBevelPanel(185, 290, 140, 20, col_bg):setLabel(app.config.enable_announcer_subtitles and _S.customise_window.option_on or _S.customise_window.option_off) |
| 147 |
self.announcer_subtitles_button = self.announcer_subtitles_panel:makeToggleButton(0, 0, 140, 20, nil, self.buttonAnnouncer_subtitles) |
| 148 |
:setToggleState(app.config.enable_announcer_subtitles):setTooltip(_S.tooltip.customise_window.enable_announcer_subtitles) |
| 149 |
|
| 150 |
-- "Back" button |
| 151 |
self:addBevelPanel(15, 320, 310, 40, col_bg):setLabel(_S.customise_window.back) |
| 152 |
:makeButton(0, 0, 310, 40, nil, self.buttonBack):setTooltip(_S.tooltip.customise_window.back) |
| 153 |
end |
| 154 |
|
| 155 |
function UICustomise:buttonAudioGlobal() |
| 156 |
local window = UIAudio(self.ui, "menu") |
| 157 |
self.ui:addWindow(window) |
| 158 |
end |
| 159 |
|
| 160 |
function UICustomise:buttonMoviesGlobal() |
| 161 |
local app = self.ui.app |
| 162 |
app.config.movies = not app.config.movies |
| 163 |
self.movies_button:toggle() |
| 164 |
self.movies_panel:setLabel(app.config.movies and _S.customise_window.option_on or _S.customise_window.option_off) |
| 165 |
self:reload() |
| 166 |
app:saveConfig() |
| 167 |
end |
| 168 |
|
| 169 |
function UICustomise:buttonIntro() |
| 170 |
local app = self.ui.app |
| 171 |
app.config.play_intro = not app.config.play_intro |
| 172 |
self.intro_button:toggle() |
| 173 |
self.intro_panel:setLabel(app.config.play_intro and _S.customise_window.option_on or _S.customise_window.option_off) |
| 174 |
self:reload() |
| 175 |
app:saveConfig() |
| 176 |
end |
| 177 |
|
| 178 |
function UICustomise:buttonPaused() |
| 179 |
local app = self.ui.app |
| 180 |
app.config.allow_user_actions_while_paused = not app.config.allow_user_actions_while_paused |
| 181 |
self.paused_button:toggle() |
| 182 |
self.paused_panel:setLabel(app.config.allow_user_actions_while_paused and _S.customise_window.option_on or _S.customise_window.option_off) |
| 183 |
self:reload() |
| 184 |
app:saveConfig() |
| 185 |
end |
| 186 |
|
| 187 |
function UICustomise:buttonVolume() |
| 188 |
local app = self.ui.app |
| 189 |
app.config.volume_opens_casebook = not app.config.volume_opens_casebook |
| 190 |
self.volume_button:toggle() |
| 191 |
self.volume_panel:setLabel(app.config.volume_opens_casebook and _S.customise_window.option_on or _S.customise_window.option_off) |
| 192 |
self:reload() |
| 193 |
app:saveConfig() |
| 194 |
end |
| 195 |
|
| 196 |
function UICustomise:buttonAliens() |
| 197 |
local app = self.ui.app |
| 198 |
app.config.alien_dna_only_by_emergency = not app.config.alien_dna_only_by_emergency |
| 199 |
app.config.alien_dna_must_stand = not app.config.alien_dna_must_stand |
| 200 |
app.config.alien_dna_can_knock_on_doors = not app.config.alien_dna_can_knock_on_doors |
| 201 |
self.aliens_button:toggle() |
| 202 |
self.aliens_panel:setLabel(app.config.alien_dna_only_by_emergency and _S.customise_window.option_on or _S.customise_window.option_off) |
| 203 |
app:saveConfig() |
| 204 |
self:reload() |
| 205 |
local err = {_S.errors.alien_dna} |
| 206 |
self.ui:addWindow(UIInformation(self.ui, err)) |
| 207 |
end |
| 208 |
|
| 209 |
function UICustomise:buttonFractured_bones() |
| 210 |
local app = self.ui.app |
| 211 |
app.config.disable_fractured_bones_females = not app.config.disable_fractured_bones_females |
| 212 |
self.fractured_bones_button:toggle() |
| 213 |
self.fractured_bones_panel:setLabel(app.config.disable_fractured_bones_females and _S.customise_window.option_on or _S.customise_window.option_off) |
| 214 |
app:saveConfig() |
| 215 |
self:reload() |
| 216 |
local err = {_S.errors.fractured_bones} |
| 217 |
self.ui:addWindow(UIInformation(self.ui, err)) |
| 218 |
end |
| 219 |
|
| 220 |
function UICustomise:buttonAverage_contents() |
| 221 |
local app = self.ui.app |
| 222 |
app.config.enable_avg_contents = not app.config.enable_avg_contents |
| 223 |
self.average_contents_button:toggle() |
| 224 |
self.average_contents_panel:setLabel(app.config.enable_avg_contents and _S.customise_window.option_on or _S.customise_window.option_off) |
| 225 |
app:saveConfig() |
| 226 |
self:reload() |
| 227 |
end |
| 228 |
|
| 229 |
function UICustomise:buttonDestroyed_rooms() |
| 230 |
local app = self.ui.app |
| 231 |
app.config.remove_destroyed_rooms = not app.config.remove_destroyed_rooms |
| 232 |
self.destroyed_rooms_button:toggle() |
| 233 |
self.destroyed_rooms_panel:setLabel(app.config.remove_destroyed_rooms and _S.customise_window.option_on or _S.customise_window.option_off) |
| 234 |
app:saveConfig() |
| 235 |
self:reload() |
| 236 |
end |
| 237 |
|
| 238 |
function UICustomise:buttonMachine_menu() |
| 239 |
local app = self.ui.app |
| 240 |
app.config.machine_menu_button = not app.config.machine_menu_button |
| 241 |
self.destroyed_rooms_button:toggle() |
| 242 |
self.destroyed_rooms_panel:setLabel(app.config.machine_menu_button and _S.customise_window.option_on or _S.customise_window.option_off) |
| 243 |
app:saveConfig() |
| 244 |
self:reload() |
| 245 |
end |
| 246 |
|
| 247 |
function UICustomise:buttonScreen_shake() |
| 248 |
local app = self.ui.app |
| 249 |
app.config.enable_screen_shake = not app.config.enable_screen_shake |
| 250 |
self.screen_shake_button:toggle() |
| 251 |
self.screen_shake_panel:setLabel(app.config.enable_screen_shake and _S.customise_window.option_on or _S.customise_window.option_off) |
| 252 |
app:saveConfig() |
| 253 |
self:reload() |
| 254 |
end |
| 255 |
|
| 256 |
function UICustomise:buttonAnnouncer_subtitles() |
| 257 |
local app = self.ui.app |
| 258 |
app.config.enable_announcer_subtitles = not app.config.enable_announcer_subtitles |
| 259 |
self.announcer_subtitles_button:toggle() |
| 260 |
self.screen_shake_panel:setLabel(app.config.enable_announcer_subtitles and _S.customise_window.option_on or _S.customise_window.option_off) |
| 261 |
app:saveConfig() |
| 262 |
self:reload() |
| 263 |
end |
| 264 |
|
| 265 |
function UICustomise:buttonBack() |
| 266 |
self:close() |
| 267 |
local window = UIOptions(self.ui, "menu") |
| 268 |
self.ui:addWindow(window) |
| 269 |
end |
| 270 |
|
| 271 |
-- So that we can see the option has been changed reload the menu |
| 272 |
function UICustomise:reload() |
| 273 |
local window = UICustomise(self.ui, "menu") |
| 274 |
self.ui:addWindow(window) |
| 275 |
end |
| 276 |
|
| 277 |
function UICustomise:close() |
| 278 |
UIResizable.close(self) |
| 279 |
if self.mode == "menu" then |
| 280 |
self.ui:addWindow(UIMainMenu(self.ui)) |
| 281 |
end |
| 282 |
end |