-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCDGCommon.lua
161 lines (130 loc) · 5.09 KB
/
CDGCommon.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
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
-- Common code betwene the Client and Master like slash commands and minimap button
-- Global 3 way UI Toggler
-- ==========================
local ToggleClientAndCasino = function()
if (CDGClient.db.global.window_shown) then
CDGClient:ToggleClient()
elseif (CalmDownandGamble.db.global.window_shown) then
CalmDownandGamble:HideUI()
else
CDGClient:ShowUI()
end
end
function CalmDownandGamble:ToggleCasino()
CalmDownandGamble:HideUI()
CDGClient:ShowUI()
end
function CDGClient:ToggleClient()
CDGClient:HideUI()
CalmDownandGamble:ShowUI()
end
-- MiniMap Icon Definition
-- =========================
function CalmDownandGamble:ConstructMiniMapIcon()
self.minimap = { }
self.minimap.icon_data = LibStub("LibDataBroker-1.1"):NewDataObject("CalmDownandGambleIcon", {
type = "data source",
text = "Calm Down and Gamble!",
icon = "Interface\\Icons\\INV_Misc_Coin_02",
OnClick = ToggleClientAndCasino,
OnTooltipShow = function(tooltip)
tooltip:AddLine("Calm Down and Gamble!",1,1,1)
tooltip:Show()
end,
})
self.minimap.icon = LibStub("LibDBIcon-1.0")
self.minimap.icon:Register("CalmDownandGambleIcon", self.minimap.icon_data, self.db.global.minimap)
end
-- Debug Setup
-- ==================
function CalmDownandGamble:PrintDebug(msg)
if self.DEBUG_ENABLED then self:Print("[CDG_DEBUG] "..msg) end
end
-- Custom Channel Handling
-- ==========================
function CalmDownandGamble:GetCustomChannelName()
-- Figure out the Channel Name
guildName, guildRankName, guildRankIndex = GetGuildInfo("player")
guildName = string.gsub(guildName, "%s+", "")
channel_name = guildName.."Gambling"
return channel_name
end
function CalmDownandGamble:JoinCustomChannel(channel_name)
-- Only if we're not only in a channel
if (self.db.global.custom_channel.index) then return end
if (channel_name == nil) then channel_name = self:GetCustomChannelName() end
-- Joining a channel without the slash command is wonky, so kind've abusing the slashcmd list
SlashCmdList["JOIN"](channel_name)
channel_number, channel_string, instanceID = GetChannelName(channel_name)
-- Update our references so we send chat to the right place
self.db.global.custom_channel.index = channel_number
self.db.global.custom_channel.name = channel_name
-- Remove it on logout/reload to avoid conflicts
self:RegisterEvent("PLAYER_LEAVING_WORLD", "LeaveCustomChannel")
end
function CalmDownandGamble:LeaveCustomChannel()
LeaveChannelByName(self.db.global.custom_channel.name)
self.db.global.custom_channel.index = nil
self.db.global.custom_channel.name = ""
end
function CalmDownandGamble:PrintSlashCommandHelp()
self:Print("CalmDown and Gamble Slash Commands: ")
self:Print(" /cdg <command> ")
self:Print(" <no command> - Toggles UI like the minimap button does")
self:Print(" auto - Toggles auto pop up of rolling UI")
self:Print(" stats - Prints the hall of fame and shame")
self:Print(" ban <player> - Bans player from entering CDG")
self:Print(" unban <player> - Unbans player")
self:Print(" resetStats - Clears hall of fame/shame")
self:Print(" resetBans - Clears all bans ")
self:Print(" join - Join custom gambling channel for your guild")
self:Print(" leave - Leave custom gambling channel")
end
-- Slash Commands
-- ================
-- Handler Needed to support multiargument commands
function CalmDownandGamble:SlashCommandHandler(...)
command_args = self:SplitString(select(1, ...), "%S+")
command = command_args[1]
if (command == nil) then
ToggleClientAndCasino()
elseif (command == "ban") then
player = command_args[2]
self.db.global.ban_list[player] = true
elseif (command == "unban") then
player = command_args[2]
self.db.global.ban_list[player] = nil
elseif (command == "resetStats") then
self.db.global.rankings = {}
elseif (command == "resetBans") then
self.db.global.ban_list = {}
elseif (command == "stats") then
self:PrintRanklist()
elseif (command == "auto") then
CDGClient.db.global.auto_pop = not CDGClient.db.global.auto_pop
if CDGClient.db.global.auto_pop then
self:Print("Enabled auto show of rolling UI.")
else
self:Print("Disabled auto show of rolling UI.")
end
elseif (command == "debug") then
self.DEBUG_ENABLED = not self.DEBUG_ENABLED
elseif (command == "join") then
channel_name = command_args[2]
self:JoinCustomChannel(channel_name)
elseif (command == "leave") then
self:LeaveCustomChannel()
elseif (command == "help") then
self:PrintSlashCommandHelp()
else
self:Print("Unrecognized CDG Slash Command: ")
self:Print(command)
self:Print("Use /cdg help for more information.")
end
end
-- Called from constructor of main addon
function CalmDownandGamble:RegisterSlashCommands()
self:RegisterChatCommand("cdg", "SlashCommandHandler")
-- Legacy Support - TODO: Remove
self:RegisterChatCommand("cdgm", "ShowUI")
end