@@ -1346,25 +1346,147 @@ function buildMode:OpenSpectreLibrary(library)
1346
1346
else
1347
1347
destList = copyTable (self .spectreList )
1348
1348
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 = { }
1349
1363
local sourceList = { }
1350
1364
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 )
1355
1377
end
1356
1378
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
1360
1388
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
1362
1405
end
1363
- end )
1406
+ buildSourceList ( library , sourceList )
1364
1407
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 ()
1368
1490
if library == " beast" then
1369
1491
self .beastList = destList
1370
1492
else
@@ -1374,20 +1496,78 @@ function buildMode:OpenSpectreLibrary(library)
1374
1496
self .buildFlag = true
1375
1497
main :ClosePopup ()
1376
1498
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 ()
1378
1500
main :ClosePopup ()
1379
1501
end )
1380
1502
local spectrePopup
1381
1503
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" )
1385
1507
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" )
1389
1511
end
1390
1512
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
1391
1571
end
1392
1572
1393
1573
function buildMode :OpenSimilarPopup ()
0 commit comments