diff --git a/source/core/assets/configs/text.json b/source/core/assets/configs/text.json new file mode 100644 index 000000000..721a313dc --- /dev/null +++ b/source/core/assets/configs/text.json @@ -0,0 +1,7 @@ +{ + "com.badlogic.gdx.graphics.g2d.BitmapFont": { + "default": { + "file": "images/ui/font.fnt" + } + } +} diff --git a/source/core/assets/images/ui/Button_Bg.png b/source/core/assets/images/ui/Button_Bg.png new file mode 100644 index 000000000..71e133831 Binary files /dev/null and b/source/core/assets/images/ui/Button_Bg.png differ diff --git a/source/core/assets/images/ui/font.fnt b/source/core/assets/images/ui/font.fnt new file mode 100644 index 000000000..1c8e0fa9d --- /dev/null +++ b/source/core/assets/images/ui/font.fnt @@ -0,0 +1,99 @@ +info face="Times New Roman" size=-32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0 +common lineHeight=37 base=29 scaleW=256 scaleH=128 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 +page id=0 file="font.png" +chars count=95 +char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=8 page=0 chnl=15 +char id=33 x=251 y=20 width=4 height=23 xoffset=4 yoffset=6 xadvance=12 page=0 chnl=15 +char id=34 x=47 y=96 width=9 height=10 xoffset=2 yoffset=6 xadvance=13 page=0 chnl=15 +char id=35 x=151 y=15 width=15 height=23 xoffset=1 yoffset=6 xadvance=17 page=0 chnl=15 +char id=36 x=169 y=77 width=13 height=26 xoffset=2 yoffset=5 xadvance=17 page=0 chnl=15 +char id=37 x=0 y=82 width=25 height=24 xoffset=1 yoffset=6 xadvance=27 page=0 chnl=15 +char id=38 x=21 y=53 width=23 height=24 xoffset=1 yoffset=6 xadvance=25 page=0 chnl=15 +char id=39 x=61 y=96 width=3 height=10 xoffset=1 yoffset=6 xadvance=5 page=0 chnl=15 +char id=40 x=218 y=37 width=9 height=30 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15 +char id=41 x=225 y=67 width=9 height=30 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=42 x=232 y=0 width=11 height=13 xoffset=2 yoffset=6 xadvance=15 page=0 chnl=15 +char id=43 x=155 y=105 width=17 height=18 xoffset=1 yoffset=10 xadvance=19 page=0 chnl=15 +char id=44 x=56 y=96 width=5 height=9 xoffset=1 yoffset=25 xadvance=8 page=0 chnl=15 +char id=45 x=52 y=24 width=8 height=3 xoffset=1 yoffset=20 xadvance=10 page=0 chnl=15 +char id=46 x=38 y=77 width=3 height=4 xoffset=2 yoffset=25 xadvance=7 page=0 chnl=15 +char id=47 x=198 y=100 width=9 height=23 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15 +char id=48 x=166 y=15 width=14 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=49 x=206 y=15 width=10 height=22 xoffset=3 yoffset=7 xadvance=16 page=0 chnl=15 +char id=50 x=141 y=82 width=15 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=51 x=156 y=82 width=13 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=52 x=160 y=38 width=14 height=22 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=15 +char id=53 x=184 y=55 width=13 height=22 xoffset=2 yoffset=7 xadvance=16 page=0 chnl=15 +char id=54 x=180 y=15 width=13 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=55 x=141 y=105 width=14 height=22 xoffset=1 yoffset=7 xadvance=16 page=0 chnl=15 +char id=56 x=186 y=100 width=12 height=23 xoffset=2 yoffset=6 xadvance=16 page=0 chnl=15 +char id=57 x=182 y=77 width=13 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=58 x=236 y=13 width=3 height=15 xoffset=3 yoffset=14 xadvance=9 page=0 chnl=15 +char id=59 x=251 y=0 width=5 height=20 xoffset=2 yoffset=14 xadvance=9 page=0 chnl=15 +char id=60 x=167 y=60 width=17 height=17 xoffset=1 yoffset=10 xadvance=19 page=0 chnl=15 +char id=61 x=29 y=22 width=17 height=7 xoffset=1 yoffset=15 xadvance=19 page=0 chnl=15 +char id=62 x=174 y=38 width=17 height=17 xoffset=1 yoffset=10 xadvance=19 page=0 chnl=15 +char id=63 x=195 y=77 width=12 height=23 xoffset=1 yoffset=6 xadvance=14 page=0 chnl=15 +char id=64 x=0 y=0 width=29 height=30 xoffset=1 yoffset=6 xadvance=30 page=0 chnl=15 +char id=65 x=0 y=106 width=24 height=22 xoffset=-1 yoffset=7 xadvance=23 page=0 chnl=15 +char id=66 x=71 y=95 width=20 height=22 xoffset=0 yoffset=7 xadvance=22 page=0 chnl=15 +char id=67 x=70 y=71 width=20 height=24 xoffset=1 yoffset=6 xadvance=21 page=0 chnl=15 +char id=68 x=47 y=74 width=23 height=22 xoffset=0 yoffset=7 xadvance=24 page=0 chnl=15 +char id=69 x=90 y=71 width=20 height=22 xoffset=0 yoffset=7 xadvance=20 page=0 chnl=15 +char id=70 x=111 y=44 width=17 height=22 xoffset=0 yoffset=7 xadvance=18 page=0 chnl=15 +char id=71 x=25 y=82 width=22 height=24 xoffset=1 yoffset=6 xadvance=23 page=0 chnl=15 +char id=72 x=48 y=106 width=23 height=22 xoffset=0 yoffset=7 xadvance=24 page=0 chnl=15 +char id=73 x=216 y=15 width=10 height=22 xoffset=0 yoffset=7 xadvance=11 page=0 chnl=15 +char id=74 x=197 y=53 width=12 height=23 xoffset=0 yoffset=7 xadvance=12 page=0 chnl=15 +char id=75 x=24 y=106 width=24 height=22 xoffset=0 yoffset=7 xadvance=24 page=0 chnl=15 +char id=76 x=91 y=46 width=20 height=22 xoffset=0 yoffset=7 xadvance=20 page=0 chnl=15 +char id=77 x=29 y=0 width=28 height=22 xoffset=0 yoffset=7 xadvance=29 page=0 chnl=15 +char id=78 x=57 y=0 width=24 height=22 xoffset=-1 yoffset=7 xadvance=23 page=0 chnl=15 +char id=79 x=78 y=22 width=21 height=24 xoffset=1 yoffset=6 xadvance=23 page=0 chnl=15 +char id=80 x=118 y=22 width=17 height=22 xoffset=0 yoffset=7 xadvance=18 page=0 chnl=15 +char id=81 x=0 y=53 width=21 height=29 xoffset=1 yoffset=6 xadvance=23 page=0 chnl=15 +char id=82 x=81 y=0 width=22 height=22 xoffset=0 yoffset=7 xadvance=21 page=0 chnl=15 +char id=83 x=172 y=103 width=14 height=24 xoffset=2 yoffset=6 xadvance=18 page=0 chnl=15 +char id=84 x=103 y=0 width=18 height=22 xoffset=1 yoffset=7 xadvance=19 page=0 chnl=15 +char id=85 x=30 y=29 width=24 height=23 xoffset=-1 yoffset=7 xadvance=22 page=0 chnl=15 +char id=86 x=44 y=52 width=24 height=22 xoffset=0 yoffset=7 xadvance=24 page=0 chnl=15 +char id=87 x=0 y=30 width=30 height=23 xoffset=0 yoffset=7 xadvance=30 page=0 chnl=15 +char id=88 x=54 y=27 width=24 height=22 xoffset=0 yoffset=7 xadvance=24 page=0 chnl=15 +char id=89 x=68 y=49 width=23 height=22 xoffset=0 yoffset=7 xadvance=23 page=0 chnl=15 +char id=90 x=99 y=22 width=19 height=22 xoffset=0 yoffset=7 xadvance=20 page=0 chnl=15 +char id=91 x=227 y=30 width=8 height=29 xoffset=3 yoffset=7 xadvance=12 page=0 chnl=15 +char id=92 x=209 y=53 width=9 height=23 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15 +char id=93 x=234 y=59 width=8 height=29 xoffset=1 yoffset=7 xadvance=12 page=0 chnl=15 +char id=94 x=91 y=116 width=15 height=12 xoffset=0 yoffset=6 xadvance=15 page=0 chnl=15 +char id=95 x=52 y=22 width=17 height=2 xoffset=0 yoffset=35 xadvance=17 page=0 chnl=15 +char id=96 x=46 y=22 width=6 height=6 xoffset=1 yoffset=6 xadvance=11 page=0 chnl=15 +char id=97 x=195 y=0 width=13 height=15 xoffset=1 yoffset=14 xadvance=15 page=0 chnl=15 +char id=98 x=128 y=44 width=16 height=23 xoffset=-1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=99 x=208 y=0 width=12 height=15 xoffset=1 yoffset=14 xadvance=14 page=0 chnl=15 +char id=100 x=135 y=15 width=16 height=23 xoffset=1 yoffset=6 xadvance=16 page=0 chnl=15 +char id=101 x=220 y=0 width=12 height=15 xoffset=1 yoffset=14 xadvance=14 page=0 chnl=15 +char id=102 x=193 y=15 width=13 height=23 xoffset=1 yoffset=6 xadvance=10 page=0 chnl=15 +char id=103 x=152 y=60 width=15 height=22 xoffset=1 yoffset=14 xadvance=16 page=0 chnl=15 +char id=104 x=91 y=93 width=17 height=23 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=105 x=243 y=0 width=8 height=23 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15 +char id=106 x=229 y=97 width=9 height=30 xoffset=-3 yoffset=6 xadvance=9 page=0 chnl=15 +char id=107 x=108 y=93 width=17 height=23 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=108 x=235 y=30 width=9 height=23 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15 +char id=109 x=110 y=68 width=25 height=15 xoffset=0 yoffset=14 xadvance=24 page=0 chnl=15 +char id=110 x=145 y=0 width=17 height=15 xoffset=0 yoffset=14 xadvance=16 page=0 chnl=15 +char id=111 x=191 y=38 width=14 height=15 xoffset=1 yoffset=14 xadvance=16 page=0 chnl=15 +char id=112 x=125 y=83 width=16 height=22 xoffset=-1 yoffset=14 xadvance=16 page=0 chnl=15 +char id=113 x=125 y=105 width=16 height=22 xoffset=1 yoffset=14 xadvance=16 page=0 chnl=15 +char id=114 x=217 y=107 width=12 height=15 xoffset=0 yoffset=14 xadvance=11 page=0 chnl=15 +char id=115 x=226 y=15 width=10 height=15 xoffset=2 yoffset=14 xadvance=13 page=0 chnl=15 +char id=116 x=207 y=107 width=10 height=20 xoffset=0 yoffset=9 xadvance=10 page=0 chnl=15 +char id=117 x=135 y=67 width=17 height=15 xoffset=-1 yoffset=14 xadvance=15 page=0 chnl=15 +char id=118 x=162 y=0 width=17 height=15 xoffset=-1 yoffset=14 xadvance=16 page=0 chnl=15 +char id=119 x=121 y=0 width=24 height=15 xoffset=0 yoffset=14 xadvance=23 page=0 chnl=15 +char id=120 x=179 y=0 width=16 height=15 xoffset=0 yoffset=14 xadvance=16 page=0 chnl=15 +char id=121 x=144 y=38 width=16 height=22 xoffset=0 yoffset=14 xadvance=16 page=0 chnl=15 +char id=122 x=205 y=38 width=13 height=15 xoffset=1 yoffset=14 xadvance=15 page=0 chnl=15 +char id=123 x=207 y=76 width=9 height=31 xoffset=4 yoffset=6 xadvance=15 page=0 chnl=15 +char id=124 x=238 y=88 width=2 height=30 xoffset=2 yoffset=6 xadvance=7 page=0 chnl=15 +char id=125 x=216 y=76 width=9 height=31 xoffset=3 yoffset=6 xadvance=16 page=0 chnl=15 +char id=126 x=21 y=77 width=17 height=5 xoffset=1 yoffset=18 xadvance=18 page=0 chnl=15 diff --git a/source/core/assets/images/ui/font.png b/source/core/assets/images/ui/font.png new file mode 100644 index 000000000..628b02462 Binary files /dev/null and b/source/core/assets/images/ui/font.png differ diff --git a/source/core/assets/images/ui/mouse_effect.png b/source/core/assets/images/ui/mouse_effect.png new file mode 100644 index 000000000..74d1ebce2 Binary files /dev/null and b/source/core/assets/images/ui/mouse_effect.png differ diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 138e0e6d9..30a2b5234 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -12,6 +12,7 @@ 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.GameEndService; @@ -24,6 +25,7 @@ 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; @@ -35,7 +37,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_BOSSKING2=3; private static final int NUM_BOSSKING1=1; @@ -49,118 +51,8 @@ public class ForestGameArea extends GameArea { private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 0); // Temporary spawn point for testing private static final float WALL_WIDTH = 0.1f; - - // Required to load assets before using them - private static final String[] forestTextures = { - "images/desert_bg.png", - "images/ice_bg.png", - "images/lava_bg.png", - "images/projectiles/projectile.png", - "images/ingamebg.png", - "images/box_boy_leaf.png", - "images/background/building1.png", - "images/ghost_1.png", - "images/grass_2.png", - "images/grass_3.png", - "images/hex_grass_1.png", - "images/background/mountain.png", - "images/ghost_king.png", - "images/ghost_1.png", - "images/terrain 2 normal.png", - "images/terrain 2 hex.png", - "images/hex_grass_2.png", - "images/hex_grass_3.png", - "images/iso_grass_1.png", - "images/iso_grass_2.png", - "images/iso_grass_3.png", - "images/towers/turret.png", - "images/towers/turret01.png", - "images/towers/turret_deployed.png", - "images/towers/fire_tower_atlas.png", - "images/towers/stun_tower.png", - "images/background/building2.png", - "images/mobs/robot.png", - "images/mobs/boss2.png", - "images/mobs/Attack_1.png", - "images/mobs/Attack_2.png", - "images/mobs/Charge_1.png", - "images/mobs/Charge_2.png", - "images/mobs/Dead.png", - "images/mobs/Enabling-5.png", - "images/mobs/satyr.png", - "images/mobs/Hurt.png", - "images/mobs/Idle.png", - "images/mobs/rangeBossRight.png", - "images/towers/wallTower.png", - "images/background/building2.png", - "images/iso_grass_3.png", - "images/terrain_use.png", - "images/Dusty_MoonBG.png", - "images/economy/scrap.png", - "images/economy/crystal.png", - "images/economy/econ-tower.png", - "images/projectiles/bossProjectile.png", - "images/towers/mine_tower.png", - "images/towers/TNTTower.png", - "images/towers/DroidTower.png", - "images/projectiles/basic_projectile.png", - "images/projectiles/mobProjectile.png", - "images/projectiles/engineer_projectile.png", - "images/projectiles/mobKing_projectile.png", - "images/projectiles/snow_ball.png", - "images/projectiles/burn_effect.png", - "images/projectiles/stun_effect.png", - "images/projectiles/firework_anim.png", - "images/projectiles/pierce_anim.png", - "images/projectiles/snow_ball.png" - }; - private static final String[] forestTextureAtlases = { - "images/economy/econ-tower.atlas", - "images/terrain_iso_grass.atlas", - "images/ghost.atlas", - "images/mobs/boss2.atlas", - "images/ghostKing.atlas", - "images/towers/turret.atlas", - "images/towers/turret01.atlas", - "images/mobs/xenoGrunt.atlas", - "images/towers/fire_tower_atlas.atlas", - "images/towers/stun_tower.atlas", - "images/mobs/xenoGruntRunning.atlas", - "images/xenoGrunt.atlas", - "images/mobs/robot.atlas", - "images/mobs/rangeBossRight.atlas", - "images/towers/DroidTower.atlas", - "images/mobs/robot.atlas", - "images/mobs/rangeBossRight.atlas", - "images/towers/TNTTower.atlas", - "images/projectiles/basic_projectile.atlas", - "images/projectiles/bossProjectile.atlas", - "images/projectiles/mobProjectile.atlas", - "images/projectiles/mobProjectile.atlas", - "images/projectiles/engineer_projectile.atlas", - "images/projectiles/mobKing_projectile.atlas", - "images/projectiles/snow_ball.atlas", - "images/projectiles/pierce_anim.atlas", - "images/projectiles/burn_effect.atlas", - "images/projectiles/firework_anim.atlas", - "images/projectiles/mobProjectile.atlas", - "images/projectiles/stun_effect.atlas" - }; - private static final String[] forestSounds = { - "sounds/Impact4.ogg", - "sounds/economy/click.wav", - "sounds/economy/click_1.wav", - "sounds/towers/gun_shot_trimmed.mp3", - "sounds/towers/deploy.mp3", - "sounds/towers/stow.mp3", - "sounds/engineers/firing_auto.mp3", - "sounds/engineers/firing_single.mp3", - "sounds/projectiles/on_collision.mp3", - "sounds/projectiles/explosion.mp3" - }; private static final String backgroundMusic = "sounds/background/Sci-Fi1.ogg"; - private static final String[] forestMusic = {backgroundMusic}; - + private final TerrainFactory terrainFactory; private Entity player; @@ -181,6 +73,9 @@ public ForestGameArea(TerrainFactory terrainFactory) { super(); this.terrainFactory = terrainFactory; } + public void setAssetLoader(AssetLoader assetLoader) { + this.assetLoader = assetLoader; + } // Add this method to start the wave spawning timer when the game starts. private void startWaveTimer() { @@ -227,7 +122,7 @@ private void spawnWave() { @Override public void create() { // Load game assets - loadAssets(); + loadAllAssets(); displayUI(); spawnTerrain(); @@ -654,27 +549,15 @@ private void playMusic() { music.play(); } - private void loadAssets() { - logger.debug("Loading assets"); - ResourceService resourceService = ServiceLocator.getResourceService(); - resourceService.loadTextures(forestTextures); - resourceService.loadTextureAtlases(forestTextureAtlases); - resourceService.loadSounds(forestSounds); - resourceService.loadMusic(forestMusic); - - while (!resourceService.loadForMillis(10)) { - // This could be upgraded to a loading screen - logger.info("Loading... {}%", resourceService.getProgress()); - } - } - + + 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 diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java index 27ace6b42..ed4750356 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/GameAreaDisplay.java @@ -87,7 +87,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("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); @@ -142,7 +142,7 @@ public void touchUp(InputEvent event, float x, float y, int pointer, int button) 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]); diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java new file mode 100644 index 000000000..9284f1492 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java @@ -0,0 +1,72 @@ +package com.csse3200.game.components.maingame; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.GdxGame; +import com.csse3200.game.entities.Entity; +import com.csse3200.game.entities.factories.PauseMenuFactory; +import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button to pause the game and bring up a pause menu. + */ +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; + + public MainGamePauseDisplay(GdxGame screenSwitchHandle) { + game = screenSwitchHandle; + } + + @Override + public void create() { + super.create(); + addActors(); + } + + private void addActors() { + table = new Table(); + table.top().right(); + table.setFillParent(true); + + TextButton mainMenuBtn = new TextButton("Pause", skin); + + // Spawns a pause menu when the button is pressed. + mainMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Pause button clicked"); + PauseMenuFactory.createPauseMenu(game, false); + } + }); + + table.add(mainMenuBtn).padTop(100f).padRight(10f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the stage + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java b/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java index 1a39b08c2..abdf962e2 100644 --- a/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java @@ -1,6 +1,8 @@ package com.csse3200.game.components.mainmenu; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Cursor; +import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -8,15 +10,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; -import com.csse3200.game.GdxGame; import com.csse3200.game.services.ServiceLocator; +import com.csse3200.game.ui.ButtonFactory; import com.csse3200.game.ui.UIComponent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * A ui component for displaying the Main menu. - */ public class MainMenuDisplay extends UIComponent { private static final Logger logger = LoggerFactory.getLogger(MainMenuDisplay.class); @@ -24,36 +23,57 @@ public class MainMenuDisplay extends UIComponent { private Table table; private Table table1; - - - @Override public void create() { super.create(); addActors(); } - private void addActors() { + /** + * Loads a custom cursor image and sets it as the system cursor. + * + * This method loads an image file named "mouse_effect.png" from the "images/ui" directory + * and sets it as the system cursor. After setting the custom cursor, it disposes of the + * Pixmap object used for loading the cursor image to release system resources. + * + * @param none + * @return none + */ + // Load the custom cursor image + Pixmap cursorPixmap = new Pixmap(Gdx.files.internal("images/ui/mouse_effect.png")); + Cursor customCursor = Gdx.graphics.newCursor(cursorPixmap, 0, 0); + Gdx.graphics.setCursor(customCursor); + cursorPixmap.dispose(); // Dispose of the Pixmap to release resources + table = new Table(); - table1=new Table(); + table1 = new Table(); table.setFillParent(true); table1.setFillParent(true); + Image title = new Image( ServiceLocator.getResourceService() .getAsset("images/background/background1.png", Texture.class)); title.setWidth(Gdx.graphics.getWidth()); title.setHeight(Gdx.graphics.getHeight()); - title.setPosition(0,0); + title.setPosition(0, 0); + // Create an instance of the ButtonFactory class + ButtonFactory buttonFactory = new ButtonFactory(); +// Create a "Start" TextButton using the default style + TextButton startBtn = buttonFactory.createButton("Start"); +// Create a "Help" TextButton using the default style + TextButton loadBtn = buttonFactory.createButton("Help"); + +// Create a "Settings" TextButton with a custom image + 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 = buttonFactory.createCustomButton("Quit", "images/ui/Sprites/UI_Glass_Button_Large_Press_01a2.png"); - TextButton startBtn = new TextButton("Start", skin); - TextButton loadBtn = new TextButton("Help", skin); - TextButton settingsBtn = new TextButton("Settings", skin); - TextButton exitBtn = new TextButton("Quit", skin); // Triggers an event when the button is pressed startBtn.addListener( @@ -87,13 +107,11 @@ public void changed(ChangeEvent changeEvent, Actor actor) { new ChangeListener() { @Override public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Exit button clicked"); entity.getEvents().trigger("exit"); } }); - table.add(title); table1.row(); table1.add(startBtn).padTop(30f); @@ -108,7 +126,6 @@ public void changed(ChangeEvent changeEvent, Actor actor) { stage.addActor(table1); } - @Override public void draw(SpriteBatch batch) { // draw is handled by the stage @@ -124,4 +141,4 @@ public void dispose() { table.clear(); super.dispose(); } -} \ No newline at end of file +} diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuContinueButton.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuContinueButton.java new file mode 100644 index 000000000..f18659c05 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuContinueButton.java @@ -0,0 +1,66 @@ +package com.csse3200.game.components.pausemenu; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.components.maingame.MainGamePauseDisplay; +import com.csse3200.game.entities.Entity; +import com.csse3200.game.entities.factories.PauseMenuFactory; +import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button in the pause menu to resume the game and put away the pause menu. + */ +public class PauseMenuContinueButton extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(PauseMenuContinueButton.class); + private static final float Z_INDEX = 2f; + private Table table; + + @Override + public void create() { + super.create(); + addActors(); + } + + private void addActors() { + table = new Table(); + table.top().right(); + table.setFillParent(true); + + TextButton pauseMenuBtn = new TextButton("Continue", skin); + + // Triggers an event when the button is pressed. + pauseMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Continue button clicked"); + entity.dispose(); + } + }); + + table.add(pauseMenuBtn).padTop(300f).padRight(700f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the renderer component + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuMainMenuButton.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuMainMenuButton.java new file mode 100644 index 000000000..e5edb5b25 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuMainMenuButton.java @@ -0,0 +1,71 @@ +package com.csse3200.game.components.pausemenu; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.GdxGame; +import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button in the pause menu to return to the main menu screen. + */ +public class PauseMenuMainMenuButton extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(PauseMenuMainMenuButton.class); + private static final float Z_INDEX = 2f; + private Table table; + + private final GdxGame game; + + public PauseMenuMainMenuButton(GdxGame screenSwitchHandle) { + game = screenSwitchHandle; + } + @Override + public void create() { + super.create(); + addActors(); + } + + private void addActors() { + table = new Table(); + table.top().right(); + table.setFillParent(true); + + TextButton pauseMenuBtn = new TextButton("Main Menu", skin); + + // Triggers an event when the button is pressed. + pauseMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Main menu button clicked"); + game.setScreen(GdxGame.ScreenType.MAIN_MENU); + } + }); + + table.add(pauseMenuBtn).padTop(400f).padRight(490f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the renderer component + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuPlanetSelectButton.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuPlanetSelectButton.java new file mode 100644 index 000000000..d8ab32a45 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuPlanetSelectButton.java @@ -0,0 +1,71 @@ +package com.csse3200.game.components.pausemenu; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.GdxGame; +import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button in the pause menu to return to the planet select screen. + */ +public class PauseMenuPlanetSelectButton extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(PauseMenuPlanetSelectButton.class); + private static final float Z_INDEX = 2f; + private Table table; + + private final GdxGame game; + + public PauseMenuPlanetSelectButton(GdxGame screenSwitchHandle) { + game = screenSwitchHandle; + } + @Override + public void create() { + super.create(); + addActors(); + } + + private void addActors() { + table = new Table(); + table.top().right(); + table.setFillParent(true); + + TextButton pauseMenuBtn = new TextButton("Planet Select", skin); + + // Triggers an event when the button is pressed. + pauseMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Planet select button clicked"); + game.setScreen(GdxGame.ScreenType.LEVEL_SELECT); + } + }); + + table.add(pauseMenuBtn).padTop(400f).padRight(675f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the renderer component + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuSettingsButton.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuSettingsButton.java new file mode 100644 index 000000000..c89a2c8b9 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuSettingsButton.java @@ -0,0 +1,71 @@ +package com.csse3200.game.components.pausemenu; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.csse3200.game.GdxGame; +import com.csse3200.game.ui.UIComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Displays a button in the pause menu to open the game settings. + */ +public class PauseMenuSettingsButton extends UIComponent { + private static final Logger logger = LoggerFactory.getLogger(PauseMenuSettingsButton.class); + private static final float Z_INDEX = 2f; + private Table table; + + private final GdxGame game; + + public PauseMenuSettingsButton(GdxGame screenSwitchHandle) { + game = screenSwitchHandle; + } + + @Override + public void create() { + super.create(); + addActors(); + } + + private void addActors() { + table = new Table(); + table.top().right(); + table.setFillParent(true); + + TextButton pauseMenuBtn = new TextButton("Settings", skin); + + // Triggers an event when the button is pressed. + pauseMenuBtn.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Settings button clicked"); + game.setScreen(GdxGame.ScreenType.SETTINGS); + } + }); + + table.add(pauseMenuBtn).padTop(300f).padRight(500f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // draw is handled by the renderer component + } + + @Override + public float getZIndex() { + return Z_INDEX; + } + + @Override + public void dispose() { + table.clear(); + super.dispose(); + } +} diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java new file mode 100644 index 000000000..41aadee4c --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java @@ -0,0 +1,43 @@ +package com.csse3200.game.components.pausemenu; + +import com.csse3200.game.components.Component; +import com.csse3200.game.entities.Entity; +import com.badlogic.gdx.utils.Array; +import com.csse3200.game.entities.factories.PauseMenuFactory; +import com.csse3200.game.services.ServiceLocator; + +/** + * Handles the pausing/resuming of time when the pause menu is brought up/put away. + */ +public class PauseMenuTimeStopComponent extends Component { + + private Array freezeList; + public PauseMenuTimeStopComponent() { + } + + /** + * Handles the pausing of the game entities when the pause menu is made. + */ + @Override + public void create() { + freezeList = ServiceLocator.getEntityService().getEntities(); + for (Entity pauseTarget : freezeList) { + if (pauseTarget.getId() != getEntity().getId()) { + // ZA WARUDO! TOKI WO TOMARE! + pauseTarget.setEnabled(false); + } + } + } + + /** + * Handles the un-pausing of the game entities when the pause menu is closed. + * Also notifies the pause menu factory that the pause menu is being disposed. + */ + @Override + public void dispose() { + PauseMenuFactory.decrementPauseMenuCount(); + for (Entity pauseTarget : freezeList) { + pauseTarget.setEnabled(true); + } + } +} diff --git a/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java new file mode 100644 index 000000000..a0dc1ad9d --- /dev/null +++ b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java @@ -0,0 +1,45 @@ +package com.csse3200.game.entities.factories; + +import com.csse3200.game.GdxGame; +import com.csse3200.game.components.pausemenu.*; +import com.csse3200.game.entities.Entity; +import com.csse3200.game.rendering.TextureRenderComponent; +import com.csse3200.game.services.ServiceLocator; + +/** + * Factory to create the pause menu and attach its components. + */ +public class PauseMenuFactory { + private static int pauseMenusActive = 0; + + /** + * Creates the pause menu + * @param game The Gdx Game that handles screen changes + * @param duplicateOverride If false, will not create a pause menu if any currently exist + * @return entity, or null if no entity was created + */ + public static Entity createPauseMenu(GdxGame game, boolean duplicateOverride) { + if (pauseMenusActive == 0 || duplicateOverride) { + Entity pauseMenu = new Entity() + .addComponent(new PauseMenuTimeStopComponent()) + .addComponent(new PauseMenuContinueButton()) + .addComponent(new PauseMenuSettingsButton(game)) + .addComponent(new PauseMenuPlanetSelectButton(game)) + .addComponent(new PauseMenuMainMenuButton(game)) + .addComponent(new TextureRenderComponent("images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png")); + pauseMenu.setScale(8, 8); + pauseMenu.setPosition(6.3f, 2f); + ServiceLocator.getEntityService().register(pauseMenu); + pauseMenusActive++; + return pauseMenu; + } + return null; + } + + /** + * Called when a pause menu is disposed to decrement the count of active pause menus. + */ + public static void decrementPauseMenuCount() { + pauseMenusActive--; + } +} diff --git a/source/core/src/main/com/csse3200/game/screens/AssetLoader.java b/source/core/src/main/com/csse3200/game/screens/AssetLoader.java new file mode 100644 index 000000000..c0809ea82 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/screens/AssetLoader.java @@ -0,0 +1,153 @@ +package com.csse3200.game.screens; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.audio.Sound; +import com.csse3200.game.areas.ForestGameArea; +import com.csse3200.game.services.ResourceService; +import com.csse3200.game.services.ServiceLocator; + +public class AssetLoader { + // Define your asset file paths here + public static final String[] textures = { + "images/desert_bg.png", + "images/ice_bg.png", + "images/lava_bg.png", + "images/projectiles/projectile.png", + "images/ingamebg.png", + "images/box_boy_leaf.png", + "images/background/building1.png", + "images/ghost_1.png", + "images/grass_2.png", + "images/grass_3.png", + "images/hex_grass_1.png", + "images/background/mountain.png", + "images/ghost_king.png", + "images/ghost_1.png", + "images/terrain 2 normal.png", + "images/terrain 2 hex.png", + "images/hex_grass_2.png", + "images/hex_grass_3.png", + "images/iso_grass_1.png", + "images/iso_grass_2.png", + "images/iso_grass_3.png", + "images/towers/turret.png", + "images/towers/turret01.png", + "images/towers/turret_deployed.png", + "images/towers/fire_tower_atlas.png", + "images/towers/stun_tower.png", + "images/background/building2.png", + "images/mobs/robot.png", + "images/mobs/boss2.png", + "images/mobs/Attack_1.png", + "images/mobs/Attack_2.png", + "images/mobs/Charge_1.png", + "images/mobs/Charge_2.png", + "images/mobs/Dead.png", + "images/mobs/Enabling-5.png", + "images/mobs/satyr.png", + "images/mobs/Hurt.png", + "images/mobs/Idle.png", + "images/mobs/rangeBossRight.png", + "images/towers/wallTower.png", + "images/background/building2.png", + "images/iso_grass_3.png", + "images/terrain_use.png", + "images/Dusty_MoonBG.png", + "images/economy/scrap.png", + "images/economy/crystal.png", + "images/economy/econ-tower.png", + "images/projectiles/bossProjectile.png", + "images/towers/mine_tower.png", + "images/towers/TNTTower.png", + "images/towers/DroidTower.png", + "images/projectiles/basic_projectile.png", + "images/projectiles/mobProjectile.png", + "images/projectiles/engineer_projectile.png", + "images/projectiles/mobKing_projectile.png", + "images/projectiles/snow_ball.png", + "images/projectiles/burn_effect.png", + "images/projectiles/stun_effect.png", + "images/projectiles/firework_anim.png", + "images/projectiles/pierce_anim.png", + "images/projectiles/snow_ball.png", + "images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png" + }; + + public static final String[] textureAtlases = { + "images/economy/econ-tower.atlas", + "images/terrain_iso_grass.atlas", + "images/ghost.atlas", + "images/mobs/boss2.atlas", + "images/ghostKing.atlas", + "images/towers/turret.atlas", + "images/towers/turret01.atlas", + "images/mobs/xenoGrunt.atlas", + "images/towers/fire_tower_atlas.atlas", + "images/towers/stun_tower.atlas", + "images/mobs/xenoGruntRunning.atlas", + "images/xenoGrunt.atlas", + "images/mobs/robot.atlas", + "images/mobs/rangeBossRight.atlas", + "images/towers/DroidTower.atlas", + "images/mobs/robot.atlas", + "images/mobs/rangeBossRight.atlas", + "images/towers/TNTTower.atlas", + "images/projectiles/basic_projectile.atlas", + "images/projectiles/bossProjectile.atlas", + "images/projectiles/mobProjectile.atlas", + "images/projectiles/mobProjectile.atlas", + "images/projectiles/engineer_projectile.atlas", + "images/projectiles/mobKing_projectile.atlas", + "images/projectiles/snow_ball.atlas", + "images/projectiles/pierce_anim.atlas", + "images/projectiles/burn_effect.atlas", + "images/projectiles/firework_anim.atlas", + "images/projectiles/mobProjectile.atlas", + "images/projectiles/stun_effect.atlas" + }; + + + public static final String[] music = { + "sounds/background/Sci-Fi1.ogg" + }; + + public static final String[] Sounds = { + "sounds/Impact4.ogg", + "sounds/economy/click.wav", + "sounds/economy/click_1.wav", + "sounds/towers/gun_shot_trimmed.mp3", + "sounds/towers/deploy.mp3", + "sounds/towers/stow.mp3", + "sounds/engineers/firing_auto.mp3", + "sounds/engineers/firing_single.mp3", + "sounds/projectiles/on_collision.mp3", + "sounds/projectiles/explosion.mp3", + }; + + + public static void loadAllAssets() { + ResourceService resourceService = ServiceLocator.getResourceService(); + + resourceService.loadTextures(textures); + resourceService.loadTextureAtlases(textureAtlases); + resourceService.loadSounds(Sounds); + resourceService.loadMusic(music); + + // Wait for the assets to finish loading (you can implement a loading screen) + while (!resourceService.loadForMillis(10)) { + // Display loading progress if needed + } + } + + public static void unloadAllAssets() { + ResourceService resourceService = ServiceLocator.getResourceService(); + + resourceService.unloadAssets(textures); + resourceService.unloadAssets(textureAtlases); + resourceService.unloadAssets(Sounds); + resourceService.unloadAssets(music); + } + + // Add methods to access loaded assets as needed (e.g., getTexture, getSound, etc.) +} diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index ab475797f..a56755b6e 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -22,6 +22,7 @@ import com.csse3200.game.components.gamearea.PerformanceDisplay; import com.csse3200.game.components.maingame.MainGameActions; import com.csse3200.game.components.maingame.MainGameLoseDisplay; +import com.csse3200.game.components.maingame.MainGamePauseDisplay; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; import com.csse3200.game.entities.factories.PlayerFactory; @@ -198,13 +199,13 @@ private void createUI() { ui = new Entity(); ui.addComponent(new InputDecorator(stage, 10)) .addComponent(new PerformanceDisplay()) - .addComponent(new MainGameActions(this.game)) - .addComponent(new MainGameExitDisplay()) + .addComponent(new MainGameActions(this.game)) + .addComponent(new MainGameExitDisplay()) .addComponent(new MainGameLoseDisplay()) - .addComponent(new Terminal()) - .addComponent(inputComponent) - .addComponent(new TerminalDisplay()); - + .addComponent(new MainGamePauseDisplay(this.game)) + .addComponent(new Terminal()) + .addComponent(inputComponent) + .addComponent(new TerminalDisplay()); ServiceLocator.getEntityService().register(ui); } } diff --git a/source/core/src/main/com/csse3200/game/ui/ButtonFactory.java b/source/core/src/main/com/csse3200/game/ui/ButtonFactory.java new file mode 100644 index 000000000..942da7c1a --- /dev/null +++ b/source/core/src/main/com/csse3200/game/ui/ButtonFactory.java @@ -0,0 +1,108 @@ +/** + * The ButtonFactory class is responsible for creating different types of TextButtons + * with customizable styles and properties for use in a LibGDX user interface. + */ +package com.csse3200.game.ui; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +/** + * This class provides methods for creating various types of TextButtons with different styles. + */ +public class ButtonFactory { + private Skin defaultSkin; + + /** + * Constructs a ButtonFactory and initializes the default skin. + */ + public ButtonFactory() { + defaultSkin = createDefaultSkin(); + } + + /** + * Creates a default skin for TextButtons using a JSON file for configuration. + * + * @return The default Skin object. + */ + private Skin createDefaultSkin() { + Skin skin = new Skin(Gdx.files.internal("configs/text.json")); + + // Load the background image for the default button style + TextureRegionDrawable buttonBackground = new TextureRegionDrawable( + new TextureRegion(new Texture("images/ui/Button_Bg.png")) + ); + + // Define the button style with the background image + TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); + style.font = skin.getFont("default"); + style.up = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Large_Lock_01a1.png"))); // Set the button background to the loaded image + + skin.add("default", style); + return skin; + } + + /** + * Creates a TextButton with the specified text using the default skin. + * + * @param text The text to display on the button. + * @return The created TextButton. + */ + public TextButton createButton(String text) { + TextButton button = new TextButton(text, defaultSkin); + button.getLabel().setFontScale(0.8f); // Adjust text size + button.pad(10f); // Adjust padding + return button; + } + + /** + * Creates a custom TextButton with the specified text and a custom image. + * + * @param text The text to display on the button. + * @param customImagePath The path to the custom image for the button. + * @return The created custom TextButton. + */ + public TextButton createCustomButton(String text, String customImagePath) { + // Create a custom button with a PNG image + Texture customTexture = new Texture(Gdx.files.internal(customImagePath)); + TextureRegionDrawable customDrawable = new TextureRegionDrawable(customTexture); + + TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); + style.font = defaultSkin.getFont("default"); + style.up = customDrawable; + + TextButton button = new TextButton(text, style); + button.getLabel().setFontScale(0.8f); // Adjust text size + button.pad(10f); // Adjust padding + + return button; + } + + /** + * Creates a custom TextButton with the specified text and an image from a TextureAtlas. + * + * @param text The text to display on the button. + * @param atlasPath The path to the TextureAtlas containing the button image. + * @return The created custom TextButton. + */ + public TextButton createCustomButtonWithAtlas(String text, String atlasPath) { + // Create a custom button with a TextureAtlas + TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(atlasPath)); + Skin customSkin = new Skin(atlas); + + TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); + style.font = customSkin.getFont("default"); // for custom font if specified in the atlas + style.up = customSkin.getDrawable("button"); // for the button drawable from the atlas + + TextButton button = new TextButton(text, style); + button.getLabel().setFontScale(0.8f); // Adjust text size + button.pad(10f); // Adjust padding + + return button; + } +}