StatusWindow::StatusWindow(): Window(local_player->getName()) { listen(Event::AttributesChannel); setWindowName("Status"); setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setSaveVisible(true); setDefaultSize((windowContainer->getWidth() - 365) / 2, (windowContainer->getHeight() - 255) / 2, 480, 275); setMinWidth(480); setMinHeight(131); // ---------------------- // Status Part // ---------------------- mLvlLabel = new Label(strprintf(_("Level: %d"), 0)); mMoneyLabel = new Label(strprintf(_("Money: %s"), "")); int max = PlayerInfo::getAttribute(MAX_HP); mHpLabel = new Label(_("HP:")); mHpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(HP) / max : 0, 80, 15, Theme::PROG_HP); max = PlayerInfo::getAttribute(EXP_NEEDED); mXpLabel = new Label(_("Exp:")); mXpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(EXP) / max : 0, 80, 15, Theme::PROG_EXP); bool magicBar = Net::getGameHandler()->canUseMagicBar(); if (magicBar) { max = PlayerInfo::getAttribute(MAX_MP); mMpLabel = new Label(_("MP:")); mMpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(MAX_MP) / max : 0, 80, 15, Net::getPlayerHandler()->canUseMagic() ? Theme::PROG_MP : Theme::PROG_NO_MP); } place(0, 0, mLvlLabel, 3); // 5, 0 Job Level place(8, 0, mMoneyLabel, 3); place(0, 1, mHpLabel).setPadding(3); place(1, 1, mHpBar, 4); place(5, 1, mXpLabel).setPadding(3); place(6, 1, mXpBar, 5); int attributesFirstRow = 2; if (magicBar) { place(0, 2, mMpLabel).setPadding(3); // 5, 2 and 6, 2 Job Progress Bar place(1, 2, mMpBar, 4); // We move the attribute row to the next one attributesFirstRow = 3; } if (Net::getPlayerHandler()->getJobLocation() > 0) { mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0)); mJobLabel = new Label(_("Job:")); mJobBar = new ProgressBar(0.0f, 80, 15, Theme::PROG_JOB); place(5, 0, mJobLvlLabel, 3); place(5, 2, mJobLabel).setPadding(3); place(6, 2, mJobBar, 5); // We move the attribute row to the next one attributesFirstRow = 3; } // ---------------------- // Stats Part // ---------------------- mAttrCont = new VertContainer(28); mAttrScroll = new ScrollArea(mAttrCont); mAttrScroll->setOpaque(false); mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); place(0, attributesFirstRow, mAttrScroll, 5, 3); mDAttrCont = new VertContainer(28); mDAttrScroll = new ScrollArea(mDAttrCont); mDAttrScroll->setOpaque(false); mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); place(6, attributesFirstRow, mDAttrScroll, 5, 3); getLayout().setRowHeight(attributesFirstRow, Layout::AUTO_SET); mCharacterPointsLabel = new Label("Character points: 0"); place(0, attributesFirstRow + 3, mCharacterPointsLabel, 4); if (Net::getPlayerHandler()->canCorrectAttributes()) { mCorrectionPointsLabel = new Label("Correction points: 0"); place(4, attributesFirstRow + 3, mCorrectionPointsLabel, 4); } loadWindowState(); // Update bars updateHPBar(mHpBar, true); if (magicBar) updateMPBar(mMpBar, true); updateXPBar(mXpBar, false); mMoneyLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency(PlayerInfo::getAttribute(MONEY)).c_str())); mMoneyLabel->adjustSize(); mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"), PlayerInfo::getAttribute(CHAR_POINTS))); mCharacterPointsLabel->adjustSize(); mLvlLabel->setCaption(strprintf(_("Level: %d"), PlayerInfo::getAttribute(LEVEL))); mLvlLabel->adjustSize(); }
void StatusWindow::event(Event::Channel channel, const Event &event) { if (event.getType() == Event::UpdateAttribute) { switch(event.getInt("id")) { case HP: case MAX_HP: updateHPBar(mHpBar, true); break; case MP: case MAX_MP: updateMPBar(mMpBar, true); break; case EXP: case EXP_NEEDED: updateXPBar(mXpBar, false); break; case MONEY: mMoneyLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency( event.getInt("newValue")).c_str())); mMoneyLabel->adjustSize(); break; case CHAR_POINTS: mCharacterPointsLabel->setCaption(strprintf( _("Character points: %d"), event.getInt("newValue"))); mCharacterPointsLabel->adjustSize(); updateAttrs(); break; case CORR_POINTS: mCorrectionPointsLabel->setCaption(strprintf( _("Correction points: %d"), event.getInt("newValue"))); mCorrectionPointsLabel->adjustSize(); updateAttrs(); break; case LEVEL: mLvlLabel->setCaption(strprintf(_("Level: %d"), event.getInt("newValue"))); mLvlLabel->adjustSize(); break; } } else if (event.getType() == Event::UpdateStat) { int id = event.getInt("id"); if (id == Net::getPlayerHandler()->getJobLocation()) { mJobLvlLabel->setCaption(strprintf(_("Job: %d"), PlayerInfo::getStatBase(id))); mJobLvlLabel->adjustSize(); updateProgressBar(mJobBar, id, false); } else { Attrs::iterator it = mAttrs.find(id); if (it != mAttrs.end()) { it->second->update(); } if (Net::getNetworkType() == ServerInfo::TMWATHENA && id == TmwAthena::MATK) { updateMPBar(mMpBar, true); } } } }
void StatusWindow::attributeChanged(const AttributesT id, const int oldVal A_UNUSED, const int newVal) { switch (id) { case Attributes::HP: case Attributes::MAX_HP: updateHPBar(mHpBar, true); break; case Attributes::MP: case Attributes::MAX_MP: updateMPBar(mMpBar, true); break; case Attributes::EXP: case Attributes::EXP_NEEDED: updateXPBar(mXpBar, false); break; case Attributes::MONEY: // TRANSLATORS: status window label mMoneyLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency(newVal).c_str())); mMoneyLabel->adjustSize(); break; case Attributes::CHAR_POINTS: mCharacterPointsLabel->setCaption(strprintf( // TRANSLATORS: status window label _("Character points: %d"), newVal)); mCharacterPointsLabel->adjustSize(); // Update all attributes for (Attrs::const_iterator it = mAttrs.begin(); it != mAttrs.end(); ++it) { if (it->second) it->second->update(); } break; case Attributes::CORR_POINTS: mCorrectionPointsLabel->setCaption(strprintf( // TRANSLATORS: status window label _("Correction points: %d"), newVal)); mCorrectionPointsLabel->adjustSize(); // Update all attributes for (Attrs::const_iterator it = mAttrs.begin(); it != mAttrs.end(); ++it) { if (it->second) it->second->update(); } break; case Attributes::LEVEL: // TRANSLATORS: status window label mLvlLabel->setCaption(strprintf(_("Level: %d"), newVal)); mLvlLabel->adjustSize(); break; default: break; } }
StatusWindow::StatusWindow() : Window(localPlayer ? localPlayer->getName() : "?", Modal_false, nullptr, "status.xml"), ActionListener(), AttributeListener(), StatListener(), // TRANSLATORS: status window label mLvlLabel(new Label(this, strprintf(_("Level: %d"), 0))), // TRANSLATORS: status window label mMoneyLabel(new Label(this, strprintf(_("Money: %s"), ""))), // TRANSLATORS: status window label mHpLabel(new Label(this, _("HP:"))), mMpLabel(nullptr), // TRANSLATORS: status window label mXpLabel(new Label(this, _("Exp:"))), mHpBar(nullptr), mMpBar(nullptr), mXpBar(nullptr), mJobLvlLabel(nullptr), mJobLabel(nullptr), mJobBar(nullptr), mAttrCont(new VertContainer(this, 32)), mAttrScroll(new ScrollArea(this, mAttrCont, false)), mDAttrCont(new VertContainer(this, 32)), mDAttrScroll(new ScrollArea(this, mDAttrCont, false)), mCharacterPointsLabel(new Label(this, "C")), mCorrectionPointsLabel(nullptr), // TRANSLATORS: status window button mCopyButton(new Button(this, _("Copy to chat"), "copy", this)), mAttrs() { setWindowName("Status"); if (setupWindow) setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setSaveVisible(true); setStickyButtonLock(true); setDefaultSize((windowContainer->getWidth() - 480) / 2, (windowContainer->getHeight() - 500) / 2, 480, 500); if (localPlayer && !localPlayer->getRaceName().empty()) { setCaption(strprintf("%s (%s)", localPlayer->getName().c_str(), localPlayer->getRaceName().c_str())); } int max = PlayerInfo::getAttribute(Attributes::MAX_HP); if (!max) max = 1; mHpBar = new ProgressBar(this, static_cast<float>(PlayerInfo::getAttribute( Attributes::HP)) / static_cast<float>(max), 80, 0, ProgressColorId::PROG_HP, "hpprogressbar.xml", "hpprogressbar_fill.xml"); mHpBar->setColor(getThemeColor(ThemeColorId::HP_BAR), getThemeColor(ThemeColorId::HP_BAR_OUTLINE)); max = PlayerInfo::getAttribute(Attributes::EXP_NEEDED); mXpBar = new ProgressBar(this, max ? static_cast<float>(PlayerInfo::getAttribute(Attributes::EXP)) / static_cast<float>(max) : static_cast<float>(0), 80, 0, ProgressColorId::PROG_EXP, "xpprogressbar.xml", "xpprogressbar_fill.xml"); mXpBar->setColor(getThemeColor(ThemeColorId::XP_BAR), getThemeColor(ThemeColorId::XP_BAR_OUTLINE)); const bool magicBar = gameHandler->canUseMagicBar(); const bool job = serverConfig.getValueBool("showJob", true); if (magicBar) { max = PlayerInfo::getAttribute(Attributes::MAX_MP); // TRANSLATORS: status window label mMpLabel = new Label(this, _("MP:")); const bool useMagic = playerHandler->canUseMagic(); mMpBar = new ProgressBar(this, max ? static_cast<float>( PlayerInfo::getAttribute(Attributes::MAX_MP)) / static_cast<float>(max) : static_cast<float>(0), 80, 0, useMagic ? ProgressColorId::PROG_MP : ProgressColorId::PROG_NO_MP, useMagic ? "mpprogressbar.xml" : "nompprogressbar.xml", useMagic ? "mpprogressbar_fill.xml" : "nompprogressbar_fill.xml"); if (useMagic) { mMpBar->setColor(getThemeColor(ThemeColorId::MP_BAR), getThemeColor(ThemeColorId::MP_BAR_OUTLINE)); } else { mMpBar->setColor(getThemeColor(ThemeColorId::NO_MP_BAR), getThemeColor(ThemeColorId::NO_MP_BAR_OUTLINE)); } } else { mMpLabel = nullptr; mMpBar = nullptr; } place(0, 0, mLvlLabel, 3); place(0, 1, mHpLabel).setPadding(3); place(1, 1, mHpBar, 4); place(5, 1, mXpLabel).setPadding(3); place(6, 1, mXpBar, 5); if (magicBar) { place(0, 2, mMpLabel).setPadding(3); // 5, 2 and 6, 2 Job Progress Bar if (job) place(1, 2, mMpBar, 4); else place(1, 2, mMpBar, 10); } if (job) { // TRANSLATORS: status window label mJobLvlLabel = new Label(this, strprintf(_("Job: %d"), 0)); // TRANSLATORS: status window label mJobLabel = new Label(this, _("Job:")); mJobBar = new ProgressBar(this, 0.0F, 80, 0, ProgressColorId::PROG_JOB, "jobprogressbar.xml", "jobprogressbar_fill.xml"); mJobBar->setColor(getThemeColor(ThemeColorId::JOB_BAR), getThemeColor(ThemeColorId::JOB_BAR_OUTLINE)); place(3, 0, mJobLvlLabel, 3); place(5, 2, mJobLabel).setPadding(3); place(6, 2, mJobBar, 5); place(6, 0, mMoneyLabel, 3); } else { mJobLvlLabel = nullptr; mJobLabel = nullptr; mJobBar = nullptr; place(3, 0, mMoneyLabel, 3); } // ---------------------- // Stats Part // ---------------------- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); place(0, 3, mAttrScroll, 5, 3); mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); place(6, 3, mDAttrScroll, 5, 3); getLayout().setRowHeight(3, LayoutType::SET); place(0, 6, mCharacterPointsLabel, 5); place(0, 5, mCopyButton); if (playerHandler->canCorrectAttributes()) { mCorrectionPointsLabel = new Label(this, "C"); place(0, 7, mCorrectionPointsLabel, 5); } loadWindowState(); enableVisibleSound(true); // Update bars updateHPBar(mHpBar, true); if (magicBar) updateMPBar(mMpBar, true); updateXPBar(mXpBar, false); // TRANSLATORS: status window label mMoneyLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency( PlayerInfo::getAttribute(Attributes::MONEY)).c_str())); mMoneyLabel->adjustSize(); // TRANSLATORS: status window label mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"), PlayerInfo::getAttribute(Attributes::CHAR_POINTS))); mCharacterPointsLabel->adjustSize(); updateLevelLabel(); }
void StatusWindow::update() { // Status Part // ----------- mLvlLabel->setCaption(strprintf(_("Level: %d"), mPlayer->getLevel())); mLvlLabel->adjustSize(); mJobLvlLabel->setCaption(strprintf(_("Job: %d"), mPlayer->mJobLevel)); mJobLvlLabel->adjustSize(); if (mCurrency != mPlayer->getMoney()) { mCurrency = mPlayer->getMoney(); mGpLabel->setCaption(strprintf(_("Money: %s"), Units::formatCurrency(mCurrency).c_str())); mGpLabel->adjustSize(); } updateHPBar(mHpBar, true); updateMPBar(mMpBar, true); updateXPBar(mXpBar, false); updateJobBar(mJobBar, false); // Stats Part // ---------- static const char *attrNames[6] = { N_("Strength"), N_("Agility"), N_("Vitality"), N_("Intelligence"), N_("Dexterity"), N_("Luck") }; int statusPoints = mPlayer->mStatsPointsToAttribute; // Update labels for (int i = 0; i < 6; i++) { mStatsLabel[i]->setCaption(gettext(attrNames[i])); mStatsDisplayLabel[i]->setCaption(toString((int) mPlayer->mAttr[i])); mPointsLabel[i]->setCaption(toString((int) mPlayer->mAttrUp[i])); mStatsLabel[i]->adjustSize(); mStatsDisplayLabel[i]->adjustSize(); mPointsLabel[i]->adjustSize(); mStatsButton[i]->setEnabled(mPlayer->mAttrUp[i] <= statusPoints); } mRemainingStatsPointsLabel->setCaption( strprintf(_("Remaining Status Points: %d"), statusPoints)); mRemainingStatsPointsLabel->adjustSize(); // Derived Stats Points // Attack TODO: Count equipped Weapons and items attack bonuses mStatsAttackPoints->setCaption( toString(mPlayer->ATK + mPlayer->ATK_BONUS)); mStatsAttackPoints->adjustSize(); // Defense TODO: Count equipped Armors and items defense bonuses mStatsDefensePoints->setCaption( toString(mPlayer->DEF + mPlayer->DEF_BONUS)); mStatsDefensePoints->adjustSize(); // Magic Attack TODO: Count equipped items M.Attack bonuses mStatsMagicAttackPoints->setCaption( toString(mPlayer->MATK + mPlayer->MATK_BONUS)); mStatsMagicAttackPoints->adjustSize(); // Magic Defense TODO: Count equipped items M.Defense bonuses mStatsMagicDefensePoints->setCaption( toString(mPlayer->MDEF + mPlayer->MDEF_BONUS)); mStatsMagicDefensePoints->adjustSize(); // Accuracy % mStatsAccuracyPoints->setCaption(toString(mPlayer->HIT)); mStatsAccuracyPoints->adjustSize(); // Evasion % mStatsEvadePoints->setCaption(toString(mPlayer->FLEE)); mStatsEvadePoints->adjustSize(); // Reflex % mStatsReflexPoints->setCaption(toString(mPlayer->DEX / 4)); // + counter mStatsReflexPoints->adjustSize(); }