Skip to content

Commit 618ce1f

Browse files
committed
Add star image and stars counter to main menu
1 parent bdd93ab commit 618ce1f

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

source/core/assets/images/star.png

384 Bytes
Loading

source/core/src/main/com/csse3200/game/components/mainmenu/MainMenuDisplay.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import com.badlogic.gdx.graphics.g2d.TextureRegion;
77
import com.badlogic.gdx.graphics.g2d.NinePatch;
88
import com.badlogic.gdx.scenes.scene2d.Actor;
9-
import com.badlogic.gdx.scenes.scene2d.ui.Image;
10-
import com.badlogic.gdx.scenes.scene2d.ui.Table;
11-
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
9+
import com.badlogic.gdx.scenes.scene2d.ui.*;
1210
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
1311
import com.csse3200.game.areas.ForestGameArea;
1412
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
@@ -53,7 +51,20 @@ private void addActors() {
5351
TextButton loadBtn = new TextButton("Continue", customButtonStyle);
5452
TextButton settingsBtn = new TextButton("Settings", customButtonStyle);
5553
TextButton exitBtn = new TextButton("Exit", customButtonStyle);
56-
54+
55+
// stars display
56+
Image starImage = new Image(
57+
ServiceLocator.getResourceService().getAsset(
58+
"images/star.png",
59+
Texture.class
60+
)
61+
);
62+
Label starsLabel = new Label(
63+
Integer.toString(ServiceLocator.getGameStateService().getStars()),
64+
skin,
65+
"large"
66+
);
67+
5768
// 设置按钮大小
5869
float buttonWidth = 200f;
5970
float buttonHeight = 50f;
@@ -103,7 +114,13 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
103114
});
104115

105116

106-
table.add().expandY().row();
117+
table.add().expandY().row();
118+
HorizontalGroup group = new HorizontalGroup();
119+
group.space(5);
120+
group.addActor(starImage);
121+
group.addActor(starsLabel);
122+
table.add(group);
123+
table.row();
107124
table.add(startBtn).size(buttonWidth, buttonHeight).padTop(50f);
108125
table.row();
109126
table.add(loadBtn).size(buttonWidth, buttonHeight).padTop(20f);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public class MainMenuScreen extends ScreenAdapter {
2626
private final Renderer renderer;
2727
private static final String[] mainMenuTextures = {
2828
"images/main_menu_background.png",
29-
"images/Main_Menu_Button_Background.png"
29+
"images/Main_Menu_Button_Background.png",
30+
"images/star.png"
3031
};
3132

3233
public MainMenuScreen(GdxGame game) {

0 commit comments

Comments
 (0)