Skip to content

Commit

Permalink
Merge pull request #8 from Taidtuskecyh/master
Browse files Browse the repository at this point in the history
fixes to team management and comms
  • Loading branch information
Vapok authored Jun 4, 2020
2 parents 1e36707 + 125cad5 commit 8f80adb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 60 deletions.
23 changes: 23 additions & 0 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,29 @@ function MonDKP:StatusVerify_Update()
end
end


-- moved to core from ManageEntries as this is called from comm.lua aswell
function MonDKP:SetCurrentTeam(index)
MonDKP:GetTable(MonDKP_DB, false)["defaults"]["CurrentTeam"] = tostring(index)

UIDropDownMenu_SetText(MonDKP.UIConfig.TeamViewChangerDropDown, MonDKP:GetCurrentTeamName())

-- reset dkp table and update it
core.WorkingTable = MonDKP:GetTable(MonDKP_DKPTable, true);
core.PriceTable = MonDKP:GetTable(MonDKP_MinBids, true);
DKPTable_Update()

-- reset dkp history table and update it
MonDKP:DKPHistory_Update(true)
-- reset loot history
MonDKP:LootHistory_Update(L["NOFILTER"])
-- update class graph
MonDKP:ClassGraph_Update()
-- update price table
MonDKP:PriceTable_Update(0)

end

-------------------------------------
-- Recursively searches tar (table) for val (string) as far as 4 nests deep (use field only if you wish to search a specific key IE: MonDKP:GetTable(MonDKP_DKPTable, true), "Roeshambo", "player" would only search for Roeshambo in the player key)
-- returns an indexed array of the keys to get to searched value
Expand Down
44 changes: 26 additions & 18 deletions Modules/ManageEntries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,10 @@ end

function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
for _ in pairs(T) do
count = count + 1
end
return count
end
function MonDKP:SetCurrentTeam(index)
MonDKP:GetTable(MonDKP_DB, false)["defaults"]["CurrentTeam"] = tostring(index)
end

function MonDKP:GetGuildTeamList()
Expand Down Expand Up @@ -306,6 +305,7 @@ end

function ChangeTeamName(index, _name)
MonDKP:GetTable(MonDKP_DB, false)["teams"][tostring(index)].name = _name;
MonDKP.Sync:SendData("MonDKPTeams", MonDKP:GetTable(MonDKP_DB, false)["teams"], "GUILD")
end

local function AddNewTeamToGuild()
Expand Down Expand Up @@ -335,6 +335,8 @@ local function AddNewTeamToGuild()
MonDKP:GetTable(MonDKP_MaxBids, false)[tostring(_index)] = {}
MonDKP:GetTable(MonDKP_Standby, false)[tostring(_index)] = {}
MonDKP:GetTable(MonDKP_Archive, false)[tostring(_index)] = {}

MonDKP.Sync:SendData("MonDKPTeams", MonDKP:GetTable(MonDKP_DB, false)["teams"], "GUILD")
end

-------
Expand Down Expand Up @@ -1047,12 +1049,16 @@ function MonDKP:ManageEntries()
StaticPopup_Show ("RENAME_TEAM")
else
ChangeTeamName(selectedTeamIndex, self:GetText())
self:SetText("")
-- if we are performing name change on currently selected team, change main team view dropdown Text
if tonumber(MonDKP:GetCurrentTeamIndex()) == selectedTeamIndex then
UIDropDownMenu_SetText(MonDKP.UIConfig.TeamViewChangerDropDown, self:SetText(""))
end
UIDropDownMenu_SetText(MonDKP.ConfigTab3.TeamListDropDown, L["TEAMSELECT"])
selectedTeam = nil
selectedTeamIndex = nil
CloseDropDownMenus()
self:ClearFocus()
self:SetText("")
end
end
)
Expand Down Expand Up @@ -1125,7 +1131,6 @@ function MonDKP:ManageEntries()
selectedTeam = nil
selectedTeamIndex = nil
CloseDropDownMenus()

else
StaticPopupDialogs["NOT_GUILD_MASTER"] = {
text = L["NOTGUILDMASTER"],
Expand Down Expand Up @@ -1195,17 +1200,20 @@ function MonDKP:ManageEntries()
end
);




-- TODO remove this later and uncomment check at the end
MonDKP.ConfigTab3.WhitelistContainer:Show()

-- only show whitelist and/or team management if player is a guild master
if CheckLeader == 1 then
MonDKP.ConfigTab3.WhitelistContainer:Show()
else
MonDKP.ConfigTab3.WhitelistContainer:Hide()
end

if CheckLeader == 1 then
MonDKP.ConfigTab3.WhitelistContainer:Show()
MonDKP.ConfigTab3.TeamHeader:Show()
MonDKP.ConfigTab3.TeamListDropDown:Show()
MonDKP.ConfigTab3.TeamNameInput:Show()
MonDKP.ConfigTab3.TeamRename:Show()
MonDKP.ConfigTab3.TeamAdd:Show()
else
MonDKP.ConfigTab3.WhitelistContainer:Hide()
MonDKP.ConfigTab3.TeamHeader:Hide()
MonDKP.ConfigTab3.TeamListDropDown:Hide()
MonDKP.ConfigTab3.TeamNameInput:Hide()
MonDKP.ConfigTab3.TeamRename:Hide()
MonDKP.ConfigTab3.TeamAdd:Hide()
end
end
31 changes: 18 additions & 13 deletions Modules/comm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function MonDKP.Sync:OnEnable()
MonDKP.Sync:RegisterComm("MonDKPAllTabs", MonDKP.Sync:OnCommReceived()) -- Full table broadcast
MonDKP.Sync:RegisterComm("MonDKPSetPrice", MonDKP.Sync:OnCommReceived()) -- Set Single Item Price
MonDKP.Sync:RegisterComm("MonDKPCurTeam", MonDKP.Sync:OnCommReceived()) -- Sets Current Raid Team
MonDKP.Sync:RegisterComm("MonDKPTeams", MonDKP.Sync:OnCommReceived())
--MonDKP.Sync:RegisterComm("MonDKPEditLoot", MonDKP.Sync:OnCommReceived()) -- not in use
--MonDKP.Sync:RegisterComm("MonDKPDataSync", MonDKP.Sync:OnCommReceived()) -- not in use
--MonDKP.Sync:RegisterComm("MonDKPDKPLogSync", MonDKP.Sync:OnCommReceived()) -- not in use
Expand Down Expand Up @@ -126,6 +127,8 @@ function MonDKP.Sync:OnCommReceived(prefix, message, distribution, sender)
else
return
end
elseif prefix == "MonDKPTeams" then
MonDKP:GetTable(MonDKP_DB, false)["teams"] = message;
elseif prefix == "MonDKPCurTeam" then
core.DB.defaults.CurrentTeam = message;
return
Expand Down Expand Up @@ -789,65 +792,67 @@ function MonDKP.Sync:SendData(prefix, data, target)
--if prefix ~= "MDKPProfile" then print("|cff00ff00Sent: "..prefix.."|r") end
if data == nil or data == "" then data = " " end -- just in case, to prevent disconnects due to empty/nil string AddonMessages

--AceComm Communication doesn't work if the prefix is longer than 15. And if sucks if you try.
if #prefix > 15 then
MonDKP:Print("MonolithDKP Error: Prefix ["..prefix.."] is longer than 15. Please shorten.");
return;
end
-- Communicate Current Officer's Sender CurrentTeam
if IsInGuild() and core.IsOfficer then
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", core.DB.defaults.CurrentTeam, "GUILD")
end
--AceComm Communication doesn't work if the prefix is longer than 15. And if sucks if you try.
if #prefix > 15 then
MonDKP:Print("MonolithDKP Error: Prefix ["..prefix.."] is longer than 15. Please shorten.");
return;
end

-- non officers / not encoded
if IsInGuild() then
if prefix == "MonDKPQuery" or prefix == "MonDKPBuild" or prefix == "MonDKPTalents" or prefix == "MonDKPRoles" then
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", core.DB.defaults.CurrentTeam, "GUILD")
MonDKP.Sync:SendCommMessage(prefix, data, "GUILD")
return;
elseif prefix == "MonDKPBidder" then -- bid submissions. Keep to raid.
MonDKP.Sync:SendCommMessage(prefix, data, "RAID")
return;
end
end

-- officers
if IsInGuild() and core.IsOfficer then
local serialized = nil;
local packet = nil;

if prefix == "MonDKPCommand" or prefix == "MonDKPRaidTime" then
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", MonDKP:GetCurrentTeamIndex(), "RAID")
MonDKP.Sync:SendCommMessage(prefix, data, "RAID")
return;
end

if prefix == "MonDKPBCastMsg" then
MonDKP.Sync:SendCommMessage(prefix, data, "GUILD")
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", MonDKP:GetCurrentTeamIndex(), "RAID")
MonDKP.Sync:SendCommMessage(prefix, data, "RAID") -- changed to raid from guild
return;
end

if data then
serialized = LibAceSerializer:Serialize(data); -- serializes tables to a string
end

local compressed = LibDeflate:CompressDeflate(serialized, {level = 9})
if compressed then
packet = LibDeflate:EncodeForWoWAddonChannel(compressed)
end

MonDKP.Sync:SendCommMessage("MonDKPCurTeam", core.DB.defaults.CurrentTeam, "GUILD")

-- encoded
if (prefix == "MonDKPZSumBank" or prefix == "MonDKPBossLoot" or prefix == "MonDKPBidShare") then -- Zero Sum bank/loot table/bid table data and bid submissions. Keep to raid.
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", MonDKP:GetCurrentTeamIndex(), "RAID")
MonDKP.Sync:SendCommMessage(prefix, packet, "RAID")
return;
end

if prefix == "MonDKPAllTabs" or prefix == "MonDKPMerge" then
if target then
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", MonDKP:GetCurrentTeamIndex(), "WHISPER", target, "NORMAL", nil, nil)
MonDKP.Sync:SendCommMessage(prefix, packet, "WHISPER", target, "NORMAL", MonDKP_BroadcastFull_Callback, nil)
else
MonDKP.Sync:SendCommMessage("MonDKPCurTeam", MonDKP:GetCurrentTeamIndex(), "GUILD")
MonDKP.Sync:SendCommMessage(prefix, packet, "GUILD", nil, "NORMAL", MonDKP_BroadcastFull_Callback, nil)
end
return
end

if target then
MonDKP.Sync:SendCommMessage(prefix, packet, "WHISPER", target)
else
Expand Down
41 changes: 12 additions & 29 deletions MonolithDKP.lua
Original file line number Diff line number Diff line change
Expand Up @@ -487,41 +487,24 @@ function MonDKP:CreateMenu()
-- Dropdown Menu on SetValue()
function MonDKP.UIConfig.TeamViewChangerDropDown:SetValue(arg1, arg2)

-- first we check if raid timer is active,
-- if yes -> block the change as this could award dkp to wrong team
if core.RaidInProgress == false and core.RaidInPause == false then
if tonumber(MonDKP:GetCurrentTeamIndex()) ~= arg2 then
if tonumber(MonDKP:GetCurrentTeamIndex()) ~= arg2 then
if core.RaidInProgress == false and core.RaidInPause == false then
MonDKP:SetCurrentTeam(arg2)
UIDropDownMenu_SetText(MonDKP.UIConfig.TeamViewChangerDropDown, arg1)

-- reset dkp table and update it
core.WorkingTable = MonDKP:GetTable(MonDKP_DKPTable, true);
core.PriceTable = MonDKP:GetTable(MonDKP_MinBids, true);
DKPTable_Update()

-- reset dkp history table and update it
MonDKP:DKPHistory_Update(true)
-- reset loot history
MonDKP:LootHistory_Update(L["NOFILTER"])
-- update class graph
MonDKP:ClassGraph_Update()
-- update price table
MonDKP:PriceTable_Update(0)
else
CloseDropDownMenus()
StaticPopupDialogs["RAID_IN_PROGRESS"] = {
text = L["TEAMCHANGERAIDINPROGRESS"],
button1 = L["OK"],
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopup_Show ("RAID_IN_PROGRESS")
end
else
StaticPopupDialogs["RAID_IN_PROGRESS"] = {
text = L["TEAMCHANGERAIDINPROGRESS"],
button1 = L["OK"],
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopup_Show ("RAID_IN_PROGRESS")
CloseDropDownMenus()
end
CloseDropDownMenus()
end

---------------------------------------
Expand Down

0 comments on commit 8f80adb

Please sign in to comment.