Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 10 | Seerah-7 | --[[editboxData = { |
2 | Seerah-7 | type = "editbox", |
|
3 | Seerah-7 | name = "My Editbox", |
|
4 | Seerah-7 | tooltip = "Editbox's tooltip text.", |
|
5 | Seerah-7 | getFunc = function() return db.text end, |
|
6 | Seerah-7 | setFunc = function(text) db.text = text doStuff() end, |
|
7 | Seerah-7 | isMultiline = true, --boolean |
|
8 | Seerah-7 | width = "full", --or "half" (optional) |
|
9 | Seerah-7 | disabled = function() return db.someBooleanSetting end, --or boolean (optional) |
|
10 | Seerah-7 | warning = "Will need to reload the UI.", --(optional) |
|
11 | Seerah-7 | default = defaults.text, --(optional) |
|
12 | 28 | Seerah-7 | reference = "MyAddonEditbox" --(optional) unique global reference to control |
13 | 10 | Seerah-7 | } ]] |
14 | Seerah-7 | ||
15 | Seerah-7 | ||
16 | 32 | Seerah-7 | local widgetVersion = 2 |
17 | 10 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
18 | 14 | Seerah-7 | if not LAM:RegisterWidget("editbox", widgetVersion) then return end |
19 | 10 | Seerah-7 | |
20 | Seerah-7 | local wm = WINDOW_MANAGER |
|
21 | Seerah-7 | local cm = CALLBACK_MANAGER |
|
22 | 16 | Seerah-7 | local tinsert = table.insert |
23 | 10 | Seerah-7 | |
24 | Seerah-7 | ||
25 | Seerah-7 | local function UpdateDisabled(control) |
|
26 | Seerah-7 | local disable |
|
27 | Seerah-7 | if type(control.data.disabled) == "function" then |
|
28 | Seerah-7 | disable = control.data.disabled() |
|
29 | Seerah-7 | else |
|
30 | Seerah-7 | disable = control.data.disabled |
|
31 | Seerah-7 | end |
|
32 | Seerah-7 | ||
33 | Seerah-7 | if disable then |
|
34 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_DISABLED_COLOR:UnpackRGBA()) |
|
35 | 21 | Seerah-7 | control.editbox:SetColor(ZO_DEFAULT_DISABLED_MOUSEOVER_COLOR:UnpackRGBA()) |
36 | 10 | Seerah-7 | else |
37 | 21 | Seerah-7 | control.label:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
38 | Seerah-7 | control.editbox:SetColor(ZO_DEFAULT_ENABLED_COLOR:UnpackRGBA()) |
|
39 | 10 | Seerah-7 | end |
40 | 21 | Seerah-7 | --control.editbox:SetEditEnabled(not disable) |
41 | Seerah-7 | control.editbox:SetMouseEnabled(not disable) |
|
42 | 10 | Seerah-7 | end |
43 | Seerah-7 | ||
44 | Seerah-7 | local function UpdateValue(control, forceDefault, value) |
|
45 | Seerah-7 | if forceDefault then --if we are forcing defaults |
|
46 | Seerah-7 | value = control.data.default |
|
47 | Seerah-7 | control.data.setFunc(value) |
|
48 | Seerah-7 | control.editbox:SetText(value) |
|
49 | Seerah-7 | elseif value then |
|
50 | Seerah-7 | control.data.setFunc(value) |
|
51 | Seerah-7 | --after setting this value, let's refresh the others to see if any should be disabled or have their settings changed |
|
52 | Seerah-7 | if control.panel.data.registerForRefresh then |
|
53 | Seerah-7 | cm:FireCallbacks("LAM-RefreshPanel", control) |
|
54 | Seerah-7 | end |
|
55 | Seerah-7 | else |
|
56 | Seerah-7 | value = control.data.getFunc() |
|
57 | Seerah-7 | control.editbox:SetText(value) |
|
58 | Seerah-7 | end |
|
59 | Seerah-7 | end |
|
60 | Seerah-7 | ||
61 | Seerah-7 | ||
62 | Seerah-7 | local scrollCount = 1 |
|
63 | Seerah-7 | function LAMCreateControl.editbox(parent, editboxData, controlName) |
|
64 | 28 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName or editboxData.reference) |
65 | 11 | Seerah-7 | control:SetParent(parent.scroll) |
66 | 10 | Seerah-7 | control:SetMouseEnabled(true) |
67 | 16 | Seerah-7 | control:SetResizeToFitDescendents(true) |
68 | 10 | Seerah-7 | control.tooltipText = editboxData.tooltip |
69 | Seerah-7 | control:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter) |
|
70 | Seerah-7 | control:SetHandler("OnMouseExit", ZO_Options_OnMouseExit) |
|
71 | Seerah-7 | ||
72 | Seerah-7 | control.label = wm:CreateControl(nil, control, CT_LABEL) |
|
73 | Seerah-7 | local label = control.label |
|
74 | Seerah-7 | label:SetAnchor(TOPLEFT) |
|
75 | Seerah-7 | label:SetFont("ZoFontWinH4") |
|
76 | Seerah-7 | label:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS) |
|
77 | Seerah-7 | label:SetText(editboxData.name) |
|
78 | Seerah-7 | ||
79 | Seerah-7 | control.bg = wm:CreateControlFromVirtual(nil, control, "ZO_EditBackdrop") |
|
80 | Seerah-7 | local bg = control.bg |
|
81 | Seerah-7 | ||
82 | 25 | Seerah-7 | if editboxData.isMultiline then |
83 | 13 | Seerah-7 | control.scroll = wm:CreateControlFromVirtual(parent:GetName().."Scroll"..scrollCount, bg, "ZO_ScrollContainer") |
84 | 10 | Seerah-7 | scrollCount = scrollCount + 1 |
85 | Seerah-7 | control.editbox = wm:CreateControlFromVirtual(nil, control.scroll, "ZO_DefaultEditMultiLineForBackdrop") |
|
86 | Seerah-7 | else |
|
87 | Seerah-7 | control.editbox = wm:CreateControlFromVirtual(nil, bg, "ZO_DefaultEditForBackdrop") |
|
88 | Seerah-7 | end |
|
89 | Seerah-7 | local editbox = control.editbox |
|
90 | Seerah-7 | editbox:SetText(editboxData.getFunc()) |
|
91 | Seerah-7 | editbox:SetMaxInputChars(3000) |
|
92 | Seerah-7 | editbox:SetHandler("OnFocusLost", function(self) control:UpdateValue(false, self:GetText()) end) |
|
93 | Seerah-7 | editbox:SetHandler("OnEscape", function(self) self:LoseFocus() control:UpdateValue() end) |
|
94 | Seerah-7 | editbox:SetHandler("OnMouseEnter", function() ZO_Options_OnMouseEnter(control) end) |
|
95 | Seerah-7 | editbox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) |
|
96 | Seerah-7 | ||
97 | Seerah-7 | local isHalfWidth = editboxData.width == "half" |
|
98 | Seerah-7 | if isHalfWidth then |
|
99 | Seerah-7 | control:SetDimensions(250, 55) |
|
100 | Seerah-7 | label:SetDimensions(250, 26) |
|
101 | 25 | Seerah-7 | bg:SetDimensions(240, editboxData.isMultiline and 74 or 24) |
102 | 10 | Seerah-7 | bg:SetAnchor(TOPRIGHT, label, BOTTOMRIGHT) |
103 | Seerah-7 | else |
|
104 | Seerah-7 | control:SetDimensions(510, 30) |
|
105 | Seerah-7 | label:SetDimensions(300, 26) |
|
106 | 25 | Seerah-7 | bg:SetDimensions(200, editboxData.isMultiline and 100 or 24) |
107 | 10 | Seerah-7 | bg:SetAnchor(TOPRIGHT) |
108 | Seerah-7 | end |
|
109 | Seerah-7 | ||
110 | Seerah-7 | if editboxData.warning then |
|
111 | Seerah-7 | control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") |
|
112 | Seerah-7 | control.warning:SetAnchor(TOPRIGHT, control.bg, TOPLEFT, -5, 0) |
|
113 | Seerah-7 | control.warning.tooltipText = editboxData.warning |
|
114 | Seerah-7 | end |
|
115 | Seerah-7 | ||
116 | Seerah-7 | control.panel = parent.panel or parent --if this is in a submenu, panel is its parent |
|
117 | Seerah-7 | control.data = editboxData |
|
118 | Seerah-7 | ||
119 | Seerah-7 | if editboxData.disabled then |
|
120 | Seerah-7 | control.UpdateDisabled = UpdateDisabled |
|
121 | Seerah-7 | control:UpdateDisabled() |
|
122 | Seerah-7 | end |
|
123 | Seerah-7 | control.UpdateValue = UpdateValue |
|
124 | Seerah-7 | control:UpdateValue() |
|
125 | Seerah-7 | ||
126 | 27 | Seerah-7 | if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list |
127 | 10 | Seerah-7 | tinsert(control.panel.controlsToRefresh, control) |
128 | Seerah-7 | end |
|
129 | Seerah-7 | ||
130 | Seerah-7 | return control |
|
131 | Seerah-7 | end |