-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsm_skillpalette.lua
120 lines (112 loc) · 4.15 KB
/
sm_skillpalette.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
-- This template holds the renderfuncs etc. for the skillpelettes
sm_skillpalette = class('sm_skillpalette')
sm_skillpalette.table = _G["table"]
-- this function is automatically called when a new "instance" of the class('..') is created with sm_skill:new(...)
function sm_skillpalette:initialize(data)
if ( data ~= nil ) then
for i,k in pairs(data) do
self[i] = k
end
end
end
-- To Draw the Icon of this palette in the skill palette selector. Returns the selected palette UID
function sm_skillpalette:RenderIcon(currentselectedsetuid)
local result
local highlighted
if ( currentselectedsetuid and self.uid == currentselectedsetuid ) then
GUI:PushStyleColor(GUI.Col_Button,1.0,0.75,0.0,0.7)
GUI:PushStyleColor(GUI.Col_ButtonHovered,1.0,0.75,0.0,0.8)
GUI:PushStyleColor(GUI.Col_ButtonActive,1.0,0.75,0.0,0.9)
highlighted = true
end
if (self.icon and FileExists(sm_mgr.iconpath.."\\"..self.icon..".png") ) then
result = GUI:ImageButton("##"..self.uid, sm_mgr.iconpath.."\\"..self.icon..".png",40,40)
else
sm_webapi.getimage( self)
result = GUI:ImageButton("##"..self.uid, sm_mgr.iconpath.."\\default.png",40,40)
end
if ( highlighted ) then GUI:PopStyleColor(3) end
if (GUI:IsItemHovered()) then GUI:SetTooltip( GetString(self.uid)) end
return result
end
-- To Draw the Skills in the Skill Palette Editor Window. Returns the selected skill ID
function sm_skillpalette:RenderSkills(currentselectedid)
if ( self.skills_luacode ) then
local skilldata
if ( type(self.skills_luacode) == "table" ) then
skilldata = self.skills_luacode
else
ml_error("TODO: ADD STRING LOAD HANDLER FOR PUBLIC SKILL SETS IN sm_skillpalette:RenderSkills")
end
if ( skilldata ) then
-- copy / save the key in the table value
for i,s in pairs(skilldata) do
s.id = i
end
for i,s in sm_skillpalette.table.pairsByValueAttribute(skilldata, "icon") do
local highlighted
if ( currentselectedid and s.id == currentselectedid ) then
GUI:PushStyleColor(GUI.Col_Button,1.0,0.75,0.0,0.7)
GUI:PushStyleColor(GUI.Col_ButtonHovered,1.0,0.75,0.0,0.8)
GUI:PushStyleColor(GUI.Col_ButtonActive,1.0,0.75,0.0,0.9)
GUI:PushStyleColor(GUI.Col_Text,1.0,1.0,1.0,1.0)
highlighted = true
end
local selected
if (s.icon and FileExists(sm_mgr.iconpath.."\\"..s.icon..".png") ) then
selected = GUI:ImageButton("##"..tostring(s.id), sm_mgr.iconpath.."\\"..s.icon..".png",30,30)
else
sm_webapi.getimage( s)
selected = GUI:ImageButton("##"..tostring(s.id), sm_mgr.iconpath.."\\default.png",30,30)
end
if ( selected ) then currentselectedid = s.id end
if ( highlighted ) then GUI:PopStyleColor(4) end
if (GUI:IsItemHovered()) then GUI:SetTooltip( GetString(s.icon) .. " - id: " .. s.id) end
GUI:SameLine()
local x,y = GUI:GetCursorPos()
GUI:SetCursorPos(x,y+10)
GUI:Text(GetString(s.icon))
x,y = GUI:GetCursorPos()
GUI:SetCursorPos(x,y-10)
end
end
end
return currentselectedid
end
-- Returns a new instance of sm_skill with the data from this palette
function sm_skillpalette:GetSkillData( id )
if ( self.skills_luacode ) then
local skilldata
if ( type(self.skills_luacode) == "table" ) then
skilldata = self.skills_luacode
else
ml_error("TODO: ADD STRING LOAD HANDLER FOR PUBLIC SKILL SETS IN sm_skillpalette:GetSkill")
end
if ( skilldata and skilldata[id]) then
local data = {}
for i,k in pairs (skilldata[id]) do
data[i] = k
end
data.id = id
data.skillpalette = self
data.skillpaletteuid = self.uid
return data
end
end
end
function sm_skillpalette:IsActive(context)
ml_error("Implement a 'function sm_skillpalette:IsActive(context)' in your SkillPalette : "..tostring(self.uid))
return false
end
function sm_skillpalette:CanActivate(context)
ml_error("Implement a 'function sm_skillpalette:CanActivate(context)' in your SkillPalette : "..tostring(self.uid))
return false
end
function sm_skillpalette:Activate(context)
ml_error("Implement a 'function sm_skillpalette:Activate(context)' in your SkillPalette : "..tostring(self.uid))
end
function sm_skillpalette:Deactivate(context)
end
function sm_skillpalette:CanCast(context,skillid)
return true
end