diff options
Diffstat (limited to 'src/gui')
78 files changed, 1636 insertions, 1868 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 5b393a06..a2398472 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -27,6 +27,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/slider.h" +#include "gui/setup.h" #include "gui/shop.h" #include "gui/shoplistbox.h" @@ -47,6 +48,7 @@ BuyDialog::BuyDialog(): mMoney(0), mAmountItems(0), mMaxItems(0) { setWindowName("Buy"); + setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setMinWidth(260); @@ -65,8 +67,12 @@ BuyDialog::BuyDialog(): mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"), "", "")); - mIncreaseButton = new Button("+", "+", this); - mDecreaseButton = new Button("-", "-", this); + // TRANSLATORS: This is a narrow symbol used to denote 'increasing'. + // You may change this symbol if your language uses another. + mIncreaseButton = new Button(_("+"), "inc", this); + // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'. + // You may change this symbol if your language uses another. + mDecreaseButton = new Button(_("-"), "dec", this); mBuyButton = new Button(_("Buy"), "buy", this); mQuitButton = new Button(_("Quit"), "quit", this); mAddMaxButton = new Button(_("Max"), "max", this); @@ -160,13 +166,13 @@ void BuyDialog::action(const gcn::ActionEvent &event) mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } - else if (event.getId() == "+" && mAmountItems < mMaxItems) + else if (event.getId() == "inc" && mAmountItems < mMaxItems) { mAmountItems++; mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 1) + else if (event.getId() == "dec" && mAmountItems > 1) { mAmountItems--; mSlider->setValue(mAmountItems); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 53c2419a..c96c9f24 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -24,6 +24,7 @@ #include "npc.h" #include "gui/widgets/button.h" +#include "gui/setup.h" #include "net/net.h" #include "net/npchandler.h" @@ -35,6 +36,7 @@ BuySellDialog::BuySellDialog(): mBuyButton(0) { setWindowName("BuySell"); + setupWindow->registerWindowForReset(this); static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index d36ab487..eb05e25e 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -46,7 +46,7 @@ ChangeEmailDialog::ChangeEmailDialog(Window *parent, LoginData *loginData): { gcn::Label *accountLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); - gcn::Label *newEmailLabel = new Label(_("Type New Email Address twice:")); + gcn::Label *newEmailLabel = new Label(_("Type new email address twice:")); mFirstEmailField = new TextField; mSecondEmailField = new TextField; mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); @@ -114,29 +114,29 @@ ChangeEmailDialog::action(const gcn::ActionEvent &event) logger->log("ChangeEmailDialog::Email change, Username is %s", username.c_str()); - std::stringstream errorMsg; + std::stringstream errorMessage; int error = 0; if (newFirstEmail.length() < LEN_MIN_PASSWORD) { // First email address too short - errorMsg << "The new email address needs to be at least " - << LEN_MIN_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The new email address needs to be at " + "least %d characters long."), + LEN_MIN_PASSWORD); error = 1; } else if (newFirstEmail.length() > LEN_MAX_PASSWORD - 1 ) { // First email address too long - errorMsg << "The new email address needs to be less than " - << LEN_MAX_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The new email address needs to be " + "less than %d characters long."), + LEN_MAX_PASSWORD); error = 1; } else if (newFirstEmail != newSecondEmail) { // Second Pass mismatch - errorMsg << "The email address entries mismatch."; + errorMessage << _("The email address entries mismatch."); error = 2; } @@ -151,7 +151,7 @@ ChangeEmailDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mSecondEmailField); } - OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), errorMessage.str()); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 4be92b15..9d66d13a 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -96,36 +96,35 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) logger->log("ChangePasswordDialog::Password change, Username is %s", username.c_str()); - std::stringstream errorMsg; + std::stringstream errorMessage; int error = 0; // Check old Password if (oldPassword.empty()) { // No old password - errorMsg << "Enter the old Password first."; + errorMessage << _("Enter the old password first."); error = 1; } else if (newFirstPass.length() < LEN_MIN_PASSWORD) { // First password too short - errorMsg << "The new password needs to be at least " - << LEN_MIN_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The new password needs to be at least " + "%d characters long."), LEN_MIN_PASSWORD); error = 2; } else if (newFirstPass.length() > LEN_MAX_PASSWORD - 1 ) { // First password too long - errorMsg << "The new password needs to be less than " - << LEN_MAX_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The new password needs to be less " + "than %d characters long."), + LEN_MAX_PASSWORD); error = 2; } else if (newFirstPass != newSecondPass) { // Second Pass mismatch - errorMsg << "The new password entries mismatch."; + errorMessage << _("The new password entries mismatch."); error = 3; } @@ -144,7 +143,7 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mSecondPassField); } - OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), errorMessage.str()); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 79ec5c1a..e09eee55 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -64,12 +64,16 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): mNameField = new TextField(""); mNameLabel = new Label(_("Name:")); - mNextHairColorButton = new Button(">", "nextcolor", this); - mPrevHairColorButton = new Button("<", "prevcolor", this); - mHairColorLabel = new Label(_("Hair Color:")); - mNextHairStyleButton = new Button(">", "nextstyle", this); - mPrevHairStyleButton = new Button("<", "prevstyle", this); - mHairStyleLabel = new Label(_("Hair Style:")); + // TRANSLATORS: This is a narrow symbol used to denote 'next'. + // You may change this symbol if your language uses another. + mNextHairColorButton = new Button(_(">"), "nextcolor", this); + // TRANSLATORS: This is a narrow symbol used to denote 'previous'. + // You may change this symbol if your language uses another. + mPrevHairColorButton = new Button(_("<"), "prevcolor", this); + mHairColorLabel = new Label(_("Hair color:")); + mNextHairStyleButton = new Button(_(">"), "nextstyle", this); + mPrevHairStyleButton = new Button(_("<"), "prevstyle", this); + mHairStyleLabel = new Label(_("Hair style:")); mCreateButton = new Button(_("Create"), "create", this); mCancelButton = new Button(_("Cancel"), "cancel", this); mMale = new RadioButton(_("Male"), "gender"); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 63a25d45..69a627e1 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -36,6 +36,8 @@ #include "gui/changeemaildialog.h" #include "net/tmwserv/accountserver/account.h" +#else +#include "net/ea/protocol.h" #endif #include "gui/widgets/button.h" @@ -116,7 +118,7 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, mNameLabel = new Label(strprintf(_("Name: %s"), "")); mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); - mMoneyLabel = new Label(strprintf(_("Money: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %s"), "")); // Control that shows the Player mPlayerBox = new PlayerBox; @@ -296,9 +298,9 @@ void CharSelectDialog::updatePlayerInfo() mNameLabel->setCaption(strprintf(_("Name: %s"), pi->getName().c_str())); mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel())); -#ifndef TMWSERV_SUPPORT +#ifdef EATHENA_SUPPORT mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), - pi->mJobLevel)); + pi->getAttributeBase(JOB))); #endif mMoneyLabel->setCaption(strprintf(_("Money: %s"), mMoney.c_str())); if (!mCharSelected) @@ -362,7 +364,10 @@ bool CharSelectDialog::selectByName(const std::string &name) LocalPlayer *player = mCharInfo->getEntry(); if (player && player->getName() == name) + { + mMoney = Units::formatCurrency(player->getMoney()); return true; + } mCharInfo->next(); } while (mCharInfo->getPos()); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 1ce1b77c..c337d33b 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -23,6 +23,7 @@ #include "gui/itemlinkhandler.h" #include "gui/recorder.h" +#include "gui/setup.h" #include "gui/sdlinput.h" #include "gui/widgets/chattab.h" @@ -39,6 +40,7 @@ #include "net/net.h" #include "utils/dtor.h" +#include "utils/gettext.h" #include "utils/stringutils.h" #include <guichan/focushandler.hpp> @@ -76,6 +78,8 @@ ChatWindow::ChatWindow(): { setWindowName("Chat"); + setupWindow->registerWindowForReset(this); + // no title presented, title bar is padding so window can be moved. gcn::Window::setTitleBarHeight(gcn::Window::getPadding() + 4); setShowTitle(false); @@ -138,9 +142,14 @@ void ChatWindow::adjustTabSize() ChatTab *tab = getFocused(); if (tab) { gcn::Widget *content = tab->mScrollArea; + bool scrollLock = false; + if(tab->mScrollArea->getVerticalMaxScroll() == tab->mScrollArea->getVerticalScrollAmount()) + scrollLock = true; content->setSize(mChatTabs->getWidth() - 2 * content->getFrameSize(), mChatTabs->getContainerHeight() - 2 * content->getFrameSize()); content->logic(); + if(scrollLock) + tab->mScrollArea->setVerticalScrollAmount(tab->mScrollArea->getVerticalMaxScroll()); } } @@ -323,8 +332,8 @@ void ChatWindow::doPresent() } } - std::string cpc = strprintf(_("%d players are present."), playercount); - std::string log = _("Present: ") + response + std::string("; ") + cpc; + std::string log = strprintf(_("Present: %s; %d players are present."), + response.c_str(), playercount); if (mRecorder->isRecording()) { @@ -360,6 +369,37 @@ void ChatWindow::scroll(int amount) tab->scroll(amount); } +void ChatWindow::mousePressed(gcn::MouseEvent &event) +{ + Window::mousePressed(event); + + if(event.isConsumed()) + return; + + mMoved = event.getY() <= mCurrentTab->getHeight(); + mDragOffsetX = event.getX(); + mDragOffsetY = event.getY(); + +} + +void ChatWindow::mouseDragged(gcn::MouseEvent &event) +{ + Window::mouseDragged(event); + + if(event.isConsumed()) + return; + + if(isMovable() && mMoved) + { + int newX = std::max(0, getX() + event.getX() - mDragOffsetX); + int newY = std::max(0, getY() + event.getY() - mDragOffsetY); + newX = std::min(graphics->getWidth() - getWidth(), newX); + newY = std::min(graphics->getHeight() - getHeight(), newY); + setPosition(newX, newY); + } +} + + void ChatWindow::keyPressed(gcn::KeyEvent &event) { if (event.getKey().getValue() == Key::DOWN) diff --git a/src/gui/chat.h b/src/gui/chat.h index 7080392e..2de3a634 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -150,6 +150,11 @@ class ChatWindow : public Window, /** Override to reset mTmpVisible */ void setVisible(bool visible); + + void mousePressed(gcn::MouseEvent &event); + void mouseDragged(gcn::MouseEvent &event); + + /** * Scrolls the chat window * diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 1c3b7ff5..9e361173 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -31,7 +31,7 @@ #include "utils/gettext.h" ConnectionDialog::ConnectionDialog(State previousState): - Window("Info"), mProgress(0), mPreviousState(previousState) + Window(_("Info")), mProgress(0), mPreviousState(previousState) { setContentSize(200, 100); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index f3dbe5e2..59c0f254 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -21,6 +21,7 @@ #include "gui/debugwindow.h" +#include "gui/setup.h" #include "gui/viewport.h" #include "gui/widgets/label.h" @@ -31,31 +32,33 @@ #include "particle.h" #include "map.h" +#include "utils/gettext.h" #include "utils/stringutils.h" DebugWindow::DebugWindow(): - Window("Debug") + Window(_("Debug")) { setWindowName("Debug"); + setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setSaveVisible(true); setDefaultSize(400, 100, ImageRect::CENTER); - mFPSLabel = new Label("0 FPS"); - mMusicFileLabel = new Label("Music: "); - mMapLabel = new Label("Map: "); - mMiniMapLabel = new Label("Mini-Map: "); - mTileMouseLabel = new Label("Mouse: 0, 0"); - mParticleCountLabel = new Label("Particle count: 0"); + mFPSLabel = new Label(strprintf(_("%d FPS"), 0)); + mMusicFileLabel = new Label(strprintf(_("Music: %s"), "")); + mMapLabel = new Label(strprintf(_("Map: %s"), "")); + mMinimapLabel = new Label(strprintf(_("Minimap: %s"), "")); + mTileMouseLabel = new Label(strprintf(_("Tile: (%d, %d)"), 0, 0)); + mParticleCountLabel = new Label(strprintf(_("Particle count: %d"), 0)); place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); place(0, 2, mMapLabel, 4); - place(0, 3, mMiniMapLabel, 4); + place(0, 3, mMinimapLabel, 4); loadWindowState(); } @@ -69,27 +72,28 @@ void DebugWindow::logic() int mouseTileX = (viewport->getMouseX() + viewport->getCameraX()) / 32; int mouseTileY = (viewport->getMouseY() + viewport->getCameraY()) / 32; - mFPSLabel->setCaption(toString(fps) + " FPS"); + mFPSLabel->setCaption(strprintf(_("%d FPS"), fps)); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + - toString(mouseTileY) + ")"); + mTileMouseLabel->setCaption(strprintf(_("Tile: (%d, %d)"), mouseTileX, + mouseTileY)); Map *currentMap = engine->getCurrentMap(); if (currentMap) { + // TODO: Add gettext support below const std::string music = "Music: " + currentMap->getProperty("music"); mMusicFileLabel->setCaption(music); const std::string minimap = - "MiniMap: " + currentMap->getProperty("minimap"); - mMiniMapLabel->setCaption(minimap); + "Minimap: " + currentMap->getProperty("minimap"); + mMinimapLabel->setCaption(minimap); const std::string map = "Map: " + currentMap->getProperty("_filename"); mMapLabel->setCaption(map); } - mParticleCountLabel->setCaption("Particle count: " + - toString(Particle::particleCount)); + mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"), + Particle::particleCount)); } diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index e30107f9..e4c45bde 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -43,7 +43,7 @@ class DebugWindow : public Window void logic(); private: - gcn::Label *mMusicFileLabel, *mMapLabel, *mMiniMapLabel; + gcn::Label *mMusicFileLabel, *mMapLabel, *mMinimapLabel; gcn::Label *mTileMouseLabel, *mFPSLabel; gcn::Label *mParticleCountLabel; }; diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index 8e37be72..c087fc7e 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -39,8 +39,6 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" static const int MAX_ITEMS = 12; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 44006971..25de201c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -25,6 +25,7 @@ #include "gui/itempopup.h" #include "gui/palette.h" #include "gui/playerbox.h" +#include "gui/setup.h" #include "gui/viewport.h" #include "equipment.h" @@ -50,31 +51,26 @@ static const int BOX_HEIGHT = 36; // Positions of the boxes, 2nd dimension is X and Y respectively. static const int boxPosition[][2] = { - { 50, 208 }, // EQUIP_LEGS_SLOT - { 8, 123 }, // EQUIP_FIGHT1_SLOT + { 90, 40 }, // EQUIP_TORSO_SLOT { 8, 78 }, // EQUIP_GLOVES_SLOT - { 129, 168 }, // EQUIP_RING2_SLOT + { 70, 0 }, // EQUIP_HEAD_SLOT + { 50, 208 }, // EQUIP_LEGS_SLOT + { 90, 208 }, // EQUIP_FEET_SLOT { 8, 168 }, // EQUIP_RING1_SLOT + { 129, 168 }, // EQUIP_RING2_SLOT + { 50, 40 }, // EQUIP_NECK_SLOT + { 8, 123 }, // EQUIP_FIGHT1_SLOT { 129, 123 }, // EQUIP_FIGHT2_SLOT - { 90, 208 }, // EQUIP_FEET_SLOT - { 50, 40 }, // EQUIP_CAPE_SLOT - { 70, 0 }, // EQUIP_HEAD_SLOT - { 90, 40 }, // EQUIP_TORSO_SLOT - { 129, 78 } // EQUIP_AMMO_SLOT + { 129, 78 } // EQUIP_PROJECTILE_SLOT }; -#ifdef TMWSERV_SUPPORT EquipmentWindow::EquipmentWindow(Equipment *equipment): -#else -EquipmentWindow::EquipmentWindow(): -#endif Window(_("Equipment")), -#ifdef TMWSERV_SUPPORT mEquipment(equipment), -#endif mSelected(-1) { mItemPopup = new ItemPopup; + setupWindow->registerWindowForReset(this); // Control that shows the Player PlayerBox *playerBox = new PlayerBox; @@ -96,16 +92,11 @@ EquipmentWindow::EquipmentWindow(): add(playerBox); add(mUnequip); - for (int i = 0; i < EQUIP_VECTOREND; i++) + for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) { mEquipBox[i].posX = boxPosition[i][0] + getPadding(); mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); } - -#ifdef EATHENA_SUPPORT - mEquipment = player_node->mEquipment.get(); - mInventory = player_node->getInventory(); -#endif } EquipmentWindow::~EquipmentWindow() @@ -122,7 +113,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) Window::drawChildren(graphics); - for (int i = 0; i < EQUIP_VECTOREND; i++) + for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) { if (i == mSelected) { @@ -140,13 +131,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT)); -#ifdef TMWSERV_SUPPORT Item *item = mEquipment->getEquipment(i); -#else - Item *item = (i != EQUIP_AMMO_SLOT) ? - mInventory->getItem(mEquipment->getEquipment(i)) : - mInventory->getItem(mEquipment->getArrows()); -#endif if (item) { // Draw Item. @@ -154,8 +139,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawImage(image, mEquipBox[i].posX + 2, mEquipBox[i].posY + 2); -#ifdef EATHENA_SUPPORT - if (i == EQUIP_AMMO_SLOT) + if (i == EQUIP_PROJECTILE_SLOT) { g->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(toString(item->getQuantity()), @@ -163,7 +147,6 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) mEquipBox[i].posY - getFont()->getHeight(), gcn::Graphics::CENTER); } -#endif } } } @@ -172,13 +155,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "unequip" && mSelected > -1) { -#ifdef TMWSERV_SUPPORT // TODO: merge these! Item *item = mEquipment->getEquipment(mSelected); -#else - Item *item = (mSelected != EQUIP_AMMO_SLOT) ? - mInventory->getItem(mEquipment->getEquipment(mSelected)) : - mInventory->getItem(mEquipment->getArrows()); -#endif Net::getInventoryHandler()->unequipItem(item); setSelected(-1); } @@ -186,20 +163,14 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) Item *EquipmentWindow::getItem(int x, int y) const { - for (int i = 0; i < EQUIP_VECTOREND; i++) + for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) { gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y)) { -#ifdef TMWSERV_SUPPORT return mEquipment->getEquipment(i); -#else - return (i != EQUIP_AMMO_SLOT) ? - mInventory->getItem(mEquipment->getEquipment(i)) : - mInventory->getItem(mEquipment->getArrows()); -#endif } } return NULL; @@ -215,15 +186,9 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { // Checks if any of the presses were in the equip boxes. - for (int i = 0; i < EQUIP_VECTOREND; i++) + for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++) { -#ifdef TMWSERV_SUPPORT Item *item = mEquipment->getEquipment(i); -#else - Item *item = (i != EQUIP_AMMO_SLOT) ? - mInventory->getItem(mEquipment->getEquipment(i)) : - mInventory->getItem(mEquipment->getArrows()); -#endif gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT); diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 8bc350a4..a7b2c0d1 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -24,11 +24,11 @@ #include "gui/widgets/window.h" +#include "equipment.h" #include "guichanfwd.h" #include <guichan/actionlistener.hpp> -class Equipment; class Inventory; class Item; class ItemPopup; @@ -44,11 +44,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener /** * Constructor. */ -#ifdef TMWSERV_SUPPORT EquipmentWindow(Equipment *equipment); -#else - EquipmentWindow(); -#endif /** * Destructor. @@ -64,40 +60,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener void mousePressed(gcn::MouseEvent& mouseEvent); -#ifdef TMWSERV_SUPPORT - enum EquipmentSlots - { - EQUIP_TORSO_SLOT = 0, - EQUIP_ARMS_SLOT = 1, - EQUIP_HEAD_SLOT = 2, - EQUIP_LEGS_SLOT = 3, - EQUIP_FEET_SLOT = 4, - EQUIP_RING1_SLOT = 5, - EQUIP_RING2_SLOT = 6, - EQUIP_NECKLACE_SLOT = 7, - EQUIP_FIGHT1_SLOT = 8, - EQUIP_FIGHT2_SLOT = 9, - EQUIP_PROJECTILE_SLOT = 10, - EQUIP_VECTOREND - }; -#else - enum EquipmentSlots - { - EQUIP_LEGS_SLOT = 0, - EQUIP_FIGHT1_SLOT, - EQUIP_GLOVES_SLOT, - EQUIP_RING2_SLOT, - EQUIP_RING1_SLOT, - EQUIP_FIGHT2_SLOT, - EQUIP_FEET_SLOT, - EQUIP_CAPE_SLOT, - EQUIP_HEAD_SLOT, - EQUIP_TORSO_SLOT, - EQUIP_AMMO_SLOT, - EQUIP_VECTOREND - }; -#endif - private: void mouseExited(gcn::MouseEvent &event); void mouseMoved(gcn::MouseEvent &event); @@ -107,9 +69,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener void setSelected(int index); Equipment *mEquipment; -#ifdef EATHENA_SUPPORT - Inventory *mInventory; -#endif /** * Equipment box. @@ -120,12 +79,12 @@ class EquipmentWindow : public Window, public gcn::ActionListener int posY; }; - EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */ + EquipBox mEquipBox[Equipment::EQUIP_VECTOREND]; /**< Equipment Boxes. */ ItemPopup *mItemPopup; gcn::Button *mUnequip; - int mSelected; /**< Index of selected item. */ + int mSelected; /**< Index of selected item. */ }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index 6dc86e13..05af7780 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -24,6 +24,7 @@ #include "gui/confirmdialog.h" #include "gui/guildlistbox.h" +#include "gui/setup.h" #include "gui/textdialog.h" #include "gui/widgets/button.h" @@ -41,6 +42,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "utils/stringutils.h" #include <algorithm> @@ -58,6 +60,7 @@ GuildWindow::GuildWindow(): setMinWidth(200); setMinHeight(280); setDefaultSize(124, 41, 288, 330); + setupWindow->registerWindowForReset(this); // Set button events Id mGuildButton[0] = new Button(_("Create Guild"), "CREATE_GUILD", this); @@ -110,7 +113,8 @@ void GuildWindow::action(const gcn::ActionEvent &event) { // Set focus so that guild name to be created can be typed. mFocus = true; - guildDialog = new TextDialog("Guild Name", "Choose your guild's name", this); + guildDialog = new TextDialog(_("Guild Name"), + _("Choose your guild's name."), this); guildDialog->setOKButtonActionId("CREATE_GUILD_OK"); guildDialog->addActionListener(this); } @@ -118,7 +122,8 @@ void GuildWindow::action(const gcn::ActionEvent &event) { // TODO - Give feedback on whether the invite succeeded mFocus = true; - inviteDialog = new TextDialog("Member Invite", "Who would you like to invite?", this); + inviteDialog = new TextDialog(_("Member Invite"), + _("Who would you like to invite?"), this); inviteDialog->setOKButtonActionId("INVITE_USER_OK"); inviteDialog->addActionListener(this); } @@ -128,7 +133,8 @@ void GuildWindow::action(const gcn::ActionEvent &event) if (guild) { Net::ChatServer::Guild::quitGuild(guild); - localChatTab->chatLog("Guild " + mGuildTabs->getSelectedTab()->getCaption() + " quit", BY_SERVER); + localChatTab->chatLog(strprintf(_("Guild %s quit."), + mGuildTabs->getSelectedTab()->getCaption().c_str()), BY_SERVER); } } else if (eventId == "CREATE_GUILD_OK") @@ -144,7 +150,8 @@ void GuildWindow::action(const gcn::ActionEvent &event) // Defocus dialog mFocus = false; - localChatTab->chatLog("Creating Guild called " + name, BY_SERVER); + localChatTab->chatLog(strprintf(_("Creating guild called %s."), + name.c_str()), BY_SERVER); guildDialog->scheduleDelete(); } else if (eventId == "INVITE_USER_OK") @@ -157,7 +164,7 @@ void GuildWindow::action(const gcn::ActionEvent &event) // Defocus dialog mFocus = false; - localChatTab->chatLog("Invited user " + name, BY_SERVER); + localChatTab->chatLog(strprintf(_("Invited user %s."), name.c_str()), BY_SERVER); inviteDialog->scheduleDelete(); } else if (eventId == "yes") @@ -233,10 +240,11 @@ short GuildWindow::getSelectedGuild() void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName) { - std::string msg = inviterName + " has invited you to join the guild " + guildName; + std::string msg = strprintf(_("%s has invited you to join the guild %s."), + inviterName.c_str(), guildName.c_str()); localChatTab->chatLog(msg, BY_SERVER); - acceptDialog = new ConfirmDialog("Accept Guild Invite", msg, this); + acceptDialog = new ConfirmDialog(_("Accept Guild Invite"), msg, this); acceptDialog->addActionListener(this); invitedGuild = guildName; diff --git a/src/gui/help.cpp b/src/gui/help.cpp index ddcf7b49..e28f64e3 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -25,6 +25,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/layout.h" #include "gui/widgets/scrollarea.h" +#include "gui/setup.h" #include "resources/resourcemanager.h" @@ -38,6 +39,7 @@ HelpWindow::HelpWindow(): setContentSize(455, 350); setWindowName("Help"); setResizable(true); + setupWindow->registerWindowForReset(this); setDefaultSize(500, 400, ImageRect::CENTER); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 06e43eac..50465a50 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -23,6 +23,7 @@ #include "gui/itemamount.h" #include "gui/itemcontainer.h" +#include "gui/setup.h" #include "gui/sdlinput.h" #include "gui/viewport.h" @@ -57,6 +58,7 @@ InventoryWindow::InventoryWindow(int invSize): mItemDesc(false) { setWindowName("Inventory"); + setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setSaveVisible(true); diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index 87df46c1..20834c54 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -90,9 +90,9 @@ ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, mItemIcon = new Icon(image); // Buttons - Button *minusButton = new Button("-", "minus", this); - Button *plusButton = new Button("+", "plus", this); - Button *okButton = new Button(_("Ok"), "ok", this); + Button *minusButton = new Button(_("-"), "dec", this); + Button *plusButton = new Button(_("+"), "inc", this); + Button *okButton = new Button(_("OK"), "ok", this); Button *cancelButton = new Button(_("Cancel"), "cancel", this); Button *addAllButton = new Button(_("All"), "all", this); @@ -172,11 +172,11 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { close(); } - else if (event.getId() == "plus" && amount < mMax) + else if (event.getId() == "inc" && amount < mMax) { amount++; } - else if (event.getId() == "minus" && amount > 1) + else if (event.getId() == "dec" && amount > 1) { amount--; } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index e1822e03..39dc603a 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -88,8 +88,9 @@ void ItemPopup::setItem(const ItemInfo &item) mItemDesc->setTextWrapped(item.getDescription(), 196); mItemEffect->setTextWrapped(item.getEffect(), 196); - mItemWeight->setTextWrapped(_("Weight: ") + - Units::formatWeight(item.getWeight()), 196); + mItemWeight->setTextWrapped(strprintf(_("Weight: %s"), + Units::formatWeight(item.getWeight()).c_str()), + 196); int minWidth = mItemName->getWidth(); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 77f2e137..3b63eff1 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -70,7 +70,7 @@ LoginDialog::LoginDialog(LoginData *loginData): mServerDropDown = new DropDown(mServerList); #endif - mKeepCheck = new CheckBox(_("Remember Username"), mLoginData->remember); + mKeepCheck = new CheckBox(_("Remember username"), mLoginData->remember); mOkButton = new Button(_("OK"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); mRegisterButton = new Button(_("Register"), "register", this); diff --git a/src/gui/magic.cpp b/src/gui/magic.cpp index c47faa18..6e314656 100644 --- a/src/gui/magic.cpp +++ b/src/gui/magic.cpp @@ -22,6 +22,7 @@ #include "gui/magic.h" #include "gui/widgets/button.h" +#include "gui/setup.h" #include "localplayer.h" @@ -35,6 +36,7 @@ MagicDialog::MagicDialog(): setCloseButton(true); setSaveVisible(true); setDefaultSize(255, 30, 175, 225); + setupWindow->registerWindowForReset(this); mSpellButtons.resize(4); diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index d1c99b84..40526a22 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -31,6 +31,7 @@ #include "player.h" #include "gui/palette.h" +#include "gui/setup.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -47,12 +48,13 @@ Minimap::Minimap(): mWidthProportion(0.5), mHeightProportion(0.5) { - setWindowName("MiniMap"); + setWindowName("Minimap"); mShow = config.getValue(getWindowName() + "Show", true); setDefaultSize(5, 25, 100, 100); // set this to false as the minimap window size is changed //depending on the map size setResizable(false); + setupWindow->registerWindowForReset(this); setDefaultVisible(true); setSaveVisible(true); diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 65d2391d..4cb0e1ac 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -22,7 +22,7 @@ #include "gui/ministatus.h" #include "gui/gui.h" -#include "gui/status.h" +#include "gui/statuswindow.h" #include "gui/widgets/progressbar.h" @@ -33,34 +33,30 @@ #include "utils/stringutils.h" +extern volatile int tick_time; + MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus") { - mHpBar = new ProgressBar(0.0f, 100, 20, gcn::Color(0, 171, 34)); -#ifdef EATHENA_SUPPORT - mMpBar = new ProgressBar(0.0f, 100, 20, gcn::Color(26, 102, 230)); - mXpBar = new ProgressBar(0.0f, 100, 20, gcn::Color(143, 192, 211)); -#endif - + mHpBar = new ProgressBar((float) player_node->getHp() + / (float) player_node->getMaxHp(), + 100, 20, gcn::Color(0, 171, 34)); + mMpBar = new ProgressBar((float) player_node->getMaxMP() + / (float) player_node->getMaxMP(), + 100, 20, gcn::Color(26, 102, 230)); + mXpBar = new ProgressBar((float) player_node->getExp() + / player_node->getExpNeeded(), + 100, 20, gcn::Color(143, 192, 211)); mHpBar->setPosition(0, 3); -#ifdef EATHENA_SUPPORT mMpBar->setPosition(mHpBar->getWidth() + 3, 3); mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); -#endif add(mHpBar); -#ifdef EATHENA_SUPPORT add(mMpBar); add(mXpBar); -#endif -#ifdef EATHENA_SUPPORT setContentSize(mXpBar->getX() + mXpBar->getWidth(), mXpBar->getY() + mXpBar->getHeight()); -#else - setContentSize(mHpBar->getX() + mHpBar->getWidth(), - mHpBar->getY() + mHpBar->getHeight()); -#endif setVisible((bool) config.getValue(getPopupName() + "Visible", true)); } @@ -81,14 +77,37 @@ void MiniStatusWindow::eraseIcon(int index) mIcons.erase(mIcons.begin() + index); } -extern volatile int tick_time; +void MiniStatusWindow::drawIcons(Graphics *graphics) +{ + // Draw icons + int icon_x = mXpBar->getX() + mXpBar->getWidth() + 4; + for (unsigned int i = 0; i < mIcons.size(); i++) { + if (mIcons[i]) { + mIcons[i]->draw(graphics, icon_x, 3); + icon_x += 2 + mIcons[i]->getWidth(); + } + } +} -void MiniStatusWindow::update() +void MiniStatusWindow::update(int id) { - StatusWindow::updateHPBar(mHpBar); -#ifdef EATHENA_SUPPORT - StatusWindow::updateMPBar(mMpBar); - StatusWindow::updateXPBar(mXpBar); + if (id == StatusWindow::HP) + { + StatusWindow::updateHPBar(mHpBar); + } + else if (id == StatusWindow::MP) + { + StatusWindow::updateMPBar(mMpBar); + } + else if (id == StatusWindow::EXP) + { + StatusWindow::updateXPBar(mXpBar); + } +} + +void MiniStatusWindow::logic() +{ + Popup::logic(); // Displays the number of monsters to next lvl // (disabled for now but interesting idea) @@ -102,31 +121,8 @@ void MiniStatusWindow::update() << config.getValue("xpBarMonsterCounterName", "Monsters") <<" left..."; } */ -#endif for (unsigned int i = 0; i < mIcons.size(); i++) if (mIcons[i]) mIcons[i]->update(tick_time * 10); } - -void MiniStatusWindow::draw(gcn::Graphics *graphics) -{ - update(); - drawChildren(graphics); -} - -void MiniStatusWindow::drawIcons(Graphics *graphics) -{ - // Draw icons -#ifdef TMWSERV_SUPPORT - int icon_x = mHpBar->getX() + mHpBar->getWidth() + 4; -#else - int icon_x = mXpBar->getX() + mXpBar->getWidth() + 4; -#endif - for (unsigned int i = 0; i < mIcons.size(); i++) { - if (mIcons[i]) { - mIcons[i]->draw(graphics, icon_x, 3); - icon_x += 2 + mIcons[i]->getWidth(); - } - } -} diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 56f53908..82ab0adc 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -40,8 +40,6 @@ class MiniStatusWindow : public Popup public: MiniStatusWindow(); - void draw(gcn::Graphics *graphics); - /** * Sets one of the icons. */ @@ -51,22 +49,24 @@ class MiniStatusWindow : public Popup void drawIcons(Graphics *graphics); - private: - /** - * Updates this dialog with values from player_node. - */ - void update(); + void update(int id); // Same types as status window + + void logic(); // Updates icons + void draw(gcn::Graphics *graphics) + { drawChildren(graphics); } + + private: /* * Mini Status Bars */ ProgressBar *mHpBar; -#ifdef EATHENA_SUPPORT ProgressBar *mMpBar; ProgressBar *mXpBar; -#endif std::vector<AnimatedSprite *> mIcons; }; +extern MiniStatusWindow *miniStatusWindow; + #endif diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index afcc150d..1956ba85 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -28,6 +28,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/textbox.h" #include "gui/widgets/textfield.h" +#include "gui/setup.h" #include "npc.h" @@ -54,6 +55,7 @@ NpcDialog::NpcDialog() // Basic Window Setup setWindowName("NpcText"); setResizable(true); + setupWindow->registerWindowForReset(this); setMinWidth(200); setMinHeight(150); @@ -91,8 +93,8 @@ NpcDialog::NpcDialog() mButton = new Button("", "ok", this); //Setup more and less buttons (int input) - mPlusButton = new Button("+", "plus", this); - mMinusButton = new Button("-", "minus", this); + mPlusButton = new Button(_("+"), "inc", this); + mMinusButton = new Button(_("-"), "dec", this); int width = std::max(mButton->getFont()->getWidth(CAPTION_WAITING), mButton->getFont()->getWidth(CAPTION_NEXT)); @@ -154,7 +156,8 @@ void NpcDialog::action(const gcn::ActionEvent &event) if (mActionState == NPC_ACTION_NEXT) { nextDialog(); - addText("\n> Next\n"); + // TRANSLATORS: Please leave the \n sequences intact. + addText(_("\n> Next\n")); } else if (mActionState == NPC_ACTION_CLOSE) { @@ -209,11 +212,11 @@ void NpcDialog::action(const gcn::ActionEvent &event) mIntField->setValue(mDefaultInt); } } - else if (event.getId() == "plus") + else if (event.getId() == "inc") { mIntField->setValue(mIntField->getValue() + 1); } - else if (event.getId() == "minus") + else if (event.getId() == "dec") { mIntField->setValue(mIntField->getValue() - 1); } diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index f43e1440..d2e9468d 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -58,9 +58,9 @@ OutfitWindow::OutfitWindow(): setCloseButton(true); setDefaultSize(250, 250, 118, 180); //160 - mPreviousButton = new Button("<", "previous", this); - mNextButton = new Button(">", "next", this); - mCurrentLabel = new Label("Outfit: 1"); + mPreviousButton = new Button(_("<"), "previous", this); + mNextButton = new Button(_(">"), "next", this); + mCurrentLabel = new Label(strprintf(_("Outfit: %d"), 1)); mCurrentLabel->setAlignment(gcn::Graphics::CENTER); mUnequipCheck = new CheckBox(_("Unequip first"), config.getValue("OutfitUnequip", true)); @@ -140,7 +140,7 @@ void OutfitWindow::action(const gcn::ActionEvent &event) mCurrentOutfit = 9; } } - mCurrentLabel->setCaption("Outfit: " + toString(mCurrentOutfit + 1)); + mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); } void OutfitWindow::wearOutfit(int outfit) @@ -153,14 +153,8 @@ void OutfitWindow::wearOutfit(int outfit) //non vis is 3,4,7 if (i != 3 && i != 4 && i != 7) { -#ifdef TMWSERV_SUPPORT if (!(item = player_node->mEquipment.get()->getEquipment(i))) continue; -#else - if (!(item = player_node->getInventory()->getItem( - player_node->mEquipment.get()->getEquipment(i)))) - continue; -#endif Net::getInventoryHandler()->unequipItem(item); } } diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 4d1233e8..a807dcd6 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -82,18 +82,21 @@ Palette::Palette() : addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels")); + addColor(BUTTON, 0xc8ad00, STATIC, indent + _("Buttons")); + addColor(BUTTON_DISABLED, 0x828282, STATIC, indent + _("Disabled Buttons")); + addColor(TAB, 0xc8ad00, STATIC, indent + _("Tabs")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); addColor(TAB_HIGHLIGHT, 0xff0000, PULSE, indent + _("Tab Highlight")); - addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item too expensive")); - addColor(ITEM_EQUIPPED, 0x000091, STATIC, indent + _("Item is equipped")); + addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item Too Expensive")); + addColor(ITEM_EQUIPPED, 0x000091, STATIC, indent + _("Item Is Equipped")); addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C'); addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G'); addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y'); - addColor(WHISPER, 0x0000ff, STATIC, indent + _("Whisper"), 'W'); + addColor(WHISPER, 0x00feaf, STATIC, indent + _("Whisper"), 'W'); addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I'); addColor(PARTY, 0xf48055, STATIC, indent + _("Party"), 'P'); addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S'); @@ -112,10 +115,10 @@ Palette::Palette() : addColor(HEAD, 0x527fa4, STATIC, indent + _("Hats")); addColor(USABLE, 0x268d24, STATIC, indent + _("Usables")); addColor(TORSO, 0xd12aa4, STATIC, indent + _("Shirts")); - addColor(ONEHAND, 0xf42a2a, STATIC, indent + _("1 Handed Weapons")); + addColor(ONEHAND, 0xf42a2a, STATIC, indent + _("One Handed Weapons")); addColor(LEGS, 0x699900, STATIC, indent + _("Pants")); addColor(FEET, 0xaa1d48, STATIC, indent + _("Shoes")); - addColor(TWOHAND, 0xf46d0e, STATIC, indent + _("2 Handed Weapons")); + addColor(TWOHAND, 0xf46d0e, STATIC, indent + _("Two Handed Weapons")); addColor(SHIELD, 0x9c2424, STATIC, indent + _("Shields")); addColor(RING, 0x0000ff, STATIC, indent + _("Rings")); addColor(NECKLACE, 0xff00ff, STATIC, indent + _("Necklaces")); @@ -126,9 +129,9 @@ Palette::Palette() : addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification")); addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification")); addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, - indent + _("Player hits Monster")); + indent + _("Player Hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, - indent + _("Monster hits Player")); + indent + _("Monster Hits Player")); addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit")); addColor(MISS, 0xffff00, STATIC, indent + _("Misses")); diff --git a/src/gui/palette.h b/src/gui/palette.h index 1dec2a60..c68a4e1c 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -57,6 +57,9 @@ class Palette : public gcn::ListModel ENTRY(SHADOW)\ ENTRY(OUTLINE)\ ENTRY(PROGRESS_BAR)\ + ENTRY(BUTTON)\ + ENTRY(BUTTON_DISABLED)\ + ENTRY(TAB)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ ENTRY(TAB_HIGHLIGHT)\ diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp index f66ffaac..d4b084ce 100644 --- a/src/gui/partywindow.cpp +++ b/src/gui/partywindow.cpp @@ -22,6 +22,7 @@ #include "gui/partywindow.h" #include "gui/widgets/chattab.h" +#include "gui/setup.h" #include "beingmanager.h" #include "player.h" @@ -56,6 +57,7 @@ PartyWindow::PartyWindow() : setMinWidth(120); setMinHeight(55); setDefaultSize(590, 200, 150, 60); + setupWindow->registerWindowForReset(this); loadWindowState(); } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index e12ca822..0f0df756 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -34,6 +34,7 @@ #include "graphics.h" #include "item.h" #include "localplayer.h" +#include "log.h" #include "npc.h" #include "playerrelations.h" @@ -72,10 +73,6 @@ void PopupMenu::showPopup(int x, int y, Being *being) mBeingId = being->getId(); mBrowserBox->clearRows(); - // Any being's name can be added to chat - if (being->getType() != Being::UNKNOWN) - mBrowserBox->addRow(_("@@name|Add name to chat@@")); - const std::string &name = being->getType() == Being::NPC ? being->getName().substr(0, being->getName().size() - 6) : being->getName(); @@ -86,42 +83,68 @@ void PopupMenu::showPopup(int x, int y, Being *being) { // Players can be traded with. Later also follow and // add as buddy will be options in this menu. - mBrowserBox->addRow(strprintf(_("@@trade|Trade With %s@@"), name.c_str())); - mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@trade|%s@@", + strprintf(_("Trade with %s"), + name.c_str()).c_str())); + // TRANSLATORS: Attacking a player. + mBrowserBox->addRow(strprintf("@@attack|%s@@", + strprintf(_("Attack %s"), + name.c_str()).c_str())); mBrowserBox->addRow("##3---"); switch (player_relations.getRelation(name)) { case PlayerRelation::NEUTRAL: - mBrowserBox->addRow(strprintf(_("@@friend|Befriend %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@friend|%s@@", + strprintf(_("Befriend %s"), + name.c_str()).c_str())); case PlayerRelation::FRIEND: - mBrowserBox->addRow(strprintf(_("@@disregard|Disregard %s@@"), name.c_str())); - mBrowserBox->addRow(strprintf(_("@@ignore|Ignore %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@disregard|%s@@", + strprintf(_("Disregard %s"), + name.c_str()).c_str())); + mBrowserBox->addRow(strprintf("@@ignore|%s@@", + strprintf(_("Ignore %s"), + name.c_str()).c_str())); break; case PlayerRelation::DISREGARDED: - mBrowserBox->addRow(strprintf(_("@@unignore|Un-Ignore %s@@"), name.c_str())); - mBrowserBox->addRow(strprintf(_("@@ignore|Completely ignore %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@unignore|%s@@", + strprintf(_("Unignore %s"), + name.c_str()).c_str())); + mBrowserBox->addRow(strprintf("@@ignore|%s@@", + strprintf(_("Completely ignore %s"), + name.c_str()).c_str())); break; case PlayerRelation::IGNORED: - mBrowserBox->addRow(strprintf(_("@@unignore|Un-Ignore %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@unignore|%s@@", + strprintf(_("Unignore %s"), + name.c_str()).c_str())); break; } - //mBrowserBox->addRow(_(strprintf("@@follow|Follow %s@@"), name.c_str())); - //mBrowserBox->addRow(_("@@buddy|Add ") + name + " to Buddy List@@"); + /*mBrowserBox->addRow(strprintf("@@follow|%s@@", + strprintf(_("Follow %s"), + name.c_str()).c_str()));*/ + /*mBrowserBox->addRow(strprintf("@@buddy|%s@@", + strprintf(_("Add %s to Buddy List"), + name.c_str()).c_str()));*/ #ifdef TMWSERV_SUPPORT - mBrowserBox->addRow(strprintf(_("@@guild|Invite %s to join your guild@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@guild|%s@@", + strprintf(_("Invite %s to join your guild"), + name.c_str()).c_str())); #endif if (player_node->isInParty()) - mBrowserBox->addRow(strprintf(_("@@party|Invite %s to join your party@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@pickup|%s@@", + strprintf(_("Invite %s to join your party"), + name.c_str()).c_str())); if (player_node->isGM()) { mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(_("@@admin-kick|Kick player@@")); + mBrowserBox->addRow(strprintf("@@admin-kick|%s@@", + _("Kick player"))); } } break; @@ -129,16 +152,21 @@ void PopupMenu::showPopup(int x, int y, Being *being) case Being::NPC: // NPCs can be talked to (single option, candidate for removal // unless more options would be added) - mBrowserBox->addRow(strprintf(_("@@talk|Talk To %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@talk|%s@@", + strprintf(_("Talk to %s"), + name.c_str()).c_str())); break; case Being::MONSTER: { // Monsters can be attacked - mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str())); + mBrowserBox->addRow(strprintf("@@attack|%s@@", + strprintf(_("Attack %s"), + name.c_str()).c_str())); if (player_node->isGM()) - mBrowserBox->addRow(_("@@admin-kick|Kick monster@@")); + mBrowserBox->addRow(strprintf("@@admin-kick|%s@@", + _("Kick monster"))); } break; @@ -146,10 +174,11 @@ void PopupMenu::showPopup(int x, int y, Being *being) /* Other beings aren't interesting... */ return; } + mBrowserBox->addRow(strprintf("@@name|%s@@", _("Add name to chat"))); - //browserBox->addRow("@@look|Look To@@"); + //mBrowserBox->addRow(strprintf("@@look|%s@@", _("Look To"))); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(_("@@cancel|Cancel@@")); + mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); showPopup(x, y); } @@ -162,12 +191,13 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) // Floor item can be picked up (single option, candidate for removal) std::string name = ItemDB::get(mFloorItem->getItemId()).getName(); - mBrowserBox->addRow(strprintf(_("@@pickup|Pick up %s@@"), name.c_str())); - mBrowserBox->addRow(_("@@chat|Add to chat@@")); + mBrowserBox->addRow(strprintf("@@pickup|%s@@", strprintf(_("Pick up %s"), + name.c_str()).c_str())); + mBrowserBox->addRow(strprintf("@@chat|%s@@", _("Add to chat"))); - //browserBox->addRow("@@look|Look To@@"); + //mBrowserBox->addRow(strprintf("@@look|%s@@", _("Look To"))); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(_("@@cancel|Cancel@@")); + mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); showPopup(x, y); } @@ -193,13 +223,11 @@ void PopupMenu::handleLink(const std::string &link) Net::getTradeHandler()->request(being); tradePartnerName = being->getName(); } -#ifdef EATHENA_SUPPORT // Attack action else if (link == "attack" && being) { player_node->attack(being, true); } -#endif else if (link == "unignore" && being && being->getType() == Being::PLAYER) @@ -332,7 +360,7 @@ void PopupMenu::handleLink(const std::string &link) // Unknown actions else if (link != "cancel") { - std::cout << link << std::endl; + logger->log("PopupMenu: Warning, unknown action '%s'", link.c_str()); } setVisible(false); @@ -353,34 +381,34 @@ void PopupMenu::showPopup(int x, int y, Item *item, bool isInventory) if (item->isEquipment()) { if (item->isEquipped()) - mBrowserBox->addRow(_("@@use|Unequip@@")); + mBrowserBox->addRow(strprintf("@@use|%s@@", _("Unequip"))); else - mBrowserBox->addRow(_("@@use|Equip@@")); + mBrowserBox->addRow(strprintf("@@use|%s@@", _("Equip"))); } else - mBrowserBox->addRow(_("@@use|Use@@")); + mBrowserBox->addRow(strprintf("@@use|%s@@", _("Use"))); - mBrowserBox->addRow(_("@@drop|Drop@@")); + mBrowserBox->addRow(strprintf("@@drop|%s@@", _("Drop"))); if (Net::getInventoryHandler()->canSplit(item)) { - mBrowserBox->addRow(_("@@split|Split@@")); + mBrowserBox->addRow(strprintf("@@split|%s@@", _("Split"))); } if (player_node->getInStorage()) { - mBrowserBox->addRow(_("@@store|Store@@")); + mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store"))); } } // Assume in storage for now // TODO: make this whole system more flexible, if needed else { - mBrowserBox->addRow(_("@@retrieve|Retrieve@@")); + mBrowserBox->addRow(strprintf("@@retrieve|%s@@", _("Retrieve"))); } - mBrowserBox->addRow(_("@@chat|Add to chat@@")); + mBrowserBox->addRow(strprintf("@@chat|%s@@", _("Add to chat"))); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow(_("@@cancel|Cancel@@")); + mBrowserBox->addRow(strprintf("@@cancel|%s@@", _("Cancel"))); showPopup(x, y); } diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 3307d904..b2679553 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -28,6 +28,7 @@ #include "gui/widgets/layout.h" #include "gui/widgets/windowcontainer.h" +#include "utils/gettext.h" #include "utils/stringutils.h" #include <physfs.h> diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 2b897641..f1313a5e 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -160,13 +160,13 @@ void RegisterDialog::action(const gcn::ActionEvent &event) const std::string user = mUserField->getText(); logger->log("RegisterDialog::register Username is %s", user.c_str()); - std::string errorMsg; + std::string errorMessage; int error = 0; if (user.length() < LEN_MIN_USERNAME) { // Name too short - errorMsg = strprintf + errorMessage = strprintf (_("The username needs to be at least %d characters long."), LEN_MIN_USERNAME); error = 1; @@ -174,7 +174,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (user.length() > LEN_MAX_USERNAME - 1 ) { // Name too long - errorMsg = strprintf + errorMessage = strprintf (_("The username needs to be less than %d characters long."), LEN_MAX_USERNAME); error = 1; @@ -182,7 +182,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (mPasswordField->getText().length() < LEN_MIN_PASSWORD) { // Pass too short - errorMsg = strprintf + errorMessage = strprintf (_("The password needs to be at least %d characters long."), LEN_MIN_PASSWORD); error = 2; @@ -190,7 +190,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (mPasswordField->getText().length() > LEN_MAX_PASSWORD - 1 ) { // Pass too long - errorMsg = strprintf + errorMessage = strprintf (_("The password needs to be less than %d characters long."), LEN_MAX_PASSWORD); error = 2; @@ -198,7 +198,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (mPasswordField->getText() != mConfirmField->getText()) { // Password does not match with the confirmation one - errorMsg = _("Passwords do not match."); + errorMessage = _("Passwords do not match."); error = 2; } @@ -219,7 +219,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mPasswordField); } - OkDialog *dlg = new OkDialog(_("Error"), errorMsg); + OkDialog *dlg = new OkDialog(_("Error"), errorMessage); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 28288ef4..4082b881 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,6 +21,7 @@ #include "gui/sell.h" +#include "gui/setup.h" #include "gui/shop.h" #include "gui/shoplistbox.h" @@ -47,6 +48,7 @@ SellDialog::SellDialog(): mMaxItems(0), mAmountItems(0) { setWindowName("Sell"); + setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setMinWidth(260); @@ -67,8 +69,8 @@ SellDialog::SellDialog(): mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"), "", "")); - mIncreaseButton = new Button("+", "+", this); - mDecreaseButton = new Button("-", "-", this); + mIncreaseButton = new Button(_("+"), "inc", this); + mDecreaseButton = new Button(_("-"), "dec", this); mSellButton = new Button(_("Sell"), "sell", this); mQuitButton = new Button(_("Quit"), "quit", this); mAddMaxButton = new Button(_("Max"), "max", this); @@ -159,13 +161,13 @@ void SellDialog::action(const gcn::ActionEvent &event) mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } - else if (event.getId() == "+" && mAmountItems < mMaxItems) + else if (event.getId() == "inc" && mAmountItems < mMaxItems) { mAmountItems++; mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 1) + else if (event.getId() == "dec" && mAmountItems > 1) { mAmountItems--; mSlider->setValue(mAmountItems); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 5d08a2ec..bd6b7d4b 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -71,7 +71,7 @@ void ServersListModel::addElement(Server server) } ServerDialog::ServerDialog(LoginData *loginData): - Window(_("Choose your server")), mLoginData(loginData) + Window(_("Choose Your Server")), mLoginData(loginData) { gcn::Label *serverLabel = new Label(_("Server:")); gcn::Label *portLabel = new Label(_("Port:")); diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index aebcf61b..2f0d78ca 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -37,29 +37,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" -extern Window *chatWindow; extern Window *statusWindow; -extern Window *buyDialog; -extern Window *sellDialog; -extern Window *buySellDialog; -extern Window *inventoryWindow; -extern Window *npcTextDialog; -extern Window *npcStringDialog; -extern Window *skillDialog; -extern Window *partyWindow; -extern Window *minimap; -extern Window *equipmentWindow; -extern Window *tradeWindow; -extern Window *helpWindow; -extern Window *debugWindow; -extern Window *itemShortcutWindow; -extern Window *emoteShortcutWindow; -#ifdef TMWSERV_SUPPORT -extern Window *magicDialog; -extern Window *guildWindow; -#else -extern Window *storageWindow; -#endif Setup::Setup(): Window(_("Setup")) @@ -137,29 +115,11 @@ void Setup::action(const gcn::ActionEvent &event) if (!statusWindow) return; - chatWindow->resetToDefaultSize(); - statusWindow->resetToDefaultSize(); - buyDialog->resetToDefaultSize(); - sellDialog->resetToDefaultSize(); -#ifdef EATHENA_SUPPORT - buySellDialog->resetToDefaultSize(); -#endif - inventoryWindow->resetToDefaultSize(); - skillDialog->resetToDefaultSize(); - partyWindow->resetToDefaultSize(); - minimap->resetToDefaultSize(); - equipmentWindow->resetToDefaultSize(); - tradeWindow->resetToDefaultSize(); - helpWindow->resetToDefaultSize(); - debugWindow->resetToDefaultSize(); - itemShortcutWindow->resetToDefaultSize(); - emoteShortcutWindow->resetToDefaultSize(); -#ifdef TMWSERV_SUPPORT - magicDialog->resetToDefaultSize(); - guildWindow->resetToDefaultSize(); -#else - storageWindow->resetToDefaultSize(); -#endif + for (std::list<Window*>::iterator it = mWindowsToReset.begin(); + it != mWindowsToReset.end(); it++) + { + (*it)->resetToDefaultSize(); + } } } @@ -168,4 +128,9 @@ void Setup::setInGame(bool inGame) mResetWindows->setEnabled(inGame); } +void Setup::registerWindowForReset(Window *window) +{ + mWindowsToReset.push_back(window); +} + Setup *setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 630d5eaa..6000adfa 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -61,8 +61,14 @@ class Setup : public Window, public gcn::ActionListener */ void setInGame(bool inGame); + void registerWindowForReset(Window *window); + + void clearWindowsForReset() + { mWindowsToReset.clear(); } + private: std::list<SetupTab*> mTabs; + std::list<Window*> mWindowsToReset; gcn::Button *mResetWindows; }; diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 9da74c2e..990a3ce8 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -91,7 +91,7 @@ void Setup_Audio::apply() } catch (const char *err) { - new OkDialog("Sound Engine", err); + new OkDialog(_("Sound Engine"), err); logger->log("Warning: %s", err); } } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index efa03ba4..7e8b8946 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -68,7 +68,7 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); - mGradTypeLabel = new Label(_("Type: ")); + mGradTypeLabel = new Label(_("Type:")); mGradTypeSlider = new Slider(0, 3); mGradTypeSlider->setWidth(200); @@ -90,7 +90,7 @@ Setup_Colors::Setup_Colors() : mGradTypeText->setCaption(longText); - mGradDelayLabel = new Label(_("Delay: ")); + mGradDelayLabel = new Label(_("Delay:")); mGradDelayText = new TextField(); mGradDelayText->setWidth(40); @@ -105,7 +105,7 @@ Setup_Colors::Setup_Colors() : mGradDelaySlider->addActionListener(this); mGradDelaySlider->setEnabled(false); - mRedLabel = new Label(_("Red: ")); + mRedLabel = new Label(_("Red:")); mRedText = new TextField; mRedText->setWidth(40); @@ -120,7 +120,7 @@ Setup_Colors::Setup_Colors() : mRedSlider->addActionListener(this); mRedSlider->setEnabled(false); - mGreenLabel = new Label(_("Green: ")); + mGreenLabel = new Label(_("Green:")); mGreenText = new TextField; mGreenText->setWidth(40); @@ -135,7 +135,7 @@ Setup_Colors::Setup_Colors() : mGreenSlider->addActionListener(this); mGreenSlider->setEnabled(false); - mBlueLabel = new Label(_("Blue: ")); + mBlueLabel = new Label(_("Blue:")); mBlueText = new TextField; mBlueText->setWidth(40); @@ -262,6 +262,9 @@ void Setup_Colors::valueChanged(const gcn::SelectionEvent &event) mTextPreview->setOutline(true); mTextPreview->setShadow(false); break; + case Palette::BUTTON: + case Palette::BUTTON_DISABLED: + case Palette::TAB: case Palette::TAB_HIGHLIGHT: mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 938c1c4e..d9117b8a 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -116,7 +116,7 @@ void Setup_Keyboard::apply() if (keyboard.hasConflicts()) { - new OkDialog(_("Key Conflict(s) Detected."), + new OkDialog(_("Key Conflict(s) Detected"), _("Resolve them, or gameplay may result in strange " "behaviour.")); } diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index a9c892b2..f21f20e0 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -192,15 +192,17 @@ Setup_Video::Setup_Video(): mVisibleNamesEnabled)), mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), - mNameCheckBox(new CheckBox(_("Show name"), mNameEnabled)), + mNameCheckBox(new CheckBox(_("Show own name"), mNameEnabled)), mPickupNotifyLabel(new Label(_("Show pickup notification"))), + // TRANSLATORS: Refers to "Show own name" mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + // TRANSLATORS: Refers to "Show own name" mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)), mSpeechSlider(new Slider(0, 3)), mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.2, 1.0)), - mFpsCheckBox(new CheckBox(_("FPS Limit:"))), + mFpsCheckBox(new CheckBox(_("FPS limit:"))), mFpsSlider(new Slider(10, 120)), mFpsField(new TextField), mOverlayDetail((int) config.getValue("OverlayDetail", 2)), @@ -219,7 +221,7 @@ Setup_Video::Setup_Video(): speechLabel = new Label(_("Overhead text")); alphaLabel = new Label(_("Gui opacity")); overlayDetailLabel = new Label(_("Ambient FX")); - particleDetailLabel = new Label(_("Particle Detail")); + particleDetailLabel = new Label(_("Particle detail")); fontSizeLabel = new Label(_("Font size")); mFontSizeDropDown = new DropDown(new FontSizeChoiceListModel); @@ -352,19 +354,27 @@ void Setup_Video::apply() fullscreen = !fullscreen; if (!graphics->setFullscreen(fullscreen)) { - std::stringstream error; - error << _("Failed to switch to ") << - (fullscreen ? _("windowed") : _("fullscreen")) << - _("mode and restoration of old mode also failed!") << - std::endl; - logger->error(error.str()); + std::stringstream errorMessage; + if (fullscreen) + { + errorMessage << _("Failed to switch to windowed mode " + "and restoration of old mode also " + "failed!") << std::endl; + } + else + { + errorMessage << _("Failed to switch to fullscreen mode " + "and restoration of old mode also " + "failed!") << std::endl; + } + logger->error(errorMessage.str()); } } #if defined(WIN32) || defined(__APPLE__) } else { - new OkDialog(_("Switching to full screen"), + new OkDialog(_("Switching to Full Screen"), _("Restart needed for changes to take effect.")); } #endif @@ -377,7 +387,7 @@ void Setup_Video::apply() config.setValue("opengl", mOpenGLCheckBox->isSelected()); // OpenGL can currently only be changed by restarting, notify user. - new OkDialog(_("Changing OpenGL"), + new OkDialog(_("Changing to OpenGL"), _("Applying change to OpenGL requires restart.")); } @@ -436,11 +446,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) const int width = atoi(mode.substr(0, mode.find("x")).c_str()); const int height = atoi(mode.substr(mode.find("x") + 1).c_str()); + // TODO: Find out why the drawing area doesn't resize without a restart. if (width != graphics->getWidth() || height != graphics->getHeight()) { - // TODO: Find out why the drawing area doesn't resize without a restart. - new OkDialog(_("Screen resolution changed"), - _("Restart your client for the change to take effect.")); + if (width < graphics->getWidth() || height < graphics->getHeight()) + new OkDialog(_("Screen Resolution Changed"), + _("Restart your client for the change to take effect.") + + std::string("\n") + + _("Some windows may be moved to fit the lowered resolution.")); + else + new OkDialog(_("Screen Resolution Changed"), + _("Restart your client for the change to take effect.")); } config.setValue("screenwidth", width); @@ -464,7 +480,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) mParticleEffectsCheckBox->isSelected()); if (engine) { - new OkDialog(_("Particle effect settings changed."), + new OkDialog(_("Particle Effect Settings Changed."), _("Changes will take effect on map change.")); } } diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index b9eda02c..8e7e0bee 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -25,6 +25,7 @@ #include "gui/widgets/layout.h" #include "gui/widgets/scrollarea.h" +#include "gui/setup.h" #include "configuration.h" @@ -42,6 +43,7 @@ ShortcutWindow::ShortcutWindow(const std::string &title, setResizable(true); setDefaultVisible(false); setSaveVisible(true); + setupWindow->registerWindowForReset(this); mItems = content; diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp deleted file mode 100644 index 7698098c..00000000 --- a/src/gui/skill.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/skill.h" - -#include "gui/table.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/listbox.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/windowcontainer.h" - -#include "localplayer.h" -#include "log.h" - -#include "net/net.h" -#include "net/skillhandler.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" -#include "utils/xml.h" - -static const char *SKILLS_FILE = "skills.xml"; - -struct SkillInfo -{ - std::string name; - bool modifiable; -}; - -static const SkillInfo fakeSkillInfo = { - _("Mystery Skill"), - false -}; - -std::vector<SkillInfo> skill_db; - -static void initSkillinfo(); - -class SkillGuiTableModel : public StaticTableModel -{ -public: - SkillGuiTableModel(SkillDialog *dialog) : - StaticTableModel(0, 3) - { - mEntriesNr = 0; - mDialog = dialog; - update(); - } - - virtual int getRows() const - { - return mEntriesNr; - } - - virtual int getColumnWidth(int index) const - { - if (index == 0) - return 160; - - return 35; - } - - virtual int getRowHeight() const - { - return 12; - } - - virtual void update() - { - mEntriesNr = mDialog->getSkills().size(); - resize(); - - for (int i = 0; i < mEntriesNr; i++) - { - SKILL *skill = mDialog->getSkills()[i]; - SkillInfo const *info; - char tmp[128]; - - if (skill->id >= 0 - && (unsigned int) skill->id < skill_db.size()) - info = &skill_db[skill->id]; - else - info = &fakeSkillInfo; - - sprintf(tmp, "%c%s", info->modifiable? ' ' : '*', info->name.c_str()); - gcn::Label *name_label = new Label(tmp); - - sprintf(tmp, "Lv:%i", skill->lv); - gcn::Label *lv_label = new Label(tmp); - - sprintf(tmp, "Sp:%i", skill->sp); - gcn::Label *sp_label = new Label(tmp); - - set(i, 0, name_label); - set(i, 1, lv_label); - set(i, 2, sp_label); - } - } - -private: - SkillDialog *mDialog; - int mEntriesNr; -}; - - -SkillDialog::SkillDialog(): - Window(_("Skills")) -{ - initSkillinfo(); - mTableModel = new SkillGuiTableModel(this); - mTable = new GuiTable(mTableModel); - mTable->setOpaque(false); - mTable->setLinewiseSelection(true); - mTable->setWrappingEnabled(true); - mTable->setActionEventId("skill"); - mTable->addActionListener(this); - - setWindowName("Skills"); - setCloseButton(true); - setDefaultSize(255, 260, ImageRect::CENTER); - - setMinHeight(50 + mTableModel->getHeight()); - setMinWidth(200); - - ScrollArea *skillScrollArea = new ScrollArea(mTable); - mPointsLabel = new Label(strprintf(_("Skill points: %d"), 0)); - mIncButton = new Button(_("Up"), "inc", this); - mUseButton = new Button(_("Use"), "use", this); - mUseButton->setEnabled(false); - - skillScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - - place(0, 0, skillScrollArea, 5).setPadding(3); - place(0, 1, mPointsLabel, 4); - place(3, 2, mIncButton); - place(4, 2, mUseButton); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - center(); - loadWindowState(); -} - -SkillDialog::~SkillDialog() -{ - delete_all(mSkillList); -} - -void SkillDialog::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "inc") - { - // Increment skill - int selectedSkill = mTable->getSelectedRow(); - if (selectedSkill >= 0) - Net::getSkillHandler()->up(mSkillList[selectedSkill]->id); - } - else if (event.getId() == "skill" && mTable->getSelectedRow() > -1) - { - SKILL *skill = mSkillList[mTable->getSelectedRow()]; - SkillInfo const *info; - - if (skill->id >= 0 && (unsigned int) skill->id < skill_db.size()) - info = &skill_db[skill->id]; - else - info = &fakeSkillInfo; - - mIncButton->setEnabled(player_node->mSkillPoint > 0 && - info->modifiable); - } - else if (event.getId() == "close") - setVisible(false); -} - -void SkillDialog::update() -{ - mPointsLabel->setCaption(strprintf(_("Skill points: %d"), - player_node->mSkillPoint)); - - int selectedSkill = mTable->getSelectedRow(); - - if (selectedSkill >= 0) - { - int skillId = mSkillList[selectedSkill]->id; - bool modifiable; - - if (skillId >= 0 && (unsigned int) skillId < skill_db.size()) - modifiable = skill_db[skillId].modifiable; - else - modifiable = false; - - mIncButton->setEnabled(modifiable - && player_node->mSkillPoint > 0); - } - else - mIncButton->setEnabled(false); - - mTableModel->update(); - setMinHeight(50 + mTableModel->getHeight()); -} - -int SkillDialog::getNumberOfElements() -{ - return mSkillList.size(); -} - -bool SkillDialog::hasSkill(int id) -{ - for (unsigned int i = 0; i < mSkillList.size(); i++) - { - if (mSkillList[i]->id == id) - return true; - } - return false; -} - -void SkillDialog::addSkill(int id, int lvl, int mp) -{ - SKILL *tmp = new SKILL; - tmp->id = id; - tmp->lv = lvl; - tmp->sp = mp; - mSkillList.push_back(tmp); -} - -void SkillDialog::setSkill(int id, int lvl, int mp) -{ - for (unsigned int i = 0; i < mSkillList.size(); i++) - { - if (mSkillList[i]->id == id) - { - mSkillList[i]->lv = lvl; - mSkillList[i]->sp = mp; - } - } -} - -void SkillDialog::cleanList() -{ - delete_all(mSkillList); - mSkillList.clear(); -} - -static void initSkillinfo() -{ - SkillInfo emptySkillInfo = { "", false }; - - XML::Document doc(SKILLS_FILE); - xmlNodePtr root = doc.rootNode(); - - if (!root || !xmlStrEqual(root->name, BAD_CAST "skills")) - { - logger->log("Error loading skills file: %s", SKILLS_FILE); - skill_db.resize(2, emptySkillInfo); - skill_db[1].name = "Basic"; - skill_db[1].modifiable = true; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlStrEqual(node->name, BAD_CAST "skill")) - { - int index = atoi(XML::getProperty(node, "id", "-1").c_str()); - std::string name = XML::getProperty(node, "name", ""); - bool modifiable = !atoi(XML::getProperty(node, "fixed", "0").c_str()); - - if (index >= 0) - { - skill_db.resize(index + 1, emptySkillInfo); - skill_db[index].name = name; - skill_db[index].modifiable = modifiable; - } - } - } -} - diff --git a/src/gui/skill.h b/src/gui/skill.h deleted file mode 100644 index 0879f7e1..00000000 --- a/src/gui/skill.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef SKILL_H -#define SKILL_H - -#include "gui/widgets/window.h" - -#include <guichan/actionlistener.hpp> - -#include <vector> - -struct SKILL -{ - short id; /**< Index into "skill_db" array */ - short lv, sp; -}; - -class GuiTable; -class ScrollArea; -class SkillGuiTableModel; - -/** - * The skill dialog. - * - * \ingroup Interface - */ -class SkillDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - */ - SkillDialog(); - - /** - * Destructor. - */ - ~SkillDialog(); - - void action(const gcn::ActionEvent &event); - - void update(); - - int getNumberOfElements(); - - bool hasSkill(int id); - void addSkill(int id, int lv, int sp); - void setSkill(int id, int lv, int sp); - void cleanList(); - - const std::vector<SKILL*>& getSkills() const { return mSkillList; } - - private: - GuiTable *mTable; - ScrollArea *skillScrollArea; - SkillGuiTableModel *mTableModel; - gcn::Label *mPointsLabel; - gcn::Button *mIncButton; - gcn::Button *mUseButton; - - std::vector<SKILL*> mSkillList; -}; - -extern SkillDialog *skillDialog; - -#endif diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index f0cd01ce..14e0e5a4 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -25,105 +25,78 @@ #include "gui/widgets/container.h" #include "gui/widgets/icon.h" #include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" #include "gui/widgets/listbox.h" #include "gui/widgets/progressbar.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" +#include "gui/widgets/vertcontainer.h" #include "gui/widgets/windowcontainer.h" +#include "gui/setup.h" #include "localplayer.h" +#include "log.h" + +#include "net/net.h" +#include "net/playerhandler.h" #include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" +#include "utils/xml.h" #include <string> #include <vector> -class SkillTab : public Container, public gcn::ActionListener +class SkillEntry; + +struct SkillInfo +{ + unsigned short id; + std::string name; + std::string icon; + bool modifiable; + SkillEntry *display; +}; + +class SkillEntry : public Container, gcn::WidgetListener { public: - /** - * The type of this skill tab - */ - const std::string type; - - /** - * Constructor - */ - SkillTab(const std::string &type); - - /** - * Update this tab - */ + SkillEntry(SkillInfo *info); + + void widgetResized(const gcn::Event &event); + void update(); - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &event) {} + protected: + friend class SkillDialog; + SkillInfo *mInfo; private: - /** - * Update the information of a skill at - * the given index - */ - void updateSkill(int index); - - /** - * Gets the number of skills in this particular - * type of tab. - */ - int getSkillNum(); - - /** - * Get the first enumeration of this skill tab's - * skill type. - */ - int getSkillBegin(); - - /** - * Get the icon associated with the given index - */ - Icon *getIcon(int index); - - std::vector<Icon *> mSkillIcons; - std::vector<gcn::Label *> mSkillNameLabels; - std::vector<gcn::Label *> mSkillLevelLabels; - std::vector<gcn::Label *> mSkillExpLabels; - std::vector<ProgressBar *> mSkillProgress; + Icon *mIcon; + Label *mNameLabel; + Label *mLevelLabel; + Label *mExpLabel; + Button *mIncrease; + ProgressBar *mProgress; }; - SkillDialog::SkillDialog(): Window(_("Skills")) { setWindowName("Skills"); setCloseButton(true); + setResizable(true); setSaveVisible(true); setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); + setupWindow->registerWindowForReset(this); - TabbedArea *panel = new TabbedArea; - panel->setDimension(gcn::Rectangle(5, 5, 270, 420)); - - SkillTab *tab; - - // Add each type of skill tab to the panel - tab = new SkillTab("Weapon"); - panel->addTab(_("Weapons"), tab); - mTabs.push_back(tab); + mTabs = new TabbedArea(); + mPointsLabel = new Label("0"); - tab = new SkillTab("Magic"); - panel->addTab(_("Magic"), tab); - mTabs.push_back(tab); - - tab = new SkillTab("Craft"); - panel->addTab(_("Crafts"), tab); - mTabs.push_back(tab); - - add(panel); - - update(); + place(0, 0, mTabs, 5, 5); + place(0, 5, mPointsLabel); setLocationRelativeTo(getParent()); loadWindowState(); @@ -131,13 +104,17 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete_all(mTabs); + //delete_all(mTabs); } void SkillDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "skill") + if (event.getId() == "inc") { + SkillEntry *disp = dynamic_cast<SkillEntry*>(event.getSource()->getParent()); + + if (disp) + Net::getPlayerHandler()->increaseSkill(disp->mInfo->id); } else if (event.getId() == "close") { @@ -145,174 +122,254 @@ void SkillDialog::action(const gcn::ActionEvent &event) } } -void SkillDialog::draw(gcn::Graphics *g) +void SkillDialog::adjustTabSize() { - update(); + gcn::Widget *content = mTabs->getCurrentWidget(); + if (content) { + int width = mTabs->getWidth() - 2 * content->getFrameSize() - 2 * mTabs->getFrameSize(); + int height = mTabs->getContainerHeight() - 2 * content->getFrameSize(); + content->setSize(width, height); + content->setVisible(true); + content->logic(); + } +} + +void SkillDialog::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); - Window::draw(g); + adjustTabSize(); } -void SkillDialog::update() +void SkillDialog::logic() { - for(std::list<SkillTab*>::const_iterator i = mTabs.begin(); - i != mTabs.end(); ++i) - { - (*i)->update(); + Window::logic(); + + Tab *tab = dynamic_cast<Tab*>(mTabs->getSelectedTab()); + if (tab != mCurrentTab) { + mCurrentTab = tab; + adjustTabSize(); } } -SkillTab::SkillTab(const std::string &type): type(type) +std::string SkillDialog::update(int id) { - setOpaque(false); - setDimension(gcn::Rectangle(0, 0, 270, 420)); - int skillNum = getSkillNum(); - - mSkillIcons.resize(skillNum); - mSkillNameLabels.resize(skillNum); - mSkillLevelLabels.resize(skillNum); - mSkillExpLabels.resize(skillNum); - mSkillProgress.resize(skillNum); + SkillMap::iterator i = mSkills.find(id); - // Set the initial positions of the skill information - for (int a = 0; a < skillNum; a++) + if (i != mSkills.end()) { - mSkillIcons.at(a) = getIcon(a); - mSkillIcons.at(a)->setPosition(1, a*32); - add(mSkillIcons.at(a)); - - mSkillNameLabels.at(a) = new Label(""); - mSkillNameLabels.at(a)->setPosition(35, a*32 ); - add(mSkillNameLabels.at(a)); + SkillInfo *info = i->second; + info->display->update(); + return info->name; + } - mSkillProgress.at(a) = new ProgressBar(0.0f, 200, 20, gcn::Color(150, 150, 150)); - mSkillProgress.at(a)->setPosition(35, a*32 + 13); - add(mSkillProgress.at(a)); + return std::string(); +} - mSkillExpLabels.at(a) = new Label(""); - mSkillExpLabels.at(a)->setPosition(45, a*32 + 16); - add(mSkillExpLabels.at(a)); +void SkillDialog::update() +{ + mPointsLabel->setCaption(strprintf(_("Skill points available: %d"), + player_node->getSkillPoints())); + mPointsLabel->adjustSize(); - mSkillLevelLabels.at(a) = new Label(""); - mSkillLevelLabels.at(a)->setPosition(165, a*32); - add(mSkillLevelLabels.at(a)); + for (SkillMap::iterator it = mSkills.begin(); it != mSkills.end(); it++) + { + if ((*it).second->modifiable) + (*it).second->display->update(); } - - update(); } -int SkillTab::getSkillNum() +void SkillDialog::loadSkills(const std::string &file) { - int skillNum = 0; + // TODO: mTabs->clear(); + delete_all(mSkills); + mSkills.clear(); - if (type == "Weapon") + XML::Document doc(file); + xmlNodePtr root = doc.rootNode(); + + if (!root || !xmlStrEqual(root->name, BAD_CAST "skills")) { - skillNum = CHAR_SKILL_WEAPON_NB; - return skillNum; + logger->log("Error loading skills file: %s", file.c_str()); + return; } - else if (type == "Magic") + + int setCount = 0; + std::string setName; + ScrollArea *scroll; + VertContainer *container; + + for_each_xml_child_node(set, root) { - skillNum = CHAR_SKILL_MAGIC_NB; - return skillNum; + if (xmlStrEqual(set->name, BAD_CAST "set")) + { + setCount++; + setName = XML::getProperty(set, "name", strprintf(_("Skill Set %d"), setCount)); + + container = new VertContainer(32); + container->setOpaque(false); + scroll = new ScrollArea(container); + scroll->setOpaque(false); + scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); + + mTabs->addTab(setName, scroll); + for_each_xml_child_node(node, set) + { + if (xmlStrEqual(node->name, BAD_CAST "skill")) + { + int id = atoi(XML::getProperty(node, "id", "-1").c_str()); + std::string name = XML::getProperty(node, "name", strprintf(_("Skill %d"), id)); + std::string icon = XML::getProperty(node, "icon", ""); + + SkillInfo *skill = new SkillInfo; + skill->id = id; + skill->name = name; + skill->icon = icon; + skill->modifiable = 0; + skill->display = new SkillEntry(skill); + + container->add(skill->display); + + mSkills[id] = skill; + } + } + } } - else if (type == "Craft") + + adjustTabSize(); + update(); +} + +void SkillDialog::setModifiable(int id, bool modifiable) +{ + SkillMap::iterator i = mSkills.find(id); + + if (i != mSkills.end()) { - skillNum = CHAR_SKILL_CRAFT_NB; - return skillNum; + SkillInfo *info = i->second; + info->modifiable = modifiable; + info->display->update(); } - else return skillNum; } -int SkillTab::getSkillBegin() +SkillEntry::SkillEntry(SkillInfo *info) : + mInfo(info), + mIcon(NULL), + mNameLabel(new Label(info->name)), + mLevelLabel(new Label("999")), + mIncrease(new Button(_("+"), "inc", skillDialog)), + mProgress(new ProgressBar(0.0f, 200, 20, gcn::Color(150, 150, 150))) +{ + setFrameSize(1); + setOpaque(false); + + addWidgetListener(this); + + if (!info->icon.empty()) + mIcon = new Icon(info->icon); + else + mIcon = new Icon("graphics/gui/unknown-item.png"); + + mIcon->setPosition(1, 0); + add(mIcon); + + mNameLabel->setPosition(35, 0); + add(mNameLabel); + + mLevelLabel->setPosition(165, 0); + add(mLevelLabel); + + mProgress->setPosition(35, 13); + add(mProgress); + + mIncrease->setPosition(getWidth() - mIncrease->getWidth(), 13); + add(mIncrease); + + update(); +} + +void SkillEntry::widgetResized(const gcn::Event &event) { - int skillBegin = 0; + gcn::Rectangle size = getChildrenArea(); - if (type == "Weapon") + if (mProgress->isVisible() && mIncrease->isVisible()) { - skillBegin = CHAR_SKILL_WEAPON_BEGIN - CHAR_SKILL_BEGIN; - return skillBegin; + mLevelLabel->setPosition(size.width - mLevelLabel->getWidth() + - mIncrease->getWidth() - 4, 0); + mProgress->setWidth(size.width - mIncrease->getWidth() - 39); + mIncrease->setPosition(getWidth() - mIncrease->getWidth() - 2, 6); } - else if (type == "Magic") + else if (mProgress->isVisible()) { - skillBegin = CHAR_SKILL_MAGIC_BEGIN - CHAR_SKILL_BEGIN; - return skillBegin; + mLevelLabel->setPosition(size.width - mLevelLabel->getWidth(), 0); + mProgress->setWidth(size.width - 39); } - else if (type == "Craft") + else if (mIncrease->isVisible()) { - skillBegin = CHAR_SKILL_CRAFT_BEGIN - CHAR_SKILL_BEGIN; - return skillBegin; + mLevelLabel->setPosition(size.width - mLevelLabel->getWidth() + - mIncrease->getWidth() - 4, 0); + mIncrease->setPosition(getWidth() - mIncrease->getWidth() - 2, 6); } - else return skillBegin; + else + mLevelLabel->setPosition(size.width - mLevelLabel->getWidth(), 0); } -Icon* SkillTab::getIcon(int index) +void SkillEntry::update() { - int skillBegin = getSkillBegin(); - std::string icon = LocalPlayer::getSkillInfo(index + skillBegin).icon; - return new Icon(icon); -} + int baseLevel = player_node->getAttributeBase(mInfo->id); + int effLevel = player_node->getAttributeEffective(mInfo->id); -void SkillTab::updateSkill(int index) -{ - int skillBegin = getSkillBegin(); + if (baseLevel <= 0 && !mInfo->modifiable) + { + setVisible(false); + return; + } + + setVisible(true); - int baseLevel = player_node->getAttributeBase(index + - skillBegin + - CHAR_SKILL_BEGIN); + std::string skillLevel; - int effLevel = player_node->getAttributeEffective(index + - skillBegin + - CHAR_SKILL_BEGIN); - if(baseLevel <= 0) + if (effLevel != baseLevel) { - mSkillProgress.at(index)->setVisible(false); - mSkillExpLabels.at(index)->setVisible(false); - mSkillLevelLabels.at(index)->setVisible(false); - mSkillNameLabels.at(index)->setVisible(false); - mSkillIcons.at(index)->setVisible(false); + skillLevel = strprintf(_("Lvl: %d (%+d)"), + baseLevel, baseLevel - effLevel); } else { - mSkillProgress.at(index)->setVisible(true); - mSkillExpLabels.at(index)->setVisible(true); - mSkillLevelLabels.at(index)->setVisible(true); - mSkillNameLabels.at(index)->setVisible(true); - mSkillIcons.at(index)->setVisible(true); - std::string skillLevel("Lvl: " + toString(baseLevel)); - if (effLevel < baseLevel) - { - skillLevel.append(" - " + toString(baseLevel - effLevel)); - } - else if (effLevel > baseLevel) - { - skillLevel.append(" + " + toString(effLevel - baseLevel)); - } - mSkillLevelLabels.at(index)->setCaption(skillLevel); + skillLevel = strprintf(_("Lvl: %d"), baseLevel); + } - std::pair<int, int> exp = player_node->getExperience(index + skillBegin); - std::string sExp (toString(exp.first) + " / " + toString(exp.second)); + mLevelLabel->setCaption(skillLevel); + std::pair<int, int> exp = player_node->getExperience(mInfo->id); + std::string sExp (toString(exp.first) + " / " + toString(exp.second)); - mSkillNameLabels.at(index)->setCaption(LocalPlayer::getSkillInfo(index + skillBegin).name); - mSkillNameLabels.at(index)->adjustSize(); - mSkillLevelLabels.at(index)->adjustSize(); - mSkillExpLabels.at(index)->setCaption(sExp); - mSkillExpLabels.at(index)->adjustSize(); - mSkillExpLabels.at(index)->setAlignment(gcn::Graphics::RIGHT); + mLevelLabel->adjustSize(); + + if (exp.second) + { + mProgress->setVisible(true); + mProgress->setText(sExp); // More intense red as exp grows int color = 150 - (int)(150 * ((float) exp.first / exp.second)); - mSkillProgress.at(index)->setColor(244, color, color); - mSkillProgress.at(index)->setProgress((float) exp.first / exp.second); + mProgress->setColor(244, color, color); + mProgress->setProgress((float) exp.first / exp.second); } -} - -void SkillTab::update() -{ - int skillNum = getSkillNum(); + else + mProgress->setVisible(false); - // Update the skill information for reach skill - for (int a = 0; a < skillNum; a++) + if (mInfo->modifiable) { - updateSkill(a); + mIncrease->setVisible(true); + mIncrease->setEnabled(player_node->getSkillPoints()); } + else + { + mIncrease->setVisible(false); + mIncrease->setEnabled(false); + } + + widgetResized(NULL); } diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 56192273..ce8f091a 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -29,10 +29,14 @@ #include <guichan/actionlistener.hpp> #include <list> +#include <map> -class ProgressBar; -class Icon; -class SkillTab; +class Label; +class ScrollArea; +class Tab; +class TabbedArea; + +struct SkillInfo; /** * The skill dialog. @@ -52,17 +56,35 @@ class SkillDialog : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * Update the tabs in this dialog + * Called when the widget changes size. Used for adapting the size of + * the tabbed area. */ - void update(); + void widgetResized(const gcn::Event &event); + + void logic(); /** - * Draw this window. - */ - void draw(gcn::Graphics *g); + * Update the given skill's display + */ + std::string update(int id); + + /** + * Update other parts of the display + */ + void update(); + + void loadSkills(const std::string &file); + + void setModifiable(int id, bool modifiable); private: - std::list<SkillTab*> mTabs; + void adjustTabSize(); + + typedef std::map<int, SkillInfo*> SkillMap; + SkillMap mSkills; + Tab *mCurrentTab; + TabbedArea *mTabs; + Label *mPointsLabel; }; extern SkillDialog *skillDialog; diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 959e47ee..c2703327 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -28,8 +28,6 @@ #include "graphics.h" -#include "utils/gettext.h" - #include <guichan/font.hpp> #include <guichan/widgets/label.hpp> diff --git a/src/gui/status.cpp b/src/gui/status.cpp deleted file mode 100644 index eca01725..00000000 --- a/src/gui/status.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "gui/status.h" -#include "gui/palette.h" - -#include "localplayer.h" -#include "units.h" - -#include "gui/widgets/button.h" -#include "gui/widgets/label.h" -#include "gui/widgets/layout.h" -#include "gui/widgets/progressbar.h" -#include "gui/widgets/windowcontainer.h" - -#include "net/net.h" -#include "net/ea/playerhandler.h" - -#include "utils/gettext.h" -#include "utils/mathutils.h" -#include "utils/stringutils.h" - -StatusWindow::StatusWindow(LocalPlayer *player): - Window(player->getName()), - mPlayer(player), - mCurrency(0) -{ - setWindowName("Status"); - setCloseButton(true); - setSaveVisible(true); - setDefaultSize(400, 345, ImageRect::CENTER); - - // ---------------------- - // Status Part - // ---------------------- - - mLvlLabel = new Label(strprintf(_("Level: %d"), 0)); - mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0)); - mGpLabel = new Label(strprintf(_("Money: %s"), - Units::formatCurrency(mCurrency).c_str())); - - mHpLabel = new Label(_("HP:")); - mHpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(0, 171, 34)); - - mXpLabel = new Label(_("Exp:")); - mXpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(143, 192, 211)); - - mMpLabel = new Label(_("MP:")); - mMpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(26, 102, 230)); - - mJobLabel = new Label(_("Job:")); - mJobBar = new ProgressBar(0.0f, 80, 15, gcn::Color(220, 135, 203)); - - // ---------------------- - // Stats Part - // ---------------------- - - // Static Labels - gcn::Label *mStatsTitleLabel = new Label(_("Stats")); - gcn::Label *mStatsTotalLabel = new Label(_("Total")); - gcn::Label *mStatsCostLabel = new Label(_("Cost")); - mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER); - - // Derived Stats - mStatsAttackLabel = new Label(_("Attack:")); - mStatsDefenseLabel= new Label(_("Defense:")); - mStatsMagicAttackLabel = new Label(_("M.Attack:")); - mStatsMagicDefenseLabel = new Label(_("M.Defense:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsAccuracyLabel = new Label(_("% Accuracy:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsEvadeLabel = new Label(_("% Evade:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsReflexLabel = new Label(_("% Reflex:")); - - mStatsAttackPoints = new Label; - mStatsDefensePoints = new Label; - mStatsMagicAttackPoints = new Label; - mStatsMagicDefensePoints = new Label; - mStatsAccuracyPoints = new Label; - mStatsEvadePoints = new Label; - mStatsReflexPoints = new Label; - - // New labels - for (int i = 0; i < 6; i++) - { - mStatsLabel[i] = new Label("0"); - mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER); - mStatsDisplayLabel[i] = new Label; - mPointsLabel[i] = new Label("0"); - mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER); - } - mRemainingStatsPointsLabel = new Label; - - // Set button events Id - mStatsButton[0] = new Button("+", "STR", this); - mStatsButton[1] = new Button("+", "AGI", this); - mStatsButton[2] = new Button("+", "VIT", this); - mStatsButton[3] = new Button("+", "INT", this); - mStatsButton[4] = new Button("+", "DEX", this); - mStatsButton[5] = new Button("+", "LUK", this); - - // Assemble - ContainerPlacer place; - place = getPlacer(0, 0); - - place(0, 0, mLvlLabel, 3); - place(5, 0, mJobLvlLabel, 3); - place(8, 0, mGpLabel, 3); - place(0, 1, mHpLabel).setPadding(3); - place(1, 1, mHpBar, 4); - place(5, 1, mXpLabel).setPadding(3); - place(6, 1, mXpBar, 5); - place(0, 2, mMpLabel).setPadding(3); - place(1, 2, mMpBar, 4); - place(5, 2, mJobLabel).setPadding(3); - place(6, 2, mJobBar, 5); - place.getCell().matchColWidth(0, 1); - place = getPlacer(0, 3); - place(0, 1, mStatsTitleLabel, 5); - place(5, 1, mStatsTotalLabel, 5); - place(12, 1, mStatsCostLabel, 5); - for (int i = 0; i < 6; i++) - { - place(0, 2 + i, mStatsLabel[i], 7).setPadding(5); - place(7, 2 + i, mStatsDisplayLabel[i]).setPadding(5); - place(10, 2 + i, mStatsButton[i]); - place(12, 2 + i, mPointsLabel[i]).setPadding(5); - } - place(14, 2, mStatsAttackLabel, 7).setPadding(5); - place(14, 3, mStatsDefenseLabel, 7).setPadding(5); - place(14, 4, mStatsMagicAttackLabel, 7).setPadding(5); - place(14, 5, mStatsMagicDefenseLabel, 7).setPadding(5); - place(14, 6, mStatsAccuracyLabel, 7).setPadding(5); - place(14, 7, mStatsEvadeLabel, 7).setPadding(5); - place(14, 8, mStatsReflexLabel, 7).setPadding(5); - place(21, 2, mStatsAttackPoints, 3).setPadding(5); - place(21, 3, mStatsDefensePoints, 3).setPadding(5); - place(21, 4, mStatsMagicAttackPoints, 3).setPadding(5); - place(21, 5, mStatsMagicDefensePoints, 3).setPadding(5); - place(21, 6, mStatsAccuracyPoints, 3).setPadding(5); - place(21, 7, mStatsEvadePoints, 3).setPadding(5); - place(21, 8, mStatsReflexPoints, 3).setPadding(5); - place(0, 8, mRemainingStatsPointsLabel, 3).setPadding(5); - - Layout &layout = getLayout(); - layout.setRowHeight(0, Layout::AUTO_SET); - - loadWindowState(); -} - -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(); -} - -void StatusWindow::draw(gcn::Graphics *g) -{ - update(); - - Window::draw(g); -} - -void StatusWindow::action(const gcn::ActionEvent &event) -{ - // Stats Part - // Net::getPlayerHandler()->increaseStat(?); - if (event.getId().length() == 3) - { - if (event.getId() == "STR") - Net::getPlayerHandler()->increaseStat(LocalPlayer::STR); - if (event.getId() == "AGI") - Net::getPlayerHandler()->increaseStat(LocalPlayer::AGI); - if (event.getId() == "VIT") - Net::getPlayerHandler()->increaseStat(LocalPlayer::VIT); - if (event.getId() == "INT") - Net::getPlayerHandler()->increaseStat(LocalPlayer::INT); - if (event.getId() == "DEX") - Net::getPlayerHandler()->increaseStat(LocalPlayer::DEX); - if (event.getId() == "LUK") - Net::getPlayerHandler()->increaseStat(LocalPlayer::LUK); - } -} - -void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) -{ - if (showMax) - bar->setText(toString(player_node->getHp()) + - "/" + toString(player_node->getMaxHp())); - else - bar->setText(toString(player_node->getHp())); - - // HP Bar coloration - float r1 = 255; - float g1 = 255; - float b1 = 255; - - float r2 = 255; - float g2 = 255; - float b2 = 255; - - float weight = 1.0f; - - int curHP = player_node->getHp(); - int thresholdLevel = player_node->getMaxHp() / 4; - int thresholdProgress = curHP % thresholdLevel; - weight = 1-((float)thresholdProgress) / ((float)thresholdLevel); - - if (curHP < (thresholdLevel)) - { - gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); - gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER); - r1 = color1.r; r2 = color2.r; - g1 = color1.g; g2 = color2.g; - b1 = color1.b; b2 = color2.b; - } - else if (curHP < (thresholdLevel*2)) - { - gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); - gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); - r1 = color1.r; r2 = color2.r; - g1 = color1.g; g2 = color2.g; - b1 = color1.b; b2 = color2.b; - } - else if (curHP < thresholdLevel*3) - { - gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); - gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); - r1 = color1.r; r2 = color2.r; - g1 = color1.g; g2 = color2.g; - b1 = color1.b; b2 = color2.b; - } - else - { - gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); - gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL); - r1 = color1.r; r2 = color2.r; - g1 = color1.g; g2 = color2.g; - b1 = color1.b; b2 = color2.b; - } - - // Safety checks - if (weight > 1.0f) weight = 1.0f; - if (weight < 0.0f) weight = 0.0f; - - // Do the color blend - r1 = (int) weightedAverage(r1, r2,weight); - g1 = (int) weightedAverage(g1, g2, weight); - b1 = (int) weightedAverage(b1, b2, weight); - - // More safety checks - if (r1 > 255) r1 = 255; - if (g1 > 255) g1 = 255; - if (b1 > 255) b1 = 255; - - bar->setColor(r1, g1, b1); - - bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); -} - -void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) -{ - if (showMax) - bar->setText(toString(player_node->mMp) + - "/" + toString(player_node->mMaxMp)); - else - bar->setText(toString(player_node->mMp)); - - if (player_node->MATK <= 0) - bar->setColor(100, 100, 100); // grey, to indicate that we lack magic - else - bar->setColor(26, 102, 230); // blue, to indicate that we have magic - - bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp); -} - -static void updateProgressBar(ProgressBar *bar, int value, int max, - bool percent) -{ - if (max == 0) - { - bar->setText(_("Max level")); - bar->setProgress(1.0); - } - else - { - float progress = (float) value / max; - - if (percent) - bar->setText(strprintf("%2.2f", 100 * progress) + "%"); - else - bar->setText(toString(value) + "/" + toString(max)); - - bar->setProgress(progress); - } -} - -void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) -{ - updateProgressBar(bar, - player_node->getXp(), - player_node->mXpForNextLevel, - percent); -} - -void StatusWindow::updateJobBar(ProgressBar *bar, bool percent) -{ - updateProgressBar(bar, - player_node->mJobXp, - player_node->mJobXpForNextLevel, - percent); -} diff --git a/src/gui/status.h b/src/gui/status.h deleted file mode 100644 index 403a7d59..00000000 --- a/src/gui/status.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef STATUS_H -#define STATUS_H - -#include "gui/widgets/window.h" - -#include <guichan/actionlistener.hpp> - -class LocalPlayer; -class ProgressBar; - -/** - * The player status dialog. - * - * \ingroup Interface - */ -class StatusWindow : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - */ - StatusWindow(LocalPlayer *player); - - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &event); - - /** - * Draw this window - */ - void draw(gcn::Graphics *graphics); - - /** - * Updates this dialog with values from PLAYER_INFO *char_info - */ - void update(); - - static void updateHPBar(ProgressBar *bar, bool showMax = false); - static void updateMPBar(ProgressBar *bar, bool showMax = false); - static void updateXPBar(ProgressBar *bar, bool percent = true); - static void updateJobBar(ProgressBar *bar, bool percent = true); - - private: - LocalPlayer *mPlayer; - - /** - * Status Part - */ - gcn::Label *mLvlLabel, *mJobLvlLabel; - gcn::Label *mGpLabel; - int mCurrency; - gcn::Label *mHpLabel, *mMpLabel, *mXpLabel, *mJobLabel; - ProgressBar *mHpBar, *mMpBar; - ProgressBar *mXpBar, *mJobBar; - - /** - * Derived Statistics captions - */ - gcn::Label *mStatsAttackLabel, *mStatsDefenseLabel; - gcn::Label *mStatsMagicAttackLabel, *mStatsMagicDefenseLabel; - gcn::Label *mStatsAccuracyLabel, *mStatsEvadeLabel; - gcn::Label *mStatsReflexLabel; - - gcn::Label *mStatsAttackPoints, *mStatsDefensePoints; - gcn::Label *mStatsMagicAttackPoints, *mStatsMagicDefensePoints; - gcn::Label *mStatsAccuracyPoints, *mStatsEvadePoints; - gcn::Label *mStatsReflexPoints; - - /** - * Stats captions. - */ - gcn::Label *mStatsLabel[6]; - gcn::Label *mPointsLabel[6]; - gcn::Label *mStatsDisplayLabel[6]; - gcn::Label *mRemainingStatsPointsLabel; - - /** - * Stats buttons. - */ - gcn::Button *mStatsButton[6]; -}; - -extern StatusWindow *statusWindow; - -#endif diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index edbf387b..6f5f72fa 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -23,353 +23,494 @@ #include "gui/widgets/button.h" #include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" #include "gui/widgets/progressbar.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/vertcontainer.h" #include "gui/widgets/windowcontainer.h" +#include "gui/ministatus.h" +#include "gui/setup.h" + #include "localplayer.h" +#include "units.h" + +#include "net/net.h" +#include "net/playerhandler.h" + +#ifdef EATHENA_SUPPORT +#include "net/ea/protocol.h" +#endif +#include "utils/gettext.h" +#include "utils/mathutils.h" #include "utils/stringutils.h" -StatusWindow::StatusWindow(LocalPlayer *player): - Window(player->getName()), - mPlayer(player) +class AttrDisplay : public Container +{ + public: + virtual std::string update(); + + protected: + AttrDisplay(int id, const std::string &name); + + const int mId; + const std::string mName; + + LayoutHelper *mLayout; + Label *mLabel; + Label *mValue; +}; + +class DerDisplay : public AttrDisplay +{ + public: + DerDisplay(int id, const std::string &name); +}; + +class ChangeDisplay : public AttrDisplay, gcn::ActionListener +{ + public: + ChangeDisplay(int id, const std::string &name); + std::string update(); + void setPointsNeeded(int needed); + + private: + void action(const gcn::ActionEvent &event); + + int mNeeded; + + Label *mPoints; + Button *mDec; + Button *mInc; +}; + +StatusWindow::StatusWindow(): + Window(player_node->getName()) { setWindowName("Status"); + setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); setSaveVisible(true); setDefaultSize((windowContainer->getWidth() - 365) / 2, (windowContainer->getHeight() - 255) / 2, 365, 275); - loadWindowState(); // ---------------------- // Status Part // ---------------------- - mLvlLabel = new Label("Level:"); - mMoneyLabel = new Label("Money:"); - - mHpLabel = new Label("HP:"); - mHpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(0, 171, 34)); - mHpValueLabel = new Label; - - int y = 3; - int x = 5; - - mLvlLabel->setPosition(x, y); - x += mLvlLabel->getWidth() + 40; - mMoneyLabel->setPosition(x, y); - - y += mLvlLabel->getHeight() + 5; // Next Row - x = 5; - - mHpLabel->setPosition(x, y); - x += mHpLabel->getWidth() + 5; - mHpBar->setPosition(x, y); - x += mHpBar->getWidth() + 5; - mHpValueLabel->setPosition(x, y); - - y += mHpLabel->getHeight() + 5; // Next Row - x = 5; - - add(mLvlLabel); - add(mMoneyLabel); - add(mHpLabel); - add(mHpValueLabel); - add(mHpBar); + mLvlLabel = new Label(strprintf(_("Level: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %s"), "")); + + mHpLabel = new Label(_("HP:")); + mHpBar = new ProgressBar((float) player_node->getHp() + / (float) player_node->getMaxHp(), + 80, 15, gcn::Color(0, 171, 34)); + + mXpLabel = new Label(_("Exp:")); + mXpBar = new ProgressBar((float) player_node->getExp() + / player_node->getExpNeeded(), + 80, 15, gcn::Color(143, 192, 211)); + + mMpLabel = new Label(_("MP:")); + mMpBar = new ProgressBar((float) player_node->getMaxMP() + / (float) player_node->getMaxMP(), + 80, 15, gcn::Color(26, 102, 230)); + + 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); + place(0, 2, mMpLabel).setPadding(3); + // 5, 2 and 6, 2 Job Progress Bar + place(1, 2, mMpBar, 4); + +#ifdef EATHENA_SUPPORT + mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0)); + mJobLabel = new Label(_("Job:")); + mJobBar = new ProgressBar(0.0f, 80, 15, gcn::Color(220, 135, 203)); + + place(5, 0, mJobLvlLabel, 3); + place(5, 2, mJobLabel).setPadding(3); + place(6, 2, mJobBar, 5); +#endif // ---------------------- // Stats Part // ---------------------- - // Static Labels - gcn::Label *mStatsTitleLabel = new Label("Stats"); - gcn::Label *mStatsTotalLabel = new Label("Total"); - - // Derived Stats -/* - mStatsAttackLabel = new Label("Attack:"); - mStatsDefenseLabel= new Label("Defense:"); - mStatsMagicAttackLabel = new Label("M.Attack:"); - mStatsMagicDefenseLabel = new Label("M.Defense:"); - mStatsAccuracyLabel = new Label("% Accuracy:"); - mStatsEvadeLabel = new Label("% Evade:"); - mStatsReflexLabel = new Label("% Reflex:"); - - mStatsAttackPoints = new Label; - mStatsDefensePoints = new Label; - mStatsMagicAttackPoints = new Label; - mStatsMagicDefensePoints = new Label; - mStatsAccuracyPoints = new Label("% Accuracy:"); - mStatsEvadePoints = new Label("% Evade:"); - mStatsReflexPoints = new Label("% Reflex:"); -*/ - // New labels - for (int i = 0; i < 6; i++) { - mStatsLabel[i] = new Label; - mStatsDisplayLabel[i] = new Label; - } - mCharacterPointsLabel = new Label; - mCorrectionPointsLabel = new Label; - - // Set button events Id - mStatsPlus[0] = new Button("+", "STR+", this); - mStatsPlus[1] = new Button("+", "AGI+", this); - mStatsPlus[2] = new Button("+", "DEX+", this); - mStatsPlus[3] = new Button("+", "VIT+", this); - mStatsPlus[4] = new Button("+", "INT+", this); - mStatsPlus[5] = new Button("+", "WIL+", this); + mAttrCont = new VertContainer(32); + mAttrScroll = new ScrollArea(mAttrCont); + mAttrScroll->setOpaque(false); + mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); + place(0, 3, mAttrScroll, 5, 3); - mStatsMinus[0] = new Button("-", "STR-", this); - mStatsMinus[1] = new Button("-", "AGI-", this); - mStatsMinus[2] = new Button("-", "DEX-", this); - mStatsMinus[3] = new Button("-", "VIT-", this); - mStatsMinus[4] = new Button("-", "INT-", this); - mStatsMinus[5] = new Button("-", "WIL-", this); + mDAttrCont = new VertContainer(32); + mDAttrScroll = new ScrollArea(mDAttrCont); + mDAttrScroll->setOpaque(false); + mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); + place(6, 3, mDAttrScroll, 5, 3); + getLayout().setRowHeight(3, Layout::AUTO_SET); + mCharacterPointsLabel = new Label("C"); + mCorrectionPointsLabel = new Label("C"); + place(0, 6, mCharacterPointsLabel, 5); + place(0, 7, mCorrectionPointsLabel, 5); - // Set position - mStatsTitleLabel->setPosition(mHpLabel->getX(), mHpLabel->getY() + 23 ); - mStatsTotalLabel->setPosition(110, mStatsTitleLabel->getY() + 15); - int totalLabelY = mStatsTotalLabel->getY(); - - for (int i = 0; i < 6; i++) - { - mStatsLabel[i]->setPosition(5, - mStatsTotalLabel->getY() + (i * 23) + 15); - mStatsMinus[i]->setPosition(85, totalLabelY + (i * 23) + 15); - mStatsDisplayLabel[i]->setPosition(125, - totalLabelY + (i * 23) + 15); - mStatsPlus[i]->setPosition(185, totalLabelY + (i * 23) + 15); - } + loadWindowState(); - mCharacterPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 25); - mCorrectionPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 35); -/* - mStatsAttackLabel->setPosition(220, mStatsLabel[0]->getY()); - mStatsDefenseLabel->setPosition(220, mStatsLabel[1]->getY()); - mStatsMagicAttackLabel->setPosition(220, mStatsLabel[2]->getY()); - mStatsMagicDefenseLabel->setPosition(220, mStatsLabel[3]->getY()); - mStatsAccuracyLabel->setPosition(220, mStatsLabel[4]->getY()); - mStatsEvadeLabel->setPosition(220, mStatsLabel[5]->getY()); - mStatsReflexLabel->setPosition(220, mStatsLabel[6]->getY()); - - mStatsAttackPoints->setPosition(310, mStatsLabel[0]->getY()); - mStatsDefensePoints->setPosition(310, mStatsLabel[1]->getY()); - mStatsMagicAttackPoints->setPosition(310, mStatsLabel[2]->getY()); - mStatsMagicDefensePoints->setPosition(310, mStatsLabel[3]->getY()); - mStatsAccuracyPoints->setPosition(310, mStatsLabel[4]->getY()); - mStatsEvadePoints->setPosition(310, mStatsLabel[5]->getY()); - mStatsReflexPoints->setPosition(310, mStatsLabel[6]->getY()); -*/ - // Assemble - add(mStatsTitleLabel); - add(mStatsTotalLabel); - for(int i = 0; i < 6; i++) - { - add(mStatsLabel[i]); - add(mStatsDisplayLabel[i]); - add(mStatsPlus[i]); - add(mStatsMinus[i]); - }/* - add(mStatsAttackLabel); - add(mStatsDefenseLabel); - add(mStatsMagicAttackLabel); - add(mStatsMagicDefenseLabel); - add(mStatsAccuracyLabel); - add(mStatsEvadeLabel); - add(mStatsReflexLabel); - - add(mStatsAttackPoints); - add(mStatsDefensePoints); - add(mStatsMagicAttackPoints); - add(mStatsMagicDefensePoints); - add(mStatsAccuracyPoints); - add(mStatsEvadePoints); - add(mStatsReflexPoints);*/ - - add(mCharacterPointsLabel); - add(mCorrectionPointsLabel); + update(HP); + update(MP); + update(EXP); + update(MONEY); + update(CHAR_POINTS); // This also updates all attributes (none atm) + update(LEVEL); +#ifdef EATHENA_SUPPORT + update(JOB); +#endif } -void StatusWindow::update() +std::string StatusWindow::update(int id) { - // Status Part - // ----------- - mLvlLabel->setCaption( "Level: " + - toString(mPlayer->getLevel()) + - " (" + - toString(mPlayer->getLevelProgress()) + - "%)"); - mLvlLabel->adjustSize(); - - mMoneyLabel->setCaption("Money: " + toString(mPlayer->getMoney()) + " GP"); - mMoneyLabel->adjustSize(); + if (miniStatusWindow) + miniStatusWindow->update(id); - updateHPBar(mHpBar, true); - - // Stats Part - // ---------- - const std::string attrNames[6] = { - "Strength", - "Agility", - "Dexterity", - "Vitality", - "Intelligence", - "Willpower" - }; - int characterPoints = mPlayer->getCharacterPoints(); - int correctionPoints = mPlayer->getCorrectionPoints(); - // Update labels - for (int i = 0; i < 6; i++) + if (id == HP) { - mStatsLabel[i]->setCaption(attrNames[i]); - mStatsDisplayLabel[i]->setCaption( - strprintf("%d / %d", - mPlayer->getAttributeEffective(CHAR_ATTR_BEGIN + i), - mPlayer->getAttributeBase(CHAR_ATTR_BEGIN + i))); - - mStatsLabel[i]->adjustSize(); - mStatsDisplayLabel[i]->adjustSize(); + updateHPBar(mHpBar, true); - mStatsPlus[i]->setEnabled(characterPoints); - mStatsMinus[i]->setEnabled(correctionPoints); + return _("HP"); } - mCharacterPointsLabel->setCaption("Character Points: " + - toString(characterPoints)); - mCharacterPointsLabel->adjustSize(); - - mCorrectionPointsLabel->setCaption("Correction Points: " + - toString(correctionPoints)); - mCorrectionPointsLabel->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(); -*/ - // Update Second column widgets position - mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, - mLvlLabel->getY()); - -} - -void StatusWindow::draw(gcn::Graphics *g) -{ - update(); - - Window::draw(g); -} - -void StatusWindow::action(const gcn::ActionEvent &event) -{ - const std::string &eventId = event.getId(); - - // Stats Part - if (eventId == "STR+") + else if (id == MP) { - mPlayer->raiseAttribute(LocalPlayer::STR); + updateMPBar(mMpBar, true); + + return _("MP"); } - else if (eventId == "AGI+") + else if (id == EXP) { - mPlayer->raiseAttribute(LocalPlayer::AGI); + updateXPBar(mXpBar, false); + + return _("Exp"); } - else if (eventId == "DEX+") + else if (id == MONEY) { - mPlayer->raiseAttribute(LocalPlayer::DEX); + int money = player_node->getMoney(); + mMoneyLabel->setCaption(strprintf(_("Money: %s"), + Units::formatCurrency(money).c_str())); + mMoneyLabel->adjustSize(); + + return _("Money"); } - else if (eventId == "VIT+") +#ifdef EATHENA_SUPPORT + else if (id == JOB) { - mPlayer->raiseAttribute(LocalPlayer::VIT); + mJobLvlLabel->setCaption(strprintf(_("Job: %d"), + player_node->getAttributeBase(JOB))); + mJobLvlLabel->adjustSize(); + + updateProgressBar(mJobBar, JOB, false); + + return _("Job"); } - else if (eventId == "INT+") +#endif + else if (id == CHAR_POINTS) { - mPlayer->raiseAttribute(LocalPlayer::INT); + mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"), + player_node->getCharacterPoints())); + mCharacterPointsLabel->adjustSize(); + + mCorrectionPointsLabel->setCaption(strprintf(_("Correction points: %d"), + player_node->getCorrectionPoints())); + mCorrectionPointsLabel->adjustSize(); + + for (Attrs::iterator it = mAttrs.begin(); it != mAttrs.end(); it++) + { + it->second->update(); + } } - else if (eventId == "WIL+") + else if (id == LEVEL) { - mPlayer->raiseAttribute(LocalPlayer::WIL); - } + mLvlLabel->setCaption(strprintf(_("Level: %d"), + player_node->getLevel())); + mLvlLabel->adjustSize(); - else if (eventId == "STR-") - { - mPlayer->lowerAttribute(LocalPlayer::STR); - } - else if (eventId == "AGI-") - { - mPlayer->lowerAttribute(LocalPlayer::AGI); + return _("Level"); } - else if (eventId == "DEX-") + else { - mPlayer->lowerAttribute(LocalPlayer::DEX); + Attrs::iterator it = mAttrs.find(id); + + if (it != mAttrs.end()) + { + return it->second->update(); + } } - else if (eventId == "VIT-") + + return ""; +} + +void StatusWindow::setPointsNeeded(int id, int needed) +{ + Attrs::iterator it = mAttrs.find(id); + + if (it != mAttrs.end()) { - mPlayer->lowerAttribute(LocalPlayer::VIT); + ChangeDisplay *disp = dynamic_cast<ChangeDisplay*>(it->second); + if (disp) + disp->setPointsNeeded(needed); } - else if (eventId == "INT-") +} + +void StatusWindow::addAttribute(int id, const std::string &name, + bool modifiable) +{ + AttrDisplay *disp; + + if (modifiable) { - mPlayer->lowerAttribute(LocalPlayer::INT); + disp = new ChangeDisplay(id, name); + mAttrCont->add(disp); } - else if (eventId == "WIL-") + else { - mPlayer->lowerAttribute(LocalPlayer::WIL); + disp = new DerDisplay(id, name); + mDAttrCont->add(disp); } -} -// WARNING: Duplicated method! + mAttrs[id] = disp; +} void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) { + if (showMax) bar->setText(toString(player_node->getHp()) + "/" + toString(player_node->getMaxHp())); else bar->setText(toString(player_node->getHp())); - // HP Bar coloration - if (player_node->getHp() < player_node->getMaxHp() / 3) + if (player_node->getMaxHp() < 4) { - bar->setColor(223, 32, 32); // Red + bar->setColor(guiPalette->getColor(Palette::HPBAR_ONE_QUARTER)); } - else if (player_node->getHp() < (player_node->getMaxHp() / 3) * 2) + else { - bar->setColor(230, 171, 34); // Orange + // HP Bar coloration + float r1 = 255; + float g1 = 255; + float b1 = 255; + + float r2 = 255; + float g2 = 255; + float b2 = 255; + + float weight = 1.0f; + + int curHP = player_node->getHp(); + int thresholdLevel = player_node->getMaxHp() / 4; + int thresholdProgress = curHP % thresholdLevel; + + if (thresholdLevel) + weight = 1 - ((float)thresholdProgress) / ((float)thresholdLevel); + else + weight = 0; + + if (curHP < (thresholdLevel)) + { + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; + } + else if (curHP < (thresholdLevel*2)) + { + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; + } + else if (curHP < thresholdLevel*3) + { + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; + } + else + { + gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL); + gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL); + r1 = color1.r; r2 = color2.r; + g1 = color1.g; g2 = color2.g; + b1 = color1.b; b2 = color2.b; + } + + // Safety checks + if (weight > 1.0f) weight = 1.0f; + if (weight < 0.0f) weight = 0.0f; + + // Do the color blend + r1 = (int) weightedAverage(r1, r2,weight); + g1 = (int) weightedAverage(g1, g2, weight); + b1 = (int) weightedAverage(b1, b2, weight); + + // More safety checks + if (r1 > 255) r1 = 255; + if (g1 > 255) g1 = 255; + if (b1 > 255) b1 = 255; + + bar->setColor(r1, g1, b1); } + + bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); + +} + +void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) +{ + if (showMax) + bar->setText(toString(player_node->getMP()) + + "/" + toString(player_node->getMaxMP())); else + bar->setText(toString(player_node->getMP())); + + if (Net::getPlayerHandler()->canUseMagic()) + bar->setColor(26, 102, 230); // blue, to indicate that we have magic + else + bar->setColor(100, 100, 100); // grey, to indicate that we lack magic + + bar->setProgress((float) player_node->getMP() / + (float) player_node->getMaxMP()); +} + +void StatusWindow::updateProgressBar(ProgressBar *bar, int value, int max, + bool percent) +{ + if (max == 0) { - bar->setColor(0, 171, 34); // Green + bar->setText(_("Max")); + bar->setProgress(1.0); } + else + { + float progress = (float) value / max; - bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); + if (percent) + bar->setText(strprintf("%2.2f", 100 * progress) + "%"); + else + bar->setText(toString(value) + "/" + toString(max)); + + bar->setProgress(progress); + } +} + +void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) +{ + updateProgressBar(bar, player_node->getExp(), player_node->getExpNeeded(), + percent); +} + +void StatusWindow::updateProgressBar(ProgressBar *bar, int id, bool percent) +{ + std::pair<int, int> exp = player_node->getExperience(id); + updateProgressBar(bar, exp.first, exp.second, percent); +} + +AttrDisplay::AttrDisplay(int id, const std::string &name): + mId(id), + mName(name) +{ + setSize(100, 32); + mLabel = new Label(name); + mValue = new Label("1"); + + mLabel->setAlignment(Graphics::CENTER); + mValue->setAlignment(Graphics::CENTER); + + mLayout = new LayoutHelper(this); +} + +std::string AttrDisplay::update() +{ + int base = player_node->getAttributeBase(mId); + int bonus = player_node->getAttributeEffective(mId) - base; + std::string value = toString(base); + if (bonus) + value += strprintf(" (%+d)", bonus); + mValue->setCaption(value); + + return mName; +} + +DerDisplay::DerDisplay(int id, const std::string &name): + AttrDisplay(id, name) +{ + // Do the layout + LayoutHelper h(this); + ContainerPlacer place = mLayout->getPlacer(0, 0); + + place(0, 0, mLabel, 3); + place(3, 0, mValue, 2); + + update(); +} + +ChangeDisplay::ChangeDisplay(int id, const std::string &name): + AttrDisplay(id, name), mNeeded(1) +{ + mPoints = new Label("1"); + mDec = new Button(_("-"), "dec", this); + mInc = new Button(_("+"), "inc", this); + mDec->setWidth(mInc->getWidth()); + + // Do the layout + ContainerPlacer place = mLayout->getPlacer(0, 0); + + place(0, 0, mLabel, 3); + place(3, 0, mDec); + place(4, 0, mValue, 2); + place(6, 0, mInc); + place(7, 0, mPoints); + + update(); +} + +std::string ChangeDisplay::update() +{ + mPoints->setCaption(toString(mNeeded)); + + mDec->setEnabled(player_node->getCorrectionPoints()); + mInc->setEnabled(player_node->getCharacterPoints() >= mNeeded); + + return AttrDisplay::update(); +} + +void ChangeDisplay::setPointsNeeded(int needed) +{ + mNeeded = needed; + + update(); +} + +void ChangeDisplay::action(const gcn::ActionEvent &event) +{ + if (event.getSource() == mDec) + { + Net::getPlayerHandler()->decreaseAttribute(mId); + } + else if (event.getSource() == mInc) + { + Net::getPlayerHandler()->increaseAttribute(mId); + } } diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index 1e2a5097..f6d4f73e 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -28,75 +28,71 @@ #include <guichan/actionlistener.hpp> -class LocalPlayer; +#include <map> + +class AttrDisplay; class ProgressBar; +class ScrollArea; +class VertContainer; /** * The player status dialog. * * \ingroup Interface */ -class StatusWindow : public Window, public gcn::ActionListener +class StatusWindow : public Window { public: + enum { // Some update constants + HP = -1, + MP = -2, + EXP = -3, + MONEY = -4, + CHAR_POINTS = -5, + LEVEL = -6 + }; + /** * Constructor. */ - StatusWindow(LocalPlayer *player); + StatusWindow(); - /** - * Called when receiving actions from widget. - */ - void action(const gcn::ActionEvent &event); + std::string update(int id); - /** - * Draw this window - */ - void draw(gcn::Graphics *graphics); + void setPointsNeeded(int id, int needed); - /** - * Updates this dialog with values from PLAYER_INFO *char_info - */ - void update(); + void addAttribute(int id, const std::string &name, bool modifiable); static void updateHPBar(ProgressBar *bar, bool showMax = false); + static void updateMPBar(ProgressBar *bar, bool showMax = false); + static void updateXPBar(ProgressBar *bar, bool percent = true); + static void updateProgressBar(ProgressBar *bar, int value, int max, + bool percent); + void updateProgressBar(ProgressBar *bar, int id, + bool percent = true); private: - LocalPlayer *mPlayer; - /** * Status Part */ - gcn::Label *mLvlLabel, *mMoneyLabel, *mHpLabel, *mHpValueLabel; - ProgressBar *mHpBar; + gcn::Label *mLvlLabel, *mMoneyLabel; + gcn::Label *mHpLabel, *mMpLabel, *mXpLabel; + ProgressBar *mHpBar, *mMpBar, *mXpBar; - /** - * Derived Statistics captions - */ -/* - gcn::Label *mStatsAttackLabel, *mStatsDefenseLabel; - gcn::Label *mStatsMagicAttackLabel, *mStatsMagicDefenseLabel; - gcn::Label *mStatsAccuracyLabel, *mStatsEvadeLabel; - gcn::Label *mStatsReflexLabel; - - gcn::Label *mStatsAttackPoints, *mStatsDefensePoints; - gcn::Label *mStatsMagicAttackPoints, *mStatsMagicDefensePoints; - gcn::Label *mStatsAccuracyPoints, *mStatsEvadePoints; - gcn::Label *mStatsReflexPoints; -*/ - /** - * Stats captions. - */ - gcn::Label *mStatsLabel[6]; - gcn::Label *mStatsDisplayLabel[6]; - gcn::Label *mCharacterPointsLabel; - gcn::Label *mCorrectionPointsLabel; +#ifdef EATHENA_SUPPORT + gcn::Label *mJobLvlLabel, *mJobLabel; + ProgressBar *mJobBar; +#endif - /** - * Stats buttons. - */ - gcn::Button *mStatsPlus[6]; - gcn::Button *mStatsMinus[6]; + VertContainer *mAttrCont; + ScrollArea *mAttrScroll; + VertContainer *mDAttrCont; + ScrollArea *mDAttrScroll; + + gcn::Label *mCharacterPointsLabel, *mCorrectionPointsLabel; + + typedef std::map<int, AttrDisplay*> Attrs; + Attrs mAttrs; }; extern StatusWindow *statusWindow; diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 91224359..f0d00ee7 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -24,6 +24,7 @@ #include "gui/inventorywindow.h" #include "gui/itemamount.h" #include "gui/itemcontainer.h" +#include "gui/setup.h" #include "gui/viewport.h" #include "gui/widgets/button.h" @@ -58,6 +59,7 @@ StorageWindow::StorageWindow(int invSize): setWindowName("Storage"); setResizable(true); setCloseButton(true); + setupWindow->registerWindowForReset(this); // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(375, 300, ImageRect::CENTER); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 3abb985e..22eefc14 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -29,6 +29,7 @@ #include "gui/inventorywindow.h" #include "gui/itemamount.h" #include "gui/itemcontainer.h" +#include "gui/setup.h" #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" @@ -65,6 +66,7 @@ TradeWindow::TradeWindow(): setDefaultSize(386, 180, ImageRect::CENTER); setMinWidth(386); setMinHeight(180); + setupWindow->registerWindowForReset(this); std::string longestName = getFont()->getWidth(_("OK")) > getFont()->getWidth(_("Trade")) ? @@ -92,7 +94,7 @@ TradeWindow::TradeWindow(): ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer); partnerScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mMoneyLabel = new Label(strprintf(_("You get %s."), "")); + mMoneyLabel = new Label(strprintf(_("You get %s"), "")); gcn::Label *mMoneyLabel2 = new Label(_("You give:")); mMoneyField = new TextField; @@ -128,7 +130,7 @@ TradeWindow::~TradeWindow() void TradeWindow::setMoney(int amount) { - mMoneyLabel->setCaption(strprintf(_("You get %s."), + mMoneyLabel->setCaption(strprintf(_("You get %s"), Units::formatCurrency(amount).c_str())); mMoneyLabel->adjustSize(); } @@ -255,7 +257,10 @@ void TradeWindow::action(const gcn::ActionEvent &event) return; if (!inventoryWindow->isVisible()) + { + inventoryWindow->setVisible(true); return; + } if (!item) return; diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 048239c5..be54453d 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -42,7 +42,7 @@ #include <sstream> UnRegisterDialog::UnRegisterDialog(Window *parent, LoginData *loginData): - Window("Unregister", true, parent), + Window(_("Unregister"), true, parent), mWrongDataNoticeListener(new WrongDataNoticeListener), mLoginData(loginData) { @@ -102,24 +102,23 @@ UnRegisterDialog::action(const gcn::ActionEvent &event) logger->log("UnregisterDialog::unregistered, Username is %s", username.c_str()); - std::stringstream errorMsg; + std::stringstream errorMessage; bool error = false; // Check password if (password.length() < LEN_MIN_PASSWORD) { // Pass too short - errorMsg << "The password needs to be at least " - << LEN_MIN_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The password needs to be at least %d " + "characters long."), LEN_MIN_PASSWORD); error = true; } - else if (password.length() > LEN_MAX_PASSWORD - 1 ) + else if (password.length() > LEN_MAX_PASSWORD - 1) { // Pass too long - errorMsg << "The password needs to be less than " - << LEN_MAX_PASSWORD - << " characters long."; + errorMessage << strprintf(_("The password needs to be less than " + "%d characters long."), + LEN_MAX_PASSWORD); error = true; } @@ -127,7 +126,7 @@ UnRegisterDialog::action(const gcn::ActionEvent &event) { mWrongDataNoticeListener->setTarget(this->mPasswordField); - OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), errorMessage.str()); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 21362630..bb2128b4 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -322,9 +322,8 @@ int UpdaterWindow::downloadThread(void *ptr) { case CURLE_COULDNT_CONNECT: default: - std::cerr << _("curl error ") << res << ": " - << uw->mCurlError << _(" host: ") << url.c_str() - << std::endl; + logger->log("curl error %d: %s host: %s", + res, uw->mCurlError, url.c_str()); break; } @@ -445,10 +444,13 @@ void UpdaterWindow::logic() } mThread = NULL; } + // TODO: Only send complete sentences to gettext mBrowserBox->addRow(""); mBrowserBox->addRow(_("##1 The update process is incomplete.")); + // TRANSLATORS: Continues "you try again later.". mBrowserBox->addRow(_("##1 It is strongly recommended that")); - mBrowserBox->addRow(_("##1 you try again later")); + // TRANSLATORS: Begins "It is strongly recommended that". + mBrowserBox->addRow(_("##1 you try again later.")); mBrowserBox->addRow(mCurlError); mScrollArea->setVerticalScrollAmount( mScrollArea->getVerticalMaxScroll()); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 68b5fed3..9a631581 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -116,22 +116,12 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) } // Calculate viewpoint -#ifdef TMWSERV_SUPPORT int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 2; int midTileY = (graphics->getHeight() + mScrollCenterOffsetX) / 2; const Vector &playerPos = player_node->getPosition(); const int player_x = (int) playerPos.x - midTileX; const int player_y = (int) playerPos.y - midTileY; -#else - int midTileX = (graphics->getWidth() + mScrollCenterOffsetX) / 32 / 2; - int midTileY = (graphics->getHeight() + mScrollCenterOffsetY) / 32 / 2; - - int player_x = (player_node->mX - midTileX) * 32 + - player_node->getXOffset(); - int player_y = (player_node->mY - midTileY) * 32 + - player_node->getYOffset(); -#endif if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 71579bd4..2357b263 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -152,7 +152,10 @@ void Button::draw(gcn::Graphics *graphics) static_cast<Graphics*>(graphics)-> drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); - graphics->setColor(guiPalette->getColor(Palette::TEXT)); + if (mode == BUTTON_DISABLED) + graphics->setColor(guiPalette->getColor(Palette::BUTTON_DISABLED)); + else + graphics->setColor(guiPalette->getColor(Palette::BUTTON)); int textX; int textY = getHeight() / 2 - getFont()->getHeight() / 2; diff --git a/src/gui/widgets/channeltab.cpp b/src/gui/widgets/channeltab.cpp index e3edbba0..8b055a22 100644 --- a/src/gui/widgets/channeltab.cpp +++ b/src/gui/widgets/channeltab.cpp @@ -72,23 +72,24 @@ bool ChannelTab::handleCommand(const std::string &type, { chatLog(_("Command: /quit")); chatLog(_("This command leaves the current channel.")); - chatLog(_("If you're the last person in the channel, it will be deleted.")); + chatLog(_("If you're the last person in the channel, " + "it will be deleted.")); } else if (args == "op") { chatLog(_("Command: /op <nick>")); chatLog(_("This command makes <nick> a channel operator.")); chatLog(_("If the <nick> has spaces in it, enclose it in " - "double quotes (\").")); + "double quotes (\").")); chatLog(_("Channel operators can kick and op other users " - "from the channel.")); + "from the channel.")); } else if (args == "kick") { chatLog(_("Command: /kick <nick>")); chatLog(_("This command makes <nick> leave the channel.")); chatLog(_("If the <nick> has spaces in it, enclose it in " - "double quotes (\").")); + "double quotes (\").")); } else return false; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index d2fa33b8..e3ba4874 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -143,7 +143,7 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) lineColor = "##2"; // Equiv. to BrowserBox::GREEN break; case ACT_WHISPER: - tmp.nick = strprintf(_("%s whispers: "), tmp.nick.c_str()); + tmp.nick = strprintf(_("%s whispers: %s"), tmp.nick.c_str(), ""); lineColor = "##W"; break; case ACT_IS: diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 2e9a234b..dd57f674 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -35,9 +35,12 @@ Image *CheckBox::checkBoxNormal; Image *CheckBox::checkBoxChecked; Image *CheckBox::checkBoxDisabled; Image *CheckBox::checkBoxDisabledChecked; +Image *CheckBox::checkBoxNormalHi; +Image *CheckBox::checkBoxCheckedHi; CheckBox::CheckBox(const std::string &caption, bool selected): - gcn::CheckBox(caption, selected) + gcn::CheckBox(caption, selected), + mHasMouse(false) { if (instances == 0) { @@ -47,10 +50,14 @@ CheckBox::CheckBox(const std::string &caption, bool selected): checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10); checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10); checkBoxDisabledChecked = checkBox->getSubImage(27, 0, 9, 10); + checkBoxNormalHi = checkBox->getSubImage(36, 0, 9, 10); + checkBoxCheckedHi = checkBox->getSubImage(45, 0, 9, 10); checkBoxNormal->setAlpha(mAlpha); checkBoxChecked->setAlpha(mAlpha); checkBoxDisabled->setAlpha(mAlpha); checkBoxDisabledChecked->setAlpha(mAlpha); + checkBoxNormalHi->setAlpha(mAlpha); + checkBoxCheckedHi->setAlpha(mAlpha); checkBox->decRef(); } @@ -67,6 +74,8 @@ CheckBox::~CheckBox() delete checkBoxChecked; delete checkBoxDisabled; delete checkBoxDisabledChecked; + delete checkBoxNormalHi; + delete checkBoxCheckedHi; } } @@ -86,17 +95,22 @@ void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box; - if (isSelected()) - { - if (isEnabled()) - box = checkBoxChecked; + if (isEnabled()) + if (isSelected()) + if (mHasMouse) + box = checkBoxCheckedHi; + else + box = checkBoxChecked; else - box = checkBoxDisabledChecked; - } - else if (isEnabled()) - box = checkBoxNormal; + if (mHasMouse) + box = checkBoxNormalHi; + else + box = checkBoxNormal; else - box = checkBoxDisabled; + if (isSelected()) + box = checkBoxDisabledChecked; + else + box = checkBoxDisabled; if (config.getValue("guialpha", 0.8) != mAlpha) { @@ -105,7 +119,19 @@ void CheckBox::drawBox(gcn::Graphics* graphics) checkBoxChecked->setAlpha(mAlpha); checkBoxDisabled->setAlpha(mAlpha); checkBoxDisabledChecked->setAlpha(mAlpha); + checkBoxNormal->setAlpha(mAlpha); + checkBoxCheckedHi->setAlpha(mAlpha); } static_cast<Graphics*>(graphics)->drawImage(box, 2, 2); } + +void CheckBox::mouseEntered(gcn::MouseEvent& event) +{ + mHasMouse = true; +} + +void CheckBox::mouseExited(gcn::MouseEvent& event) +{ + mHasMouse = false; +} diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index 303782b0..7a7c8674 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -24,6 +24,7 @@ #include <guichan/widgets/checkbox.hpp> + class Image; /** @@ -54,13 +55,26 @@ class CheckBox : public gcn::CheckBox */ void drawBox(gcn::Graphics* graphics); + /** + * Called when the mouse enteres the widget area. + */ + void mouseEntered(gcn::MouseEvent& event); + + /** + * Called when the mouse leaves the widget area. + */ + void mouseExited(gcn::MouseEvent& event); + private: static int instances; static float mAlpha; + bool mHasMouse; static Image *checkBoxNormal; static Image *checkBoxChecked; static Image *checkBoxDisabled; static Image *checkBoxDisabledChecked; + static Image *checkBoxNormalHi; + static Image *checkBoxCheckedHi; }; #endif diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index a4164bcc..13ac866a 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -39,8 +39,9 @@ Desktop::Desktop() Wallpaper::loadWallpapers(); - gcn::Label *versionLabel = new Label(FULL_VERSION); - add(versionLabel, 25, 2); + mVersionLabel = new Label(FULL_VERSION); + mVersionLabel->setBackgroundColor(gcn::Color(255, 255, 255, 128)); + add(mVersionLabel, 25, 2); } Desktop::~Desktop() @@ -74,11 +75,20 @@ void Desktop::draw(gcn::Graphics *graphics) if (mWallpaper) { - g->drawImage(mWallpaper, + if (!mWallpaper->isAnOpenGLOne()) + g->drawImage(mWallpaper, (getWidth() - mWallpaper->getWidth()) / 2, (getHeight() - mWallpaper->getHeight()) / 2); + else + g->drawRescaledImage(mWallpaper, 0, 0, 0, 0, + mWallpaper->getWidth(), mWallpaper->getHeight(), + getWidth(), getHeight(), false); } + // Draw a thin border under the application version... + g->setColor(gcn::Color(255, 255, 255, 128)); + g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); + Container::draw(graphics); } @@ -87,13 +97,27 @@ void Desktop::setBestFittingWallpaper() const std::string wallpaperName = Wallpaper::getWallpaper(getWidth(), getHeight()); - Image *temp = ResourceManager::getInstance()->getImage(wallpaperName); + Image *nWallPaper = ResourceManager::getInstance()->getImage(wallpaperName); - if (temp) + if (nWallPaper) { if (mWallpaper) mWallpaper->decRef(); - mWallpaper = temp; + + if (!nWallPaper->isAnOpenGLOne() && (nWallPaper->getWidth() != getWidth() + || nWallPaper->getHeight() != getHeight())) + { + // We rescale to obtain a fullscreen wallpaper... + Image *newRsclWlPpr = nWallPaper->SDLgetScaledImage(getWidth(), getHeight()); + std::string idPath = nWallPaper->getIdPath(); + + // We replace the resource in the resource manager + nWallPaper->decRef(); + ResourceManager::getInstance()->addResource(idPath, newRsclWlPpr); + mWallpaper = newRsclWlPpr; + } + else + mWallpaper = nWallPaper; } else { diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index ad04ee96..da623bbd 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -24,6 +24,8 @@ #include "gui/widgets/container.h" +#include "guichanfwd.h" + #include <guichan/widgetlistener.hpp> class Image; @@ -60,6 +62,7 @@ class Desktop : public Container, gcn::WidgetListener void setBestFittingWallpaper(); Image *mWallpaper; + gcn::Label *mVersionLabel; }; #endif // DESKTOP_H diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 134d071f..7cc020ef 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -43,14 +43,17 @@ ProgressBar::ProgressBar(float progress, int width, int height, const gcn::Color &color): gcn::Widget(), - mProgress(0.0f), - mProgressToGo(0.0f), mSmoothProgress(true), mColor(color), mColorToGo(color), mSmoothColorChange(true) { - setProgress(progress); + // The progress value is directly set at load time: + if (progress > 1.0f || progress < 0.0f) + progress = 1.0f; + + mProgress = mProgressToGo = progress; + setSize(width, height); if (mInstances == 0) diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 6f0ccdbd..9cf49672 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -33,10 +33,13 @@ Image *RadioButton::radioNormal; Image *RadioButton::radioChecked; Image *RadioButton::radioDisabled; Image *RadioButton::radioDisabledChecked; +Image *RadioButton::radioNormalHi; +Image *RadioButton::radioCheckedHi; RadioButton::RadioButton(const std::string &caption, const std::string &group, bool marked): - gcn::RadioButton(caption, group, marked) + gcn::RadioButton(caption, group, marked), + mHasMouse(false) { if (instances == 0) { @@ -45,10 +48,14 @@ RadioButton::RadioButton(const std::string &caption, const std::string &group, radioChecked = resman->getImage("graphics/gui/radioin.png"); radioDisabled = resman->getImage("graphics/gui/radioout.png"); radioDisabledChecked = resman->getImage("graphics/gui/radioin.png"); + radioNormalHi = resman->getImage("graphics/gui/radioout_highlight.png"); + radioCheckedHi = resman->getImage("graphics/gui/radioin_highlight.png"); radioNormal->setAlpha(mAlpha); radioChecked->setAlpha(mAlpha); radioDisabled->setAlpha(mAlpha); radioDisabledChecked->setAlpha(mAlpha); + radioNormalHi->setAlpha(mAlpha); + radioCheckedHi->setAlpha(mAlpha); } instances++; @@ -64,6 +71,8 @@ RadioButton::~RadioButton() radioChecked->decRef(); radioDisabled->decRef(); radioDisabledChecked->decRef(); + radioNormalHi->decRef(); + radioCheckedHi->decRef(); } } @@ -76,21 +85,28 @@ void RadioButton::drawBox(gcn::Graphics* graphics) radioChecked->setAlpha(mAlpha); radioDisabled->setAlpha(mAlpha); radioDisabledChecked->setAlpha(mAlpha); + radioNormalHi->setAlpha(mAlpha); + radioCheckedHi->setAlpha(mAlpha); } Image *box = NULL; - if (isSelected()) - { - if (isEnabled()) - box = radioChecked; + if (isEnabled()) + if (isSelected()) + if (mHasMouse) + box = radioCheckedHi; + else + box = radioChecked; else - box = radioDisabledChecked; - } - else if (isEnabled()) - box = radioNormal; + if (mHasMouse) + box = radioNormalHi; + else + box = radioNormal; else - box = radioDisabled; + if (isSelected()) + box = radioDisabledChecked; + else + box = radioDisabled; if (box) static_cast<Graphics*>(graphics)->drawImage(box, 2, 2); @@ -111,3 +127,14 @@ void RadioButton::draw(gcn::Graphics* graphics) int h = getHeight() + getHeight() / 2; graphics->drawText(getCaption(), h - 2, 0); } + +void RadioButton::mouseEntered(gcn::MouseEvent& event) +{ + mHasMouse = true; +} + +void RadioButton::mouseExited(gcn::MouseEvent& event) +{ + mHasMouse = false; +} + diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h index 9aec3add..57eb3623 100644 --- a/src/gui/widgets/radiobutton.h +++ b/src/gui/widgets/radiobutton.h @@ -26,13 +26,13 @@ class Image; -/* +/** * Guichan based RadioButton with custom look */ class RadioButton : public gcn::RadioButton { public: - /* + /** * Constructor. */ RadioButton(const std::string &caption,const std::string &group, @@ -54,13 +54,26 @@ class RadioButton : public gcn::RadioButton */ void draw(gcn::Graphics* graphics); + /** + * Called when the mouse enteres the widget area. + */ + void mouseEntered(gcn::MouseEvent& event); + + /** + * Called when the mouse leaves the widget area. + */ + void mouseExited(gcn::MouseEvent& event); + private: static int instances; static float mAlpha; + bool mHasMouse; static Image *radioNormal; static Image *radioChecked; static Image *radioDisabled; static Image *radioDisabledChecked; + static Image *radioNormalHi; + static Image *radioCheckedHi; }; #endif /* RADIOBUTTON_H */ diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index ff3a23d1..52322b05 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -33,10 +33,13 @@ int ScrollArea::instances = 0; float ScrollArea::mAlpha = 1.0; ImageRect ScrollArea::background; ImageRect ScrollArea::vMarker; +ImageRect ScrollArea::vMarkerHi; Image *ScrollArea::buttons[4][2]; ScrollArea::ScrollArea(): gcn::ScrollArea(), + mX(0), + mY(0), mOpaque(true) { init(); @@ -44,6 +47,7 @@ ScrollArea::ScrollArea(): ScrollArea::ScrollArea(gcn::Widget *widget): gcn::ScrollArea(widget), + mHasMouse(false), mOpaque(true) { init(); @@ -60,6 +64,7 @@ ScrollArea::~ScrollArea() { for_each(background.grid, background.grid + 9, dtor<Image*>()); for_each(vMarker.grid, vMarker.grid + 9, dtor<Image*>()); + for_each(vMarkerHi.grid, vMarkerHi.grid + 9, dtor<Image*>()); buttons[UP][0]->decRef(); buttons[UP][1]->decRef(); @@ -103,6 +108,8 @@ void ScrollArea::init() // Load vertical scrollbar skin Image *vscroll = resman->getImage("graphics/gui/vscroll_grey.png"); + Image *vscrollHi = resman->getImage("graphics/gui/vscroll_highlight.png"); + int vsgridx[4] = {0, 4, 7, 11}; int vsgridy[4] = {0, 4, 15, 19}; a = 0; @@ -115,12 +122,18 @@ void ScrollArea::init() vsgridx[x], vsgridy[y], vsgridx[x + 1] - vsgridx[x], vsgridy[y + 1] - vsgridy[y]); + vMarkerHi.grid[a] = vscrollHi->getSubImage( + vsgridx[x], vsgridy[y], + vsgridx[x + 1] - vsgridx[x], + vsgridy[y + 1] - vsgridy[y]); vMarker.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); + vMarkerHi.grid[a]->setAlpha(config.getValue("guialpha", 0.8)); a++; } } vscroll->decRef(); + vscrollHi->decRef(); buttons[UP][0] = resman->getImage("graphics/gui/vscroll_up_default.png"); @@ -202,6 +215,7 @@ void ScrollArea::draw(gcn::Graphics *graphics) { background.grid[a]->setAlpha(mAlpha); vMarker.grid[a]->setAlpha(mAlpha); + vMarkerHi.grid[a]->setAlpha(mAlpha); } } @@ -296,14 +310,39 @@ void ScrollArea::drawVMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getVerticalMarkerDimension(); - static_cast<Graphics*>(graphics)-> - drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); + if ((mHasMouse) && (mX > (getWidth() - getScrollbarWidth()))) + static_cast<Graphics*>(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarkerHi); + else + static_cast<Graphics*>(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height,vMarker); } void ScrollArea::drawHMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getHorizontalMarkerDimension(); - static_cast<Graphics*>(graphics)-> - drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); + if ((mHasMouse) && (mY > (getHeight() - getScrollbarWidth()))) + static_cast<Graphics*>(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarkerHi); + else + static_cast<Graphics*>(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); } + +void ScrollArea::mouseMoved(gcn::MouseEvent& event) +{ +mX = event.getX(); +mY = event.getY(); +} + +void ScrollArea::mouseEntered(gcn::MouseEvent& event) +{ + mHasMouse = true; +} + +void ScrollArea::mouseExited(gcn::MouseEvent& event) +{ + mHasMouse = false; +} + diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 700de32b..8fd92b5f 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -83,6 +83,21 @@ class ScrollArea : public gcn::ScrollArea */ bool isOpaque() const { return mOpaque; } + /** + * Called when the mouse moves in the widget area. + */ + void mouseMoved(gcn::MouseEvent& event); + + /** + * Called when the mouse enteres the widget area. + */ + void mouseEntered(gcn::MouseEvent& event); + + /** + * Called when the mouse leaves the widget area. + */ + void mouseExited(gcn::MouseEvent& event); + protected: enum BUTTON_DIR { UP, @@ -110,8 +125,11 @@ class ScrollArea : public gcn::ScrollArea static float mAlpha; static ImageRect background; static ImageRect vMarker; + static ImageRect vMarkerHi; static Image *buttons[4][2]; + int mX,mY; + bool mHasMouse; bool mOpaque; }; diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 7cd0e54a..6ce5f849 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -29,17 +29,21 @@ Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip; Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip; +Image *Slider::hStartHi, *Slider::hMidHi, *Slider::hEndHi, *Slider::hGripHi; +Image *Slider::vStartHi, *Slider::vMidHi, *Slider::vEndHi, *Slider::vGripHi; float Slider::mAlpha = 1.0; int Slider::mInstances = 0; Slider::Slider(double scaleEnd): - gcn::Slider(scaleEnd) + gcn::Slider(scaleEnd), + mHasMouse(false) { init(); } Slider::Slider(double scaleStart, double scaleEnd): - gcn::Slider(scaleStart, scaleEnd) + gcn::Slider(scaleStart, scaleEnd), + mHasMouse(false) { init(); } @@ -58,6 +62,14 @@ Slider::~Slider() delete vMid; delete vEnd; delete vGrip; + delete hStartHi; + delete hMidHi; + delete hEndHi; + delete hGripHi; + delete vStartHi; + delete vMidHi; + delete vEndHi; + delete vGripHi; } } @@ -71,6 +83,7 @@ void Slider::init() { ResourceManager *resman = ResourceManager::getInstance(); Image *slider = resman->getImage("graphics/gui/slider.png"); + Image *sliderHi = resman->getImage("graphics/gui/slider_hilight.png"); x = 0; y = 0; w = 15; h = 6; @@ -78,10 +91,14 @@ void Slider::init() hStart = slider->getSubImage(x, y, o1 - x, h); hMid = slider->getSubImage(o1, y, o2 - o1, h); hEnd = slider->getSubImage(o2, y, w - o2 + x, h); + hStartHi = sliderHi->getSubImage(x, y, o1 - x, h); + hMidHi = sliderHi->getSubImage(o1, y, o2 - o1, h); + hEndHi = sliderHi->getSubImage(o2, y, w - o2 + x, h); x = 6; y = 8; w = 9; h = 10; hGrip = slider->getSubImage(x, y, w, h); + hGripHi = sliderHi->getSubImage(x, y, w, h); x = 0; y = 6; w = 6; h = 21; @@ -89,22 +106,35 @@ void Slider::init() vStart = slider->getSubImage(x, y, w, o1 - y); vMid = slider->getSubImage(x, o1, w, o2 - o1); vEnd = slider->getSubImage(x, o2, w, h - o2 + y); + vStartHi = sliderHi->getSubImage(x, y, w, o1 - y); + vMidHi = sliderHi->getSubImage(x, o1, w, o2 - o1); + vEndHi = sliderHi->getSubImage(x, o2, w, h - o2 + y); x = 6; y = 8; w = 9; h = 10; vGrip = slider->getSubImage(x, y, w, h); + vGripHi = sliderHi->getSubImage(x, y, w, h); slider->decRef(); + sliderHi->decRef(); hStart->setAlpha(mAlpha); hMid->setAlpha(mAlpha); hEnd->setAlpha(mAlpha); hGrip->setAlpha(mAlpha); + hStartHi->setAlpha(mAlpha); + hMidHi->setAlpha(mAlpha); + hEndHi->setAlpha(mAlpha); + hGripHi->setAlpha(mAlpha); vStart->setAlpha(mAlpha); vMid->setAlpha(mAlpha); vEnd->setAlpha(mAlpha); vGrip->setAlpha(mAlpha); + vStartHi->setAlpha(mAlpha); + vMidHi->setAlpha(mAlpha); + vEndHi->setAlpha(mAlpha); + vGripHi->setAlpha(mAlpha); } mInstances++; @@ -117,7 +147,7 @@ void Slider::draw(gcn::Graphics *graphics) int w = getWidth(); int h = getHeight(); int x = 0; - int y = (h - hStart->getHeight()) / 2; + int y = mHasMouse?(h - hStartHi->getHeight()) / 2:(h - hStart->getHeight()) / 2; if (config.getValue("guialpha", 0.8) != mAlpha) { @@ -126,23 +156,45 @@ void Slider::draw(gcn::Graphics *graphics) hMid->setAlpha(mAlpha); hEnd->setAlpha(mAlpha); hGrip->setAlpha(mAlpha); + hStartHi->setAlpha(mAlpha); + hMidHi->setAlpha(mAlpha); + hEndHi->setAlpha(mAlpha); + hGripHi->setAlpha(mAlpha); vStart->setAlpha(mAlpha); vMid->setAlpha(mAlpha); vEnd->setAlpha(mAlpha); vGrip->setAlpha(mAlpha); + vStartHi->setAlpha(mAlpha); + vMidHi->setAlpha(mAlpha); + vEndHi->setAlpha(mAlpha); + vGripHi->setAlpha(mAlpha); } + if (!mHasMouse) + { + static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); - static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); + w -= hStart->getWidth() + hEnd->getWidth(); + x += hStart->getWidth(); - w -= hStart->getWidth() + hEnd->getWidth(); - x += hStart->getWidth(); + static_cast<Graphics*>(graphics)-> + drawImagePattern(hMid, x, y, w, hMid->getHeight()); - static_cast<Graphics*>(graphics)-> - drawImagePattern(hMid, x, y, w, hMid->getHeight()); + x += w; + static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); + } else + { + static_cast<Graphics*>(graphics)->drawImage(hStartHi, x, y); - x += w; - static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); + w -= hStartHi->getWidth() + hEndHi->getWidth(); + x += hStartHi->getWidth(); + + static_cast<Graphics*>(graphics)-> + drawImagePattern(hMidHi, x, y, w, hMidHi->getHeight()); + + x += w; + static_cast<Graphics*>(graphics)->drawImage(hEndHi, x, y); + } drawMarker(graphics); } @@ -150,5 +202,16 @@ void Slider::draw(gcn::Graphics *graphics) void Slider::drawMarker(gcn::Graphics *graphics) { static_cast<Graphics*>(graphics)-> - drawImage(hGrip, getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); + drawImage(mHasMouse?hGripHi:hGrip, getMarkerPosition(), + (getHeight() - (mHasMouse?hGripHi:hGrip)->getHeight()) / 2); } + +void Slider::mouseEntered(gcn::MouseEvent& event) +{ + mHasMouse = true; +} + +void Slider::mouseExited(gcn::MouseEvent& event) +{ + mHasMouse = false; +}
\ No newline at end of file diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index 56ea334a..85fb2633 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -58,6 +58,16 @@ class Slider : public gcn::Slider { */ void drawMarker(gcn::Graphics *graphics); + /** + * Called when the mouse enteres the widget area. + */ + void mouseEntered(gcn::MouseEvent& event); + + /** + * Called when the mouse leaves the widget area. + */ + void mouseExited(gcn::MouseEvent& event); + private: /** * Used to initialize instances. @@ -66,6 +76,9 @@ class Slider : public gcn::Slider { static Image *hStart, *hMid, *hEnd, *hGrip; static Image *vStart, *vMid, *vEnd, *vGrip; + static Image *hStartHi, *hMidHi, *hEndHi, *hGripHi; + static Image *vStartHi, *vMidHi, *vEndHi, *vGripHi; + bool mHasMouse; static float mAlpha; static int mInstances; }; diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index f2231fca..3e49263e 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -55,7 +55,7 @@ struct TabData static TabData const data[TAB_COUNT] = { { "graphics/gui/tab.png", 0, 0 }, - { "graphics/gui/tab.png", 9, 4 }, + { "graphics/gui/tab_hilight.png", 9, 4 }, { "graphics/gui/tabselected.png", 16, 19 }, { "graphics/gui/tab.png", 25, 23 } }; @@ -63,7 +63,7 @@ static TabData const data[TAB_COUNT] = { ImageRect Tab::tabImg[TAB_COUNT]; Tab::Tab() : gcn::Tab(), - mTabColor(&guiPalette->getColor(Palette::TEXT)) + mTabColor(&guiPalette->getColor(Palette::TAB)) { init(); } @@ -123,21 +123,19 @@ void Tab::draw(gcn::Graphics *graphics) // check which type of tab to draw if (mTabbedArea) { + mLabel->setForegroundColor(*mTabColor); if (mTabbedArea->isTabSelected(this)) { mode = TAB_SELECTED; // if tab is selected, it doesnt need to highlight activity - mLabel->setForegroundColor(*mTabColor); mHighlighted = false; - } - else if (mHighlighted) + } else if (mHasMouse) { mode = TAB_HIGHLIGHTED; - mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT)); } - else + if (mHighlighted) { - mLabel->setForegroundColor(*mTabColor); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT)); } } diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 07f46a94..bb5ae9a4 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -69,6 +69,16 @@ gcn::Widget *TabbedArea::getWidget(const std::string &name) const return NULL; } +gcn::Widget *TabbedArea::getCurrentWidget() +{ + gcn::Tab *tab = getSelectedTab(); + + if (tab) + return getWidget(tab->getCaption()); + else + return NULL; +} + void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget) { Tab *tab = new Tab; diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 6aaafe16..29ba2f76 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -63,6 +63,11 @@ class TabbedArea : public gcn::TabbedArea */ gcn::Widget *getWidget(const std::string &name) const; + /** + * Returns the widget for the current tab + */ + gcn::Widget *getCurrentWidget(); + using gcn::TabbedArea::addTab; /** diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp new file mode 100644 index 00000000..9dd02cdc --- /dev/null +++ b/src/gui/widgets/vertcontainer.cpp @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "gui/widgets/vertcontainer.h" + +VertContainer::VertContainer(int spacing): + mSpacing(spacing), + mCount(0) +{ + addWidgetListener(this); +} + +void VertContainer::add(gcn::Widget *widget) +{ + Container::add(widget); + widget->setPosition(0, mCount * mSpacing); + widget->setSize(getWidth(), mSpacing); + mCount++; + setHeight(mCount * mSpacing); +} + +void VertContainer::clear() +{ + Container::clear(); + + mCount = 0; +} + +void VertContainer::widgetResized(const gcn::Event &event) +{ + for (WidgetListIterator it = mWidgets.begin(); it != mWidgets.end(); it++) + { + (*it)->setWidth(getWidth()); + } +} diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h new file mode 100644 index 00000000..9e15e66a --- /dev/null +++ b/src/gui/widgets/vertcontainer.h @@ -0,0 +1,47 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef GUI_VERTCONTAINER_H +#define GUI_VERTCONTAINER_H + +#include "gui/widgets/container.h" + +#include <guichan/widgetlistener.hpp> + +/** + * A widget container. + * + * This container places it's contents veritcally. + */ +class VertContainer : public Container, public gcn::WidgetListener +{ + public: + VertContainer(int spacing); + virtual void add(gcn::Widget *widget); + virtual void clear(); + void widgetResized(const gcn::Event &event); + + private: + int mSpacing; + int mCount; +}; + +#endif diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 43c63cc0..5509a589 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -84,14 +84,14 @@ bool WhisperTab::handleCommand(const std::string &type, else if (args == "ignore") { chatLog(_("Command: /ignore")); - chatLog(_("This command ignores the other player reguardless of " + chatLog(_("This command ignores the other player regardless of " "current relations.")); } else if (args == "unignore") { chatLog(_("Command: /unignore <player>")); chatLog(_("This command stops ignoring the other player if they " - "are being ignored")); + "are being ignored.")); } else return false; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 19d80671..1ee84a6f 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -306,6 +306,10 @@ void Window::setVisible(bool visible) void Window::setVisible(bool visible, bool forceSticky) { + // Check if the window is off screen... + if (visible) + checkIfIsOffScreen(); + gcn::Window::setVisible((!forceSticky && isSticky()) || visible); } @@ -526,6 +530,9 @@ void Window::loadWindowState() { setSize(mDefaultWidth, mDefaultHeight); } + + // Check if the window is off screen... + checkIfIsOffScreen(); } void Window::saveWindowState() @@ -739,3 +746,63 @@ void Window::center() { setLocationRelativeTo(getParent()); } + +void Window::checkIfIsOffScreen(bool partially, bool entirely) +{ + // Move the window onto screen if it has become off screen + // For instance, because of resolution change... + + // First of all, don't deal when a window hasn't got + // any size initialized yet... + if (getWidth() == 0 && getHeight() == 0) + return; + + // Made partially the default behaviour + if (!partially && !entirely) + partially = true; + + // Keep guichan window inside screen (supports resizing any side) + + gcn::Rectangle winDimension = getDimension(); + + if (winDimension.x < 0) + { + winDimension.width += winDimension.x; + winDimension.x = 0; + } + if (winDimension.y < 0) + { + winDimension.height += winDimension.y; + winDimension.y = 0; + } + + // Look if the window is partially off-screen limits... + if (partially) + { + if (winDimension.x + winDimension.width > graphics->getWidth()) + { + winDimension.x = graphics->getWidth() - winDimension.width; + } + + if (winDimension.y + winDimension.height > graphics->getHeight()) + { + winDimension.y = graphics->getHeight() - winDimension.height; + } + setDimension(winDimension); + return; + } + + if (entirely) + { + if (winDimension.x > graphics->getWidth()) + { + winDimension.x = graphics->getWidth() - winDimension.width; + } + + if (winDimension.y > graphics->getHeight()) + { + winDimension.y = graphics->getHeight() - winDimension.height; + } + } + setDimension(winDimension); +} diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 153602ba..b3ef3fdc 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -269,7 +269,7 @@ class Window : public gcn::Window, gcn::WidgetListener int defaultWidth, int defaultHeight); /** - * Set the default win pos and size tot he current ones. + * Set the default win pos and size to the current ones. */ void setDefaultSize(); @@ -347,6 +347,13 @@ class Window : public gcn::Window, gcn::WidgetListener }; /** + * Check if the window is off-screen and then move it to be visible + * again. This is internally used by loadWindowState + * and setVisible(true) members. + */ + void checkIfIsOffScreen(bool partially = true, bool entirely = true); + + /** * Determines if the mouse is in a resize area and returns appropriate * resize handles. Also initializes drag offset in case the resize * grip is used. diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 8964f072..96776617 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -62,7 +62,7 @@ WindowMenu::WindowMenu(): #ifdef TMWSERV_SUPPORT N_("Magic"), N_("Guilds"), - N_("Buddys"), + N_("Buddies"), #endif N_("Shortcut"), N_("Setup"), @@ -138,7 +138,7 @@ void WindowMenu::action(const gcn::ActionEvent &event) { window = guildWindow; } - else if (event.getId() == "Buddys") + else if (event.getId() == "Buddies") { window = buddyWindow; } |