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

fix

Disruption Shield uses the new shield shader effect


git-svn-id: http://svn.net-core.org/repos/t-engine4@5415 51575b47-30f0-44d4-a5cc-537603b46e54
parent 51b7934d
No related branches found
No related tags found
No related merge requests found
Showing
with 238 additions and 167 deletions
......@@ -194,7 +194,7 @@ function _M:toScreen(x, y, nb_keyframes)
self.last_display_x = x
self.last_display_y = y
if self.inhibited == true then return nil end
if self.inhibited == true or self.empty == true then return nil end
nb_keyframes = nb_keyframes or 0
-- Save current matrix and load coords to default values
core.display.glPush()
......
......@@ -440,8 +440,6 @@ function _M:setupUI(resizex, resizey, on_resize, addmw, addmh)
end
function _M:setFocus(id)
if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end
if type(id) == "table" then
for i = 1, #self.uis do
if self.uis[i].ui == id then id = i break end
......@@ -450,6 +448,8 @@ function _M:setFocus(id)
end
local ui = self.uis[id]
if self.focus_ui == ui then return end
if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end
if not ui.ui.can_focus then self:no_focus() return end
self.focus_ui = ui
self.focus_ui_id = id
......
......@@ -21,8 +21,9 @@ require "engine.class"
local Base = require "engine.ui.Base"
local Focusable = require "engine.ui.Focusable"
local EquipDollFrame = require "engine.ui.EquipDollFrame"
local UIGroup = require "engine.ui.UIGroup"
module(..., package.seeall, class.inherit(Base, Focusable))
module(..., package.seeall, class.inherit(Base, Focusable, UIGroup))
function _M:init(t)
self.actor = assert(t.actor, "no equipdoll actor")
......@@ -36,10 +37,6 @@ function _M:init(t)
Base.init(self, t)
end
function _M:on_focus(v)
game:onTickEnd(function() self.key:unicodeInput(v) end)
end
function _M:generate()
self.mouse:reset()
self.key:reset()
......@@ -84,42 +81,11 @@ function _M:keyTrigger(c)
end
end
function _M:setInnerFocus(id)
if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end
if type(id) == "table" then
for i = 1, #self.uis do
if self.uis[i].ui == id then id = i break end
end
if type(id) == "table" then self:no_focus() return end
end
local ui = self.uis[id]
if not ui.ui.can_focus then self:no_focus() return end
self.focus_ui = ui
self.focus_ui_id = id
ui.ui:setFocus(true)
self:on_focus(id, ui)
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
end
function _M:no_focus()
end
function _M:moveFocus(v)
local id = self.focus_ui_id
local start = id or 1
local cnt = 0
id = util.boundWrap((id or 1) + v, 1, #self.uis)
while start ~= id and cnt <= #self.uis do
if self.uis[id] and self.uis[id].ui and self.uis[id].ui.can_focus and not self.uis[id].ui.no_keyboard_focus then
self:setInnerFocus(id)
break
end
id = util.boundWrap(id + v, 1, #self.uis)
cnt = cnt + 1
function _M:on_focus_change(status)
if status == true then
game.tooltip:erase()
local ui = self.focus_ui
if self.on_select and ui then self.on_select(ui, ui.ui.inven, ui.ui.item, ui.ui:getItem()) end
end
end
......@@ -160,6 +126,7 @@ function _M:generateEquipDollFrames()
frame.actorWear = function(_, ...) if self.actorWear then self.actorWear(frame, ...) end end
frame.fct=function(button, event) if frame:getItem() and self.fct then self.fct({inven=inven, item=item, object=frame:getItem()}, button, event) end end
frame.filter = self.filter
frame.on_focus_change=function(status) local ui = self.focus_ui if self.on_select and ui then self.on_select(ui, ui.ui.inven, ui.ui.item, ui.ui:getItem()) end end
uis[#uis+1] = {x=def.x, y=def.y, ui=frame, _weight=def.weight}
max_w = math.max(def.x, max_w)
max_h = math.max(def.y, max_h)
......
......@@ -28,9 +28,21 @@ focus_decay_max_d = 8
one_by_focus_decay = 1/32
function _M:setFocus(v)
local prev_focus = self.focused
self.focused = v
if not v then
self.focus_decay = self.focus_decay_max
end
if not v then self.focus_decay = self.focus_decay_max end
if v ~= prev_focus and self.on_focus_change then self:on_focus_change(v) end
if self.on_focus then self:on_focus(v) end
end
--while focused
function _M:on_focus(id, ui)
end
--while not focused
function _M:no_focus()
end
--focus change
function _M:on_focus_change(status)
end
......@@ -180,9 +180,11 @@ function _M:onUse(button, forcectrl)
end
end
function _M:onSelect(how)
function _M:onSelect(how, force)
local item = self.dlist[self.sel_j] and self.dlist[self.sel_j][self.sel_i]
if self.prev_item == item and not force then return end
if self.on_select and item then self.on_select(item, how) end
self.prev_item = item
end
function _M:display(x, y, nb_keyframes, screen_x, screen_y)
......
......@@ -23,9 +23,10 @@ local Focusable = require "engine.ui.Focusable"
local ImageList = require "engine.ui.ImageList"
local ListColumns = require "engine.ui.ListColumns"
local KeyBind = require "engine.KeyBind"
local UIGroup = require "engine.ui.UIGroup"
--- A generic inventory, with possible tabs
module(..., package.seeall, class.inherit(Base, Focusable))
module(..., package.seeall, class.inherit(Base, Focusable, UIGroup))
function _M:init(t)
self.inven = assert(t.inven, "no inventory inven")
......@@ -40,6 +41,7 @@ function _M:init(t)
self.on_select_tab = t.select_tab
self.on_drag = t.on_drag
self.on_drag_end = t.on_drag_end
self.on_focus_change = t.on_focus_change
self.special_bg = t.special_bg
self._last_x, _last_y, self._last_ox, self._last_oy = 0, 0, 0, 0
......@@ -60,7 +62,11 @@ function _M:generate()
self.uis = {}
if self.tabslist then
self.c_tabs = ImageList.new{width=self.w, height=36, tile_w=32, tile_h=32, padding=5, force_size=true, selection="ctrl-multiple", list=self.tabslist, fct=function() self:generateList() end, on_select=function(item, how) self:selectTab(item, how) end}
self.c_tabs = ImageList.new{width=self.w, height=36, tile_w=32, tile_h=32, padding=5, force_size=true, selection="ctrl-multiple", list=self.tabslist,
fct=function() self:generateList() end,
on_select=function(item, how) self:selectTab(item, how) end
}
self.c_tabs.no_keyboard_focus = true
if _M._last_tabs then
for _, l in ipairs(_M._last_tabs) do self.c_tabs.dlist[l[1]][l[2]].selected = true end
......@@ -68,6 +74,12 @@ function _M:generate()
self.c_tabs.dlist[1][1].selected = true
end
self.uis[#self.uis+1] = {x=0, y=0, ui=self.c_tabs}
self.c_tabs.on_focus_change = function(ui_self, status)
if status == true then
local item = ui_self.dlist[ui_self.sel_j] and ui_self.dlist[ui_self.sel_j][ui_self.sel_i]
self.on_select(item, true)
end
end
end
local direct_draw= function(item, x, y, w, h, total_w, total_h, loffset_x, loffset_y, dest_area)
......@@ -91,7 +103,7 @@ function _M:generate()
return 0, 0, 0, 0, 0, 0
end
self.c_inven = ListColumns.new{width=self.w, height=self.h - (self.c_tabs and self.c_tabs.h or 0), floating_headers = true, sortable=true, scrollbar=true, columns=self.columns or {
self.c_inven = ListColumns.new{width=self.w, height=self.h - (self.c_tabs and self.c_tabs.h or 0), sortable=true, scrollbar=true, select_delay = 0.1, columns=self.columns or {
{name="", width={33,"fixed"}, display_prop="char", sort="id"},
{name="", width={24,"fixed"}, display_prop="object", sort="sortname", direct_draw=direct_draw},
{name="Inventory", width=72, display_prop="name", sort="sortname"},
......@@ -158,45 +170,6 @@ function _M:selectTab(item, how)
if how == "key" then self.c_inven:onSelect() end
end
function _M:setInnerFocus(id)
if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end
if type(id) == "table" then
for i = 1, #self.uis do
if self.uis[i].ui == id then id = i break end
end
if type(id) == "table" then self:no_focus() return end
end
local ui = self.uis[id]
if not ui.ui.can_focus then self:no_focus() return end
self.focus_ui = ui
self.focus_ui_id = id
ui.ui:setFocus(true)
self:on_focus(id, ui)
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
end
function _M:no_focus()
end
function _M:moveFocus(v)
local id = self.focus_ui_id
local start = id or 1
local cnt = 0
id = util.boundWrap((id or 1) + v, 1, #self.uis)
while start ~= id and cnt <= #self.uis do
if self.uis[id] and self.uis[id].ui and self.uis[id].ui.can_focus and not self.uis[id].ui.no_keyboard_focus then
self:setInnerFocus(id)
break
end
id = util.boundWrap(id + v, 1, #self.uis)
cnt = cnt + 1
end
end
function _M:mouseEvent(button, x, y, xrel, yrel, bx, by, event)
-- Look for focus
for i = 1, #self.uis do
......@@ -274,7 +247,7 @@ function _M:generateList(no_update)
local enc = 0
o:forAllStack(function(o) enc=enc+o.encumber end)
list[#list+1] = { id=#list+1, char=char, name=o:getName(), sortname=o:getName():toString():removeColorCodes(), color=o:getDisplayColor(), object=o, inven=self.actor.INVEN_INVEN, item=item, cat=o.subtype, encumberance=enc, desc=o:getDesc(), special_bg=self.special_bg }
list[#list+1] = { id=#list+1, char=char, name=o:getName(), sortname=o:getName():toString():removeColorCodes(), color=o:getDisplayColor(), object=o, inven=self.actor.INVEN_INVEN, item=item, cat=o.subtype, encumberance=enc, special_bg=self.special_bg }
chars[char] = #list
i = i + 1
end
......
......@@ -33,11 +33,12 @@ function _M:init(t)
self.nb_rows = t.nb_items
self.font = t.font or self.font
self.row_height = t.item_height or (self.font_h + 6)
self.h = t.height or self.row_height * ( (self.nb_rows or 0) + (self.hide_columns and 1 or 0) )
self.h = t.height or self.row_height * ( (self.nb_rows or 0) + (self.hide_columns and 0 or 1) )
self.sortable = t.sortable
self.scrollbar = t.scrollbar
self.fct = t.fct
self.on_select = t.select
--self.on_focus_change = t.on_focus_change
self.on_drag = t.on_drag
self.on_drag_end = t.on_drag_end
self.all_clicks = t.all_clicks
......@@ -47,10 +48,12 @@ function _M:init(t)
self.text_shadow = t.text_shadow or self.text_shadow
self.click_select = t.click_select or false
self.only_display = t.only_display or false
if t.select_delay then self:setSelectDelay(t.select_delay) end
self.max_h = 0
self.max_h_columns = 0
self.prevrow = 0
self.prev_sel = 0
self.prevclick = 0
self.last_input_was_keyboard = false
self.scroll_inertia = 0
......@@ -137,13 +140,17 @@ function _M:setupInput()
self.key:addBinds{
ACCEPT = function() self.last_input_was_keyboard = true self:onUse("left", "key") end,
MOVE_UP = function()
local prev = self.sel
self.last_input_was_keyboard = true
self.prevrow = self.sel
self.sel = util.minBound(self.sel - 1, 1, #self.list) end,
self.sel = util.minBound(self.sel - 1, 1, #self.list)
self.prev_sel = self.sel ~= prev and prev or self.prev_sel
end,
MOVE_DOWN = function()
local prev = self.sel
self.last_input_was_keyboard = true
self.prevrow = self.sel
self.sel = util.minBound(self.sel + 1, 1, #self.list) end,
self.sel = util.minBound(self.sel + 1, 1, #self.list)
self.prev_sel = self.sel ~= prev and prev or self.prev_sel
end,
}
self.key:addCommands{
......@@ -379,9 +386,11 @@ function _M:setColumns(columns, force)
colx = colx + col.width
if col.h > max_h then max_h = col.h end
end
self.columns = columns
self.max_h_columns = self.hide_columns and 0 or (self.row_height or max_h)
self.max_h = self.max_h_columns
self.sel = 1
self:selectColumn(1, true)
end
......@@ -410,6 +419,7 @@ function _M:setList(list, force)
self.scrollbar.max = self.max_h - self.h
end
self.prevrow = 0
self.prev_sel = 0
end
function _M:changeAll(columns, list)
......@@ -475,6 +485,11 @@ function _M:selectColumn(i, force, reverse)
end
end
function _M:setSelectDelay(delay)
self.delay = delay
self.delay_start = os.clock()
end
function _M:display(x, y, nb_keyframes, screen_x, screen_y, offset_x, offset_y, local_x, local_y)
self.last_display_x = screen_x
self.last_display_y = screen_y
......@@ -623,9 +638,26 @@ function _M:display(x, y, nb_keyframes, screen_x, screen_y, offset_x, offset_y,
end
end
-- if row was changed then refresh it
if self.prevrow ~= self.sel then
-- if there is delay set and its still focused
if self.delay and self.focused == true then
-- previously displayed selection is still the same
if self.prevrow == self.sel then
if os.clock() > self.delay + self.delay_start then
if self.prev_sel ~= self.sel then
self.prev_sel = self.sel
if not self.click_select then self:onSelect() end
end
self.delay_start = os.clock()
end
else
-- selection was changed
self.delay_start = os.clock()
end
self.prevrow = self.sel
-- if the rows changed
elseif not self.delay and self.prev_sel ~= self.sel then
self.prev_sel = self.sel
if not self.click_select then self:onSelect() end
end
end
......@@ -136,7 +136,7 @@ end
function _M:switchItem(item, create_if_needed, force)
if self.cur_item == item and not force then return true end
if create_if_needed and not self.items[item] then self:createItem(item, create_if_needed) end
if (create_if_needed and not self.items[item]) or force then self:createItem(item, create_if_needed) end
if not item or not self.items[item] then self.list = nil return false end
local d = self.items[item]
......
......@@ -34,6 +34,8 @@ function _M:init(t)
self.scrollbar = Slider.new{size=self.h, max=0}
self.uis_h = 0
self.scroll_inertia = 0
Base.init(self, t)
end
......@@ -52,8 +54,8 @@ function _M:generate()
self.mouse:registerZone(0, 0, self.w, self.h, on_mousewheel)
self.key:addBinds{
MOVE_UP = function() if self.scrollbar.pos and self.uis_h > self.h then self.scrollbar.pos = util.bound(self.scrollbar.pos - 1, 0, self.scrollbar.max) end end,
MOVE_DOWN = function() if self.scrollbar.pos and self.uis_h > self.h then self.scrollbar.pos = util.bound(self.scrollbar.pos + 1, 0, self.scrollbar.max) end end,
MOVE_UP = function() if self.scrollbar.pos and self.uis_h > self.h then self.scroll_inertia = math.min(self.scroll_inertia, 0) - 5 end end,
MOVE_DOWN = function() if self.scrollbar.pos and self.uis_h > self.h then self.scroll_inertia = math.max(self.scroll_inertia, 0) + 5 end end,
}
end
......@@ -86,6 +88,14 @@ function _M:display(x, y, nb_keyframes, screen_x, screen_y, offset_x, offset_y,
local_x = local_x and local_x or 0
local_y = local_y and local_y or 0
if self.scrollbar then
self.scrollbar.pos = util.minBound(self.scrollbar.pos + self.scroll_inertia, 0, self.scrollbar.max)
if self.scroll_inertia > 0 then self.scroll_inertia = math.max(self.scroll_inertia - 1, 0)
elseif self.scroll_inertia < 0 then self.scroll_inertia = math.min(self.scroll_inertia + 1, 0)
end
if self.scrollbar.pos == 0 or self.scrollbar.pos == self.scrollbar.max then self.scroll_inertia = 0 end
end
offset_x = offset_x and offset_x or 0
offset_y = offset_y and offset_y or (self.scrollbar and self.scrollbar.pos or 0)
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010, 2011, 2012 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"
--- Make a UI element clickable
module(..., package.seeall, class.make)
function _M:setInnerFocus(id)
if type(id) == "table" then
for i = 1, #self.uis do
if self.uis[i].ui == id then id = i break end
end
if type(id) == "table" then self:no_focus() return end
end
local ui = self.uis[id]
if self.focus_ui == ui then return end
if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end
if not ui.ui.can_focus then self:no_focus() return end
self.focus_ui = ui
self.focus_ui_id = id
ui.ui:setFocus(true)
self:on_focus(id, ui)
end
function _M:moveFocus(v)
local id = self.focus_ui_id
local start = id or 1
local cnt = 0
id = util.boundWrap((id or 1) + v, 1, #self.uis)
while start ~= id and cnt <= #self.uis do
if self.uis[id] and self.uis[id].ui and self.uis[id].ui.can_focus and not self.uis[id].ui.no_keyboard_focus then
self:setInnerFocus(id)
break
end
id = util.boundWrap(id + v, 1, #self.uis)
cnt = cnt + 1
end
end
function _M:on_focus_change(status)
if self.focus_ui then self.focus_ui.ui:setFocus(status) end
end
......@@ -1691,7 +1691,7 @@ function _M:onTakeHit(value, src)
eff.begone = game.turn
end
end
-- Mind save to reduce damage to zero
if self:knowTalent(self.T_DISMISSAL) and value > 0 then
local t = self:getTalentFromId(self.T_DISMISSAL)
......@@ -1850,7 +1850,7 @@ function _M:onTakeHit(value, src)
end
if self.on_takehit then value = self:check("on_takehit", value, src) end
-- Apply Solipsism hit
if damage_to_psi > 0 then
if self:getPsi() > damage_to_psi then
......@@ -1984,6 +1984,12 @@ function _M:takeHit(value, src, death_note)
e.damage_feedback(self, p, src, value)
end
end
for tid, p in pairs(self.sustain_talents) do
local t = self:getTalentFromId(tid)
if t.damage_feedback then
t.damage_feedback(self, t, p, src, value)
end
end
local dead, val = engine.interface.ActorLife.takeHit(self, value, src, death_note)
......
......@@ -4,9 +4,10 @@ uniform float aadjust;
uniform vec3 color;
uniform float time_factor;
vec3 impact_color = vec3(1.0, 0.3, 1.0);
uniform vec3 impact_color;
uniform vec2 impact;
uniform float impact_tick;
uniform float impact_time;
void main(void)
{
......@@ -31,8 +32,8 @@ void main(void)
// Impact
float it = tick - impact_tick;
if (it < 400.0) {
float v = (400.0 - it) / 400.0;
if (it < impact_time) {
float v = (impact_time - it) / impact_time;
float il = distance(impact / ll, (vec2(0.5) - gl_TexCoord[0].xy) / ll);
if (il < 0.5 * (1.0 - v)) {
v *= v * v;
......
......@@ -27,6 +27,8 @@ return {
aadjust = aadjust or 10,
impact = {0, 0},
impact_tick = -1000,
impact_color = {1.0, 0.3, 1.0},
impact_time = 400,
},
clone = false,
}
......@@ -154,13 +154,29 @@ newTalent{
true
)
end,
damage_feedback = function(self, t, p, src)
if p.particle and p.particle._shader and p.particle._shader.shad and src and src.x and src.y then
local r = -rng.float(0.2, 0.4)
local a = math.atan2(src.y - self.y, src.x - self.x)
p.particle._shader:setUniform("impact", {math.cos(a) * r, math.sin(a) * r})
p.particle._shader:setUniform("impact_tick", core.game.getTime())
end
end,
activate = function(self, t)
local power = t.getManaRatio(self, t)
self.disruption_shield_absorb = 0
game:playSoundNear(self, "talents/arcane")
local particle
if core.shader.active() then
particle = self:addParticles(Particles.new("shader_shield", 1, {size_factor=1.3}, {type="shield", time_factor=-2500, color={0.8, 0.1, 1.0}, impact_color = {0, 1, 0}, impact_time=800}))
else
particle = self:addParticles(Particles.new("disruption_shield", 1))
end
return {
shield = self:addTemporaryValue("disruption_shield", power),
particle = self:addParticles(Particles.new("disruption_shield", 1)),
particle = particle,
}
end,
deactivate = function(self, t, p)
......
......@@ -31,7 +31,8 @@ function _M:init(title, actor, filter, action, on_select)
self.action = action
self.filter = filter
self.actor = actor
self.on_select = on_select
game.tooltip.add_map_str = nil
Dialog.init(self, title or "Inventory", math.max(800, game.w * 0.8), math.max(600, game.h * 0.8))
......@@ -67,6 +68,8 @@ function _M:init(title, actor, filter, action, on_select)
on_drag_end=function() self:onDragTakeoff() end,
special_bg=function(item) if item.object and item.object.__transmo then return colors.GOLD end end,
}
self.c_inven.c_inven.on_focus_change = function(ui_self, status) if status == true then self:select(ui_self.list[ui_self.sel], true) end end
local uis = {
{left=0, top=0, ui=self.c_main_set},
......@@ -91,9 +94,9 @@ function _M:init(title, actor, filter, action, on_select)
self.mouse:reset()
local on_mouse = function(button, x, y, xrel, yrel, bx, by, event)
if button == "wheelup" and event == "button" then
game.tooltip.container.scrollbar.pos = util.minBound(game.tooltip.container.scrollbar.pos - 1, 0, game.tooltip.container.scrollbar.max)
game.tooltip.container.scroll_inertia = math.min(game.tooltip.container.scroll_inertia, 0) - 5
elseif button == "wheeldown" and event == "button" then
game.tooltip.container.scrollbar.pos = util.minBound(game.tooltip.container.scrollbar.pos + 1, 0, game.tooltip.container.scrollbar.max)
game.tooltip.container.scroll_inertia = math.max(game.tooltip.container.scroll_inertia, 0) + 5
end
if button == "middle" then
if not self.scroll_drag then
......@@ -117,23 +120,25 @@ function _M:init(title, actor, filter, action, on_select)
end
end
self.key:reset()
engine.interface.PlayerHotkeys:bindAllHotkeys(self.key, function(i) self:defineHotkey(i) end)
self.key.any_key = function(sym)
-- Control resets the tooltip
if sym == self.key._LCTRL or sym == self.key._RCTRL then
local ctrl = core.key.modState("ctrl")
if self.prev_ctrl ~= ctrl then self:select(self.cur_item, true) end
self.prev_ctrl = ctrl
end
end
self.key:addBinds{
ACCEPT = function()
if self.focus_ui and self.focus_ui.ui == self.c_inven then self:use(self.c_inven.c_inven.list[self.c_inven.c_inven.sel])
end
end,
ACCEPT = function() if self.focus_ui and self.focus_ui.ui == self.c_inven then self:use(self.c_inven.c_inven.list[self.c_inven.c_inven.sel]) end end,
EXIT = function() game.tooltip.locked = false game:unregisterDialog(self) end,
MOVE_UP = function() game.log("up") if game.tooltip.locked then game.tooltip.container.scroll_inertia = math.min(game.tooltip.container.scroll_inertia, 0) - 5 end end,
MOVE_DOWN = function() if game.tooltip.locked then game.tooltip.container.scroll_inertia = math.max(game.tooltip.container.scroll_inertia, 0) + 5 end end,
LOCK_TOOLTIP = lock_tooltip,
LOCK_TOOLTIP_COMPARE = lock_tooltip,
MOVE_UP = function() if game.tooltip.locked then game.tooltip.container.scrollbar.pos = util.minBound(game.tooltip.container.scrollbar.pos - 1, 0, game.tooltip.container.scrollbar.max) end end,
MOVE_DOWN = function() if game.tooltip.locked then game.tooltip.container.scrollbar.pos = util.minBound(game.tooltip.container.scrollbar.pos + 1, 0, game.tooltip.container.scrollbar.max) 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
function _M:switchSets(which)
......@@ -169,25 +174,12 @@ function _M:defineHotkey(id)
self.actor.changed = true
end
function _M:select(item)
if self.cur_item == item then return end
if item then
if self.on_select then self.on_select(item) end
end
function _M:select(item, force)
--if self.cur_item == item and not force then return end
if item then self.on_select(item) end
self.cur_item = item
end
function _M:on_focus(id, ui)
if self.focus_ui and self.focus_ui.ui == self.c_inven then self:select(self.c_inven.c_inven.list[self.c_inven.c_inven.sel])
elseif self.focus_ui and self.focus_ui.ui == self.c_tabs then
else
game.tooltip_x = nil
end
end
function _M:no_focus()
game.tooltip_x = nil
end
function _M:use(item, button, event)
if item then
if self.action(item.object, item.inven, item.item, button, event) then
......@@ -196,10 +188,6 @@ function _M:use(item, button, event)
end
end
function _M:on_recover_focus()
self.c_inven:generateList()
end
function _M:unload()
for inven_id = 1, #self.actor.inven_def do if self.actor.inven[inven_id] then for item, o in ipairs(self.actor.inven[inven_id]) do o.__new_pickup = nil end end end
end
......
......@@ -33,16 +33,23 @@ function _M:init(title, inven, filter, action, actor)
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_desc = TextzoneList.new{scrollbar = true, width=math.floor(self.iw / 2 - 10), height=self.ih}
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,
select=function(item, force) self:select(item, force) end,
select_tab=function(item) self:select(item) end,
}
self.c_inven.c_inven.on_focus_change = function(ui_self, status) if status == true then game.tooltip:erase() end 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
if sym == self.key._LCTRL or sym == self.key._RCTRL then
local ctrl = core.key.modState("ctrl")
if self.prev_ctrl ~= ctrl then self:select(self.cur_item, true) end
self.prev_ctrl = ctrl
end
end
self:loadUI{
......@@ -69,16 +76,15 @@ function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:select(item)
if item then
self.cur_item = item
if not item.desc or item.ctrl_state ~= core.key.modState("ctrl") then
item.ctrl_state = core.key.modState("ctrl")
item.desc = item.object:getDesc({do_color=true}, self.actor:getInven(item.object:wornInven()))
self.c_desc:createItem(item, item.desc)
end
self.c_desc:switchItem(item, item.desc)
function _M:select(item, force)
if self.cur_item == item and not force then return end
if item.last_display_x and item.object then
if not item.desc or force then item.desc = item.object:getDesc({do_color=true}, self.actor:getInven(item.object:wornInven())) end
self.c_desc:switchItem(item, item.desc, true)
elseif item.last_display_x and item.data and item.data.desc then
game:tooltipDisplayAtMap(item.last_display_x, item.last_display_y, item.data.desc, {up=true}, force)
end
self.cur_item = item
end
function _M:use(item)
......
......@@ -46,6 +46,7 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
},
fct=function(item, sel, button, event) self:use(item, button, event) end,
select=function(item, sel) self:select(item) end,
select_tab=function(item) self:select(item) end,
on_drag=function(item) self:onDrag(item, "store-sell") end,
on_drag_end=function() self:onDragTakeoff("store-buy") end,
}
......@@ -90,6 +91,10 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
{right=0, top=0, ui=self.c_inven},
{hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
}
self.c_inven.c_inven.on_focus_change = function(ui_self, status) if status == true then self:select(ui_self.list[ui_self.sel]) end end
self.c_store.c_inven.on_focus_change = function(ui_self, status) if status == true then self:select(ui_self.list[ui_self.sel]) end end
self:setFocus(self.c_inven)
self:setupUI()
......@@ -117,8 +122,11 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
end
game:tooltipDisplayAtMap(x or item.last_display_x, item.last_display_y, item.object:getDesc({do_color=true}, game.player:getInven(item.object:wornInven())))
elseif item.last_display_x and item.data and item.data.desc then
game:tooltipDisplayAtMap(item.last_display_x, item.last_display_y, item.data.desc, {up=true})
end
end
self.key.any_key = function(sym)
-- Control resets the tooltip
if (sym == self.key._LCTRL or sym == self.key._RCTRL) and sym~=self.prev_ctrl then local i = self.cur_item self.cur_item = nil self:select(i, true) end
......@@ -140,18 +148,6 @@ function _M:select(item, force)
self.cur_item = item
end
function _M:on_recover_focus()
if self.focus_ui and self.focus_ui.ui == self.c_inven then self:select(self.c_inven.c_inven.list[self.c_inven.c_inven.sel], true)
elseif self.focus_ui and self.focus_ui.ui == self.c_store then self:select(self.c_store.c_inven.list[self.c_store.c_inven.sel], true)
end
end
function _M:on_focus(id, ui)
if self.focus_ui and self.focus_ui.ui == self.c_inven then self:select(self.c_inven.c_inven.list[self.c_inven.c_inven.sel])
elseif self.focus_ui and self.focus_ui.ui == self.c_store then self:select(self.c_store.c_inven.list[self.c_store.c_inven.sel])
end
end
function _M:use(item, force)
if item and item.object then
if self.focus_ui and self.focus_ui.ui == self.c_store then
......
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