Skip to content

Commit

Permalink
Fixed save button placement/scaling for fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
uoy-jb2501 committed May 2, 2022
1 parent f00c7fb commit 0e58148
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions core/src/main/java/io/github/annabeths/UI/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class HUD extends GameObject {

/**
* Constructor for HUD
*
* @param gameController Instance of GameController
*/
public HUD(GameController gameController) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -278,6 +279,7 @@ public static Texture barKnob(Color col) {

/**
* Update the hud. Called once per frame
*
* @param delta time since last frame
*/
@Override
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -536,26 +541,27 @@ 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();
saveSlot2.remove();
saveSlot3.remove();
}


}


/**
* toggles the upgrade menu on or off
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -739,6 +744,7 @@ public void updateShopMenu() {

/**
* Purchases an upgrade
*
* @param upgrade the upgrade to be purchased
*/
void BuyUpgrade(int upgrade) {
Expand Down Expand Up @@ -827,6 +833,7 @@ void RandomiseUpgrades() {

/**
* Resize the HUD
*
* @param width new width
* @param height new height
*/
Expand Down

0 comments on commit 0e58148

Please sign in to comment.