mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-31 04:12:17 +00:00
fix bugs, work on options
This commit is contained in:
parent
5df7ac6315
commit
0518137b92
12 changed files with 388 additions and 19 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -5,4 +5,6 @@ data
|
|||
*.js.map
|
||||
*.tmp
|
||||
.vscode
|
||||
native
|
||||
native
|
||||
*.exe
|
||||
*.obj
|
||||
|
|
@ -3,9 +3,8 @@ A Haxe port of Marble Blast Gold, name subject to change.
|
|||
|
||||
# Build
|
||||
Requires Haxe 4.2.2
|
||||
You require the latest versions of the following Haxe libraries:
|
||||
- heaps
|
||||
- polygonal-ds (With https://github.com/polygonal/ds/pull/53 applied)
|
||||
You require the following Haxe libraries:
|
||||
- heaps: 1.9.1 (not the git version)
|
||||
|
||||
You also have to compile your own version of Hashlink with https://github.com/HaxeFoundation/hashlink/pull/444 applied
|
||||
After all that has been setup, copy the data folder of MBG to the repo directory, compile to hashlink by doing `haxe compile.hxml` and then running the game by `hl marblegame.hl`
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
-cp src
|
||||
-lib heaps
|
||||
-lib hlsdl
|
||||
-lib polygonal-ds
|
||||
-hl marblegame.hl
|
||||
-D windowSize=1280x720
|
||||
--main Main
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package src;
|
||||
|
||||
import gui.LoadingGui;
|
||||
import gui.PlayMissionGui;
|
||||
import src.MarbleGame;
|
||||
import gui.EndGameGui;
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ class PathedInterior extends InteriorObject {
|
|||
|
||||
override function reset() {
|
||||
this.currentTime = 0;
|
||||
this.targetTime = -1;
|
||||
this.targetTime = 0;
|
||||
this.changeTime = 0;
|
||||
|
||||
if (this.element.initialposition != "") {
|
||||
|
|
@ -304,8 +304,10 @@ class PathedInterior extends InteriorObject {
|
|||
|
||||
if (this.element.initialtargetposition != "") {
|
||||
this.targetTime = MisParser.parseNumber(this.element.initialtargetposition);
|
||||
if (this.targetTime > 0)
|
||||
this.targetTime /= 1000;
|
||||
// Alright this is strange. In Torque, there are some FPS-dependent client/server desync issues that cause the interior to start at the end position whenever the initialTargetPosition is somewhere greater than 1 and, like, approximately below 50.
|
||||
if (this.targetTime > 0 && this.targetTime < 50)
|
||||
if (this.targetTime > 0 && this.targetTime < 0.05)
|
||||
this.currentTime = this.duration;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package src;
|
||||
|
||||
import sys.thread.Lock;
|
||||
import sys.thread.FixedThreadPool;
|
||||
import hxd.res.Image;
|
||||
import h3d.mat.Texture;
|
||||
import h3d.scene.Object;
|
||||
|
|
@ -19,13 +21,20 @@ class ResourceLoader {
|
|||
static var dtsResources:Map<String, DtsFile> = new Map();
|
||||
static var textureCache:Map<String, Texture> = new Map();
|
||||
static var imageCache:Map<String, Image> = new Map();
|
||||
static var threadPool:FixedThreadPool = new FixedThreadPool(4);
|
||||
|
||||
public static function loadInterior(path:String) {
|
||||
if (interiorResources.exists(path))
|
||||
return interiorResources.get(path);
|
||||
else {
|
||||
var itr = Dif.Load(path);
|
||||
interiorResources.set(path, itr);
|
||||
var itr:Dif;
|
||||
var lock = new Lock();
|
||||
threadPool.run(() -> {
|
||||
itr = Dif.Load(path);
|
||||
interiorResources.set(path, itr);
|
||||
lock.release();
|
||||
});
|
||||
lock.wait();
|
||||
return itr;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,8 +44,13 @@ class ResourceLoader {
|
|||
return dtsResources.get(path);
|
||||
else {
|
||||
var dts = new DtsFile();
|
||||
dts.read(path);
|
||||
dtsResources.set(path, dts);
|
||||
var lock = new Lock();
|
||||
threadPool.run(() -> {
|
||||
dts.read(path);
|
||||
dtsResources.set(path, dts);
|
||||
lock.release();
|
||||
});
|
||||
lock.wait();
|
||||
return dts;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,6 +61,7 @@ class ResourceLoader {
|
|||
if (fileSystem.exists(path)) {
|
||||
var tex = loader.load(path).toTexture();
|
||||
textureCache.set(path, tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import gui.GuiControl.MouseState;
|
|||
import hxd.Window;
|
||||
import h2d.Tile;
|
||||
|
||||
enum ButtonType {
|
||||
Normal;
|
||||
Toggle;
|
||||
}
|
||||
|
||||
class GuiButton extends GuiAnim {
|
||||
// 0 is normal
|
||||
// 1 is hover
|
||||
|
|
@ -14,20 +19,44 @@ class GuiButton extends GuiAnim {
|
|||
|
||||
public var disabled:Bool = false;
|
||||
|
||||
public var buttonType:ButtonType = Normal;
|
||||
public var pressed:Bool = false;
|
||||
|
||||
public function new(anim:Array<Tile>) {
|
||||
super(anim);
|
||||
}
|
||||
|
||||
public override function update(dt:Float, mouseState:MouseState) {
|
||||
var renderRect = getRenderRectangle();
|
||||
if (renderRect.inRect(mouseState.position) && !disabled) {
|
||||
if (Key.isDown(Key.MOUSE_LEFT)) {
|
||||
if (buttonType == Normal) {
|
||||
if (renderRect.inRect(mouseState.position) && !disabled) {
|
||||
if (Key.isDown(Key.MOUSE_LEFT)) {
|
||||
this.anim.currentFrame = 2;
|
||||
pressed = true;
|
||||
} else {
|
||||
this.anim.currentFrame = 1;
|
||||
pressed = false;
|
||||
}
|
||||
} else {
|
||||
this.anim.currentFrame = disabled ? 3 : 0;
|
||||
pressed = false;
|
||||
}
|
||||
}
|
||||
if (buttonType == Toggle) {
|
||||
if (this.pressed) {
|
||||
this.anim.currentFrame = 2;
|
||||
} else {
|
||||
this.anim.currentFrame = 1;
|
||||
if (renderRect.inRect(mouseState.position) && !disabled) {
|
||||
if (Key.isDown(Key.MOUSE_LEFT)) {
|
||||
this.anim.currentFrame = 2;
|
||||
} else if (!Key.isReleased(Key.MOUSE_LEFT)) {
|
||||
this.anim.currentFrame = 1;
|
||||
}
|
||||
} else {
|
||||
this.anim.currentFrame = disabled ? 3 : 0;
|
||||
}
|
||||
}
|
||||
} else
|
||||
this.anim.currentFrame = disabled ? 3 : 0;
|
||||
}
|
||||
super.update(dt, mouseState);
|
||||
}
|
||||
|
||||
|
|
@ -36,5 +65,8 @@ class GuiButton extends GuiAnim {
|
|||
if (this.pressedAction != null && !disabled) {
|
||||
this.pressedAction(this);
|
||||
}
|
||||
if (buttonType == Toggle) {
|
||||
pressed = !pressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
src/gui/GuiProgress.hx
Normal file
41
src/gui/GuiProgress.hx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package gui;
|
||||
|
||||
import h2d.Graphics;
|
||||
import h2d.Scene;
|
||||
import h3d.Vector;
|
||||
|
||||
class GuiProgress extends GuiControl {
|
||||
public var progress:Float = 0;
|
||||
public var progressColor:Int = 0x2C98A264;
|
||||
|
||||
var progressRect:h2d.Graphics;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
public override function render(scene2d:Scene) {
|
||||
var renderRect = getRenderRectangle();
|
||||
if (this.progressRect == null) {
|
||||
this.progressRect = new Graphics();
|
||||
}
|
||||
if (scene2d.contains(progressRect))
|
||||
progressRect.remove();
|
||||
scene2d.addChild(progressRect);
|
||||
var rgb = progressColor >> 2;
|
||||
var a = progressColor & 0xFF;
|
||||
this.progressRect.clear();
|
||||
this.progressRect.beginFill(rgb, a / 0xFF);
|
||||
this.progressRect.drawRect(0, 0, renderRect.extent.x * progress, renderRect.extent.y);
|
||||
this.progressRect.endFill();
|
||||
this.progressRect.x = renderRect.position.x;
|
||||
this.progressRect.y = renderRect.position.y;
|
||||
super.render(scene2d);
|
||||
}
|
||||
|
||||
public override function dispose() {
|
||||
if (progressRect != null)
|
||||
progressRect.remove();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
55
src/gui/LoadingGui.hx
Normal file
55
src/gui/LoadingGui.hx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package gui;
|
||||
|
||||
import h3d.Vector;
|
||||
import src.ResourceLoader;
|
||||
|
||||
class LoadingGui extends GuiImage {
|
||||
public var setProgress:Float->Void;
|
||||
|
||||
public function new() {
|
||||
super(ResourceLoader.getImage("data/ui/background.jpg").toTile());
|
||||
this.horizSizing = Width;
|
||||
this.vertSizing = Height;
|
||||
this.extent = new Vector(640, 480);
|
||||
this.position = new Vector();
|
||||
|
||||
var loadingGui = new GuiImage(ResourceLoader.getImage("data/ui/loading/loadinggui.png").toTile());
|
||||
loadingGui.horizSizing = Center;
|
||||
loadingGui.vertSizing = Center;
|
||||
loadingGui.position = new Vector(86, 77);
|
||||
loadingGui.extent = new Vector(468, 325);
|
||||
|
||||
function loadButtonImages(path:String) {
|
||||
var normal = ResourceLoader.getImage('${path}_n.png').toTile();
|
||||
var hover = ResourceLoader.getImage('${path}_h.png').toTile();
|
||||
var pressed = ResourceLoader.getImage('${path}_d.png').toTile();
|
||||
return [normal, hover, pressed];
|
||||
}
|
||||
|
||||
// TODO mapname
|
||||
|
||||
var progress = new GuiProgress();
|
||||
progress.vertSizing = Bottom;
|
||||
progress.position = new Vector(153, 133);
|
||||
progress.extent = new Vector(269, 78);
|
||||
progress.progress = 0.5;
|
||||
|
||||
setProgress = (progressPz) -> {
|
||||
progress.progress = progressPz;
|
||||
}
|
||||
|
||||
var cancelButton = new GuiButton(loadButtonImages("data/ui/loading/cancel"));
|
||||
cancelButton.position = new Vector(320, 233);
|
||||
cancelButton.extent = new Vector(88, 50);
|
||||
|
||||
var overlay = new GuiImage(ResourceLoader.getImage("data/ui/loading/overlay.png").toTile());
|
||||
overlay.position = new Vector(151, 131);
|
||||
overlay.extent = new Vector(278, 86);
|
||||
|
||||
loadingGui.addChild(progress);
|
||||
loadingGui.addChild(cancelButton);
|
||||
loadingGui.addChild(overlay);
|
||||
|
||||
this.addChild(loadingGui);
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,9 @@ class MainMenuGui extends GuiImage {
|
|||
var optionsButton = new GuiButton(loadButtonImages("data/ui/home/options"));
|
||||
optionsButton.position = new Vector(55, 279);
|
||||
optionsButton.extent = new Vector(253, 83);
|
||||
optionsButton.pressedAction = (sender) -> {
|
||||
cast(this.parent, Canvas).setContent(new OptionsDlg());
|
||||
}
|
||||
homebase.addChild(optionsButton);
|
||||
|
||||
var exitButton = new GuiButton(loadButtonImages("data/ui/home/exit"));
|
||||
|
|
|
|||
222
src/gui/OptionsDlg.hx
Normal file
222
src/gui/OptionsDlg.hx
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
package gui;
|
||||
|
||||
import src.MarbleGame;
|
||||
import h3d.Vector;
|
||||
import src.ResourceLoader;
|
||||
|
||||
class OptionsDlg extends GuiImage {
|
||||
public function new() {
|
||||
super(ResourceLoader.getImage("data/ui/background.jpg").toTile());
|
||||
this.horizSizing = Width;
|
||||
this.vertSizing = Height;
|
||||
this.position = new Vector();
|
||||
this.extent = new Vector(640, 480);
|
||||
|
||||
function loadButtonImages(path:String) {
|
||||
var normal = ResourceLoader.getImage('${path}_n.png').toTile();
|
||||
var hover = ResourceLoader.getImage('${path}_h.png').toTile();
|
||||
var pressed = ResourceLoader.getImage('${path}_d.png').toTile();
|
||||
return [normal, hover, pressed];
|
||||
}
|
||||
|
||||
var tabs = new GuiControl();
|
||||
tabs.horizSizing = Center;
|
||||
tabs.vertSizing = Center;
|
||||
tabs.position = new Vector(60, 15);
|
||||
tabs.extent = new Vector(520, 450);
|
||||
this.addChild(tabs);
|
||||
|
||||
var graphicsTab = new GuiImage(ResourceLoader.getImage("data/ui/options/graf_tab.png").toTile());
|
||||
graphicsTab.position = new Vector(58, 44);
|
||||
graphicsTab.extent = new Vector(149, 86);
|
||||
|
||||
var controlsTab = new GuiImage(ResourceLoader.getImage("data/ui/options/cntr_tab.png").toTile());
|
||||
controlsTab.position = new Vector(315, 15);
|
||||
controlsTab.extent = new Vector(149, 65);
|
||||
|
||||
var boxFrame = new GuiImage(ResourceLoader.getImage("data/ui/options/options_base.png").toTile());
|
||||
boxFrame.position = new Vector(25, 14);
|
||||
boxFrame.extent = new Vector(470, 422);
|
||||
boxFrame.horizSizing = Center;
|
||||
boxFrame.vertSizing = Center;
|
||||
|
||||
var audioTab = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_tab.png").toTile());
|
||||
audioTab.position = new Vector(204, 33);
|
||||
audioTab.extent = new Vector(114, 75);
|
||||
|
||||
tabs.addChild(audioTab);
|
||||
tabs.addChild(controlsTab);
|
||||
tabs.addChild(boxFrame);
|
||||
tabs.addChild(graphicsTab);
|
||||
|
||||
var mainPane = new GuiControl();
|
||||
mainPane.position = new Vector(60, 15);
|
||||
mainPane.extent = new Vector(520, 450);
|
||||
mainPane.horizSizing = Center;
|
||||
mainPane.vertSizing = Center;
|
||||
this.addChild(mainPane);
|
||||
|
||||
var graphicsPane = new GuiControl();
|
||||
graphicsPane.position = new Vector(35, 110);
|
||||
graphicsPane.extent = new Vector(438, 298);
|
||||
|
||||
mainPane.addChild(graphicsPane);
|
||||
|
||||
var mainMenuButton = new GuiButton(loadButtonImages("data/ui/options/mainm"));
|
||||
mainMenuButton.position = new Vector(330, 356);
|
||||
mainMenuButton.extent = new Vector(121, 53);
|
||||
mainMenuButton.pressedAction = (sender) -> {
|
||||
MarbleGame.canvas.setContent(new MainMenuGui());
|
||||
}
|
||||
mainPane.addChild(mainMenuButton);
|
||||
|
||||
// Hacky radio box logic
|
||||
var windowBoxes = [];
|
||||
|
||||
function updateWindowFunc(sender:GuiButton) {
|
||||
for (box in windowBoxes) {
|
||||
if (box != sender)
|
||||
box.pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
var gfxWindow = new GuiButton(loadButtonImages("data/ui/options/grafwindo"));
|
||||
gfxWindow.position = new Vector(174, 116);
|
||||
gfxWindow.extent = new Vector(97, 55);
|
||||
gfxWindow.buttonType = Toggle;
|
||||
gfxWindow.pressed = true;
|
||||
gfxWindow.pressedAction = (sender) -> {
|
||||
updateWindowFunc(gfxWindow);
|
||||
}
|
||||
graphicsPane.addChild(gfxWindow);
|
||||
windowBoxes.push(gfxWindow);
|
||||
|
||||
var gfxFull = new GuiButton(loadButtonImages("data/ui/options/grafful"));
|
||||
gfxFull.position = new Vector(288, 118);
|
||||
gfxFull.extent = new Vector(61, 55);
|
||||
gfxFull.buttonType = Toggle;
|
||||
gfxFull.pressedAction = (sender) -> {
|
||||
updateWindowFunc(gfxFull);
|
||||
}
|
||||
graphicsPane.addChild(gfxFull);
|
||||
windowBoxes.push(gfxFull);
|
||||
|
||||
var gfxText = new GuiImage(ResourceLoader.getImage("data/ui/options/graf_txt.png").toTile());
|
||||
gfxText.horizSizing = Right;
|
||||
gfxText.vertSizing = Bottom;
|
||||
gfxText.position = new Vector(12, 12);
|
||||
gfxText.extent = new Vector(146, 261);
|
||||
graphicsPane.addChild(gfxText);
|
||||
|
||||
var resolutionBoxes = [];
|
||||
|
||||
function updateResolutionFunc(sender:GuiButton) {
|
||||
for (box in resolutionBoxes) {
|
||||
if (box != sender)
|
||||
box.pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
var gfx640480 = new GuiButton(loadButtonImages("data/ui/options/graf640"));
|
||||
gfx640480.position = new Vector(157, -3);
|
||||
gfx640480.extent = new Vector(84, 53);
|
||||
gfx640480.buttonType = Toggle;
|
||||
resolutionBoxes.push(gfx640480);
|
||||
gfx640480.pressedAction = (sender) -> {
|
||||
updateResolutionFunc(gfx640480);
|
||||
}
|
||||
graphicsPane.addChild(gfx640480);
|
||||
|
||||
var gfx800600 = new GuiButton(loadButtonImages("data/ui/options/graf800"));
|
||||
gfx800600.position = new Vector(237, 0);
|
||||
gfx800600.extent = new Vector(86, 51);
|
||||
gfx800600.buttonType = Toggle;
|
||||
resolutionBoxes.push(gfx800600);
|
||||
gfx800600.pressedAction = (sender) -> {
|
||||
updateResolutionFunc(gfx800600);
|
||||
}
|
||||
graphicsPane.addChild(gfx800600);
|
||||
|
||||
var gfx1024768 = new GuiButton(loadButtonImages("data/ui/options/graf1024"));
|
||||
gfx1024768.position = new Vector(320, -1);
|
||||
gfx1024768.extent = new Vector(94, 51);
|
||||
gfx1024768.buttonType = Toggle;
|
||||
gfx1024768.pressed = true;
|
||||
resolutionBoxes.push(gfx1024768);
|
||||
gfx1024768.pressedAction = (sender) -> {
|
||||
updateResolutionFunc(gfx1024768);
|
||||
}
|
||||
graphicsPane.addChild(gfx1024768);
|
||||
|
||||
var driverBoxes = [];
|
||||
|
||||
function updateDriverFunc(sender:GuiButton) {
|
||||
for (box in driverBoxes) {
|
||||
if (box != sender)
|
||||
box.pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
var gfxopengl = new GuiButton(loadButtonImages("data/ui/options/grafopgl"));
|
||||
gfxopengl.position = new Vector(165, 58);
|
||||
gfxopengl.extent = new Vector(97, 54);
|
||||
gfxopengl.buttonType = Toggle;
|
||||
gfxopengl.pressed = true;
|
||||
driverBoxes.push(gfxopengl);
|
||||
gfxopengl.pressedAction = (sender) -> {
|
||||
updateDriverFunc(gfxopengl);
|
||||
}
|
||||
graphicsPane.addChild(gfxopengl);
|
||||
|
||||
var gfxd3d = new GuiButton(loadButtonImages("data/ui/options/grafdir3d"));
|
||||
gfxd3d.position = new Vector(270, 59);
|
||||
gfxd3d.extent = new Vector(104, 52);
|
||||
gfxd3d.buttonType = Toggle;
|
||||
driverBoxes.push(gfxd3d);
|
||||
gfxd3d.pressedAction = (sender) -> {
|
||||
updateDriverFunc(gfxd3d);
|
||||
}
|
||||
graphicsPane.addChild(gfxd3d);
|
||||
|
||||
var applyButton = new GuiButton(loadButtonImages("data/ui/options/grafapply"));
|
||||
applyButton.position = new Vector(188, 239);
|
||||
applyButton.extent = new Vector(106, 60);
|
||||
graphicsPane.addChild(applyButton);
|
||||
|
||||
var bitBoxes = [];
|
||||
|
||||
function updateBitsFunc(sender:GuiButton) {
|
||||
for (box in bitBoxes) {
|
||||
if (box != sender)
|
||||
box.pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
var gfx16 = new GuiButton(loadButtonImages("data/ui/options/graf16bt"));
|
||||
gfx16.position = new Vector(179, 170);
|
||||
gfx16.extent = new Vector(79, 54);
|
||||
gfx16.buttonType = Toggle;
|
||||
bitBoxes.push(gfx16);
|
||||
gfx16.pressedAction = (sender) -> {
|
||||
updateBitsFunc(gfx16);
|
||||
}
|
||||
graphicsPane.addChild(gfx16);
|
||||
|
||||
var gfx32 = new GuiButton(loadButtonImages("data/ui/options/graf32bt"));
|
||||
gfx32.position = new Vector(272, 174);
|
||||
gfx32.extent = new Vector(84, 51);
|
||||
gfx32.buttonType = Toggle;
|
||||
gfx32.pressed = true;
|
||||
bitBoxes.push(gfx32);
|
||||
gfx32.pressedAction = (sender) -> {
|
||||
updateBitsFunc(gfx32);
|
||||
}
|
||||
graphicsPane.addChild(gfx32);
|
||||
|
||||
var shadowsButton = new GuiButton(loadButtonImages("data/ui/options/graf_chkbx"));
|
||||
shadowsButton.position = new Vector(141, 233);
|
||||
shadowsButton.extent = new Vector(46, 54);
|
||||
shadowsButton.buttonType = Toggle;
|
||||
graphicsPane.addChild(shadowsButton);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package octree;
|
||||
|
||||
import polygonal.ds.Prioritizable;
|
||||
|
||||
interface IOctreeElement extends Prioritizable {
|
||||
interface IOctreeElement {
|
||||
function getElementType():Int;
|
||||
function setPriority(priority:Int):Void;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue