| 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 |
--! Base class for 640x480px dialogs (fullscreen in original game resolution). |
| 22 |
class "UIFullscreen" (Window) |
| 23 |
|
| 24 |
---@type UIFullscreen |
| 25 |
local UIFullscreen = _G["UIFullscreen"] |
| 26 |
|
| 27 |
function UIFullscreen:UIFullscreen(ui) |
| 28 |
self:Window() |
| 29 |
|
| 30 |
self.esc_closes = true |
| 31 |
self.ui = ui |
| 32 |
self.modal_class = "fullscreen" |
| 33 |
|
| 34 |
self.width = 640 |
| 35 |
self.height = 480 |
| 36 |
|
| 37 |
self:onChangeResolution() |
| 38 |
end |
| 39 |
|
| 40 |
-- Cause all fullscreen windows to share a common saved window position. |
| 41 |
function UIFullscreen:getSavedWindowPositionName() |
| 42 |
return "UIFullscreen" |
| 43 |
end |
| 44 |
|
| 45 |
function UIFullscreen:onChangeResolution() |
| 46 |
local app = self.ui.app |
| 47 |
local s = app.config.ui_scale |
| 48 |
local sw = app.config.width / s |
| 49 |
local sh = app.config.height / s |
| 50 |
if sw > self.width or sh > self.height then |
| 51 |
if not self.border_sprites then |
| 52 |
self.border_sprites = app.gfx:loadSpriteTable("Bitmap", "aux_ui", true) |
| 53 |
end |
| 54 |
else |
| 55 |
self.border_sprites = nil |
| 56 |
end |
| 57 |
-- not draggable in actual fullscreen mode |
| 58 |
self.draggable = not not self.border_sprites |
| 59 |
|
| 60 |
local config = self.ui.app.runtime_config.window_position |
| 61 |
if config then |
| 62 |
config = config[self:getSavedWindowPositionName()] |
| 63 |
if config and config.x and config.y then |
| 64 |
return self:setPosition(config.x, config.y) |
| 65 |
end |
| 66 |
end |
| 67 |
|
| 68 |
self.x = math.floor((sw - self.width) / 2) |
| 69 |
|
| 70 |
-- NB: Bottom panel is 48 pixels high |
| 71 |
if sh > 480 + 48 then |
| 72 |
self.y = math.floor((sh - 48 - self.height) / 2) |
| 73 |
elseif app.config.height >= 480 then |
| 74 |
self.y = 0 |
| 75 |
else |
| 76 |
self.y = math.floor((sh - self.height) / 2) |
| 77 |
end |
| 78 |
end |
| 79 |
|
| 80 |
function UIFullscreen:draw(canvas, x, y) |
| 81 |
local sprites = self.border_sprites |
| 82 |
if sprites then |
| 83 |
local s = TheApp.config.ui_scale |
| 84 |
local draw = sprites.draw |
| 85 |
local scr_x = self.x * s + x |
| 86 |
local scr_y = self.y * s + y |
| 87 |
canvas:nonOverlapping(true) |
| 88 |
draw(sprites, canvas, 10, scr_x - 9 * s, scr_y - 9 * s, { scaleFactor = s }) |
| 89 |
draw(sprites, canvas, 12, scr_x + 600 * s, scr_y - 9 * s, { scaleFactor = s }) |
| 90 |
draw(sprites, canvas, 15, scr_x - 9 * s, scr_y + 440 * s, { scaleFactor = s }) |
| 91 |
draw(sprites, canvas, 17, scr_x + 600 * s, scr_y + 440 * s, { scaleFactor = s }) |
| 92 |
for loop_x = scr_x + 40 * s, scr_x + 560 * s, 40 * s do |
| 93 |
draw(sprites, canvas, 11, loop_x, scr_y - 9 * s, { scaleFactor = s }) |
| 94 |
draw(sprites, canvas, 16, loop_x, scr_y + 480 * s, { scaleFactor = s }) |
| 95 |
end |
| 96 |
for loop_y = scr_y + 40 * s, scr_y + 400 * s, 40 * s do |
| 97 |
draw(sprites, canvas, 13, scr_x - 9 * s, loop_y, { scaleFactor = s }) |
| 98 |
draw(sprites, canvas, 14, scr_x + 640 * s, loop_y, { scaleFactor = s }) |
| 99 |
end |
| 100 |
canvas:nonOverlapping(false) |
| 101 |
end |
| 102 |
return Window.draw(self, canvas, x, y) |
| 103 |
end |
| 104 |
|
| 105 |
function UIFullscreen:onMouseDown(button, x, y) |
| 106 |
local repaint = Window.onMouseDown(self, button, x, y) |
| 107 |
local s = TheApp.config.ui_scale |
| 108 |
if button == "left" and not repaint and not (x >= 0 and y >= 0 and |
| 109 |
x < self.width * s and y < self.height * s) and self:hitTest(x, y) then |
| 110 |
return self:beginDrag(x, y) |
| 111 |
end |
| 112 |
return repaint |
| 113 |
end |
| 114 |
|
| 115 |
function UIFullscreen:hitTest(x, y) |
| 116 |
local s = TheApp.config.ui_scale |
| 117 |
if x >= 0 and y >= 0 and x < self.width * s and y < self.height * s then |
| 118 |
return true |
| 119 |
end |
| 120 |
local sprites = self.border_sprites |
| 121 |
if not sprites then |
| 122 |
return false |
| 123 |
end |
| 124 |
if x < -9 * s or y < -9 * s or x >= self.width * s + 9 * s or y >= self.height * s + 9 * s then |
| 125 |
return false |
| 126 |
end |
| 127 |
if (0 <= x and x < self.width * s) or (0 <= y and y < self.height * s) then |
| 128 |
return true |
| 129 |
end |
| 130 |
|
| 131 |
return sprites.hitTest(sprites, 10, x + 9 * s, y + 9 * s) or |
| 132 |
sprites.hitTest(sprites, 12, x - 600 * s, y + 9 * s) or |
| 133 |
sprites.hitTest(sprites, 15, x + 9 * s, y - 440 * s) or |
| 134 |
sprites.hitTest(sprites, 17, x - 600 * s, y - 440 * s) |
| 135 |
end |
| 136 |
|
| 137 |
function UIFullscreen:afterLoad(old, new) |
| 138 |
Window.afterLoad(self, old, new) |
| 139 |
if old < 22 then |
| 140 |
self.draggable = not not self.border_sprites |
| 141 |
end |
| 142 |
end |