ui_legacy.lua

main 135 lines · 3.5 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1local context = G.botContext
2
3-- DO NOT USE THIS CODE.
4-- IT'S ONLY HERE FOR BACKWARD COMPATIBILITY, MAY BE REMOVED IN THE FUTURE
5
6context.createWidget = function(name, parent)
7 if parent == nil then
8 parent = context.panel
9 end
10 g_ui.createWidget(name, parent)
11end
12
13context.setupUI = function(otml, parent)
14 if parent == nil then
15 parent = context.panel
16 end
17 local widget = g_ui.loadUIFromString(otml, parent)
18 widget.botWidget = true
19 return widget
20end
21
22context.importStyle = function(otml)
23 if type(otml) ~= "string" then
24 return error("Invalid parameter for importStyle, should be string")
25 end
26 if otml:find(".otui") and not otml:find("\n") then
27 return g_ui.importStyle(context.configDir .. "/" .. otml)
28 end
29 return g_ui.importStyleFromString(otml)
30end
31
32context.addTab = function(name)
33 local tab = context.tabs:getTab(name)
34 if tab then -- return existing tab
35 return tab.tabPanel.content
36 end
37
38 local smallTabs = #(context.tabs.tabs) >= 5
39 local newTab = context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content
40 context.tabs:setOn(true)
41 if smallTabs then
42 for k,tab in pairs(context.tabs.tabs) do
43 tab:setFont('small-9px')
44 end
45 end
46
47 return newTab
48end
49context.getTab = context.addTab
50
51context.setDefaultTab = function(name)
52 local tab = context.addTab(name)
53 context.panel = tab
54end
55
56context.addSwitch = function(id, text, onClickCallback, parent)
57 if not parent then
58 parent = context.panel
59 end
60 local switch = g_ui.createWidget('BotSwitch', parent)
61 switch:setId(id)
62 switch:setText(text)
63 switch.onClick = onClickCallback
64 return switch
65end
66
67context.addButton = function(id, text, onClickCallback, parent)
68 if not parent then
69 parent = context.panel
70 end
71 local button = g_ui.createWidget('BotButton', parent)
72 button:setId(id)
73 button:setText(text)
74 button.onClick = onClickCallback
75 return button
76end
77
78context.addLabel = function(id, text, parent)
79 if not parent then
80 parent = context.panel
81 end
82 local label = g_ui.createWidget('BotLabel', parent)
83 label:setId(id)
84 label:setText(text)
85 return label
86end
87
88context.addTextEdit = function(id, text, onTextChangeCallback, parent)
89 if not parent then
90 parent = context.panel
91 end
92 local widget = g_ui.createWidget('BotTextEdit', parent)
93 widget:setId(id)
94 widget.onTextChange = onTextChangeCallback
95 widget:setText(text)
96 return widget
97end
98
99context.addSeparator = function(id, parent)
100 if not parent then
101 parent = context.panel
102 end
103 local separator = g_ui.createWidget('BotSeparator', parent)
104 separator:setId(id)
105 return separator
106end
107
108context._addMacroSwitch = function(name, keys, parent)
109 if not parent then
110 parent = context.panel
111 end
112 local text = name
113 if keys:len() > 0 then
114 text = name .. " [" .. keys .. "]"
115 end
116 local switch = context.addSwitch("macro_" .. #context._macros, text, function(widget)
117 context.storage._macros[name] = not context.storage._macros[name]
118 widget:setOn(context.storage._macros[name])
119 end, parent)
120 switch:setOn(context.storage._macros[name])
121 return switch
122end
123
124context._addHotkeySwitch = function(name, keys, parent)
125 if not parent then
126 parent = context.panel
127 end
128 local text = name
129 if keys:len() > 0 then
130 text = name .. " [" .. keys .. "]"
131 end
132 local switch = context.addSwitch("hotkey_" .. #context._hotkeys, text, nil, parent)
133 switch:setOn(false)
134 return switch
135end
Top