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

Tooltip will now tell you if there are more than one item on the ground

Button clickable area expanded to fit actual display size
Text in ListColums and Tree UI elements is now bouncing from left to right when overflowing


git-svn-id: http://svn.net-core.org/repos/t-engine4@3388 51575b47-30f0-44d4-a5cc-537603b46e54
parent ad5b13b1
No related branches found
No related tags found
No related merge requests found
......@@ -158,7 +158,7 @@ function _M:generateList(kind)
i = i + 1
end
end
if kind == "self" and self.player then
if kind == "self" and self.player and self.player.achievements then
for id, data in pairs(self.player.achievements) do handle(id, world.achieved[id]) end
elseif kind == "main" then
for id, data in pairs(world.achieved) do handle(id, data) end
......
......@@ -53,7 +53,7 @@ function _M:generate()
self.font:setStyle("normal")
-- Add UI controls
self.mouse:registerZone(0, 0, self.w, self.h, function(button, x, y, xrel, yrel, bx, by, event) if button == "left" and event == "button" then self.fct() end end)
self.mouse:registerZone(0, 0, self.w+6, self.h+6, function(button, x, y, xrel, yrel, bx, by, event) if button == "left" and event == "button" then self.fct() end end)
self.key:addBind("ACCEPT", function() self.fct() end)
self.rw, self.rh = w, h
......
......@@ -72,7 +72,8 @@ function _M:init(t)
Base.init(self, t)
end
function _M:drawItem(item)
function _M:drawItem(item, nb_keyframes)
nb_keyframes = (nb_keyframes or 0) / 2
for j, col in ipairs(self.columns) do
if not col.direct_draw then
local fw, fh = col.fw, self.fh
......@@ -91,8 +92,33 @@ function _M:drawItem(item)
local s = col.surface
s:erase(0, 0, 0, 0)
-- We use 1000 and do not cut lines to make sure it draws as much as possible
text:drawOnSurface(s, 10000, nil, self.font, col.frame_sel.b4.w, (fh - self.font_h) / 2, color[1], color[2], color[3])
local test_text = text:toString()
local font_w, _ = self.font:size(test_text)
if font_w > fw then
item.displayx_offset = item.displayx_offset or {}
item.displayx_offset[j] = item.displayx_offset[j] or 0
item.dir = item.dir or {}
item.dir[j] = item.dir[j] or 0
if item.dir[j] == 0 then
item.displayx_offset[j] = item.displayx_offset[j] - nb_keyframes
if -item.displayx_offset[j] >= font_w - fw + 15 then
item.dir[j] = 1
end
elseif item.dir[j] == 1 then
item.displayx_offset[j] = item.displayx_offset[j] + nb_keyframes
if item.displayx_offset[j] >= 0 then
item.dir[j] = 0
end
end
-- We use 1000 and do not cut lines to make sure it draws as much as possible
text:drawOnSurface(s, 10000, nil, self.font, col.frame_sel.b4.w+item.displayx_offset[j], (fh - self.font_h) / 2, color[1], color[2], color[3])
else
text:drawOnSurface(s, 10000, nil, self.font, col.frame_sel.b4.w, (fh - self.font_h) / 2, color[1], color[2], color[3])
end
item._tex = item._tex or {}
item._tex[j] = {s:glTexture()}
end
......@@ -241,6 +267,19 @@ end
function _M:display(x, y, nb_keyframes, screen_x, screen_y)
local bx, by = x, y
if self.sel then
local item = self.list[self.sel]
if self.previtem and self.previtem~=item then
self.previtem.displayx_offset = {}
self:drawItem(self.previtem)
self.previtem = nil
end
if item then
self:drawItem(item, nb_keyframes)
self.previtem = item
end
end
for j = 1, #self.columns do
local col = self.columns[j]
local y = y
......
......@@ -52,7 +52,7 @@ function _M:generate()
self.tex = {s:glTexture()}
-- Add UI controls
self.mouse:registerZone(0, 0, self.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
self.mouse:registerZone(0, 0, self.w+1, self.h+6, function(button, x, y, xrel, yrel, bx, by, event)
if event == "button" then
self:select()
end
......
......@@ -86,9 +86,11 @@ function _M:init(t)
Base.init(self, t)
end
function _M:drawItem(item)
function _M:drawItem(item, nb_keyframes)
nb_keyframes = (nb_keyframes or 0) / 2
item.cols = {}
for i, col in ipairs(self.columns) do
local fw = col.width
local level = item.level
local color = util.getval(item.color, item) or {255,255,255}
local text
......@@ -113,7 +115,35 @@ function _M:drawItem(item)
item.cols[i] = {}
s:erase(0, 0, 0, 0)
text:drawOnSurface(s, col.width - startx - col.frame_sel.b6.w, 1, self.font, startx, (self.fh - self.font_h) / 2, color[1], color[2], color[3])
local test_text = text:toString()
local font_w, _ = self.font:size(test_text)
font_w = font_w + startx
if font_w > fw then
item.displayx_offset = item.displayx_offset or {}
item.displayx_offset[i] = item.displayx_offset[i] or 0
item.dir = item.dir or {}
item.dir[i] = item.dir[i] or 0
if item.dir[i] == 0 then
item.displayx_offset[i] = item.displayx_offset[i] - nb_keyframes
if -item.displayx_offset[i] >= font_w - fw + 15 then
item.dir[i] = 1
end
elseif item.dir[i] == 1 then
item.displayx_offset[i] = item.displayx_offset[i] + nb_keyframes
if item.displayx_offset[i] >= 0 then
item.dir[i] = 0
end
end
-- We use 1000 and do not cut lines to make sure it draws as much as possible
text:drawOnSurface(s, 10000, nil, self.font, startx + item.displayx_offset[i], (self.fh - self.font_h) / 2, color[1], color[2], color[3])
else
text:drawOnSurface(s, 10000, nil, self.font, startx, (self.fh - self.font_h) / 2, color[1], color[2], color[3])
end
--text:drawOnSurface(s, col.width - startx - col.frame_sel.b6.w, 1, self.font, startx, (self.fh - self.font_h) / 2, color[1], color[2], color[3])
item.cols[i]._tex, item.cols[i]._tex_w, item.cols[i]._tex_h = s:glTexture()
end
if self.on_drawitem then self.on_drawitem(item) end
......@@ -268,6 +298,18 @@ end
function _M:display(x, y, nb_keyframes)
local bx, by = x, y
if self.sel then
local item = self.list[self.sel]
if self.previtem and self.previtem~=item then
self.previtem.displayx_offset = {}
self:drawItem(self.previtem)
self.previtem = nil
end
if item then
self:drawItem(item, nb_keyframes)
self.previtem = item
end
end
local max = math.min(self.scroll + self.max_display - 1, self.max)
for i = self.scroll, max do
......@@ -289,13 +331,14 @@ function _M:display(x, y, nb_keyframes)
end
end
if self.text_shadow then item.cols[j]._tex:toScreenFull(x+1, y+1, col.width, self.fh, item.cols[j]._tex_w, item.cols[j]._tex_h, 0, 0, 0, self.text_shadow) end
item.cols[j]._tex:toScreenFull(x, y, col.width, self.fh, item.cols[j]._tex_w, item.cols[j]._tex_h)
if item.nodes and j == 1 then
local s = item.shown and self.minus or self.plus
s.t:toScreenFull(x, y + (self.fh - s.h) / 2, s.w, s.h, s.th, s.th)
end
if self.text_shadow then item.cols[j]._tex:toScreenFull(x+1, y+1, col.width, self.fh, item.cols[j]._tex_w, item.cols[j]._tex_h, 0, 0, 0, self.text_shadow) end
item.cols[j]._tex:toScreenFull(x, y, col.width, self.fh, item.cols[j]._tex_w, item.cols[j]._tex_h)
x = x + col.width
end
y = y + self.fh
......
......@@ -95,9 +95,13 @@ function _M:use(who, typ, inven, item)
end
--- Returns a tooltip for the object
function _M:tooltip()
function _M:tooltip(x, y)
local str = self:getDesc{do_color=true}
if config.settings.cheat then str:add(true, "UID: "..self.uid, true, self.image) end
local nb = game.level.map:getObjectTotal(x, y)
if nb == 2 then str:add(true, "---", true, "You see one more object.")
elseif nb > 2 then str:add(true, "---", true, "You see "..(nb-1).." more objects.")
end
return str
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