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

plop

git-svn-id: http://svn.net-core.org/repos/t-engine4@1361 51575b47-30f0-44d4-a5cc-537603b46e54
parent 999afe6c
No related branches found
No related tags found
No related merge requests found
Showing
with 225 additions and 364 deletions
game/engines/default/data/gfx/ui/varsel-1-sel.png

383 B

game/engines/default/data/gfx/ui/varsel-2-sel.png

234 B

game/engines/default/data/gfx/ui/varsel-3-sel.png

378 B

game/engines/default/data/gfx/ui/varsel-4-sel.png

193 B

game/engines/default/data/gfx/ui/varsel-6-sel.png

193 B

game/engines/default/data/gfx/ui/varsel-7-sel.png

313 B

game/engines/default/data/gfx/ui/varsel-8-sel.png

221 B

game/engines/default/data/gfx/ui/varsel-9-sel.png

342 B

game/engines/default/data/gfx/ui/varsel-repeat-sel.png

182 B

...@@ -27,6 +27,13 @@ COMPLETED = 1 ...@@ -27,6 +27,13 @@ COMPLETED = 1
DONE = 100 DONE = 100
FAILED = 101 FAILED = 101
status_text = {
[PENDING] = "active",
[COMPLETED] = "completed",
[DONE] = "done",
[FAILED] = "failed",
}
function _M:init(q, who) function _M:init(q, who)
for k, e in pairs(q) do for k, e in pairs(q) do
self[k] = e self[k] = e
......
...@@ -113,7 +113,7 @@ function _M:doBuy(who, o, item, nb, store_dialog) ...@@ -113,7 +113,7 @@ function _M:doBuy(who, o, item, nb, store_dialog)
who.changed = true who.changed = true
self:onBuy(who, o, item, nb) self:onBuy(who, o, item, nb)
if store_dialog then store_dialog:updateStore() end if store_dialog then store_dialog:updateStore() end
end end) end end, "Buy", "Cancel")
end end
end end
...@@ -134,7 +134,7 @@ function _M:doSell(who, o, item, nb, store_dialog) ...@@ -134,7 +134,7 @@ function _M:doSell(who, o, item, nb, store_dialog)
who.changed = true who.changed = true
self:onSell(who, o, item, nb) self:onSell(who, o, item, nb)
if store_dialog then store_dialog:updateStore() end if store_dialog then store_dialog:updateStore() end
end end) end end, "Sell", "Cancel")
end end
end end
......
...@@ -18,51 +18,47 @@ ...@@ -18,51 +18,47 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local VariableList = require "engine.ui.VariableList"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(chat, id) function _M:init(chat, id)
self.cur_id = id self.cur_id = id
self.chat = chat self.chat = chat
self.npc = chat.npc self.npc = chat.npc
self.player = chat.player self.player = chat.player
engine.Dialog.init(self, self.npc.name, 500, 400) Dialog.init(self, self.npc.name, 500, 400)
self:generateList() self:generateList()
self.sel = 1 self.c_desc = Textzone.new{width=self.iw - 10, height=1, auto_height=true, no_color_bleed=true, text=self.text.."\n"}
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({ self:generateList()
self.c_list = VariableList.new{width=self.iw - 10, list=self.list, fct=function(item) self:use(item) end}
self:loadUI{
{left=0, top=0, ui=self.c_desc},
{left=0, bottom=0, ui=self.c_list},
{left=5, top=self.c_desc.h - 10, ui=Separator.new{dir="vertical", size=self.iw - 10}},
}
self:setFocus(self.c_list)
self:setupUI(false, true)
self.key:addCommands{
__TEXTINPUT = function(c) __TEXTINPUT = function(c)
if c:find("^[a-z]$") then if self.list and self.list.chars[c] then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list) self:use(self.list[self.list.chars[c]])
self:use()
end end
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,
})
self:mouseZones{
{ x=0, y=0, w=self.w, h=self.h, fct=function(button, x, y, xrel, yrel, tx, ty, event)
if self.start_answer_y and y >= self.start_answer_y then
ty = ty - self.start_answer_y
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
self.changed = true
if button == "left" and event == "button" then self:use()
elseif button == "right" and event == "button" then
end
end
end },
} }
end end
function _M:use(a) function _M:use(item, a)
a = a or self.chat:get(self.cur_id).answers[self.list[self.sel].answer] a = a or self.chat:get(self.cur_id).answers[item.answer]
if not a then return end if not a then return end
self.changed = true self.changed = true
...@@ -86,17 +82,17 @@ function _M:use(a) ...@@ -86,17 +82,17 @@ function _M:use(a)
end end
function _M:regen() function _M:regen()
self.changed = true game:unregisterDialog(self)
self:generateList() local d = new(self.chat, self.cur_id)
self.sel = 1 d.__showup = false
self.scroll = 1 game:registerDialog(d)
end end
function _M:resolveAuto() function _M:resolveAuto()
if not self.chat:get(self.cur_id).auto then return end if not self.chat:get(self.cur_id).auto then return end
for i, a in ipairs(self.chat:get(self.cur_id).answers) do for i, a in ipairs(self.chat:get(self.cur_id).answers) do
if not a.cond or a.cond(self.npc, self.player) then if not a.cond or a.cond(self.npc, self.player) then
if not self:use(a) then return if not self:use(nil, a) then return
else return self:resolveAuto() else return self:resolveAuto()
end end
end end
...@@ -107,31 +103,18 @@ function _M:generateList() ...@@ -107,31 +103,18 @@ function _M:generateList()
self:resolveAuto() self:resolveAuto()
-- Makes up the list -- Makes up the list
local list = {} local list = { chars={} }
local nb = 1 local nb = 1
for i, a in ipairs(self.chat:get(self.cur_id).answers) do for i, a in ipairs(self.chat:get(self.cur_id).answers) do
if not a.cond or a.cond(self.npc, self.player) then if not a.cond or a.cond(self.npc, self.player) then
list[#list+1] = { name=string.char(string.byte('a')+nb-1)..") "..a[1], answer=i, color=a.color} list[#list+1] = { name=string.char(string.byte('a')+nb-1)..") "..a[1], answer=i, color=a.color}
list.chars[string.char(string.byte('a')+nb-1)] = #list
nb = nb + 1 nb = nb + 1
end end
end end
self.list = list self.list = list
return true
end
function _M:drawDialog(s) self.text = self.chat:replace(self.chat:get(self.cur_id).text)
local h = 5
local lines = self.chat:replace(self.chat:get(self.cur_id).text):splitLines(self.iw - 10, self.font)
local r, g, b
for i = 1, #lines do
r, g, b = s:drawColorStringBlended(self.font, lines[i], 5, 2 + h, r, g, b)
h = h + self.font:lineSkip()
end
self:drawWBorder(s, 5, h + 0.5 * self.font:lineSkip(), self.iw - 10)
-- Answers return true
self.start_answer_y = h + 1.5 * self.font:lineSkip()
self:drawSelectionList(s, 5, h + 1.5 * self.font:lineSkip(), self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, self.iw - 10)
self.changed = false
end end
...@@ -18,46 +18,31 @@ ...@@ -18,46 +18,31 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local List = require "engine.ui.List"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init() function _M:init()
self:generateList() self:generateList()
engine.Dialog.init(self, "Switch Resolution", 300, #self.list * 30 + 20) Dialog.init(self, "Switch Resolution", 300, 20)
self.sel = 1 self.c_list = List.new{width=self.iw, nb_items=#self.list, list=self.list, fct=function(item) self:use(item) end}
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({ self:loadUI{
__TEXTINPUT = function(c) {left=0, top=0, ui=self.c_list},
if c:find("^[a-z]$") then }
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list) self:setFocus(self.c_list)
self:use() self:setupUI(false, true)
end
end, self.key:addBinds{
},{
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, 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=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty, event)
self.changed = true
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" and event == "button" then self:use()
elseif button == "right" and event == "button" then
end
end },
} }
end end
function _M:use() function _M:use(item)
game:setResolution(self.list[self.sel].r) game:setResolution(item.r)
game:unregisterDialog(self) game:unregisterDialog(self)
end end
...@@ -85,8 +70,3 @@ function _M:generateList() ...@@ -85,8 +70,3 @@ function _M:generateList()
end end
self.list = list self.list = list
end end
function _M:drawDialog(s)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self.chanegd = false
end
...@@ -18,47 +18,31 @@ ...@@ -18,47 +18,31 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local List = require "engine.ui.List"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(actions) function _M:init(actions)
self:generateList(actions) self:generateList(actions)
engine.Dialog.init(self, "Game Menu", 300, #self.list * 30 + 20) Dialog.init(self, "Game Menu", 300, 20)
self.sel = 1 self.c_list = List.new{width=self.iw, nb_items=#self.list, list=self.list, fct=function(item) self:use(item) end}
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({ self:loadUI{
__TEXTINPUT = function(c) {left=0, top=0, ui=self.c_list},
if c:find("^[a-z]$") then }
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list) self:setFocus(self.c_list)
self.changed = true self:setupUI(false, true)
self:use()
end self.key:addBinds{
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, 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=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty, event)
self.changed = true
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" and event == "button" then self:use()
elseif button == "right" and event == "button" then
end
end },
} }
end end
function _M:use() function _M:use(item)
self.list[self.sel].fct() item.fct()
end end
function _M:generateList(actions) function _M:generateList(actions)
...@@ -94,18 +78,13 @@ function _M:generateList(actions) ...@@ -94,18 +78,13 @@ function _M:generateList(actions)
for _, act in ipairs(actions) do for _, act in ipairs(actions) do
if type(act) == "string" then if type(act) == "string" then
local a = default_actions[act] local a = default_actions[act]
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..a[1], fct=a[2] } list[#list+1] = { name=a[1], fct=a[2] }
i = i + 1 i = i + 1
else else
local a = act local a = act
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..a[1], fct=a[2] } list[#list+1] = { name=a[1], fct=a[2] }
i = i + 1 i = i + 1
end end
end end
self.list = list self.list = list
end end
function _M:drawDialog(s)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self.changed = false
end
...@@ -18,70 +18,59 @@ ...@@ -18,70 +18,59 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local ListColumns = require "engine.ui.ListColumns"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(title) function _M:init(title)
local total = #world.achiev_defs local total = #world.achiev_defs
local nb = 0 local nb = 0
for id, data in pairs(world.achieved) do nb = nb + 1 end for id, data in pairs(world.achieved) do nb = nb + 1 end
engine.Dialog.init(self, (title or "Achievements").." ("..nb.."/"..total..")", game.w * 0.8, game.h * 0.8, nil, nil, nil, core.display.newFont("/data/font/VeraMono.ttf", 12)) Dialog.init(self, (title or "Achievements").." ("..nb.."/"..total..")", game.w * 0.8, game.h * 0.8)
self.c_desc = Textzone.new{width=math.floor(self.iw / 2 - 10), height=self.ih, text=""}
self:generateList() self:generateList()
self.sel = 1 self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, scrollbar=true, sortable=true, columns={
self.scroll = 1 {name="Achievement", width=60, display_prop="name", sort="name"},
self.max = math.floor((self.ih - 5) / self.font_h) - 1 {name="When", width=20, display_prop="when", sort="when"},
{name="Who", width=20, display_prop="who", sort="who"},
}, list=self.list, fct=function(item) end, select=function(item, sel) self:select(item) end}
self:loadUI{
{left=0, top=0, ui=self.c_list},
{right=0, top=0, ui=self.c_desc},
{hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
}
self:setFocus(self.c_list)
self:setupUI()
self:keyCommands({},{ self.key:addBinds{
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,
EXIT = function() game:unregisterDialog(self) 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=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.changed = true
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if 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 },
} }
end end
function _M:select(item)
if item then
self.uis[2].ui = item.zone
end
end
function _M:generateList() function _M:generateList()
-- Makes up the list -- Makes up the list
local list = {} local list = {}
local i = 0 local i = 0
for id, data in pairs(world.achieved) do for id, data in pairs(world.achieved) do
local a = world:getAchievementFromId(id) local a = world:getAchievementFromId(id)
list[#list+1] = { name=a.name, desc=a.desc, when=data.when, who=data.who, order=a.order } local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=("#GOLD#Achieved on:#LAST# %s\n#GOLD#Achieved by:#LAST# %s\n\n#GOLD#Description:#LAST# %s"):format(data.when, data.who, a.desc)}
list[#list+1] = { zone=zone, name=a.name, desc=a.desc, when=data.when, who=data.who, order=a.order }
i = i + 1 i = i + 1
end end
table.sort(list, function(a, b) return a.name < b.name end) table.sort(list, function(a, b) return a.name < b.name end)
self.list = list self.list = list
end end
function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local h = 2
if self.list[self.sel] then
local str = ("#GOLD#Achieved on:#LAST# %s\n#GOLD#Achieved by:#LAST# %s\n\n#GOLD#Description:#LAST# %s"):format(self.list[self.sel].when, self.list[self.sel].who, self.list[self.sel].desc)
lines = str:splitLines(self.iw / 2 - 10, self.font)
else
lines = {}
end
self:drawWBorder(s, self.iw / 2 + self.iw / 6, h - 0.5 * self.font:lineSkip(), self.iw / 6)
for i = 1, #lines do
s:drawColorStringBlended(self.font, lines[i], self.iw / 2 + 5, 2 + h)
h = h + self.font:lineSkip()
end
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5, true)
self.changed = false
end
...@@ -36,11 +36,11 @@ function _M:init(title, inven, filter, action, actor) ...@@ -36,11 +36,11 @@ function _M:init(title, inven, filter, action, actor)
self:generateList() self:generateList()
self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, scrollbar=true, columns={ self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, sortable=true, scrollbar=true, columns={
{name="", width=4, display_prop="char"}, {name="", width=4, display_prop="char", sort="id"},
{name="Inventory", width=68, display_prop="name"}, {name="Inventory", width=68, display_prop="name", sort="name"},
{name="Category", width=20, display_prop="cat"}, {name="Category", width=20, display_prop="cat", sort="cat"},
{name="Enc.", width=8, display_prop="encumberance"}, {name="Enc.", width=8, display_prop="encumberance", sort="encumberance"},
}, list=self.list, fct=function(item) self:use(item) end, select=function(item, sel) self:select(item) end} }, list=self.list, fct=function(item) self:use(item) end, select=function(item, sel) self:select(item) end}
self:loadUI{ self:loadUI{
...@@ -59,9 +59,6 @@ function _M:init(title, inven, filter, action, actor) ...@@ -59,9 +59,6 @@ function _M:init(title, inven, filter, action, actor)
end, end,
} }
self.key:addBinds{ self.key:addBinds{
ACCEPT = function()
self:use(self.c_list.list[self.c_list.sel])
end,
EXIT = function() game:unregisterDialog(self) end, EXIT = function() game:unregisterDialog(self) end,
} }
end end
......
...@@ -122,35 +122,3 @@ function _M:generateList() ...@@ -122,35 +122,3 @@ function _M:generateList()
self.c_list:generate() self.c_list:generate()
end end
end end
function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select an object; #00FF00#enter#FFFFFF# to use.
Mouse: #00FF00#Left click#FFFFFF# to pickup.
]]):splitLines(self.iw / 2 - 10, self.font)
local lines = {}
local h = 2
for i = 1, #talentshelp do
s:drawColorStringBlended(self.font, talentshelp[i], self.iw / 2 + 5, h)
h = h + self.font:lineSkip()
end
h = h + self.font:lineSkip()
if self.list[self.sel] then
lines = self.list[self.sel].object:getDesc():splitLines(self.iw / 2 - 10, self.font)
else
lines = {}
end
self:drawWBorder(s, self.iw / 2 + self.iw / 6, h - 0.5 * self.font:lineSkip(), self.iw / 6)
for i = 1, #lines do
s:drawColorStringBlended(self.font, lines[i], self.iw / 2 + 5, 2 + h)
h = h + self.font:lineSkip()
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5, true)
self.changed = false
end
...@@ -18,53 +18,60 @@ ...@@ -18,53 +18,60 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local ListColumns = require "engine.ui.ListColumns"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(actor) function _M:init(actor)
self.actor = actor self.actor = actor
actor.hotkey = actor.hotkey or {} Dialog.init(self, "Quest Log for "..actor.name, game.w, game.h)
engine.Dialog.init(self, "Quest Log for "..actor.name, game.w, game.h)
self.c_desc = Textzone.new{width=math.floor(self.iw / 2 - 10), height=self.ih, text=""}
self:generateList() self:generateList()
self.sel = 1 self.c_list = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, scrollbar=true, sortable=true, columns={
self.scroll = 1 {name="Quest", width=70, display_prop="name", sort="name"},
self.max = math.floor((self.ih - 5) / self.font_h) - 1 {name="Status", width=30, display_prop="status", sort="status_order"},
}, list=self.list, fct=function(item) end, select=function(item, sel) self:select(item) end}
self:keyCommands({ self:loadUI{
_t = function() {left=0, top=0, ui=self.c_list},
self.sel = 1 {right=0, top=0, ui=self.c_desc},
self.scroll = 1 {hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
self.show_ended = not self.show_ended }
self:generateList() self:setFocus(self.c_list)
self.changed = true print("plop") self:setupUI()
end, self:select(self.list[1])
},{ self.c_list:selectColumn(2)
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,
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=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty, event)
self.changed = true
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "wheelup" and event == "button" then self.key:triggerVirtual("MOVE_UP") self.key:addBinds{
elseif button == "wheeldown" and event == "button" then self.key:triggerVirtual("MOVE_DOWN") EXIT = function() game:unregisterDialog(self) end,
end
end },
} }
end end
function _M:select(item)
if item then
self.uis[2].ui = item.zone
end
end
function _M:generateList() function _M:generateList()
-- Makes up the list -- Makes up the list
local list = {} local list = {}
for id, q in pairs(self.actor.quests or {}) do for id, q in pairs(self.actor.quests or {}) do
if not q:isEnded() or self.show_ended then if true then
list[#list+1] = { name=q.name, quest=q, color = q:isCompleted() and {0,255,0} or nil } local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=q:desc(self.actor)}
local color = nil
if q:isStatus(q.COMPLETED) then color = colors.simple(colors.LIGHT_GREEN)
elseif q:isStatus(q.DONE) then color = colors.simple(colors.GREEN)
elseif q:isStatus(q.FAILED) then color = colors.simple(colors.RED)
end
list[#list+1] = { zone=zone, name=q.name, quest=q, color = color, status=q.status_text[q.status], status_order=q.status }
end end
end end
if game.turn then if game.turn then
...@@ -74,35 +81,3 @@ function _M:generateList() ...@@ -74,35 +81,3 @@ function _M:generateList()
end end
self.list = list self.list = list
end end
function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local r, g, b
local help = [[Keyboard: #00FF00#up key/down key#FFFFFF# to select a quest; #00FF00#t#FFFFFF# to toggle finished quests.
]]
local talentshelp = help:splitLines(self.iw / 2 - 10, self.font)
local lines = {}
if self.list[self.sel] then
lines = self.list[self.sel].quest:desc(self.actor):splitLines(self.iw / 2 - 10, self.font)
end
local h = 2
for i = 1, #talentshelp do
s:drawColorStringBlended(self.font, talentshelp[i], self.iw / 2 + 5, h)
h = h + self.font:lineSkip()
end
h = h + self.font:lineSkip()
self:drawWBorder(s, self.iw / 2 + self.iw / 6, h - 0.5 * self.font:lineSkip(), self.iw / 6)
for i = 1, #lines do
r, g, b = s:drawColorStringBlended(self.font, lines[i], self.iw / 2 + 5, 2 + h, r, g, b)
h = h + self.font:lineSkip()
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5, true)
self.changed = false
end
...@@ -18,9 +18,12 @@ ...@@ -18,9 +18,12 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local ListColumns = require "engine.ui.ListColumns"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, action, desc) function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, action, desc)
self.action = action self.action = action
...@@ -29,67 +32,69 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac ...@@ -29,67 +32,69 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
self.actor_inven = actor_inven self.actor_inven = actor_inven
self.store_filter = store_filter self.store_filter = store_filter
self.actor_filter = actor_filter self.actor_filter = actor_filter
engine.Dialog.init(self, title or "Store", game.w * 0.8, game.h * 0.8, nil, nil, nil, core.display.newFont("/data/font/VeraMono.ttf", 12)) Dialog.init(self, title or "Store", game.w * 0.8, game.h * 0.8)
self:generateList() self:generateList()
self.list = self.store_list self.c_inven = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.max_h*self.font_h - 10, sortable=true, scrollbar=true, columns={
self.sel = 1 {name="", width=4, display_prop="char", sort="id"},
self.scroll = 1 {name="Inventory", width=68, display_prop="name", sort="name"},
-- self.max = math.floor((self.ih * 0.8 - 5) / self.font_h) - 1 {name="Category", width=20, display_prop="cat", sort="cat"},
{name="Price", width=8, display_prop="cost", sort="cost"},
}, list=self.actor_list, fct=function(item, sel) self:use(item) end, select=function(item, sel) self:select(item) end}
self:keyCommands({ self.c_store = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.max_h*self.font_h - 10, sortable=true, scrollbar=true, columns={
{name="", width=4, display_prop="char", sort="id"},
{name="Store", width=68, display_prop="name"},
{name="Category", width=20, display_prop="cat"},
{name="Price", width=8, display_prop="cost", sort="cost"},
}, list=self.store_list, fct=function(item) self:use(item) end, select=function(item, sel) self:select(item) end}
self.c_desc = Textzone.new{width=self.iw, height=self.max_h*self.font_h, no_color_bleed=true, text=""}
self:loadUI{
{left=0, top=0, ui=self.c_store},
{right=0, top=0, ui=self.c_inven},
{left=0, bottom=0, ui=self.c_desc},
{hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - self.c_desc.h - 10}},
{left=5, bottom=self.c_desc.h, ui=Separator.new{dir="vertical", size=self.iw - 10}},
}
self:setFocus(self.c_inven)
self:setupUI()
self.key:addCommands{
__TEXTINPUT = function(c) __TEXTINPUT = function(c)
if c:find("^[a-z]$") then local list
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list) if self.focus_ui and self.focus_ui.ui == self.c_inven then list = self.c_inven.list
self:use() elseif self.focus_ui and self.focus_ui.ui == self.c_equip then list = self.c_equip.list
end
if list and list.chars[c] then
self:use(list[list.chars[c]])
end end
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, self.key:addBinds{
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,
MOVE_LEFT = function() self.list = self.store_list self.sel = util.bound(self.sel, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_RIGHT = function() self.list = self.actor_list self.sel = util.bound(self.sel, 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, 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=2, y=5, w=self.iw, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty, event)
if tx < self.iw / 2 then
self.list = self.store_list
else
self.list = self.actor_list
end
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
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 },
} }
end end
function _M:updateStore() function _M:updateStore()
self:generateList() self:generateList()
self.list = #self.store_list > 0 and self.store_list or self.actor_list
self.sel = util.bound(self.sel, 1, #self.list)
self.scroll = util.scroll(self.sel, self.scroll, self.max)
self.changed = true
end end
function _M:use() function _M:select(item)
if self.list[self.sel] then if item then
if self.list == self.store_list then self.uis[3].ui = item.zone
self.action("buy", self.list[self.sel].object, self.list[self.sel].item) end
end
function _M:use(item)
if item and item.object then
if self.focus_ui and self.focus_ui.ui == self.c_store then
self.action("buy", item.object, item.item)
self:updateStore() self:updateStore()
else else
self.action("sell", self.list[self.sel].object, self.list[self.sel].item) self.action("sell", item.object, item.item)
self:updateStore() self:updateStore()
end end
end end
...@@ -98,12 +103,16 @@ end ...@@ -98,12 +103,16 @@ end
function _M:generateList() function _M:generateList()
-- Makes up the list -- Makes up the list
local list = {} local list = {}
list.chars = {}
local i = 0 local i = 0
self.max_h = 0 self.max_h = 0
for item, o in ipairs(self.store_inven) do for item, o in ipairs(self.store_inven) do
if not self.store_filter or self.store_filter(o) then if not self.store_filter or self.store_filter(o) then
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item } local char = string.char(string.byte('a') + i)
local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()}
list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost }
self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font))
list.chars[char] = #list
i = i + 1 i = i + 1
end end
end end
...@@ -111,35 +120,24 @@ function _M:generateList() ...@@ -111,35 +120,24 @@ function _M:generateList()
-- Makes up the list -- Makes up the list
local list = {} local list = {}
list.chars = {}
local i = 0 local i = 0
for item, o in ipairs(self.actor_inven) do for item, o in ipairs(self.actor_inven) do
if not self.actor_filter or self.actor_filter(o) then if not self.actor_filter or self.actor_filter(o) then
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item } local char = string.char(string.byte('a') + i)
local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()}
list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost }
self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font))
list.chars[char] = #list
i = i + 1 i = i + 1
end end
end end
self.actor_list = list self.actor_list = list
self.max = math.floor((self.ih - 5) / self.font_h) - self.max_h
end
function _M:drawDialog(s)
if self.list[self.sel] then
lines = self.desc(self.list == self.store_list and "buy" or "sell", self.list[self.sel].object):splitLines(self.iw - 10, self.font)
else
lines = {}
end
local sh = self.ih - 4 - self.max_h * self.font:lineSkip() if self.c_inven then
h = sh self.c_inven.list = self.actor_list
self:drawWBorder(s, 3, sh, self.iw - 6) self.c_store.list = self.store_list
for i = 1, #lines do self.c_inven:generate()
s:drawColorStringBlended(self.font, lines[i], 5, 2 + h) self.c_store:generate()
h = h + self.font:lineSkip()
end end
self:drawSelectionList(s, 2, 5, self.font_h, self.store_list, self.list == self.store_list and self.sel or -1, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5, true)
self:drawHBorder(s, self.iw / 2, 2, sh - 4)
self:drawSelectionList(s, self.iw / 2 + 5, 5, self.font_h, self.actor_list, self.list == self.actor_list and self.sel or -1, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5, true)
self.changed = false
end end
...@@ -18,35 +18,29 @@ ...@@ -18,35 +18,29 @@
-- darkgod@te4.org -- darkgod@te4.org
require "engine.class" require "engine.class"
require "engine.Dialog" local Dialog = require "engine.ui.Dialog"
local Textzone = require "engine.ui.Textzone"
module(..., package.seeall, class.inherit(engine.Dialog)) module(..., package.seeall, class.inherit(Dialog))
function _M:init(title, file, replace, w, h) function _M:init(title, file, replace, w, h)
local rw, rh = w, h
w = math.floor(w or game.w * 0.6) w = math.floor(w or game.w * 0.6)
h = math.floor(h or game.h * 0.8) h = math.floor(h or game.h * 0.8)
self.iw = w - 2 * 5 -- Cheat, this is normaly done by Dialog:init but we need it to generate the list and we needto generate it before init Dialog.init(self, title or "Text", w, h)
self.font = core.display.newFont("/data/font/Vera.ttf", 12)
self:generateList(file, replace) self:generateList(file, replace)
h = math.min(4 + 30 + (#self.list) * self.font:lineSkip(), h)
engine.Dialog.init(self, title or "Text", w, h, nil, nil, nil, self.font) self.c_desc = Textzone.new{width=math.floor(self.iw - 10), height=self.ih, no_color_bleed=true, auto_height=true, text=self.text}
self.sel = 1 self:loadUI{
self.max = math.floor((self.ih - 5) / self.font_h) - 1 {left=0, top=0, ui=self.c_desc},
}
self:setupUI(not rw, not rh)
self:keyCommands({ self.key:addBinds{
},{ EXIT = function() game:unregisterDialog(self) end,
-- MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.changed = true end,
-- MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.changed = true end,
ACCEPT = function() game:unregisterDialog(self) end,
EXIT = "ACCEPT",
})
self:mouseZones{
{ x=0, y=0, w=game.w, h=game.h, mode={button=true}, norestrict=true, fct=function(button) if button ~= "none" then game:unregisterDialog(self) end end},
{ x=0, y=0, w=self.w, h=self.h, fct=function(button, x, y, xrel, yrel, tx, ty)
end },
} }
end end
...@@ -61,15 +55,6 @@ function _M:generateList(file, replace) ...@@ -61,15 +55,6 @@ function _M:generateList(file, replace)
return util.getval(replace[what]) return util.getval(replace[what])
end) end)
self.list = str:splitLines(self.iw - 10, self.font) self.text = str
return true return true
end end
function _M:drawDialog(s)
for ii = self.sel, #self.list do
local i = ii - self.sel + 1
if not self.list[i] or 4 + (i) * self.font:lineSkip() >= self.ih then break end
s:drawColorStringBlended(self.font, self.list[i], 5, 4 + (i-1) * self.font:lineSkip())
end
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