basic settings stuff

This commit is contained in:
RandomityGuy 2021-06-27 22:22:43 +05:30
parent 7d3c373a40
commit d440165f91
3 changed files with 113 additions and 5 deletions

View file

@ -15,7 +15,7 @@ class Main extends hxd.App {
override function init() { override function init() {
super.init(); super.init();
Settings.load(); Settings.init();
marbleGame = new MarbleGame(s2d, s3d); marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui()); MarbleGame.canvas.setContent(new MainMenuGui());
// world = new MarbleWorld(s3d, s2d, mission); // world = new MarbleWorld(s3d, s2d, mission);

View file

@ -1,5 +1,7 @@
package src; package src;
import src.MarbleGame;
import hxd.Window;
import haxe.DynamicAccess; import haxe.DynamicAccess;
import sys.io.File; import sys.io.File;
import src.ResourceLoader; import src.ResourceLoader;
@ -10,9 +12,38 @@ typedef Score = {
var time:Float; var time:Float;
} }
typedef OptionsSettings = {
var screenWidth:Int;
var screenHeight:Int;
var isFullScreen:Bool;
var videoDriver:Int;
var colorDepth:Int;
var shadows:Bool;
var musicVolume:Float;
var soundVolume:Float;
}
class Settings { class Settings {
public static var highScores:Map<String, Array<Score>> = []; public static var highScores:Map<String, Array<Score>> = [];
public static var optionsSettings:OptionsSettings = {
screenWidth: 1280,
screenHeight: 720,
isFullScreen: false,
videoDriver: 0,
colorDepth: 1,
shadows: false,
musicVolume: 0,
soundVolume: 0
};
public static function applySettings() {
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
}
public static function saveScore(mapPath:String, score:Score) { public static function saveScore(mapPath:String, score:Score) {
if (highScores.exists(mapPath)) { if (highScores.exists(mapPath)) {
var scoreList = highScores.get(mapPath); var scoreList = highScores.get(mapPath);
@ -49,4 +80,16 @@ class Settings {
} }
} }
} }
public static function init() {
load();
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
Window.getInstance().addResizeEvent(() -> {
var wnd = Window.getInstance();
Settings.optionsSettings.screenWidth = wnd.width;
Settings.optionsSettings.screenHeight = wnd.height;
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
});
}
} }

View file

@ -1,5 +1,6 @@
package gui; package gui;
import src.Settings;
import src.Marble; import src.Marble;
import h2d.Tile; import h2d.Tile;
import hxd.res.BitmapFont; import hxd.res.BitmapFont;
@ -94,10 +95,12 @@ class OptionsDlg extends GuiImage {
gfxWindow.position = new Vector(174, 116); gfxWindow.position = new Vector(174, 116);
gfxWindow.extent = new Vector(97, 55); gfxWindow.extent = new Vector(97, 55);
gfxWindow.buttonType = Toggle; gfxWindow.buttonType = Toggle;
gfxWindow.pressed = true;
gfxWindow.pressedAction = (sender) -> { gfxWindow.pressedAction = (sender) -> {
updateWindowFunc(gfxWindow); updateWindowFunc(gfxWindow);
} }
if (!Settings.optionsSettings.isFullScreen) {
gfxWindow.pressed = true;
}
graphicsPane.addChild(gfxWindow); graphicsPane.addChild(gfxWindow);
windowBoxes.push(gfxWindow); windowBoxes.push(gfxWindow);
@ -108,6 +111,9 @@ class OptionsDlg extends GuiImage {
gfxFull.pressedAction = (sender) -> { gfxFull.pressedAction = (sender) -> {
updateWindowFunc(gfxFull); updateWindowFunc(gfxFull);
} }
if (Settings.optionsSettings.isFullScreen) {
gfxFull.pressed = true;
}
graphicsPane.addChild(gfxFull); graphicsPane.addChild(gfxFull);
windowBoxes.push(gfxFull); windowBoxes.push(gfxFull);
@ -136,6 +142,8 @@ class OptionsDlg extends GuiImage {
updateResolutionFunc(gfx640480); updateResolutionFunc(gfx640480);
} }
graphicsPane.addChild(gfx640480); graphicsPane.addChild(gfx640480);
if (Settings.optionsSettings.screenWidth == 640)
gfx640480.pressed = true;
var gfx800600 = new GuiButton(loadButtonImages("data/ui/options/graf800")); var gfx800600 = new GuiButton(loadButtonImages("data/ui/options/graf800"));
gfx800600.position = new Vector(237, 0); gfx800600.position = new Vector(237, 0);
@ -146,16 +154,19 @@ class OptionsDlg extends GuiImage {
updateResolutionFunc(gfx800600); updateResolutionFunc(gfx800600);
} }
graphicsPane.addChild(gfx800600); graphicsPane.addChild(gfx800600);
if (Settings.optionsSettings.screenWidth == 800)
gfx800600.pressed = true;
var gfx1024768 = new GuiButton(loadButtonImages("data/ui/options/graf1024")); var gfx1024768 = new GuiButton(loadButtonImages("data/ui/options/graf1024"));
gfx1024768.position = new Vector(320, -1); gfx1024768.position = new Vector(320, -1);
gfx1024768.extent = new Vector(94, 51); gfx1024768.extent = new Vector(94, 51);
gfx1024768.buttonType = Toggle; gfx1024768.buttonType = Toggle;
gfx1024768.pressed = true;
resolutionBoxes.push(gfx1024768); resolutionBoxes.push(gfx1024768);
gfx1024768.pressedAction = (sender) -> { gfx1024768.pressedAction = (sender) -> {
updateResolutionFunc(gfx1024768); updateResolutionFunc(gfx1024768);
} }
if (Settings.optionsSettings.screenWidth == 1024)
gfx1024768.pressed = true;
graphicsPane.addChild(gfx1024768); graphicsPane.addChild(gfx1024768);
var driverBoxes = []; var driverBoxes = [];
@ -171,11 +182,13 @@ class OptionsDlg extends GuiImage {
gfxopengl.position = new Vector(165, 58); gfxopengl.position = new Vector(165, 58);
gfxopengl.extent = new Vector(97, 54); gfxopengl.extent = new Vector(97, 54);
gfxopengl.buttonType = Toggle; gfxopengl.buttonType = Toggle;
gfxopengl.pressed = true;
driverBoxes.push(gfxopengl); driverBoxes.push(gfxopengl);
gfxopengl.pressedAction = (sender) -> { gfxopengl.pressedAction = (sender) -> {
updateDriverFunc(gfxopengl); updateDriverFunc(gfxopengl);
} }
if (Settings.optionsSettings.videoDriver == 0) {
gfxopengl.pressed = true;
}
graphicsPane.addChild(gfxopengl); graphicsPane.addChild(gfxopengl);
var gfxd3d = new GuiButton(loadButtonImages("data/ui/options/grafdir3d")); var gfxd3d = new GuiButton(loadButtonImages("data/ui/options/grafdir3d"));
@ -186,11 +199,17 @@ class OptionsDlg extends GuiImage {
gfxd3d.pressedAction = (sender) -> { gfxd3d.pressedAction = (sender) -> {
updateDriverFunc(gfxd3d); updateDriverFunc(gfxd3d);
} }
if (Settings.optionsSettings.videoDriver == 1) {
gfxd3d.pressed = true;
}
graphicsPane.addChild(gfxd3d); graphicsPane.addChild(gfxd3d);
var applyFunc:Void->Void;
var applyButton = new GuiButton(loadButtonImages("data/ui/options/grafapply")); var applyButton = new GuiButton(loadButtonImages("data/ui/options/grafapply"));
applyButton.position = new Vector(188, 239); applyButton.position = new Vector(188, 239);
applyButton.extent = new Vector(106, 60); applyButton.extent = new Vector(106, 60);
applyButton.pressedAction = (sender) -> applyFunc();
graphicsPane.addChild(applyButton); graphicsPane.addChild(applyButton);
var bitBoxes = []; var bitBoxes = [];
@ -210,17 +229,22 @@ class OptionsDlg extends GuiImage {
gfx16.pressedAction = (sender) -> { gfx16.pressedAction = (sender) -> {
updateBitsFunc(gfx16); updateBitsFunc(gfx16);
} }
if (Settings.optionsSettings.colorDepth == 0) {
gfx16.pressed = true;
}
graphicsPane.addChild(gfx16); graphicsPane.addChild(gfx16);
var gfx32 = new GuiButton(loadButtonImages("data/ui/options/graf32bt")); var gfx32 = new GuiButton(loadButtonImages("data/ui/options/graf32bt"));
gfx32.position = new Vector(272, 174); gfx32.position = new Vector(272, 174);
gfx32.extent = new Vector(84, 51); gfx32.extent = new Vector(84, 51);
gfx32.buttonType = Toggle; gfx32.buttonType = Toggle;
gfx32.pressed = true;
bitBoxes.push(gfx32); bitBoxes.push(gfx32);
gfx32.pressedAction = (sender) -> { gfx32.pressedAction = (sender) -> {
updateBitsFunc(gfx32); updateBitsFunc(gfx32);
} }
if (Settings.optionsSettings.colorDepth == 1) {
gfx32.pressed = true;
}
graphicsPane.addChild(gfx32); graphicsPane.addChild(gfx32);
var shadowsButton = new GuiButton(loadButtonImages("data/ui/options/graf_chkbx")); var shadowsButton = new GuiButton(loadButtonImages("data/ui/options/graf_chkbx"));
@ -228,6 +252,39 @@ class OptionsDlg extends GuiImage {
shadowsButton.extent = new Vector(46, 54); shadowsButton.extent = new Vector(46, 54);
shadowsButton.buttonType = Toggle; shadowsButton.buttonType = Toggle;
graphicsPane.addChild(shadowsButton); graphicsPane.addChild(shadowsButton);
if (Settings.optionsSettings.shadows) {
shadowsButton.pressed = true;
}
applyFunc = () -> {
if (gfx640480.pressed) {
Settings.optionsSettings.screenWidth = 640;
Settings.optionsSettings.screenHeight = 480;
}
if (gfx800600.pressed) {
Settings.optionsSettings.screenWidth = 800;
Settings.optionsSettings.screenHeight = 600;
}
if (gfx1024768.pressed) {
Settings.optionsSettings.screenWidth = 1024;
Settings.optionsSettings.screenHeight = 768;
}
if (gfxFull.pressed)
Settings.optionsSettings.isFullScreen = true;
else
Settings.optionsSettings.isFullScreen = false;
if (gfx16.pressed)
Settings.optionsSettings.colorDepth = 0;
else
Settings.optionsSettings.colorDepth = 1;
if (gfxopengl.pressed)
Settings.optionsSettings.videoDriver = 0;
else
Settings.optionsSettings.videoDriver = 1;
Settings.optionsSettings.shadows = shadowsButton.pressed;
Settings.applySettings();
}
// AUDIO PANEL // AUDIO PANEL
@ -249,11 +306,19 @@ class OptionsDlg extends GuiImage {
var audMusKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_mus_knb.png").toTile()); var audMusKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_mus_knb.png").toTile());
audMusKnob.position = new Vector(137, 37); audMusKnob.position = new Vector(137, 37);
audMusKnob.extent = new Vector(250, 34); audMusKnob.extent = new Vector(250, 34);
audMusKnob.sliderValue = Settings.optionsSettings.musicVolume;
audMusKnob.pressedAction = (sender) -> {
Settings.optionsSettings.musicVolume = audMusKnob.sliderValue;
}
audioPane.addChild(audMusKnob); audioPane.addChild(audMusKnob);
var audSndKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_snd_knb.png").toTile()); var audSndKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_snd_knb.png").toTile());
audSndKnob.position = new Vector(137, 95); audSndKnob.position = new Vector(137, 95);
audSndKnob.extent = new Vector(254, 37); audSndKnob.extent = new Vector(254, 37);
audSndKnob.sliderValue = Settings.optionsSettings.soundVolume;
audSndKnob.pressedAction = (sender) -> {
Settings.optionsSettings.soundVolume = audSndKnob.sliderValue;
}
audioPane.addChild(audSndKnob); audioPane.addChild(audSndKnob);
var audTxtWndo = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_txt_wndo.png").toTile()); var audTxtWndo = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_txt_wndo.png").toTile());