-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the basic framework for buttons in the main game area
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 67 additions & 1 deletion
68
source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,68 @@ | ||
package com.csse3200.game.components.maingame;public class UIElementsDisplay { | ||
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.Button; | ||
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.ui.ButtonFactory; | ||
import com.csse3200.game.ui.UIComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Text; | ||
|
||
/** | ||
* Displays a button to exit the Main Game screen to the Main Menu screen. | ||
*/ | ||
public class UIElementsDisplay extends UIComponent { | ||
private static final Logger logger = LoggerFactory.getLogger(MainGameExitDisplay.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 remainingMobsButton = new ButtonFactory().createButton("Remaining mobs:"); | ||
TextButton testSlider = new ButtonFactory().createButton("Test slider"); | ||
|
||
// Triggers an event when the button is pressed. | ||
remainingMobsButton.addListener( | ||
new ChangeListener() { | ||
@Override | ||
public void changed(ChangeEvent changeEvent, Actor actor) { | ||
logger.debug("Wave counter button clicked"); | ||
entity.getEvents().trigger("wave counter"); | ||
} | ||
}); | ||
|
||
table.add(remainingMobsButton).padTop(0f).padRight(10f); | ||
table.add(testSlider).padTop(90).padRight(10f); | ||
|
||
stage.addActor(table); | ||
} | ||
|
||
@Override | ||
public void draw(SpriteBatch batch) { | ||
// drawing is handled by the stage | ||
} | ||
|
||
@Override | ||
public float getZIndex() { | ||
return Z_INDEX; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
table.clear(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters