| 1 |
--[[ Copyright (c) 2010 Manuel "Roujin" Wolf |
| 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 |
--! Load Game Window |
| 22 |
class "UILoadGame" (UIFileBrowser) |
| 23 |
|
| 24 |
---@type UILoadGame |
| 25 |
local UILoadGame = _G["UILoadGame"] |
| 26 |
|
| 27 |
function UILoadGame:UILoadGame(ui, mode) |
| 28 |
local treenode = FilteredFileTreeNode(ui.app.savegame_dir, ".sav") |
| 29 |
treenode.label = "Saves" |
| 30 |
self:UIFileBrowser(ui, mode, _S.load_game_window.caption:format(".sav"), 295, |
| 31 |
treenode, true, _S.load_game_window.load_button) |
| 32 |
-- The most probable preference of sorting is by date - what you played last |
| 33 |
-- is the thing you want to play soon again. |
| 34 |
self.control:sortByDate() |
| 35 |
end |
| 36 |
|
| 37 |
function UILoadGame:choiceMade(name) |
| 38 |
local app = self.ui.app |
| 39 |
-- Make sure there is no blue filter active. |
| 40 |
app.video:setBlueFilterActive(false) |
| 41 |
|
| 42 |
local status, err = pcall(app.load, app, name) |
| 43 |
if not status then |
| 44 |
err = _S.errors.load_prefix .. err |
| 45 |
self:loadError(err) |
| 46 |
end |
| 47 |
end |
| 48 |
|
| 49 |
--! Output the error when trying to load a game |
| 50 |
--!param err The error given |
| 51 |
function UILoadGame:loadError(err) |
| 52 |
print(err) |
| 53 |
TheApp:loadMainMenu() |
| 54 |
TheApp.ui:addWindow(UIInformation(TheApp.ui, {err})) |
| 55 |
end |
| 56 |
|
| 57 |
function UILoadGame:close() |
| 58 |
UIResizable.close(self) |
| 59 |
if self.mode == "menu" then |
| 60 |
self.ui:addWindow(UIMainMenu(self.ui)) |
| 61 |
end |
| 62 |
end |