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

drawColorStringBlended and drawColorString can now get a new argument that...

drawColorStringBlended and drawColorString can now get a new argument that limits the size of the string to output
Inventories/Stores/... dialogs will not allow an item name to "bleed over" other parts of the dialog


git-svn-id: http://svn.net-core.org/repos/t-engine4@1239 51575b47-30f0-44d4-a5cc-537603b46e54
parent 0e582291
No related branches found
No related tags found
No related merge requests found
Showing
with 51 additions and 23 deletions
......@@ -330,7 +330,7 @@ function _M:drawHBorder(s, x, y, h)
end
end
function _M:drawSelectionList(s, x, y, hskip, list, sel, prop, scroll, max, color, selcolor, max_size)
function _M:drawSelectionList(s, x, y, hskip, list, sel, prop, scroll, max, color, selcolor, max_size, cutoff_size)
selcolor = selcolor or {0,255,255}
color = color or {255,255,255}
max = max or 99999
......@@ -352,11 +352,11 @@ function _M:drawSelectionList(s, x, y, hskip, list, sel, prop, scroll, max, colo
if sel == i then
local sx, sy = self.font:size(lines[j])
-- s:erase(selcolor[1]/3, selcolor[2]/3, selcolor[3]/3, 1, x, y, sx, sy)
s:drawColorStringBlended(self.font, lines[j], x, y, selcolor[1], selcolor[2], selcolor[3])
s:drawColorStringBlended(self.font, lines[j], x, y, selcolor[1], selcolor[2], selcolor[3], nil, cutoff_size)
else
local r, g, b = color[1], color[2], color[3]
if vc then r, g, b = vc[1], vc[2], vc[3] end
s:drawColorStringBlended(self.font, lines[j], x, y, r, g, b)
s:drawColorStringBlended(self.font, lines[j], x, y, r, g, b, nil, cutoff_size)
end
y = y + hskip
end
......
......@@ -49,7 +49,7 @@ function _M:init(chat, id)
})
self:mouseZones{
{ x=0, y=0, w=self.w, h=self.h, fct=function(button, x, y, xrel, yrel, tx, ty)
if y >= self.start_answer_y then
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
......
......@@ -78,6 +78,6 @@ function _M:drawDialog(s)
h = h + self.font:lineSkip()
end
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -185,8 +185,8 @@ function _M:drawDialog(s)
h = h + self.font:lineSkip()
end
self:drawSelectionList(s, 2, 5, self.font_h, self.equip_list, self.list == self.equip_list and self.sel or -1, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.equip_list, self.list == self.equip_list and self.sel or -1, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self:drawHBorder(s, self.iw / 2, 2, sh - 4)
self:drawSelectionList(s, self.iw / 2 + 5, 5, self.font_h, self.inven_list, self.list == self.inven_list and self.sel or -1, "name", self.scroll, self.max)
self:drawSelectionList(s, self.iw / 2 + 5, 5, self.font_h, self.inven_list, self.list == self.inven_list and self.sel or -1, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -118,6 +118,6 @@ Mouse: #00FF00#Left click#FFFFFF# to use.
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -160,6 +160,6 @@ Mouse: #00FF00#Left click#FFFFFF# to use.
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -122,6 +122,6 @@ Mouse: #00FF00#Left click#FFFFFF# to pickup.
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -101,6 +101,6 @@ function _M:drawDialog(s)
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -128,8 +128,8 @@ function _M:drawDialog(s)
h = h + self.font:lineSkip()
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)
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)
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)
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)
self.changed = false
end
......@@ -187,6 +187,6 @@ Mouse: #00FF00#Left click#FFFFFF# to use.
end
-- Talents
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max, nil, nil, nil, self.iw / 2 - 5)
self.changed = false
end
......@@ -183,6 +183,8 @@ function _M:generate(lev, old_lev)
local status = self.tiles[c] and self.tiles[c].status
local define_spot = self.tiles[c] and self.tiles[c].define_spot
self.map.room_map[i-1] = self.map.room_map[i-1] or {}
self.map.room_map[i-1][j-1] = self.map.room_map[i-1][j-1] or {}
self.map.room_map[i-1][j-1].add_entities = self.map.room_map[i-1][j-1].add_entities or {}
local rm = self.map.room_map[i-1][j-1].add_entities
......
......@@ -248,13 +248,15 @@ function string.parseHex(str)
end
local tmps = core.display.newSurface(1, 1)
getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g, b, alpha_from_texture)
getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g, b, alpha_from_texture, limit_w)
local list = str:split("#" * (Puid + Pcolorcodefull + Pcolorname + Pfontstyle) * "#", true)
r = r or 255
g = g or 255
b = b or 255
limit_w = limit_w or 99999999
local oldr, oldg, oldb = r, g, b
local max_h = 0
local sw = 0
for i, v in ipairs(list) do
local nr, ng, nb = lpeg.match("#" * lpeg.C(Pcolorcode) * lpeg.C(Pcolorcode) * lpeg.C(Pcolorcode) * "#", v)
local col = lpeg.match("#" * lpeg.C(Pcolorname) * "#", v)
......@@ -278,37 +280,50 @@ getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g,
local surf = e:getEntityFinalSurface(game.level.map.tiles, font:lineSkip(), font:lineSkip())
if surf then
local w, h = surf:getSize()
if sw + w > limit_w then break end
s:merge(surf, x, y)
if h > max_h then max_h = h end
x = x + (w or 0)
sw = sw + (w or 0)
end
end
elseif fontstyle then
font:setStyle(fontstyle)
else
local w, h = font:size(v)
local stop = false
while sw + w > limit_w do
v = v:sub(1, #v - 1)
if #v == 0 then break end
w, h = font:size(v)
stop = true
end
if h > max_h then max_h = h end
s:drawString(font, v, x, y, r, g, b, alpha_from_texture)
s:drawStringBlended(font, v, x, y, r, g, b, alpha_from_texture)
x = x + w
sw = sw + w
if stop then break end
end
end
return r, g, b, max_h
end
getmetatable(tmps).__index.drawColorStringCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture)
getmetatable(tmps).__index.drawColorStringCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture, limit_w)
local w, h = font:size(str)
local x, y = dx + (dw - w) / 2, dy + (dh - h) / 2
s:drawColorString(font, str, x, y, r, g, b, alpha_from_texture)
s:drawColorString(font, str, x, y, r, g, b, alpha_from_texture, limit_w)
end
getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y, r, g, b, alpha_from_texture)
getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y, r, g, b, alpha_from_texture, limit_w)
local list = str:split("#" * (Puid + Pcolorcodefull + Pcolorname + Pfontstyle) * "#", true)
r = r or 255
g = g or 255
b = b or 255
limit_w = limit_w or 99999999
local oldr, oldg, oldb = r, g, b
local max_h = 0
local sw = 0
for i, v in ipairs(list) do
local nr, ng, nb = lpeg.match("#" * lpeg.C(Pcolorcode) * lpeg.C(Pcolorcode) * lpeg.C(Pcolorcode) * "#", v)
local col = lpeg.match("#" * lpeg.C(Pcolorname) * "#", v)
......@@ -332,27 +347,38 @@ getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y,
local surf = e:getEntityFinalSurface(game.level.map.tiles, font:lineSkip(), font:lineSkip())
if surf then
local w, h = surf:getSize()
if sw + (w or 0) > limit_w then break end
s:merge(surf, x, y)
if h > max_h then max_h = h end
x = x + (w or 0)
sw = sw + (w or 0)
end
end
elseif fontstyle then
font:setStyle(fontstyle)
else
local w, h = font:size(v)
local stop = false
while sw + w > limit_w do
v = v:sub(1, #v - 1)
if #v == 0 then break end
w, h = font:size(v)
stop = true
end
if h > max_h then max_h = h end
s:drawStringBlended(font, v, x, y, r, g, b, alpha_from_texture)
x = x + w
sw = sw + w
if stop then break end
end
end
return r, g, b, max_h
end
getmetatable(tmps).__index.drawColorStringBlendedCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture)
getmetatable(tmps).__index.drawColorStringBlendedCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture, limit_w)
local w, h = font:size(str)
local x, y = dx + (dw - w) / 2, dy + (dh - h) / 2
s:drawColorStringBlended(font, str, x, y, r, g, b, alpha_from_texture)
s:drawColorStringBlended(font, str, x, y, r, g, b, alpha_from_texture, limit_w)
end
dir_to_coord = {
......
......@@ -18,7 +18,7 @@
-- darkgod@te4.org
-- Engine Version
engine.version = {0,9,10,"te4",2}
engine.version = {0,9,11,"te4",2}
engine.require_c_core = engine.version[5]
engine.version_id = ("%s-%d_%d.%d.%d"):format(engine.version[4], engine.require_c_core, engine.version[1], engine.version[2], engine.version[3])
......
......@@ -21,7 +21,7 @@ return {
name = "Angolwen",
level_range = {20, 20},
max_level = 1,
width = 80, height = 80,
width = 90, height = 90,
persistant = "zone",
-- all_remembered = true,
all_lited = true,
......
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