00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/statuswindow.h"
00023
00024 #include "gui/widgets/button.h"
00025 #include "gui/widgets/label.h"
00026 #include "gui/widgets/progressbar.h"
00027 #include "gui/widgets/windowcontainer.h"
00028
00029 #include "localplayer.h"
00030
00031 #include "utils/strprintf.h"
00032 #include "utils/stringutils.h"
00033
00034 StatusWindow::StatusWindow(LocalPlayer *player):
00035 Window(player->getName()),
00036 mPlayer(player)
00037 {
00038 setWindowName("Status");
00039 setResizable(true);
00040 setCloseButton(true);
00041 setSaveVisible(true);
00042 setDefaultSize((windowContainer->getWidth() - 365) / 2,
00043 (windowContainer->getHeight() - 255) / 2, 365, 275);
00044 loadWindowState();
00045
00046
00047
00048
00049
00050 mLvlLabel = new Label("Level:");
00051 mMoneyLabel = new Label("Money:");
00052
00053 mHpLabel = new Label("HP:");
00054 mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34);
00055 mHpValueLabel = new Label;
00056
00057 int y = 3;
00058 int x = 5;
00059
00060 mLvlLabel->setPosition(x, y);
00061 x += mLvlLabel->getWidth() + 40;
00062 mMoneyLabel->setPosition(x, y);
00063
00064 y += mLvlLabel->getHeight() + 5;
00065 x = 5;
00066
00067 mHpLabel->setPosition(x, y);
00068 x += mHpLabel->getWidth() + 5;
00069 mHpBar->setPosition(x, y);
00070 x += mHpBar->getWidth() + 5;
00071 mHpValueLabel->setPosition(x, y);
00072
00073 y += mHpLabel->getHeight() + 5;
00074 x = 5;
00075
00076 add(mLvlLabel);
00077 add(mMoneyLabel);
00078 add(mHpLabel);
00079 add(mHpValueLabel);
00080 add(mHpBar);
00081
00082
00083
00084
00085
00086
00087 gcn::Label *mStatsTitleLabel = new Label("Stats");
00088 gcn::Label *mStatsTotalLabel = new Label("Total");
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 for (int i = 0; i < 6; i++) {
00110 mStatsLabel[i] = new Label;
00111 mStatsDisplayLabel[i] = new Label;
00112 }
00113 mCharacterPointsLabel = new Label;
00114 mCorrectionPointsLabel = new Label;
00115
00116
00117 mStatsPlus[0] = new Button("+", "STR+", this);
00118 mStatsPlus[1] = new Button("+", "AGI+", this);
00119 mStatsPlus[2] = new Button("+", "DEX+", this);
00120 mStatsPlus[3] = new Button("+", "VIT+", this);
00121 mStatsPlus[4] = new Button("+", "INT+", this);
00122 mStatsPlus[5] = new Button("+", "WIL+", this);
00123
00124 mStatsMinus[0] = new Button("-", "STR-", this);
00125 mStatsMinus[1] = new Button("-", "AGI-", this);
00126 mStatsMinus[2] = new Button("-", "DEX-", this);
00127 mStatsMinus[3] = new Button("-", "VIT-", this);
00128 mStatsMinus[4] = new Button("-", "INT-", this);
00129 mStatsMinus[5] = new Button("-", "WIL-", this);
00130
00131
00132
00133
00134 mStatsTitleLabel->setPosition(mHpLabel->getX(), mHpLabel->getY() + 23 );
00135 mStatsTotalLabel->setPosition(110, mStatsTitleLabel->getY() + 15);
00136 int totalLabelY = mStatsTotalLabel->getY();
00137
00138 for (int i = 0; i < 6; i++)
00139 {
00140 mStatsLabel[i]->setPosition(5,
00141 mStatsTotalLabel->getY() + (i * 23) + 15);
00142 mStatsMinus[i]->setPosition(85, totalLabelY + (i * 23) + 15);
00143 mStatsDisplayLabel[i]->setPosition(125,
00144 totalLabelY + (i * 23) + 15);
00145 mStatsPlus[i]->setPosition(185, totalLabelY + (i * 23) + 15);
00146 }
00147
00148 mCharacterPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 25);
00149 mCorrectionPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 35);
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 add(mStatsTitleLabel);
00169 add(mStatsTotalLabel);
00170 for(int i = 0; i < 6; i++)
00171 {
00172 add(mStatsLabel[i]);
00173 add(mStatsDisplayLabel[i]);
00174 add(mStatsPlus[i]);
00175 add(mStatsMinus[i]);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 add(mCharacterPointsLabel);
00194 add(mCorrectionPointsLabel);
00195 }
00196
00197 void StatusWindow::update()
00198 {
00199
00200
00201 mLvlLabel->setCaption( "Level: " +
00202 toString(mPlayer->getLevel()) +
00203 " (" +
00204 toString(mPlayer->getLevelProgress()) +
00205 "%)");
00206 mLvlLabel->adjustSize();
00207
00208 mMoneyLabel->setCaption("Money: " + toString(mPlayer->getMoney()) + " GP");
00209 mMoneyLabel->adjustSize();
00210
00211 updateHPBar(mHpBar, true);
00212
00213
00214
00215 const std::string attrNames[6] = {
00216 "Strength",
00217 "Agility",
00218 "Dexterity",
00219 "Vitality",
00220 "Intelligence",
00221 "Willpower"
00222 };
00223 int characterPoints = mPlayer->getCharacterPoints();
00224 int correctionPoints = mPlayer->getCorrectionPoints();
00225
00226 for (int i = 0; i < 6; i++)
00227 {
00228 mStatsLabel[i]->setCaption(attrNames[i]);
00229 mStatsDisplayLabel[i]->setCaption(
00230 strprintf("%d / %d",
00231 mPlayer->getAttributeEffective(CHAR_ATTR_BEGIN + i),
00232 mPlayer->getAttributeBase(CHAR_ATTR_BEGIN + i)));
00233
00234 mStatsLabel[i]->adjustSize();
00235 mStatsDisplayLabel[i]->adjustSize();
00236
00237 mStatsPlus[i]->setEnabled(characterPoints);
00238 mStatsMinus[i]->setEnabled(correctionPoints);
00239 }
00240 mCharacterPointsLabel->setCaption("Character Points: " +
00241 toString(characterPoints));
00242 mCharacterPointsLabel->adjustSize();
00243
00244 mCorrectionPointsLabel->setCaption("Correction Points: " +
00245 toString(correctionPoints));
00246 mCorrectionPointsLabel->adjustSize();
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
00284 mLvlLabel->getY());
00285
00286 }
00287
00288 void StatusWindow::draw(gcn::Graphics *g)
00289 {
00290 update();
00291
00292 Window::draw(g);
00293 }
00294
00295 void StatusWindow::action(const gcn::ActionEvent &event)
00296 {
00297 const std::string &eventId = event.getId();
00298
00299
00300 if (eventId == "STR+")
00301 {
00302 mPlayer->raiseAttribute(LocalPlayer::STR);
00303 }
00304 else if (eventId == "AGI+")
00305 {
00306 mPlayer->raiseAttribute(LocalPlayer::AGI);
00307 }
00308 else if (eventId == "DEX+")
00309 {
00310 mPlayer->raiseAttribute(LocalPlayer::DEX);
00311 }
00312 else if (eventId == "VIT+")
00313 {
00314 mPlayer->raiseAttribute(LocalPlayer::VIT);
00315 }
00316 else if (eventId == "INT+")
00317 {
00318 mPlayer->raiseAttribute(LocalPlayer::INT);
00319 }
00320 else if (eventId == "WIL+")
00321 {
00322 mPlayer->raiseAttribute(LocalPlayer::WIL);
00323 }
00324
00325 else if (eventId == "STR-")
00326 {
00327 mPlayer->lowerAttribute(LocalPlayer::STR);
00328 }
00329 else if (eventId == "AGI-")
00330 {
00331 mPlayer->lowerAttribute(LocalPlayer::AGI);
00332 }
00333 else if (eventId == "DEX-")
00334 {
00335 mPlayer->lowerAttribute(LocalPlayer::DEX);
00336 }
00337 else if (eventId == "VIT-")
00338 {
00339 mPlayer->lowerAttribute(LocalPlayer::VIT);
00340 }
00341 else if (eventId == "INT-")
00342 {
00343 mPlayer->lowerAttribute(LocalPlayer::INT);
00344 }
00345 else if (eventId == "WIL-")
00346 {
00347 mPlayer->lowerAttribute(LocalPlayer::WIL);
00348 }
00349 }
00350
00351
00352
00353 void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
00354 {
00355 if (showMax)
00356 bar->setText(toString(player_node->getHp()) +
00357 "/" + toString(player_node->getMaxHp()));
00358 else
00359 bar->setText(toString(player_node->getHp()));
00360
00361
00362 if (player_node->getHp() < player_node->getMaxHp() / 3)
00363 {
00364 bar->setColor(223, 32, 32);
00365 }
00366 else if (player_node->getHp() < (player_node->getMaxHp() / 3) * 2)
00367 {
00368 bar->setColor(230, 171, 34);
00369 }
00370 else
00371 {
00372 bar->setColor(0, 171, 34);
00373 }
00374
00375 bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
00376 }