Mercurial > wow > reaction
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/classes/ReAction_ColorScheme.lua Tue Mar 20 21:25:29 2007 +0000 @@ -0,0 +1,107 @@ +-- ReAction.IColorScheme is an interface to describe color schemes for hotkey labels and +-- icon/border colorization, depending on the current state. +-- + +local AceOO = AceLibrary("AceOO-2.0") + +ReAction.IColorScheme = AceOO.Interface { + GetHotkeyColor = "function", -- r,g,b,a = GetHotkeyColor( isUsable, notEnoughMana, outOfRange, [bindingText] ) + GetIconColor = "function", -- r,g,b,a = GetIconColor( isUsable, notEnoughMana, outOfRange ) + GetBorderColor = "function", -- r,g,b,a = GetBorderColor( isUsable, notEnoughMana, outOfRange ) +} + + + +-- ReAction.DefaultColorScheme is a Mixin implementation of ReAction.IColorScheme which +-- supports the standard Blizzard colorization plus optional hotkey modifier-driven colorization +-- and colorizing icons red (in addition to hotkeys) when out of range. +-- +-- DefaultColorScheme makes use of self.config as follows: +-- +-- self.config = { +-- keyBindColorCode = true/false, -- color-code keybindings based on modifier key +-- } + + +ReAction.DefaultColorScheme = AceOO.Mixin { + "GetHotkeyColor", + "GetModifiedHotkeyColor", -- returns the default modified color (if configured) + "GetIconColor", + "GetBorderColor" +} + + +-- private variables +local hotKeyDefaultColor = { r=1.00, g=1.00, b=1.00, a=1.00 } -- white +local hotKeyDisabledColor = { r=0.60, g=0.60, b=0.60, a=1.00 } -- 60% gray +local hotKeyOutOfRangeColor = { r=1.00, g=0.20, b=0.20, a=1.00 } -- red + +local actionUsableColor = { r=1.00, g=1.00, b=1.00, a=1.00 } -- white +local actionNotUsableColor = { r=0.40, g=0.40, b=0.40, a=1.00 } -- 40% gray +local actionNotEnoughManaColor = { r=0.20, g=0.20, b=0.70, a=1.00 } -- medium blue +local actionOutOfRangeColor = { r=1.00, g=0.20, b=0.20, a=1.00 } -- red + +local hotKeyModifierColors = { + S = { r=0.60, g=0.60, b=1.00, a=1.00 }, -- shift (blue) + C = { r=1.00, g=0.82, b=0.00, a=1.00 }, -- ctrl (gold) + A = { r=0.10, g=1.00, b=0.10, a=1.00 }, -- alt (green) + M = { r=0.90, g=0.30, b=1.00, a=1.00 }, -- mouse (purple) +} + +-- build list of modifier keys (as a string) from table above +local hotKeyModifiers = "" +for k, _ in pairs(hotKeyModifierColors) do + hotKeyModifiers = hotKeyModifiers..k +end + +-- private functions +-- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor() +local function tcolor(c) + return c.r, c.g, c.b, c.a +end + + + +-- mixin methods + +local RADCS = ReAction.DefaultColorScheme + +function RADCS:GetHotkeyColor( isUsable, notEnoughMana, outOfRange, bindingTxt ) + if isUsable or notEnoughMana then + return tcolor(self:GetModifiedHotkeyColor(bindingTxt)) + elseif outOfRange then + return tcolor(hotKeyOutOfRangeColor) + else + return tcolor(hotKeyDisabledColor) + end +end + +function RADCS:GetModifiedHotkeyColor(txt) + local c = hotKeyDefaultColor + if txt and self.config.keyBindColorCode then + local modKey = string.match( txt or "", "(["..hotKeyModifiers.."])%-") + c = modKey and hotKeyModifierColors[modKey] or c + end + return c +end + +function RADCS:GetIconColor( isUsable, notEnoughMana, outOfRange ) + if isUsable then + return tcolor(actionUsableColor) + elseif notEnoughMana then + return tcolor(actionNotEnoughManaColor) + elseif outOfRange then + return tcolor(actionOutOfRangeColor) + else + return tcolor(actionNotUsableColor) + end +end + +function RADCS:GetBorderColor( isUsable, notEnoughMana, outOfRange ) + if isUsable or notEnoughMana or outOfRange then + return tcolor(actionUsableColor) + else + return tcolor(actionNotUsableColor) + end +end +