Skip to content
Snippets Groups Projects
Commit 49086d25 authored by dg's avatar dg
Browse files

resolution switcher

git-svn-id: http://svn.net-core.org/repos/t-engine4@238 51575b47-30f0-44d4-a5cc-537603b46e54
parent f9664ea6
No related branches found
No related tags found
No related merge requests found
......@@ -138,6 +138,13 @@ function _M:setResolution(res)
if self.w ~= old_w or self.h ~= old_h then
self:onResolutionChange()
local restore = fs.getWritePath()
fs.setWritePath(engine.homepath)
local f = fs.open("/settings/resolution.cfg", "w")
f:write(("window.size = %q\n"):format(res))
f:close()
if restore then fs.setWritePath(restore) end
end
end
......
require "engine.class"
require "engine.Dialog"
module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init()
self:generateList()
engine.Dialog.init(self, "Switch Resolution", 300, #self.list * 30 + 20)
self.sel = 1
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" then self:use()
elseif button == "right" then
end
end },
}
end
function _M:use()
game:setResolution(self.list[self.sel].r)
game:unregisterDialog(self)
end
function _M:generateList()
local l = {}
for r, _ in pairs(game.available_resolutions) do
l[#l+1] = r
end
table.sort(l, function(a,b) return game.available_resolutions[a][1] < game.available_resolutions[b][1] end)
-- Makes up the list
local list = {}
local i = 0
for _, r in ipairs(l) do
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..r, r=r }
i = i + 1
end
self.list = list
end
function _M:drawDialog(s)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
end
......@@ -47,6 +47,11 @@ function _M:generateList(actions)
local menu = require("engine.dialogs.KeyBinder").new(game.normal_key)
game:registerDialog(menu)
end },
resolution = { "Display Resolution", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.DisplayResolution").new()
game:registerDialog(menu)
end },
save = { "Save Game", function() game:saveGame() end },
quit = { "Save and Exit", function() game:onQuit() end },
}
......
......@@ -144,6 +144,6 @@ function _M:drawDialog(s)
local selcol = {255,255,0}
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 200, 5, self.font_h, self.list, self.sel, "b1", self.scroll, self.max, col, self.selcol == 1 and selcol or col)
self:drawSelectionList(s, 400, 5, self.font_h, self.list, self.sel, "b2", self.scroll, self.max, col, self.selcol == 2 and selcol or col)
self:drawSelectionList(s, 230, 5, self.font_h, self.list, self.sel, "b1", self.scroll, self.max, col, self.selcol == 1 and selcol or col)
self:drawSelectionList(s, 430, 5, self.font_h, self.list, self.sel, "b2", self.scroll, self.max, col, self.selcol == 2 and selcol or col)
end
......@@ -17,15 +17,19 @@ engine.homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.
fs.setWritePath(fs.getUserPath())
fs.mkdir(fs.getHomePath())
fs.mkdir(fs.getHomePath().."/4.0/")
fs.mkdir(fs.getHomePath().."/4.0/settings/")
fs.setWritePath(fs.getHomePath())
-- Loads default config & user config
fs.mount(engine.homepath, "/")
config.loadString[[
keyboard.locale = "en_US"
window.size = "1024x768"
window.size = "800x600"
]]
config.load("/settings.cfg")
for i, file in ipairs(fs.list("/settings/")) do
if file:find(".cfg$") then
config.load("/settings/"..file)
end
end
-- Load default keys
engine.KeyBind:load("move,actions")
......
......@@ -452,7 +452,7 @@ function _M:setupCommands()
end,
EXIT = function()
local menu = require("engine.dialogs.GameMenu").new{"resume", "keybinds", "save", "quit"}
local menu = require("engine.dialogs.GameMenu").new{"resume", "keybinds", "resolution", "save", "quit"}
self:registerDialog(menu)
end,
}
......
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