Skip to content
Snippets Groups Projects
Commit 9f69713c authored by DarkGod's avatar DarkGod
Browse files

plop

parent 0bf37e0a
No related branches found
No related tags found
No related merge requests found
......@@ -22,10 +22,11 @@ local KeyBind = require "engine.KeyBind"
local Base = require "engine.ui.Base"
local Particles = require "engine.Particles"
local Scrollbar = require "engine.ui.blocks.Scrollbar"
local LayoutEngine = require "engine.ui.LayoutEngine"
--- A generic UI Dialog
-- @classmod engine.ui.Dialog
module(..., package.seeall, class.inherit(Base))
module(..., package.seeall, class.inherit(Base, LayoutEngine))
--- Requests a simple waiter dialog
function _M:simpleWaiter(title, text, width, count, max)
......
......@@ -20,11 +20,12 @@
require "engine.class"
local Base = require "engine.ui.Base"
local Focusable = require "engine.ui.Focusable"
local LayoutEngine = require "engine.ui.LayoutEngine"
local KeyBind = require "engine.KeyBind"
--- A UI container that can host other UI elements and lay them out same as Dialog can
-- @classmod engine.ui.LayoutContainer
module(..., package.seeall, class.inherit(Base, Focusable))
module(..., package.seeall, class.inherit(Base, Focusable, LayoutEngine))
function _M:init(t)
if not t.uis then error("LayoutContainer needs uis") end
......@@ -286,49 +287,3 @@ function _M:on_focus_change(status)
self:moveSubFocus(1)
end
end
function _M:getNUI(name)
return self.nuis and self.nuis[name]
end
function _M:makeByLines(lines)
local uis = self.uis
local linew = self.iw
local y = 0
self.nuis = {}
for i, line in ipairs(lines) do
local x = 0
local max_h = 0
line.padding = line.padding or 10
for j, ui in ipairs(line) do
local forcew = nil
local args = table.clone(ui[2], true)
local use_w = 0
if ui.w then
local p1 = ((j > 1) and line[j-1].pos.ui.w or 0) + line.padding
local p2 = ((j > 2) and line[j-2].pos.ui.w or 0) + line.padding
local p3 = ((j > 3) and line[j-3].pos.ui.w or 0) + line.padding
local p4 = ((j > 4) and line[j-4].pos.ui.w or 0) + line.padding
local p5 = ((j > 5) and line[j-5].pos.ui.w or 0) + line.padding
local s = "return function(p1,p2,p3,p4,p5) return "..ui.w:gsub('%%', '*'..self.iw.."/100").." end"
s = loadstring(s)()
args.width = s(p1,p2,p3,p4,p5)
use_w = args.width
end
local class = ui[1]
if not class:find("%.") then class = "engine.ui."..class end
local c = require(class).new(args)
ui.pos = {left = x, top = y, ui=c}
uis[#uis+1] = ui.pos
x = x + math.max(c.w, use_w) + line.padding
max_h = math.max(max_h, c.h)
if ui[3] then self.nuis[ui[3]] = c end
end
if line.vcenter then
for j, ui in ipairs(line) do
ui.pos.top = y + math.floor((max_h - ui.pos.ui.h) / 2)
end
end
y = y + max_h + (line.vpadding or 3)
end
end
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2018 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
--- Allows a setup'able UI container (like Dialog & LayoutContainer) to spawn controls with paddings, layout, ...
-- @classmod engine.ui.LayoutEngine
module(..., package.seeall, class.make)
function _M:getNUI(name)
return self.nuis and self.nuis[name]
end
function _M:makeUIByLines(lines)
self.uis = {}
local uis = self.uis
local linew = self.iw
local y = 0
self.nuis = {}
for i, line in ipairs(lines) do
local x = 0
local max_h = 0
line.padding = line.padding or 10
if line.vpadding_up then y = y + line.vpadding_up end
for j, ui in ipairs(line) do
local forcew = nil
local args = table.clone(ui[2], true)
local use_w = 0
if ui.w then
local p1 = ((j > 1) and line[j-1].pos.ui.w or 0) + line.padding
local p2 = ((j > 2) and line[j-2].pos.ui.w or 0) + line.padding
local p3 = ((j > 3) and line[j-3].pos.ui.w or 0) + line.padding
local p4 = ((j > 4) and line[j-4].pos.ui.w or 0) + line.padding
local p5 = ((j > 5) and line[j-5].pos.ui.w or 0) + line.padding
local s = "return function(p1,p2,p3,p4,p5) return "..ui.w:gsub('%%', '*'..self.iw.."/100").." end"
s = loadstring(s)()
args.width = s(p1,p2,p3,p4,p5)
use_w = args.width
end
local class = ui[1]
if not class:find("%.") then class = "engine.ui."..class end
local c = require(class).new(args)
ui.pos = {left = x, top = y, ui=c}
uis[#uis+1] = ui.pos
x = x + math.max(c.w, use_w) + line.padding
max_h = math.max(max_h, c.h)
if ui[3] then self.nuis[ui[3]] = c end
end
if line.vcenter then
for j, ui in ipairs(line) do
ui.pos.top = y + math.floor((max_h - ui.pos.ui.h) / 2)
end
end
y = y + max_h + (line.vpadding or 3)
end
return self.nuis
end
This diff is collapsed.
......@@ -46,7 +46,7 @@ function _M:init()
self.c_desc = TextzoneList.new{width=math.floor((self.iw - self.vsep.w)/2), height=self.ih}
local tabs = {
{title=_t"Display", kind="video"},
{title=_t"Visual", kind="video"},
{title=_t"Audio", kind="audio"},
{title=_t"UI", kind="ui"},
{title=_t"Gameplay", kind="gameplay"},
......@@ -86,22 +86,49 @@ function _M:isTome()
return game.__mod_info.short_name == "tome"
end
function _M:saveNumberValue(name, fct)
function _M:saveNumberValue(name, fct, subv, factor)
return function(v)
if subv then v = v[subv] end
if factor then v = v * factor end
loadstring(("config.settings.%s = %d"):format(name, v))()
game:saveSettings(name, ("%s = %d\n"):format(name, v))
config.settings[name] = v
if fct then fct(v) end
end
end
function _M:saveBoolValue(name, fct)
function _M:saveFloatValue(name, fct, subv, factor)
return function(v)
if subv then v = v[subv] end
if factor then v = v * factor end
loadstring(("config.settings.%s = %d"):format(name, v))()
game:saveSettings(name, ("%s = %d\n"):format(name, v))
if fct then fct(v) end
end
end
function _M:saveBoolValue(name, fct, subv)
return function(v)
if subv then v = v[subv] end
loadstring(("config.settings.%s = %s"):format(name, v and "true" or "false"))()
game:saveSettings(name, ("%s = %s\n"):format(name, v and "true" or "false"))
config.settings[name] = v
if fct then fct(v) end
end
end
function _M:saveArrayValue(name, fct, subv)
return function(v)
if subv then v = v[subv] end
local f, s = self.save_array[name](v)
loadstring(("config.settings.%s = %s"):format(f, s))()
game:saveSettings(f, f.." = "..s.."\n")
if fct then fct(v) end
end
end
_M.save_array = {
["tome.fonts.type"] = function(v) return "tome.fonts", ("{ type = %q, size = %q }"):format(v, "normal") end,
}
function _M:switchTo(kind)
self['generateList'..kind:capitalize()](self)
self:triggerHook{"GameOptions2:generateList", list=self.list, kind=kind}
......@@ -121,12 +148,10 @@ function _M:switchTo(kind)
local resolutions, default_resolution = self:getResolutions()
local font_styles = FontPackage:list()
local default_font_style = table.findValueSub(font_styles, )
local default_font_style = table.findValueSub(font_styles, config.settings.tome.fonts.type, "id")
self.c_layout:makeByLines{
{
{"Header", {width=self.iw, text=_t"Resolution", color=colors.simple1(colors.GOLD)}},
},
self.c_layout:makeUIByLines{
{{"Header", {width=self.iw, text=_t"Display", color=colors.simple1(colors.GOLD)}}},
{ vcenter = true,
{ "Textzone", {auto_width=true, auto_height=true, text=_t"Mode: "}},
{w="40%-p1", "Dropdown", {default=default_mode, list=modes}, "resolution_mode"},
......@@ -135,24 +160,33 @@ function _M:switchTo(kind)
{w="20%", "Button", {text="Apply", fct=function() self:changeResolution() end}},
},
{ vcenter = true,
{w="40%", "NumberSlider", {title=_t"Max FPS: ", max=60, min=5, value=config.settings.display_fps, step=1, on_change=self:saveNumberValue("display_fps", function(v) core.game.setFPS(v) end)}},
{w="50%", "NumberSlider", {title=_t"Max FPS: ", max=60, min=5, value=config.settings.display_fps, step=1, on_change=self:saveNumberValue("display_fps", function(v) core.game.setFPS(v) end)}},
{w="50%", "NumberSlider", {title=_t"Gamma: ", max=300, min=50, value=config.settings.gamma_correction, step=5, on_change=self:saveNumberValue("gamma_correction", function(v) game:setGamma(v / 100) end)}},
},
{
{"Header", {width=self.iw, text=_t"Shaders", color=colors.simple1(colors.GOLD)}},
{ vcenter = true,
{w="50%", "NumberSlider", {title=_t"Zoom: ", max=400, min=50, value=config.settings.screen_zoom*100, step=5, on_change=self:saveFloatValue("screen_zoom", nil, nil, 1/100)}},
},
{{"Header", {width=self.iw, text=_t"Shaders", color=colors.simple1(colors.GOLD)}}, vpadding_up=20},
{ vcenter = true,
{w="33%", "Checkbox", {title=_t"Shaders: Advanced", default=config.settings.shaders_kind_adv, on_change=self:saveBoolValue("shaders_kind_adv")}},
{w="33%", "Checkbox", {title=_t"Shaders: Distortion", default=config.settings.shaders_kind_distort, on_change=self:saveBoolValue("shaders_kind_distort")}},
{w="33%", "Checkbox", {title=_t"Shaders: Volumetric", default=config.settings.shaders_kind_volumetric, on_change=self:saveBoolValue("shaders_kind_volumetric")}},
},
{
{"Header", {width=self.iw, text=_t"Fonts", color=colors.simple1(colors.GOLD)}},
},
{{"Header", {width=self.iw, text=_t"Fonts", color=colors.simple1(colors.GOLD)}}, vpadding_up=20},
{ vcenter = true,
{ "Textzone", {auto_width=true, auto_height=true, text=_t"Style: "}},
{w="40%-p1", "Dropdown", {default=default_resolution, list=resolutions}, "resolution_size"},
{w="50%-p1", "Dropdown", {default=default_font_style, list=font_styles, fct=self:saveArrayValue("tome.fonts.type", nil, "id")}},
{w="50%", "NumberSlider", {title=_t"Size: ", max=300, min=50, value=config.settings.font_scale, step=1, on_change=self:saveNumberValue("font_scale")}},
},
{{"Header", {width=self.iw, text=_t"Misc", color=colors.simple1(colors.GOLD)}}, vpadding_up=20},
{ vcenter = true,
{w="50%", "NumberSlider", {title=_t"Particle effects density: ", max=100, min=0, value=config.settings.particles_density, step=1, on_change=self:saveNumberValue("particles_density")}},
},
{ vcenter = true,
{w="50%", "Checkbox", {title=_t"Custom mouse cursor", default=config.settings.mouse_cursor, on_change=self:saveBoolValue("mouse_cursor")}},
},
}
......
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