summaryrefslogtreecommitdiff
path: root/Data/BuiltIn/Libraries/lua-addons/addons/bluguide/ui/traitboxes.lua
blob: 85edb303fe0195e0f54813478639ff8cf350b659 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
local tbx = {}
buttons = require("ui/buttons")
texts = require("texts")
spellbuttons = require("ui/spellbuttons")

local default_settings = {
    text = { size = 10, font = 'Lucida Console' },
    bg = { alpha = 120, red = 0, green = 0, blue = 0, visible = false },
    flags = {draggable = false}
}

local header_settings = {
    text = { size = 10, font = 'Lucida Console',},
    bg = { alpha = 200, red = 0, green = 100, blue = 100, visible = false },
}

function tbx.new(trait)
    local me = { trait = trait, x = 0, y = 0, splist = {}, collapsed = false}
    
    me.greybox = texts.new("", default_settings)
    me.greenbox = texts.new("", default_settings)
    me.greybox:color(190, 190, 190)
    me.greenbox:color(50, 255, 50)
    me.greenbox:bg_visible(true)
    me.greybox:bg_visible(false)
    
    me.header = buttons.new(string.format('- %-24s', trait.name), header_settings)
    me.header.bold(false)
    me.header.color(255, 255, 255)
    me.header.bg_color(0, 100, 100)
    me.header.left_click = function() collapsetrait(me) end
    me.header.hover_on = function() show_bg(me) end
    me.header.hover_off = function() hide_bg(me) end
    
    local linenum = 1
    local totalpoints = 0
    for k, v in pairs(trait.spells) do
        if spellinfo[v.id].level <= setspells.limits.level then
            me.splist[#me.splist+1] = spellbuttons.new(string.format('  %-20s %i %i', v.name, v.cost, v.points), v.id, v.cost, me.x, me.y + (linenum * lineheight))
            me.splist[#me.splist]:update()
            linenum = linenum + 1
            totalpoints = totalpoints + v.points
        end
    end
    
    if totalpoints >= 8 then return setmetatable(me, {__index = tbx}) end
    
    for _, v in pairs(me.splist) do
        v:destroy()
    end
    return nil
end

function tbx.update(me)
    local vspace = "                          \n  "
    for _, v in pairs(me.splist) do
        v:update()
        if not me.collapsed then
            vspace = vspace.."\n    "
        end
    end
        
    local traitpoints = 0
    for k, v in pairs(me.trait.spells) do
        if setspells[v.id] then
            traitpoints = traitpoints + v.points
        end
    end
    
    if traitpoints > 7 and giftexempttraits[me.trait.name] == nil then
        traitpoints = traitpoints + (8 * setspells.gifts)
    end
    
    me.greybox:text(vspace)
    me.greenbox:text(vspace)
    
    for v = 8, 48 do
        if me.trait.tiers[v] ~= nil then
            if me.trait.name == "Double/Triple Attack" then
                if v == 8 then
                    if traitpoints == 8 or traitpoints == 12 or sub == 'WAR' then
                        me.greenbox:append(string.format('%s ', me.trait.tiers[v]))
                        me.greybox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
                    else
                        me.greybox:append(string.format('%s ', me.trait.tiers[v]))
                        me.greenbox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
                    end
                elseif traitpoints >= 16 or sub == "THF" then
                    me.greenbox:append(string.format('%s ', me.trait.tiers[v]))
                    me.greybox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
                else
                    me.greybox:append(string.format('%s ', me.trait.tiers[v]))
                    me.greenbox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
                end
            elseif v <= traitpoints or (me.trait.subs[sub] and me.trait.subs[sub] >= v) then
                me.greenbox:append(string.format('%s ', me.trait.tiers[v]))
                me.greybox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
            else
                me.greybox:append(string.format('%s ', me.trait.tiers[v]))
                me.greenbox:append(string.gsub(me.trait.tiers[v], ".", " ").." ")
            end
        end
    end
end

function tbx.bottom(me)
    if not me.collapsed then
        return me.y + ((2 + #me.splist) * lineheight)
    else
        return me.y + (2 * lineheight)
    end
end

function tbx.left(me)
    return me.x 
end

function tbx.show(me)
    if not me.collapsed then
        for _, v in pairs(me.splist) do
            v:show()
        end
    end
    me.greenbox:show()
    me.greybox:show()
    me.header.show()
end

function tbx.pos(me, x, y)
    me.x = x
    me.y = y
    me.greybox:pos(x, y)
    me.greenbox:pos(x, y)
    me.header.pos(x, y)
    local by = 0
    for i = 1, #me.splist do
        by = by + lineheight
        me.splist[i]:pos(x, y+by)
    end
end

function tbx.hide(me)
    for _, v in pairs(me.splist) do
        v:hide()
    end
    me.greenbox:hide()
    me.greybox:hide()
    me.header.hide()
end

function show_bg(me)
    me.header.bg_visible(true)
end

function hide_bg(me)
    me.header.bg_visible(false)
end

function collapsetrait(me)
    me.collapsed = not me.collapsed
    if me.collapsed then
        me.header.text:text(string.format('+ %-24s', me.trait.name))
        me.header.bold(true)
        for _, v in pairs(me.splist) do
            v:hide()
        end
        me:update()
    else
        me.header.text:text(string.format('- %-24s', me.trait.name))
        me.header.bold(false)
        for _, v in pairs(me.splist) do
            v:show()
        end
    end
    update()
end

return tbx

--Copyright © 2015, Anissa
--All rights reserved.

--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are met:

--    * Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--    * Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in the
--      documentation and/or other materials provided with the distribution.
--    * Neither the name of bluGuide nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.

--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
--ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
--WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
--DISCLAIMED. IN NO EVENT SHALL ANISSA BE LIABLE FOR ANY
--DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
--(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
--LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
--ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
--(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.