From 0e5814898aa9e9d21499748449f66f2a3bbc0e4b Mon Sep 17 00:00:00 2001 From: James Burnell <94061765+uoy-jb2501@users.noreply.github.com> Date: Mon, 2 May 2022 23:17:05 +0100 Subject: [PATCH] Fixed save button placement/scaling for fullscreen --- .../main/java/io/github/annabeths/UI/HUD.java | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/io/github/annabeths/UI/HUD.java b/core/src/main/java/io/github/annabeths/UI/HUD.java index 7ba5a13..ee5e208 100644 --- a/core/src/main/java/io/github/annabeths/UI/HUD.java +++ b/core/src/main/java/io/github/annabeths/UI/HUD.java @@ -109,6 +109,7 @@ public class HUD extends GameObject { /** * Constructor for HUD + * * @param gameController Instance of GameController */ public HUD(GameController gameController) { @@ -212,8 +213,8 @@ public void setupPowerups() { for (int y = 0; y < 2; y++) { PowerupType pt = powerups.get(i++); powerupIcons.get(pt).setPosition(startX + 125, startY - gap * (y + 1), Align.center); - powerupQuantityLabels.get(pt).setPosition(startX + 30 + 125, startY - gap * (y + 1) - 10, - Align.bottomLeft); + powerupQuantityLabels.get(pt).setPosition(startX + 30 + 125, + startY - gap * (y + 1) - 10, Align.bottomLeft); powerupTimeLabels.get(pt).setBounds(startX - 25 + 125, startY - 25 - gap * (y + 1), 50, 50); } @@ -278,6 +279,7 @@ public static Texture barKnob(Color col) { /** * Update the hud. Called once per frame + * * @param delta time since last frame */ @Override @@ -294,7 +296,8 @@ public void Update(float delta) { boolean f = gc.playerBoat.activePowerups.containsKey(p); i.setColor(f ? Color.DARK_GRAY : Color.WHITE); }); - powerupQuantityLabels.forEach((p, l) -> l.setText("x" + gc.playerBoat.collectedPowerups.getOrDefault(p, 0))); + powerupQuantityLabels.forEach( + (p, l) -> l.setText("x" + gc.playerBoat.collectedPowerups.getOrDefault(p, 0))); powerupTimeLabels.forEach((p, l) -> { float t = gc.playerBoat.activePowerups.getOrDefault(p, 0f); if (t > 0) {// add label if powerup is active @@ -333,6 +336,7 @@ public static String generateTimeString(int seconds) { /** * Draw the hud. called once per frame + * * @param batch Spritebatch to draw the HUD */ @Override @@ -351,19 +355,19 @@ public void Draw(SpriteBatch batch) { /** * Updates the state of the save menu. */ - public void updateSaveMenu(){ + public void updateSaveMenu() { String slot1Text = "Slot 1"; String slot2Text = "Slot 2"; String slot3Text = "Slot 3"; - if(!SaveManager.doesSaveFileExist("save0")){ + if (!SaveManager.doesSaveFileExist("save0")) { slot1Text += " [Empty]"; } - if(!SaveManager.doesSaveFileExist("save1")){ + if (!SaveManager.doesSaveFileExist("save1")) { slot2Text += " [Empty]"; } - if(!SaveManager.doesSaveFileExist("save2")){ + if (!SaveManager.doesSaveFileExist("save2")) { slot3Text += " [Empty]"; } saveSlot1.setText(slot1Text); @@ -374,12 +378,10 @@ public void updateSaveMenu(){ /** * Sets up the SaveMenu. */ - public void setUpSaveMenu(){ + public void setUpSaveMenu() { saveMenuBackground = new Image(getTexture("ui/background.png")); - - saveMenuBackground.addListener(new ClickListener() { @Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { @@ -428,13 +430,13 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor fromActo String slot2Text = "Slot 2"; String slot3Text = "Slot 3"; - if(!SaveManager.doesSaveFileExist("save0")){ + if (!SaveManager.doesSaveFileExist("save0")) { slot1Text += " [Empty]"; } - if(!SaveManager.doesSaveFileExist("save1")){ + if (!SaveManager.doesSaveFileExist("save1")) { slot2Text += " [Empty]"; } - if(!SaveManager.doesSaveFileExist("save2")){ + if (!SaveManager.doesSaveFileExist("save2")) { slot3Text += " [Empty]"; } saveSlot1 = new TextButton(slot1Text, upgradeButtonStyle); @@ -444,13 +446,17 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor fromActo saveMenuInitialized = true; // shopButton.setPosition(1655, 16); - saveButton.setBounds(250, Gdx.graphics.getHeight()*2 - 437, 286, 75); - saveMenuBackground.setBounds(168, Gdx.graphics.getHeight()-260, 189, 200); - - - saveSlot1.setBounds(saveMenuBackground.getX(), saveMenuBackground.getY() + 2*(saveMenuBackground.getHeight()/3) + 4, saveMenuBackground.getWidth(), saveMenuBackground.getHeight()/3); - saveSlot2.setBounds(saveMenuBackground.getX(), saveMenuBackground.getY() + (saveMenuBackground.getHeight()/3) + 2, saveMenuBackground.getWidth(), saveMenuBackground.getHeight()/3); - saveSlot3.setBounds(saveMenuBackground.getX(), saveMenuBackground.getY(), saveMenuBackground.getWidth(), saveMenuBackground.getHeight()/3); + saveButton.setBounds(250, 1080 - 75, 286, 75); + saveMenuBackground.setBounds(252, 1080 - 280, 282, 200); + + saveSlot1.setBounds(saveMenuBackground.getX(), + saveMenuBackground.getY() + 2 * (saveMenuBackground.getHeight() / 3) + 4, + saveMenuBackground.getWidth(), saveMenuBackground.getHeight() / 3); + saveSlot2.setBounds(saveMenuBackground.getX(), + saveMenuBackground.getY() + (saveMenuBackground.getHeight() / 3) + 2, + saveMenuBackground.getWidth(), saveMenuBackground.getHeight() / 3); + saveSlot3.setBounds(saveMenuBackground.getX(), saveMenuBackground.getY(), + saveMenuBackground.getWidth(), saveMenuBackground.getHeight() / 3); setUpSaveSlotButton(saveSlot1, "save0"); setUpSaveSlotButton(saveSlot2, "save1"); @@ -462,10 +468,11 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor fromActo /** * defines behaviour for a save slot button + * * @param button the button * @param saveSlot the save slot to write to */ - public void setUpSaveSlotButton(TextButton button, String saveSlot){ + public void setUpSaveSlotButton(TextButton button, String saveSlot) { button.addListener(new ClickListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { @@ -490,12 +497,10 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor fromActo }); } - /** Set up the shop button on the HUD */ public void setupShopButton() { shopButton = new TextButton("Shop", shopButtonStyle); - TextTooltip tip = new TextTooltip(" Buy upgrades with plunder and experience! ", toolTipStyle); tip.setInstant(true); @@ -536,15 +541,18 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor fromActo */ public void toggleSaveMenu() { saveMenuOpen = !saveMenuOpen; - if (!saveMenuInitialized) {setUpSaveMenu();}else{ updateSaveMenu();} - + if (!saveMenuInitialized) { + setUpSaveMenu(); + } else { + updateSaveMenu(); + } if (saveMenuOpen) { - //updateSaveMenu(); - stage.addActor(saveMenuBackground); - stage.addActor(saveSlot1); - stage.addActor(saveSlot2); - stage.addActor(saveSlot3); + // updateSaveMenu(); + hudGroup.addActor(saveMenuBackground); + hudGroup.addActor(saveSlot1); + hudGroup.addActor(saveSlot2); + hudGroup.addActor(saveSlot3); } else { saveMenuBackground.remove(); saveSlot1.remove(); @@ -552,10 +560,8 @@ public void toggleSaveMenu() { saveSlot3.remove(); } - } - /** * toggles the upgrade menu on or off */ @@ -592,7 +598,6 @@ public void setupShopMenu() { Gdx.graphics.getWidth() / 2f - upgradeMenuBackground.getWidth() / 2f, Gdx.graphics.getHeight() / 2f - upgradeMenuBackground.getHeight() / 2f); - upgradeMenuBackground.setPosition( Gdx.graphics.getWidth() / 2f - upgradeMenuBackground.getWidth() / 2f, Gdx.graphics.getHeight() / 2f - upgradeMenuBackground.getHeight() / 2f); @@ -739,6 +744,7 @@ public void updateShopMenu() { /** * Purchases an upgrade + * * @param upgrade the upgrade to be purchased */ void BuyUpgrade(int upgrade) { @@ -827,6 +833,7 @@ void RandomiseUpgrades() { /** * Resize the HUD + * * @param width new width * @param height new height */