minor gui fixes

This commit is contained in:
RandomityGuy 2024-04-29 19:17:34 +05:30
parent bac95e7881
commit 05b0b37e8c
7 changed files with 174 additions and 110 deletions

View file

@ -190,6 +190,13 @@ class Console {
MarbleGame.instance.world.rollback(t); MarbleGame.instance.world.rollback(t);
} else if (cmdType == 'addDummy') { } else if (cmdType == 'addDummy') {
Net.addDummyConnection(); Net.addDummyConnection();
} else if (cmdType == 'setfps') {
var scale = Std.parseFloat(cmdSplit[1]);
if (Math.isNaN(scale))
scale = 1;
MarbleGame.instance.fpsLimit = scale;
MarbleGame.instance.limitingFps = true;
log("Set FPS to " + scale);
} else { } else {
error("Unknown command"); error("Unknown command");
} }

View file

@ -60,6 +60,10 @@ class MarbleGame {
var _mouseWheelDelta:Float; var _mouseWheelDelta:Float;
var _exitingToMenu:Bool = false; var _exitingToMenu:Bool = false;
var fpsLimit:Float = 60;
var limitingFps:Bool = false;
var fpsLimitAccum:Float = 0.0;
public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) { public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) {
Console.log("Initializing the game..."); Console.log("Initializing the game...");
canvas = new Canvas(scene2d, cast this); canvas = new Canvas(scene2d, cast this);
@ -189,6 +193,16 @@ class MarbleGame {
public function update(dt:Float) { public function update(dt:Float) {
MasterServerClient.process(); MasterServerClient.process();
if (limitingFps) {
fpsLimitAccum += dt;
if (fpsLimitAccum < 1.0 / fpsLimit) {
return;
}
fpsLimitAccum -= (1.0 / fpsLimit);
dt = 1.0 / fpsLimit;
}
if (world != null) { if (world != null) {
if (world._disposed) { if (world._disposed) {
world = null; world = null;

View file

@ -26,14 +26,17 @@ class GuiXboxOptionsList extends GuiControl {
var _prevMousePos:Vector; var _prevMousePos:Vector;
var usedGamepad:Bool = false; var usedGamepad:Bool = false;
var enableButtons:Bool = true;
public var selected:Bool = false; public var selected:Bool = false;
public var list:GuiXboxOptionsListCollection; public var list:GuiXboxOptionsListCollection;
public function new(icon:Int, name:String, values:Array<String>, midcolumn:Float = 0.3, textOff = 155.5) { public function new(icon:Int, name:String, values:Array<String>, midcolumn:Float = 0.3, textOff = 155.5, enableButtons:Bool = true) {
super(); super();
this.options = values; this.options = values;
this.enableButtons = enableButtons;
var baseImage = ResourceLoader.getResource("data/ui/xbox/optionsCursorArray.png", ResourceLoader.getImage, this.imageResources).toTile(); var baseImage = ResourceLoader.getResource("data/ui/xbox/optionsCursorArray.png", ResourceLoader.getImage, this.imageResources).toTile();
var inactiveImage = baseImage.sub(0, 2, 815, 94); var inactiveImage = baseImage.sub(0, 2, 815, 94);
@ -65,27 +68,29 @@ class GuiXboxOptionsList extends GuiControl {
var rightShadeFilter = new h2d.filter.ColorMatrix(cmat); var rightShadeFilter = new h2d.filter.ColorMatrix(cmat);
rightShadeFilter.enable = false; rightShadeFilter.enable = false;
leftButton = new GuiAnim([arrowButtonImage, arrowButtonImagePressed]); if (enableButtons) {
leftButton.position = new Vector(815 * midcolumn, 0); leftButton = new GuiAnim([arrowButtonImage, arrowButtonImagePressed]);
leftButton.extent = new Vector(114, 94); leftButton.position = new Vector(815 * midcolumn, 0);
leftButton.anim.filter = leftShadeFilter; leftButton.extent = new Vector(114, 94);
this.addChild(leftButton); leftButton.anim.filter = leftShadeFilter;
this.addChild(leftButton);
var leftButtonIcon = new GuiAnim([leftArrow, leftArrowSelected]); var leftButtonIcon = new GuiAnim([leftArrow, leftArrowSelected]);
leftButtonIcon.position = new Vector(39, 36); leftButtonIcon.position = new Vector(39, 36);
leftButtonIcon.extent = new Vector(22, 22); leftButtonIcon.extent = new Vector(22, 22);
leftButton.addChild(leftButtonIcon); leftButton.addChild(leftButtonIcon);
rightButton = new GuiAnim([arrowButtonImage, arrowButtonImagePressed]); rightButton = new GuiAnim([arrowButtonImage, arrowButtonImagePressed]);
rightButton.position = new Vector(815 * 0.8, 0); rightButton.position = new Vector(815 * 0.8, 0);
rightButton.extent = new Vector(114, 94); rightButton.extent = new Vector(114, 94);
rightButton.anim.filter = rightShadeFilter; rightButton.anim.filter = rightShadeFilter;
this.addChild(rightButton); this.addChild(rightButton);
var rightButtonIcon = new GuiAnim([rightArrow, rightArrowSelected]); var rightButtonIcon = new GuiAnim([rightArrow, rightArrowSelected]);
rightButtonIcon.position = new Vector(52, 36); rightButtonIcon.position = new Vector(52, 36);
rightButtonIcon.extent = new Vector(22, 22); rightButtonIcon.extent = new Vector(22, 22);
rightButton.addChild(rightButtonIcon); rightButton.addChild(rightButtonIcon);
}
var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt"); var arial14fontdata = ResourceLoader.getFileEntry("data/font/Arial Bold.fnt");
var arial14b = new BitmapFont(arial14fontdata.entry); var arial14b = new BitmapFont(arial14fontdata.entry);
@ -148,100 +153,102 @@ class GuiXboxOptionsList extends GuiControl {
optionText.text.textColor = 0x787878; optionText.text.textColor = 0x787878;
} }
} }
var leftBtnRect = leftButton.getHitTestRect(); if (enableButtons) {
leftBtnRect.position = leftBtnRect.position.add(new Vector(15 * Settings.uiScale, 21 * Settings.uiScale)); var leftBtnRect = leftButton.getHitTestRect();
leftBtnRect.extent.set(83 * Settings.uiScale, 53 * Settings.uiScale); leftBtnRect.position = leftBtnRect.position.add(new Vector(15 * Settings.uiScale, 21 * Settings.uiScale));
var rightBtnRect = rightButton.getHitTestRect(); leftBtnRect.extent.set(83 * Settings.uiScale, 53 * Settings.uiScale);
rightBtnRect.position = rightBtnRect.position.add(new Vector(15 * Settings.uiScale, 21 * Settings.uiScale)); var rightBtnRect = rightButton.getHitTestRect();
rightBtnRect.extent.set(83 * Settings.uiScale, 53 * Settings.uiScale); rightBtnRect.position = rightBtnRect.position.add(new Vector(15 * Settings.uiScale, 21 * Settings.uiScale));
if (leftBtnRect.inRect(mouseState.position) || rightBtnRect.inRect(mouseState.position)) { rightBtnRect.extent.set(83 * Settings.uiScale, 53 * Settings.uiScale);
if (Key.isPressed(Key.MOUSE_LEFT)) { if (leftBtnRect.inRect(mouseState.position) || rightBtnRect.inRect(mouseState.position)) {
AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources)); if (Key.isPressed(Key.MOUSE_LEFT)) {
AudioManager.playSound(ResourceLoader.getResource("data/sound/buttonpress.wav", ResourceLoader.getAudio, this.soundResources));
}
} }
} // Left Button
// Left Button if (leftBtnRect.inRect(mouseState.position)) {
if (leftBtnRect.inRect(mouseState.position)) { if (Key.isDown(Key.MOUSE_LEFT)) {
if (Key.isDown(Key.MOUSE_LEFT)) { leftButton.anim.currentFrame = 1;
leftButton.anim.currentFrame = 1; leftButton.anim.filter.enable = true;
leftButton.anim.filter.enable = true; } else {
leftButton.anim.currentFrame = 1;
leftButton.anim.filter.enable = false;
}
if (Key.isReleased(Key.MOUSE_LEFT)) {
var newOption = currentOption - 1;
if (newOption < 0)
newOption = options.length - 1;
var doChange = true;
if (onChangeFunc != null)
doChange = onChangeFunc(newOption);
if (doChange) {
currentOption = newOption;
optionText.text.text = options[currentOption];
}
}
} else { } else {
leftButton.anim.currentFrame = 1; leftButton.anim.currentFrame = 0;
leftButton.anim.filter.enable = false; leftButton.anim.filter.enable = false;
} }
if (Key.isReleased(Key.MOUSE_LEFT)) { // Right Button
var newOption = currentOption - 1; if (rightBtnRect.inRect(mouseState.position)) {
if (newOption < 0) if (Key.isDown(Key.MOUSE_LEFT)) {
newOption = options.length - 1; rightButton.anim.currentFrame = 1;
rightButton.anim.filter.enable = true;
var doChange = true; } else {
if (onChangeFunc != null) rightButton.anim.currentFrame = 1;
doChange = onChangeFunc(newOption); rightButton.anim.filter.enable = false;
if (doChange) { }
currentOption = newOption; if (Key.isReleased(Key.MOUSE_LEFT)) {
optionText.text.text = options[currentOption]; var newOption = currentOption + 1;
if (newOption >= options.length)
newOption = 0;
var doChange = true;
if (onChangeFunc != null)
doChange = onChangeFunc(newOption);
if (doChange) {
currentOption = newOption;
optionText.text.text = options[currentOption];
}
} }
}
} else {
leftButton.anim.currentFrame = 0;
leftButton.anim.filter.enable = false;
}
// Right Button
if (rightBtnRect.inRect(mouseState.position)) {
if (Key.isDown(Key.MOUSE_LEFT)) {
rightButton.anim.currentFrame = 1;
rightButton.anim.filter.enable = true;
} else { } else {
rightButton.anim.currentFrame = 1; rightButton.anim.currentFrame = 0;
rightButton.anim.filter.enable = false; rightButton.anim.filter.enable = false;
} }
if (Key.isReleased(Key.MOUSE_LEFT)) { if (selected || alwaysActive) {
var newOption = currentOption + 1; if (Key.isPressed(Key.LEFT) || Gamepad.isPressed(['dpadLeft']) || (Gamepad.getAxis('analogX') < -0.75 && !usedGamepad)) {
if (newOption >= options.length) var newOption = currentOption - 1;
newOption = 0; if (newOption < 0)
newOption = options.length - 1;
var doChange = true; var doChange = true;
if (onChangeFunc != null) if (onChangeFunc != null)
doChange = onChangeFunc(newOption); doChange = onChangeFunc(newOption);
if (doChange) { if (doChange) {
currentOption = newOption; currentOption = newOption;
optionText.text.text = options[currentOption]; optionText.text.text = options[currentOption];
}
} }
} if (Key.isPressed(Key.RIGHT) || Gamepad.isPressed(['dpadRight']) || (Gamepad.getAxis('analogX') > 0.75 && !usedGamepad)) {
} else { var newOption = currentOption + 1;
rightButton.anim.currentFrame = 0; if (newOption >= options.length)
rightButton.anim.filter.enable = false; newOption = 0;
}
if (selected || alwaysActive) {
if (Key.isPressed(Key.LEFT) || Gamepad.isPressed(['dpadLeft']) || (Gamepad.getAxis('analogX') < -0.75 && !usedGamepad)) {
var newOption = currentOption - 1;
if (newOption < 0)
newOption = options.length - 1;
var doChange = true; var doChange = true;
if (onChangeFunc != null) if (onChangeFunc != null)
doChange = onChangeFunc(newOption); doChange = onChangeFunc(newOption);
if (doChange) { if (doChange) {
currentOption = newOption; currentOption = newOption;
optionText.text.text = options[currentOption]; optionText.text.text = options[currentOption];
}
} }
if (Math.abs(Gamepad.getAxis('analogX')) > 0.75)
usedGamepad = true;
else
usedGamepad = false;
} }
if (Key.isPressed(Key.RIGHT) || Gamepad.isPressed(['dpadRight']) || (Gamepad.getAxis('analogX') > 0.75 && !usedGamepad)) {
var newOption = currentOption + 1;
if (newOption >= options.length)
newOption = 0;
var doChange = true;
if (onChangeFunc != null)
doChange = onChangeFunc(newOption);
if (doChange) {
currentOption = newOption;
optionText.text.text = options[currentOption];
}
}
if (Math.abs(Gamepad.getAxis('analogX')) > 0.75)
usedGamepad = true;
else
usedGamepad = false;
} }
super.update(dt, mouseState); super.update(dt, mouseState);
} }

View file

@ -59,10 +59,20 @@ class MPServerListGui extends GuiImage {
function imgLoader(path:String) { function imgLoader(path:String) {
switch (path) { switch (path) {
case "locked": case "ready":
return ResourceLoader.getResource("data/ui/xbox/DemoOutOfTimeIcon.png", ResourceLoader.getImage, this.imageResources).toTile();
case "unlocked":
return ResourceLoader.getResource("data/ui/xbox/Ready.png", ResourceLoader.getImage, this.imageResources).toTile(); return ResourceLoader.getResource("data/ui/xbox/Ready.png", ResourceLoader.getImage, this.imageResources).toTile();
case "notready":
return ResourceLoader.getResource("data/ui/xbox/NotReady.png", ResourceLoader.getImage, this.imageResources).toTile();
case "pc":
return ResourceLoader.getResource("data/ui/xbox/platform_desktop.png", ResourceLoader.getImage, this.imageResources).toTile();
case "mac":
return ResourceLoader.getResource("data/ui/xbox/platform_mac.png", ResourceLoader.getImage, this.imageResources).toTile();
case "web":
return ResourceLoader.getResource("data/ui/xbox/platform_web.png", ResourceLoader.getImage, this.imageResources).toTile();
case "android":
return ResourceLoader.getResource("data/ui/xbox/platform_android.png", ResourceLoader.getImage, this.imageResources).toTile();
case "unknown":
return ResourceLoader.getResource("data/ui/xbox/platform_unknown.png", ResourceLoader.getImage, this.imageResources).toTile();
} }
return null; return null;
} }
@ -84,9 +94,10 @@ class MPServerListGui extends GuiImage {
serverWnd.addChild(serverList); serverWnd.addChild(serverList);
var ourServerList:Array<RemoteServerInfo> = []; var ourServerList:Array<RemoteServerInfo> = [];
var platformToString = ["unknown", "pc", "mac", "web", "android"];
function updateServerListDisplay() { function updateServerListDisplay() {
serverDisplays = ourServerList.map(x -> x.name); serverDisplays = ourServerList.map(x -> return '<img src="${platformToString[x.platform]}"></img><font color="#101010">${x.name}</font>');
serverList.setTexts(serverDisplays); serverList.setTexts(serverDisplays);
} }

View file

@ -268,7 +268,7 @@ class MultiplayerLevelSelectGui extends GuiImage {
levelWnd.addChild(levelInfoLeft); levelWnd.addChild(levelInfoLeft);
var levelNames = difficultyMissions.map(x -> x.title); var levelNames = difficultyMissions.map(x -> x.title);
var levelSelectOpts = new GuiXboxOptionsList(6, "Level", levelNames); var levelSelectOpts = new GuiXboxOptionsList(6, "Level", levelNames, 0.3, 155.5, isHost);
function setLevel(idx:Int) { function setLevel(idx:Int) {
// if (lock) // if (lock)

View file

@ -75,6 +75,8 @@ class PlayGui {
var playerListContainer:GuiControl; var playerListContainer:GuiControl;
var playerListCtrl:GuiMLTextListCtrl; var playerListCtrl:GuiMLTextListCtrl;
var playerListScoresCtrl:GuiMLTextListCtrl; var playerListScoresCtrl:GuiMLTextListCtrl;
var playerListShadowCtrl:GuiMLTextListCtrl;
var playerListScoresShadowCtrl:GuiMLTextListCtrl;
var playerList:Array<PlayerInfo> = []; var playerList:Array<PlayerInfo> = [];
var imageResources:Array<Resource<Image>> = []; var imageResources:Array<Resource<Image>> = [];
@ -695,9 +697,25 @@ class PlayGui {
// '<font color="#EBEBEB"><img src="them"></img>Player 2 2</font>' // '<font color="#EBEBEB"><img src="them"></img>Player 2 2</font>'
// ]; // ];
var ds = new h2d.filter.DropShadow(1.414, 0.785, 0x000000, 1, 0, 0.4, 1, true); // var ds = new h2d.filter.DropShadow(1.414, 0.785, 0x000000, 1, 0, 0.4, 1, true);
playerListCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader, ds); playerListShadowCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader);
playerListShadowCtrl.position = new Vector(28, 44);
playerListShadowCtrl.extent = new Vector(392, 271);
playerListShadowCtrl.scrollable = true;
playerListShadowCtrl.onSelectedFunc = (sel) -> {}
playerListContainer.addChild(playerListShadowCtrl);
playerListScoresShadowCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader);
playerListScoresShadowCtrl.position = new Vector(278, 44);
playerListScoresShadowCtrl.extent = new Vector(392, 271);
playerListScoresShadowCtrl.scrollable = true;
playerListScoresShadowCtrl.onSelectedFunc = (sel) -> {}
playerListContainer.addChild(playerListScoresShadowCtrl);
playerListCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader);
playerListCtrl.position = new Vector(27, 43); playerListCtrl.position = new Vector(27, 43);
playerListCtrl.extent = new Vector(392, 271); playerListCtrl.extent = new Vector(392, 271);
@ -705,7 +723,7 @@ class PlayGui {
playerListCtrl.onSelectedFunc = (sel) -> {} playerListCtrl.onSelectedFunc = (sel) -> {}
playerListContainer.addChild(playerListCtrl); playerListContainer.addChild(playerListCtrl);
playerListScoresCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader, ds); playerListScoresCtrl = new GuiMLTextListCtrl(arial14, [], imgLoader);
playerListScoresCtrl.position = new Vector(277, 43); playerListScoresCtrl.position = new Vector(277, 43);
playerListScoresCtrl.extent = new Vector(392, 271); playerListScoresCtrl.extent = new Vector(392, 271);
@ -717,13 +735,19 @@ class PlayGui {
public function redrawPlayerList() { public function redrawPlayerList() {
var pl = []; var pl = [];
var plScores = []; var plScores = [];
var plShadow = [];
var plShadowScores = [];
playerList.sort((a, b) -> a.score > b.score ? -1 : (a.score < b.score ? 1 : 0)); playerList.sort((a, b) -> a.score > b.score ? -1 : (a.score < b.score ? 1 : 0));
for (item in playerList) { for (item in playerList) {
pl.push('<font color="#EBEBEB"><img src="${item.us ? "us" : "them"}"></img>${Util.rightPad(item.name, 25, 3)}</font>'); pl.push('<font color="#EBEBEB"><img src="${item.us ? "us" : "them"}"></img>${Util.rightPad(item.name, 25, 3)}</font>');
plScores.push('<font color="#EBEBEB">${item.score}</font>'); plScores.push('<font color="#EBEBEB">${item.score}</font>');
plShadow.push('<font color="#000000"><img src="them"></img>${Util.rightPad(item.name, 25, 3)}</font>');
plShadowScores.push('<font color="#000000">${item.score}</font>');
} }
playerListCtrl.setTexts(pl); playerListCtrl.setTexts(pl);
playerListScoresCtrl.setTexts(plScores); playerListScoresCtrl.setTexts(plScores);
playerListShadowCtrl.setTexts(plShadow);
playerListScoresShadowCtrl.setTexts(plShadowScores);
} }
public function doMPEndGameMessage() { public function doMPEndGameMessage() {

View file

@ -12,7 +12,7 @@ typedef RemoteServerInfo = {
name:String, name:String,
players:Int, players:Int,
maxPlayers:Int, maxPlayers:Int,
platform:String, platform:Int,
} }
class MasterServerClient { class MasterServerClient {
@ -78,7 +78,8 @@ class MasterServerClient {
privateSlots: serverInfo.privateSlots, privateSlots: serverInfo.privateSlots,
privateServer: serverInfo.privateServer, privateServer: serverInfo.privateServer,
inviteCode: serverInfo.inviteCode, inviteCode: serverInfo.inviteCode,
state: serverInfo.state state: serverInfo.state,
platform: serverInfo.platform
})); }));
} }