mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
basic settings stuff
This commit is contained in:
parent
7d3c373a40
commit
d440165f91
3 changed files with 113 additions and 5 deletions
|
|
@ -15,7 +15,7 @@ class Main extends hxd.App {
|
|||
override function init() {
|
||||
super.init();
|
||||
|
||||
Settings.load();
|
||||
Settings.init();
|
||||
marbleGame = new MarbleGame(s2d, s3d);
|
||||
MarbleGame.canvas.setContent(new MainMenuGui());
|
||||
// world = new MarbleWorld(s3d, s2d, mission);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package src;
|
||||
|
||||
import src.MarbleGame;
|
||||
import hxd.Window;
|
||||
import haxe.DynamicAccess;
|
||||
import sys.io.File;
|
||||
import src.ResourceLoader;
|
||||
|
|
@ -10,9 +12,38 @@ typedef Score = {
|
|||
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 {
|
||||
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) {
|
||||
if (highScores.exists(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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package gui;
|
||||
|
||||
import src.Settings;
|
||||
import src.Marble;
|
||||
import h2d.Tile;
|
||||
import hxd.res.BitmapFont;
|
||||
|
|
@ -94,10 +95,12 @@ class OptionsDlg extends GuiImage {
|
|||
gfxWindow.position = new Vector(174, 116);
|
||||
gfxWindow.extent = new Vector(97, 55);
|
||||
gfxWindow.buttonType = Toggle;
|
||||
gfxWindow.pressed = true;
|
||||
gfxWindow.pressedAction = (sender) -> {
|
||||
updateWindowFunc(gfxWindow);
|
||||
}
|
||||
if (!Settings.optionsSettings.isFullScreen) {
|
||||
gfxWindow.pressed = true;
|
||||
}
|
||||
graphicsPane.addChild(gfxWindow);
|
||||
windowBoxes.push(gfxWindow);
|
||||
|
||||
|
|
@ -108,6 +111,9 @@ class OptionsDlg extends GuiImage {
|
|||
gfxFull.pressedAction = (sender) -> {
|
||||
updateWindowFunc(gfxFull);
|
||||
}
|
||||
if (Settings.optionsSettings.isFullScreen) {
|
||||
gfxFull.pressed = true;
|
||||
}
|
||||
graphicsPane.addChild(gfxFull);
|
||||
windowBoxes.push(gfxFull);
|
||||
|
||||
|
|
@ -136,6 +142,8 @@ class OptionsDlg extends GuiImage {
|
|||
updateResolutionFunc(gfx640480);
|
||||
}
|
||||
graphicsPane.addChild(gfx640480);
|
||||
if (Settings.optionsSettings.screenWidth == 640)
|
||||
gfx640480.pressed = true;
|
||||
|
||||
var gfx800600 = new GuiButton(loadButtonImages("data/ui/options/graf800"));
|
||||
gfx800600.position = new Vector(237, 0);
|
||||
|
|
@ -146,16 +154,19 @@ class OptionsDlg extends GuiImage {
|
|||
updateResolutionFunc(gfx800600);
|
||||
}
|
||||
graphicsPane.addChild(gfx800600);
|
||||
if (Settings.optionsSettings.screenWidth == 800)
|
||||
gfx800600.pressed = true;
|
||||
|
||||
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);
|
||||
}
|
||||
if (Settings.optionsSettings.screenWidth == 1024)
|
||||
gfx1024768.pressed = true;
|
||||
graphicsPane.addChild(gfx1024768);
|
||||
|
||||
var driverBoxes = [];
|
||||
|
|
@ -171,11 +182,13 @@ class OptionsDlg extends GuiImage {
|
|||
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);
|
||||
}
|
||||
if (Settings.optionsSettings.videoDriver == 0) {
|
||||
gfxopengl.pressed = true;
|
||||
}
|
||||
graphicsPane.addChild(gfxopengl);
|
||||
|
||||
var gfxd3d = new GuiButton(loadButtonImages("data/ui/options/grafdir3d"));
|
||||
|
|
@ -186,11 +199,17 @@ class OptionsDlg extends GuiImage {
|
|||
gfxd3d.pressedAction = (sender) -> {
|
||||
updateDriverFunc(gfxd3d);
|
||||
}
|
||||
if (Settings.optionsSettings.videoDriver == 1) {
|
||||
gfxd3d.pressed = true;
|
||||
}
|
||||
graphicsPane.addChild(gfxd3d);
|
||||
|
||||
var applyFunc:Void->Void;
|
||||
|
||||
var applyButton = new GuiButton(loadButtonImages("data/ui/options/grafapply"));
|
||||
applyButton.position = new Vector(188, 239);
|
||||
applyButton.extent = new Vector(106, 60);
|
||||
applyButton.pressedAction = (sender) -> applyFunc();
|
||||
graphicsPane.addChild(applyButton);
|
||||
|
||||
var bitBoxes = [];
|
||||
|
|
@ -210,17 +229,22 @@ class OptionsDlg extends GuiImage {
|
|||
gfx16.pressedAction = (sender) -> {
|
||||
updateBitsFunc(gfx16);
|
||||
}
|
||||
if (Settings.optionsSettings.colorDepth == 0) {
|
||||
gfx16.pressed = true;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (Settings.optionsSettings.colorDepth == 1) {
|
||||
gfx32.pressed = true;
|
||||
}
|
||||
graphicsPane.addChild(gfx32);
|
||||
|
||||
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.buttonType = Toggle;
|
||||
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
|
||||
|
||||
|
|
@ -249,11 +306,19 @@ class OptionsDlg extends GuiImage {
|
|||
var audMusKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_mus_knb.png").toTile());
|
||||
audMusKnob.position = new Vector(137, 37);
|
||||
audMusKnob.extent = new Vector(250, 34);
|
||||
audMusKnob.sliderValue = Settings.optionsSettings.musicVolume;
|
||||
audMusKnob.pressedAction = (sender) -> {
|
||||
Settings.optionsSettings.musicVolume = audMusKnob.sliderValue;
|
||||
}
|
||||
audioPane.addChild(audMusKnob);
|
||||
|
||||
var audSndKnob = new GuiSlider(ResourceLoader.getImage("data/ui/options/aud_snd_knb.png").toTile());
|
||||
audSndKnob.position = new Vector(137, 95);
|
||||
audSndKnob.extent = new Vector(254, 37);
|
||||
audSndKnob.sliderValue = Settings.optionsSettings.soundVolume;
|
||||
audSndKnob.pressedAction = (sender) -> {
|
||||
Settings.optionsSettings.soundVolume = audSndKnob.sliderValue;
|
||||
}
|
||||
audioPane.addChild(audSndKnob);
|
||||
|
||||
var audTxtWndo = new GuiImage(ResourceLoader.getImage("data/ui/options/aud_txt_wndo.png").toTile());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue