implement sorting for customs

This commit is contained in:
RandomityGuy 2023-10-08 01:50:32 +05:30
parent f303925551
commit c40243acaa
11 changed files with 49 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -32,7 +32,7 @@ class Marbleland {
for (missionData in claJson) {
// filter
if (missionData.compatibility != 'mbw' && missionData.compatibility != 'mbg')
if (missionData.datablockCompatibility != 'mbw' && missionData.datablockCompatibility != 'mbg')
continue;
if (!['gold', 'platinum', 'ultra', 'platinumquest'].contains(missionData.modification))
continue;
@ -61,6 +61,7 @@ class Marbleland {
mission.ultimateTime = missionData.ultimateTime != null ? missionData.ultimateTime / 1000 : 0;
mission.hasEgg = missionData.hasEgg;
mission.isClaMission = true;
mission.addedAt = missionData.addedAt;
var game = missionData.modification;

View file

@ -1,5 +1,6 @@
package src;
import haxe.Int64;
import src.Http.HttpRequest;
import gui.Canvas;
import gui.MessageBoxOkDlg;
@ -40,6 +41,7 @@ class Mission {
public var game:String;
public var hasEgg:Bool;
public var isCustom:Bool;
public var addedAt:Int64;
var next:Mission;

View file

@ -37,7 +37,7 @@ class PlayMissionGui extends GuiImage {
var setSelectedFunc:Int->Void;
var setScoreHover:Bool->Void;
var setCategoryFunc:(String, String, ?Bool) -> Void;
var setCategoryFunc:(String, String, ?String, ?Bool) -> Void;
var buttonHoldFunc:(dt:Float, mouseState:MouseState) -> Void;
var pmScoreButton:GuiButton;
@ -204,6 +204,27 @@ class PlayMissionGui extends GuiImage {
}
pmBox.addChild(pmSearch);
var sortType = 0; // 0 = alphabetical, 1 = date
var sortAlphaImgs = loadButtonImages("data/ui/play/sort_alpha");
var sortDateImgs = loadButtonImages("data/ui/play/sort_date");
var pmSort = new GuiButton(sortAlphaImgs);
pmSort.position = new Vector(366, 325);
pmSort.extent = new Vector(43, 43);
pmSort.pressedAction = (e) -> {
sortType = (sortType + 1) % 2;
if (sortType == 0) {
@:privateAccess pmSort.anim.frames = sortAlphaImgs;
}
if (sortType == 1) {
@:privateAccess pmSort.anim.frames = sortDateImgs;
}
setCategoryFunc(currentGame, currentCategoryStatic, sortType == 1 ? "date" : "alpha");
// MarbleGame.canvas.pushDialog(new SearchGui(currentGame, currentCategory == "custom"));
}
pmBox.addChild(pmSort);
var pmPrev = new GuiButton(loadButtonImages("data/ui/play/prev"));
pmPrev.position = new Vector(436, 325);
pmPrev.extent = new Vector(72, 43);
@ -605,7 +626,7 @@ class PlayMissionGui extends GuiImage {
MarbleGame.canvas.pushDialog(mbo);
} else {
currentCategory = "custom";
setCategoryFunc("gold", "custom");
setCategoryFunc("gold", "custom", sortType == 1 ? "date" : "alpha");
}
}
pmDifficultyCtrl.addChild(pmDifficultyGoldCustom);
@ -621,7 +642,7 @@ class PlayMissionGui extends GuiImage {
MarbleGame.canvas.pushDialog(mbo);
} else {
currentCategory = "custom";
setCategoryFunc("platinum", "custom");
setCategoryFunc("platinum", "custom", sortType == 1 ? "date" : "alpha");
}
}
pmDifficultyCtrl.addChild(pmDifficultyPlatinumCustom);
@ -637,7 +658,7 @@ class PlayMissionGui extends GuiImage {
MarbleGame.canvas.pushDialog(mbo);
} else {
currentCategory = "custom";
setCategoryFunc("ultra", "custom");
setCategoryFunc("ultra", "custom", sortType == 1 ? "date" : "alpha");
}
}
pmDifficultyCtrl.addChild(pmDifficultyUltraCustom);
@ -812,7 +833,7 @@ class PlayMissionGui extends GuiImage {
currentList = MissionList.missionList["platinum"]["beginner"];
setCategoryFunc = function(game:String, category:String, ?doRender:Bool = true) {
setCategoryFunc = function(game:String, category:String, ?sort:String = null, ?doRender:Bool = true) {
currentList = category == "custom" ? (switch (game) {
case 'gold' if (Marbleland.goldMissions.length != 0): Marbleland.goldMissions;
case 'platinum' if (Marbleland.platinumMissions.length != 0): Marbleland.platinumMissions;
@ -836,6 +857,24 @@ class PlayMissionGui extends GuiImage {
pmAchievements.disabled = true;
}
if (category == "custom") {
pmSort.anim.visible = true;
pmSort.disabled = false;
} else {
pmSort.anim.visible = false;
pmSort.disabled = true;
}
if (sort != null) {
currentList = currentList.copy(); // Don't modify the originals
if (sort == "alpha") {
currentList.sort((x, y) -> x.title > y.title ? 1 : (x.title < y.title ? -1 : 0));
}
if (sort == "date") {
currentList.sort((x, y) -> x.addedAt > y.addedAt ? 1 : (x.addedAt < y.addedAt ? -1 : 0));
}
}
currentCategoryStatic = currentCategory;
if (currentGame != game) {
@ -1044,7 +1083,7 @@ class PlayMissionGui extends GuiImage {
#end
}
setCategoryFunc(currentGame, currentCategoryStatic, false);
setCategoryFunc(currentGame, currentCategoryStatic, null, false);
#if js
var kofi = new GuiButton(loadButtonImages("data/ui/kofi1"));