diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 7a65bd1c..24fca115 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -224,6 +224,9 @@ class MarbleGame { public function playMission(mission:Mission) { canvas.clearContent(); + if (world != null) { + world.dispose(); + } world = new MarbleWorld(scene, scene2d, mission, toRecord); toRecord = false; world.init(); diff --git a/src/Mission.hx b/src/Mission.hx index 126f148c..2e74e4a9 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -29,6 +29,8 @@ class Mission { public var id:Int; public var isClaMission:Bool; + var next:Mission; + var imageResources:Array> = []; var imgFileEntry:hxd.fs.FileEntry; @@ -72,6 +74,10 @@ class Mission { return mission; } + public function getNextMission() { + return this.next; + } + public function getPreviewImage(onLoaded:h2d.Tile->Void) { if (!this.isClaMission) { var basename = haxe.io.Path.withoutExtension(this.path); diff --git a/src/MissionList.hx b/src/MissionList.hx index 01d40204..085d613b 100644 --- a/src/MissionList.hx +++ b/src/MissionList.hx @@ -8,6 +8,7 @@ class MissionList { static var beginnerMissions:Array; static var intermediateMissions:Array; static var advancedMissions:Array; + static var expertMissions:Array; static var customMissions:Array; static var missions:Map; @@ -40,14 +41,24 @@ class MissionList { } } difficultyMissions.sort((a, b) -> Std.parseInt(a.missionInfo.level) - Std.parseInt(b.missionInfo.level)); + + for (i in 0...difficultyMissions.length - 1) { + @:privateAccess difficultyMissions[i].next = difficultyMissions[i + 1]; + } return difficultyMissions; } beginnerMissions = parseDifficulty("beginner"); intermediateMissions = parseDifficulty("intermediate"); advancedMissions = parseDifficulty("advanced"); + expertMissions = parseDifficulty("expert"); customMissions = parseDifficulty("expert"); + @:privateAccess beginnerMissions[beginnerMissions.length - 1].next = intermediateMissions[0]; + @:privateAccess intermediateMissions[intermediateMissions.length - 1].next = advancedMissions[0]; + @:privateAccess advancedMissions[advancedMissions.length - 1].next = expertMissions[0]; + @:privateAccess expertMissions[expertMissions.length - 1].next = beginnerMissions[0]; + // parseCLAList(); _build = true; diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index 3d75ad44..bede25df 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -1,5 +1,7 @@ package gui; +import hxd.BitmapData; +import h2d.Tile; import src.MarbleGame; import src.Settings.Score; import src.Settings.Settings; @@ -55,23 +57,29 @@ class EndGameGui extends GuiControl { nextLevel.position = new Vector(326, 307); nextLevel.extent = new Vector(130, 110); - var nextLevelPreview = new GuiImage(ResourceLoader.getResource('data/missions/beginner/LearnTheWall-Hit.png', ResourceLoader.getImage, - this.imageResources) - .toTile()); + 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.pressedAction = function(self:GuiControl) { - // var nextMission = Mission.getNextMission(mission); - // if (nextMission != null) { - // continueFunc(self); - // } + var nextMission = mission.getNextMission(); + if (nextMission != null) { + cast(this.parent, Canvas).marbleGame.playMission(nextMission); + } }; nextLevel.addChild(nextLevelBtn); @@ -147,6 +155,36 @@ class EndGameGui extends GuiControl { 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 = 'Your Time:'; @@ -201,16 +239,22 @@ class EndGameGui extends GuiControl { egFourthLine.text.text = '

4. ${scoreData[3].name}

'; egFifthLine.text.text = '

5. ${scoreData[4].name}

'; - var lineelems = [egFirstLine, egSecondLine, egThirdLine, egFourthLine, egFifthLine]; + var lineelems = [ + egFirstLineScore, + egSecondLineScore, + egThirdLineScore, + egFourthLineScore, + egFifthLineScore + ]; for (i in 0...5) { if (scoreData[i].time < mission.ultimateTime) { - lineelems[i].text.text += '

${Util.formatTime(scoreData[i].time)}

'; + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; } else { if (scoreData[i].time < mission.goldTime) { - lineelems[i].text.text += '

${Util.formatTime(scoreData[i].time)}

'; + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; } else { - lineelems[i].text.text += '

${Util.formatTime(scoreData[i].time)}

'; + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; } } } @@ -257,7 +301,7 @@ class EndGameGui extends GuiControl { } Settings.save(); - if (idx <= 2) { + if (idx <= 4) { var end = new EnterNameDlg(idx, (name) -> { if (scoreSubmitted) return; @@ -266,6 +310,24 @@ class EndGameGui extends GuiControl { scoreData.push(myScore); scoreData.sort((a, b) -> a.time == b.time ? 0 : (a.time > b.time ? 1 : -1)); + egFirstLine.text.text = '

1. ${scoreData[0].name}

'; + egSecondLine.text.text = '

2. ${scoreData[1].name}

'; + egThirdLine.text.text = '

3. ${scoreData[2].name}

'; + egFourthLine.text.text = '

4. ${scoreData[3].name}

'; + egFifthLine.text.text = '

5. ${scoreData[4].name}

'; + + for (i in 0...5) { + if (scoreData[i].time < mission.ultimateTime) { + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; + } else { + if (scoreData[i].time < mission.goldTime) { + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; + } else { + lineelems[i].text.text = '${Util.formatTime(scoreData[i].time)}'; + } + } + } + Settings.saveScore(mission.path, myScore); scoreSubmitted = true; diff --git a/src/gui/GuiImage.hx b/src/gui/GuiImage.hx index 6eb23366..ea5ce4f5 100644 --- a/src/gui/GuiImage.hx +++ b/src/gui/GuiImage.hx @@ -1,5 +1,7 @@ package gui; +import shaders.GuiClipFilter; +import h2d.filter.Mask; import gui.GuiControl.MouseState; import h2d.Scene; import h2d.Tile; @@ -12,6 +14,8 @@ class GuiImage extends GuiControl { public var pressedAction:GuiControl->Void = null; + public var doClipping:Bool = true; + public function new(texture:Tile) { super(); this.bmp = new Bitmap(texture); @@ -19,6 +23,16 @@ class GuiImage extends GuiControl { public override function render(scene2d:Scene) { var renderRect = this.getRenderRectangle(); + var hittestRect = this.getHitTestRect(); + if (doClipping + && (hittestRect.position.x > renderRect.position.x + || hittestRect.position.y > renderRect.position.y + || hittestRect.extent.x < renderRect.extent.x + || hittestRect.extent.y < renderRect.extent.y)) { + if (bmp.filter == null) { + bmp.filter = new GuiClipFilter(hittestRect); + } + } bmp.setPosition(Math.floor(renderRect.position.x), Math.floor(renderRect.position.y)); // bmp.scaleX = renderRect.extent.x / bmp.tile.width; // bmp.scaleY = renderRect.extent.y / bmp.tile.height; diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx index 857a5ea5..a102f4b8 100644 --- a/src/gui/PlayGui.hx +++ b/src/gui/PlayGui.hx @@ -164,6 +164,7 @@ class PlayGui { .toTile()); timerTransparency.position = new Vector(14, -7); timerTransparency.extent = new Vector(228, 71); + timerTransparency.doClipping = false; timerCtrl.addChild(timerTransparency); timerNumbers[0].position = new Vector(23, 0); diff --git a/src/shaders/GuiClipFilter.hx b/src/shaders/GuiClipFilter.hx new file mode 100644 index 00000000..0d70c56e --- /dev/null +++ b/src/shaders/GuiClipFilter.hx @@ -0,0 +1,32 @@ +package shaders; + +import h3d.Vector; +import h2d.Mask; +import h2d.filter.Shader; +import h2d.Object; +import h2d.col.Bounds; +import h2d.col.Point; +import gui.Rect; +import h2d.RenderContext; +import h2d.filter.Filter; + +class GuiClipFilter extends Filter { + public var renderRect:Rect; + + public function new(rect:Rect) { + super(); + this.renderRect = rect; + } + + override function draw(ctx:RenderContext, t:h2d.Tile) { + var tout = ctx.textures.allocTileTarget("guiClip", t); + ctx.pushTarget(tout); + ctx.flush(); + ctx.clipRenderZone(renderRect.position.x, renderRect.position.y, renderRect.extent.x, renderRect.extent.y); + h3d.pass.Copy.run(t.getTexture(), tout); + ctx.flush(); + ctx.popRenderZone(); + ctx.popTarget(); + return h2d.Tile.fromTexture(tout); + } +}