comparison classes/ReAction_ColorScheme.lua @ 7:f920db5fc6b1

version 0.3
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:25:29 +0000
parents
children
comparison
equal deleted inserted replaced
6:2da5089ab7ff 7:f920db5fc6b1
1 -- ReAction.IColorScheme is an interface to describe color schemes for hotkey labels and
2 -- icon/border colorization, depending on the current state.
3 --
4
5 local AceOO = AceLibrary("AceOO-2.0")
6
7 ReAction.IColorScheme = AceOO.Interface {
8 GetHotkeyColor = "function", -- r,g,b,a = GetHotkeyColor( isUsable, notEnoughMana, outOfRange, [bindingText] )
9 GetIconColor = "function", -- r,g,b,a = GetIconColor( isUsable, notEnoughMana, outOfRange )
10 GetBorderColor = "function", -- r,g,b,a = GetBorderColor( isUsable, notEnoughMana, outOfRange )
11 }
12
13
14
15 -- ReAction.DefaultColorScheme is a Mixin implementation of ReAction.IColorScheme which
16 -- supports the standard Blizzard colorization plus optional hotkey modifier-driven colorization
17 -- and colorizing icons red (in addition to hotkeys) when out of range.
18 --
19 -- DefaultColorScheme makes use of self.config as follows:
20 --
21 -- self.config = {
22 -- keyBindColorCode = true/false, -- color-code keybindings based on modifier key
23 -- }
24
25
26 ReAction.DefaultColorScheme = AceOO.Mixin {
27 "GetHotkeyColor",
28 "GetModifiedHotkeyColor", -- returns the default modified color (if configured)
29 "GetIconColor",
30 "GetBorderColor"
31 }
32
33
34 -- private variables
35 local hotKeyDefaultColor = { r=1.00, g=1.00, b=1.00, a=1.00 } -- white
36 local hotKeyDisabledColor = { r=0.60, g=0.60, b=0.60, a=1.00 } -- 60% gray
37 local hotKeyOutOfRangeColor = { r=1.00, g=0.20, b=0.20, a=1.00 } -- red
38
39 local actionUsableColor = { r=1.00, g=1.00, b=1.00, a=1.00 } -- white
40 local actionNotUsableColor = { r=0.40, g=0.40, b=0.40, a=1.00 } -- 40% gray
41 local actionNotEnoughManaColor = { r=0.20, g=0.20, b=0.70, a=1.00 } -- medium blue
42 local actionOutOfRangeColor = { r=1.00, g=0.20, b=0.20, a=1.00 } -- red
43
44 local hotKeyModifierColors = {
45 S = { r=0.60, g=0.60, b=1.00, a=1.00 }, -- shift (blue)
46 C = { r=1.00, g=0.82, b=0.00, a=1.00 }, -- ctrl (gold)
47 A = { r=0.10, g=1.00, b=0.10, a=1.00 }, -- alt (green)
48 M = { r=0.90, g=0.30, b=1.00, a=1.00 }, -- mouse (purple)
49 }
50
51 -- build list of modifier keys (as a string) from table above
52 local hotKeyModifiers = ""
53 for k, _ in pairs(hotKeyModifierColors) do
54 hotKeyModifiers = hotKeyModifiers..k
55 end
56
57 -- private functions
58 -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor()
59 local function tcolor(c)
60 return c.r, c.g, c.b, c.a
61 end
62
63
64
65 -- mixin methods
66
67 local RADCS = ReAction.DefaultColorScheme
68
69 function RADCS:GetHotkeyColor( isUsable, notEnoughMana, outOfRange, bindingTxt )
70 if isUsable or notEnoughMana then
71 return tcolor(self:GetModifiedHotkeyColor(bindingTxt))
72 elseif outOfRange then
73 return tcolor(hotKeyOutOfRangeColor)
74 else
75 return tcolor(hotKeyDisabledColor)
76 end
77 end
78
79 function RADCS:GetModifiedHotkeyColor(txt)
80 local c = hotKeyDefaultColor
81 if txt and self.config.keyBindColorCode then
82 local modKey = string.match( txt or "", "(["..hotKeyModifiers.."])%-")
83 c = modKey and hotKeyModifierColors[modKey] or c
84 end
85 return c
86 end
87
88 function RADCS:GetIconColor( isUsable, notEnoughMana, outOfRange )
89 if isUsable then
90 return tcolor(actionUsableColor)
91 elseif notEnoughMana then
92 return tcolor(actionNotEnoughManaColor)
93 elseif outOfRange then
94 return tcolor(actionOutOfRangeColor)
95 else
96 return tcolor(actionNotUsableColor)
97 end
98 end
99
100 function RADCS:GetBorderColor( isUsable, notEnoughMana, outOfRange )
101 if isUsable or notEnoughMana or outOfRange then
102 return tcolor(actionUsableColor)
103 else
104 return tcolor(actionNotUsableColor)
105 end
106 end
107