vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Constants
2 TITAN_CLOCK_ID = "Clock";
3 TITAN_CLOCK_FORMAT_12H = "12H";
4 TITAN_CLOCK_FORMAT_24H = "24H";
5 TITAN_CLOCK_FREQUENCY = 0.5;
6 TITAN_CLOCK_FRAME_SHOW_TIME = 0.5;
7  
8 function TitanPanelClockButton_OnLoad()
9 this.registry = {
10 id = TITAN_CLOCK_ID,
11 builtIn = 1,
12 version = TITAN_VERSION,
13 menuText = TITAN_CLOCK_MENU_TEXT,
14 buttonTextFunction = "TitanPanelClockButton_GetButtonText",
15 tooltipTitle = TITAN_CLOCK_TOOLTIP,
16 tooltipTextFunction = "TitanPanelClockButton_GetTooltipText",
17 frequency = TITAN_CLOCK_FREQUENCY,
18 updateType = TITAN_PANEL_UPDATE_BUTTON,
19 savedVariables = {
20 OffsetHour = 0,
21 Format = TITAN_CLOCK_FORMAT_12H,
22 DisplayOnRightSide = 1,
23 }
24 };
25 end
26  
27 function TitanPanelClockButton_GetButtonText()
28 -- Calculate the hour/minutes considering the offset
29 local hour, minute = GetGameTime();
30 local twentyfour = "";
31 local offsettime = string.format("%s", TitanGetVar(TITAN_CLOCK_ID, "OffsetHour"));
32 local offsethour = 0;
33 local offsetmin = 0;
34 local s, e, id = string.find(offsettime, '%.5');
35  
36 if s ~= nil then
37 offsethour = string.sub(offsettime, 1, s);
38 offsetmin = string.sub(offsettime, s+1);
39 if offsetmin == "" or offsetmin == nil then offsetmin = "0"; end
40 if offsethour == "" or offsethour == nil then offsethour = "0"; end
41  
42 offsethour = tonumber(offsethour);
43  
44 if tonumber(offsettime) < 0 then offsetmin = tonumber("-" .. offsetmin); end
45  
46 minute = minute + (offsetmin*6);
47  
48 if( minute > 59 ) then
49 minute = minute - 30;
50 offsethour = offsethour + 1;
51 elseif( minute < 0 ) then
52 minute = 60 + minute;
53 offsethour = offsethour - 1;
54 end
55 else
56 offsethour = TitanGetVar(TITAN_CLOCK_ID, "OffsetHour");
57 end
58 hour = hour + offsethour;
59  
60 if( hour > 23 ) then
61 hour = hour - 24;
62 elseif( hour < 0 ) then
63 hour = 24 + hour;
64 end
65  
66 -- Calculate the display text based on format 12H/24H
67 if (TitanGetVar(TITAN_CLOCK_ID, "Format") == TITAN_CLOCK_FORMAT_12H) then
68 local isAM;
69 if (hour >= 12) then
70 isAM = false;
71 hour = hour - 12;
72 else
73 isAM = true;
74 end
75 if (hour == 0) then
76 hour = 12;
77 end
78 if (isAM) then
79 return nil, format(TEXT(TIME_TWELVEHOURAM), hour, minute);
80 else
81 return nil, format(TEXT(TIME_TWELVEHOURPM), hour, minute);
82 end
83 else
84 twentyfour = format(TEXT(TIME_TWENTYFOURHOURS), hour, minute);
85 if hour < 10 then
86 twentyfour = "0" .. twentyfour
87 end
88  
89 return nil, twentyfour;
90 end
91  
92 end
93  
94 function TitanPanelClockButton_GetTooltipText()
95 local clockText = TitanPanelClock_GetOffsetText(TitanGetVar(TITAN_CLOCK_ID, "OffsetHour"));
96 return ""..
97 TITAN_CLOCK_TOOLTIP_VALUE.."\t"..TitanUtils_GetHighlightText(clockText).."\n"..
98 TitanUtils_GetGreenText(TITAN_CLOCK_TOOLTIP_HINT1).."\n"..
99 TitanUtils_GetGreenText(TITAN_CLOCK_TOOLTIP_HINT2);
100 end
101  
102 function TitanPanelClockControlSlider_OnEnter()
103 this.tooltipText = TitanOptionSlider_TooltipText(TITAN_CLOCK_CONTROL_TOOLTIP, TitanPanelClock_GetOffsetText(TitanGetVar(TITAN_CLOCK_ID, "OffsetHour")));
104 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMLEFT");
105 GameTooltip:SetText(this.tooltipText, nil, nil, nil, nil, 1);
106 TitanUtils_StopFrameCounting(this:GetParent());
107 end
108  
109 function TitanPanelClockControlSlider_OnLeave()
110 this.tooltipText = nil;
111 GameTooltip:Hide();
112 TitanUtils_StartFrameCounting(this:GetParent(), TITAN_CLOCK_FRAME_SHOW_TIME);
113 end
114  
115 function TitanPanelClockControlSlider_OnShow()
116 getglobal(this:GetName().."Text"):SetText(TitanPanelClock_GetOffsetText(TitanGetVar(TITAN_CLOCK_ID, "OffsetHour")));
117 getglobal(this:GetName().."High"):SetText(TITAN_CLOCK_CONTROL_LOW);
118 getglobal(this:GetName().."Low"):SetText(TITAN_CLOCK_CONTROL_HIGH);
119 this:SetMinMaxValues(-12, 12);
120 this:SetValueStep(0.5);
121 this:SetValue(0 - TitanGetVar(TITAN_CLOCK_ID, "OffsetHour"));
122  
123 position = TitanUtils_GetRealPosition(TITAN_CLOCK_ID);
124  
125 TitanPanelClockControlFrame:SetPoint("BOTTOMRIGHT", "TitanPanel" .. TitanUtils_GetWhichBar(TITAN_CLOCK_ID) .."Button", "TOPRIGHT", 0, 0);
126 if (position == TITAN_PANEL_PLACE_TOP) then
127 TitanPanelClockControlFrame:ClearAllPoints();
128 TitanPanelClockControlFrame:SetPoint("TOPLEFT", "TitanPanel" .. TitanUtils_GetWhichBar(TITAN_CLOCK_ID) .."Button", "BOTTOMLEFT", UIParent:GetRight() - TitanPanelClockControlFrame:GetWidth(), -4);
129 else
130 TitanPanelClockControlFrame:ClearAllPoints();
131 TitanPanelClockControlFrame:SetPoint("BOTTOMLEFT", "TitanPanel" .. TitanUtils_GetWhichBar(TITAN_CLOCK_ID) .."Button", "TOPLEFT", UIParent:GetRight() - TitanPanelClockControlFrame:GetWidth(), 0);
132 end
133  
134 end
135  
136 function TitanPanelClockControlSlider_OnValueChanged()
137 getglobal(this:GetName().."Text"):SetText(TitanPanelClock_GetOffsetText(0 - this:GetValue()));
138 TitanSetVar(TITAN_CLOCK_ID, "OffsetHour", 0 - this:GetValue())
139 TitanPanelButton_UpdateButton(TITAN_CLOCK_ID);
140  
141 -- Update GameTooltip
142 if (this.tooltipText) then
143 this.tooltipText = TitanOptionSlider_TooltipText(TITAN_CLOCK_CONTROL_TOOLTIP, TitanPanelClock_GetOffsetText(TitanGetVar(TITAN_CLOCK_ID, "OffsetHour")));
144 GameTooltip:SetText(this.tooltipText, nil, nil, nil, nil, 1);
145 end
146 end
147  
148 function TitanPanelClockControlCheckButton_OnShow()
149 TitanPanelClockControlCheckButtonText:SetText(TITAN_CLOCK_CHECKBUTTON);
150  
151 if (TitanGetVar(TITAN_CLOCK_ID, "Format") == TITAN_CLOCK_FORMAT_24H) then
152 this:SetChecked(1);
153 else
154 this:SetChecked(0);
155 end
156 end
157  
158 function TitanPanelClockControlCheckButton_OnClick()
159 if (this:GetChecked()) then
160 TitanSetVar(TITAN_CLOCK_ID, "Format", TITAN_CLOCK_FORMAT_24H);
161 else
162 TitanSetVar(TITAN_CLOCK_ID, "Format", TITAN_CLOCK_FORMAT_12H);
163 end
164 TitanPanelButton_UpdateButton(TITAN_CLOCK_ID);
165 end
166  
167 function TitanPanelClockControlCheckButton_OnEnter()
168 this.tooltipText = TITAN_CLOCK_CHECKBUTTON_TOOLTIP;
169 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMLEFT");
170 GameTooltip:SetText(this.tooltipText, nil, nil, nil, nil, 1);
171 TitanUtils_StopFrameCounting(this:GetParent());
172 end
173  
174 function TitanPanelClockControlCheckButton_OnLeave()
175 this.tooltipText = nil;
176 GameTooltip:Hide();
177 TitanUtils_StartFrameCounting(this:GetParent(), TITAN_CLOCK_FRAME_SHOW_TIME);
178 end
179  
180 function TitanPanelClock_GetOffsetText(offset)
181 if (offset > 0) then
182 return "+" .. tostring(offset);
183 else
184 return tostring(offset);
185 end
186 end
187  
188 function TitanPanelClockControlFrame_OnLoad()
189 getglobal(this:GetName().."Title"):SetText(TITAN_CLOCK_CONTROL_TITLE);
190 this:SetBackdropBorderColor(1, 1, 1);
191 this:SetBackdropColor(0, 0, 0, 1);
192 end
193  
194 function TitanPanelClockControlFrame_OnUpdate(elapsed)
195 TitanUtils_CheckFrameCounting(this, elapsed);
196 end
197  
198 function TitanPanelRightClickMenu_PrepareClockMenu()
199 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_CLOCK_ID].menuText);
200  
201 info = {};
202 info.text = TITAN_CLOCK_MENU_DISPLAY_ON_RIGHT_SIDE;
203 info.func = TitanPanelClockButton_ToggleRightSideDisplay;
204 info.checked = TitanGetVar(TITAN_CLOCK_ID, "DisplayOnRightSide");
205 UIDropDownMenu_AddButton(info);
206  
207 TitanPanelRightClickMenu_AddSpacer();
208 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_CLOCK_ID, TITAN_PANEL_MENU_FUNC_HIDE);
209 end
210  
211 function TitanPanelClockButton_ToggleRightSideDisplay()
212 TitanToggleVar(TITAN_CLOCK_ID, "DisplayOnRightSide");
213 TITAN_PANEL_SELECTED = TitanUtils_GetWhichBar(TITAN_CLOCK_ID);
214 TitanPanel_RemoveButton(TITAN_CLOCK_ID);
215 TitanDebug(TITAN_PANEL_SELECTED);
216 TitanPanel_AddButton(TITAN_CLOCK_ID);
217 -- TitanPanelButton_UpdateButton(TITAN_BAG_ID);
218 end