Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 9 | Seerah-7 | -- ZAM_Stats © ZAM Network LLC |
2 | Seerah-7 | -- All Rights Reserved |
|
3 | Seerah-7 | ||
4 | 2 | Seerah-7 | -- API for Modules -- |
5 | Seerah-7 | --------------------- |
|
6 | Seerah-7 | ||
7 | Seerah-7 | -- Creating your module -- |
|
8 | Seerah-7 | -- Usage: control, label = ZAM_Stats:CreateModule(key) |
|
9 | Seerah-7 | -- key = string; a unique identifier/name of your module |
|
10 | Seerah-7 | -- control = reference to your module's frame |
|
11 | Seerah-7 | -- label = reference to your module's text |
|
12 | Seerah-7 | ||
13 | Seerah-7 | -- Knowing when your module is ready -- |
|
14 | Seerah-7 | -- Usage: CALLBACK_MANAGER:RegisterCallback(event, method) |
|
15 | Seerah-7 | -- event = string; the event fired by ZAM_Stats - it is called "ZAM_Stats_Modules_Ready" |
|
16 | Seerah-7 | -- method = function; the function to call when the event fires |
|
17 | Seerah-7 | ||
18 | Seerah-7 | -- Setting the text -- |
|
19 | Seerah-7 | -- Usage: ZAM_Stats:SetModuleText(label, prefix, suffix) |
|
20 | Seerah-7 | -- label = reference to the module's label |
|
21 | Seerah-7 | -- prefix = string; the value/data to display in the module |
|
22 | Seerah-7 | -- suffix = string; any descriptor text after the data (ex. "MB") |
|
23 | Seerah-7 | ||
24 | Seerah-7 | -- Letting the options panel force a refresh of the text -- |
|
25 | Seerah-7 | -- Usage: CALLBACK_MANAGER:RegisterCallback(event, method) |
|
26 | Seerah-7 | -- event = string; the event fired by ZAM_Stats - it is called "ZAM_Stats_Force_Refresh" |
|
27 | Seerah-7 | -- method = function; the function to call when the event fires (should be your ZAM_Stats:SetModuleText function call) |
|
28 | Seerah-7 | ||
29 | Seerah-7 | --------------------------------------------------------------------------- |
|
30 | Seerah-7 | ||
31 | Seerah-7 | ZAM_Stats = {} |
|
32 | Seerah-7 | ||
33 | Seerah-7 | -- UPVALUES -- |
|
34 | Seerah-7 | local ZAM_Stats = ZAM_Stats |
|
35 | 5 | Seerah-7 | local LMP = LibStub("LibMediaProvider-1.0") |
36 | 10 | Seerah-7 | local db |
37 | 2 | Seerah-7 | local wm = GetWindowManager() |
38 | 10 | Seerah-7 | ZAM_Stats.modules = {} |
39 | Seerah-7 | local modules = ZAM_Stats.modules |
|
40 | 2 | Seerah-7 | |
41 | Seerah-7 | ||
42 | 10 | Seerah-7 | function ZAM_Stats.ConfigModule(frame) |
43 | 2 | Seerah-7 | local name = frame:GetName() |
44 | Seerah-7 | frame:ClearAnchors() |
|
45 | Seerah-7 | if not db[name].point then |
|
46 | Seerah-7 | db[name].point = {["a"]=CENTER, ["b"]=CENTER, ["x"]=0, ["y"]=0} |
|
47 | Seerah-7 | end |
|
48 | Seerah-7 | local anchor = db[name].point |
|
49 | Seerah-7 | frame:SetAnchor(anchor.a, GuiRoot, anchor.b or anchor.a, anchor.x, anchor.y) |
|
50 | Seerah-7 | frame:SetMovable(not db.locked) |
|
51 | Seerah-7 | frame.bg:SetCenterColor(0,0,0, db.locked and 0 or .4) |
|
52 | 5 | Seerah-7 | frame.text:SetFont(("%s|%s|%s"):format(LMP:Fetch("font", db.font), db.fsize, db.fstyle)) |
53 | 2 | Seerah-7 | frame.text:SetHorizontalAlignment(_G["TEXT_ALIGN_"..db.align]) |
54 | Seerah-7 | end |
|
55 | Seerah-7 | ||
56 | Seerah-7 | function ZAM_Stats:CreateModule(module) |
|
57 | Seerah-7 | local f = wm:CreateTopLevelWindow("ZAM_Stats_"..module) |
|
58 | Seerah-7 | f:SetDimensions(100, 30) |
|
59 | Seerah-7 | f:SetMouseEnabled(true) |
|
60 | Seerah-7 | f:SetHandler("OnReceiveDrag", function(self) |
|
61 | Seerah-7 | if not db.locked then |
|
62 | Seerah-7 | self:StartMoving() |
|
63 | Seerah-7 | end |
|
64 | Seerah-7 | end) |
|
65 | Seerah-7 | f:SetHandler("OnMouseUp", function(self) |
|
66 | Seerah-7 | self:StopMovingOrResizing() |
|
67 | Seerah-7 | local _,a,_,b,x,y = self:GetAnchor() |
|
68 | Seerah-7 | db[self:GetName()].point = {["a"]=a, ["b"]=b, ["x"]=x, ["y"]=y} |
|
69 | Seerah-7 | end) |
|
70 | Seerah-7 | f:SetClampedToScreen(true) |
|
71 | 5 | Seerah-7 | f:SetDrawLayer(DL_BACKGROUND) |
72 | 2 | Seerah-7 | f.bg = wm:CreateControlFromVirtual("ZAM_Stats_"..module.."BG", f, "ZAM_StatsBGTemplate") |
73 | Seerah-7 | local fbg = f.bg |
|
74 | Seerah-7 | fbg:SetCenterColor(0, 0, 0, .4) |
|
75 | Seerah-7 | fbg:SetEdgeColor(0, 0, 0, 0) |
|
76 | Seerah-7 | fbg:SetDimensions(100, 30) |
|
77 | Seerah-7 | fbg:SetAnchorFill(f) |
|
78 | Seerah-7 | f.text = wm:CreateControlFromVirtual("ZAM_Stats_"..module.."Text", f, "ZAM_StatsTextTemplate") |
|
79 | Seerah-7 | local ftext = f.text |
|
80 | Seerah-7 | ftext:SetDimensions(100, 30) |
|
81 | Seerah-7 | ftext:SetAnchorFill(f) |
|
82 | Seerah-7 | ftext:SetVerticalAlignment(TEXT_ALIGN_CENTER) |
|
83 | Seerah-7 | ftext:SetText("test") |
|
84 | Seerah-7 | ||
85 | Seerah-7 | table.insert(modules, f) |
|
86 | Seerah-7 | ||
87 | Seerah-7 | --maybe change later to only return module (module.bg and module.text are there now anyway) |
|
88 | Seerah-7 | return f, ftext |
|
89 | Seerah-7 | end |
|
90 | Seerah-7 | ||
91 | 10 | Seerah-7 | function ZAM_Stats.RGBPercToHex(r,g,b) |
92 | 2 | Seerah-7 | r = r <= 1 and r >= 0 and r or 0 |
93 | Seerah-7 | g = g <= 1 and g >= 0 and g or 0 |
|
94 | Seerah-7 | b = b <= 1 and b >= 0 and b or 0 |
|
95 | Seerah-7 | return string.format("%02x%02x%02x", r*255, g*255, b*255) |
|
96 | Seerah-7 | end |
|
97 | Seerah-7 | ||
98 | Seerah-7 | --maybe change this later so you just need to pass in the module, not its text object |
|
99 | Seerah-7 | function ZAM_Stats:SetModuleText(ftext, value, suffix) |
|
100 | 10 | Seerah-7 | ftext:SetText("|c"..ZAM_Stats.preHex..value.."|c"..ZAM_Stats.sufHex..suffix) |
101 | 2 | Seerah-7 | end |
102 | Seerah-7 | ||
103 | Seerah-7 | local function AddonLoaded() |
|
104 | 10 | Seerah-7 | db = ZAM_Stats.SetUpSavedVars() |
105 | Seerah-7 | ||
106 | Seerah-7 | ZAM_Stats.preHex = ZAM_Stats.RGBPercToHex(db.preColor.r,db.preColor.g,db.preColor.b) |
|
107 | Seerah-7 | ZAM_Stats.sufHex = ZAM_Stats.RGBPercToHex(db.sufColor.r,db.sufColor.g,db.sufColor.b) |
|
108 | 2 | Seerah-7 | |
109 | Seerah-7 | --setup each module |
|
110 | Seerah-7 | for k,v in pairs(modules) do |
|
111 | 10 | Seerah-7 | ZAM_Stats.ConfigModule(v) |
112 | 2 | Seerah-7 | end |
113 | Seerah-7 | --send a callback to each module |
|
114 | 10 | Seerah-7 | CALLBACK_MANAGER:FireCallbacks("ZAM_Stats_Modules_Ready") --maybe switch to a per-module callback? |
115 | 2 | Seerah-7 | end |
116 | Seerah-7 | ||
117 | Seerah-7 | ||
118 | Seerah-7 | EVENT_MANAGER:RegisterForEvent("ZAM_Stats", EVENT_ADD_ON_LOADED, function(event, addon) |
|
119 | Seerah-7 | --EVENT_MANAGER:RegisterForEvent("ZAM_Stats", EVENT_PLAYER_ACTIVATED, function(event, addon) |
|
120 | Seerah-7 | if addon == "ZAM_Stats" then |
|
121 | Seerah-7 | AddonLoaded() |
|
122 | 10 | Seerah-7 | ZAM_Stats.RegisterOptions() |
123 | 2 | Seerah-7 | end |
124 | Seerah-7 | end) |