ce390f57f603b0cf8328bdf09fe02e5db544bf14
[wowui.git] / kehys / player.lua
1 -- player.lua
2 local _, addon = ...;
3 local unpack = unpack;
4 local format = string.format;
5 local CFrame = CreateFrame("Frame", "kehysPlayerInit", UIParent);
6
7 local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist";
8 local vehicletoggle = [=[
9     if newstate == "vehicle" then
10         self:SetAttribute("displayed", self:GetAttribute("vehicle"));
11     else
12         self:SetAttribute("displayed", self:GetAttribute("unit"));
13     end
14 ]=]
15
16 local updater = nil;
17 function addon.PlayerFrame(parent, width, height, update, event)
18     assert(type(parent) == "table", "Player frame creation missing parent!");
19     assert(type(width) == "number", "Player frame creation missing width!");
20     assert(type(height) == "number", "Player frame creation missing height!");
21     assert(type(update) == "function",
22            "Player frame creation missing update function!");
23     assert(type(event) == "function",
24            "Player frame creation missing event function!");
25
26     local f = CreateFrame("Button", "kehysPlayer", parent,
27                           "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
28     f:Hide();
29     f:SetPoint("CENTER", parent, "CENTER", 10, 10);
30     f:SetWidth(width);
31     f:SetHeight(height);
32     f.barwidth = width - 2; -- 1px padding
33     f:SetAttribute("unit", "player");
34     f:SetAttribute("displayed", "player");
35     f:SetAttribute("vehicle", "vehicle");
36     f.nonraid = true;
37     f.prev = {};
38     -- empty, just to be able to use general updater
39     f.alert = {};
40     f.heal = {};
41     f.tankcd = {};
42     f.stacks = {};
43     f.buff1 = {};
44     f.incoming = {};
45
46     updater = function()
47         CTimerAfter(0.1, updater);
48         update(f);
49     end
50     f:SetScript("OnEvent", event);
51     f:SetAttribute("*type1", "target");
52     f:SetAttribute("*type2", "togglemenu");
53     f:SetAttribute("toggleForVehicle", true);
54     RegisterStateDriver(f, "vehicleui", "[vehicleui] vehicle; no");
55     f:SetAttribute("_onstate-vehicleui", vehicletoggle);
56
57     -- create visuals
58     f.base = f:CreateTexture(nil, "BACKGROUND");
59     f.base:SetAllPoints();
60     f.base:SetColorTexture(1, 1, 1);
61     f.base:SetVertexColor(unpack(addon.Colors.Base));
62     f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2);
63     f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
64     f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
65     f.background:SetColorTexture(0.7, 0.7, 0.7);
66     f.health = f:CreateTexture(nil, "BORDER");
67     f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
68     f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, 1);
69     f.health:SetTexture(barTexture);
70     f.health:SetVertexColor(0.3, 0.3, 0.3);
71     f.health:Hide();
72     f.mana = f:CreateTexture(nil, "BORDER");
73     f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -1);
74     f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
75     f.mana:SetTexture(barTexture);
76     f.mana:SetVertexColor(0.3, 0.4, 0.7);
77     f.mana:Hide();
78     f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
79     f.manatext:SetPoint("RIGHT", frame.background, "RIGHT", -2, -height/4);
80     f.manatext:Hide();
81     f.shield = f:CreateTexture(nil, "BORDER");
82     f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
83     f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
84     f.shield:SetTexture(barTexture);
85     f.shield:SetVertexColor(0, 0.7, 1);
86     f.shield:Hide();
87     f.shieldhl = f:CreateTexture(nil, "ARTWORK");
88     f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
89     f.shieldhl:SetPoint("BOTTOMRIGHT", f, "RIGHT");
90     f.shieldhl:SetColorTexture(0.5, 0.8, 1);
91     f.shieldhl:Hide();
92     f.healpred = f:CreateTexture(nil, "ARTWORK");
93     f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
94     f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
95     f.healpred:SetColorTexture(0.5, 0.6, 0.5);
96     f.healpred:Hide();
97     f.healabsorb = f:CreateTexture(nil, "ARTWORK");
98     f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
99     f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
100     f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
101     f.healabsorb:Hide();
102     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
103     f.text:SetPoint("LEFT", f.health, "LEFT", 10, 0);
104     f.text:SetFont(STANDARD_TEXT_FONT, 13);
105     f.text:Hide();
106     f.targeticon = f:CreateTexture(nil, "OVERLAY");
107     f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
108     f.targeticon:SetWidth(12);
109     f.targeticon:SetHeight(12);
110     f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
111     f.targeticon:Hide();
112
113     registerEvents(f);
114     registerUnitEvents(f);
115     event(f, "UPDATE_ALL_BARS");
116     updater();
117     f.Show();
118 end
119
120 CFrame:SetScript("OnEvent", function(self)
121     self:UnregisterAllEvents();
122     CFrame:SetFrameStrata("LOW");
123     CFrame:SetPoint("CENTER", nil, "CENTER");
124     CFrame:SetWidth(2);
125     CFrame:SetHeight(2);
126     initPlayer(self, 180, 100, addon.FrameUpdate, addon.UnitEvent);
127 end);
128 CFrame:RegisterEvent("PLAYER_LOGIN");