Skip to content

Commit 0661cde

Browse files
authored
Merge pull request #217 from UQcsse3200/team5-ui
Fix UI in Main Game
2 parents fa61ef2 + 345846b commit 0661cde

File tree

7 files changed

+137
-86
lines changed

7 files changed

+137
-86
lines changed
1.4 MB
Loading

source/core/src/main/com/csse3200/game/areas/ForestGameArea.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,20 @@ public void create() {
429429
ServiceLocator.getAudioService().stopMusic();
430430
logger.info("主菜单音乐已停止");
431431
}
432-
432+
433433
// Load assets (textures, sounds, etc.) before creating anything that needs them
434434
loadAssets();
435435
registerForCleanup();
436436

437437
// Create the main UI entity that will handle area info, hotbar, and tower placement
438438
Entity ui = new Entity();
439-
ui.addComponent(new GameAreaDisplay("Box Forest")); // Shows the game area's name
440-
439+
441440
// 添加防御塔列表组件,但初始隐藏(如果是新游戏)
442441
TowerHotbarDisplay towerHotbar = new TowerHotbarDisplay();
443442
if (!hasExistingPlayer) {
444443
towerHotbar.setVisible(false); // 新游戏时隐藏,对话结束后显示
445444
}
446445
ui.addComponent(towerHotbar);
447-
448446
ui.addComponent(new com.csse3200.game.components.maingame.MainGameWin());
449447
SimplePlacementController placementController = new SimplePlacementController();
450448
ui.addComponent(placementController); // Handles user input for tower placement
@@ -471,7 +469,7 @@ public void create() {
471469

472470
// Create background entity (renders behind everything)
473471
Entity background = new Entity();
474-
background.addComponent(new com.csse3200.game.rendering.BackgroundRenderComponent("images/game background.jpg"));
472+
background.addComponent(new com.csse3200.game.rendering.BackgroundRenderComponent("images/main_game_background.png"));
475473
background.setPosition(0, 0); // Set position at origin
476474
spawnEntity(background);
477475

@@ -752,11 +750,11 @@ private Entity spawnPlayer() {
752750
// mapEditor = new com.csse3200.game.areas2.MapTwo.MapEditor2((TerrainComponent2)terrain, newPlayer);
753751
mapEditor = new MapEditor(terrain, newPlayer);
754752
mapEditor.generateEnemyPath(); // Generate fixed enemy path
755-
753+
756754
// Set path layer opacity to 0.7 (70% opacity) for map1
757755
// 调整map1路径砖块的透明度为70%
758756
mapEditor.setPathLayerOpacity(0.7f);
759-
757+
760758
// Uncomment if crystal spawning is needed:
761759
// mapEditor.spawnCrystal(); // Generate crystal
762760

@@ -1106,7 +1104,7 @@ private void spawnIntroDialogue() {
11061104
// 对话结束后显示防御塔列表和播放背景音乐
11071105
showTowerUI();
11081106
playMusic();
1109-
1107+
11101108
if (MainGameScreen.ui != null) {
11111109
MainGameScreen.ui.getEvents().trigger("startWave");
11121110
} else {

source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,17 @@ private void addActors() {
4444
table.setFillParent(true);
4545

4646
// Create custom button style
47-
TextButtonStyle customButtonStyle = UIStyleHelper.orangeButtonStyle();
47+
TextButtonStyle customButtonStyle = UIStyleHelper.mainGameMenuButtonStyle();
4848
TextButton saveBtn = new TextButton("Save", customButtonStyle);
4949
TextButton mainMenuBtn = new TextButton("Exit", customButtonStyle);
5050
TextButton rankingBtn = new TextButton("Ranking", customButtonStyle);
5151
speedButton = new TextButton("Speed: 1x", customButtonStyle);
5252
TextButton startWaveButton = new TextButton("Start Wave", customButtonStyle);
5353

5454
// Set button size
55-
float buttonWidth = 120f;
55+
float buttonWidth = 140f;
5656
float buttonHeight = 40f;
5757

58-
saveBtn.getLabel().setColor(Color.CYAN);
59-
mainMenuBtn.getLabel().setColor(Color.CYAN);
60-
rankingBtn.getLabel().setColor(Color.CYAN);
61-
speedButton.getLabel().setColor(Color.CYAN);
62-
startWaveButton.getLabel().setColor(Color.CYAN);
63-
6458
saveBtn.addListener(
6559
new ChangeListener() {
6660
@Override
@@ -117,13 +111,13 @@ public void changed(ChangeEvent event, Actor actor) {
117111

118112
table.add(saveBtn).size(buttonWidth, buttonHeight).padTop(10f).padRight(10f);
119113
table.row();
120-
table.add(mainMenuBtn).size(buttonWidth, buttonHeight).padTop(5f).padRight(10f);
114+
table.add(mainMenuBtn).size(buttonWidth, buttonHeight).padTop(10f).padRight(10f);
121115
table.row();
122-
table.add(rankingBtn).size(buttonWidth, buttonHeight).padTop(5f).padRight(10f);
116+
table.add(rankingBtn).size(buttonWidth, buttonHeight).padTop(10f).padRight(10f);
123117
table.row();
124-
table.add(speedButton).size(buttonWidth, buttonHeight).padTop(5f).padRight(10f);
118+
table.add(speedButton).size(buttonWidth, buttonHeight).padTop(10f).padRight(10f);
125119
table.row();
126-
table.add(startWaveButton).size(buttonWidth, buttonHeight).padTop(5f).padRight(10f);
120+
table.add(startWaveButton).size(buttonWidth, buttonHeight).padTop(10f).padRight(10f);
127121

128122
stage.addActor(table);
129123
applyUiScale();

source/core/src/main/com/csse3200/game/components/maingame/PlayerNameDisplay.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ private void addActors() {
6464
avatarImage = createAvatarImage(avatarId);
6565

6666
// Create player name label
67-
playerNameLabel = new Label(playerName, skin, "large");
68-
playerNameLabel.setColor(Color.WHITE);
67+
Label.LabelStyle labelStyle = new Label.LabelStyle(skin.get(Label.LabelStyle.class));
68+
labelStyle.fontColor = Color.WHITE;
69+
playerNameLabel = new Label(playerName, labelStyle);
6970

7071
// Add padding and positioning
7172
table.pad(20f, 20f, 0f, 20f);

source/core/src/main/com/csse3200/game/components/player/PlayerStatsDisplay.java

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.csse3200.game.components.player;
22

3+
import com.badlogic.gdx.graphics.Color;
4+
import com.badlogic.gdx.graphics.Pixmap;
35
import com.badlogic.gdx.graphics.Texture;
46
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
57
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -25,13 +27,11 @@
2527
*/
2628
public class PlayerStatsDisplay extends UIComponent {
2729
Table table;
28-
private Image heartImage;
29-
private Label healthLabel;
3030
private final Map<CurrencyType, Image> currencyImages = new EnumMap<>(CurrencyType.class);
3131
private final Map<CurrencyType, Label> currencyLabels = new EnumMap<>(CurrencyType.class);
3232
private Image scoreImage;
3333
private Label scoreLabel;
34-
34+
// private Texture bgTexture;
3535
/**
3636
* Creates reusable ui styles and adds actors to the stage.
3737
*/
@@ -40,7 +40,6 @@ public void create() {
4040
super.create();
4141
addActors();
4242

43-
entity.getEvents().addListener("updateHealth", this::updatePlayerHealthUI);
4443
entity.getEvents().addListener("updateCurrencyUI", this::updatePlayerCurrencyAmountUI);
4544
entity.getEvents().addListener("updateScore", this::updatePlayerScoreUI);
4645
}
@@ -52,29 +51,23 @@ public void create() {
5251
private void addActors() {
5352
table = new Table();
5453
table.top().left();
54+
table.setFillParent(true);
55+
table.padTop(60f).padLeft(5f);
56+
5557
float screenWidth = stage.getWidth();
5658
float screenHeight = stage.getHeight();
57-
float rowWidth = screenWidth * 0.03f;
58-
59-
// Heart image
60-
heartImage = new Image(ServiceLocator.getResourceService().getAsset("images/heart.png", Texture.class));
61-
62-
// Health text
63-
int health = entity.getComponent(PlayerCombatStatsComponent.class).getHealth();
64-
CharSequence healthText = String.format("Health: %d", health);
65-
healthLabel = new Label(healthText, skin, "large");
6659

6760
// Score image (trophy)
61+
float scoreSideLength = 64f;
6862
scoreImage = new Image(ServiceLocator.getResourceService().getAsset("images/score_trophy.png", Texture.class));
6963

64+
Label.LabelStyle labelStyle = new Label.LabelStyle(skin.get(Label.LabelStyle.class));
65+
labelStyle.fontColor = Color.WHITE;
66+
labelStyle.font = skin.getFont("segoe_ui");
7067
// Score text
7168
int score = 0; //entity.getComponent(ScrapStatsComponent.class).getScrap();
7269
CharSequence scoreText = String.format("Score: %d", score);
73-
scoreLabel = new Label(scoreText, skin, "large");
74-
75-
table.add(heartImage).size(rowWidth).pad(5);
76-
table.add(healthLabel);
77-
table.row();
70+
scoreLabel = new Label(scoreText, labelStyle);
7871

7972
// Dynamically render currencies
8073
for (CurrencyType currencyType : CurrencyType.values()) {
@@ -86,46 +79,43 @@ private void addActors() {
8679
);
8780
int currencyAmount = entity.getComponent(CurrencyManagerComponent.class).getCurrencyAmount(currencyType);
8881
Label currencyLabel = new Label(
89-
String.format("%s%n%d", currencyType.getDisplayName(), currencyAmount),
90-
skin,
91-
"large"
92-
);
82+
String.format("%s%n%d", currencyType.getDisplayName(), currencyAmount), labelStyle);
9383

9484
currencyImages.put(currencyType, currencyImage);
9585
currencyLabels.put(currencyType, currencyLabel);
9686

97-
table.add(currencyImage).size(rowWidth).pad(5);
87+
float sideLength = 64f;
88+
table.add(currencyImage).size(sideLength).pad(5);
9889
table.add(currencyLabel).left();
9990
table.row();
10091
}
10192

10293
// Score text position
10394
table.row();
104-
table.add(scoreImage).size(rowWidth).pad(5);
95+
table.add(scoreImage).size(scoreSideLength).pad(5);
10596
table.add(scoreLabel).left().padTop(5f);
106-
107-
// set table’s background
108-
Texture bgTexture = ServiceLocator.getResourceService()
109-
.getAsset("images/Main_Menu_Button_Background.png", Texture.class);
110-
Drawable background = new TextureRegionDrawable(new TextureRegion(bgTexture));
111-
table.setBackground(background);
112-
113-
// Wrap table inside a container for background + positioning
114-
Container<Table> container = new Container<>(table);
115-
container.align(Align.topLeft); // align the content inside
116-
container.top().left(); // align the container itself
117-
container.padTop(60f);
118-
119-
// Add container to root layout
120-
Table rootTable = new Table();
121-
rootTable.top().left(); // this line ensures it's anchored to top-left
122-
rootTable.setFillParent(true);
123-
rootTable.add(container)
124-
.width(screenWidth * 0.15f)
125-
.height(screenHeight * 0.3f)
126-
.left().top();
127-
128-
stage.addActor(rootTable);
97+
// bgTexture = buildSolidTexture(new Color(0.15f, 0.15f, 0.18f, 0.6f)); // 60% opacity
98+
// Drawable background = new TextureRegionDrawable(new TextureRegion(bgTexture));
99+
//
100+
// table.setBackground(background);
101+
//
102+
// // Wrap table inside a container for background + positioning
103+
// Container<Table> container = new Container<>(table);
104+
// container.align(Align.topLeft); // align the content inside
105+
// container.top().left(); // align the container itself
106+
// container.padTop(60f);
107+
//
108+
// // Add container to root layout
109+
// Table rootTable = new Table();
110+
// rootTable.top().left(); // this line ensures it's anchored to top-left
111+
// rootTable.setFillParent(true);
112+
// rootTable.add(container)
113+
// .width(screenWidth * 0.15f)
114+
// .height(screenHeight * 0.3f)
115+
// .left().top();
116+
//
117+
// stage.addActor(rootTable);
118+
stage.addActor(table);
129119

130120
applyUiScale();
131121
}
@@ -154,15 +144,6 @@ public void draw(SpriteBatch batch) {
154144
// draw is handled by the stage
155145
}
156146

157-
/**
158-
* Updates the player's health on the ui.
159-
* @param health player health
160-
*/
161-
public void updatePlayerHealthUI(int health) {
162-
CharSequence text = String.format("Health: %d", health);
163-
healthLabel.setText(text);
164-
}
165-
166147
/**
167148
* Updates the player's currency amount for certain type on the UI.
168149
* @param type currency type to render
@@ -184,12 +165,9 @@ private void updatePlayerScoreUI(int totalScore) {
184165
scoreLabel.setText(text);
185166
}
186167

187-
188168
@Override
189169
public void dispose() {
190170
super.dispose();
191-
heartImage.remove();
192-
healthLabel.remove();
193171

194172
for (Image image : currencyImages.values()) {
195173
image.remove();

source/core/src/main/com/csse3200/game/screens/MainGameScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public class MainGameScreen extends ScreenAdapter {
5656
"images/homebase1.png",
5757
"images/homebase2.png",
5858
"images/basement.png",
59-
"images/Background4.png",
60-
"images/re.gif"
59+
"images/re.gif",
60+
"images/main_game_background.png"
6161
};
6262

6363
private static final Vector2 CAMERA_POSITION = new Vector2(7.5f, 7.5f);

0 commit comments

Comments
 (0)