mirror of
https://github.com/OldManAlpha/Puppeteer.git
synced 2025-11-28 23:48:35 +00:00
Make it clear if you've made bindings changes
This commit is contained in:
parent
a7f35eb4cd
commit
c7be283367
@ -5,6 +5,7 @@ local util = PTUtil
|
||||
local colorize = util.Colorize
|
||||
local GetSpellID = util.GetSpellID
|
||||
local GetClass = util.GetClass
|
||||
local CompostReclaim = util.CompostReclaim
|
||||
|
||||
BindingClipboard = nil
|
||||
|
||||
@ -84,6 +85,27 @@ function GetBindingLoadoutNames()
|
||||
return names
|
||||
end
|
||||
|
||||
-- Returns a pruned copy of the loadout using composted tables
|
||||
function PruneLoadoutCompost(loadout)
|
||||
loadout = util.CloneTableCompost(loadout, true)
|
||||
for targetName, target in pairs(loadout.Bindings) do
|
||||
for modifierName, modifier in pairs(target) do
|
||||
for button, binding in pairs(modifier) do
|
||||
local shouldRemove = PruneBinding(binding, true)
|
||||
if shouldRemove then
|
||||
CompostReclaim(binding)
|
||||
modifier[button] = nil
|
||||
end
|
||||
end
|
||||
if util.IsTableEmpty(modifier) then
|
||||
CompostReclaim(modifier)
|
||||
target[modifierName] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
return loadout
|
||||
end
|
||||
|
||||
function PruneLoadout(loadout, copy)
|
||||
if copy then
|
||||
loadout = util.CloneTable(loadout, true)
|
||||
@ -104,8 +126,8 @@ function PruneLoadout(loadout, copy)
|
||||
return loadout
|
||||
end
|
||||
|
||||
function PruneBinding(binding)
|
||||
if not binding.Type then
|
||||
function PruneBinding(binding, useCompost)
|
||||
if not binding.Type or not binding.Data then
|
||||
return true
|
||||
end
|
||||
if binding.Tooltip then
|
||||
@ -116,6 +138,9 @@ function PruneBinding(binding)
|
||||
end
|
||||
|
||||
if util.IsTableEmpty(tooltip) then
|
||||
if useCompost then
|
||||
CompostReclaim(binding.Tooltip)
|
||||
end
|
||||
binding.Tooltip = nil
|
||||
end
|
||||
end
|
||||
@ -150,8 +175,48 @@ function ExpandBinding(binding)
|
||||
end
|
||||
end
|
||||
|
||||
function LoadoutEquals(loadout1, loadout2, noCopy)
|
||||
return util.TableEquals(PruneLoadout(loadout1, not noCopy), PruneLoadout(loadout2, not noCopy))
|
||||
function LoadoutEquals(loadout1, loadout2)
|
||||
loadout1 = PruneLoadoutCompost(loadout1)
|
||||
loadout2 = PruneLoadoutCompost(loadout2)
|
||||
local equals = util.TableEquals(loadout1, loadout2)
|
||||
CompostReclaim(loadout1)
|
||||
CompostReclaim(loadout2)
|
||||
return equals
|
||||
end
|
||||
|
||||
function GetNumLoadoutChanges(origLoadout, modifiedLoadout)
|
||||
origLoadout = PruneLoadoutCompost(origLoadout)
|
||||
modifiedLoadout = PruneLoadoutCompost(modifiedLoadout)
|
||||
local numChanges = 0
|
||||
local alreadyChecked = compost:GetTable()
|
||||
for targetName, target in pairs(modifiedLoadout.Bindings) do
|
||||
for modifierName, modifier in pairs(target) do
|
||||
for button, binding in pairs(modifier) do
|
||||
local otherBinding = util.TraverseTable(origLoadout.Bindings, targetName, modifierName, button)
|
||||
if otherBinding == nil or not util.TableEquals(binding, otherBinding) then
|
||||
numChanges = numChanges + 1
|
||||
alreadyChecked[binding] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for targetName, target in pairs(origLoadout.Bindings) do
|
||||
for modifierName, modifier in pairs(target) do
|
||||
for button, binding in pairs(modifier) do
|
||||
local otherBinding = util.TraverseTable(modifiedLoadout.Bindings, targetName, modifierName, button)
|
||||
if not alreadyChecked[otherBinding] and (otherBinding == nil or not util.TableEquals(binding, otherBinding)) then
|
||||
numChanges = numChanges + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if origLoadout.UseFriendlyForHostile ~= modifiedLoadout.UseFriendlyForHostile then
|
||||
numChanges = numChanges + 1
|
||||
end
|
||||
CompostReclaim(origLoadout)
|
||||
CompostReclaim(modifiedLoadout)
|
||||
compost:Reclaim(alreadyChecked)
|
||||
return numChanges
|
||||
end
|
||||
|
||||
-- Returns a copy of the clipboard
|
||||
|
||||
@ -225,6 +225,7 @@ function CreateTab_Bindings()
|
||||
EditedBindings.UseFriendlyForHostile = self:GetChecked() == 1
|
||||
SetTargetContext("Friendly")
|
||||
UpdateBindingsInterface()
|
||||
UpdateUnsavedChanges()
|
||||
end)
|
||||
UniversalBindingsCheckbox = universalBindingsCheckbox
|
||||
|
||||
@ -253,11 +254,36 @@ function CreateTab_Bindings()
|
||||
|
||||
SpellBindInterface = interface
|
||||
|
||||
LoadBindings()
|
||||
UnsavedChangesText = PTGuiLib.GetText(container, "", 12)
|
||||
:SetPoint("TOP", interface, "BOTTOM", 0, -3)
|
||||
--:SetTextColor(1, 0.2, 0.2)
|
||||
|
||||
|
||||
DiscardButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT", 10, 35)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Discard Changes")
|
||||
:OnClick(function()
|
||||
LoadBindings()
|
||||
end)
|
||||
SaveAndCloseButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOM", container, "BOTTOM", 0, 35)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Save & Close")
|
||||
:OnClick(function()
|
||||
SaveBindings()
|
||||
TabFrame:Hide()
|
||||
end)
|
||||
SaveButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOMRIGHT", container, "BOTTOMRIGHT", -10, 35)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Save Changes")
|
||||
:OnClick(function()
|
||||
SaveBindings()
|
||||
end)
|
||||
|
||||
local addButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("TOP", container, "TOP", 0, -440)
|
||||
:SetPoint("TOP", container, "TOP", 0, -445)
|
||||
:SetSize(200, 25)
|
||||
:SetText("Add or Remove Buttons")
|
||||
:ApplyTooltip("Edit what buttons you can bind spells to")
|
||||
@ -267,28 +293,7 @@ function CreateTab_Bindings()
|
||||
AddOverlayFrame(editor)
|
||||
end)
|
||||
|
||||
local discardButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT", 10, 50)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Discard Changes")
|
||||
:OnClick(function()
|
||||
LoadBindings()
|
||||
end)
|
||||
local saveAndCloseButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOM", container, "BOTTOM", 0, 50)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Save & Close")
|
||||
:OnClick(function()
|
||||
SaveBindings()
|
||||
TabFrame:Hide()
|
||||
end)
|
||||
local saveButton = PTGuiLib.Get("button", container)
|
||||
:SetPoint("BOTTOMRIGHT", container, "BOTTOMRIGHT", -10, 50)
|
||||
:SetSize(125, 25)
|
||||
:SetText("Save Changes")
|
||||
:OnClick(function()
|
||||
SaveBindings()
|
||||
end)
|
||||
LoadBindings()
|
||||
end
|
||||
|
||||
function PromptNewLoadout()
|
||||
@ -354,6 +359,7 @@ function LoadBindings()
|
||||
end
|
||||
BindingsForDropdown:UpdateText()
|
||||
UpdateBindingsInterface()
|
||||
UpdateUnsavedChanges()
|
||||
end
|
||||
|
||||
function SaveBindings()
|
||||
@ -361,6 +367,26 @@ function SaveBindings()
|
||||
LoadBindings()
|
||||
end
|
||||
|
||||
function UpdateUnsavedChanges()
|
||||
local ok, changes = pcall(Puppeteer.GetNumLoadoutChanges, Puppeteer.GetBindings(), EditedBindings)
|
||||
if not ok then
|
||||
Puppeteer.print(changes)
|
||||
changes = "ERROR"
|
||||
end
|
||||
if changes == 0 then
|
||||
UnsavedChangesText:Hide()
|
||||
DiscardButton:SetEnabled(false)
|
||||
SaveAndCloseButton:SetEnabled(false)
|
||||
SaveButton:SetEnabled(false)
|
||||
else
|
||||
UnsavedChangesText:Show()
|
||||
UnsavedChangesText:SetText("You have "..changes.." unsaved change"..(changes ~= 1 and "s" or "").." to your bindings")
|
||||
DiscardButton:SetEnabled(true)
|
||||
SaveAndCloseButton:SetEnabled(true)
|
||||
SaveButton:SetEnabled(true)
|
||||
end
|
||||
end
|
||||
|
||||
function CreateTab_Options()
|
||||
local container = TabFrame:CreateTab("Options")
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ function PTBindingOptions:New()
|
||||
end
|
||||
local func = function(self)
|
||||
obj.Binding.Tooltip.Type = self.type
|
||||
obj.Binding.Tooltip.Data = nil
|
||||
obj:UpdateTooltipType()
|
||||
end
|
||||
tooltipTypeDropdown:SetOptions({
|
||||
|
||||
@ -97,8 +97,6 @@ function PTBindingScriptEditor:New()
|
||||
"unitData:HasBuff(buffName) -- Returns true if the unit has buffName",
|
||||
"unitData:HasDebuff(debuffName) -- Returns true if the unit has debuffName",
|
||||
"unitData:HasDebuffType(typeName) -- Returns true if the unit has the debuff type(such as \"Magic\")",
|
||||
"unitData:GetDistance() -- Returns the distance between you and the unit(SuperWoW/UnitXP SP3 required)",
|
||||
"unitData:IsInSight() -- Returns true if the unit is in your sight(UnitXP SP3 required)",
|
||||
"unitData:GetAuraTimeRemaining(auraName) -- Returns the time remaining on an aura, or nil if unknown(SuperWoW required)")
|
||||
local local4 = PTGuiLib.GetText(frame, "local unitFrame")
|
||||
:SetTextColor(0.4, 1, 0.4)
|
||||
|
||||
@ -116,6 +116,7 @@ function PTSpellLine:New()
|
||||
PTSettingsGui.AddOverlayFrame(editor)
|
||||
editor:SetDisposeHandler(function()
|
||||
PTSettingsGui.PopOverlayFrame()
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
obj:Update()
|
||||
end)
|
||||
end)
|
||||
@ -209,6 +210,7 @@ function PTSpellLine:SetBindType(bindType)
|
||||
self:GetTypeDropdown():SetText(bindType)
|
||||
util.ClearTable(self.Binding)
|
||||
self.Binding.Type = bindType
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
self:Update()
|
||||
return self
|
||||
end
|
||||
@ -246,6 +248,7 @@ function PTSpellLine:ApplySearchableEditbox(bindType, searchFunc, searchAtLength
|
||||
return
|
||||
end
|
||||
binding.Data = self:GetContentEditbox():GetText()
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
if not binding.Type then
|
||||
binding.Type = bindType
|
||||
end
|
||||
@ -263,6 +266,7 @@ function PTSpellLine:ApplySearchableEditbox(bindType, searchFunc, searchAtLength
|
||||
notCheckable = true,
|
||||
func = function(option)
|
||||
binding.Data = option.text
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
self:Update()
|
||||
end
|
||||
}
|
||||
@ -287,6 +291,7 @@ function PTSpellLine:ApplySearchableEditbox(bindType, searchFunc, searchAtLength
|
||||
local searchResults = searchFunc(binding.Data)
|
||||
if table.getn(searchResults) > 0 then
|
||||
editbox:SetText(searchResults[1])
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
end
|
||||
end)
|
||||
end
|
||||
@ -317,6 +322,7 @@ function PTSpellLine:Update()
|
||||
func = function(self, gui)
|
||||
binding.Data = self.text
|
||||
gui:SetText(self.text)
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
end
|
||||
})
|
||||
elseif binding.Type == "MACRO" then
|
||||
@ -375,6 +381,7 @@ function PTSpellLine:Update()
|
||||
:SetCallback(function(save, scriptData, nameData)
|
||||
if save then
|
||||
binding.Data = scriptData
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
end
|
||||
editor:Dispose()
|
||||
|
||||
@ -407,6 +414,7 @@ function PTSpellLine:Update()
|
||||
PTSettingsGui.AddOverlayFrame(editor)
|
||||
editor:SetDisposeHandler(function()
|
||||
PTSettingsGui.PopOverlayFrame()
|
||||
PTSettingsGui.UpdateUnsavedChanges()
|
||||
self:Update()
|
||||
end)
|
||||
end, true)
|
||||
|
||||
@ -154,6 +154,14 @@ function IndexOf(table, value)
|
||||
return -1
|
||||
end
|
||||
|
||||
function KeyOf(table, value)
|
||||
for k, v in pairs(table) do
|
||||
if v == value then
|
||||
return k
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ArrayContains(table, value)
|
||||
for _, v in ipairs(table) do
|
||||
if v == value then
|
||||
@ -186,6 +194,17 @@ function CloneTable(table, deep)
|
||||
end
|
||||
|
||||
local compost = AceLibrary("Compost-2.0")
|
||||
|
||||
-- Recursively reclaims all tables this table contains
|
||||
function CompostReclaim(t)
|
||||
for k, v in pairs(t) do
|
||||
if type(v) == "table" then
|
||||
CompostReclaim(v)
|
||||
end
|
||||
end
|
||||
compost:Reclaim(t)
|
||||
end
|
||||
|
||||
function CloneTableCompost(t, deep)
|
||||
local clone = compost:GetTable()
|
||||
local n = 0
|
||||
@ -251,6 +270,18 @@ function TableEquals(t1, t2)
|
||||
return true
|
||||
end
|
||||
|
||||
function TraverseTable(v, k1, k2, k3, k4, k5)
|
||||
local keys = compost:Acquire(k1, k2, k3, k4, k5)
|
||||
for _, k in ipairs(keys) do
|
||||
if type(v) ~= "table" then
|
||||
return nil, k
|
||||
end
|
||||
v = v[k]
|
||||
end
|
||||
compost:Reclaim(keys)
|
||||
return v
|
||||
end
|
||||
|
||||
-- Courtesy of ChatGPT
|
||||
function SplitString(str, delimiter)
|
||||
local result = {}
|
||||
@ -1201,7 +1232,7 @@ function CanClientSightCheck()
|
||||
end
|
||||
|
||||
function CanClientGetAuraIDs()
|
||||
return SuperWoW or TurtleWow
|
||||
return SuperWoW-- or TurtleWow -- Turtle ID fetching is not reliable
|
||||
end
|
||||
|
||||
function IsSuperWowPresent()
|
||||
|
||||
@ -5,7 +5,7 @@ local compost = AceLibrary("Compost-2.0")
|
||||
Translations = nil
|
||||
|
||||
-- Set to true to enable the ability to dump all things that need translations
|
||||
local EXPORT_MODE = true
|
||||
local EXPORT_MODE = false
|
||||
|
||||
function SetTranslations(translations)
|
||||
Translations = translations
|
||||
|
||||
Loading…
Reference in New Issue
Block a user