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

Inventory window now displays a currently equiped compare tooltip if available

git-svn-id: http://svn.net-core.org/repos/t-engine4@2484 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5d3342b8
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ tiles = engine.Tiles.new(16, 16)
function _M:init(fontname, fontsize, color, bgcolor, max)
self.color = color or {255,255,255}
self.bgcolor = bgcolor or {0,0,0}
self.bgcolor[4] = self.bgcolor[4] or 200
self.font = core.display.newFont(fontname or "/data/font/Vera.ttf", fontsize or 12)
self.font_h = self.font:lineSkip()
self.max = max or 300
......@@ -67,7 +68,7 @@ function _M:display()
self.surface = core.display.newSurface(self.w, self.h)
-- Erase and the display the tooltip
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3], 200)
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3], self.bgcolor[4])
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_7.png"), 0, 0)
self.surface:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_9.png"), self.w - 8, 0)
......
......@@ -34,7 +34,6 @@ function _M:init(title, actor, filter, action, on_select)
Dialog.init(self, title or "Inventory", math.max(800, game.w * 0.8), math.max(600, game.h * 0.8))
-- self:maxH()
self.max_h = 0
-- self.c_desc = TextzoneList.new{width=self.iw, height=self.max_h*self.font_h, no_color_bleed=true}
......@@ -47,9 +46,9 @@ function _M:init(title, actor, filter, action, on_select)
{name="Enc.", width=8, display_prop="encumberance", sort="encumberance"},
}, list={}, fct=function(item, sel, button, event) self:use(item, button, event) end, select=function(item, sel) self:select(item) end}
self.c_equip = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.max_h*self.font_h - 10, scrollbar=true, columns={
self.c_equip = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.max_h*self.font_h - 10, item_height=32, scrollbar=true, columns={
{name="", width={20,"fixed"}, display_prop="char"},
{name="", width={24,"fixed"}, display_prop="object", direct_draw=function(item, x, y) if item.object then item.object:toScreen(nil, x+4, y, 16, 16) end end},
{name="", width={8+32,"fixed"}, display_prop="object", direct_draw=function(item, x, y) if item.object then item.object:toScreen(nil, x+4, y, 64, 64) end end},
{name="Equipment", width=72, display_prop="name"},
{name="Category", width=20, display_prop="cat"},
{name="Enc.", width=8, display_prop="encumberance"},
......@@ -140,7 +139,6 @@ end
function _M:select(item)
if item then
-- self.c_desc:switchItem(item, item.desc)
if self.on_select then self.on_select(item) end
end
end
......@@ -205,21 +203,6 @@ function _M:generateList()
self.c_equip:setList(self.equip_list)
end
function _M:maxH()
self.max_h = 0
for inven_id = 1, #self.actor.inven_def do
if self.actor.inven[inven_id] and self.actor.inven_def[inven_id].is_worn then
self.max_h = math.max(self.max_h, #self.actor.inven_def[inven_id].description:splitLines(self.iw - 10, self.font))
end
end
local i = 1
for item, o in ipairs(self.actor:getInven("INVEN")) do
if not self.filter or self.filter(o) then
self.max_h = math.max(self.max_h, o:getDesc():splitLines(self.iw - 10, self.font):countLines())
end
end
end
function _M:on_recover_focus()
self:generateList()
end
......@@ -70,6 +70,27 @@ function _M:targetDisplayTooltip(dx, dy)
end
self.old_tmx, self.old_tmy = tmx, tmy
end
if not self.tooltip2 then return end
-- Tooltip is displayed over all else
if self.level and self.level.map and self.level.map.finished then
-- Display a tooltip if available
if self.tooltip2_x then
if type(self.tooltip2_x) == "table" then
self.tooltip2:toScreen(self.tooltip2.last_display_x, self.tooltip2.last_display_y)
else
local tmx, tmy = self.level.map:getMouseTile(self.tooltip2_x , self.tooltip2_y)
self.tooltip2:displayAtMap(tmx, tmy, dx, dy)
end
end
-- Move target around
if self.old_tmx ~= tmx or self.old_tmy ~= tmy then
self.target.target.x, self.target.target.y = tmx, tmy
end
self.old_tmx, self.old_tmy = tmx, tmy
end
end
--- Enter/leave targeting mode
......
......@@ -52,7 +52,7 @@ function _M:init(t)
self.all_clicks = t.all_clicks
self.hide_columns = t.hide_columns
self.fh = ls_h
self.fh = t.item_height or ls_h
local w = self.w
if self.scrollbar then w = w - 10 end
......
......@@ -86,7 +86,8 @@ function _M:run()
self.hotkeys_display = HotkeysDisplay.new(nil, self.w * 0.5 + 30, self.h * 0.8 + 7, self.w * 0.5 - 30, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png")
self.npcs_display = ActorsSeenDisplay.new(nil, self.w * 0.5 + 30, self.h * 0.8 + 7, self.w * 0.5 - 30, self.h * 0.2 - 7, "/data/gfx/ui/talents-list.png")
self.calendar = Calendar.new("/data/calendar_allied.lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167)
self.tooltip = Tooltip.new(nil, nil, {255,255,255}, {30,30,30})
self.tooltip = Tooltip.new(nil, nil, {255,255,255}, {30,30,30,230})
self.tooltip2 = Tooltip.new(nil, nil, {255,255,255}, {30,30,30,230})
self.flyers = FlyingText.new()
self:setFlyingText(self.flyers)
self.minimap_bg, self.minimap_bg_w, self.minimap_bg_h = core.display.loadImage("/data/gfx/ui/minimap.png"):glTexture()
......@@ -733,9 +734,13 @@ end
function _M:onRegisterDialog(d)
-- Clean up tooltip
self.tooltip_x, self.tooltip_y = nil, nil
self.tooltip2_x, self.tooltip2_y = nil, nil
if self.player then self.player:updateMainShader() end
end
function _M:onUnregisterDialog(d)
-- Clean up tooltip
self.tooltip_x, self.tooltip_y = nil, nil
self.tooltip2_x, self.tooltip2_y = nil, nil
if self.player then self.player:updateMainShader() end
end
......
......@@ -566,10 +566,33 @@ end
--- Show combined equipment/inventory dialog
-- Overload to make it use the tooltip
function _M:showEquipInven(title, filter, action)
local last = nil
return mod.class.Actor.showEquipInven(self, title, filter, action, function(item)
if item.last_display_x then
game.tooltip_x, game.tooltip_y = {}, 1
game.tooltip:displayAtMap(nil, nil, item.last_display_x, item.last_display_y, item.desc)
if item == last or not item.object or item.object.wielded then return end
last = item
local winven = item.object:wornInven()
winven = winven and self:getInven(winven)
if not winven then return end
local str = tstring{{"font", "bold"}, {"color", "GREY"}, "Currently equiped:", {"font", "normal"}, {"color", "LAST"}, true}
local ok = false
for i = 1, #winven do
str:merge(winven[i]:getDesc())
if i < #winven then str:add{"---", true} end
ok = true
end
if ok then
game.tooltip2_x, game.tooltip2_y = {}, 1
game.tooltip2:displayAtMap(nil, nil, 1, item.last_display_y, str)
game.tooltip2.last_display_x = game.tooltip.last_display_x - game.tooltip2.w
else
game.tooltip2_x = nil
end
end
end)
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