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

update inventory

git-svn-id: http://svn.net-core.org/repos/t-engine4@4613 51575b47-30f0-44d4-a5cc-537603b46e54
parent ba6373bf
No related branches found
No related tags found
No related merge requests found
......@@ -33,12 +33,19 @@ function _M:init(t)
self.w = assert(t.width, "no inventory width")
self.h = assert(t.height, "no inventory height")
self.tabslist = t.tabslist
self.filter = t.filter
self.fct = t.fct
self.on_select = t.select
self.on_select_tab = t.select_tab
self.on_drag = t.on_drag
self.on_drag_end = t.on_drag_end
if not self.tabslist and self.default_tabslist then
if type(self.default_tabslist) == "function" then self.tabslist = self.default_tabslist(self)
else self.tabslist = self.default_tabslist
end
end
Base.init(self, t)
end
......@@ -92,15 +99,17 @@ function _M:generate()
self:use(list[list.chars[c]])
end
end,
_TAB = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i+1, 1, #self.tabslist) self.c_tabs:onUse("left") end,
[{"_TAB","ctrl"}] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i-1, 1, self.tabslist) self.c_tabs:onUse("left", false) end,
_TAB = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i+1, 1, #self.tabslist) self.c_tabs:onUse("left") self.c_tabs:onSelect() end,
[{"_TAB","ctrl"}] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i-1, 1, self.tabslist) self.c_tabs:onUse("left", false) self.c_tabs:onSelect() end,
}
for i = 1, #self.tabslist do
self.key:addCommands{
['_F'..i] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i self.c_tabs:onUse("left") end,
[{'_F'..i,"ctrl"}] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i self.c_tabs:onUse("left", true) end,
['_F'..i] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i self.c_tabs:onUse("left") self.c_tabs:onSelect() end,
[{'_F'..i,"ctrl"}] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i self.c_tabs:onUse("left", true) self.c_tabs:onSelect() end,
}
end
self.c_inven:onSelect()
end
function _M:switchTab(filter)
......@@ -108,7 +117,9 @@ function _M:switchTab(filter)
for i, d in ipairs(self.tabslist) do
for k, e in pairs(filter) do if d[k] == e then
self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i self.c_tabs:onUse("left", false)
self.c_tabs.sel_j = 1 self.c_tabs.sel_i = i
self.c_tabs:onUse("left", false)
self.c_tabs:onSelect()
return
end end
end
......@@ -116,6 +127,7 @@ end
function _M:selectTab(item)
if self.on_select_tab then self.on_select_tab(item) end
self.c_inven:onSelect()
end
function _M:setInnerFocus(id)
......@@ -137,7 +149,7 @@ function _M:setInnerFocus(id)
end
function _M:on_focus(id, ui)
if self.on_select and ui then self.on_select(ui, ui.ui.inven, ui.ui.item, ui.ui:getItem()) end
-- if self.on_select and ui then self.on_select(ui, ui.ui.inven, ui.ui.item, ui.ui:getItem()) end
end
function _M:no_focus()
end
......
......@@ -44,17 +44,7 @@ function _M:init(title, actor, filter, action, on_select)
end
}
local tabslist = {
{image="metal-ui/inven_tabs/weapons.png", kind="weapons", desc="All kinds of weapons", filter=function(o) return not o.__transmo and (o.type == "weapon") end},
{image="metal-ui/inven_tabs/armors.png", kind="armors", desc="All kinds of armours", filter=function(o) return not o.__transmo and (o.type == "armor") end},
{image="metal-ui/inven_tabs/jewelry.png", kind="jewelry", desc="Rings and Amulets", filter=function(o) return not o.__transmo and (o.type == "jewelry") end},
{image="metal-ui/inven_tabs/gems.png", kind="gems", desc="Gems" , filter=function(o) return not o.__transmo and (o.type == "gem" or o.type == "alchemist-gem") end},
{image="metal-ui/inven_tabs/inscriptions.png", kind="inscriptions", desc="Infusions, Runes, ...", filter=function(o) return not o.__transmo and (o.type == "scroll") end},
{image="metal-ui/inven_tabs/misc.png", kind="misc", desc="Miscellaneous", filter="others"},
{image="metal-ui/inven_tabs/quests.png", kind="quests", desc="Quest and plot related items", filter=function(o) return not o.__transmo and (o.plot or o.quest) end},
}
if actor:attr("has_transmo") then tabslist[#tabslist+1] = {image="metal-ui/inven_tabs/chest.png", kind="transmo", desc="Transmogrification Chest", filter=function(o) return o.__transmo end} end
self.c_inven = Inventory.new{actor=actor, inven=actor:getInven("INVEN"), width=self.iw - 20 - self.c_doll.w, height=self.ih - 10, tabslist=tabslist,
self.c_inven = Inventory.new{actor=actor, inven=actor:getInven("INVEN"), width=self.iw - 20 - self.c_doll.w, height=self.ih - 10,
fct=function(item, sel, button, event) self:use(item, button, event) end,
on_select=function(item, sel) self:select(item) end,
on_drag=function(item) self:onDrag(item) end,
......
......@@ -18,21 +18,55 @@
-- darkgod@te4.org
require "engine.class"
local Base = require "engine.dialogs.ShowInventory"
local Dialog = require "engine.ui.Dialog"
local Inventory = require "engine.ui.Inventory"
local Textzone = require "engine.ui.Textzone"
local TextzoneList = require "engine.ui.TextzoneList"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(Base))
module(..., package.seeall, class.inherit(Dialog))
function _M:init(...)
Base.init(self, ...)
function _M:init(title, inven, filter, action, actor)
self.inven = inven
self.filter = filter
self.action = action
self.actor = actor
Dialog.init(self, title or "Inventory", math.max(800, game.w * 0.8), math.max(600, game.h * 0.8))
self.c_desc = TextzoneList.new{width=math.floor(self.iw / 2 - 10), height=self.ih, no_color_bleed=true}
self.c_inven = Inventory.new{actor=actor, inven=inven, filter=filter, width=math.floor(self.iw / 2 - 10), height=self.ih - 10,
fct=function(item, sel, button, event) self:use(item, button, event) end,
select=function(item, sel) self:select(item) end,
}
self.key.any_key = function(sym)
-- Control resets the tooltip
if (sym == self.key._LCTRL or sym == self.key._RCTRL) and self.cur_item then self.cur_item.desc = nil self:select(self.cur_item) end
end
for i, item in ipairs(self.list) do item.desc = nil end
self:loadUI{
{left=0, top=0, ui=self.c_inven},
{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_inven)
self:setupUI()
self:select(self.list[1])
self.key:addCommands{
__TEXTINPUT = function(c)
if self.list and self.list.chars[c] then
self:use(self.list[self.list.chars[c]])
end
end,
}
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:select(item)
......@@ -47,8 +81,18 @@ function _M:select(item)
end
end
function _M:use(item)
local dont_end = false
if item and item.object then
dont_end = self.action(item.object, item.item)
end
self.c_inven:generateList()
self:select(self.c_inven.c_inven.list[self.c_inven.c_inven.sel])
if not dont_end then game:unregisterDialog(self) end
end
function _M:updateTitle(title)
Base.updateTitle(self, title)
Dialog.updateTitle(self, title)
local green = colors.LIGHT_GREEN
local red = colors.LIGHT_RED
......@@ -64,7 +108,7 @@ function _M:updateTitle(title)
end
function _M:drawFrame(x, y, r, g, b, a)
Base.drawFrame(self, x, y, r, g, b, a)
Dialog.drawFrame(self, x, y, r, g, b, a)
if r == 0 then return end -- Drawing the shadow
if self.ui ~= "metal" then return end
if not self.title_fill then return end
......
......@@ -30,6 +30,7 @@ local DamageType = require "engine.DamageType"
local Faction = require "engine.Faction"
local Map = require "engine.Map"
local Tiles = require "engine.Tiles"
local InventoryUI = require "engine.ui.Inventory"
local ActorStats = require "engine.interface.ActorStats"
local ActorResource = require "engine.interface.ActorResource"
local ActorTalents = require "engine.interface.ActorTalents"
......@@ -258,6 +259,21 @@ Birther:loadDefinition("/data/birth/descriptors.lua")
-- Stores
Store:loadStores("/data/general/stores/basic.lua")
-- Inventory tabs
InventoryUI.default_tabslist = function(self)
local tabslist = {
{image="metal-ui/inven_tabs/weapons.png", kind="weapons", desc="All kinds of weapons", filter=function(o) return not o.__transmo and (o.type == "weapon") end},
{image="metal-ui/inven_tabs/armors.png", kind="armors", desc="All kinds of armours", filter=function(o) return not o.__transmo and (o.type == "armor") end},
{image="metal-ui/inven_tabs/jewelry.png", kind="jewelry", desc="Rings and Amulets", filter=function(o) return not o.__transmo and (o.type == "jewelry") end},
{image="metal-ui/inven_tabs/gems.png", kind="gems", desc="Gems" , filter=function(o) return not o.__transmo and (o.type == "gem" or o.type == "alchemist-gem") end},
{image="metal-ui/inven_tabs/inscriptions.png", kind="inscriptions", desc="Infusions, Runes, ...", filter=function(o) return not o.__transmo and (o.type == "scroll") end},
{image="metal-ui/inven_tabs/misc.png", kind="misc", desc="Miscellaneous", filter="others"},
{image="metal-ui/inven_tabs/quests.png", kind="quests", desc="Quest and plot related items", filter=function(o) return not o.__transmo and (o.plot or o.quest) end},
}
if self.actor:attr("has_transmo") then tabslist[#tabslist+1] = {image="metal-ui/inven_tabs/chest.png", kind="transmo", desc="Transmogrification Chest", filter=function(o) return o.__transmo end} end
return tabslist
end
------------------------------------------------------------------------
-- Count the number of talents per types
------------------------------------------------------------------------
......
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