Skip to content
Snippets Groups Projects
Commit 05cf1fe9 authored by dg's avatar dg
Browse files

To upgrade to the new resolution switch simply remove your...

To upgrade to the new resolution switch simply remove your Game:onResolutionChange() method it's not needed anymore.


git-svn-id: http://svn.net-core.org/repos/t-engine4@1437 51575b47-30f0-44d4-a5cc-537603b46e54
parent cdff021b
No related branches found
No related tags found
No related merge requests found
......@@ -275,9 +275,34 @@ end
--- Called when screen resolution changes
function _M:onResolutionChange()
if game and not self.change_res_dialog_oldw then
self.change_res_dialog_oldw, self.change_res_dialog_oldh = self.w, self.h
end
self.w, self.h = core.display.size()
config.settings.window.size = ("%dx%d"):format(self.w, self.h)
self:saveSettings("resolution", ("window.size = '%s'\n"):format(config.settings.window.size))
print("[RESOLUTION] changed to ", self.w, self.h)
-- We do not even have a game yet
if not game then return end
-- Do not repop if we just revert back
if self.change_res_dialog and type(self.change_res_dialog) == "string" and self.change_res_dialog == "revert" then return end
-- Unregister old dialog if there was one
if self.change_res_dialog and type(self.change_res_dialog) == "table" then self:unregisterDialog(self.change_res_dialog) end
-- Ask if we want to switch
self.change_res_dialog = require("engine.ui.Dialog"):yesnoPopup("Resolution changed", "Accept the new resolution?", function(ret)
if ret then
if not self.creating_player then self:saveGame() end
util.showMainMenu(false, nil, nil, self.__mod_info.short_name, self.save_name, false)
else
self.change_res_dialog = "revert"
self:setResolution(self.change_res_dialog_oldw.."x"..self.change_res_dialog_oldh, true)
self.change_res_dialog = nil
self.change_res_dialog_oldw, self.change_res_dialog_oldh = nil, nil
end
end, "Accept", "Revert")
end
--- Requests the game to save
......
......@@ -63,7 +63,7 @@ function _M:yesnoPopup(title, text, fct, yes_text, no_text)
local tw, th = self.font:size(title:removeColorCodes())
local d = new(title, math.max(w, tw) + 35, h + 75)
d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end)
-- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end)
local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true) end}
local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false) end}
d:loadUI{
......@@ -83,7 +83,7 @@ function _M:yesnoLongPopup(title, text, w, fct, yes_text, no_text)
local list = text:splitLines(w - 10, font)
local d = new(title, w + 20, #list * self.font_h + 75)
d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end)
-- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end)
local ok = require("engine.ui.Button").new{text=yes_text or "Yes", fct=function() game:unregisterDialog(d) fct(true) end}
local cancel = require("engine.ui.Button").new{text=no_text or "No", fct=function() game:unregisterDialog(d) fct(false) end}
d:loadUI{
......
......@@ -94,6 +94,7 @@ function _M:newGame()
Map:setViewerActor(self.player)
self:setupDisplayMode()
self.creating_player = true
local birth = Birther.new(self.player, {"base", "role" }, function()
self:changeLevel(1, "dungeon")
print("[PLAYER BIRTH] resolve...")
......@@ -101,6 +102,7 @@ function _M:newGame()
self.player:resolve(nil, true)
self.player.energy.value = self.energy_to_act
self.paused = true
self.creating_player = false
print("[PLAYER BIRTH] resolved!")
end)
self:registerDialog(birth)
......@@ -114,22 +116,6 @@ function _M:loaded()
self.key = engine.KeyBind.new()
end
function _M:onResolutionChange()
local oldw, oldh = self.w, self.h
engine.Game.onResolutionChange(self)
print("[RESOLUTION] changed to ", self.w, self.h)
if not self.change_res_dialog then
self.change_res_dialog = Dialog:yesnoPopup("Resolution changed", "Accept the new resolution?", function(ret)
self.change_res_dialog = nil
if ret then
util.showMainMenu(false, nil, nil, "boot", "boot", false)
else
self:setResolution(oldw.."x"..oldh, true)
end
end, "Accept", "Revert")
end
end
function _M:setupDisplayMode()
print("[DISPLAY MODE] 32x32 ASCII/background")
Map:setViewPort(200, 20, self.w - 200, math.floor(self.h * 0.80) - 20, 32, 32, nil, 22, true, true)
......
......@@ -94,6 +94,7 @@ function _M:newGame()
Map:setViewerActor(self.player)
self:setupDisplayMode()
self.creating_player = true
local birth = Birther.new(self.player, {"base", "role" }, function()
self:changeLevel(1, "dungeon")
print("[PLAYER BIRTH] resolve...")
......@@ -101,6 +102,7 @@ function _M:newGame()
self.player:resolve(nil, true)
self.player.energy.value = self.energy_to_act
self.paused = true
self.creating_player = false
print("[PLAYER BIRTH] resolved!")
end)
self:registerDialog(birth)
......@@ -114,22 +116,6 @@ function _M:loaded()
self.key = engine.KeyBind.new()
end
function _M:onResolutionChange()
local oldw, oldh = self.w, self.h
engine.Game.onResolutionChange(self)
print("[RESOLUTION] changed to ", self.w, self.h)
if not self.change_res_dialog then
self.change_res_dialog = Dialog:yesnoPopup("Resolution changed", "Accept the new resolution?", function(ret)
self.change_res_dialog = nil
if ret then
util.showMainMenu(false, nil, nil, "boot", "boot", false)
else
self:setResolution(oldw.."x"..oldh, true)
end
end, "Accept", "Revert")
end
end
function _M:setupDisplayMode()
print("[DISPLAY MODE] 32x32 ASCII/background")
Map:setViewPort(200, 20, self.w - 200, math.floor(self.h * 0.80) - 20, 32, 32, nil, 22, true, true)
......
......@@ -132,6 +132,7 @@ function _M:newGame()
self.always_target = true
self.creating_player = true
local birth; birth = Birther.new(self.player, {"base", "difficulty", "world", "race", "subrace", "sex", "class", "subclass" }, function()
-- Save for quick birth
local save = Savefile.new(self.save_name)
......@@ -157,6 +158,7 @@ function _M:newGame()
self.player:onBirth(birth)
-- For quickbirth
savefile_pipe:push("", "entity", self.player)
self.creating_player = false
end, true))
end
......@@ -214,23 +216,6 @@ function _M:createSeparators()
self.player_separator, self.player_separator_w, self.player_separator_h = self:createVisualSeparator("vertical", math.floor(self.h * 0.8) - 20)
end
function _M:onResolutionChange()
local oldw, oldh = self.w, self.h
engine.Game.onResolutionChange(self)
print("[RESOLUTION] changed to ", self.w, self.h)
if self.change_res_dialog and type(self.change_res_dialog) == "table" then self:unregisterDialog(self.change_res_dialog) end
self.change_res_dialog = Dialog:yesnoPopup("Resolution changed", "Accept the new resolution?", function(ret)
if ret then
self:saveGame()
util.showMainMenu(false, nil, nil, self.__mod_info.short_name, self.save_name, false)
else
self.change_res_dialog = nil
self:setResolution(oldw.."x"..oldh, true)
end
end, "Accept", "Revert")
end
function _M:setupDisplayMode(reboot)
self.gfxmode = self.gfxmode or (config.settings.tome and config.settings.tome.gfxmode) or 1
self:saveSettings("tome.gfxmode", ("tome.gfxmode = %d\n"):format(self.gfxmode))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment