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

plop

git-svn-id: http://svn.net-core.org/repos/t-engine4@2279 51575b47-30f0-44d4-a5cc-537603b46e54
parent 503b2507
No related branches found
No related tags found
No related merge requests found
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010 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"
require "engine.ui.Dialog"
local List = require "engine.ui.List"
local GetQuantity = require "engine.dialogs.GetQuantity"
module(..., package.seeall, class.inherit(engine.ui.Dialog))
function _M:init()
self:generateList()
engine.ui.Dialog.init(self, "Switch to which character?", 1, 1)
local list = List.new{width=400, nb_items=#self.list, list=self.list, fct=function(item) self:use(item) end}
self:loadUI{
{left=0, top=0, ui=list},
}
self:setupUI(true, true)
self.key:addCommands{ __TEXTINPUT = function(c) if self.list and self.list.chars[c] then self:use(self.list[self.list.chars[c]]) end end}
self.key:addBinds{ EXIT = function() game:unregisterDialog(self) end, }
end
function _M:use(item)
if not item then return end
game:unregisterDialog(self)
game.party:setPlayer(item.actor)
end
function _M:generateList()
local list = {}
for i, act in ipairs(game.party.m_list) do
local def = game.party.members[act]
if def.control == "full" and not act.dead then
list[#list+1] = {name=act.name, actor=act}
end
end
local chars = {}
for i, v in ipairs(list) do
v.name = self:makeKeyChar(i)..") "..v.name
chars[self:makeKeyChar(i)] = i
end
list.chars = chars
self.list = list
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