-
Notifications
You must be signed in to change notification settings - Fork 354
/
options.lua
717 lines (590 loc) · 28.2 KB
/
options.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
--[[ Copyright (c) 2010 Manuel "Roujin" Wolf
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. --]]
--! Options window used in the main menu and ingame.
class "UIOptions" (UIResizable)
---@type UIOptions
local UIOptions = _G["UIOptions"]
-- Constants for most button's width and height
local BTN_WIDTH = 135
local BTN_HEIGHT = 20
local col_bg = {
red = 154,
green = 146,
blue = 198,
}
local col_textbox = {
red = 0,
green = 0,
blue = 0,
}
local col_highlight = {
red = 174,
green = 166,
blue = 218,
}
local col_shadow = {
red = 134,
green = 126,
blue = 178,
}
local col_caption = {
red = 174,
green = 166,
blue = 218,
}
-- Private functions
--- Calculates the Y position for the dialog box in the option menu
-- and increments along the current position for the next element
-- @return The Y position to place the element at
--!param reset (boolean) Reset the index to start at the top of a column, below the title.
function UIOptions:_getOptionYPos(reset)
if reset then self._current_option_index = 2 end
-- Offset from top of options box
local STARTING_Y_POS = 15
-- Y Height is 20 for panel size + 10 for spacing
local Y_HEIGHT = 30
-- Multiply by the index so that index=1 is at STARTING_Y_POS
local calculated_pos = STARTING_Y_POS + Y_HEIGHT * (self._current_option_index - 1)
self._current_option_index = self._current_option_index + 1
return calculated_pos
end
function UIOptions:UIOptions(ui, mode)
self:UIResizable(ui, 620, 300, col_bg)
local app = ui.app
self.mode = mode
self.modal_class = mode == "menu" and "main menu" or "options"
self.on_top = mode == "menu"
self.esc_closes = true
self.resizable = false
self:setDefaultPosition(0.5, 0.25)
self.default_button_sound = "selectx.wav"
self.app = app
-- Tracks the current position of the object
self._current_option_index = 1
self:checkForAvailableLanguages()
-- Set up list of resolutions
self.available_resolutions = {
{text = "640x480 (4:3)", width = 640, height = 480},
{text = "800x600 (4:3)", width = 800, height = 600},
{text = "1024x768 (4:3)", width = 1024, height = 768},
{text = "1280x960 (4:3)", width = 1280, height = 960},
{text = "1600x1200 (4:3)", width = 1600, height = 1200},
{text = "1280x1024 (5:4)", width = 1280, height = 1024},
{text = "1280x720 (16:9)", width = 1280, height = 720},
{text = "1366x768 (16:9)", width = 1366, height = 768},
{text = "1600x900 (16:9)", width = 1600, height = 900},
{text = "1920x1080 (16:9)", width = 1920, height = 1080},
{text = "1280x800 (16:10)", width = 1280, height = 800},
{text = "1440x900 (16:10)", width = 1440, height = 900},
{text = "1680x1050 (16:10)", width = 1680, height = 1050},
{text = "1920x1200 (16:10)", width = 1920, height = 1200},
{text = _S.options_window.custom_resolution, custom = true},
}
-- Window parts definition
-- Title
local title_y_pos = self:_getOptionYPos()
self:addBevelPanel(175, title_y_pos, BTN_WIDTH * 2, 20, col_caption):setLabel(_S.options_window.caption)
.lowered = true
if app:isUpdateCheckAvailable() then
-- Check for updates
local updates_y_pos = self:_getOptionYPos()
local updates_string = app.config.check_for_updates and
_S.options_window.option_enabled or _S.options_window.option_disabled
self:addBevelPanel(20, updates_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.check_for_updates):setTooltip(_S.tooltip.options_window.check_for_updates).lowered = true
self.updates_panel =
self:addBevelPanel(165, updates_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(updates_string)
self.updates_button = self.updates_panel:makeToggleButton(0, 0, 140, BTN_HEIGHT, nil, self.buttonUpdates)
:setToggleState(app.config.check_for_updates)
end
-- Fullscreen
local fullscreen_y_pos = self:_getOptionYPos()
self:addBevelPanel(20, fullscreen_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.fullscreen):setTooltip(_S.tooltip.options_window.fullscreen).lowered = true
self.fullscreen_panel =
self:addBevelPanel(165, fullscreen_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(app.fullscreen and _S.options_window.option_on or _S.options_window.option_off)
self.fullscreen_button = self.fullscreen_panel:makeToggleButton(0, 0, 140, BTN_HEIGHT, nil, self.buttonFullscreen)
:setToggleState(app.fullscreen):setTooltip(_S.tooltip.options_window.fullscreen_button)
-- Screen resolution
local screen_res_y_pos = self:_getOptionYPos()
self:addBevelPanel(20, screen_res_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.resolution):setTooltip(_S.tooltip.options_window.resolution).lowered = true
self.resolution_panel = self:addBevelPanel(165, screen_res_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(app.config.width .. "x" .. app.config.height)
self.resolution_button = self.resolution_panel:makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.dropdownResolution):setTooltip(_S.tooltip.options_window.select_resolution)
-- Mouse capture
local capture_mouse_y_pos = self:_getOptionYPos()
self:addBevelPanel(20, capture_mouse_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.capture_mouse):setTooltip(_S.tooltip.options_window.capture_mouse).lowered = true
self.mouse_capture_panel =
self:addBevelPanel(165, capture_mouse_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(app.config.capture_mouse and _S.options_window.option_on or _S.options_window.option_off)
self.mouse_capture_button = self.mouse_capture_panel:makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonMouseCapture)
:setToggleState(app.config.capture_mouse):setTooltip(_S.tooltip.options_window.capture_mouse)
-- Mouse scroll key
local right_mouse_scrolling_y_pos = self:_getOptionYPos()
self:addBevelPanel(20, right_mouse_scrolling_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.right_mouse_scrolling):setTooltip(_S.tooltip.options_window.right_mouse_scrolling).lowered = true
self.right_mouse_scrolling_panel =
self:addBevelPanel(165, right_mouse_scrolling_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(app.config.right_mouse_scrolling and _S.options_window.right_mouse_scrolling_option_right or _S.options_window.right_mouse_scrolling_option_middle)
self.right_mouse_scrolling_button = self.right_mouse_scrolling_panel:makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonRightMouseScrolling)
:setToggleState(app.config.right_mouse_scrolling):setTooltip(_S.tooltip.options_window.right_mouse_scrolling)
-- Language
-- Get language name in the language to normalize display.
-- If it doesn't exist, display the current config option.
local lang = self.app.strings:getLanguageNames(app.config.language)
if lang then
lang = lang[1]
else
lang = app.config.language
end
-- Start a new column of buttons
local lang_y_pos = self:_getOptionYPos(true)
self:addBevelPanel(320, lang_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.language):setTooltip(_S.tooltip.options_window.language).lowered = true
self.language_panel = self:addBevelPanel(465, lang_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(lang)
self.language_button = self.language_panel:makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.dropdownLanguage):setTooltip(_S.tooltip.options_window.select_language)
-- add the Audio global switch.
local audio_status = app:isAudioEnabled()
local audio_y_pos = self:_getOptionYPos()
self:addBevelPanel(320, audio_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg)
:setLabel(_S.options_window.audio):setTooltip(_S.tooltip.options_window.audio_button).lowered = true
self.volume_panel =
self:addBevelPanel(465, audio_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(app.config.audio and audio_status and _S.customise_window.option_on or _S.customise_window.option_off)
self.volume_button = self.volume_panel:makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonAudioGlobal)
:setToggleState(app.config.audio and audio_status):setTooltip(_S.tooltip.options_window.audio_toggle)
self.volume_button.enabled = audio_status
-- Set scroll speed.
local scroll_y_pos = self:_getOptionYPos()
self:addBevelPanel(320, scroll_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg) : setLabel(_S.options_window.scrollspeed):setTooltip(_S.tooltip.options_window.scrollspeed).lowered = true
self.scrollspeed_panel = self:addBevelPanel(465, scroll_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel(tostring(self.ui.app.config.scroll_speed))
self.scrollspeed_button = self.scrollspeed_panel : makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonScrollSpeed) : setTooltip(_S.tooltip.options_window.scrollspeed)
-- Set shift scroll speed.
local shiftscroll_y_pos = self:_getOptionYPos()
self:addBevelPanel(320, shiftscroll_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg) : setLabel(_S.options_window.shift_scrollspeed):setTooltip(_S.tooltip.options_window.shift_scrollspeed).lowered = true
self.shift_scrollspeed_panel = self:addBevelPanel(465, shiftscroll_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel( tostring(self.ui.app.config.shift_scroll_speed) )
self.shift_scrollspeed_button = self.shift_scrollspeed_panel : makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonShiftScrollSpeed) : setTooltip(_S.tooltip.options_window.shift_scrollspeed)
-- Set zoom speed.
local zoom_y_pos = self:_getOptionYPos()
self:addBevelPanel(320, zoom_y_pos, BTN_WIDTH, BTN_HEIGHT, col_shadow, col_bg, col_bg) : setLabel(_S.options_window.zoom_speed):setTooltip(_S.tooltip.options_window.zoom_speed).lowered = true
self.zoomspeed_panel = self:addBevelPanel(465, zoom_y_pos, BTN_WIDTH, BTN_HEIGHT, col_bg):setLabel( tostring(self.ui.app.config.zoom_speed) )
self.zoomspeed_button = self.zoomspeed_panel : makeToggleButton(0, 0, BTN_WIDTH, BTN_HEIGHT, nil, self.buttonZoomSpeed) : setTooltip(_S.tooltip.options_window.zoom_speed)
local lower_row_y_pos = self:_getOptionYPos()
-- "Customise" button
self:addBevelPanel(20, lower_row_y_pos, BTN_WIDTH, 30, col_bg):setLabel(_S.options_window.customise)
:makeButton(0, 0, BTN_WIDTH, 30, nil, self.buttonCustomise):setTooltip(_S.tooltip.options_window.customise_button)
-- "Folders" button
self:addBevelPanel(165, lower_row_y_pos, BTN_WIDTH, 30, col_bg):setLabel(_S.options_window.folder)
:makeButton(0, 0, BTN_WIDTH, 30, nil, self.buttonFolder):setTooltip(_S.tooltip.options_window.folder_button)
-- "Hotkeys" button
self:addBevelPanel(320, lower_row_y_pos, BTN_WIDTH, 30, col_bg):setLabel(_S.options_window.hotkey)
:makeButton(0, 0, BTN_WIDTH, 30, nil, self.buttonHotkey):setTooltip(_S.tooltip.options_window.hotkey)
-- "Jukebox" button
self:addBevelPanel(465, lower_row_y_pos, BTN_WIDTH, 30, col_bg):setLabel(_S.options_window.jukebox)
:makeButton(0, 0, BTN_WIDTH, 30, nil, self.buttonJukebox):setTooltip(_S.tooltip.options_window.jukebox)
-- "Back" button
-- Give some extra space to back button. This is fine as long as it is the last button in the options menu
local back_button_y_pos = self:_getOptionYPos() + 20
self:addBevelPanel(175, back_button_y_pos, BTN_WIDTH * 2, 40, col_bg):setLabel(_S.options_window.back)
:makeButton(0, 0, 280, 40, nil, self.buttonBack):setTooltip(_S.tooltip.options_window.back)
end
-- Stubs for backward compatibility
local --[[persistable:options_window_language_button]] function language_button() end
local --[[persistable:options_width_textbox_reset]] function width_textbox_reset() end
local --[[persistable:options_height_textbox_reset]] function height_textbox_reset() end
function UIOptions:checkForAvailableLanguages()
local app = self.app
-- Set up list of available languages
local langs, c = {}, 1
for _, lang in pairs(app.strings.languages) do
local font = app.strings:getFont(lang)
local eng_name = app.strings.languages_english[lang]
c = c + 1
-- If freetype support and a unicode font setting are not present then
-- languages not supported by the builtin font are named in English and cannot be selected
if app.gfx:hasLanguageFont(font) then
font = font and app.gfx:loadLanguageFont(font, app.gfx:loadSpriteTable("QData", "Font01V"))
langs[#langs + 1] = { text = lang, name = lang, font = font, disabled = false,
tooltip = { _S.tooltip.options_window.language_dropdown_item:format(eng_name), nil, BTN_HEIGHT * c } }
else
langs[#langs + 1] = { text = eng_name, name = lang, font = self.builtin_font, disabled = true,
tooltip = { _S.tooltip.options_window.language_dropdown_no_font, nil, BTN_HEIGHT * c } }
end
end
self.available_languages = langs
end
function UIOptions:dropdownLanguage(activate)
if activate then
self:dropdownResolution(false)
self.language_dropdown = UIDropdown(self.ui, self, self.language_button, self.available_languages, self.selectLanguage)
self:addWindow(self.language_dropdown)
else
self.language_button:setToggleState(false)
if self.language_dropdown then
self.language_dropdown:close()
self.language_dropdown = nil
end
end
end
function UIOptions:selectLanguage(number)
local lang = self.app.strings.languages_english[self.available_languages[number].name]
local app = self.ui.app
app.config.language = (lang)
app:initLanguage()
app:saveConfig()
end
function UIOptions:dropdownResolution(activate)
if activate then
self:dropdownLanguage(false)
self.resolution_dropdown = UIDropdown(self.ui, self, self.resolution_button, self.available_resolutions, self.selectResolution)
self:addWindow(self.resolution_dropdown)
else
self.resolution_button:setToggleState(false)
if self.resolution_dropdown then
self.resolution_dropdown:close()
self.resolution_dropdown = nil
end
end
end
function UIOptions:selectResolution(number)
local res = self.available_resolutions[number]
local callback = --[[persistable:options_resolution_callback]] function(width, height)
if not self.ui:changeResolution(width, height) then
local err = {_S.errors.unavailable_screen_size}
self.ui:addWindow(UIInformation(self.ui, err))
end
self.resolution_panel:setLabel(self.ui.app.config.width .. "x" .. self.ui.app.config.height)
end
if res.custom then
self.resolution_panel:setLabel(self.ui.app.config.width .. "x" .. self.ui.app.config.height)
self.ui:addWindow(UIResolution(self.ui, callback))
else
callback(res.width, res.height)
end
end
--! Changes check for update setting to on/of
function UIOptions:toggleUpdateCheck()
self.ui.app.config.check_for_updates = not self.ui.app.config.check_for_updates
self.ui.app:saveConfig()
end
--! Function handles button toggle of checking for updates
function UIOptions:buttonUpdates()
self:toggleUpdateCheck()
local new_updates_string = self.ui.app.config.check_for_updates and
_S.options_window.option_enabled or _S.options_window.option_disabled
self.updates_panel:setLabel(new_updates_string)
end
function UIOptions:buttonFullscreen()
if not self.ui:toggleFullscreen() then
local err = {_S.errors.unavailable_screen_size}
self.ui:addWindow(UIInformation(self.ui, err))
self.fullscreen_button:toggle()
end
self.fullscreen_panel:setLabel(self.ui.app.fullscreen and _S.options_window.option_on or _S.options_window.option_off)
end
function UIOptions:buttonMouseCapture()
local app = self.ui.app
app.config.capture_mouse = not app.config.capture_mouse
app:saveConfig()
app:setCaptureMouse()
self.mouse_capture_button:setLabel(app.config.capture_mouse and _S.options_window.option_on or _S.options_window.option_off)
end
function UIOptions:buttonRightMouseScrolling()
local app = self.ui.app
app.config.right_mouse_scrolling = not app.config.right_mouse_scrolling
app:saveConfig()
self.right_mouse_scrolling_button:setLabel(app.config.right_mouse_scrolling and _S.options_window.right_mouse_scrolling_option_right or _S.options_window.right_mouse_scrolling_option_middle)
end
function UIOptions:buttonCustomise()
local window = UICustomise(self.ui, "menu")
self.ui:addWindow(window)
end
function UIOptions:buttonFolder()
local window = UIFolder(self.ui, "menu")
self.ui:addWindow(window)
end
function UIOptions:buttonHotkey()
local window = UIHotkeyAssign(self.ui, "menu")
self.ui:addWindow(window)
end
function UIOptions:buttonJukebox()
if self.app.config.audio and self.app:isAudioEnabled() then
self.ui:addWindow(UIJukebox(self.app))
end
end
function UIOptions:buttonBrowseForTHInstall()
local function callback(path)
local app = TheApp
app.config.theme_hospital_install = path
app:saveConfig()
debug.getregistry()._RESTART = true
app.running = false
end
local browser = UIDirectoryBrowser(self.ui, self.mode, _S.options_window.new_th_directory, "InstallDirTreeNode", callback)
self.ui:addWindow(browser)
end
function UIOptions:buttonAudioGlobal()
local app = self.ui.app
app.config.audio = not app.config.audio
app:saveConfig()
self.volume_button:setLabel(app.config.audio and _S.customise_window.option_on or _S.customise_window.option_off)
-- Reinit audio
app.audio:stopBackgroundTrack()
app.audio.has_bg_music = false
app.audio.not_loaded = not app.config.audio
app.audio.speech_file_name = nil
app.audio:init()
app:initLanguage()
end
function UIOptions:buttonScrollSpeed()
local callback = function(scrollspeed_number)
self.scrollspeed_panel : setLabel(tostring(scrollspeed_number))
self.scrollspeed_button : setToggleState(false)
end
self.ui:addWindow(UIScrollSpeed(self.ui, callback))
end
function UIOptions:buttonBack()
self:close()
end
function UIOptions:buttonShiftScrollSpeed()
local callback = function(shift_scrollspeed_number)
self.shift_scrollspeed_panel : setLabel( tostring(shift_scrollspeed_number) )
self.shift_scrollspeed_button : setToggleState(false)
end
self.ui:addWindow(UIShiftScrollSpeed(self.ui, callback))
end
function UIOptions:buttonBack()
self:close()
end
function UIOptions:buttonZoomSpeed()
local callback = function(zoomspeed_number)
self.zoomspeed_panel : setLabel( tostring(zoomspeed_number) )
self.zoomspeed_button : setToggleState(false)
end
self.ui:addWindow( UIZoomSpeed(self.ui, callback) )
end
function UIOptions:close()
UIResizable.close(self)
if self.mode == "menu" then
self.ui:addWindow(UIMainMenu(self.ui))
end
end
--! A custom resolution selection window
class "UIResolution" (UIResizable)
---@type UIResolution
local UIResolution = _G["UIResolution"]
function UIResolution:UIResolution(ui, callback)
self:UIResizable(ui, 200, 140, col_bg)
local app = ui.app
self.modal_class = "resolution"
self.on_top = true
self.esc_closes = true
self.resizable = false
self:setDefaultPosition(0.5, 0.5)
self.default_button_sound = "selectx.wav"
self.callback = callback
-- Window parts definition
-- Title
self:addBevelPanel(20, 10, 160, 20, col_caption):setLabel(_S.options_window.resolution)
.lowered = true
-- Textboxes
self:addBevelPanel(20, 40, 80, 20, col_shadow, col_bg, col_bg):setLabel(_S.options_window.width)
self.width_textbox = self:addBevelPanel(100, 40, 80, 20, col_textbox, col_highlight, col_shadow)
:setTooltip(_S.tooltip.options_window.width)
:makeTextbox():allowedInput("numbers"):characterLimit(4):setText(tostring(app.config.width))
self:addBevelPanel(20, 60, 80, 20, col_shadow, col_bg, col_bg):setLabel(_S.options_window.height)
self.height_textbox = self:addBevelPanel(100, 60, 80, 20, col_textbox, col_highlight, col_shadow)
:setTooltip(_S.tooltip.options_window.height)
:makeTextbox():allowedInput("numbers"):characterLimit(4):setText(tostring(app.config.height))
-- Apply and cancel
self:addBevelPanel(20, 90, 80, 40, col_bg):setLabel(_S.options_window.apply)
:makeButton(0, 0, 80, 40, nil, self.ok):setTooltip(_S.tooltip.options_window.apply)
self:addBevelPanel(100, 90, 80, 40, col_bg):setLabel(_S.options_window.cancel)
:makeButton(0, 0, 80, 40, nil, self.cancel):setTooltip(_S.tooltip.options_window.cancel)
end
function UIResolution:cancel()
self:close(false)
end
function UIResolution:ok()
local width, height = tonumber(self.width_textbox.text) or 0, tonumber(self.height_textbox.text) or 0
if width < 640 or height < 480 then
local err = {_S.errors.minimum_screen_size}
self.ui:addWindow(UIInformation(self.ui, err))
elseif width > 3000 or height > 2000 then
self.ui:addWindow(UIConfirmDialog(self.ui, false,
_S.confirmation.maximum_screen_size,
--[[persistable:maximum_screen_size_confirm_dialog]]function()
self:close(true)
self:close(false)
end
))
else
self:close(true)
end
end
--! Closes the resolution dialog
--!param ok (boolean or nil) whether the resolution entry was confirmed (true) or aborted (false)
function UIResolution:close(ok)
UIResizable.close(self)
if ok and self.callback then
self.callback(tonumber(self.width_textbox.text) or 0, tonumber(self.height_textbox.text) or 0)
end
end
--! A window for setting the scroll speed of the camera.
class "UIScrollSpeed" (UIResizable)
---@type UIScrollSpeed
local UIScrollSpeed = _G["UIScrollSpeed"]
function UIScrollSpeed:UIScrollSpeed(ui, callback)
self:UIResizable(ui, 200, 140, col_bg)
self.on_top = true
self.esc_closes = true
self.resizable = false
self:setDefaultPosition(0.5, 0.5)
self.default_button_sound = "selectx.wav"
self.scrollspeed_temp = 2
self.callback = callback
self:addBevelPanel(20, 10, 160, 20, col_caption):setLabel(_S.options_window.scrollspeed).lowered = true
self:addBevelPanel(20, 50, 90, 20, col_shadow, col_bg, col_bg):setLabel(_S.options_window.scrollspeed)
--
self.scrollspeed_textbox = self:addBevelPanel(110, 50, 70, 20, col_textbox, col_highlight, col_shadow)
:setTooltip(_S.tooltip.options_window.scrollspeed)
:makeTextbox():allowedInput("numbers"):characterLimit(4):setText(tostring(self.ui.app.config.scroll_speed))
--Apply and cancel.
self:addBevelPanel(20, 90, 80, 40, col_bg):setLabel(_S.options_window.apply)
:makeButton(0, 0, 80, 40, nil, self.ok):setTooltip(_S.tooltip.options_window.apply_scrollspeed)
self:addBevelPanel(100, 90, 80, 40, col_bg):setLabel(_S.options_window.cancel)
:makeButton(0, 0, 80, 40, nil, self.cancel):setTooltip(_S.tooltip.options_window.cancel_scrollspeed)
end
function UIScrollSpeed:ok()
self.scrollspeed_temp = tonumber(self.scrollspeed_textbox.text) or 2
if self.scrollspeed_temp < 1 then
self.scrollspeed_temp = 1
elseif self.scrollspeed_temp > 10 then
self.scrollspeed_temp = 10
end
self:close(true)
end
function UIScrollSpeed:cancel()
self:close(false)
end
--!param ok (boolean or nil) whether the resolution entry was confirmed (true) or aborted (false)
function UIScrollSpeed:close(ok)
UIResizable.close(self)
if ok then
self.scrollspeed_textbox.text = self.scrollspeed_temp or 2
self.ui.app.config.scroll_speed = self.scrollspeed_textbox.text
self.callback(self.scrollspeed_textbox.text)
else
self.callback(self.ui.app.config.scroll_speed)
end
end
--! A window for setting the scroll speed of the camera while pressing the SHIFT key..
class "UIShiftScrollSpeed" (UIResizable)
---@type UIShiftScrollSpeed
local UIShiftScrollSpeed = _G["UIShiftScrollSpeed"]
function UIShiftScrollSpeed:UIShiftScrollSpeed(ui, callback)
self:UIResizable(ui, 200, 140, col_bg)
self.on_top = true
self.esc_closes = true
self.resizable = false
self:setDefaultPosition(0.5, 0.5)
self.default_button_sound = "selectx.wav"
self.shift_scrollspeed_temp = 4
self.callback = callback
self:addBevelPanel(20, 10, 160, 20, col_caption):setLabel(_S.options_window.shift_scrollspeed).lowered = true
self:addBevelPanel(20, 50, 120, 20, col_shadow, col_bg, col_bg):setLabel(_S.options_window.shift_scrollspeed)
--
self.shift_scrollspeed_textbox = self:addBevelPanel(140, 50, 40, 20, col_textbox, col_highlight, col_shadow)
:setTooltip(_S.tooltip.options_window.shift_scrollspeed)
:makeTextbox():allowedInput("numbers"):characterLimit(4):setText(tostring(self.ui.app.config.shift_scroll_speed))
--Apply and cancel.
self:addBevelPanel(20, 90, 80, 40, col_bg):setLabel(_S.options_window.apply)
:makeButton(0, 0, 80, 40, nil, self.ok):setTooltip(_S.tooltip.options_window.apply_shift_scrollspeed)
self:addBevelPanel(100, 90, 80, 40, col_bg):setLabel(_S.options_window.cancel)
:makeButton(0, 0, 80, 40, nil, self.cancel):setTooltip(_S.tooltip.options_window.cancel_shift_scrollspeed)
end
function UIShiftScrollSpeed:ok()
self.shift_scrollspeed_temp = tonumber(self.shift_scrollspeed_textbox.text) or 4
if self.shift_scrollspeed_temp < 1 then
self.shift_scrollspeed_temp = 1
elseif self.shift_scrollspeed_temp > 10 then
self.shift_scrollspeed_temp = 10
end
self:close(true)
end
function UIShiftScrollSpeed:cancel()
self:close(false)
end
--!param ok (boolean or nil) whether the resolution entry was confirmed (true) or aborted (false)
function UIShiftScrollSpeed:close(ok)
UIResizable.close(self)
if ok then
self.shift_scrollspeed_textbox.text = self.shift_scrollspeed_temp or 4
self.ui.app.config.shift_scroll_speed = self.shift_scrollspeed_textbox.text
self.callback(self.shift_scrollspeed_textbox.text)
else
self.callback(self.ui.app.config.shift_scroll_speed)
end
end
--! Window to set the zoom speed of the scroll wheel while in-game.
class "UIZoomSpeed" (UIResizable)
---@type UIZoomSpeed
local UIZoomSpeed = _G["UIZoomSpeed"]
function UIZoomSpeed:UIZoomSpeed(ui, callback)
self:UIResizable(ui, 200, 140, col_bg)
self.on_top = true
self.esc_closes = true
self.resizable = false
self:setDefaultPosition(0.5, 0.5)
self.default_button_sound = "selectx.wav"
self.zoomspeed_temp = 80
self.callback = callback
--
self:addBevelPanel(20, 10, 160, 20, col_caption):setLabel(_S.options_window.zoom_speed).lowered = true
--
self:addBevelPanel(20, 50, 90, 20, col_shadow, col_bg, col_bg):setLabel(_S.options_window.zoom_speed)
--
self.zoomspeed_textbox = self:addBevelPanel(110, 50, 70, 20, col_textbox, col_highlight, col_shadow)
:setTooltip(_S.tooltip.options_window.zoom_speed)
:makeTextbox():allowedInput("numbers"):characterLimit(4):setText( tostring(self.ui.app.config.zoom_speed) )
--Apply and cancel.
self:addBevelPanel(20, 90, 80, 40, col_bg):setLabel(_S.options_window.apply)
:makeButton(0, 0, 80, 40, nil, self.ok):setTooltip(_S.tooltip.options_window.apply_zoomspeed)
self:addBevelPanel(100, 90, 80, 40, col_bg):setLabel(_S.options_window.cancel)
:makeButton(0, 0, 80, 40, nil, self.cancel):setTooltip(_S.tooltip.options_window.cancel_zoomspeed)
end
function UIZoomSpeed:ok()
self.zoomspeed_temp = tonumber( self.zoomspeed_textbox.text ) or 80
if self.zoomspeed_temp < 10 then
self.zoomspeed_temp = 10
elseif self.zoomspeed_temp > 1000 then
self.zoomspeed_temp = 1000
end
self:close(true)
end
function UIZoomSpeed:cancel()
self:close(false)
end
--!param ok (boolean or nil) whether the resolution entry was confirmed (true) or aborted (false)
function UIZoomSpeed:close(ok)
UIResizable.close(self)
if ok then
self.zoomspeed_textbox.text = self.zoomspeed_temp or 2
self.ui.app.config.zoom_speed = self.zoomspeed_textbox.text
self.callback(self.zoomspeed_textbox.text)
else
self.callback(self.ui.app.config.zoom_speed)
end
end