11package com .csse3200 .game .components .player ;
22
3+ import com .badlogic .gdx .graphics .Color ;
4+ import com .badlogic .gdx .graphics .Pixmap ;
35import com .badlogic .gdx .graphics .Texture ;
46import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
57import com .badlogic .gdx .graphics .g2d .TextureRegion ;
2527 */
2628public 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 ();
0 commit comments