From c03fccc9af7136e82b568e1c2486271887d556fb Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Thu, 2 Jun 2011 14:29:43 +0000 Subject: [PATCH] tooltip in stores git-svn-id: http://svn.net-core.org/repos/t-engine4@3547 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/Store.lua | 2 +- game/engines/default/engine/ui/Dialog.lua | 6 ++-- game/modules/tome/class/Store.lua | 29 ----------------- game/modules/tome/dialogs/ShowStore.lua | 39 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 game/modules/tome/dialogs/ShowStore.lua diff --git a/game/engines/default/engine/Store.lua b/game/engines/default/engine/Store.lua index 263d5db517..c60d031ce2 100644 --- a/game/engines/default/engine/Store.lua +++ b/game/engines/default/engine/Store.lua @@ -21,7 +21,7 @@ require "engine.class" local Entity = require "engine.Entity" local Dialog = require "engine.ui.Dialog" local Inventory = require "engine.interface.ActorInventory" -local ShowStore = require "engine.dialogs.ShowStore" +local ShowStore = require_first("mod.dialogs.ShowStore", "engine.dialogs.ShowStore") local GetQuantity = require "engine.dialogs.GetQuantity" module(..., package.seeall, class.inherit(Entity, Inventory)) diff --git a/game/engines/default/engine/ui/Dialog.lua b/game/engines/default/engine/ui/Dialog.lua index 6e7498f23d..715d469868 100644 --- a/game/engines/default/engine/ui/Dialog.lua +++ b/game/engines/default/engine/ui/Dialog.lua @@ -300,11 +300,11 @@ function _M:setupUI(resizex, resizey, on_resize, addmw, addmh) end -- print("===", mw, addw) mw = mw + addw + 5 * 2 + (addmw or 0) - + -- print("===", mw, addw) local tw, th = self.font_bold:size(self.title) mw = math.max(tw + 6, mw) - + mh = mh + addh + 5 + 22 + 3 + (addmh or 0) + th if on_resize then on_resize(resizex and mw or self.w, resizey and mh or self.h) end @@ -389,7 +389,7 @@ function _M:getUIElement(id) end if type(id) == "table" then return end end - + return self.uis[id] end diff --git a/game/modules/tome/class/Store.lua b/game/modules/tome/class/Store.lua index bb52b38d58..c6ae4a5282 100644 --- a/game/modules/tome/class/Store.lua +++ b/game/modules/tome/class/Store.lua @@ -203,32 +203,3 @@ function _M:interact(who, name) who:sortInven() Store.interact(self, who, name) end - ---- Display tooltips -function _M:on_select(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 not item.object or item.object.wielded then game.tooltip2_x = nil return end - local winven = item.object:wornInven() - winven = winven and game.player:getInven(winven) - if not winven then game.tooltip2_x = nil 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, "---", 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 - last = item - else - game.tooltip2_x = nil - end - end -end diff --git a/game/modules/tome/dialogs/ShowStore.lua b/game/modules/tome/dialogs/ShowStore.lua new file mode 100644 index 0000000000..27595367cb --- /dev/null +++ b/game/modules/tome/dialogs/ShowStore.lua @@ -0,0 +1,39 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010, 2011 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 + +require "engine.class" +local Base = require "engine.dialogs.ShowStore" + +module(..., package.seeall, class.inherit(Base)) + +function _M:init(...) + Base.init(self, ...) + + -- Add tooltips + self.on_select = function(item) + if item.last_display_x and item.object then + game.tooltip_x, game.tooltip_y = {}, 1 + game.tooltip:displayAtMap(nil, nil, item.last_display_x, item.last_display_y, item.object:getDesc({do_color=true}, game.player:getInven(item.object:wornInven()))) + end + end + self.key.any_key = function(sym) + -- Control resets the tooltip + if sym == self.key._LCTRL or sym == self.key._RCTRL then local i = self.cur_item self.cur_item = nil self:select(i) end + end +end -- GitLab