Skip to content

Commit d629287

Browse files
committed
Set the league combo to the last used if possible, used for previously imported characters
1 parent 92f13a5 commit d629287

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

src/Classes/ImportTab.lua

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ end)
336336
function ImportTabClass:Load(xml, fileName)
337337
self.lastRealm = xml.attrib.lastRealm
338338
self.controls.accountRealm:SelByValue( self.lastRealm or main.lastRealm or "PC", "id" )
339+
self.lastLeague = xml.attrib.lastLeague
340+
self.controls.charSelectLeague:SelByValue( self.lastLeague or "Standard", "id" )
339341
self.lastAccountHash = xml.attrib.lastAccountHash
340342
if self.lastAccountHash then
341343
for accountName in pairs(main.gameAccounts) do
@@ -350,6 +352,7 @@ end
350352
function ImportTabClass:Save(xml)
351353
xml.attrib = {
352354
lastRealm = self.lastRealm,
355+
lastLeague = self.lastLeague,
353356
lastAccountHash = self.lastAccountHash,
354357
lastCharacterHash = self.lastCharacterHash,
355358
}
@@ -369,6 +372,23 @@ function ImportTabClass:Draw(viewPort, inputEvents)
369372
end
370373

371374
function ImportTabClass:DownloadCharacterList()
375+
function FindMatchingStandardLeague(league)
376+
-- Find a Standard league name for a given league name
377+
-- Reference https://api.pathofexile.com/league?realm=pc
378+
if string.find(league, "Hardcore") then
379+
return "Hardcore"
380+
elseif string.find(league, "HC SSF") then
381+
-- includes Ruthless "HC SSF R "
382+
return "SSF Hardcore"
383+
elseif string.find(league, "SSF") then
384+
-- Any non HardCore SSF's - includes Ruthless "SSF R "
385+
return "SSF Standard"
386+
else
387+
-- normal league and ruthless league (Sanctum, Ruthless Sanctum)
388+
return "Standard"
389+
end
390+
end
391+
372392
self.charImportMode = "DOWNLOADCHARLIST"
373393
self.charImportStatus = "Retrieving character list..."
374394
-- Trim Trailing/Leading spaces
@@ -436,6 +456,7 @@ function ImportTabClass:DownloadCharacterList()
436456
end
437457
end
438458
table.sort(leagueList)
459+
charSelectLeague = self.controls.charSelectLeague
439460
wipeTable(self.controls.charSelectLeague.list)
440461
for _, league in ipairs(leagueList) do
441462
t_insert(self.controls.charSelectLeague.list, {
@@ -446,11 +467,28 @@ function ImportTabClass:DownloadCharacterList()
446467
t_insert(self.controls.charSelectLeague.list, {
447468
label = "All",
448469
})
449-
if self.controls.charSelectLeague.selIndex > #self.controls.charSelectLeague.list then
450-
self.controls.charSelectLeague.selIndex = 1
470+
-- set the league combo to the last used if possible, used for previously imported characters
471+
if self.lastLeague then
472+
charSelectLeague:SelByValue( self.lastLeague, "league" )
473+
-- check that it worked
474+
if charSelectLeague:GetSelValue("league") ~= self.lastLeague then
475+
-- League maybe over, Character will be in standard
476+
standardLeagueName = FindMatchingStandardLeague(self.lastLeague)
477+
self.controls.charSelectLeague:SelByValue( standardLeagueName, "league" )
478+
if charSelectLeague:GetSelValue("league") ~= standardLeagueName then
479+
-- give up and select the first entry. Ruthless mode may not have Standard equivalents
480+
charSelectLeague.selIndex = 1
481+
else
482+
self.lastLeague = standardLeagueName
483+
end
484+
end
485+
else
486+
if self.controls.charSelectLeague.selIndex > #self.controls.charSelectLeague.list then
487+
self.controls.charSelectLeague.selIndex = 1
488+
end
451489
end
452490
self.lastCharList = charList
453-
self:BuildCharacterList(self.controls.charSelectLeague:GetSelValue("league"))
491+
self:BuildCharacterList(charSelectLeague:GetSelValue("league"))
454492

455493
-- We only get here if the accountname was correct, found, and not private, so add it to the account history.
456494
self:SaveAccountHistory()
@@ -512,6 +550,9 @@ function ImportTabClass:DownloadPassiveTree()
512550
return
513551
end
514552
self.lastCharacterHash = common.sha1(charData.name)
553+
if not self.lastLeague then
554+
self.lastLeague = charSelectLeague:GetSelValue("league")
555+
end
515556
self:ImportPassiveTreeAndJewels(response.body, charData)
516557
end, sessionID and { header = "Cookie: POESESSID=" .. sessionID })
517558
end
@@ -534,6 +575,9 @@ function ImportTabClass:DownloadItems()
534575
return
535576
end
536577
self.lastCharacterHash = common.sha1(charData.name)
578+
if not self.lastLeague then
579+
self.lastLeague = charSelectLeague:GetSelValue("league")
580+
end
537581
self:ImportItemsAndSkills(response.body)
538582
end, sessionID and { header = "Cookie: POESESSID=" .. sessionID })
539583
end
@@ -582,6 +626,9 @@ function ImportTabClass:ImportPassiveTreeAndJewels(json, charData)
582626
self.build.itemsTab:AddUndoState()
583627
self.build.spec:ImportFromNodeList(charData.classId, charData.ascendancyClass, charPassiveData.hashes, charPassiveData.mastery_effects or {})
584628
self.build.spec:AddUndoState()
629+
if not self.lastLeague then
630+
self.lastLeague = charSelectLeague:GetSelValue("league")
631+
end
585632
self.build.characterLevel = charData.level
586633
self.build.controls.characterLevel:SetText(charData.level)
587634
self.build.buildFlag = true

0 commit comments

Comments
 (0)