Skip to content
Snippets Groups Projects
Commit 29aa12f6 authored by DarkGod's avatar DarkGod
Browse files

UIs definitions are now loaded from files in /data/gfx/ui/definitions/ so that...

UIs definitions are now loaded from files in /data/gfx/ui/definitions/ so that addons can add new ones
parent a801604d
No related branches found
No related tags found
No related merge requests found
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 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
metal = {
frame_shadow = {x=15, y=15, a=0.5},
frame_alpha = 0.9,
frame_ox1 = -42,
frame_ox2 = 42,
frame_oy1 = -42,
frame_oy2 = 42,
title_bar = {x=0, y=-18, w=4, h=25},
}
stone = {
frame_shadow = {x=15, y=15, a=0.5},
frame_alpha = 1,
frame_ox1 = -42,
frame_ox2 = 42,
frame_oy1 = -42,
frame_oy2 = 42,
}
simple = {
frame_shadow = nil,
frame_alpha = 0.9,
frame_ox1 = -2,
frame_ox2 = 2,
frame_oy1 = -2,
frame_oy2 = 2,
}
parchment = {
frame_shadow = {x = 10, y = 10, a = 0.5},
frame_ox1 = -16,
frame_ox2 = 16,
frame_oy1 = -16,
frame_oy2 = 16,
}
tombstone = {
frame_shadow = {x = 10, y = 10, a = 0.5},
frame_ox1 = -16,
frame_ox2 = 16,
frame_oy1 = -16,
frame_oy2 = 16,
}
......@@ -266,6 +266,8 @@ end
function _M:unload()
end
function _M:cleanup()
end
function _M:drawWBorder(s, x, y, w)
for i = x, x + w do
......
......@@ -333,6 +333,7 @@ function _M:unregisterDialog(d)
if not self.dialogs[d] then return end
table.remove(self.dialogs, self.dialogs[d])
self.dialogs[d] = nil
d:cleanup()
d:unload()
-- Update positions
for i, id in ipairs(self.dialogs) do id.__stack_id = i self.dialogs[id] = i end
......
......@@ -21,6 +21,7 @@
require "engine.class"
local Dialog = require "engine.ui.Dialog"
local Savefile = require "engine.Savefile"
local UIBase = require "engine.ui.Base"
require "engine.PlayerProfile"
--- Handles dialog windows
......@@ -696,6 +697,11 @@ function _M:instanciate(mod, name, new_game, no_reboot)
self:loadAddons(mod, (save_desc and save_desc.addons) or (__module_extra_info.set_addons))
-- Now that addons are loaded we can load UI definitions
for _, file in ipairs(fs.list("/data/gfx/ui/definitions")) do
if file:find("%.lua$") then UIBase:loadUIDefinitions("/data/gfx/ui/definitions/"..file) end
end
-- Check addons
if hash_valid then
for name, add in pairs(mod.addons) do
......
......@@ -52,6 +52,7 @@ function _M:loaded()
local gl = nil
local islast = false
local sub_particle = nil
local sub_particle_args = nil
if type(self.def) == "string" then
local f, err = loadfile("/data/gfx/particles/"..self.def..".lua")
if not f and err then error(err) end
......@@ -64,6 +65,7 @@ function _M:loaded()
if t.alterscreen then islast = true end
if t.toback then self.toback = true end
if t.sub_particle then sub_particle = t.sub_particle end
if t.sub_particle_args then sub_particle_args = t.sub_particle_args end
else error("unsupported particle type: "..type(self.def))
end
......@@ -94,7 +96,7 @@ function _M:loaded()
self.ps = core.particles.newEmitter("/data/gfx/particles/"..self.def..".lua", args, self.zoom, config.settings.particles_density or 100, gl, sha, islast)
if sub_particle then
self:setSub(sub_particle)
self:setSub(sub_particle, 1, sub_particle_args)
end
end
......
......@@ -45,47 +45,15 @@ sounds = {
button = "ui/subtle_button_sound",
}
_M.ui_conf = {
metal = {
frame_shadow = {x=15, y=15, a=0.5},
frame_alpha = 0.9,
frame_ox1 = -42,
frame_ox2 = 42,
frame_oy1 = -42,
frame_oy2 = 42,
title_bar = {x=0, y=-21, w=4, h=25},
},
stone = {
frame_shadow = {x=15, y=15, a=0.5},
frame_alpha = 1,
frame_ox1 = -42,
frame_ox2 = 42,
frame_oy1 = -42,
frame_oy2 = 42,
},
simple = {
frame_shadow = nil,
frame_alpha = 0.9,
frame_ox1 = -2,
frame_ox2 = 2,
frame_oy1 = -2,
frame_oy2 = 2,
},
parchment = {
frame_shadow = {x = 10, y = 10, a = 0.5},
frame_ox1 = -16,
frame_ox2 = 16,
frame_oy1 = -16,
frame_oy2 = 16,
},
tombstone = {
frame_shadow = {x = 10, y = 10, a = 0.5},
frame_ox1 = -16,
frame_ox2 = 16,
frame_oy1 = -16,
frame_oy2 = 16,
},
}
_M.ui_conf = {}
function _M:loadUIDefinitions(file)
local f, err = loadfile(file)
if not f then print("Error while loading UI definition from", file, ":", err) return end
setfenv(f, self.ui_conf)
local ok, err = pcall(f)
if not f then print("Error while loading UI definition from", file, ":", err) return end
end
function _M:inherited(base)
if base._NAME == "engine.ui.Base" then
......@@ -117,6 +85,8 @@ function _M:init(t, no_gen)
if t.ui then self.ui = t.ui end
if not self.ui_conf[self.ui] then self.ui = "metal" end
if not no_gen then self:generate() end
end
......
......@@ -20,6 +20,7 @@
require "engine.class"
local KeyBind = require "engine.KeyBind"
local Base = require "engine.ui.Base"
local Particles = require "engine.Particles"
--- A generic UI button
module(..., package.seeall, class.inherit(Base))
......@@ -200,6 +201,7 @@ function _M:init(title, w, h, x, y, alpha, font, showup, skin)
end
self.color = self.color or {r=255, g=255, b=255}
if skin then self.ui = skin end
if not self.ui_conf[self.ui] then self.ui = "metal" end
local conf = self.ui_conf[self.ui]
self.frame = self.frame or {
......@@ -214,12 +216,15 @@ function _M:init(title, w, h, x, y, alpha, font, showup, skin)
b5 = "ui/dialogframe_5.png",
shadow = conf.frame_shadow,
a = conf.frame_alpha or 1,
particles = table.clone(conf.particles, true),
}
self.frame.ox1 = self.frame.ox1 or conf.frame_ox1
self.frame.ox2 = self.frame.ox2 or conf.frame_ox2
self.frame.oy1 = self.frame.oy1 or conf.frame_oy1
self.frame.oy2 = self.frame.oy2 or conf.frame_oy2
self.particles = {}
self.frame.title_x = 0
self.frame.title_y = 0
if conf.title_bar then
......@@ -537,9 +542,15 @@ end
function _M:display() end
--- This does nothing and can be changed by other classes
function _M:unload()
end
--- This provides required cleanups, do not touch
function _M:cleanup()
for p, _ in pairs(self.particles) do p:dieDisplay() end
end
function _M:drawFrame(x, y, r, g, b, a)
x = x + self.frame.ox1
y = y + self.frame.oy1
......@@ -557,13 +568,46 @@ function _M:drawFrame(x, y, r, g, b, a)
self.b6.t:toScreenFull(x + self.frame.w - self.b9.w, y + self.b7.h, self.b6.w, self.frame.h - self.b7.h - self.b1.h, self.b6.tw, self.b6.th, r, g, b, a)
-- Body
self.b5.t:toScreenFull(x + self.b7.w, y + self.b7.h, self.frame.w - self.b7.w - self.b3.w , self.frame.h - self.b7.h - self.b3.h, self.b6.tw, self.b6.th, r, g, b, a)
self.b5.t:toScreenFull(x + self.b7.w, y + self.b7.h, self.frame.w - self.b7.w - self.b3.w , self.frame.h - self.b7.h - self.b3.h, self.b5.tw, self.b5.th, r, g, b, a)
-- Overlays
for i = 1, #self.overs do
local ov = self.overs[i]
ov.t:toScreenFull(x + ov.x, y + ov.y, ov.w , ov.h, ov.tw, ov.th, r, g, b, a * ov.a)
end
if self.frame.particles then
for i, pdef in ipairs(self.frame.particles) do
if rng.chance(pdef.chance) then
local p = Particles.new(pdef.name, 1, pdef.args)
local pos = {x=0, y=0}
if pdef.position.base == 7 then
pos.x = pdef.position.ox
pos.y = pdef.position.oy
elseif pdef.position.base == 9 then
pos.x = self.w + pdef.position.ox + self.b9.w
pos.y = pdef.position.oy
elseif pdef.position.base == 1 then
pos.x = pdef.position.ox
pos.y = self.h + pdef.position.oy + self.b1.h
elseif pdef.position.base == 3 then
pos.x = self.w + pdef.position.ox + self.b3.w
pos.y = self.h + pdef.position.oy + self.b3.h
end
self.particles[p] = pos
end
end
end
if next(self.particles) then
for p, pos in pairs(self.particles) do
if p.ps:isAlive() then
p.ps:toScreen(x + pos.x, y + pos.y, true, 1)
else
self.particles[p] = nil
end
end
end
end
function _M:innerDisplayBack(x, y, nb_keyframes)
......
......@@ -103,6 +103,7 @@ end
-- @param k_skip A table containing key values set to true if you want to skip them.
-- @return The cloned table.
function table.clone(tbl, deep, k_skip)
if not tbl then return nil end
local n = {}
k_skip = k_skip or {}
for k, e in pairs(tbl) do
......
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