Skip to content

Commit

Permalink
Implement stats up UI when level up with quest
Browse files Browse the repository at this point in the history
  • Loading branch information
hdescottes committed Feb 27, 2022
1 parent 8a2e552 commit 09176f8
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 30 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ The inventory can be displayed through the chest icon on the status UI. <br>
You can drag and drop items and use consumables by double-clicking on them.

#### Level Up
When you level up in battle, you will be able to display some more extra points to your base stats. <br>
This feature will soon be available when you level up through quests.
When you level up (battle, quest), you will be able to display some more extra points to your base stats. <br>

#### Profiles
The game is saved automatically when a specific action is down (change map, get quest, ...). <br>
Expand All @@ -61,7 +60,6 @@ You can chose to start a new game or load an existing profile on the menu screen
- [ ] add sounds & sounds settings

- [x] leveling system
- [ ] stats UI when lvl up with quest
- [ ] class tree

- [x] battle feature
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

allprojects {

version = "2.5.0"
version = "2.5.1"

apply(plugin = "java")
apply(plugin = "java-library")
Expand Down
25 changes: 22 additions & 3 deletions core/src/main/java/com/gdx/game/entities/player/PlayerHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.gdx.game.profile.ProfileObserver;
import com.gdx.game.quest.QuestGraph;
import com.gdx.game.quest.QuestUI;
import com.gdx.game.status.StatsUpUI;
import com.gdx.game.status.StatusObserver;
import com.gdx.game.status.StatusUI;

Expand All @@ -56,6 +57,7 @@ public class PlayerHUD implements Screen, AudioSubject, ProfileObserver, Compone
private ConversationUI conversationUI;
private StoreInventoryUI storeInventoryUI;
private QuestUI questUI;
private StatsUpUI statsUpUI;

private Dialog messageBoxUI;
private Json json;
Expand Down Expand Up @@ -102,6 +104,14 @@ protected void result(final Object object) {
statusUI.setKeepWithinStage(false);
statusUI.setMovable(false);

statsUpUI = new StatsUpUI();
statsUpUI.setPosition(stage.getWidth() / 4, stage.getHeight() / 4);
statsUpUI.setKeepWithinStage(false);
statsUpUI.setVisible(false);
statsUpUI.setWidth(stage.getWidth() / 2);
statsUpUI.setHeight(stage.getHeight() / 2);
statsUpUI.setMovable(false);

inventoryUI = new InventoryUI();
inventoryUI.setKeepWithinStage(false);
inventoryUI.setMovable(false);
Expand Down Expand Up @@ -134,13 +144,15 @@ protected void result(final Object object) {
stage.addActor(messageBoxUI);
stage.addActor(statusUI);
stage.addActor(inventoryUI);
stage.addActor(statsUpUI);

questUI.validate();
storeInventoryUI.validate();
conversationUI.validate();
messageBoxUI.validate();
statusUI.validate();
inventoryUI.validate();
statsUpUI.validate();

//add tooltips to the stage
Array<Actor> actors = inventoryUI.getInventoryActors();
Expand All @@ -159,6 +171,7 @@ protected void result(final Object object) {
storeInventoryUI.addObserver(this);
//inventoryUI.addObserver(battleUI.getCurrentState());
inventoryUI.addObserver(this);
statsUpUI.addObserver(this);
//battleUI.getCurrentState().addObserver(this);
this.addObserver(AudioManager.getInstance());

Expand Down Expand Up @@ -295,7 +308,7 @@ public void onNotify(ProfileManager profileManager, ProfileEvent event) {

//then add in current values
statusUI.setGoldValue(goldVal);
statusUI.setLevelValue(levelVal);
statusUI.setLevelValue(levelVal, false);
}
break;
case SAVING_PROFILE:
Expand Down Expand Up @@ -451,7 +464,7 @@ public void onNotify(ConversationGraph graph, ConversationCommandEvent event) {
if(questUI.isQuestReadyForReturn(questID)) {
//notify(AudioObserver.AudioCommand.MUSIC_PLAY_ONCE, AudioObserver.AudioTypeEvent.MUSIC_LEVEL_UP_FANFARE);
QuestGraph quest = questUI.getQuestByID(questID);
statusUI.addXPValue(quest.getXpReward()); //TODO: should trigger statsUpUI if lvl up
statusUI.addXPValue(quest.getXpReward(), true);
statusUI.addGoldValue(quest.getGoldReward());
//notify(AudioObserver.AudioCommand.SOUND_PLAY_ONCE, AudioObserver.AudioTypeEvent.SOUND_COIN_RUSTLE);
inventoryUI.removeQuestItemFromInventory(questID);
Expand Down Expand Up @@ -522,6 +535,10 @@ public void onNotify(int value, StatusEvent event) {
case UPDATED_LEVEL:
ProfileManager.getInstance().setProperty("currentPlayerLevel", statusUI.getLevelValue());
break;
case UPDATED_LEVEL_FROM_QUEST:
ProfileManager.getInstance().setProperty("currentPlayerLevel", statusUI.getLevelValue());
statsUpUI.setVisible(true);
break;
case UPDATED_MP:
ProfileManager.getInstance().setProperty("currentPlayerMP", statusUI.getMPValue());
break;
Expand Down Expand Up @@ -575,7 +592,7 @@ public void onNotify(Entity enemyEntity, BattleEvent event) {
int goldReward = Integer.parseInt(enemyEntity.getEntityConfig().getPropertyValue(EntityConfig.EntityProperties.ENTITY_GP_REWARD.toString()));
statusUI.addGoldValue(goldReward);
int xpReward = Integer.parseInt(enemyEntity.getEntityConfig().getPropertyValue(EntityConfig.EntityProperties.ENTITY_XP_REWARD.toString()));
statusUI.addXPValue(xpReward);
statusUI.addXPValue(xpReward, false);
break;
case PLAYER_HIT_DAMAGE:
int hpVal = ProfileManager.getInstance().getProperty("currentPlayerHP", Integer.class);
Expand Down Expand Up @@ -606,6 +623,8 @@ public void onNotify(String value, InventoryEvent event) {
statusUI.addMPValue(typeValue);
}
break;
case REFRESH_STATS:
inventoryUI.resetEquipSlots();
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum InventoryEvent {
ITEM_CONSUMED,
ADD_WAND_AP,
REMOVE_WAND_AP,
REFRESH_STATS,
NONE
}

Expand Down
8 changes: 0 additions & 8 deletions core/src/main/java/com/gdx/game/inventory/InventoryUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ public void resetEquipSlots() {
notify(String.valueOf(APVal), InventoryObserver.InventoryEvent.UPDATED_AP);
}

public void refreshStats() {
APVal = ProfileManager.getInstance().getProperty("currentPlayerAP", Integer.class);
DPVal = ProfileManager.getInstance().getProperty("currentPlayerDP", Integer.class);

DPValLabel.setText(String.valueOf(DPVal));
APValLabel.setText(String.valueOf(APVal));
}

public static void clearInventoryItems(Table targetTable) {
Array<Cell> cells = targetTable.getCells();
for(int i = 0; i < cells.size; i++) {
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/gdx/game/screen/BattleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private void setupGameOver() {
private void refreshStatus() {
playerHUD.getStatusUI().setHPValue(battleHUD.getBattleStatusUI().getHPValue());
playerHUD.getStatusUI().setMPValue(battleHUD.getBattleStatusUI().getMPValue());
playerHUD.getInventoryUI().refreshStats();
}

private void refreshInventory() {
Expand Down
33 changes: 32 additions & 1 deletion core/src/main/java/com/gdx/game/status/StatsUpUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Array;
import com.gdx.game.inventory.InventoryObserver;
import com.gdx.game.inventory.InventorySubject;
import com.gdx.game.manager.ResourceManager;
import com.gdx.game.profile.ProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StatsUpUI extends Window {
public class StatsUpUI extends Window implements InventorySubject {

private static final Logger LOGGER = LoggerFactory.getLogger(StatsUpUI.class);

private TextButton validateBtn;
private Array<InventoryObserver> observers;

private final int maxPoint = 5;
private Label PValLabel;
Expand All @@ -34,6 +38,8 @@ public class StatsUpUI extends Window {
public StatsUpUI() {
super("stats up", ResourceManager.skin);

observers = new Array<>();

PVal = maxPoint;
APValInit = ProfileManager.getInstance().getProperty("currentPlayerCharacterAP", Integer.class);
DPValInit = ProfileManager.getInstance().getProperty("currentPlayerCharacterDP", Integer.class);
Expand Down Expand Up @@ -157,6 +163,7 @@ public void clicked(InputEvent event, float x, float y) {
LOGGER.info("Attack bonus point : " + bonusAPAdded);
LOGGER.info("Defense bonus point : " + bonusDPAdded);
setVisible(false);
StatsUpUI.this.notify("", InventoryObserver.InventoryEvent.REFRESH_STATS);
}
});

Expand All @@ -177,4 +184,28 @@ private void pValChange(boolean inc) {
PValLabel.setText(String.valueOf(PVal));
validateBtn.setVisible(PVal == 0);
}

@Override
public void addObserver(InventoryObserver inventoryObserver) {
observers.add(inventoryObserver);
}

@Override
public void removeObserver(InventoryObserver inventoryObserver) {
observers.removeValue(inventoryObserver, true);
}

@Override
public void removeAllObservers() {
for(InventoryObserver observer: observers) {
observers.removeValue(observer, true);
}
}

@Override
public void notify(String value, InventoryObserver.InventoryEvent event) {
for(InventoryObserver observer: observers) {
observer.onNotify(value, event);
}
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/com/gdx/game/status/StatusObserver.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gdx.game.status;


public interface StatusObserver {
enum StatusEvent {
UPDATED_GP,
UPDATED_LEVEL,
UPDATED_LEVEL_FROM_QUEST,
UPDATED_HP,
UPDATED_MP,
UPDATED_XP,
Expand Down
20 changes: 12 additions & 8 deletions core/src/main/java/com/gdx/game/status/StatusUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ public int getLevelValue() {
return levelVal;
}

public void setLevelValue(int levelValue) {
public void setLevelValue(int levelValue, boolean isFromQuest) {
this.levelVal = levelValue;
levelValLabel.setText(String.valueOf(levelVal));
notify(levelVal, StatusObserver.StatusEvent.UPDATED_LEVEL);
if(isFromQuest) {
notify(levelVal, StatusObserver.StatusEvent.UPDATED_LEVEL_FROM_QUEST);
} else {
notify(levelVal, StatusObserver.StatusEvent.UPDATED_LEVEL);
}
}

public int getGoldValue() {
Expand All @@ -215,11 +219,11 @@ public int getXPValue() {
return xpVal;
}

public void addXPValue(int xpValue) {
public void addXPValue(int xpValue, boolean isFromQuest) {
this.xpVal += xpValue;

if(xpVal > xpCurrentMax) {
updateToNewLevel();
updateToNewLevel(isFromQuest);
}

xpValLabel.setText(String.valueOf(xpVal));
Expand All @@ -233,7 +237,7 @@ public void setXPValue(int xpValue) {
this.xpVal = xpValue;

if(xpVal > xpCurrentMax) {
updateToNewLevel();
updateToNewLevel(false);
}

xpValLabel.setText(String.valueOf(xpVal));
Expand All @@ -259,13 +263,13 @@ public void setStatusForLevel(int level) {
setMPValueMax(table.getMpMax());
setMPValue(table.getMpMax());

setLevelValue(Integer.parseInt(table.getLevelID()));
setLevelValue(Integer.parseInt(table.getLevelID()), false);
return;
}
}
}

public void updateToNewLevel(){
public void updateToNewLevel(boolean isFromQuest){
for(LevelTable table: levelTables) {
//System.out.println("XPVAL " + _xpVal + " table XPMAX " + table.getXpMax() );
if(xpVal <= table.getXpMax()) {
Expand All @@ -277,7 +281,7 @@ public void updateToNewLevel(){
setMPValueMax(table.getMpMax());
setMPValue(table.getMpMax());

setLevelValue(Integer.parseInt(table.getLevelID()));
setLevelValue(Integer.parseInt(table.getLevelID()), isFromQuest);
notify(levelVal, StatusObserver.StatusEvent.LEVELED_UP);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/quests/quest003.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
questTitle : "Give Me My Baby Back!"
questID : 3
goldReward : 20
xpReward : 20
xpReward : 205
isQuestComplete : FALSE
questTasks: {
2: {
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/com/gdx/game/status/StatusUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testStatusUI_ShouldSucceed() {
@Test
public void testSetLevelValue_ShouldSucceed() {
StatusUI statusUI = new StatusUI();
statusUI.setLevelValue(1);
statusUI.setLevelValue(1, false);

assertThat(statusUI).isNotNull();
assertThat(statusUI.getLevelValue()).isEqualTo(1);
Expand All @@ -55,7 +55,7 @@ public void testSetGoldValue_ShouldSucceed() {
@Test
public void testSetXpValue_ShouldSucceedWithoutLevelUp() {
StatusUI statusUI = new StatusUI();
statusUI.setLevelValue(1);
statusUI.setLevelValue(1, false);
statusUI.setXPValue(1);

assertThat(statusUI).isNotNull();
Expand All @@ -66,7 +66,7 @@ public void testSetXpValue_ShouldSucceedWithoutLevelUp() {
@Test
public void testSetXpValue_ShouldSucceedWithLevelUp() {
StatusUI statusUI = new StatusUI();
statusUI.setLevelValue(1);
statusUI.setLevelValue(1, false);
statusUI.setXPValue(210);

assertThat(statusUI).isNotNull();
Expand Down

0 comments on commit 09176f8

Please sign in to comment.