This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoseCore_Interface.lua
More file actions
384 lines (358 loc) · 13.1 KB
/
RoseCore_Interface.lua
File metadata and controls
384 lines (358 loc) · 13.1 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
Rose.Interface = {
moduleName = "Rose.Interface",
open = true,
visible = true,
currentTab = 1,
}
local self = Rose.Interface
local core = Rose.Core
self.internal = {
currentACR = nil,
settings = {}
}
self.tabs = {
[1] = {
name = "General",
image = {
path = Rose.paths.image .. "background.png",
width = 180,
height = 180,
},
tooltip = "General Settings",
options = {
{
label = "Button Options",
type = "group",
items = {}
}
}
},
}
self.social = {
[1] = {
name = "Discord",
link = [[https://discord.gg/BM9MBERbA9]],
icon = {
path = Rose.paths.image .. "discord.png",
width = 55,
height = 55,
},
tooltip = "Join the RoseCore Discord",
},
[2] = {
name = "Trello",
link = [[https://trello.com/b/4Z7Z7Z7Z/rosecore]],
icon = {
path = Rose.paths.image .. "trello.png",
width = 55,
height = 55,
},
tooltip = "View the RoseCore Trello",
},
[3] = {
name = "Ko-fi",
link = [[https://ko-fi.com/rosecore1000]],
icon = {
path = Rose.paths.image .. "kofi.png",
width = 55,
height = 60,
},
tooltip = "Support RoseCore on Ko-fi",
},
}
local function getSetting(module, key, default)
if(Rose.Settings ~= nil) then
if(Rose.Settings.getSetting ~= nil) then
return Rose.Settings.getSetting(module, key, default)
end
end
end
local function setSetting(module, key, value)
if(Rose.Settings ~= nil) then
if(Rose.Settings.getSetting ~= nil) then
Rose.Settings.setSetting(module, key, value)
end
end
end
local function log (...)
local message = Rose.Debug.Console.parse(arg)
if(Rose.Debug ~= nil) then
if(Rose.Debug.Console.log ~= nil) then
Rose.Debug.Console.log(message, self.moduleName)
end
end
end
local function logWarning (...)
local message = Rose.Debug.Console.parse(arg)
if(Rose.Debug ~= nil) then
if(Rose.Debug.Console.warning ~= nil) then
Rose.Debug.Console.warning(message, self.moduleName)
end
end
end
function self.parseOptionCheckbox(checkbox, moduleName)
local enableOption, changeOption = GUI:Checkbox(checkbox.label, getSetting(moduleName, checkbox.id, checkbox.default))
if(changeOption) then
log("Changed [" .. checkbox.id .. "] to " .. tostring(enableOption))
setSetting(moduleName,checkbox.id, enableOption)
end
end
function self.parseOptionKeybind(keybind, moduleName)
if(GUI:TreeNode("Keybind Options")) then
GUI:BeginGroup()
local keybindValue = GUI:Keybind(keybind.label, getSetting(moduleName, keybind.id, 0))
if(keybindValue ~= getSetting(moduleName, keybind.id, 0)) then
log("Changed [" .. keybind.id .. "] to " .. tostring(keybindValue))
setSetting(moduleName, keybind.id, keybindValue)
end
if(GUI:IsItemHovered()) then
GUI:SetTooltip("Click then press key to set the keybind")
end
GUI:EndGroup()
GUI:BeginGroup()
GUI:Text("Modifier Keys")
local enableShift, changeShift = GUI:Checkbox('Shift', getSetting(moduleName, keybind.id .. [[_shift]], false))
if(changeShift) then
log("Changed [" .. keybind.id .. [[_shift]] .. "] to " .. tostring(enableShift))
setSetting(moduleName,keybind.id .. [[_shift]], enableShift)
end
local enableCtrl, changeCtrl = GUI:Checkbox('Ctrl', getSetting(moduleName, keybind.id .. [[_ctrl]], false))
if(changeCtrl) then
log("Changed [" .. keybind.id .. [[_ctrl]] .. "] to " .. tostring(enableCtrl))
setSetting(moduleName,keybind.id .. [[_ctrl]], enableCtrl)
end
local enableAlt, changeAlt = GUI:Checkbox('Alt', getSetting(moduleName, keybind.id .. [[_alt]], false))
if(changeAlt) then
log("Changed [" .. keybind.id .. [[_alt]] .. "] to " .. tostring(enableAlt))
setSetting(moduleName,keybind.id .. [[_alt]], enableAlt)
end
GUI:EndGroup()
if(GUI:IsItemHovered()) then
GUI:SetTooltip([[Use checkboxes to enable modifier keys.
e.g. Shift + Keybind]])
end
GUI:TreePop()
end
end
function self.parseOptionLabel(label, moduleName)
if(label.label ~= nil) then
GUI:Text(label.label)
end
end
function self.parseOptionBlank(blank, moduleName)
GUI:Text("")
end
function self.getColumnWidth()
GUI:Columns(12, "", false)
local columnWidth = GUI:GetColumnWidth( -1 )
GUI:Columns(1)
return columnWidth
end
function self.parseOptionSlider(slider, moduleName)
local value = getSetting(moduleName, slider.id, slider.default)
local sliderValue, changeSlider = GUI:SliderInt(value .. '%', value, slider.min, slider.max)
if(changeSlider) then
log("Changed [" .. slider.id .. "] to " .. tostring(sliderValue))
setSetting(moduleName, slider.id, sliderValue)
end
end
function self.parseOptionRow(row, moduleName)
local columnWidth = self.getColumnWidth() * 4
local rowItems = row.items
if(rowItems ~= nil and #rowItems > 0) then
local columnCount = #rowItems
GUI:Columns(columnCount)
for k, item in pairsByKeys(rowItems) do
if(item.span ~= nil and type(item.span) == "number") then
GUI:SetColumnWidth( -1, columnWidth * item.span )
else
GUI:SetColumnWidth( -1, columnWidth )
end
if(item.type == "checkbox") then
self.parseOptionCheckbox(item, moduleName)
end
if(item.type == "keybind") then
self.parseOptionKeybind(item, moduleName)
end
if(item.type == "label") then
self.parseOptionLabel(item, moduleName)
end
if(item.type == "blank") then
self.parseOptionBlank(item, moduleName)
end
if(item.type == "slider") then
self.parseOptionSlider(item, moduleName)
end
if(columnCount ~= k) then
GUI:NextColumn()
else
GUI:Columns(1)
end
end
end
end
function self.parseOptionGroup(group, moduleName)
local groupItems = group.items
if(groupItems ~= nil and #groupItems > 0) then
if(group.label ~= nil) then
GUI:Text(group.label)
end
for _, item in pairsByKeys(groupItems) do
if(item.type == "row") then
self.parseOptionRow(item, moduleName)
end
end
else
if(group.label ~= nil) then
GUI:Text(group.label)
end
end
end
function self.parseOptions(options, moduleName)
if(table.valid(options)) then
for _,optionSet in pairsByKeys(options) do
if(optionSet.type == "group") then
self.parseOptionGroup(optionSet, moduleName)
end
end
end
end
function self.onInitialize(_, ...)
log('onInitialize')
local icon = Rose.paths.image .. "icon.png"
ml_gui.ui_mgr:AddMember({
id = "FFXIVMINION##MENU_RoseCore",
name = "RoseCore",
onClick = function()
self.open = not self.open
end,
tooltip = "Complete Healing Reactions",
texture = icon
}, "FFXIVMINION##MENU_HEADER")
end
function self.openLink(link, label)
if(label ~= nil) then
log("Opening " .. label .. " link: " .. link)
else
log("Opening link: " .. link)
end
if(link ~= nil) then
io.popen([[cmd /c start "" "]]..link..[["]]):close()
end
end
function self.socialIcons()
for _, social in ipairs(self.social) do
if(social.icon ~= nil) then
if(_ ~= 1) then
GUI:SameLine(0, 5)
end
GUI:Image(social.icon.path, social.icon.width, social.icon.height)
if(social.tooltip ~= nil) then
if(GUI:IsItemHovered()) then
GUI:SetTooltip(social.tooltip)
end
end
if(GUI:IsItemClicked()) then
self.openLink(social.link, social.name)
end
end
end
end
-- A function that creates a block of GUI:Button
function self.quickToggles(buttonList)
for _, button in ipairs(buttonList) do
if(button.icon ~= nil) then
if(_ ~= 1) then
GUI:SameLine(0, 5)
end
if(GUI:ImageButton("##RoseCore_" .. button.name .. "Button", button.icon.path, button.icon.width, button.icon.height, 0, 0, 1, 1, 0, 0, 0, 0)) then
if(button.tooltip ~= nil) then
if(GUI:IsItemHovered()) then
GUI:SetTooltip(button.tooltip)
end
end
if(button.onClick ~= nil) then
button.onClick()
end
end
end
end
end
function self.onDraw(_, ...)
if(self.open) then
GUI:SetNextWindowSize(1050, 450)
self.visible, self.open = GUI:Begin("Rose Core", self.open, GUI.WindowFlags_NoCollapse)
GUI:BeginChild("##RoseCore_Tabs", 200, -1, false, GUI.WindowFlags_NoResize)
for k, v in ipairs(self.tabs) do
if(v.image ~= nil) then
GUI:PushStyleColor(GUI.Col_Button, 0,0,0,0)
GUI:PushStyleColor(GUI.Col_ButtonHovered, 0,0,0,0.6)
GUI:PushStyleColor(GUI.Col_ButtonActive, 0,0,0,0.8)
if(GUI:ImageButton("##RoseCore_" .. v.name .. "Button", v.image.path, v.image.width, v.image.height, 0, 0, 1, 1, 0, 0, 0, 0, 0)) then
log("Clicked " .. v.name .. " button")
self.currentTab = k
end
GUI:PopStyleColor(3)
else
if(table.find(core.availableACR, v.moduleName) ~= nil) then
local label = v.name
if(self.internal.currentACR == v.acrName) then
label = label .. "\n\t[Active]"
end
if(self.currentTab == k) then
GUI:PushStyleColor(GUI.Col_Button, 1,0.5,0,0.8)
GUI:PushStyleColor(GUI.Col_ButtonHovered, 1,0.5,0,1)
GUI:PushStyleColor(GUI.Col_ButtonActive, 1,0.6,0,0.8)
if(GUI:Button(label, 180, 40)) then
log("Set already set to " .. v.name)
end
GUI:PopStyleColor(3)
else
if(GUI:Button(label, 180, 40)) then
self.currentTab = k
log("Tab set to " .. v.name)
end
end
if(v.tooltip ~= nil) then
if(GUI:IsItemHovered()) then
GUI:SetTooltip(v.tooltip)
end
end
end
end
end
self.socialIcons()
GUI:EndChild()
GUI:SameLine(0, 0)
GUI:BeginChild("##RoseCore_Options", -1, -1, false, GUI.WindowFlags_AlwaysAutoResize)
if(self.currentTab == 1) then
GUI:Text("Welcome to RoseCore ~") GUI:SameLine()
end
for k, tab in ipairs(self.tabs) do
if(self.currentTab == k) then
GUI:Text(tab.name .. " Settings")
GUI:Separator()
self.parseOptions(tab.options, tab.moduleName)
end
end
GUI:EndChild()
GUI:End()
end
end
function self.onACRChanged(_, old, new)
if(old ~= new) then
log("ACR Changed from [" .. old .. "] to [" .. new .. "]")
end
self.internal.currentACR = new
end
function self.loadACR(_, ...)
-- arg[1] = sender module name
local decodedTab = json.decode(arg[2])
decodedTab.options = json.decode(arg[3])
table.insert(self.tabs, decodedTab)
end
RegisterEventHandler("Module.Initalize", self.onInitialize, "Rose.Interface.onInitialize")
RegisterEventHandler("Gameloop.Draw", self.onDraw, "Rose.Interface.onDraw")
-- Custom Events
RegisterEventHandler("Rose.Events.LoadACR", self.loadACR, "Rose.Interface.onACRAvailable")
RegisterEventHandler("Rose.Events.ACRChanged", self.onACRChanged, "Rose.Interface.onACRChanged")