annotate Options.lua @ 127:65c285394049 v59

Fixed an issue with reading bank data.
author yellowfive
date Tue, 17 Jul 2018 16:32:12 -0700
parents e31b02b24488
children a0894ffebd15
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 onChkMinimapClick()
yellowfive@57 46 Amr.db.profile.minimap.hide = _chkMinimap:GetChecked()
yellowfive@57 47 Amr:RefreshConfig()
yellowfive@57 48 end
yellowfive@57 49
yellowfive@57 50 local function createCheck(container, setting, text, description)
yellowfive@57 51
yellowfive@57 52 local chk = AceGUI:Create("AmrUiCheckBox")
yellowfive@57 53 chk:SetUserData("setting", setting)
yellowfive@57 54 chk:SetText(text)
yellowfive@57 55 chk:SetCallback("OnClick", onCheckClick)
yellowfive@57 56 container:AddChild(chk)
yellowfive@57 57
yellowfive@57 58 local desc = AceGUI:Create("AmrUiLabel")
yellowfive@124 59 container:AddChild(desc)
yellowfive@57 60 desc:SetWidth(800)
yellowfive@57 61 desc:SetText(description)
yellowfive@57 62 desc:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@57 63 desc:SetPoint("TOPLEFT", chk.frame, "BOTTOMLEFT", 24, -3)
yellowfive@57 64
yellowfive@57 65 return chk, desc
yellowfive@57 66 end
yellowfive@57 67
yellowfive@61 68 local function createSmallTextbox(container, setting, text, description)
yellowfive@61 69
yellowfive@61 70 local txt = AceGUI:Create("AmrUiTextarea")
yellowfive@61 71 txt:SetUserData("setting", setting)
yellowfive@61 72 txt:SetMultiLine(false)
yellowfive@61 73 txt:SetWidth(35)
yellowfive@61 74 txt:SetHeight(24)
yellowfive@61 75 txt:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@61 76 txt:SetCallback("OnEnterPressed", onTextboxEnter)
yellowfive@61 77 container:AddChild(txt)
yellowfive@61 78
yellowfive@61 79 local lbl = AceGUI:Create("AmrUiLabel")
yellowfive@124 80 container:AddChild(lbl)
yellowfive@61 81 lbl:SetWidth(600)
yellowfive@61 82 lbl:SetText(text)
yellowfive@61 83 lbl:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@61 84 lbl:SetPoint("LEFT", txt.frame, "RIGHT", 6, 0)
yellowfive@61 85
yellowfive@61 86 local desc = AceGUI:Create("AmrUiLabel")
yellowfive@124 87 container:AddChild(desc)
yellowfive@61 88 desc:SetWidth(800)
yellowfive@61 89 desc:SetText(description)
yellowfive@61 90 desc:SetFont(Amr.CreateFont("Italic", 12, Amr.Colors.TextTan))
yellowfive@61 91 desc:SetPoint("TOPLEFT", lbl.frame, "BOTTOMLEFT", 0, -4)
yellowfive@61 92
yellowfive@61 93 return txt, desc
yellowfive@61 94 end
yellowfive@61 95
yellowfive@57 96 -- renders the main UI for the Combat Log tab
yellowfive@57 97 function Amr:RenderTabOptions(container)
yellowfive@57 98
yellowfive@57 99 local header = AceGUI:Create("AmrUiLabel")
yellowfive@124 100 container:AddChild(header)
yellowfive@57 101 header:SetWidth(600)
yellowfive@57 102 header:SetText(L.OptionsHeaderGeneral)
yellowfive@57 103 header:SetFont(Amr.CreateFont("Bold", 24, Amr.Colors.TextHeaderActive))
yellowfive@57 104 header:SetPoint("TOPLEFT", container.content, "TOPLEFT", 12, -40)
yellowfive@57 105
yellowfive@57 106 local desc, desc2
yellowfive@57 107
yellowfive@57 108 _chkMinimap, desc = createCheck(container, "minimap", L.OptionsHideMinimapName, L.OptionsHideMinimapDesc)
yellowfive@61 109 _chkMinimap:SetPoint("TOPLEFT", header.frame, "BOTTOMLEFT", 10, -20)
yellowfive@57 110
yellowfive@57 111 _chkAutoGear, desc2 = createCheck(container, "autoGear", L.OptionsAutoGearName, L.OptionsAutoGearDesc)
yellowfive@57 112 _chkAutoGear:SetPoint("TOPLEFT", desc.frame, "BOTTOMLEFT", -24, -20)
yellowfive@57 113
yellowfive@57 114 _chkAh, desc = createCheck(container, "shopAh", L.OptionsShopAhName, L.OptionsShopAhDesc)
yellowfive@57 115 _chkAh:SetPoint("TOPLEFT", desc2.frame, "BOTTOMLEFT", -24, -20)
yellowfive@57 116
yellowfive@91 117 _chkEm, desc2 = createCheck(container, "disableEm", L.OptionsDisableEmName, L.OptionsDisableEmDesc)
yellowfive@91 118 _chkEm:SetPoint("TOPLEFT", desc.frame, "BOTTOMLEFT", -24, -20)
yellowfive@91 119
yellowfive@91 120 _txtScale, desc = createSmallTextbox(container, "uiScale", L.OptionsUiScaleName, L.OptionsUiScaleDesc)
yellowfive@91 121 _txtScale:SetPoint("TOPLEFT", desc2.frame, "BOTTOMLEFT", -43, -20)
yellowfive@61 122
yellowfive@57 123 -- initialize state of controls
yellowfive@57 124 Amr:RefreshOptionsUi()
yellowfive@57 125 end
yellowfive@57 126
yellowfive@57 127 function Amr:ReleaseTabOptions()
yellowfive@57 128 _chkMinimap = nil
yellowfive@124 129 _chkAutoGear = nil
yellowfive@124 130 _chkAh = nil
yellowfive@124 131 _chkEm = nil
yellowfive@124 132 _txtScale = nil
yellowfive@57 133 end
yellowfive@57 134
yellowfive@57 135 function Amr:RefreshOptionsUi()
yellowfive@57 136
yellowfive@57 137 if _chkMinimap then
yellowfive@57 138 _chkMinimap:SetChecked(self.db.profile.minimap.hide)
yellowfive@57 139 end
yellowfive@57 140
yellowfive@57 141 if _chkAutoGear then
yellowfive@57 142 _chkAutoGear:SetChecked(self.db.profile.options.autoGear)
yellowfive@57 143 end
yellowfive@57 144
yellowfive@57 145 if _chkAh then
yellowfive@57 146 _chkAh:SetChecked(self.db.profile.options.shopAh)
yellowfive@57 147 end
yellowfive@61 148
yellowfive@91 149 if _chkEm then
yellowfive@91 150 _chkEm:SetChecked(self.db.profile.options.disableEm)
yellowfive@91 151 end
yellowfive@91 152
yellowfive@61 153 if _txtScale then
yellowfive@61 154 _txtScale:SetText(self.db.profile.options.uiScale)
yellowfive@61 155 _txtScale:ClearFocus()
yellowfive@61 156 end
yellowfive@122 157 end