Skip to content
Snippets Groups Projects
Commit 87d6403c authored by dg's avatar dg
Browse files

plop

git-svn-id: http://svn.net-core.org/repos/t-engine4@1359 51575b47-30f0-44d4-a5cc-537603b46e54
parent b24ab1e2
No related branches found
No related tags found
No related merge requests found
......@@ -124,7 +124,7 @@ function _M:resize(w, h, nogen)
local gamew, gameh = core.display.size()
self.w, self.h = math.floor(w), math.floor(h)
self.display_x = math.floor(self.force_x or (gamew - self.w) / 2)
self.display_y = math.floor(self.force_x or (gameh - self.h) / 2)
self.display_y = math.floor(self.force_y or (gameh - self.h) / 2)
self.ix, self.iy = 5, 22 + 3
self.iw, self.ih = w - 2 * 5, h - 8 - 22 - 3
......@@ -195,7 +195,7 @@ function _M:loadUI(t)
end
end
function _M:setupUI(resizex, resizey)
function _M:setupUI(resizex, resizey, on_resize)
local mw, mh = nil, nil
-- resizex, resizey = true, true
......@@ -218,8 +218,10 @@ function _M:setupUI(resizex, resizey)
mh = mh + addh + 5 + 22 + 3
-- print("===", mw, addw)
if on_resize then on_resize(resizex and mw or self.w, resizey and mh or self.h) end
self:resize(resizex and mw or self.w, resizey and mh or self.h)
else
if on_resize then on_resize(self.w, self.h) end
self:resize(self.w, self.h)
end
......
......@@ -73,6 +73,7 @@ function _M:generate()
-- Draw the list items
for i, item in ipairs(self.list) do
local color = item.color or {255,255,255}
local text = item[self.display_prop]
local ss = core.display.newSurface(fw, fh)
local sus = core.display.newSurface(fw, fh)
......@@ -81,15 +82,15 @@ function _M:generate()
ss:merge(ls, 0, 0)
for i = ls_w, fw - rs_w do ss:merge(ms, i, 0) end
ss:merge(rs, fw - rs_w, 0)
ss:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, 255, 255, 255, nil, fw - ls_w - rs_w)
ss:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, color[1], color[2], color[3], nil, fw - ls_w - rs_w)
s:erase(0, 0, 0)
s:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, 255, 255, 255, nil, fw - ls_w - rs_w)
s:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, color[1], color[2], color[3], nil, fw - ls_w - rs_w)
sus:merge(l, 0, 0)
for i = l_w, fw - r_w do sus:merge(m, i, 0) end
sus:merge(r, fw - r_w, 0)
sus:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, 255, 255, 255, nil, fw - ls_w - rs_w)
sus:drawColorStringBlended(self.font, text, ls_w, (fh - self.font_h) / 2, color[1], color[2], color[3], nil, fw - ls_w - rs_w)
item._tex, item._tex_w, item._tex_h = s:glTexture()
item._stex = ss:glTexture()
......
......@@ -18,57 +18,42 @@
-- darkgod@te4.org
require "engine.class"
require "engine.Dialog"
local Savefile = require "engine.Savefile"
require "engine.ui.Dialog"
local List = require "engine.ui.List"
local Map = require "engine.Map"
module(..., package.seeall, class.inherit(engine.Dialog))
module(..., package.seeall, class.inherit(engine.ui.Dialog))
function _M:init(mx, my, tmx, tmy)
self.tmx, self.tmy = util.bound(tmx, 0, game.level.map.w - 1), util.bound(tmy, 0, game.level.map.h - 1)
if tmx == game.player.x and tmy == game.player.y then self.on_player = true end
self.font = core.display.newFont("/data/font/Vera.ttf", 12)
self:generateList()
self.__showup = false
mx = mx - (self.max + 20) / 2
my = my - 30
engine.Dialog.init(self, "Actions", self.max + 20, self.maxh + 10 + 25, mx, my, nil, self.font)
self.sel = 1
self.scroll = 1
self.max = math.floor((self.ih - 45) / self.font_h) - 1
self:keyCommands(nil, {
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=0, y=0, w=game.w, h=game.h, mode={button=true}, norestrict=true, fct=function(button) if button == "left" then game:unregisterDialog(self) end end},
{ x=0, y=0, w=350, h=self.ih, fct=function(button, x, y, xrel, yrel, tx, ty, event)
if button ~= "wheelup" and button ~= "wheeldown" then
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
end
self.changed = true
local name = "Actions"
local w = self.font_bold:size(name)
engine.ui.Dialog.init(self, name, 1, 100, mx, my)
if button == "left" and event == "button" then self:use()
elseif button == "right" and event == "button" then
elseif button == "wheelup" and event == "button" then self.key:triggerVirtual("MOVE_UP")
elseif button == "wheeldown" and event == "button" then self.key:triggerVirtual("MOVE_DOWN")
end
end },
local list = List.new{width=math.max(w, self.max) + 10, nb_items=#self.list, list=self.list, fct=function(item) self:use(item) end}
self:loadUI{
{left=0, top=0, ui=list},
}
self:setupUI(true, true, function(w, h)
self.force_x = mx - w / 2
self.force_y = my - (self.h - self.ih + list.fh / 3)
end)
self.key:addBinds{ EXIT = function() game:unregisterDialog(self) end, }
end
function _M:use()
if not self.list[self.sel] then return end
function _M:use(item)
if not item then return end
game:unregisterDialog(self)
local act = self.list[self.sel].action
local act = item.action
if act == "move_to" then game.player:mouseMove(self.tmx, self.tmy)
elseif act == "change_level" then game.key:triggerVirtual("CHANGE_LEVEL")
......@@ -79,7 +64,7 @@ function _M:use()
elseif act == "inventory" then game.key:triggerVirtual("SHOW_INVENTORY")
elseif act == "rest" then game.key:triggerVirtual("REST")
elseif act == "talent" then
local d = self.list[self.sel]
local d = item
if d.set_target then
local a = game.level.map(self.tmx, self.tmy, Map.ACTOR)
if not a then a = {x=self.tmx, y=self.tmy, __no_self=true} end
......@@ -147,11 +132,3 @@ function _M:generateList()
self.list = list
end
function _M:drawDialog(s)
if #self.list == 0 then game:unregisterDialog(self) return end
local h = 2
self:drawSelectionList(s, 2, h, self.font_h, self.list, self.sel, "name")
self.changed = false
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