Go to most recent revision | Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 2 | Seerah-7 | --why did health bar show in combat? (while committing suicide) |
2 | Seerah-7 | --add "you have died" text to inside player frame |
|
3 | Seerah-7 | ||
4 | Seerah-7 | local wm = GetWindowManager() |
|
5 | Seerah-7 | local strformat = string.format |
|
6 | Seerah-7 | local db |
|
7 | Seerah-7 | ||
8 | Seerah-7 | --create these in the main chunk |
|
9 | Seerah-7 | local playerFrame = wm:CreateTopLevelWindow("ZAMUnitFrames_Player") |
|
10 | Seerah-7 | do |
|
11 | Seerah-7 | playerFrame.health = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerHealth", playerFrame, "ZO_DefaultStatusBar") |
|
12 | Seerah-7 | playerFrame.magicka = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerMagicka", playerFrame, "ZO_DefaultStatusBar") |
|
13 | Seerah-7 | playerFrame.stamina = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerStamina", playerFrame, "ZO_DefaultStatusBar") |
|
14 | Seerah-7 | playerFrame.health.text = wm:CreateControl("ZAMUnitFrames_PlayerHealthText", playerFrame, CT_LABEL) |
|
15 | Seerah-7 | playerFrame.magicka.text = wm:CreateControl("ZAMUnitFrames_PlayerMagickaText", playerFrame, CT_LABEL) |
|
16 | Seerah-7 | playerFrame.stamina.text = wm:CreateControl("ZAMUnitFrames_PlayerStaminaText", playerFrame, CT_LABEL) |
|
17 | Seerah-7 | end |
|
18 | Seerah-7 | ||
19 | Seerah-7 | local defaults = { |
|
20 | Seerah-7 | flatBars = true, |
|
21 | Seerah-7 | locked = true, |
|
22 | Seerah-7 | } |
|
23 | Seerah-7 | ||
24 | Seerah-7 | local function CreatePlayerFrame() |
|
25 | Seerah-7 | --main frame |
|
26 | Seerah-7 | playerFrame:SetDimensions(300, 54) |
|
27 | Seerah-7 | if not db.playerFrame then |
|
28 | Seerah-7 | db.playerFrame = {} |
|
29 | Seerah-7 | db.playerFrame.point = {["a"]=BOTTOM, ["b"]=BOTTOM, ["x"]=0, ["y"]=-100} |
|
30 | Seerah-7 | end |
|
31 | Seerah-7 | local anchor = db.playerFrame.point |
|
32 | Seerah-7 | playerFrame:SetAnchor(anchor.a, GuiRoot, anchor.b or anchor.a, anchor.x, anchor.y) |
|
33 | Seerah-7 | playerFrame:SetDrawLayer(DL_BACKGROUND) |
|
34 | Seerah-7 | playerFrame:SetMouseEnabled(true) |
|
35 | Seerah-7 | playerFrame:SetMovable(not db.locked) |
|
36 | Seerah-7 | playerFrame:SetClampedToScreen(true) |
|
37 | Seerah-7 | playerFrame:SetHandler("OnMouseUp", function(self) |
|
38 | Seerah-7 | self:StopMovingOrResizing() |
|
39 | Seerah-7 | local _,a,_,b,x,y = self:GetAnchor() |
|
40 | Seerah-7 | --db[self:GetName()].point = {["a"]=a, ["b"]=b, ["x"]=x, ["y"]=y} |
|
41 | Seerah-7 | db.playerFrame.point = {["a"]=a, ["b"]=b, ["x"]=x, ["y"]=y} |
|
42 | Seerah-7 | end) |
|
43 | Seerah-7 | ||
44 | Seerah-7 | --border & background |
|
45 | Seerah-7 | playerFrame.frameL = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerFrameL", playerFrame, "ZO_PlayerAttributeFrameLeft") |
|
46 | Seerah-7 | playerFrame.frameL:SetDimensions(10, 65) |
|
47 | Seerah-7 | playerFrame.frameR = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerFrameR", playerFrame, "ZO_PlayerAttributeFrameRight") |
|
48 | Seerah-7 | playerFrame.frameR:SetDimensions(10, 65) |
|
49 | Seerah-7 | playerFrame.frameC = wm:CreateControlFromVirtual("ZAMUnitFrames_PlayerFrameC", playerFrame, "ZO_PlayerAttributeFrameCenter") |
|
50 | Seerah-7 | playerFrame.frameC:SetAnchor(TOPLEFT, playerFrame.frameL, TOPRIGHT, 0, 0) |
|
51 | Seerah-7 | playerFrame.frameC:SetAnchor(BOTTOMRIGHT, playerFrame.frameR, BOTTOMLEFT, 0, 0) |
|
52 | Seerah-7 | playerFrame.bg = wm:CreateControl("ZAMUnitFrames_PlayerBG", playerFrame, CT_TEXTURE) |
|
53 | Seerah-7 | playerFrame.bg:SetAnchorFill(playerFrame) |
|
54 | Seerah-7 | playerFrame.bg:SetColor(0, 0, 0, .5) |
|
55 | Seerah-7 | ||
56 | Seerah-7 | --health bar |
|
57 | Seerah-7 | playerFrame.health:SetAnchor(TOPLEFT, playerFrame, TOPLEFT, 1, 1) |
|
58 | Seerah-7 | playerFrame.health:SetAnchor(TOPRIGHT, playerFrame, TOPRIGHT, -1, 1) |
|
59 | Seerah-7 | playerFrame.health:SetHeight(20) |
|
60 | Seerah-7 | playerFrame.health:SetMinMax(0, 100) |
|
61 | Seerah-7 | playerFrame.health:SetValue(100) |
|
62 | Seerah-7 | playerFrame.health.gloss:SetHidden(db.flatBars) |
|
63 | Seerah-7 | playerFrame.health.text:SetFont("EsoUi\\Common\\Fonts\\Univers67.otf|36|soft-shadow-thin") |
|
64 | Seerah-7 | playerFrame.health.text:SetAnchor(LEFT, playerFrame, RIGHT, 5, 0) |
|
65 | Seerah-7 | playerFrame.health.text:SetText("100%") |
|
66 | Seerah-7 | do |
|
67 | Seerah-7 | local r1,g1,b1 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_HEALTH][1]:UnpackRGBA() |
|
68 | Seerah-7 | local r2,g2,b2 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_HEALTH][2]:UnpackRGBA() |
|
69 | Seerah-7 | playerFrame.health:SetGradientColors(r1, g1, b1, 1, r2, g2, b2, 1) |
|
70 | Seerah-7 | playerFrame.health.text:SetColor(r2, g2, b2) |
|
71 | Seerah-7 | end |
|
72 | Seerah-7 | ||
73 | Seerah-7 | --magicka bar |
|
74 | Seerah-7 | playerFrame.magicka:SetAnchor(TOPLEFT, playerFrame.health, BOTTOMLEFT, 0, 1) |
|
75 | Seerah-7 | playerFrame.magicka:SetAnchor(TOPRIGHT, playerFrame.health, BOTTOMRIGHT, 0, 1) |
|
76 | Seerah-7 | playerFrame.magicka:SetHeight(15) |
|
77 | Seerah-7 | playerFrame.magicka:SetMinMax(0,100) |
|
78 | Seerah-7 | playerFrame.magicka:SetValue(50) |
|
79 | Seerah-7 | playerFrame.magicka.gloss:SetHidden(db.flatBars) --for flat textures |
|
80 | Seerah-7 | playerFrame.magicka.text:SetFont("EsoUi\\Common\\Fonts\\Univers67.otf|22|soft-shadow-thin") |
|
81 | Seerah-7 | playerFrame.magicka.text:SetAnchor(TOPRIGHT, playerFrame, TOPLEFT, -5, 0) |
|
82 | Seerah-7 | playerFrame.magicka.text:SetText("100%") |
|
83 | Seerah-7 | do |
|
84 | Seerah-7 | local r1,g1,b1 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_MAGICKA][1]:UnpackRGBA() |
|
85 | Seerah-7 | local r2,g2,b2 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_MAGICKA][2]:UnpackRGBA() |
|
86 | Seerah-7 | playerFrame.magicka:SetGradientColors(r1, g1, b1, 1, r2, g2, b2, 1) |
|
87 | Seerah-7 | playerFrame.magicka.text:SetColor(r2, g2, b2) |
|
88 | Seerah-7 | end |
|
89 | Seerah-7 | ||
90 | Seerah-7 | --stamina bar |
|
91 | Seerah-7 | playerFrame.stamina:SetAnchor(TOPLEFT, playerFrame.magicka, BOTTOMLEFT, 0, 1) |
|
92 | Seerah-7 | playerFrame.stamina:SetAnchor(TOPRIGHT, playerFrame.magicka, BOTTOMRIGHT, 0, 1) |
|
93 | Seerah-7 | playerFrame.stamina:SetHeight(15) |
|
94 | Seerah-7 | playerFrame.stamina:SetMinMax(0,100) |
|
95 | Seerah-7 | playerFrame.stamina:SetValue(75) |
|
96 | Seerah-7 | playerFrame.stamina.gloss:SetHidden(db.flatBars) --for flat textures |
|
97 | Seerah-7 | playerFrame.stamina.text:SetFont("EsoUi\\Common\\Fonts\\Univers67.otf|22|soft-shadow-thick") |
|
98 | Seerah-7 | playerFrame.stamina.text:SetAnchor(BOTTOMRIGHT, playerFrame, BOTTOMLEFT, -5, 0) |
|
99 | Seerah-7 | playerFrame.stamina.text:SetText("100%") |
|
100 | Seerah-7 | do |
|
101 | Seerah-7 | local r1,g1,b1 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_STAMINA][1]:UnpackRGBA() |
|
102 | Seerah-7 | local r2,g2,b2 = ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_STAMINA][2]:UnpackRGBA() |
|
103 | Seerah-7 | playerFrame.stamina:SetGradientColors(r1, g1, b1, 1, r2, g2, b2, 1) |
|
104 | Seerah-7 | playerFrame.stamina.text:SetColor(r2 +.05, g2 +.05, b2 +.05) |
|
105 | Seerah-7 | end |
|
106 | Seerah-7 | end |
|
107 | Seerah-7 | ||
108 | Seerah-7 | local function InitializeBars() |
|
109 | Seerah-7 | local curHealth, maxHealth, effMaxHealth = GetUnitPower("player", POWERTYPE_HEALTH) |
|
110 | Seerah-7 | playerFrame.health:SetMinMax(0, effMaxHealth) |
|
111 | Seerah-7 | playerFrame.health:SetValue(curHealth) |
|
112 | Seerah-7 | local curMagicka, maxMagicka, effMaxMagicka = GetUnitPower("player", POWERTYPE_MAGICKA) |
|
113 | Seerah-7 | playerFrame.magicka:SetMinMax(0, effMaxMagicka) |
|
114 | Seerah-7 | playerFrame.magicka:SetValue(curMagicka) |
|
115 | Seerah-7 | local curStamina, maxStamina, effMaxStamina = GetUnitPower("player", POWERTYPE_STAMINA) |
|
116 | Seerah-7 | playerFrame.stamina:SetMinMax(0, effMaxStamina) |
|
117 | Seerah-7 | playerFrame.stamina:SetValue(curStamina) |
|
118 | Seerah-7 | end |
|
119 | Seerah-7 | ||
120 | Seerah-7 | local function UnregisterAttributeBars() |
|
121 | Seerah-7 | ZO_PlayerAttributeMagicka:UnregisterForEvent(EVENT_POWER_UPDATE) |
|
122 | Seerah-7 | ZO_PlayerAttributeMagicka:UnregisterForEvent(EVENT_INTERFACE_SETTING_CHANGED) |
|
123 | Seerah-7 | ZO_PlayerAttributeMagicka:UnregisterForEvent(EVENT_PLAYER_ACTIVATED) |
|
124 | Seerah-7 | EVENT_MANAGER:UnregisterForUpdate("ZO_PlayerAttributeMagickaFadeUpdate") |
|
125 | Seerah-7 | ZO_PlayerAttributeMagicka:SetHidden(true) |
|
126 | Seerah-7 | ||
127 | Seerah-7 | ZO_PlayerAttributeStamina:UnregisterForEvent(EVENT_POWER_UPDATE) |
|
128 | Seerah-7 | ZO_PlayerAttributeStamina:UnregisterForEvent(EVENT_INTERFACE_SETTING_CHANGED) |
|
129 | Seerah-7 | ZO_PlayerAttributeStamina:UnregisterForEvent(EVENT_PLAYER_ACTIVATED) |
|
130 | Seerah-7 | EVENT_MANAGER:UnregisterForUpdate("ZO_PlayerAttributeStaminaFadeUpdate") |
|
131 | Seerah-7 | ZO_PlayerAttributeStamina:SetHidden(true) |
|
132 | Seerah-7 | ||
133 | Seerah-7 | ZO_PlayerAttributeHealth:UnregisterForEvent(EVENT_POWER_UPDATE) |
|
134 | Seerah-7 | ZO_PlayerAttributeHealth:UnregisterForEvent(EVENT_INTERFACE_SETTING_CHANGED) |
|
135 | Seerah-7 | ZO_PlayerAttributeHealth:UnregisterForEvent(EVENT_PLAYER_ACTIVATED) |
|
136 | Seerah-7 | EVENT_MANAGER:UnregisterForUpdate("ZO_PlayerAttributeHealthFadeUpdate") |
|
137 | Seerah-7 | ZO_PlayerAttributeHealth:SetHidden(true) |
|
138 | Seerah-7 | ||
139 | Seerah-7 | end |
|
140 | Seerah-7 | ||
141 | Seerah-7 | local function SetUpDB() |
|
142 | Seerah-7 | ZAM_UnitFramesDB = ZAM_UnitFramesDB or {} |
|
143 | Seerah-7 | for k,v in pairs(defaults) do |
|
144 | Seerah-7 | if type(ZAM_UnitFramesDB[k]) == "nil" then |
|
145 | Seerah-7 | ZAM_UnitFramesDB[k] = v |
|
146 | Seerah-7 | end |
|
147 | Seerah-7 | end |
|
148 | Seerah-7 | db = ZAM_UnitFramesDB |
|
149 | Seerah-7 | end |
|
150 | Seerah-7 | ||
151 | Seerah-7 | local function CreateOptions() |
|
152 | Seerah-7 | local LAM = LibStub("LibAddonMenu-1.0") |
|
153 | Seerah-7 | local zamPanel = LAM:CreateControlPanel("ZAM_ADDON_OPTIONS", "ZAM Addons") |
|
154 | Seerah-7 | LAM:AddHeader(zamPanel, "ZAM_UnitFrames_Options_Header", "ZAM UnitFrames") |
|
155 | Seerah-7 | LAM:AddCheckbox(zamPanel, "ZAM_UnitFrames_Options_Locked", "Lock Frames", "Lock the unit frames in place.", |
|
156 | Seerah-7 | function() return db.locked end, |
|
157 | Seerah-7 | function() db.locked = not db.locked playerFrame:SetMovable(not db.locked) end) |
|
158 | Seerah-7 | LAM:AddCheckbox(zamPanel, "ZAM_UnitFrames_Options_Flat", "Flat Bar Texture", "Remove the gloss from the bar textures.", |
|
159 | Seerah-7 | function() return db.flatBars end, |
|
160 | Seerah-7 | function() |
|
161 | Seerah-7 | db.flatBars = not db.flatBars |
|
162 | Seerah-7 | playerFrame.health.gloss:SetHidden(db.flatBars) |
|
163 | Seerah-7 | playerFrame.magicka.gloss:SetHidden(db.flatBars) |
|
164 | Seerah-7 | playerFrame.stamina.gloss:SetHidden(db.flatBars) |
|
165 | Seerah-7 | end) |
|
166 | Seerah-7 | end |
|
167 | Seerah-7 | ||
168 | Seerah-7 | playerFrame:RegisterForEvent(EVENT_ADD_ON_LOADED, function(event, addon) |
|
169 | Seerah-7 | if addon == "ZAM_UnitFrames" then |
|
170 | Seerah-7 | SetUpDB() |
|
171 | Seerah-7 | CreatePlayerFrame() |
|
172 | Seerah-7 | InitializeBars() |
|
173 | Seerah-7 | UnregisterAttributeBars() |
|
174 | Seerah-7 | CreateOptions() |
|
175 | Seerah-7 | ||
176 | Seerah-7 | playerFrame:UnregisterForEvent(EVENT_ADD_ON_LOADED) |
|
177 | Seerah-7 | end |
|
178 | Seerah-7 | end) |
|
179 | Seerah-7 | ||
180 | Seerah-7 | playerFrame:RegisterForEvent(EVENT_POWER_UPDATE, function(self, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax) |
|
181 | Seerah-7 | if unitTag == "player" then |
|
182 | Seerah-7 | if powerType == POWERTYPE_MAGICKA then |
|
183 | Seerah-7 | ZO_StatusBar_SmoothTransition(playerFrame.magicka, powerValue, powerEffectiveMax) |
|
184 | Seerah-7 | playerFrame.magicka.text:SetText(strformat("%d%%", powerValue/powerEffectiveMax*100)) |
|
185 | Seerah-7 | elseif powerType == POWERTYPE_STAMINA then |
|
186 | Seerah-7 | --playerFrame.stamina:SetValue(powerValue) |
|
187 | Seerah-7 | ZO_StatusBar_SmoothTransition(playerFrame.stamina, powerValue, powerEffectiveMax) |
|
188 | Seerah-7 | playerFrame.stamina.text:SetText(strformat("%d%%", powerValue/powerEffectiveMax*100)) |
|
189 | Seerah-7 | elseif powerType == POWERTYPE_HEALTH then |
|
190 | Seerah-7 | --playerFrame.health:SetValue(powerValue) |
|
191 | Seerah-7 | ZO_StatusBar_SmoothTransition(playerFrame.health, powerValue, powerEffectiveMax) |
|
192 | Seerah-7 | playerFrame.health.text:SetText(strformat("%d%%", powerValue/powerEffectiveMax*100)) |
|
193 | Seerah-7 | end |
|
194 | Seerah-7 | end |
|
195 | Seerah-7 | end) |
|
196 | Seerah-7 | ||
197 | Seerah-7 |