| 1 |
--[[ Copyright (c) 2013 Alan Woolley |
| 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 |
--! Options window used in the main menu and ingame. |
| 22 |
class "UIUpdate" (UIResizable) |
| 23 |
|
| 24 |
---@type UIUpdate |
| 25 |
local UIUpdate = _G["UIUpdate"] |
| 26 |
|
| 27 |
local col_bg = { |
| 28 |
red = 154, |
| 29 |
green = 146, |
| 30 |
blue = 198, |
| 31 |
} |
| 32 |
|
| 33 |
local col_old_version = { |
| 34 |
red = 255, |
| 35 |
green = 0, |
| 36 |
blue = 0, |
| 37 |
} |
| 38 |
|
| 39 |
local col_new_version = { |
| 40 |
red = 0, |
| 41 |
green = 255, |
| 42 |
blue = 0, |
| 43 |
} |
| 44 |
|
| 45 |
local col_shadow = { |
| 46 |
red = 134, |
| 47 |
green = 126, |
| 48 |
blue = 178, |
| 49 |
} |
| 50 |
|
| 51 |
local col_caption = { |
| 52 |
red = 174, |
| 53 |
green = 166, |
| 54 |
blue = 218, |
| 55 |
} |
| 56 |
|
| 57 |
function UIUpdate:UIUpdate(ui, this_version, new_version, brief_description, download_url) |
| 58 |
self:UIResizable(ui, 320, 320, col_bg) |
| 59 |
|
| 60 |
local app = ui.app |
| 61 |
self.modal_class = "main" |
| 62 |
self.on_top = true |
| 63 |
self.esc_closes = true |
| 64 |
self.resizable = false |
| 65 |
self:setDefaultPosition(0.5, 0.25) |
| 66 |
self.default_button_sound = "selectx.wav" |
| 67 |
self.description_text = brief_description |
| 68 |
self.app = app |
| 69 |
self.white_font = app.gfx:loadFontAndSpriteTable("QData", "Font01V", nil, nil, { apply_ui_scale = true }) |
| 70 |
self.download_url = download_url |
| 71 |
|
| 72 |
self:addBevelPanel(20, 50, 140, 20, col_shadow, col_bg, col_bg) |
| 73 |
:setLabel(_S.update_window.current_version).lowered = true |
| 74 |
self:addBevelPanel(20, 70, 140, 20, col_shadow, col_bg, col_bg) |
| 75 |
:setLabel(_S.update_window.new_version).lowered = true |
| 76 |
|
| 77 |
self:addBevelPanel (160,50,140,20, col_old_version, col_bg, col_bg):setLabel(this_version) |
| 78 |
self:addBevelPanel (160,70,140,20, col_new_version, col_bg, col_bg):setLabel(new_version) |
| 79 |
|
| 80 |
-- Title |
| 81 |
self:addBevelPanel(80, 10, 160, 20, col_caption):setLabel(_S.update_window.caption) |
| 82 |
.lowered = true |
| 83 |
|
| 84 |
-- Download button |
| 85 |
self:addBevelPanel(20, 225, 280, 40, col_bg):setLabel(_S.update_window.download) |
| 86 |
:makeButton(0, 0, 280, 40, nil, self.buttonDownload):setTooltip(_S.tooltip.update_window.download) |
| 87 |
|
| 88 |
-- Ignore button |
| 89 |
self:addBevelPanel(20, 270, 280, 40, col_bg):setLabel(_S.update_window.ignore) |
| 90 |
:makeButton(0, 0, 280, 40, nil, self.buttonIgnore):setTooltip(_S.tooltip.update_window.ignore) |
| 91 |
end |
| 92 |
|
| 93 |
function UIUpdate:draw(canvas, x, y) |
| 94 |
-- Draw window components |
| 95 |
UIResizable.draw(self, canvas, x, y) |
| 96 |
|
| 97 |
local s = TheApp.config.ui_scale |
| 98 |
|
| 99 |
-- Draw description |
| 100 |
x, y = self.x * s + x, self.y * s + y |
| 101 |
self.white_font:drawWrapped(canvas, self.description_text, x + 20 * s, y + 100 * s, (self.width - 20) * s) |
| 102 |
end |
| 103 |
|
| 104 |
function UIUpdate:buttonDownload() |
| 105 |
|
| 106 |
if self.app.os == "windows" then |
| 107 |
os.execute("start " .. self.download_url) |
| 108 |
elseif self.app.os == "macos" then |
| 109 |
os.execute("open " .. self.download_url) |
| 110 |
else |
| 111 |
os.execute("xdg-open " .. self.download_url) |
| 112 |
end |
| 113 |
|
| 114 |
end |
| 115 |
|
| 116 |
function UIUpdate:buttonIgnore() |
| 117 |
self:close() |
| 118 |
end |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|