From 66054a0462e3a6a66d08a1d26c95ad3882ec238f Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 4 Dec 2009 01:31:33 +0000
Subject: [PATCH] 'm' use talents menu

git-svn-id: http://svn.net-core.org/repos/t-engine4@91 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/dialogs/UseTalents.lua            | 81 +++++++++++++++++++
 game/engine/interface/ActorTalents.lua        |  8 +-
 game/modules/tome/class/Game.lua              |  2 +-
 game/modules/tome/data/talents/misc/misc.lua  |  8 ++
 .../tome/data/talents/spells/spells.lua       |  1 +
 5 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 game/engine/dialogs/UseTalents.lua

diff --git a/game/engine/dialogs/UseTalents.lua b/game/engine/dialogs/UseTalents.lua
new file mode 100644
index 0000000000..dcb7f9c990
--- /dev/null
+++ b/game/engine/dialogs/UseTalents.lua
@@ -0,0 +1,81 @@
+require "engine.class"
+require "engine.Dialog"
+
+module(..., package.seeall, class.inherit(engine.Dialog))
+
+function _M:init(actor)
+	self.actor = actor
+	engine.Dialog.init(self, "Use Talents: "..actor.name, game.w / 2, game.h / 2)
+
+	self:generateList()
+
+	self.talentsel = 1
+	self:keyCommands{
+		_UP = function() self.talentsel = util.boundWrap(self.talentsel - 1, 1, #self.list) end,
+		_DOWN = function() self.talentsel = util.boundWrap(self.talentsel + 1, 1, #self.list) end,
+		_RETURN = function() self:use() end,
+		_ESCAPE = function() game:unregisterDialog(self) end,
+		__TEXTINPUT = function(c)
+			if c:find("^[a-z]$") then
+				self.talentsel = 1 + string.byte(c) - string.byte('a')
+				self:use()
+			end
+		end,
+	}
+	self:mouseZones{
+		{ x=2, y=5, w=350, h=self.font_h*#self.list, fct=function(button, x, y, xrel, yrel, tx, ty)
+			self.talentsel = 1 + math.floor(ty / self.font_h)
+			if button == "left" then self:use()
+			elseif button == "right" then
+			end
+		end },
+	}
+end
+
+function _M:use()
+	game:unregisterDialog(self)
+	self.actor:useTalent(self.list[self.talentsel].talent)
+end
+
+function _M:generateList()
+	-- Makes up the list
+	local list = {}
+	local i = 0
+	for tid, _ in pairs(self.actor.talents) do
+		local t = self.actor:getTalentFromId(tid)
+		if t and t.mode ~= "passive" then
+			local typename = "talent"
+			if t.type[1]:find("^spell/") then typename = "spell" end
+			list[#list+1] = { name=string.char(string.byte('a') + i)..")  "..t.name.." ("..typename..")", talent=t.id }
+			i = i + 1
+		end
+	end
+	self.list = list
+end
+
+function _M:drawDialog(s)
+	-- Description part
+	self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
+
+	local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select a stat; #00FF00#right key#FFFFFF# to learn; #00FF00#left key#FFFFFF# to unlearn.
+Mouse: #00FF00#Left click#FFFFFF# to learn; #00FF00#right click#FFFFFF# to unlearn.
+]]):splitLines(self.iw / 2 - 10, self.font)
+
+	local lines = {}
+	lines = self.actor:getTalentFromId(self.list[self.talentsel].talent).info(self.actor):splitLines(self.iw / 2 - 10, self.font)
+	local h = 2
+	for i = 1, #talentshelp do
+		s:drawColorString(self.font, talentshelp[i], self.iw / 2 + 5, h)
+		h = h + self.font:lineSkip()
+	end
+
+	h = h + self.font:lineSkip()
+	self:drawWBorder(s, self.iw / 2 + self.iw / 6, h - 0.5 * self.font:lineSkip(), self.iw / 6)
+	for i = 1, #lines do
+		s:drawColorString(self.font, lines[i], self.iw / 2 + 5, 2 + h)
+		h = h + self.font:lineSkip()
+	end
+
+	-- Talents
+	self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.talentsel, "name")
+end
diff --git a/game/engine/interface/ActorTalents.lua b/game/engine/interface/ActorTalents.lua
index 2c5071e22e..a77b491fd9 100644
--- a/game/engine/interface/ActorTalents.lua
+++ b/game/engine/interface/ActorTalents.lua
@@ -40,7 +40,7 @@ function _M:newTalent(t)
 	t.short_name = t.short_name:upper():gsub("[ ]", "_")
 	t.mode = t.mode or "activated"
 	t.points = t.points or 1
-	assert(t.mode == "activated" or t.mode == "sustained", "wrong talent mode, requires either 'activated' or 'sustained'")
+	assert(t.mode == "activated" or t.mode == "sustained" or t.mode == "passive", "wrong talent mode, requires either 'activated' or 'sustained'")
 	assert(t.info, "no talent info")
 
 	-- Can pass a string, make it into a function
@@ -270,3 +270,9 @@ function _M:cooldownTalents()
 		end
 	end
 end
+
+--- Show usage dialog
+function _M:useTalents()
+	local d = require("engine.dialogs.UseTalents").new(self)
+	game:registerDialog(d)
+end
diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua
index 1a280726e2..adb3b5762b 100644
--- a/game/modules/tome/class/Game.lua
+++ b/game/modules/tome/class/Game.lua
@@ -279,7 +279,7 @@ function _M:setupCommands()
 			self.player:useTalent(ActorTalents.T_BLINK)
 		end,
 		_m = function()
-			self.player:listTalents()
+			self.player:useTalents()
 		end,
 
 		[{"_g","shift"}] = function()
diff --git a/game/modules/tome/data/talents/misc/misc.lua b/game/modules/tome/data/talents/misc/misc.lua
index 2e11e98dff..16cf90cc94 100644
--- a/game/modules/tome/data/talents/misc/misc.lua
+++ b/game/modules/tome/data/talents/misc/misc.lua
@@ -6,12 +6,14 @@ newTalent{
 	name = "Mana Pool",
 	type = {"base/class", 1},
 	info = "Allows you to have a mana pool. Mana is used to cast all spells.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Stamina Pool",
 	type = {"base/class", 1},
 	info = "Allows you to have a stamina pool. Stamina is used to activate special combat attacks.",
+	mode = "passive",
 	hide = true,
 }
 
@@ -19,35 +21,41 @@ newTalent{
 	name = "Improved Health I",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Improved Health II",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Improved Health III",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Decreased Health I",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Decreased Health II",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
 newTalent{
 	name = "Decreased Health III",
 	type = {"base/race", 1},
 	info = "Improves the number of health points per levels.",
+	mode = "passive",
 	hide = true,
 }
diff --git a/game/modules/tome/data/talents/spells/spells.lua b/game/modules/tome/data/talents/spells/spells.lua
index 673fde5369..b68f2bb932 100644
--- a/game/modules/tome/data/talents/spells/spells.lua
+++ b/game/modules/tome/data/talents/spells/spells.lua
@@ -119,6 +119,7 @@ newTalent{
 newTalent{
 	name = "Teleport Control",
 	type = {"spell/conveyance",2},
+	mode = "passive",
 	require = { stat = { mag=38 }, },
 	info = function(self)
 		return ([[Allows teleport spells to specify a target area. You will blink in this radius randomly.
-- 
GitLab