end game finish

This commit is contained in:
RandomityGuy 2023-06-22 23:03:58 +05:30
parent bd940b0f8c
commit 0bf31fb68c
4 changed files with 225 additions and 322 deletions

View file

@ -1398,7 +1398,7 @@ class MarbleWorld extends Scheduler {
this.finishPitch = this.marble.camera.CameraPitch;
displayAlert("Congratulations! You've finished!");
if (!this.isWatching)
this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen());
this.schedule(this.timeState.currentAttemptTime + 5, () -> cast showFinishScreen());
// Stop the ongoing sounds
if (timeTravelSound != null) {
timeTravelSound.stop();
@ -1410,6 +1410,7 @@ class MarbleWorld extends Scheduler {
function showFinishScreen() {
if (this.isWatching)
return 0;
playGui.setGuiVisibility(false);
Console.log("State End");
var egg:EndGameGui = null;
#if js

View file

@ -1,5 +1,6 @@
package gui;
import mis.MisParser;
import hxd.BitmapData;
import h2d.Tile;
import src.MarbleGame;
@ -13,13 +14,14 @@ import src.ResourceLoader;
import src.TimeState;
import src.Util;
class EndGameGui extends GuiControl {
class EndGameGui extends GuiImage {
var mission:Mission;
var scoreSubmitted:Bool = false;
public function new(continueFunc:GuiControl->Void, restartFunc:GuiControl->Void, nextLevelFunc:GuiControl->Void, mission:Mission, timeState:TimeState) {
super();
var res = ResourceLoader.getImage("data/ui/xbox/BG_fadeOutSoftEdge.png").resource.toTile();
super(res);
this.horizSizing = Width;
this.vertSizing = Height;
this.position = new Vector(0, 0);
@ -38,8 +40,8 @@ class EndGameGui extends GuiControl {
var offsetX = (scene2d.width - 1280) / 2;
var offsetY = (scene2d.height - 720) / 2;
var subX = 640 - (scene2d.width - offsetX * 2) * 640 / scene2d.width;
var subY = 480 - (scene2d.height - offsetY * 2) * 480 / scene2d.height;
var subX = 640 - (scene2d.width - offsetX) * 640 / scene2d.width;
var subY = 480 - (scene2d.height - offsetY) * 480 / scene2d.height;
var innerCtrl = new GuiControl();
innerCtrl.position = new Vector(offsetX, offsetY);
@ -48,16 +50,26 @@ class EndGameGui extends GuiControl {
innerCtrl.vertSizing = Height;
this.addChild(innerCtrl);
var coliseumfontdata = ResourceLoader.getFileEntry("data/font/ColiseumRR.fnt");
var coliseumb = new BitmapFont(coliseumfontdata.entry);
@:privateAccess coliseumb.loader = ResourceLoader.loader;
var coliseum = coliseumb.toSdfFont(cast 44 * Settings.uiScale, MultiChannel);
var rootTitle = new GuiText(coliseum);
rootTitle.position = new Vector(100, 30);
rootTitle.extent = new Vector(1120, 80);
rootTitle.text.textColor = 0xFFFFFF;
rootTitle.text.text = "LEVEL COMPLETE!";
rootTitle.text.alpha = 0.5;
innerCtrl.addChild(rootTitle);
var endGameWnd = new GuiImage(ResourceLoader.getResource("data/ui/xbox/endGameWindow.png", ResourceLoader.getImage, this.imageResources).toTile());
endGameWnd.horizSizing = Left;
endGameWnd.vertSizing = Top;
endGameWnd.position = new Vector(80 - offsetX / 2, 170);
endGameWnd.position = new Vector(80 - offsetX, 170 - offsetY);
endGameWnd.extent = new Vector(336, 150);
innerCtrl.addChild(endGameWnd);
var subX = 640 - (scene2d.width - offsetX * 2) * 640 / scene2d.width;
var subY = 480 - (scene2d.height - offsetY * 2) * 480 / scene2d.height;
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
var arial14b = new BitmapFont(arial14fontdata.entry);
@:privateAccess arial14b.loader = ResourceLoader.loader;
@ -72,16 +84,37 @@ class EndGameGui extends GuiControl {
return arial14;
}
var beatPar = timeState.gameplayClock < mission.qualifyTime;
var egResultLeft = new GuiMLText(arial14, mlFontLoader);
egResultLeft.position = new Vector(28, 26);
egResultLeft.extent = new Vector(180, 100);
egResultLeft.text.text = '<p align="right"><font color="#8DFF8D">Time:</font><br/><font color="#88BCEE">Par Time:</font><br/><font color="#EBEBEB">Rating:</font><br/><font color="#EBEBEB">My Best Time:</font></p>';
egResultLeft.text.text = '<p align="right"><font color="${beatPar ? "#8DFF8D" : "0xFF7575"}">Time:</font><br/><font color="#88BCEE">Par Time:</font><br/><font color="#EBEBEB">Rating:</font><br/><font color="#EBEBEB">My Best Time:</font></p>';
endGameWnd.addChild(egResultLeft);
var c0 = 0xEBEBEB;
var c1 = 0x8DFF8D;
var c2 = 0x88BCEE;
var c3 = 0xFF7575;
function calcRating(time:Float, parTime:Float, goldTime:Float, difficulty:Int):Int {
var t = time - (time % 10);
if (t == 0)
return 0;
var completionBonus = 1000;
var timeBonus = 0;
if (t < parTime)
timeBonus = Math.floor(parTime / t) * 1000;
else
timeBonus = Math.floor(parTime / t) * 500;
return (completionBonus + timeBonus) * difficulty;
}
var rating = calcRating(timeState.gameplayClock * 1000, mission.qualifyTime * 1000, mission.goldTime * 1000,
Std.parseInt(mission.missionInfo.difficulty));
var myScore = {name: "Player", time: timeState.gameplayClock};
Settings.saveScore(mission.path, myScore);
var scoreData:Array<Score> = Settings.getScores(mission.path);
while (scoreData.length < 1) {
scoreData.push({name: "Nardo Polo", time: 5999.999});
@ -90,324 +123,38 @@ class EndGameGui extends GuiControl {
var bestScore = scoreData[0];
var egResultRight = new GuiMLText(arial14, mlFontLoader);
egResultRight.position = new Vector(214, 26);
egResultRight.extent = new Vector(180, 100);
egResultRight.text.text = '<font color="#8DFF8D">${Util.formatTime(timeState.gameplayClock)}</font><br/><font color="#88BCEE">${Util.formatTime(mission.qualifyTime)}</font><br/><font color="#EBEBEB">0</font><br/><font color="#EBEBEB">${Util.formatTime(bestScore.time)}</font>';
egResultRight.text.text = '<font color="${beatPar ? "#8DFF8D" : "0xFF7575"}">${Util.formatTime(timeState.gameplayClock)}</font><br/><font color="#88BCEE">${Util.formatTime(mission.qualifyTime)}</font><br/><font color="#EBEBEB">${rating}</font><br/><font color="#EBEBEB">${Util.formatTime(bestScore.time)}</font>';
endGameWnd.addChild(egResultRight);
// var pg = new GuiImage(ResourceLoader.getResource("data/ui/endgame/base.png", ResourceLoader.getImage, this.imageResources).toTile());
// pg.horizSizing = Center;
// pg.vertSizing = Center;
// pg.position = new Vector(28, 20);
// pg.extent = new Vector(584, 440);
var bottomBar = new GuiControl();
bottomBar.position = new Vector(0, innerCtrl.extent.x * 590 / 480);
bottomBar.extent = new Vector(640, 200);
bottomBar.horizSizing = Width;
bottomBar.vertSizing = Bottom;
this.addChild(bottomBar);
// var continueButton = new GuiButton(loadButtonImages("data/ui/endgame/continue"));
// continueButton.horizSizing = Right;
// continueButton.vertSizing = Bottom;
// continueButton.position = new Vector(460, 307);
// continueButton.extent = new Vector(104, 54);
// continueButton.accelerator = hxd.Key.ENTER;
// continueButton.gamepadAccelerator = ["A"];
// continueButton.pressedAction = (e) -> continueFunc(continueButton);
var retryButton = new GuiXboxButton("Retry", 160);
retryButton.position = new Vector(-240, 0);
retryButton.vertSizing = Bottom;
retryButton.horizSizing = Left;
retryButton.gamepadAccelerator = ["B"];
retryButton.pressedAction = (e) -> restartFunc(retryButton);
bottomBar.addChild(retryButton);
// var restartButton = new GuiButton(loadButtonImages("data/ui/endgame/replay"));
// restartButton.horizSizing = Right;
// restartButton.vertSizing = Bottom;
// restartButton.position = new Vector(460, 363);
// restartButton.extent = new Vector(104, 54);
// restartButton.gamepadAccelerator = ["B"];
// restartButton.pressedAction = (e) -> restartFunc(restartButton);
var lbButton = new GuiXboxButton("Leaderboard", 220);
lbButton.position = new Vector(110, 0);
lbButton.vertSizing = Bottom;
lbButton.horizSizing = Left;
bottomBar.addChild(lbButton);
// var nextLevel = new GuiControl();
// nextLevel.position = new Vector(326, 307);
// nextLevel.extent = new Vector(130, 110);
// var temprev = new BitmapData(1, 1);
// temprev.setPixel(0, 0, 0);
// var tmpprevtile = Tile.fromBitmap(temprev);
// var nextLevelPreview = new GuiImage(tmpprevtile);
// nextLevelPreview.position = new Vector(-15, 0);
// nextLevelPreview.extent = new Vector(160, 110);
// nextLevel.addChild(nextLevelPreview);
// mission.getNextMission().getPreviewImage(t -> {
// nextLevelPreview.bmp.tile = t;
// });
// var nextLevelBtn = new GuiButton(loadButtonImages('data/ui/endgame/level_window'));
// nextLevelBtn.horizSizing = Width;
// nextLevelBtn.vertSizing = Height;
// nextLevelBtn.position = new Vector(0, 0);
// nextLevelBtn.extent = new Vector(130, 110);
// nextLevelBtn.gamepadAccelerator = ["X"];
// nextLevelBtn.pressedAction = (e) -> nextLevelFunc(nextLevelBtn);
// nextLevel.addChild(nextLevelBtn);
// function setButtonStates(enabled:Bool) {
// nextLevelBtn.disabled = !enabled;
// continueButton.disabled = !enabled;
// restartButton.disabled = !enabled;
// }
// var arial14fontdata = ResourceLoader.getFileEntry("data/font/arial.fnt");
// var arial14b = new BitmapFont(arial14fontdata.entry);
// @:privateAccess arial14b.loader = ResourceLoader.loader;
// var arial14 = arial14b.toSdfFont(cast 12 * Settings.uiScale, 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 28 * Settings.uiScale, MultiChannel);
// var domcasual64 = domcasual32b.toSdfFont(cast 58 * Settings.uiScale, MultiChannel);
// var domcasual24 = domcasual32b.toSdfFont(cast 20 * Settings.uiScale, MultiChannel);
// var expo50fontdata = ResourceLoader.getFileEntry("data/font/EXPON.fnt");
// var expo50b = new BitmapFont(expo50fontdata.entry);
// @:privateAccess expo50b.loader = ResourceLoader.loader;
// var expo50 = expo50b.toSdfFont(cast 35 * Settings.uiScale, MultiChannel);
// var expo32 = expo50b.toSdfFont(cast 24 * Settings.uiScale, MultiChannel);
// function mlFontLoader(text:String) {
// switch (text) {
// case "DomCasual24":
// return domcasual24;
// case "DomCasual32":
// return domcasual32;
// case "DomCasual64":
// return domcasual64;
// case "Arial14":
// return arial14;
// case "Expo32":
// return expo32;
// default:
// return null;
// }
// }
// var egResult = new GuiMLText(domcasual32, mlFontLoader);
// egResult.position = new Vector(313, 54);
// egResult.extent = new Vector(244, 69);
// egResult.text.text = '<font face="DomCasual64" color="#FFFFFF"><p align="right">${Util.formatTime(timeState.gameplayClock)}</p></font>';
// egResult.text.filter = new DropShadow(1.414, 0.785, 0, 1, 0, 0.4, 1, true);
// pg.addChild(egResult);
// var egFirstLine = new GuiMLText(domcasual24, mlFontLoader);
// egFirstLine.position = new Vector(340, 150);
// egFirstLine.extent = new Vector(210, 25);
// egFirstLine.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFirstLine);
// var egSecondLine = new GuiMLText(domcasual24, mlFontLoader);
// egSecondLine.position = new Vector(341, 178);
// egSecondLine.extent = new Vector(209, 25);
// egSecondLine.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egSecondLine);
// var egThirdLine = new GuiMLText(domcasual24, mlFontLoader);
// egThirdLine.position = new Vector(341, 206);
// egThirdLine.extent = new Vector(209, 25);
// egThirdLine.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egThirdLine);
// var egFourthLine = new GuiMLText(domcasual24, mlFontLoader);
// egFourthLine.position = new Vector(341, 234);
// egFourthLine.extent = new Vector(209, 25);
// egFourthLine.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFourthLine);
// var egFifthLine = new GuiMLText(domcasual24, mlFontLoader);
// egFifthLine.position = new Vector(341, 262);
// egFifthLine.extent = new Vector(209, 25);
// egFifthLine.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFifthLine);
// var egFirstLineScore = new GuiMLText(domcasual24, mlFontLoader);
// egFirstLineScore.position = new Vector(475, 150);
// egFirstLineScore.extent = new Vector(210, 25);
// egFirstLineScore.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFirstLineScore);
// var egSecondLineScore = new GuiMLText(domcasual24, mlFontLoader);
// egSecondLineScore.position = new Vector(476, 178);
// egSecondLineScore.extent = new Vector(209, 25);
// egSecondLineScore.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egSecondLineScore);
// var egThirdLineScore = new GuiMLText(domcasual24, mlFontLoader);
// egThirdLineScore.position = new Vector(476, 206);
// egThirdLineScore.extent = new Vector(209, 25);
// egThirdLineScore.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egThirdLineScore);
// var egFourthLineScore = new GuiMLText(domcasual24, mlFontLoader);
// egFourthLineScore.position = new Vector(476, 234);
// egFourthLineScore.extent = new Vector(209, 25);
// egFourthLineScore.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFourthLineScore);
// var egFifthLineScore = new GuiMLText(domcasual24, mlFontLoader);
// egFifthLineScore.position = new Vector(476, 262);
// egFifthLineScore.extent = new Vector(209, 25);
// egFifthLineScore.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// pg.addChild(egFifthLineScore);
// var egTitleText = new GuiMLText(expo50, mlFontLoader);
// egTitleText.text.textColor = 0xffff00;
// egTitleText.text.text = '<font color="#FFFFFF" face="DomCasual64">Your Time:</font>';
// egTitleText.text.filter = new DropShadow(1.414, 0.785, 0, 1, 0, 0.4, 1, true);
// egTitleText.position = new Vector(34, 54);
// egTitleText.extent = new Vector(247, 69);
// pg.addChild(egTitleText);
// var egTopThreeText = new GuiMLText(domcasual32, mlFontLoader);
// egTopThreeText.position = new Vector(341, 114);
// egTopThreeText.extent = new Vector(209, 34);
// egTopThreeText.text.text = '<font face="DomCasual32" color="#FFFFFF">Top 5 Times:</font>'; // Make toggleable 3-5
// egTopThreeText.text.filter = new DropShadow(1.414, 0.785, 0, 1, 0, 0.4, 1, true);
// pg.addChild(egTopThreeText);
// var text = '<font color="#FFFFFF" face="DomCasual32"><p align="center">';
// // Check for ultimate time TODO
// if (mission.ultimateTime > 0 && timeState.gameplayClock < mission.ultimateTime) {
// text += 'You beat the <font color="#FFDD22">Ultimate</font> Time!';
// } else {
// if (mission.goldTime > 0 && timeState.gameplayClock < mission.goldTime) {
// if (mission.game == "gold" || mission.game.toLowerCase() == "ultra")
// text += 'You beat the <font color="#FFCC00">Gold</font> Time!';
// else
// text += 'You beat the <font color="#CCCCCC">Platinum</font> Time!';
// } else {
// if (mission.qualifyTime > timeState.gameplayClock) {
// text += "You beat the Par Time!";
// } else {
// text += '<font color="#F55555">You didn\'t pass the Par Time!</font>';
// }
// }
// }
// text += '</p></font>';
// var finishMessage = new GuiMLText(expo32, mlFontLoader);
// finishMessage.text.textColor = 0x00ff00;
// finishMessage.text.text = text;
// finishMessage.text.filter = new DropShadow(1, 0.785, 0, 1, 0, 0.4, 1, true);
// // finishMessage.justify = Center;
// finishMessage.position = new Vector(25, 120);
// finishMessage.extent = new Vector(293, 211);
// pg.addChild(finishMessage);
// var qualified = mission.qualifyTime > timeState.gameplayClock;
// var scoreData:Array<Score> = Settings.getScores(mission.path);
// while (scoreData.length < 5) {
// scoreData.push({name: "Matan W.", time: 5999.999});
// }
// egFirstLine.text.text = '<p align="left"><font color="#EEC884">1. </font>${scoreData[0].name}</p>';
// egSecondLine.text.text = '<p align="left"><font color="#CDCDCD">2. </font>${scoreData[1].name}</p>';
// egThirdLine.text.text = '<p align="left"><font color="#C9AFA0">3. </font>${scoreData[2].name}</p>';
// egFourthLine.text.text = '<p align="left"><font color="#A4A4A4">4. </font>${scoreData[3].name}</p>';
// egFifthLine.text.text = '<p align="left"><font color="#949494">5. </font>${scoreData[4].name}</p>';
// var lineelems = [
// egFirstLineScore,
// egSecondLineScore,
// egThirdLineScore,
// egFourthLineScore,
// egFifthLineScore
// ];
// for (i in 0...5) {
// if (scoreData[i].time < mission.ultimateTime) {
// lineelems[i].text.text = '<font color="#FFDD22">${Util.formatTime(scoreData[i].time)}</font>';
// } else {
// if (scoreData[i].time < mission.goldTime) {
// if (mission.game == "gold" || mission.game.toLowerCase() == "ultra")
// lineelems[i].text.text = '<font color="#FFCC00">${Util.formatTime(scoreData[i].time)}</font>';
// else
// lineelems[i].text.text = '<font color="#CCCCCC">${Util.formatTime(scoreData[i].time)}</font>';
// } else {
// lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}';
// }
// }
// }
// var leftColumn = new GuiMLText(domcasual24, mlFontLoader);
// leftColumn.text.lineSpacing = 5;
// leftColumn.text.textColor = 0xFFFFFF;
// leftColumn.text.text = 'Par Time:<br/>${mission.game == "gold" || mission.game.toLowerCase() == "ultra" ? '<font color="#FFCC00">Gold Time:</font>' : '<font color="#CCCCCC">Platinum Time:</font>'}<br/>${mission.ultimateTime != 0 ? '<font color="#FFDD22">Ultimate Time:</font><br/>' : ''}<font face="Arial14"><br/></font><font color="#FFFFFF" face="DomCasual24">Time Passed:<br/>Clock Bonuses:</font>';
// leftColumn.text.filter = new DropShadow(1.414, 0.785, 0x7777777F, 1, 0, 0.4, 1, true);
// leftColumn.position = new Vector(25, 165);
// leftColumn.extent = new Vector(293, 211);
// pg.addChild(leftColumn);
// var elapsedTime = Math.max(timeState.currentAttemptTime - 3.5, 0);
// var bonusTime = Math.max(0, Std.int((elapsedTime - timeState.gameplayClock) * 1000) / 1000);
// var rightColumn = new GuiMLText(domcasual24, mlFontLoader);
// rightColumn.text.lineSpacing = 5;
// rightColumn.text.textColor = 0xFFFFFF;
// rightColumn.text.text = '${Util.formatTime(mission.qualifyTime == Math.POSITIVE_INFINITY ? 5999.999 : mission.qualifyTime)}<br/><font color="${mission.game == "gold" || mission.game.toLowerCase() == "ultra" ? '#FFCC00' : '#CCCCCC'}">${Util.formatTime(mission.goldTime)}</font><br/>${mission.ultimateTime != 0 ? '<font color="#FFDD22">${Util.formatTime(mission.ultimateTime)}</font><br/>' : ''}<font face="Arial14"><br/></font><font color="#FFFFFF" face="DomCasual24">${Util.formatTime(elapsedTime)}<br/>${Util.formatTime(bonusTime)}</font>';
// rightColumn.text.filter = new DropShadow(1.414, 0.785, 0xffffff, 1, 0, 0.4, 1, true);
// rightColumn.position = new Vector(235, 165);
// rightColumn.extent = new Vector(293, 211);
// pg.addChild(rightColumn);
// pg.addChild(continueButton);
// pg.addChild(restartButton);
// pg.addChild(nextLevel);
// pg.addChild(egFirstLine);
// pg.addChild(egSecondLine);
// pg.addChild(egThirdLine);
// pg.addChild(egFourthLine);
// pg.addChild(egFifthLine);
// this.addChild(pg);
// var scoreTimes = scoreData.map(x -> x.time).concat([timeState.gameplayClock]);
// scoreTimes.sort((a, b) -> a == b ? 0 : (a > b ? 1 : -1));
// var idx = scoreTimes.indexOf(timeState.gameplayClock);
// // if (Settings.progression[mission.difficultyIndex] == mission.index && qualified) {
// // Settings.progression[mission.difficultyIndex]++;
// // }
// Settings.save();
// if (idx <= 4) {
// setButtonStates(false);
// var end = new EnterNameDlg(idx, (name) -> {
// setButtonStates(true);
// if (scoreSubmitted)
// return;
// var myScore = {name: name, time: timeState.gameplayClock};
// scoreData.push(myScore);
// scoreData.sort((a, b) -> a.time == b.time ? 0 : (a.time > b.time ? 1 : -1));
// egFirstLine.text.text = '<p align="left"><font color="#EEC884">1. </font>${scoreData[0].name}</p>';
// egSecondLine.text.text = '<p align="left"><font color="#CDCDCD">2. </font>${scoreData[1].name}</p>';
// egThirdLine.text.text = '<p align="left"><font color="#C9AFA0">3. </font>${scoreData[2].name}</p>';
// egFourthLine.text.text = '<p align="left"><font color="#A4A4A4">4. </font>${scoreData[3].name}</p>';
// egFifthLine.text.text = '<p align="left"><font color="#949494">5. </font>${scoreData[4].name}</p>';
// for (i in 0...5) {
// if (scoreData[i].time < mission.ultimateTime) {
// lineelems[i].text.text = '<font color="#FFDD22">${Util.formatTime(scoreData[i].time)}</font>';
// } else {
// if (scoreData[i].time < mission.goldTime) {
// lineelems[i].text.text = '<font color="${mission.game == "gold" || mission.game.toLowerCase() == "ultra" ? '#FFCC00' : '#CCCCCC'}">${Util.formatTime(scoreData[i].time)}</font>';
// } else {
// lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}';
// }
// }
// }
// Settings.saveScore(mission.path, myScore);
// scoreSubmitted = true;
// });
// this.addChild(end);
// }
var nextButton = new GuiXboxButton("Next", 160);
nextButton.position = new Vector(320, 0);
nextButton.vertSizing = Bottom;
nextButton.horizSizing = Left;
nextButton.pressedAction = (e) -> continueFunc(nextButton);
bottomBar.addChild(nextButton);
}
}

154
src/gui/GuiXboxButton.hx Normal file
View file

@ -0,0 +1,154 @@
package gui;
import h3d.Matrix;
import hxd.Key;
import gui.GuiControl.MouseState;
import hxd.res.BitmapFont;
import h3d.Vector;
import src.ResourceLoader;
import src.Settings;
import src.Gamepad;
import src.AudioManager;
class GuiXboxButton extends GuiControl {
var left:GuiAnim;
var fill:GuiAnim;
var right:GuiAnim;
var text:GuiText;
public var pressedAction:GuiEvent->Void = null;
public var disabled:Bool = false;
public var pressed:Bool = false;
public var buttonSounds:Bool = true;
public var accelerator:Int = 0;
public var gamepadAccelerator:Array<String> = [];
public var acceleratorWasPressed = false;
public function new(text:String, width:Int) {
super();
this.extent = new Vector(width, 94);
var buttonImage = ResourceLoader.getResource("data/ui/xbox/cursorButtonArray.png", ResourceLoader.getImage, this.imageResources).toTile();
var buttonLeft = buttonImage.sub(0, 2, 39, 94);
var buttonFill = buttonImage.sub(52, 2, 396, 94);
var buttonRight = buttonImage.sub(452, 2, 41, 94);
var buttonLeftPressed = buttonImage.sub(0, 98, 39, 94);
var buttonFillPressed = buttonImage.sub(52, 98, 396, 94);
var buttonRightPressed = buttonImage.sub(452, 98, 41, 94);
var cmat = Matrix.I();
cmat.colorGain(0x7F7F7F, 1);
// cmat._44 = 1;
var shadeFilter = new h2d.filter.ColorMatrix(cmat);
shadeFilter.enable = false;
var fillWidth = width - 39 - 41;
left = new GuiAnim([buttonLeft, buttonLeftPressed]);
left.position = new Vector(0, 0);
left.extent = new Vector(39, 94);
left.anim.filter = shadeFilter;
this.addChild(left);
fill = new GuiAnim([buttonFill, buttonFillPressed]);
fill.position = new Vector(39, 0);
fill.extent = new Vector(fillWidth, 94);
fill.anim.filter = shadeFilter;
this.addChild(fill);
right = new GuiAnim([buttonRight, buttonRightPressed]);
right.position = new Vector(39 + fillWidth, 0);
right.extent = new Vector(41, 94);
right.anim.filter = shadeFilter;
this.addChild(right);
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 20 * Settings.uiScale, h2d.Font.SDFChannel.MultiChannel);
this.text = new GuiText(arial14);
this.text.position = new Vector(39, 37);
this.text.extent = new Vector(fillWidth, 35);
this.text.justify = Center;
this.text.vertSizing = Top;
this.text.text.text = text;
this.text.text.textColor = 0x787878;
this.addChild(this.text);
}
public override function update(dt:Float, mouseState:MouseState) {
var renderRect = getHitTestRect();
if (renderRect.inRect(mouseState.position) && !disabled) {
if (buttonSounds && Key.isPressed(Key.MOUSE_LEFT)) {
AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources));
}
}
if (renderRect.inRect(mouseState.position) && !disabled) {
if (Key.isDown(Key.MOUSE_LEFT)) {
left.anim.currentFrame = 1;
fill.anim.currentFrame = 1;
right.anim.currentFrame = 1;
left.anim.filter.enable = true;
fill.anim.filter.enable = true;
right.anim.filter.enable = true;
text.text.textColor = 0x101010;
pressed = true;
} else {
left.anim.currentFrame = 1;
fill.anim.currentFrame = 1;
right.anim.currentFrame = 1;
left.anim.filter.enable = false;
fill.anim.filter.enable = false;
right.anim.filter.enable = false;
text.text.textColor = 0x101010;
pressed = false;
}
} else {
left.anim.currentFrame = 0;
fill.anim.currentFrame = 0;
right.anim.currentFrame = 0;
left.anim.filter.enable = false;
fill.anim.filter.enable = false;
right.anim.filter.enable = false;
this.text.text.textColor = 0x787878;
pressed = false;
}
if (!disabled) {
if (acceleratorWasPressed && (accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator)) {
if (this.pressedAction != null) {
this.pressedAction(new GuiEvent(this));
}
} else if ((accelerator != 0 && hxd.Key.isPressed(accelerator)) || Gamepad.isPressed(gamepadAccelerator)) {
acceleratorWasPressed = true;
}
}
if (acceleratorWasPressed) {
if ((accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator))
acceleratorWasPressed = false;
}
super.update(dt, mouseState);
}
public override function onMouseRelease(mouseState:MouseState) {
if (mouseState.handled)
return;
mouseState.handled = true;
super.onMouseRelease(mouseState);
if (this.pressedAction != null && !disabled) {
this.pressedAction(new GuiEvent(this));
}
}
public override function onMouseEnter(mouseState:MouseState) {
if (mouseState.handled)
return;
mouseState.handled = true;
super.onMouseEnter(mouseState);
if (buttonSounds && !disabled) {
AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonover.wav", ResourceLoader.getAudio, this.soundResources));
}
}
}

View file

@ -58,6 +58,7 @@ class MissionElementScriptObject extends MissionElementBase {
var music:String;
var alarmstarttime:String;
var game:String;
var difficulty:String;
public function new() {
_type = MissionElementType.ScriptObject;