-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.lua
111 lines (94 loc) · 3.68 KB
/
gui.lua
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
local settings = require('settings')
local imgui = require('imgui')
require("discord")
local gui = T{
is_open = T{ False }
}
function render_config_menu(todbot)
if (not gui.is_open[1]) then
return
end
imgui.SetNextWindowSize({ -1, -1 })
if (imgui.Begin('todbot', gui.is_open)) then
imgui.Text(todbot.settings.webhookURL)
local webhookURL = T{ todbot.settings.webhookURL }
imgui.InputText('webhookURL', webhookURL, 1024)
todbot.settings.webhookURL = table.concat(webhookURL)
imgui.NewLine()
imgui.Text(todbot.settings.avatarURL)
local avatarURL = T{ todbot.settings.avatarURL }
imgui.InputText('avatarURL', avatarURL, 1024)
todbot.settings.avatarURL = table.concat(avatarURL)
end
imgui.End()
end
function deepCopy(original)
local copy
if type(original) == "table" then
copy = {}
for key, value in next, original, nil do
copy[deepCopy(key)] = deepCopy(value)
end
setmetatable(copy, deepCopy(getmetatable(original)))
else
copy = original
end
return copy
end
local monster_tod_open = T{ true }
function render_monster_tod_popup(todbot)
if next(todbot.recent_monsters) == nil then
return
end
local recent_monsters = deepCopy(todbot.recent_monsters)
imgui.SetNextWindowSize({ -1, -1 })
if (imgui.Begin('monster_tod', monster_tod_open, ImGuiWindowFlags_NoCollapse)) then
if( imgui.Button("Dismiss All") ) then
todbot.recent_monsters = T{}
end
imgui.Separator()
if imgui.BeginTable('##tods', 3, bit.bor(ImGuiTableFlags_RowBg, ImGuiTableFlags_BordersH, ImGuiTableFlags_BordersV, ImGuiTableFlags_ScrollY)) then
imgui.TableSetupColumn('Name', ImGuiTableColumnFlags_WidthStretch, 0, 0)
imgui.TableSetupColumn('TOD', ImGuiTableColumnFlags_WidthFixed, 300, 0)
imgui.TableSetupColumn('Action', ImGuiTableColumnFlags_WidthFixed, 150, 0)
imgui.TableHeadersRow();
for i, monster in ipairs(recent_monsters) do
imgui.PushID(i)
imgui.TableNextRow()
imgui.TableSetColumnIndex(0)
imgui.Text(monster.name)
imgui.TableNextColumn()
local pt_format = "%Y-%m-%d %H:%M:%S %Z"
local pt_timestamp = os.date(pt_format, monster.timestamp)
imgui.Text(pt_timestamp)
imgui.TableNextColumn()
local message = string.format("%s: <t:%d:T> <t:%d:R> ", monster.name, monster.timestamp, monster.timestamp)
if( imgui.Button("Copy") ) then
ashita.misc.set_clipboard(message)
table.remove(todbot.recent_monsters, i)
end
imgui.SameLine()
if( imgui.Button("Post") ) then
ashita.tasks.once(0, function()
sendToDiscordWebhook(message, todbot.settings.webhookURL, todbot.settings.avatarURL)
end)
table.remove(todbot.recent_monsters, i)
end
imgui.SameLine()
if( imgui.Button("Dismiss") ) then
table.remove(todbot.recent_monsters, i)
end
imgui.PopID()
end
imgui.EndTable()
end
end
imgui.End()
end
function register_gui(todbot)
ashita.events.register('d3d_present', 'present_cb', function ()
render_config_menu(todbot)
render_monster_tod_popup(todbot)
end)
end
return gui