public
Description: WoW Addon - Crowd control assistance
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/controlfreak.git
Click here to lend your support to: controlfreak and make a donation at www.pledgie.com !
controlfreak / ConfigDB.lua
100644 156 lines (129 sloc) 5.311 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

 
if not ControlFreak then return end
 
 
----------------------
-- Locals --
----------------------
 
local ww = LibStub("WidgetWarlock-Alpha1")
local GAP, EDGEGAP, DROPDOWNOFFSET, NUMROWS, ROWHEIGHT = 8, 16, 16, 13, 18
 
 
---------------------
-- Panel --
---------------------
 
local frame = CreateFrame("Frame", nil, UIParent)
frame.name = "Macro Profile"
frame.parent = "Control Freak"
frame:Hide()
frame:SetScript("OnShow", function(frame)
  local ControlFreak = ControlFreak
  local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Control Freak - Macro Profile", "These controls let you select a different macro, or create your own. To reset a default profile you've changed, just delete it!")
 
 
  local currentlabel = ww:SummonFontString(frame, "OVERLAY", "GameFontNormal", "Current profile:", "TOPLEFT", subtitle, "BOTTOMLEFT", -2, -GAP)
  local current = ww:SummonFontString(frame, "OVERLAY", "GameFontHighlight", ControlFreak.db:GetCurrentProfile(), "LEFT", currentlabel, "RIGHT", 10, 0)
 
 
  local createname = ww:SummonEditBox(frame, 255, "TOPLEFT", currentlabel, "BOTTOMLEFT", GAP - 2, -1)
  local createbutton = ww:SummonButton(frame, "Create", nil, nil, "LEFT", createname, "RIGHT", 5, 0)
  createbutton:Disable()
  createname:SetScript("OnTextChanged", function(frame) if frame:GetText() ~= "" then createbutton:Enable() else createbutton:Disable() end end)
 
 
  local deletebutton = ww:SummonButton(frame, "Delete", nil, nil, "BOTTOMRIGHT", -EDGEGAP, EDGEGAP)
  local copybutton = ww:SummonButton(frame, "Copy", nil, nil, "RIGHT", deletebutton, "LEFT", -GAP, 0)
  local loadbutton = ww:SummonButton(frame, "Load", nil, nil, "RIGHT", copybutton, "LEFT", -GAP, 0)
  local function ToggleButtons(value)
    if not value or value == ControlFreak.db:GetCurrentProfile() then
      loadbutton:Disable()
      copybutton:Disable()
      deletebutton:Disable()
    else
      loadbutton:Enable()
      copybutton:Enable()
      deletebutton:Enable()
    end
  end
 
 
  local rows = {}
  local offset, selectedprofile, proflies = 0
  local function sort(a,b) return string.lower(a) < string.lower(b) end
  local function UpdateRows()
    table.sort(profiles, sort)
    for i,row in ipairs(rows) do
      local profile = profiles[i + offset]
      if profile then
        row.text:SetText((profile == ControlFreak.db:GetCurrentProfile() and "|cff999999" or "")..profile)
        if profile == ControlFreak.db:GetCurrentProfile() then row:Disable() else row:Enable() end
        row.value = profile
        row:SetChecked(selectedprofile == profile)
      else
        row.text:SetText()
        row:Disable()
        row:SetChecked(false)
      end
    end
  end
 
  local function rowOnClick(self)
    selectedprofile = selectedprofile ~= self.value and self.value or nil
    ToggleButtons(selectedprofile)
    UpdateRows()
  end
 
  local function OnMouseWheel(f, val)
    offset = offset - val
    if (offset + NUMROWS) > #profiles then offset = #profiles - NUMROWS end
    if offset < 0 then offset = 0 end
    UpdateRows()
  end
 
  for i=1,NUMROWS do
    local row = CreateFrame("CheckButton", nil, frame)
    row:SetHeight(ROWHEIGHT)
    if i == 1 then row:SetPoint("TOP", createname, "BOTTOM", 0, -2) else row:SetPoint("TOP", rows[i-1], "BOTTOM", 0, 0) end
    row:SetPoint("LEFT", EDGEGAP, 0)
    row:SetPoint("RIGHT", -EDGEGAP, 0)
 
    row.text = ww:SummonFontString(row, "OVERLAY", "GameFontWhite", "SAMPLE PROFILE "..i, "LEFT", row, 10, 0)
    row.text:SetPoint("RIGHT", row, -10, 0)
    row.text:SetJustifyH("LEFT")
 
    local highlight = ww:SummonTextureWithCoords(row, nil, nil, nil, "Interface\\HelpFrame\\HelpFrameButton-Highlight", 0, 1, 0, 0.578125)
    highlight:SetAllPoints()
    row:SetHighlightTexture(highlight)
    row:SetCheckedTexture(highlight)
 
    row:EnableMouseWheel()
    row:SetScript("OnMouseWheel", OnMouseWheel)
    row:SetScript("OnClick", rowOnClick)
    rows[i] = row
  end
 
 
  loadbutton:SetScript("OnClick", function()
    local profile = selectedprofile
    ControlFreak.db:SetProfile(profile)
    current:SetText(profile)
    selectedprofile = nil
    ToggleButtons()
    UpdateRows()
  end)
  copybutton:SetScript("OnClick", function()
    ControlFreak.db:ResetProfile()
    ControlFreak.db:CopyProfile(selectedprofile)
    profiles = ControlFreak.db:GetProfiles()
  end)
  deletebutton:SetScript("OnClick", function()
    ControlFreak.db:DeleteProfile(selectedprofile)
    profiles, selectedprofile = ControlFreak.db:GetProfiles(), nil
    ToggleButtons()
    UpdateRows()
  end)
  createbutton:SetScript("OnClick", function()
    local profile = createname:GetText()
    if profile ~= "" then
      local oldprofile = ControlFreak.db:GetCurrentProfile()
      ControlFreak.db:SetProfile(profile)
      ControlFreak.db:CopyProfile(oldprofile)
      current:SetText(profile)
      profiles = ControlFreak.db:GetProfiles()
      createname:SetText("")
      createname:ClearFocus()
      createbutton:Disable()
      UpdateRows()
    end
  end)
 
  ww:EnslaveTooltip(copybutton, "Copy the selected profile into your current profile.")
  ww:EnslaveTooltip(deletebutton, "Delete the selected profile. Default profiles will reset to their original settings when deleted.")
  ww:EnslaveTooltip(createbutton, "Duplicate the current profile into a new profile.")
 
  local function OnShow(frame)
    profiles = ControlFreak.db:GetProfiles()
    UpdateRows()
  end
  frame:SetScript("OnShow", OnShow)
  OnShow(frame)
end)
 
InterfaceOptions_AddCategory(frame)