Use binding struct in Character menu

This commit is contained in:
William Brawner 2021-06-07 21:27:29 -06:00 committed by seedhartha
parent f3465b742a
commit a0f6e13ac7
3 changed files with 212 additions and 57 deletions

View file

@ -19,11 +19,12 @@
#include <boost/format.hpp>
#include "../../../gui/scenebuilder.h"
#include "../../../graphics/model/models.h"
#include "../../../gui/scenebuilder.h"
#include "../../d20/classes.h"
#include "../../game.h"
#include "../../gameidutil.h"
#include "../colorutil.h"
@ -39,7 +40,7 @@ namespace reone {
namespace game {
CharacterMenu::CharacterMenu(Game *game) : GameGUI(game) {
CharacterMenu::CharacterMenu(Game *game, InGameMenu &inGameMenu) : GameGUI(game), _inGameMenu(inGameMenu) {
_resRef = getResRef("character");
initForGame();
@ -48,30 +49,103 @@ CharacterMenu::CharacterMenu(Game *game) : GameGUI(game) {
void CharacterMenu::load() {
GUI::load();
bindControls();
hideControl("BTN_CHARLEFT");
hideControl("BTN_CHARRIGHT");
hideControl("LBL_GOOD0");
hideControl("LBL_GOOD1");
hideControl("LBL_GOOD2");
hideControl("LBL_GOOD3");
hideControl("LBL_GOOD4");
hideControl("LBL_GOOD5");
hideControl("LBL_GOOD6");
hideControl("LBL_GOOD7");
hideControl("LBL_GOOD8");
hideControl("LBL_GOOD9");
hideControl("LBL_GOOD10");
hideControl("LBL_MORE");
_binding.btnAuto->setDisabled(true);
if (!isTSL(_game->gameId())) {
_binding.btnCharLeft->setVisible(false);
_binding.btnCharRight->setVisible(false);
disableControl("BTN_AUTO");
disableControl("BTN_SCRIPTS");
for (auto &control : _binding.lblGood) {
control->setVisible(false);
}
_binding.lblMore->setVisible(false);
_binding.btnScripts->setDisabled(true);
}
}
void CharacterMenu::bindControls() {
_binding.lbl3dChar = getControlPtr<Label>("LBL_3DCHAR");
_binding.btn3dChar = getControlPtr<Button>("BTN_3DCHAR");
_binding.sldAlign = getControlPtr<Slider>("SLD_ALIGN");
_binding.lblStr = getControlPtr<Label>("LBL_STR");
_binding.lblFortitudeStat = getControlPtr<Label>("LBL_FORTITUDE_STAT");
_binding.lblReflexStat = getControlPtr<Label>("LBL_REFLEX_STAT");
_binding.lblWillStat = getControlPtr<Label>("LBL_WILL_STAT");
_binding.lblDefenseStat = getControlPtr<Label>("LBL_DEFENSE_STAT");
_binding.lblForceStat = getControlPtr<Label>("LBL_FORCE_STAT");
_binding.lblVitalityStat = getControlPtr<Label>("LBL_VITALITY_STAT");
_binding.lblDex = getControlPtr<Label>("LBL_DEX");
_binding.lblCon = getControlPtr<Label>("LBL_CON");
_binding.lblInt = getControlPtr<Label>("LBL_INT");
_binding.lblCha = getControlPtr<Label>("LBL_CHA");
_binding.lblWis = getControlPtr<Label>("LBL_WIS");
_binding.lblStrMod = getControlPtr<Label>("LBL_STR_MOD");
_binding.lblDexMod = getControlPtr<Label>("LBL_DEX_MOD");
_binding.lblConMod = getControlPtr<Label>("LBL_CON_MOD");
_binding.lblIntMod = getControlPtr<Label>("LBL_INT_MOD");
_binding.lblWisMod = getControlPtr<Label>("LBL_WIS_MOD");
_binding.lblChaMod = getControlPtr<Label>("LBL_CHA_MOD");
_binding.lblExperienceStat = getControlPtr<Label>("LBL_EXPERIENCE_STAT");
_binding.lblNeededXp = getControlPtr<Label>("LBL_NEEDED_XP");
_binding.lblStrength = getControlPtr<Label>("LBL_STRENGTH");
_binding.lblDexterity = getControlPtr<Label>("LBL_DEXTERITY");
_binding.lblConstitution = getControlPtr<Label>("LBL_CONSTITUTION");
_binding.lblIntelligence = getControlPtr<Label>("LBL_INTELLIGENCE");
_binding.lblCharisma = getControlPtr<Label>("LBL_CHARISMA");
_binding.lblReflex = getControlPtr<Label>("LBL_REFLEX");
_binding.lblWill = getControlPtr<Label>("LBL_WILL");
_binding.lblExperience = getControlPtr<Label>("LBL_EXPERIENCE");
_binding.lblNextLevel = getControlPtr<Label>("LBL_NEXT_LEVEL");
_binding.lblForce = getControlPtr<Label>("LBL_FORCE");
_binding.lblVitality = getControlPtr<Label>("LBL_VITALITY");
_binding.lblDefense = getControlPtr<Label>("LBL_DEFENSE");
_binding.lblFortitude = getControlPtr<Label>("LBL_DEFENSE");
_binding.lblBevel = getControlPtr<Label>("LBL_BEVEL");
_binding.lblWisdom = getControlPtr<Label>("LBL_WISDOM");
_binding.lblBevel2 = getControlPtr<Label>("LBL_BEVEL2");
_binding.lblLight = getControlPtr<Label>("LBL_LIGHT");
_binding.lblDark = getControlPtr<Label>("LBL_DARK");
_binding.btnExit = getControlPtr<Button>("BTN_EXIT");
_binding.btnAuto = getControlPtr<Button>("BTN_AUTO");
_binding.btnLevelup = getControlPtr<Button>("BTN_LEVELUP");
if (!isTSL(_game->gameId())) {
_binding.lblAdorn = getControlPtr<Label>("LBL_ADORN");
_binding.btnScripts = getControlPtr<Button>("BTN_SCRIPTS");
_binding.lblClass = getControlPtr<Label>("LBL_CLASS");
_binding.lblClass1 = getControlPtr<Label>("LBL_CLASS1");
_binding.lblClass2 = getControlPtr<Label>("LBL_CLASS2");
for (int i = 0; i < 10; ++i) {
_binding.lblGood[i] = getControlPtr<Label>("LBL_GOOD" + to_string(i + 1));
}
_binding.lblLevel = getControlPtr<Label>("LBL_LEVEL");
_binding.lblLevel1 = getControlPtr<Label>("LBL_LEVEL1");
_binding.lblLevel2 = getControlPtr<Label>("LBL_LEVEL2");
_binding.lblMore = getControlPtr<Label>("LBL_MORE");
_binding.lblName = getControlPtr<Label>("LBL_NAME");
_binding.btnChange1 = getControlPtr<Button>("BTN_CHANGE1");
_binding.btnChange2 = getControlPtr<Button>("BTN_CHANGE2");
_binding.btnCharLeft = getControlPtr<Button>("BTN_CHARLEFT");
_binding.btnCharRight = getControlPtr<Button>("BTN_CHARRIGHT");
} else {
_binding.lblForceMastery = getControlPtr<Label>("LBL_FORCEMASTERY");
_binding.lblMoreBack = getControlPtr<Label>("LBL_FORCEMASTERY");
_binding.lblStatsBorder = getControlPtr<Label>("LBL_STATSBORDER");
_binding.lblTitle = getControlPtr<Label>("LBL_TITLE");
_binding.lblXpBack = getControlPtr<Label>("LBL_XP_BACK");
for (int i = 0; i < 6; ++i) {
_binding.lblBar[i] = getControlPtr<Label>("LBL_BAR" + to_string(i + 1));
}
_binding.btnChange1 = _inGameMenu.getBtnChange2();
_binding.btnChange2 = _inGameMenu.getBtnChange3();
}
}
void CharacterMenu::update(float dt) {
shared_ptr<Creature> leader(_game->services().party().getLeader());
setControlVisible("BTN_LEVELUP", leader->isLevelUpPending());
setControlVisible("BTN_AUTO", leader->isLevelUpPending());
_binding.btnLevelup->setVisible(leader->isLevelUpPending());
_binding.btnAuto->setVisible(leader->isLevelUpPending());
GUI::update(dt);
}
@ -87,35 +161,37 @@ void CharacterMenu::refreshControls() {
shared_ptr<Creature> partyLeader(_game->services().party().getLeader());
CreatureAttributes &attributes = partyLeader->attributes();
setControlText("LBL_CLASS1", describeClass(attributes.getClassByPosition(1)));
setControlText("LBL_CLASS2", describeClass(attributes.getClassByPosition(2)));
setControlText("LBL_LEVEL1", toStringOrEmptyIfZero(attributes.getLevelByPosition(1)));
setControlText("LBL_LEVEL2", toStringOrEmptyIfZero(attributes.getLevelByPosition(2)));
if (!isTSL(_game->gameId())) {
_binding.lblClass1->setTextMessage(describeClass(attributes.getClassByPosition(1)));
_binding.lblClass2->setTextMessage(describeClass(attributes.getClassByPosition(2)));
_binding.lblLevel1->setTextMessage(toStringOrEmptyIfZero(attributes.getLevelByPosition(1)));
_binding.lblLevel2->setTextMessage(toStringOrEmptyIfZero(attributes.getLevelByPosition(2)));
}
setControlText("LBL_VITALITY_STAT", str(boost::format("%d/%d") % partyLeader->currentHitPoints() % partyLeader->hitPoints()));
setControlText("LBL_DEFENSE_STAT", to_string(attributes.getDefense()));
setControlText("LBL_FORCE_STAT", "");
_binding.lblVitalityStat->setTextMessage(str(boost::format("%d/%d") % partyLeader->currentHitPoints() % partyLeader->hitPoints()));
_binding.lblDefenseStat->setTextMessage(to_string(attributes.getDefense()));
_binding.lblForceStat->setTextMessage("");
setControlText("LBL_STR", to_string(attributes.strength()));
setControlText("LBL_STR_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Strength)));
setControlText("LBL_DEX", to_string(attributes.dexterity()));
setControlText("LBL_DEX_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Dexterity)));
setControlText("LBL_CON", to_string(attributes.constitution()));
setControlText("LBL_CON_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Constitution)));
setControlText("LBL_INT", to_string(attributes.intelligence()));
setControlText("LBL_INT_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Intelligence)));
setControlText("LBL_WIS", to_string(attributes.wisdom()));
setControlText("LBL_WIS_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Wisdom)));
setControlText("LBL_CHA", to_string(attributes.charisma()));
setControlText("LBL_CHA_MOD", describeAbilityModifier(attributes.getAbilityModifier(Ability::Charisma)));
_binding.lblStr->setTextMessage(to_string(attributes.strength()));
_binding.lblStrMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Strength)));
_binding.lblDex->setTextMessage(to_string(attributes.dexterity()));
_binding.lblDexMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Dexterity)));
_binding.lblCon->setTextMessage(to_string(attributes.constitution()));
_binding.lblConMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Constitution)));
_binding.lblInt->setTextMessage(to_string(attributes.intelligence()));
_binding.lblIntMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Intelligence)));
_binding.lblWis->setTextMessage(to_string(attributes.wisdom()));
_binding.lblWisMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Wisdom)));
_binding.lblCha->setTextMessage(to_string(attributes.charisma()));
_binding.lblChaMod->setTextMessage(describeAbilityModifier(attributes.getAbilityModifier(Ability::Charisma)));
SavingThrows savingThrows(attributes.getAggregateSavingThrows());
setControlText("LBL_FORTITUDE_STAT", to_string(savingThrows.fortitude));
setControlText("LBL_REFLEX_STAT", to_string(savingThrows.reflex));
setControlText("LBL_WILL_STAT", to_string(savingThrows.will));
_binding.lblFortitudeStat->setTextMessage(to_string(savingThrows.fortitude));
_binding.lblReflexStat->setTextMessage(to_string(savingThrows.reflex));
_binding.lblWillStat->setTextMessage(to_string(savingThrows.will));
setControlText("LBL_EXPERIENCE_STAT", to_string(partyLeader->xp()));
setControlText("LBL_NEEDED_XP", to_string(partyLeader->getNeededXP()));
_binding.lblExperienceStat->setTextMessage(to_string(partyLeader->xp()));
_binding.lblNeededXp->setTextMessage(to_string(partyLeader->getNeededXP()));
refreshPortraits();
refresh3D();
@ -134,18 +210,15 @@ void CharacterMenu::refreshPortraits() {
shared_ptr<Creature> partyMember1(party.getMember(1));
shared_ptr<Creature> partyMember2(party.getMember(2));
Control &btnChange1 = getControl("BTN_CHANGE1");
btnChange1.setBorderFill(partyMember1 ? partyMember1->portrait() : nullptr);
btnChange1.setHilightFill(partyMember1 ? partyMember1->portrait() : nullptr);
_binding.btnChange1->setBorderFill(partyMember1 ? partyMember1->portrait() : nullptr);
_binding.btnChange1->setHilightFill(partyMember1 ? partyMember1->portrait() : nullptr);
Control &btnChange2 = getControl("BTN_CHANGE2");
btnChange2.setBorderFill(partyMember2 ? partyMember2->portrait() : nullptr);
btnChange2.setHilightFill(partyMember2 ? partyMember2->portrait() : nullptr);
_binding.btnChange2->setBorderFill(partyMember2 ? partyMember2->portrait() : nullptr);
_binding.btnChange2->setHilightFill(partyMember2 ? partyMember2->portrait() : nullptr);
}
void CharacterMenu::refresh3D() {
Control &control3d = getControl("LBL_3DCHAR");
float aspect = control3d.extent().width / static_cast<float>(control3d.extent().height);
float aspect = _binding.lbl3dChar->extent().width / static_cast<float>(_binding.lbl3dChar->extent().height);
auto scene = SceneBuilder(_options, _game->services().graphics())
.aspect(aspect)
@ -156,7 +229,7 @@ void CharacterMenu::refresh3D() {
.lightingRefFromModelNode("charmain_light")
.build();
control3d.setScene(move(scene));
_binding.lbl3dChar->setScene(move(scene));
}
shared_ptr<ModelSceneNode> CharacterMenu::getSceneModel(SceneGraph &sceneGraph) const {
@ -177,7 +250,7 @@ shared_ptr<ModelSceneNode> CharacterMenu::getSceneModel(SceneGraph &sceneGraph)
character->loadAppearance();
character->updateModelAnimation();
auto sceneModel = make_shared<ModelSceneNode>(_game->services().graphics().models().get("charmain_light"), ModelUsage::GUI, &sceneGraph);
auto sceneModel = make_shared<ModelSceneNode>( _game->services().graphics().models().get("charmain_light"), ModelUsage::GUI, &sceneGraph);
sceneModel->attach("charmain_light", character->sceneNode());
return move(sceneModel);

View file

@ -18,16 +18,21 @@
#pragma once
#include "../gui.h"
#include "../../../gui/control/button.h"
#include "../../../gui/control/label.h"
#include "../../../gui/control/listbox.h"
#include "../../../gui/control/slider.h"
#include "../../../scene/node/modelnode.h"
namespace reone {
namespace game {
class InGameMenu;
class CharacterMenu : public GameGUI {
public:
CharacterMenu(Game *game);
CharacterMenu(Game *game, InGameMenu &inGameMenu);
void load() override;
void update(float dt) override;
@ -35,6 +40,83 @@ public:
void refreshControls();
private:
struct Binding {
std::shared_ptr<gui::Label> lbl3dChar {nullptr};
std::shared_ptr<gui::Button> btn3dChar {nullptr};
std::shared_ptr<gui::Slider> sldAlign {nullptr};
std::shared_ptr<gui::Label> lblStr {nullptr};
std::shared_ptr<gui::Label> lblFortitudeStat {nullptr};
std::shared_ptr<gui::Label> lblReflexStat {nullptr};
std::shared_ptr<gui::Label> lblWillStat {nullptr};
std::shared_ptr<gui::Label> lblDefenseStat {nullptr};
std::shared_ptr<gui::Label> lblForceStat {nullptr};
std::shared_ptr<gui::Label> lblVitalityStat {nullptr};
std::shared_ptr<gui::Label> lblDex {nullptr};
std::shared_ptr<gui::Label> lblCon {nullptr};
std::shared_ptr<gui::Label> lblInt {nullptr};
std::shared_ptr<gui::Label> lblCha {nullptr};
std::shared_ptr<gui::Label> lblWis {nullptr};
std::shared_ptr<gui::Label> lblStrMod {nullptr};
std::shared_ptr<gui::Label> lblDexMod {nullptr};
std::shared_ptr<gui::Label> lblConMod {nullptr};
std::shared_ptr<gui::Label> lblIntMod {nullptr};
std::shared_ptr<gui::Label> lblWisMod {nullptr};
std::shared_ptr<gui::Label> lblChaMod {nullptr};
std::shared_ptr<gui::Label> lblExperienceStat {nullptr};
std::shared_ptr<gui::Label> lblNeededXp {nullptr};
std::shared_ptr<gui::Label> lblStrength {nullptr};
std::shared_ptr<gui::Label> lblDexterity {nullptr};
std::shared_ptr<gui::Label> lblConstitution {nullptr};
std::shared_ptr<gui::Label> lblIntelligence {nullptr};
std::shared_ptr<gui::Label> lblCharisma {nullptr};
std::shared_ptr<gui::Label> lblReflex {nullptr};
std::shared_ptr<gui::Label> lblWill {nullptr};
std::shared_ptr<gui::Label> lblExperience {nullptr};
std::shared_ptr<gui::Label> lblNextLevel {nullptr};
std::shared_ptr<gui::Label> lblForce {nullptr};
std::shared_ptr<gui::Label> lblVitality {nullptr};
std::shared_ptr<gui::Label> lblDefense {nullptr};
std::shared_ptr<gui::Label> lblFortitude {nullptr};
std::shared_ptr<gui::Label> lblBevel {nullptr};
std::shared_ptr<gui::Label> lblWisdom {nullptr};
std::shared_ptr<gui::Label> lblBevel2 {nullptr};
std::shared_ptr<gui::Label> lblLight {nullptr};
std::shared_ptr<gui::Label> lblDark {nullptr};
std::shared_ptr<gui::Button> btnExit {nullptr};
std::shared_ptr<gui::Button> btnAuto {nullptr};
std::shared_ptr<gui::Button> btnLevelup {nullptr};
std::shared_ptr<gui::Button> btnChange1 {nullptr};
std::shared_ptr<gui::Button> btnChange2 {nullptr};
// KOTOR only
std::shared_ptr<gui::Label> lblAdorn {nullptr};
std::shared_ptr<gui::Button> btnScripts {nullptr};
std::shared_ptr<gui::Label> lblClass {nullptr};
std::shared_ptr<gui::Label> lblClass1 {nullptr};
std::shared_ptr<gui::Label> lblClass2 {nullptr};
std::shared_ptr<gui::Label> lblGood[10];
std::shared_ptr<gui::Label> lblLevel {nullptr};
std::shared_ptr<gui::Label> lblLevel1 {nullptr};
std::shared_ptr<gui::Label> lblLevel2 {nullptr};
std::shared_ptr<gui::Label> lblMore {nullptr};
std::shared_ptr<gui::Label> lblName {nullptr};
std::shared_ptr<gui::Button> btnCharLeft {nullptr};
std::shared_ptr<gui::Button> btnCharRight {nullptr};
// End KOTOR only
// TSL only
std::shared_ptr<gui::Label> lblForceMastery {nullptr};
std::shared_ptr<gui::Label> lblMoreBack {nullptr};
std::shared_ptr<gui::Label> lblStatsBorder {nullptr};
std::shared_ptr<gui::Label> lblTitle {nullptr};
std::shared_ptr<gui::Label> lblXpBack {nullptr};
std::shared_ptr<gui::Label> lblBar[6];
// End TSL only
} _binding;
InGameMenu &_inGameMenu;
void bindControls();
void refreshPortraits();
void refresh3D();

View file

@ -89,7 +89,7 @@ void InGameMenu::loadInventory() {
}
void InGameMenu::loadCharacter() {
_character = make_unique<CharacterMenu>(_game);
_character = make_unique<CharacterMenu>(_game, *this);
_character->load();
}