Commit 8bc22a14 authored by Patrick Wuttke's avatar Patrick Wuttke

im- and export

parent 7140fa31
......@@ -57,12 +57,17 @@ function ReGroup.GetGroups()
return ReGroupPersistent.groups
end
function ReGroup.CreateGroup()
function ReGroup.NewGroup()
local groups = ReGroup.GetGroups()
local newGroup = {}
newGroup.name = "Unnamed group"
newGroup.members = {}
table.insert(groups, newGroup)
return newGroup
end
function ReGroup.CreateGroup()
local newGroup = ReGroup.NewGroup()
ReGroup.SelectGroup(newGroup)
ReGroup.StartRename()
end
......@@ -92,9 +97,14 @@ function ReGroup.AddMemberToGroup(group, name_, class, race)
role = "NONE"
}
table.insert(group.members, member)
ReGroup.NotifyMembersChanged()
ReGroup.UpdateFrame()
ReGroup.QueryMemberInfo(member)
if group == ReGroup.selectedGroup then
ReGroup.NotifyMembersChanged()
ReGroup.UpdateFrame()
ReGroup.QueryMemberInfo(member)
end
return member
end
function ReGroup.FindMemberInGroup(group, name)
......
......@@ -253,6 +253,64 @@ function ReGroup.ToggleMemberRole(index, role)
ReGroup.UpdateFrame()
end
----------------------------
-- group options dropdown --
----------------------------
function ReGroup.GroupOptionsDropDown_Initialize()
local info = UIDropDownMenu_CreateInfo();
info.notCheckable = true
if not ReGroup.selectedGroup then
info.disabled = true
end
info.text = "Rename"
info.func = function()
ReGroup.StartRename()
end
UIDropDownMenu_AddButton(info)
info.text = "Remove"
info.func = function()
ReGroup.StartRemove()
end
UIDropDownMenu_AddButton(info)
info.text = "Export ..."
info.func = function()
if not ReGroup.selectedGroup then return end
ReGroup_SerializeFrame_Text.EditBox:SetText(ReGroup.SerializeGroup(ReGroup.selectedGroup))
ReGroup_SerializeFrame:Show()
ReGroup_ImportMembersFrame_ButtonImport:Disable()
end
UIDropDownMenu_AddButton(info)
info.text = "Import ..."
info.disabled = false
info.func = function()
ReGroup_SerializeFrame_Text.EditBox:SetText("")
ReGroup_SerializeFrame:Show()
ReGroup_ImportMembersFrame_ButtonImport:Enable()
end
UIDropDownMenu_AddButton(info)
end
ReGroupGroupOptionsMixin = {}
function ReGroupGroupOptionsMixin:OnLoad()
SquareButton_SetIcon(self, "DOWN");
end
function ReGroupGroupOptionsMixin:OnMouseDown(button)
UIMenuButtonStretchMixin.OnMouseDown(self, button)
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
ToggleDropDownMenu(nil, nil, self.DropDown, self, 0, 0)
end
-------------------------------------------
-- various actions on the selected group --
-------------------------------------------
......
......@@ -6,8 +6,6 @@ function ReGroup.SelectGroup(group)
ReGroup.selectedGroup = group
if group then
UIDropDownMenu_SetText(ReGroupDropDownButton, group.name)
ReGroupButtonRename:Enable()
ReGroupButtonRemove:Enable()
for _, member in ipairs(group.members) do
if not member.hasCharacterInfo then
......@@ -16,8 +14,6 @@ function ReGroup.SelectGroup(group)
end
else
UIDropDownMenu_SetText(ReGroupDropDownButton, "Select group ...")
ReGroupButtonRename:Disable()
ReGroupButtonRemove:Disable()
end
ReGroup.ClearTable("selectedMembers")
......
......@@ -65,3 +65,88 @@ end
function ReGroup.IsGroupNameValid(name)
return ReGroup.TrimString(name) ~= ""
end
local lines = {}
function ReGroup.SerializeGroup(group)
table.wipe(lines)
table.insert(lines, "# This is your group in text form.")
table.insert(lines, "# It can be stored and used to restore the group using the \"import\" option of ReGroup.")
table.insert(lines, "")
table.insert(lines, "[Group]")
table.insert(lines, "Name=" .. group.name)
for i, member in ipairs(group.members) do
table.insert(lines, "")
table.insert(lines, "[Member." .. i .. "]")
table.insert(lines, "Name=" .. member.name)
table.insert(lines, "Class=" .. member.class)
table.insert(lines, "Race=" .. member.race)
table.insert(lines, "Role=" .. member.role)
end
return table.concat(lines, "\n")
end
local group
local section = ""
local line = ""
local key = ""
local value = ""
local activeMember
function ReGroup.DeserializeGroup_ParseLine()
if section == "Group" then
if key == "Name" then
group.name = value
else
print("Invalid key in Group section: " .. key)
end
elseif activeMember then
if key == "Name" then
activeMember.name = value
elseif key == "Class" then
activeMember.class = value
elseif key == "Race" then
activeMember.race = value
elseif key == "Role" then
activeMember.role = value
else
print("Invalid key in Member section: " .. key)
end
else
print("Invalid line: " .. line)
end
end
function ReGroup.DeserializeGroup(text)
group = ReGroup.NewGroup()
section = ""
for line_ in string.gmatch(text .. "\n", "([^#\n]*)[^\n]-\n") do
line = line_:match("^%s*(.-)%s*$") -- trim whitespace
if line ~= "" then
local v = line:match("^%[(.*)%]$")
if v then
section = v
if section:sub(1, 6) == "Member" then
activeMember = ReGroup.AddMemberToGroup(group, "NoName-NoRealm")
else
activeMember = nil
end
else
key, value = line:match("^([^=]*)=(.*)$")
if not key then
print("Invalid line: " .. line)
else
ReGroup.DeserializeGroup_ParseLine()
end
end
end
end
print("Successfully imported group.")
ReGroup.SelectGroup(group)
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment