working level select and play

This commit is contained in:
RandomityGuy 2023-06-25 23:48:23 +05:30
parent 13dd1dc5fa
commit 0c30f05745
19 changed files with 210 additions and 144 deletions

BIN
data/ui/game/CloudBG.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

View file

@ -1,5 +1,6 @@
package src;
import gui.LevelSelectGui;
import gui.MainMenuGui;
#if !js
import gui.ReplayCenterGui;
@ -263,25 +264,26 @@ class MarbleGame {
public function quitMission() {
Console.log("Quitting mission");
var watching = world.isWatching;
var missionType = world.mission.type;
var isNotCustom = !world.mission.isClaMission && !world.mission.isCustom;
world.setCursorLock(false);
world.dispose();
world = null;
paused = false;
if (world.isWatching) {
if (watching) {
#if !js
canvas.setContent(new ReplayCenterGui());
#else
canvas.setContent(new MainMenuGui());
#end
} else {
if (!world.mission.isClaMission && !world.mission.isCustom) {
PlayMissionGui.currentCategoryStatic = world.mission.type;
if (isNotCustom) {
PlayMissionGui.currentCategoryStatic = missionType;
}
var pmg = new PlayMissionGui();
PlayMissionGui.currentSelectionStatic = world.mission.index;
PlayMissionGui.currentGameStatic = world.mission.game;
var pmg = new LevelSelectGui(LevelSelectGui.currentDifficultyStatic);
canvas.setContent(pmg);
}
world.dispose();
world = null;
Settings.save();
}

View file

@ -1079,13 +1079,11 @@ class MarbleWorld extends Scheduler {
func(() -> {
lock = false;
this._resourcesLoaded++;
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
});
#end
#if js
func(() -> {
lock = false;
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
this._resourcesLoaded++;
});
#end

View file

@ -66,6 +66,8 @@ class PreviewWorld extends Scheduler {
var sky:Sky;
var itrAddTime:Float = 0;
public function new(scene:Scene) {
this.scene = scene;
}
@ -183,8 +185,15 @@ class PreviewWorld extends Scheduler {
var worker = new ResourceLoaderWorker(onFinish);
worker.addTask(fwd -> addScenery(difficulty, fwd));
itrAddTime = 0;
for (elem in itrpaths) {
worker.addTask(fwd -> addInteriorFromMis(cast elem, fwd));
worker.addTask(fwd -> {
var startTime = Sys.time();
addInteriorFromMis(cast elem, () -> {
itrAddTime += Sys.time() - startTime;
fwd();
});
});
}
for (elem in shapeDbs) {
worker.addTask(fwd -> addStaticShape(cast elem, fwd));
@ -192,6 +201,7 @@ class PreviewWorld extends Scheduler {
worker.addTask(fwd -> {
timeState.timeSinceLoad = 0;
timeState.dt = 0;
Console.log('ITR ADD TIME: ' + itrAddTime);
fwd();
});
worker.run();
@ -238,6 +248,7 @@ class PreviewWorld extends Scheduler {
}
public function destroyAllObjects() {
currentMission = null;
for (itr in interiors) {
itr.dispose();
}

View file

@ -27,6 +27,8 @@ class Sky extends Object {
var imageResources:Array<Resource<Image>> = [];
static var cubemapTextureCache:Map<String, Texture> = [];
public function new() {
super();
}
@ -111,6 +113,10 @@ class Sky extends Object {
var noSkyTexture = element.useskytextures == "0";
var worker = new ResourceLoaderWorker(() -> {
var cubemaptexture:Texture = null;
if (cubemapTextureCache.exists(dmlPath))
cubemaptexture = cubemapTextureCache.get(dmlPath);
else {
var fnames = [];
for (i in 0...6) {
var line = StringTools.trim(lines[i]);
@ -170,10 +176,12 @@ class Sky extends Object {
} else
Util.flipImage(skyboxImages[3], true, false);
var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]);
cubemaptexture = new Texture(maxheight, maxwidth, [Cube]);
for (i in 0...6) {
cubemaptexture.uploadPixels(skyboxImages[skyboxIndices[i]], 0, i);
}
cubemapTextureCache.set(dmlPath, cubemaptexture);
}
onFinish(cubemaptexture);
});

View file

@ -76,6 +76,9 @@ class ExitGameDlg extends GuiImage {
btnList.addButton(3, "Help & Options", (evt) -> {}, 20);
btnList.addButton(2, "Leaderboards", (evt) -> {});
btnList.addButton(2, "Achievements", (evt) -> {});
btnList.addButton(4, "Main Menu", (evt) -> yesFunc(btnList));
btnList.addButton(4, "Main Menu", (evt) -> {
yesFunc(btnList);
MarbleGame.canvas.setContent(new MainMenuGui());
});
}
}

19
src/gui/GuiLoadAnim.hx Normal file
View file

@ -0,0 +1,19 @@
package gui;
import src.ResourceLoader;
class GuiLoadAnim extends GuiAnim {
public function new() {
var img = ResourceLoader.getImage("data/ui/xbox/loadingAnimation.png").resource.toTile();
var f1 = img.sub(0, 1, 63, 63);
var f2 = img.sub(64, 1, 63, 63);
var f3 = img.sub(0, 65, 63, 63);
var f4 = img.sub(64, 65, 63, 63);
var f5 = img.sub(0, 129, 63, 63);
var f6 = img.sub(64, 129, 63, 63);
var f7 = img.sub(0, 193, 63, 63);
super([f1, f2, f3, f4, f5, f6, f7]);
this.anim.loop = true;
this.anim.speed = 20;
}
}

View file

@ -170,4 +170,9 @@ class GuiXboxOptionsList extends GuiControl {
}
super.update(dt, mouseState);
}
public function setCurrentOption(opt:Int) {
currentOption = opt;
optionText.text.text = options[currentOption];
}
}

View file

@ -16,9 +16,50 @@ class LevelSelectGui extends GuiImage {
static var currentDifficultyStatic:String = "beginner";
public function new(difficulty:String) {
var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile();
var res = ResourceLoader.getImage("data/ui/game/CloudBG.jpg").resource.toTile();
super(res);
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
var arial14b = new BitmapFont(arial14fontdata.entry);
@:privateAccess arial14b.loader = ResourceLoader.loader;
var arial14 = arial14b.toSdfFont(cast 21 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel);
function mlFontLoader(text:String) {
return arial14;
}
var fadeEdge = new GuiImage(ResourceLoader.getResource("data/ui/xbox/BG_fadeOutSoftEdge.png", ResourceLoader.getImage, this.imageResources).toTile());
fadeEdge.position = new Vector(0, 0);
fadeEdge.extent = new Vector(640, 480);
fadeEdge.vertSizing = Height;
fadeEdge.horizSizing = Width;
this.addChild(fadeEdge);
var loadAnim = new GuiLoadAnim();
loadAnim.position = new Vector(610, 253);
loadAnim.extent = new Vector(63, 63);
loadAnim.horizSizing = Center;
loadAnim.vertSizing = Bottom;
this.addChild(loadAnim);
var loadTextBg = new GuiText(arial14);
loadTextBg.position = new Vector(608, 335);
loadTextBg.extent = new Vector(63, 40);
loadTextBg.horizSizing = Center;
loadTextBg.vertSizing = Bottom;
loadTextBg.justify = Center;
loadTextBg.text.text = "Loading";
loadTextBg.text.textColor = 0;
this.addChild(loadTextBg);
var loadText = new GuiText(arial14);
loadText.position = new Vector(610, 334);
loadText.extent = new Vector(63, 40);
loadText.horizSizing = Center;
loadText.vertSizing = Bottom;
loadText.justify = Center;
loadText.text.text = "Loading";
this.addChild(loadText);
if (currentDifficultyStatic != difficulty) {
currentSelectionStatic = 0;
}
@ -32,6 +73,10 @@ class LevelSelectGui extends GuiImage {
var misFile = Path.withoutExtension(Path.withoutDirectory(curMission.path));
MarbleGame.instance.setPreviewMission(misFile, () -> {
lock = false;
this.bmp.visible = false;
loadAnim.anim.visible = false;
loadText.text.visible = false;
loadTextBg.text.visible = false;
});
var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
@ -114,14 +159,6 @@ class LevelSelectGui extends GuiImage {
statIcon.extent = new Vector(20, 20);
levelWnd.addChild(statIcon);
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
var arial14b = new BitmapFont(arial14fontdata.entry);
@:privateAccess arial14b.loader = ResourceLoader.loader;
var arial14 = arial14b.toSdfFont(cast 21 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel);
function mlFontLoader(text:String) {
return arial14;
}
var c0 = 0xEBEBEB;
var c1 = 0x8DFF8D;
var c2 = 0x88BCEE;
@ -151,12 +188,21 @@ class LevelSelectGui extends GuiImage {
function setLevel(idx:Int) {
if (lock)
return false;
this.bmp.visible = true;
loadAnim.anim.visible = true;
loadText.text.visible = true;
loadTextBg.text.visible = true;
lock = true;
curMission = difficultyMissions[idx];
currentSelectionStatic = idx;
var misFile = Path.withoutExtension(Path.withoutDirectory(curMission.path));
var mis = difficultyMissions[idx];
MarbleGame.instance.setPreviewMission(misFile, () -> {
lock = false;
this.bmp.visible = false;
loadAnim.anim.visible = false;
loadText.text.visible = false;
loadTextBg.text.visible = false;
});
var myScore = Settings.getScores(mis.path);
var scoreDisp = "None";
@ -180,6 +226,7 @@ class LevelSelectGui extends GuiImage {
levelSelectOpts.horizSizing = Right;
levelSelectOpts.alwaysActive = true;
levelSelectOpts.onChangeFunc = setLevel;
levelSelectOpts.setCurrentOption(currentSelectionStatic);
innerCtrl.addChild(levelSelectOpts);
}
}

View file

@ -8,77 +8,50 @@ import src.Settings;
import src.Util;
class LoadingGui extends GuiImage {
public var setProgress:Float->Void;
public function new(missionName:String, game:String) {
function chooseBg() {
if (game == "gold")
return ResourceLoader.getImage('data/ui/backgrounds/gold/${cast (Math.floor(Util.lerp(1, 12, Math.random())), Int)}.jpg');
if (game == "platinum")
return ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg');
if (game == "ultra")
return ResourceLoader.getImage('data/ui/backgrounds/ultra/${cast (Math.floor(Util.lerp(1, 9, Math.random())), Int)}.jpg');
return ResourceLoader.getImage('data/ui/backgrounds/platinum/${cast (Math.floor(Util.lerp(1, 28, Math.random())), Int)}.jpg');
}
var img = chooseBg();
super(img.resource.toTile());
var res = ResourceLoader.getImage("data/ui/game/CloudBG.jpg").resource.toTile();
super(res);
this.position = new Vector();
this.extent = new Vector(640, 480);
this.horizSizing = Width;
this.vertSizing = Height;
this.extent = new Vector(640, 480);
this.position = new Vector();
var loadingGui = new GuiImage(ResourceLoader.getResource("data/ui/loading/loadinggui.png", ResourceLoader.getImage, this.imageResources).toTile());
loadingGui.horizSizing = Center;
loadingGui.vertSizing = Center;
loadingGui.position = new Vector(86, 77);
loadingGui.extent = new Vector(468, 325);
var fadeEdge = new GuiImage(ResourceLoader.getResource("data/ui/xbox/BG_fadeOutSoftEdge.png", ResourceLoader.getImage, this.imageResources).toTile());
fadeEdge.position = new Vector(0, 0);
fadeEdge.extent = new Vector(640, 480);
fadeEdge.vertSizing = Height;
fadeEdge.horizSizing = Width;
this.addChild(fadeEdge);
function loadButtonImages(path:String) {
var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile();
var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile();
var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile();
return [normal, hover, pressed];
}
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
var arial14b = new BitmapFont(arial14fontdata.entry);
@:privateAccess arial14b.loader = ResourceLoader.loader;
var arial14 = arial14b.toSdfFont(cast 21 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel);
var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
var domcasual32b = new BitmapFont(domcasual32fontdata.entry);
@:privateAccess domcasual32b.loader = ResourceLoader.loader;
var domcasual32 = domcasual32b.toSdfFont(cast 26 * Settings.uiScale, MultiChannel);
var loadAnim = new GuiLoadAnim();
loadAnim.position = new Vector(610, 253);
loadAnim.extent = new Vector(63, 63);
loadAnim.horizSizing = Center;
loadAnim.vertSizing = Bottom;
this.addChild(loadAnim);
var mapName = new GuiText(domcasual32);
mapName.position = new Vector(6, 33);
mapName.extent = new Vector(456, 14);
mapName.text.text = missionName;
mapName.text.textColor = 0;
mapName.justify = Center;
var loadTextBg = new GuiText(arial14);
loadTextBg.position = new Vector(608, 335);
loadTextBg.extent = new Vector(63, 40);
loadTextBg.horizSizing = Center;
loadTextBg.vertSizing = Bottom;
loadTextBg.justify = Center;
loadTextBg.text.text = "Loading";
loadTextBg.text.textColor = 0;
this.addChild(loadTextBg);
var progress = new GuiProgress();
progress.vertSizing = Top;
progress.position = new Vector(194, 145);
progress.extent = new Vector(225, 56);
progress.progress = 0.5;
setProgress = (progressPz) -> {
progress.progress = progressPz;
}
var cancelButton = new GuiButton(loadButtonImages("data/ui/loading/cancel"));
cancelButton.position = new Vector(333, 243);
cancelButton.extent = new Vector(112, 59);
cancelButton.pressedAction = (sender) -> {
MarbleGame.instance.quitMission();
}
var overlay = new GuiImage(ResourceLoader.getResource("data/ui/loading/overlay.png", ResourceLoader.getImage, this.imageResources).toTile());
overlay.position = new Vector(188, 139);
overlay.extent = new Vector(242, 75);
loadingGui.addChild(mapName);
loadingGui.addChild(progress);
loadingGui.addChild(cancelButton);
loadingGui.addChild(overlay);
this.addChild(loadingGui);
var loadText = new GuiText(arial14);
loadText.position = new Vector(610, 334);
loadText.extent = new Vector(63, 40);
loadText.horizSizing = Center;
loadText.vertSizing = Bottom;
loadText.justify = Center;
loadText.text.text = "Loading";
this.addChild(loadText);
}
}