Skip to content

Commit faead82

Browse files
committed
The Save button is now disabled if there are no changes
1 parent 99a1f35 commit faead82

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

core/ManagerApi.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ function GlobalAPI:UpdateCustomLoadoutWithImportString(loadoutID, importText)
228228
return result and self:GetLoadoutInfoByID(loadoutID) or false, (not result and errorOrLevelingOrder or nil);
229229
end
230230

231+
--- Returns a serialized string of talent selections from an import string
232+
--- Can be useful to compare import strings to see if they contain the same build
233+
--- IMPORTANT: the returned string format is not guaranteed to be stable, and may change at any time in the future
234+
--- @param importText string - the import string (icy-veins calculator URLs are also supported)
235+
--- @return string|false - false on failure, serializedSelectedNodes on success
236+
function GlobalAPI:SerializeLoadoutString(importText)
237+
return TLM:BuildSerializedSelectedNodesFromImportString(importText);
238+
end
239+
231240
-------------------------------------------------------------------------
232241
---
233242
--- character specific functions

modules/DefaultUISidebar.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ function Module:GetDefaultActionText(elementData)
5757
or "Load";
5858
end
5959

60+
function Module:GetExportString()
61+
return C_Traits.GenerateImportString(C_ClassTalents.GetActiveConfigID());
62+
end
63+
6064
function Module:UpdateCustomLoadoutWithCurrentTalents(loadoutID)
6165
-- todo: add warning if the loadout has leveling information, as that'll get lost
6266
CharacterAPI:UpdateCustomLoadoutWithCurrentTalents(loadoutID);

modules/SideBarMixin.lua

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ function SideBarMixin:SetupHook()
211211
if not self.importDialog then
212212
self.importDialog = self:CreateImportDialog();
213213
end
214-
self:SecureHookScript(self:GetTalentsTab(), "OnShow", "OnTalentsTabShow");
214+
local talentsTab = self:GetTalentsTab();
215+
self:SecureHookScript(talentsTab, "OnShow", "OnTalentsTabShow");
216+
self:SecureHook(talentsTab, "OnUpdate", "OnTalentsChanged");
215217

216218
API:RegisterCallback(API.Event.LoadoutListUpdated, self.RefreshSideBarData, self);
217219
end
@@ -232,6 +234,7 @@ do
232234
error('override in implementation');
233235
end
234236

237+
--- @return TalentLoadoutManagerAPI_LoadoutInfo|nil - selected loadout's info, if any
235238
function SideBarMixin:GetActiveLoadout(forceRefresh)
236239
error('override in implementation');
237240
end
@@ -249,6 +252,10 @@ do
249252
error('override in implementation');
250253
end
251254

255+
function SideBarMixin:GetExportString()
256+
error('override in implementation');
257+
end
258+
252259
function SideBarMixin:UpdateCustomLoadoutWithCurrentTalents(loadoutID)
253260
error('override in implementation');
254261
end
@@ -263,6 +270,41 @@ do
263270
end
264271
end
265272

273+
function SideBarMixin:OnTalentsChanged()
274+
if self.talentChangePending then return; end
275+
self.talentChangePending = true
276+
RunNextFrame(function()
277+
self.talentChangePending = false
278+
279+
self:SaveButtonUpdateEnableState();
280+
end);
281+
end
282+
283+
function SideBarMixin:SaveButtonUpdateEnableState()
284+
local activeLoadout = self:GetActiveLoadout();
285+
local identicalTalents = false;
286+
if activeLoadout then
287+
local savedExportString = GlobalAPI:GetExportString(activeLoadout.id);
288+
local currentExportString = self:GetExportString();
289+
290+
if savedExportString == currentExportString then
291+
identicalTalents = true;
292+
elseif savedExportString and currentExportString and savedExportString ~= "" and currentExportString ~= "" then
293+
local serializedSavedExportString = GlobalAPI:SerializeLoadoutString(savedExportString);
294+
local serializedCurrentExportString = GlobalAPI:SerializeLoadoutString(currentExportString);
295+
296+
identicalTalents = serializedSavedExportString == serializedCurrentExportString;
297+
end
298+
end
299+
300+
self.SideBar.SaveButton:SetEnabled(
301+
activeLoadout
302+
and not activeLoadout.isBlizzardLoadout
303+
and not activeLoadout.isLocked
304+
and not identicalTalents
305+
);
306+
end
307+
266308
function SideBarMixin:OnTalentsTabShow(frame)
267309
self:UpdateScaleForFit(frame:GetParent());
268310
self:UpdatePosition(frame:GetParent());
@@ -565,6 +607,7 @@ function SideBarMixin:CreateSideBar()
565607
if not activeLoadout or not activeLoadout.id then return; end
566608

567609
self:UpdateCustomLoadoutWithCurrentTalents(activeLoadout.id);
610+
self:SaveButtonUpdateEnableState();
568611
end);
569612
sideBar.SaveButton.tooltipText = "Save the current talents into the currently selected loadout";
570613

@@ -839,7 +882,7 @@ function SideBarMixin:SetElementAsActive(frame, loadoutInfo)
839882
previouslyActiveLoadoutFrame:ApplyColors();
840883
end
841884
frame:ApplyColors();
842-
self.SideBar.SaveButton:SetEnabled(self.activeLoadout and not self.activeLoadout.isBlizzardLoadout and not self.activeLoadout.isLocked);
885+
self:SaveButtonUpdateEnableState();
843886
end
844887

845888
--- @param frame TLM_ElementFrame
@@ -1036,7 +1079,7 @@ function SideBarMixin:RefreshSideBarData()
10361079
self.DataProvider = CreateDataProvider(dataProviderEntries);
10371080
self.SideBar.ScrollBoxContainer.ScrollBox:SetDataProvider(self.DataProvider);
10381081

1039-
self.SideBar.SaveButton:SetEnabled(self.activeLoadout and not self.activeLoadout.isBlizzardLoadout and not self.activeLoadout.isLocked);
1082+
self:SaveButtonUpdateEnableState();
10401083
end
10411084

10421085
function SideBarMixin:ShowConfigDialog()

modules/TalentTreeViewerSidebar.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local GlobalAPI = TalentLoadoutManagerAPI.GlobalAPI;
1010
local Module = TLM:NewModule("TTVSideBar", "AceHook-3.0");
1111
TLM.TTVSideBarModule = Module;
1212

13+
--- @type TLM_SideBarMixin
1314
local parentMixin = ns.SideBarMixin;
1415
Mixin(Module, parentMixin);
1516

@@ -46,6 +47,10 @@ function Module:GetDefaultActionText(elementData)
4647
return "Load";
4748
end
4849

50+
function Module:GetExportString()
51+
return self:GetTalentTreeViewer():ExportLoadout();
52+
end
53+
4954
function Module:UpdateCustomLoadoutWithCurrentTalents(loadoutID)
5055
local importString = self:GetTalentTreeViewer():ExportLoadout();
5156
-- todo: check if importString contains lvling info, if it doesn't, and current loadout does, show warning

0 commit comments

Comments
 (0)