Skip to content

Commit 8d909de

Browse files
committed
Initial Spectre Library UI Update
1 parent ad6b2e5 commit 8d909de

File tree

3 files changed

+201
-21
lines changed

3 files changed

+201
-21
lines changed

src/Classes/MinionSearchListControl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local MinionSearchListClass = newClass("MinionSearchListControl", "MinionListCon
1313
self.unfilteredList = copyTable(list)
1414
self.isMutable = false
1515

16-
self.controls.searchText = new("EditControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, -2, 128, 18}, "", "Search", "%c", 100, function(buf)
16+
self.controls.searchText = new("EditControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, -2, 148, 18}, "", "Search", "%c", 100, function(buf)
1717
self:ListFilterChanged(buf, self.controls.searchModeDropDown.selIndex)
1818
end, nil, nil, true)
1919

src/Classes/Tooltip.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,6 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
241241
end
242242
DrawImage(nil, ttX, ttY, ttW * columns, BORDER_WIDTH) -- top border
243243
DrawImage(nil, ttX, ttY + maxColumnHeight - BORDER_WIDTH, ttW * columns, BORDER_WIDTH) -- bottom border
244-
244+
SetDrawColor(1, 1, 1) -- Reset draw color to white as it messes with Spectre Library
245245
return ttW, ttH
246246
end

src/Modules/Build.lua

Lines changed: 199 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,25 +1346,147 @@ function buildMode:OpenSpectreLibrary(library)
13461346
else
13471347
destList = copyTable(self.spectreList)
13481348
end
1349+
local monsterTypeSort = {
1350+
Beast = true,
1351+
Humanoid = true,
1352+
Eldritch = true,
1353+
Construct = true,
1354+
Demon = true,
1355+
Undead = true
1356+
}
1357+
local beastList = { }
1358+
local humanoidList = { }
1359+
local eldritchList = { }
1360+
local constructList = { }
1361+
local demonList = { }
1362+
local undeadList = { }
13491363
local sourceList = { }
13501364
for id in pairs(self.data.spectres) do
1351-
if library == "beast" and self.data.minions[id].monsterCategory == "Beast" then
1352-
t_insert(sourceList, id)
1353-
elseif library ~= "beast" then
1354-
t_insert(sourceList, id)
1365+
if self.data.minions[id].monsterCategory == "Beast" then
1366+
t_insert(beastList, id)
1367+
elseif self.data.minions[id].monsterCategory == "Humanoid" then
1368+
t_insert(humanoidList, id)
1369+
elseif self.data.minions[id].monsterCategory == "Eldritch" then
1370+
t_insert(eldritchList, id)
1371+
elseif self.data.minions[id].monsterCategory == "Construct" then
1372+
t_insert(constructList, id)
1373+
elseif self.data.minions[id].monsterCategory == "Demon" then
1374+
t_insert(demonList, id)
1375+
elseif self.data.minions[id].monsterCategory == "Undead" then
1376+
t_insert(undeadList, id)
13551377
end
13561378
end
1357-
table.sort(sourceList, function(a,b)
1358-
if self.data.minions[a].name == self.data.minions[b].name then
1359-
return a < b
1379+
1380+
local function buildSourceList(library, sourceList)
1381+
wipeTable(sourceList)
1382+
if library == "beast" then
1383+
if monsterTypeSort["Beast"] then
1384+
for _, id in ipairs(beastList) do
1385+
table.insert(sourceList, id)
1386+
end
1387+
end
13601388
else
1361-
return self.data.minions[a].name < self.data.minions[b].name
1389+
local monsterCategories = {
1390+
{ key = "Beast", list = beastList },
1391+
{ key = "Humanoid", list = humanoidList },
1392+
{ key = "Eldritch", list = eldritchList },
1393+
{ key = "Construct", list = constructList },
1394+
{ key = "Demon", list = demonList },
1395+
{ key = "Undead", list = undeadList },
1396+
}
1397+
for _, category in ipairs(monsterCategories) do
1398+
if monsterTypeSort[category.key] then
1399+
for _, id in ipairs(category.list) do
1400+
table.insert(sourceList, id)
1401+
end
1402+
end
1403+
end
1404+
end
13621405
end
1363-
end)
1406+
buildSourceList(library, sourceList)
13641407
local controls = { }
1365-
controls.list = new("MinionListControl", nil, {-100, 40, 190, 250}, self.data, destList)
1366-
controls.source = new("MinionSearchListControl", nil, {100, 60, 190, 230}, self.data, sourceList, controls.list)
1367-
controls.save = new("ButtonControl", nil, {-45, 330, 80, 20}, "Save", function()
1408+
1409+
local function sortSourceList()
1410+
local sortFields = {
1411+
[1] = { field = "name", asc = true },
1412+
[2] = { field = "life", asc = false },
1413+
[3] = { field = "energyShield", asc = false },
1414+
[4] = { field = "attackTime", asc = true },
1415+
[5] = { field = "companionReservation", asc = true },
1416+
[6] = { field = "spectreReservation", asc = true },
1417+
[7] = { field = "fireResist", asc = false },
1418+
[8] = { field = "coldResist", asc = false },
1419+
[9] = { field = "lightningResist", asc = false },
1420+
[10] = { field = "totalResist", asc = false },
1421+
}
1422+
local sortModeIndex = controls.sortModeDropDown and controls.sortModeDropDown.selIndex or 1
1423+
local sortOption = sortFields[sortModeIndex]
1424+
if sortOption then
1425+
table.sort(sourceList, function(a, b)
1426+
local minionA = self.data.minions[a]
1427+
local minionB = self.data.minions[b]
1428+
local valueA = minionA[sortOption.field]
1429+
local valueB = minionB[sortOption.field]
1430+
if sortOption.field == "energyShield" then
1431+
-- Calculate actual ES value
1432+
local totalLifeA = 2490 * minionA.life
1433+
local totalLifeB = 2490 * minionB.life
1434+
local esA = (minionA.energyShield or 0) * totalLifeA
1435+
local esB = (minionB.energyShield or 0) * totalLifeB
1436+
-- If both are 0 (no ES), sort by name
1437+
if esA == 0 and esB == 0 then
1438+
return minionA.name < minionB.name
1439+
end
1440+
valueA = esA
1441+
valueB = esB
1442+
end
1443+
if sortOption.field == "totalResist" then -- currently all minions have one resist, but may have more in future.
1444+
valueA = minionA.fireResist + minionA.coldResist + minionA.lightningResist + minionA.chaosResist
1445+
valueB = minionB.fireResist + minionB.coldResist + minionB.lightningResist + minionB.chaosResist
1446+
end
1447+
-- If values are equal, sort by name
1448+
if valueA == valueB then
1449+
return minionA.name < minionB.name
1450+
else
1451+
if sortOption.asc then
1452+
return valueA < valueB
1453+
else
1454+
return valueA > valueB
1455+
end
1456+
end
1457+
end)
1458+
end
1459+
end
1460+
1461+
sortSourceList()
1462+
controls.list = new("MinionListControl", nil, {-230, 40, 210, 250}, self.data, destList)
1463+
controls.source = new("MinionSearchListControl", nil, {0, 60, 210, 230}, self.data, sourceList, controls.list)
1464+
local function monsterTypeCheckboxChange(name)
1465+
monsterTypeSort[name] = true
1466+
return function(state)
1467+
monsterTypeSort[name] = state
1468+
self.listBuildFlag = true
1469+
buildSourceList(library, sourceList)
1470+
sortSourceList()
1471+
end
1472+
end
1473+
controls.sortMonsterCheckboxBeast = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {0, 24, 26, 26}, "", monsterTypeCheckboxChange("Beast"), "Beast", true)
1474+
controls.sortMonsterCheckboxBeast.shown = library ~= "beast"
1475+
controls.sortMonsterCheckboxHumanoid = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {37, 24, 26, 26}, "", monsterTypeCheckboxChange("Humanoid"), "Humanoid", true)
1476+
controls.sortMonsterCheckboxHumanoid.shown = library ~= "beast"
1477+
controls.sortMonsterCheckboxEldritch = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {74, 24, 26, 26}, "", monsterTypeCheckboxChange("Eldritch"), "Eldritch", true)
1478+
controls.sortMonsterCheckboxEldritch.shown = library ~= "beast"
1479+
controls.sortMonsterCheckboxConstruct = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {111, 24, 26, 26}, "", monsterTypeCheckboxChange("Construct"), "Construct", true)
1480+
controls.sortMonsterCheckboxConstruct.shown = library ~= "beast"
1481+
controls.sortMonsterCheckboxDemon = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {148, 24, 26, 26}, "", monsterTypeCheckboxChange("Demon"), "Demon", true)
1482+
controls.sortMonsterCheckboxDemon.shown = library ~= "beast"
1483+
controls.sortMonsterCheckboxUndead = new("CheckBoxControl", {"TOPLEFT", controls.source, "BOTTOMLEFT"}, {185, 24, 26, 26}, "", monsterTypeCheckboxChange("Undead"), "Undead", true)
1484+
controls.sortMonsterCheckboxUndead.shown = library ~= "beast"
1485+
controls.sortLabel = new("LabelControl", {"TOPLEFT",controls.source,"BOTTOMLEFT"}, {2, 2, 0, 16}, "Sort by:")
1486+
controls.sortModeDropDown = new("DropDownControl", {"TOPRIGHT",controls.source,"BOTTOMRIGHT"}, {0, 2, 155, 18}, { "Names", "Life", "Energy Shield", "Attack Speed", "Companion Reservation", "Spectre Reservation", "Fire Resistance", "Cold Resistance", "Lightning Resistance", "Total Resistance"}, function(index, value)
1487+
sortSourceList()
1488+
end)
1489+
controls.save = new("ButtonControl", nil, {-45, 390, 80, 20}, "Save", function()
13681490
if library == "beast" then
13691491
self.beastList = destList
13701492
else
@@ -1374,20 +1496,78 @@ function buildMode:OpenSpectreLibrary(library)
13741496
self.buildFlag = true
13751497
main:ClosePopup()
13761498
end)
1377-
controls.cancel = new("ButtonControl", nil, {45, 330, 80, 20}, "Cancel", function()
1499+
controls.cancel = new("ButtonControl", nil, {45, 390, 80, 20}, "Cancel", function()
13781500
main:ClosePopup()
13791501
end)
13801502
local spectrePopup
13811503
if library == "beast" then
1382-
spectrePopup = main:OpenPopup(410, 360, "Beast Library", controls)
1383-
controls.noteLine1 = new("LabelControl", {"TOPLEFT",controls.list,"BOTTOMLEFT"}, {24, 2, 0, 16}, "Beasts in your Library must be assigned to an active")
1384-
controls.noteLine2 = new("LabelControl", {"TOPLEFT",controls.list,"BOTTOMLEFT"}, {20, 18, 0, 16}, "Companion gem for their buffs and curses to activate")
1504+
spectrePopup = main:OpenPopup(720, 430, "Beast Library", controls)
1505+
controls.noteLine1 = new("LabelControl", {"TOP",controls.save,"BOTTOM"}, {45, -60, 0, 16}, "Beasts in your Library must be assigned to an active")
1506+
controls.noteLine2 = new("LabelControl", {"TOP",controls.save,"BOTTOM"}, {45, -42, 0, 16}, "Companion gem for their buffs and curses to activate")
13851507
else
1386-
spectrePopup = main:OpenPopup(410, 360, "Spectre Library", controls)
1387-
controls.noteLine1 = new("LabelControl", {"TOPLEFT",controls.list,"BOTTOMLEFT"}, {24, 2, 0, 16}, "Spectres in your Library must be assigned to an active")
1388-
controls.noteLine2 = new("LabelControl", {"TOPLEFT",controls.list,"BOTTOMLEFT"}, {20, 18, 0, 16}, "Raise Spectre gem for their buffs and curses to activate")
1508+
spectrePopup = main:OpenPopup(720, 430, "Spectre Library", controls)
1509+
controls.noteLine1 = new("LabelControl", {"TOP",controls.save,"BOTTOM"}, {45, -60, 0, 16}, "Spectres in your Library must be assigned to an active")
1510+
controls.noteLine2 = new("LabelControl", {"TOP",controls.save,"BOTTOM"}, {45, -42, 0, 16}, "Raise Spectre gem for their buffs and curses to activate")
13891511
end
13901512
spectrePopup:SelectControl(spectrePopup.controls.source.controls.searchText)
1513+
1514+
controls.minionNameLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {130, -25, 0, 18}, "Minion Stats")
1515+
controls.minionGemLevelLabel = new("LabelControl", {"BOTTOM", controls.minionNameLabel, "TOP"}, {-40, -10, 0, 16}, "Gem Level:")
1516+
controls.minionGemLevel = new("EditControl", {"LEFT", controls.minionGemLevelLabel, "RIGHT"}, {4, 0, 60, 20}, "20", nil, "%D", 3, function()
1517+
controls.source.OnSelect()
1518+
end)
1519+
controls.lifeLabel = new("LabelControl", {"TOP", controls.source, "TOPRIGHT"}, {60, 4, 0, 16}, colorCodes.LIFE.."LIFE")
1520+
controls.energyshieldLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {190, 4, 0, 16}, colorCodes.ES.."ENERGY SHIELD")
1521+
controls.armourLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {60, 42, 0, 16}, colorCodes.ARMOUR.."ARMOUR")
1522+
controls.evasionLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {190, 42, 0, 16}, colorCodes.EVASION.."EVASION")
1523+
controls.blockLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {60, 80, 0, 16}, colorCodes.NORMAL.."BLOCK")
1524+
controls.resistsLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {190, 80, 0, 16}, "RESISTS")
1525+
1526+
-- Run this code whenever a new minion is selected in the list
1527+
controls.source.OnSelect = function()
1528+
local selected = controls.source.selValue
1529+
local minion = self.data.minions[selected]
1530+
-- Get the gem level from the control, default to 20 if not set
1531+
local gemLevel = controls.minionGemLevel.buf
1532+
local baseLife = self.data.monsterAllyLifeTable[m_min(gemLevel * 2, 100)]
1533+
local totalLife = baseLife * minion.life
1534+
local totalES
1535+
if minion.energyShield then
1536+
totalES = totalLife * minion.energyShield
1537+
totalLife = totalLife - (totalLife * minion.energyShield)
1538+
else
1539+
totalES = 0
1540+
end
1541+
local totalArmour = self.data.monsterArmourTable[m_min(gemLevel * 2, 100)]
1542+
local totalEvasion = self.data.monsterEvasionTable[m_min(gemLevel * 2, 100)]
1543+
if minion.armour then
1544+
totalArmour = (1 + minion.armour) * totalArmour
1545+
end
1546+
if minion.evasion then
1547+
totalEvasion = (1 + minion.evasion) * totalEvasion
1548+
end
1549+
-- Check if minion.modList contains a mod for BlockChance and use it for blockLabel
1550+
local blockChance = 0
1551+
if minion.modList then
1552+
for _, mod in ipairs(minion.modList) do
1553+
if mod.name == "BlockChance" then
1554+
blockChance = mod.value
1555+
break
1556+
end
1557+
end
1558+
end
1559+
controls.minionNameLabel = new("LabelControl", {"TOP",controls.source,"TOPRIGHT"}, {130, -25, 0, 18}, minion.name)
1560+
controls.lifeLabelNum = new("LabelControl", {"TOP",controls.lifeLabel,"BOTTOM"}, {0, 2, 0, 16}, colorCodes.LIFE..round(totalLife))
1561+
controls.energyshieldLabelNum = new("LabelControl", {"TOP",controls.energyshieldLabel,"BOTTOM"}, {0, 2, 0, 16}, colorCodes.ES..round(totalES))
1562+
controls.blockLabelNum = new("LabelControl", {"TOP",controls.blockLabel,"BOTTOM"}, {4, 2, 0, 16}, blockChance.."%")
1563+
controls.armourLabelNum = new("LabelControl", {"TOP",controls.armourLabel,"BOTTOM"}, {0, 2, 0, 16}, colorCodes.ARMOUR..round(totalArmour))
1564+
controls.evasionLabelNum = new("LabelControl", {"TOP",controls.evasionLabel,"BOTTOM"}, {0, 2, 0, 16}, colorCodes.EVASION..round(totalEvasion))
1565+
controls.resistsLabelNum = new("LabelControl", {"TOP",controls.resistsLabel,"BOTTOM"}, {0, 2, 0, 16},
1566+
colorCodes.FIRE..minion.fireResist.."^7/"..
1567+
colorCodes.COLD..minion.coldResist.."^7/"..
1568+
colorCodes.LIGHTNING..minion.lightningResist.."^7/"..
1569+
colorCodes.CHAOS..minion.chaosResist..colorCodes.NORMAL)
1570+
end
13911571
end
13921572

13931573
function buildMode:OpenSimilarPopup()

0 commit comments

Comments
 (0)