annotate Options.lua @ 141:cc82eeeec1c8 v66

Fixed bug with multiple set import.
author yellowfive
date Tue, 06 Nov 2018 15:39:13 -0800
parents a0894ffebd15
children a3507735dfd9
rev   line source
yellowfive@57 1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
yellowfive@57 3 local AceGUI = LibStub("AceGUI-3.0")
yellowfive@57 4
yellowfive@57 5 local _chkMinimap
yellowfive@57 6 local _chkAutoGear
yellowfive@57 7 local _chkAh
yellowfive@91 8 local _chkEm
yellowfive@61 9 local _txtScale
yellowfive@61 10
yellowfive@61 11 local function onTextboxEnter(widget)
yellowfive@61 12 local setting = widget:GetUserData("setting")
yellowfive@61 13 local val = widget:GetText()
yellowfive@61 14
yellowfive@61 15 val = tonumber(val)
yellowfive@61 16 if not val then
yellowfive@61 17 widget:SetText(Amr.db.profile.options[setting])
yellowfive@61 18 else
yellowfive@61 19 if setting == "uiScale" then
yellowfive@61 20 if val < 0.5 then
yellowfive@61 21 val = 0.5
yellowfive@61 22 elseif val > 1.5 then
yellowfive@61 23 val = 1.5
yellowfive@61 24 end
yellowfive@61 25 end
yellowfive@61 26
yellowfive@61 27 Amr.db.profile.options[setting] = val
yellowfive@61 28 Amr:RefreshConfig()
yellowfive@61 29 end
yellowfive@61 30 end
yellowfive@57 31
yellowfive@124 32 local function onCheckClick(widget)
yellowfive@57 33 local setting = widget:GetUserData("setting")
yellowfive@57 34 local val = widget:GetChecked()
yellowfive@57 35
yellowfive@57 36 if setting == "minimap" then
yellowfive@57 37 Amr.db.profile.minimap.hide = val
yellowfive@57 38 else
yellowfive@57 39 Amr.db.profile.options[setting] = val
yellowfive@57 40 end
yellowfive@57 41
yellowfive@57 42 Amr:RefreshConfig()
yellowfive@57 43 end
yellowfive@57 44
yellowfive@57 45 local function createCheck(container, setting, text, description)
yellowfive@57 46
yellowfive@57 47 local chk = AceGUI:Create("AmrUiCheckBox")
yellowfive@57 48 chk:SetUserData("setting", setting)
yellowfive@57 49 chk:SetText(text)
yellowfive@57 50 chk:SetCallback("OnClick", onCheckClick)
yellowfive@57 51 container:AddChild(chk)
yellowfive@57 52
yellowfive@57 53 local desc = AceGUI:Create("AmrUiLabel")
yellowfive@124 54 container:AddChild(desc)
yellowfive@57 55 desc:SetWidth(800)
yellowfive@57 56 desc:SetText(description)
yellowfive@57 57 desc:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@57 58 desc:SetPoint("TOPLEFT", chk.frame, "BOTTOMLEFT", 24, -3)
yellowfive@57 59
yellowfive@57 60 return chk, desc
yellowfive@57 61 end
yellowfive@57 62
yellowfive@61 63 local function createSmallTextbox(container, setting, text, description)
yellowfive@61 64
yellowfive@61 65 local txt = AceGUI:Create("AmrUiTextarea")
yellowfive@61 66 txt:SetUserData("setting", setting)
yellowfive@61 67 txt:SetMultiLine(false)
yellowfive@61 68 txt:SetWidth(35)
yellowfive@61 69 txt:SetHeight(24)
yellowfive@61 70 txt:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@61 71 txt:SetCallback("OnEnterPressed", onTextboxEnter)
yellowfive@61 72 container:AddChild(txt)
yellowfive@61 73
yellowfive@61 74 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 75 container:AddChild(lbl)
yellowfive@61 76 lbl:SetWidth(600)
yellowfive@61 77 lbl:SetText(text)
yellowfive@61 78 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@61 79 lbl:SetPoint("LEFT", txt.frame, "RIGHT", 6, 0)
yellowfive@61 80
yellowfive@61 81 local desc = AceGUI:Create("AmrUiLabel")
yellowfive@124 82 container:AddChild(desc)
yellowfive@61 83 desc:SetWidth(800)
yellowfive@61 84 desc:SetText(description)
yellowfive@61 85 desc:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@61 86 desc:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -4)
yellowfive@61 87
yellowfive@61 88 return txt, desc
yellowfive@61 89 end
yellowfive@61 90
yellowfive@57 91 -- renders the main UI for the Combat Log tab
yellowfive@57 92 function Amr:RenderTabOptions(container)
yellowfive@57 93
yellowfive@57 94 local header = AceGUI:Create("AmrUiLabel")
yellowfive@124 95 container:AddChild(header)
yellowfive@57 96 header:SetWidth(600)
yellowfive@57 97 header:SetText(L.OptionsHeaderGeneral)
yellowfive@57 98 header:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
yellowfive@57 99 header:SetPoint("TOPLEFT", container.content, "TOPLEFT", 12, -40)
yellowfive@57 100
yellowfive@57 101 local desc, desc2
yellowfive@57 102
yellowfive@57 103 _chkMinimap, desc = createCheck(container, "minimap", L.OptionsHideMinimapName, L.OptionsHideMinimapDesc)
yellowfive@61 104 _chkMinimap:SetPoint("TOPLEFT", header.frame, "BOTTOMLEFT", 10, -20)
yellowfive@57 105
yellowfive@57 106 _chkAutoGear, desc2 = createCheck(container, "autoGear", L.OptionsAutoGearName, L.OptionsAutoGearDesc)
yellowfive@57 107 _chkAutoGear:SetPoint("TOPLEFT", desc.frame, "BOTTOMLEFT", -24, -20)
yellowfive@57 108
yellowfive@57 109 _chkAh, desc = createCheck(container, "shopAh", L.OptionsShopAhName, L.OptionsShopAhDesc)
yellowfive@57 110 _chkAh:SetPoint("TOPLEFT", desc2.frame, "BOTTOMLEFT", -24, -20)
yellowfive@57 111
yellowfive@91 112 _chkEm, desc2 = createCheck(container, "disableEm", L.OptionsDisableEmName, L.OptionsDisableEmDesc)
yellowfive@91 113 _chkEm:SetPoint("TOPLEFT", desc.frame, "BOTTOMLEFT", -24, -20)
yellowfive@91 114
yellowfive@91 115 _txtScale, desc = createSmallTextbox(container, "uiScale", L.OptionsUiScaleName, L.OptionsUiScaleDesc)
yellowfive@91 116 _txtScale:SetPoint("TOPLEFT", desc2.frame, "BOTTOMLEFT", -43, -20)
yellowfive@61 117
yellowfive@57 118 -- initialize state of controls
yellowfive@57 119 Amr:RefreshOptionsUi()
yellowfive@57 120 end
yellowfive@57 121
yellowfive@57 122 function Amr:ReleaseTabOptions()
yellowfive@57 123 _chkMinimap = nil
yellowfive@124 124 _chkAutoGear = nil
yellowfive@124 125 _chkAh = nil
yellowfive@124 126 _chkEm = nil
yellowfive@124 127 _txtScale = nil
yellowfive@57 128 end
yellowfive@57 129
yellowfive@57 130 function Amr:RefreshOptionsUi()
yellowfive@57 131
yellowfive@57 132 if _chkMinimap then
yellowfive@57 133 _chkMinimap:SetChecked(self.db.profile.minimap.hide)
yellowfive@57 134 end
yellowfive@57 135
yellowfive@57 136 if _chkAutoGear then
yellowfive@57 137 _chkAutoGear:SetChecked(self.db.profile.options.autoGear)
yellowfive@57 138 end
yellowfive@57 139
yellowfive@57 140 if _chkAh then
yellowfive@57 141 _chkAh:SetChecked(self.db.profile.options.shopAh)
yellowfive@57 142 end
yellowfive@61 143
yellowfive@91 144 if _chkEm then
yellowfive@91 145 _chkEm:SetChecked(self.db.profile.options.disableEm)
yellowfive@91 146 end
yellowfive@91 147
yellowfive@61 148 if _txtScale then
yellowfive@61 149 _txtScale:SetText(self.db.profile.options.uiScale)
yellowfive@61 150 _txtScale:ClearFocus()
yellowfive@61 151 end
yellowfive@122 152 end