Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TurnInUI.lua 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. local TI_OptionsPriorityFramePool = {};
  2. local TI_OptionsPriorityFramePoolMax = 0;
  3. local function TI_GetOptionsPriorityFrame(idx)
  4. if idx > TI_OptionsPriorityFramePoolMax then
  5. for i=TI_OptionsPriorityFramePoolMax+1, idx, 1 do
  6. local frame = CreateFrame("Button", "TI_OptionsPriority"..i,
  7. getglobal("TI_OptionsPriority"), "TI_PriorityList", i);
  8. if i == 1 then
  9. frame:SetPoint("TOPLEFT", 0, 0);
  10. else
  11. frame:SetPoint("TOPLEFT", "TI_OptionsPriority"..i-1, "BOTTOMLEFT", 0, 0);
  12. end
  13. frame:Hide();
  14. table.insert(TI_OptionsPriorityFramePool, i, frame);
  15. TI_OptionsPriorityFramePoolMax = TI_OptionsPriorityFramePoolMax + 1;
  16. end
  17. end
  18. return TI_OptionsPriorityFramePool[idx];
  19. end
  20. local function TI_HideUnusedOptionFrames(last)
  21. for i=last, TI_OptionsPriorityFramePoolMax, 1 do
  22. TI_OptionsPriorityFramePool[i]:Hide();
  23. end
  24. end
  25. function TI_PopulateOptions(arg)
  26. TI_debug(arg);
  27. local CurrOpts;
  28. local last=1;
  29. if(TI_status and TI_status.options) then
  30. if(TI_LoadedNPCIndex > 0) then
  31. CurrOpts = TI_NPCDB[TI_NPCIndex[TI_LoadedNPCIndex]];
  32. else
  33. CurrOpts = TI_status.options;
  34. end
  35. for i,v in ipairs(CurrOpts) do
  36. local entrybutton = TI_GetOptionsPriorityFrame(i);
  37. local icon, entrytext = entrybutton:GetRegions();
  38. local checkbox = entrybutton:GetChildren();
  39. local iconpath;
  40. if(v.name == nil) then TI_debug("oh noes") end;
  41. entrytext:SetText(v.name);
  42. if(v.type == "activequest") then
  43. if(v.icon) then
  44. iconpath = v.icon;
  45. else
  46. iconpath = "Interface/GossipFrame/ActiveQuestIcon";
  47. end
  48. elseif(v.type == "availquest") then
  49. if(v.icon) then
  50. iconpath = v.icon;
  51. else
  52. iconpath = "Interface/GossipFrame/AvailableQuestIcon";
  53. end
  54. else
  55. if(v.icon) then
  56. iconpath = v.icon;
  57. else
  58. iconpath = "Interface/GossipFrame/" .. v.type .. "GossipIcon";
  59. end
  60. end
  61. icon:SetTexture(iconpath);
  62. checkbox:SetChecked(v.state);
  63. entrytext:SetWidth(156); --make sure to change this if you change the anchors in the XML
  64. entrybutton:SetHeight( entrytext:GetHeight() + 6);
  65. entrybutton:Show();
  66. last = last+1;
  67. end
  68. TI_HideUnusedOptionFrames(last);
  69. TI_OptionsPriorityScrollFrame:SetVerticalScroll(0);
  70. TI_OptionsPriorityScrollFrame:UpdateScrollChildRect();
  71. TI_StatusIndicatorUpdate();
  72. end
  73. TI_NPCListScrollBarUpdate();
  74. TI_SettingCheckboxUpdate();
  75. end
  76. function TI_NPCListScrollBarUpdate()
  77. if(TI_NPCIndex) then
  78. FauxScrollFrame_Update(TI_NPCListScrollFrame,table.getn(TI_NPCIndex),8,20);
  79. -- arg2 is max entries, arg3 is number of lines, arg4 is pixel height of each line
  80. local line; -- 1 through 8 of our window to scroll
  81. local lineplusoffset; -- an index into our data calculated from the scroll offset
  82. local offset = FauxScrollFrame_GetOffset(TI_NPCListScrollFrame);
  83. local i=1;
  84. local j=1;
  85. for line=1,8 do
  86. lineplusoffset = line + FauxScrollFrame_GetOffset(TI_NPCListScrollFrame);
  87. if(lineplusoffset <= table.getn(TI_NPCIndex)) then
  88. getglobal("TI_OptionsNPCContainer"..line):SetID(lineplusoffset);
  89. getglobal("TI_OptionsNPCContainer"..line.."_Text"):SetText(TI_NPCIndex[lineplusoffset]);
  90. getglobal("TI_OptionsNPCContainer"..line.."_Check"):SetChecked(TI_NPCDB[TI_NPCIndex[lineplusoffset]].state);
  91. if(lineplusoffset == TI_LoadedNPCIndex) then
  92. getglobal("TI_OptionsNPCContainer"..line):LockHighlight();
  93. else
  94. getglobal("TI_OptionsNPCContainer"..line):UnlockHighlight();
  95. end
  96. getglobal("TI_OptionsNPCContainer"..line):Show();
  97. else
  98. getglobal("TI_OptionsNPCContainer"..line):Hide();
  99. end
  100. end
  101. end
  102. end
  103. function TI_SelectNPCIndex(self)
  104. local index = self:GetID();
  105. if(TI_LoadedNPCIndex == index) then
  106. TI_LoadedNPCIndex = 0;
  107. else
  108. TI_LoadedNPCIndex = index;
  109. end
  110. TI_PopulateOptions("select npc");
  111. end
  112. function TI_DeleteNPCIndex(self)
  113. local index = self:GetParent():GetID();
  114. TI_DeleteNPC(index);
  115. if(TI_LoadedNPCIndex == index) then
  116. TI_LoadedNPCIndex = 0;
  117. end
  118. TI_PopulateOptions("npclist update");
  119. end
  120. function TI_NPCToggle(self)
  121. local index = self:GetParent():GetID();
  122. TI_NPCDB[TI_NPCIndex[index]].state = self:GetChecked();
  123. if(TI_NPCDB[TI_NPCIndex[index]].state) then
  124. TI_LoadedNPCIndex = index;
  125. else
  126. if(TI_LoadedNPCIndex == index) then
  127. TI_LoadedNPCIndex = 0;
  128. end
  129. end
  130. TI_PopulateOptions("select npc");
  131. end
  132. function TI_OptionMove(self, offset)
  133. local CurrOpts;
  134. if(TI_LoadedNPCIndex > 0) then
  135. CurrOpts = TI_NPCDB[TI_NPCIndex[TI_LoadedNPCIndex]];
  136. else
  137. CurrOpts = TI_status.options;
  138. end
  139. local id = self:GetParent():GetID();
  140. local newid = id + offset;
  141. if(newid < 1 or newid > table.getn(CurrOpts)) then
  142. return;
  143. end
  144. local temp = CurrOpts[newid];
  145. CurrOpts[newid] = CurrOpts[id];
  146. CurrOpts[id] = temp;
  147. TI_PopulateOptions("move");
  148. end
  149. function TI_OptionToggle(self)
  150. local CurrOpts;
  151. if(TI_LoadedNPCIndex > 0) then
  152. CurrOpts = TI_NPCDB[TI_NPCIndex[TI_LoadedNPCIndex]];
  153. else
  154. CurrOpts = TI_status.options;
  155. end
  156. local id = self:GetParent():GetID();
  157. if(self:GetChecked()) then
  158. CurrOpts[id].state=true;
  159. else
  160. CurrOpts[id].state=false;
  161. end
  162. end
  163. function TI_StatusIndicatorUpdate()
  164. if(TI_status) then
  165. if(TI_status.state) then
  166. TI_StatusIndicator_Status:SetText("On");
  167. TI_StatusIndicator_Status:SetTextColor(0,1,0);
  168. else
  169. TI_StatusIndicator_Status:SetText("Off");
  170. TI_StatusIndicator_Status:SetTextColor(1,0,0);
  171. end
  172. TI_StatusIndicator_Checkbox:SetChecked(TI_status.state);
  173. end
  174. end
  175. function TI_StatusIndicator_CheckFn(self)
  176. if(self:GetChecked()) then
  177. TI_Switch("on");
  178. else
  179. TI_Switch("off");
  180. end
  181. end
  182. function TI_TempNPCListTooltipShow(self)
  183. TI_Tooltip:SetOwner(self, ANCHOR_PRESERVE);
  184. TI_Tooltip:ClearLines();
  185. local id = self:GetID();
  186. TI_Tooltip:AddLine(TI_TempNPCList[id].location);
  187. for i,v in ipairs(TI_TempNPCList[id].list) do
  188. TI_Tooltip:AddLine("- " .. v.name);
  189. end
  190. --TI_Tooltip:SetText(text);
  191. TI_Tooltip:Show();
  192. end
  193. function TI_TooltipHide()
  194. TI_Tooltip:Hide();
  195. end
  196. function TI_TooltipMessage(self, msg)
  197. TI_Tooltip:SetOwner(self, ANCHOR_PRESERVE);
  198. TI_Tooltip:ClearLines();
  199. TI_Tooltip:SetText(msg);
  200. TI_Tooltip:Show();
  201. end
  202. function TI_TempNPCListUpdate()
  203. local last = 1;
  204. for i,v in ipairs(TI_TempNPCList) do
  205. local tempbuttontext = _G["TI_TempNPCListWindow"..i.."_Text"];
  206. tempbuttontext:SetText(v.name);
  207. tempbuttontext:GetParent():Show();
  208. last = last+1;
  209. end
  210. for j=last, TI_TempNPCListMaxSize, 1 do
  211. _G["TI_TempNPCListWindow" .. j]:Hide();
  212. end
  213. end
  214. function TI_NPCListCheckboxTooltip(self)
  215. if(self:GetChecked()) then
  216. TI_TooltipMessage(self, "NPC is using specific settings.");
  217. else
  218. TI_TooltipMessage(self, "NPC is using default settings.");
  219. end
  220. end
  221. function TI_OptionListCheckboxTooltip(self)
  222. if(self:GetChecked()) then
  223. TI_TooltipMessage(self, "This option is enabled.");
  224. else
  225. TI_TooltipMessage(self, "This option is disabled.");
  226. end
  227. end
  228. function TI_SettingCheckboxFn(self, var)
  229. if(self:GetChecked()) then
  230. TI_status[var] = true;
  231. else
  232. TI_status[var] = false;
  233. end
  234. end
  235. function TI_SettingCheckboxUpdate()
  236. if(TI_status) then
  237. TI_SettingCheckboxes_UseDefault:SetChecked(TI_status.usedefault);
  238. TI_SettingCheckboxes_AddAutomatically:SetChecked(TI_status.autoadd);
  239. end
  240. end