Skip to content

Commit

Permalink
Merge branch 'team-2-ui' into Team-2-sound
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Oct 2, 2023
2 parents a08a11f + eeaefbf commit b2e84e2
Show file tree
Hide file tree
Showing 25 changed files with 763 additions and 211 deletions.
199 changes: 199 additions & 0 deletions source/core/assets/images/ui/buttons/dot_gothic_32.fnt

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 87 additions & 94 deletions source/core/assets/images/ui/buttons/glass.atlas

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions source/core/assets/images/ui/buttons/glass.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
{
com.badlogic.gdx.graphics.g2d.BitmapFont: {
dot_gothic_16: {
font_small: {
file: dot_gothic_16.fnt
scaledSize: -1
markupEnabled: false
flip: false
}
Toriko: {
file: Toriko.fnt
scaledSize: 18
markupEnabled: false
flip: false
}
Toriko1: {
file: Toriko(1).fnt
scaledSize: 18
title: {
file: dot_gothic_32.fnt
scaledSize: -1
markupEnabled: false
flip: false
}
Expand Down Expand Up @@ -69,7 +63,7 @@ com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle: {
com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton$ImageTextButtonStyle: {
default: {
parent: default
font: dot_gothic_16
font: font_small
fontColor: White
downFontColor: Blue
overFontColor: White
Expand All @@ -89,13 +83,18 @@ com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton$ImageTextButtonStyle: {
}
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: {
font: dot_gothic_16
font: title
fontColor: White
}
title: {
parent: default
font: title
fontColor: White
}
}
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
default: {
font: dot_gothic_16
font: font_small
fontColorSelected: White
fontColorUnselected: Grey
selection: UI_Glass_Banner_01a
Expand Down Expand Up @@ -124,7 +123,7 @@ com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
}
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
default: {
font: dot_gothic_16
font: font_small
fontColor: Grey
overFontColor: White
disabledFontColor: Grey
Expand All @@ -144,7 +143,7 @@ com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: {
parent: default
font: dot_gothic_16
font: font_small
fontColor: Grey
downFontColor: White
overFontColor: White
Expand Down Expand Up @@ -174,7 +173,7 @@ com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
default: {
background: UI_Glass_Frame_Standard_01a
titleFont: dot_gothic_16
titleFont: font_small
titleFontColor: White
stageBackground: UI_Glass_Frame_Standard_01a
}
Expand Down
Binary file modified source/core/assets/images/ui/buttons/glass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 23 additions & 8 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.csse3200.game.components.ProjectileEffects;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.*;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.screens.AssetLoader;
import com.csse3200.game.utils.math.RandomUtils;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -27,7 +29,9 @@
import java.security.SecureRandom;
import java.util.Random;
import java.util.Timer;
import static com.csse3200.game.entities.factories.NPCFactory.createGhost;
import static com.csse3200.game.screens.AssetLoader.loadAllAssets;
import java.util.ArrayList;
import java.util.TimerTask;

/** Forest area for the demo game with trees, a player, and some enemies. */
Expand All @@ -37,7 +41,7 @@ public class ForestGameArea extends GameArea {
private static final int NUM_GHOSTS = 0;
private static final int NUM_GRUNTS = 5;
private static final int NUM_BOSS = 4;

private AssetLoader assetLoader;

private static final int NUM_MOBBOSS2=3;
private static final int NUM_MOBBOSS1=1;
Expand Down Expand Up @@ -213,6 +217,7 @@ public class ForestGameArea extends GameArea {
"sounds/mobBoss/patrickHit.mp3"
};
private static final String backgroundMusic = "sounds/background/Sci-Fi1.ogg";

private static final String[] forestMusic = {backgroundMusic};

private Entity player;
Expand All @@ -232,6 +237,9 @@ public class ForestGameArea extends GameArea {
public ForestGameArea() {
super();
}
public void setAssetLoader(AssetLoader assetLoader) {
this.assetLoader = assetLoader;
}

/**
* Add this method to start the wave spawning timer when the game starts.
Expand Down Expand Up @@ -721,7 +729,14 @@ private void spawnDroidTower() {
spawnEntityAt(weaponTower, randomPos, true, false);
}
}


private void playMusic() {
Music music = ServiceLocator.getResourceService().getAsset(backgroundMusic, Music.class);
music.setLooping(true);
music.setVolume(0.3f);
music.play();
}

private void loadAssets() {
logger.debug("Loading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
Expand All @@ -738,11 +753,11 @@ private void loadAssets() {

private void unloadAssets() {
logger.debug("Unloading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
resourceService.unloadAssets(forestTextures);
resourceService.unloadAssets(forestTextureAtlases);
resourceService.unloadAssets(forestSounds);
resourceService.unloadAssets(forestMusic);
if (assetLoader != null) {
AssetLoader.unloadAllAssets(); // Use the AssetLoader to unload assets if it's not null
} else {
logger.error("AssetLoader is not set. Cannot unload assets.");
}
}

@Override
Expand Down Expand Up @@ -792,4 +807,4 @@ private void spawnGapScanners() {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class CurrencyDisplay extends UIComponent {
private TextButton scrapsTb;
private TextButton crystalsTb;
private Sound clickSound;
private Sound buildSound;
private TextButton test;

/**
Expand All @@ -39,7 +38,6 @@ public class CurrencyDisplay extends UIComponent {
public void create() {
super.create();
clickSound = ServiceLocator.getResourceService().getAsset("sounds/economy/click.wav", Sound.class);
buildSound = ServiceLocator.getResourceService().getAsset("sounds/economy/buildSound.ogg", Sound.class);
addActors();
}

Expand Down Expand Up @@ -120,9 +118,6 @@ public void currencyPopUp(float x , float y, int amount, int offset) {
clickSound.setVolume(soundId, 0.4f);
label = new Label(String.format("+%d", amount), skin);
} else {
// play sound and set the volume
long soundId = buildSound.play();
buildSound.setVolume(soundId, 0.4f);
label = new Label(String.format("%d", amount), skin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ public void create() {
Image[] towers2 = new Image[2]; // Create an array for two towers
Image[] towers3 = new Image[3]; // Create an array for two towers


// for (int i = 0; i < 2; i++) {
// // Use "building1" for the first tower and "building2" for the second tower
// skin.add("default", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
// skin.add("building1", new Texture("images/towers/WallTower.png"));
// skin.add("building1", new Texture("images/towers/wallTower.png"));
// // Load textures for building1 and building2
// towers1[i] = new Image(skin, "building1");
// towers1[i].setBounds(Gdx.graphics.getWidth() * 40f / 100f, Gdx.graphics.getHeight() * 80f / 100f, 100, 100);
Expand Down Expand Up @@ -131,7 +130,7 @@ public void create() {
// for (int i = 0; i < 2; i++) {
// // Use "building1" for the first tower and "building2" for the second tower
// skin.add("default", new Label.LabelStyle(new BitmapFont(), Color.WHITE));
// skin.add("building2", new Texture("images/towers/WallTower.png"));
// skin.add("building2", new Texture("images/towers/wallTower.png"));
// towers2[i] = new Image(skin, "building2");
// towers2[i].setBounds(Gdx.graphics.getWidth() * 50f / 100f, Gdx.graphics.getHeight() * 80f / 100f, 100, 100);
// stage.addActor(towers2[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand All @@ -8,6 +9,7 @@
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.PauseMenuFactory;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,8 +21,12 @@ public class MainGamePauseDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class);
private static final float Z_INDEX = 2f;
private Table table;

private GdxGame game;
private final String[] sounds = {
"sounds/ui/Open_Close/NA_SFUI_Vol1_Open_01.ogg"
};
private Sound openSound;


public MainGamePauseDisplay(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
Expand All @@ -30,6 +36,7 @@ public MainGamePauseDisplay(GdxGame screenSwitchHandle) {
public void create() {
super.create();
addActors();
loadSounds();
}

private void addActors() {
Expand All @@ -45,7 +52,10 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Pause button clicked");
PauseMenuFactory.createPauseMenu(game, false);
openSound.play(0.4f);
// PauseMenuFactory.createPauseMenu(game, false);
PauseMenuFactory.createPauseMenu(game);

}
});

Expand All @@ -69,4 +79,10 @@ public void dispose() {
table.clear();
super.dispose();
}

public void loadSounds() {
ServiceLocator.getResourceService().loadSounds(sounds);
ServiceLocator.getResourceService().loadAll();
openSound = ServiceLocator.getResourceService().getAsset(sounds[0], Sound.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.GridPoint2;
Expand Down Expand Up @@ -34,13 +35,20 @@ public class UIElementsDisplay extends UIComponent {
private final Table buttonTable = new Table();
private final Table towerTable = new Table();
Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json"));
private String[] sounds = {
"sounds/ui/Click/NA_SFUI_Vol1_Click_01.ogg",
"sounds/ui/Hover/NA_SFUI_Vol1_hover_01.ogg"
};
private Sound click;
private Sound hover;
private TextButton remainingMobsButton = new ButtonFactory().createButton("Mobs left:");
private final TextButton timerButton = new ButtonFactory().createButton("Next wave:");

@Override
public void create() {
super.create();
addActors();
loadSounds();
}

/**
Expand Down Expand Up @@ -88,6 +96,7 @@ private void addActors() {
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 1 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(0));
click.play(0.4f);
}
});

Expand All @@ -98,6 +107,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 2 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(1));
click.play(0.4f);
}
});

Expand All @@ -107,6 +117,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 3 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(2));
click.play(0.4f);
}
});

Expand All @@ -116,6 +127,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 4 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(3));
click.play(0.4f);
}
});

Expand All @@ -125,6 +137,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Tower 5 build button clicked");
ServiceLocator.getCurrencyService().setTowerType(towers.get(4));
click.play(0.4f);
}
});

Expand Down Expand Up @@ -173,6 +186,13 @@ public float getZIndex() {
return Z_INDEX;
}

private void loadSounds() {
ServiceLocator.getResourceService().loadSounds(sounds);
ServiceLocator.getResourceService().loadAll();
click = ServiceLocator.getResourceService().getAsset(sounds[0], Sound.class);
hover = ServiceLocator.getResourceService().getAsset(sounds[1], Sound.class);
}

/**
* Disposes off the tables and buttons created using this display
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ private void addActors() {

// Create an instance of the ButtonFactory class
ButtonFactory buttonFactory = new ButtonFactory();
Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json"));

// Create a "Start" TextButton using the default style
TextButton startBtn = new TextButton("Start", skin);
TextButton startBtn = buttonFactory.createButton("Start");

// Create a "Help" TextButton using the default style
TextButton loadBtn = new TextButton("Help", skin);
TextButton loadBtn = buttonFactory.createButton("Help");

// Create a "Settings" TextButton with a custom image
TextButton settingsBtn = new TextButton("Settings", skin);
TextButton settingsBtn = buttonFactory.createCustomButton("Settings", "images/ui/Sprites/UI_Glass_Button_Large_Lock_01a2.png");

// Create a "Quit" TextButton with a custom image
TextButton exitBtn = new TextButton("Quit", skin);
TextButton exitBtn = buttonFactory.createCustomButton("Quit", "images/ui/Sprites/UI_Glass_Button_Large_Press_01a2.png");

// Triggers an event when the button is pressed
startBtn.addListener(
Expand Down
Loading

0 comments on commit b2e84e2

Please sign in to comment.