diff options
Diffstat (limited to 'src/gui')
54 files changed, 940 insertions, 934 deletions
diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 95b181ad..a2c9dd9b 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -31,6 +31,7 @@ #include <guichan/mouselistener.hpp> #include "../guichanfwd.h" +#include "../main.h" class LinkHandler; diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp index e4a96b67..145f0ad2 100644 --- a/src/gui/buddywindow.cpp +++ b/src/gui/buddywindow.cpp @@ -61,7 +61,7 @@ BuddyWindow::BuddyWindow(): add(cancel); } -void BuddyWindow::action(const std::string& eventId, gcn::Widget* widget) +void BuddyWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Talk") { int selected = mListbox->getSelected(); diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 0bf4c56d..73f696b7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -26,28 +26,27 @@ #include <guichan/widgets/label.hpp> #include "button.h" +#include "listbox.h" #include "scrollarea.h" #include "shop.h" #include "slider.h" #include "../npc.h" +#include "../resources/iteminfo.h" #include "../resources/itemmanager.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../utils/tostring.h" -BuyDialog::BuyDialog(Network *network): - Window("Buy"), mNetwork(network), +BuyDialog::BuyDialog(): + Window("Buy"), mMoney(0), mAmountItems(0), mMaxItems(0) { mShopItems = new ShopItems; - mShopItemList = new ShopListBox(mShopItems, mShopItems); - mScrollArea = new ScrollArea(mShopItemList); + mItemList = new ListBox(mShopItems); + mScrollArea = new ScrollArea(mItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP"); @@ -61,7 +60,7 @@ BuyDialog::BuyDialog(Network *network): setContentSize(260, 210); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); - mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); + mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10)); mSlider->setEnabled(false); @@ -85,11 +84,11 @@ BuyDialog::BuyDialog(Network *network): mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14)); mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14)); - mShopItemList->setEventId("item"); + mItemList->setEventId("item"); mSlider->setEventId("slider"); - mShopItemList->addActionListener(this); - mShopItemList->addSelectionListener(this); + mItemList->addActionListener(this); + mItemList->addSelectionListener(this); mSlider->addActionListener(this); add(mScrollArea); @@ -114,7 +113,6 @@ BuyDialog::~BuyDialog() void BuyDialog::setMoney(int amount) { mMoney = amount; - mShopItemList->setPlayersMoney(amount); mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); } @@ -127,7 +125,7 @@ void BuyDialog::reset() mAmountItems = 0; // Reset Previous Selected Items to prevent failing asserts - mShopItemList->setSelected(-1); + mItemList->setSelected(-1); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mQuantityLabel->setCaption("0"); @@ -140,13 +138,20 @@ void BuyDialog::reset() void BuyDialog::addItem(short id, int price) { - mShopItems->addItem(id, price); - mShopItemList->adjustSize(); + ITEM_SHOP item_shop; + + item_shop.name = itemDb->getItemInfo(id).getName() + " " + + toString(price) + " GP"; + item_shop.price = price; + item_shop.id = id; + + mShopItems->push_back(item_shop); + mItemList->adjustSize(); } -void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) +void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { - int selectedItem = mShopItemList->getSelected(); + int selectedItem = mItemList->getSelected(); if (eventId == "item") { @@ -164,7 +169,7 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) // If no item was selected, none can be bought, otherwise // calculate how many the player can afford - mMaxItems = (mShopItemList->getSelected() == -1) ? 0 : + mMaxItems = (mItemList->getSelected() == -1) ? 0 : mMoney / mShopItems->at(selectedItem).price; // When at least one item can be bought, enable the slider and the @@ -179,7 +184,7 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->getNumberOfElements())) + if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) { return; } @@ -219,11 +224,13 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) else if (eventId == "buy" && (mAmountItems > 0 && mAmountItems <= mMaxItems)) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mAmountItems); - outMsg.writeInt16(mShopItems->at(selectedItem).id); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_NPC_BUY_REQUEST); + outMsg.writeShort(8); + outMsg.writeShort(mAmountItems); + outMsg.writeShort(mShopItems->at(selectedItem).id); + */ // update money ! mMoney -= mAmountItems * mShopItems->at(selectedItem).price; @@ -262,7 +269,7 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) void BuyDialog::selectionChanged(const SelectionEvent &event) { - int selectedItem = mShopItemList->getSelected(); + int selectedItem = mItemList->getSelected(); if (selectedItem > -1) { diff --git a/src/gui/buy.h b/src/gui/buy.h index 2af6cfe8..f5c163e1 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -28,11 +28,9 @@ #include "window.h" #include "selectionlistener.h" -#include "shoplistbox.h" #include "../guichanfwd.h" -class Network; class ShopItems; class ListBox; @@ -49,7 +47,7 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener * * @see Window::Window */ - BuyDialog(Network *network); + BuyDialog(); /** * Destructor @@ -94,12 +92,11 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener std::string getElementAt(int i); private: - Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; - ShopListBox *mShopItemList; + ListBox *mItemList; gcn::ScrollArea *mScrollArea; gcn::Label *mItemDescLabel; gcn::Label *mItemEffectLabel; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index e2e0e686..4bbbb2ff 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -52,7 +52,7 @@ BuySellDialog::BuySellDialog(): requestFocus(); } -void BuySellDialog::action(const std::string& eventId, gcn::Widget* widget) +void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Buy") { current_npc->buy(); diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index fa4c0241..d825db31 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -37,7 +37,7 @@ #include "../localplayer.h" #include "../main.h" -#include "../net/messageout.h" +#include "../net/accountserver/account.h" #include "../utils/tostring.h" @@ -48,7 +48,7 @@ class CharDeleteConfirm : public ConfirmDialog { public: CharDeleteConfirm(CharSelectDialog *master); - void action(const std::string& eventId, gcn::Widget* widget); + void action(const std::string &eventId, gcn::Widget *widget); private: CharSelectDialog *master; }; @@ -60,7 +60,7 @@ CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): { } -void CharDeleteConfirm::action(const std::string& eventId, gcn::Widget* widget) +void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) { //ConfirmDialog::action(eventId); if (eventId == "yes") { @@ -69,11 +69,9 @@ void CharDeleteConfirm::action(const std::string& eventId, gcn::Widget* widget) ConfirmDialog::action(eventId, widget); } -CharSelectDialog::CharSelectDialog(Network *network, - LockedArray<LocalPlayer*> *charInfo, - unsigned char sex): - Window("Select Character"), mNetwork(network), - mCharInfo(charInfo), mSex(sex), mCharSelected(false) +CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo): + Window("Select Character"), + mCharInfo(charInfo), mCharSelected(false) { mSelectButton = new Button("Ok", "ok", this); mCancelButton = new Button("Cancel", "cancel", this); @@ -84,9 +82,8 @@ CharSelectDialog::CharSelectDialog(Network *network, mNameLabel = new gcn::Label("Name"); mLevelLabel = new gcn::Label("Level"); - mJobLevelLabel = new gcn::Label("Job Level"); mMoneyLabel = new gcn::Label("Money"); - mPlayerBox = new PlayerBox(sex); + mPlayerBox = new PlayerBox(0); int w = 195; int h = 220; @@ -94,7 +91,6 @@ CharSelectDialog::CharSelectDialog(Network *network, mPlayerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90)); mNameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16)); mLevelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16)); - mJobLevelLabel->setDimension(gcn::Rectangle(10, 132, 128, 16)); mMoneyLabel->setDimension(gcn::Rectangle(10, 148, 128, 16)); mPreviousButton->setPosition(5, 170); mNextButton->setPosition(mPreviousButton->getWidth() + 10, 170); @@ -118,7 +114,6 @@ CharSelectDialog::CharSelectDialog(Network *network, add(mNextButton); add(mNameLabel); add(mLevelLabel); - add(mJobLevelLabel); add(mMoneyLabel); mSelectButton->requestFocus(); @@ -126,7 +121,7 @@ CharSelectDialog::CharSelectDialog(Network *network, updatePlayerInfo(); } -void CharSelectDialog::action(const std::string& eventId, gcn::Widget* widget) +void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok" && n_character > 0) { @@ -137,11 +132,12 @@ void CharSelectDialog::action(const std::string& eventId, gcn::Widget* widget) mPreviousButton->setEnabled(false); mNextButton->setEnabled(false); mCharSelected = true; - attemptCharSelect(); + Net::AccountServer::Account::selectCharacter(mCharInfo->getPos()); + mCharInfo->lock(); } else if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_EXIT; } else if (eventId == "new") { @@ -149,7 +145,7 @@ void CharSelectDialog::action(const std::string& eventId, gcn::Widget* widget) { // Start new character dialog mCharInfo->lock(); - new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mSex); + new CharCreateDialog(this, mCharInfo->getPos()); mCharInfo->unlock(); } } @@ -178,21 +174,20 @@ void CharSelectDialog::updatePlayerInfo() if (pi) { mNameLabel->setCaption(pi->getName()); mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel)); - mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel)); - mMoneyLabel->setCaption("Gold: " + toString(pi->mGp)); + mMoneyLabel->setCaption("Money: " + toString(pi->mMoney)); if (!mCharSelected) { mNewCharButton->setEnabled(false); mDelCharButton->setEnabled(true); mSelectButton->setEnabled(true); } - mPlayerBox->mHairStyle = pi->getHairStyle() - 1; - mPlayerBox->mHairColor = pi->getHairColor() - 1; + mPlayerBox->mHairStyle = pi->getHairStyle(); + mPlayerBox->mHairColor = pi->getHairColor(); + mPlayerBox->mSex = pi->getSex(); mPlayerBox->mShowPlayer = true; } else { mNameLabel->setCaption("Name"); mLevelLabel->setCaption("Level"); - mJobLevelLabel->setCaption("Job Level"); mMoneyLabel->setCaption("Money"); mNewCharButton->setEnabled(true); mDelCharButton->setEnabled(false); @@ -206,20 +201,7 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { - // Request character deletion - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0068); - outMsg.writeInt32(mCharInfo->getEntry()->mCharId); - outMsg.writeString("a@a.com", 40); - mCharInfo->lock(); -} - -void CharSelectDialog::attemptCharSelect() -{ - // Request character selection - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0066); - outMsg.writeInt8(mCharInfo->getPos()); + Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos()); mCharInfo->lock(); } @@ -255,9 +237,8 @@ std::string CharSelectDialog::getName() return mNameLabel->getCaption(); } -CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char sex): - Window("Create Character", true, parent), mNetwork(network), mSlot(slot) +CharCreateDialog::CharCreateDialog(Window *parent, int slot): + Window("Create Character", true, parent), mSlot(slot) { mNameField = new TextField(""); mNameLabel = new gcn::Label("Name:"); @@ -269,7 +250,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, mHairStyleLabel = new gcn::Label("Hair Style:"); mCreateButton = new Button("Create", "create", this); mCancelButton = new Button("Cancel", "cancel", this); - mPlayerBox = new PlayerBox(sex); + mPlayerBox = new PlayerBox(0); mPlayerBox->mShowPlayer = true; mNameField->setEventId("create"); @@ -311,13 +292,21 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, setLocationRelativeTo(getParent()); } -void CharCreateDialog::action(const std::string& eventId, gcn::Widget* widget) +void CharCreateDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "create") { if (getName().length() >= 4) { // Attempt to create the character mCreateButton->setEnabled(false); - attemptCharCreate(); + Net::AccountServer::Account::createCharacter( + getName(), mPlayerBox->mHairStyle, mPlayerBox->mHairColor, + 0, // gender + 10, // STR + 10, // AGI + 10, // VIT + 10, // INT + 10, // DEX + 10); // LUK scheduleDelete(); } else { @@ -349,20 +338,3 @@ std::string CharCreateDialog::getName() { return mNameField->getText(); } - -void CharCreateDialog::attemptCharCreate() -{ - // Send character infos - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0067); - outMsg.writeString(getName(), 24); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(mSlot); - outMsg.writeInt16(mPlayerBox->mHairColor + 1); - outMsg.writeInt16(mPlayerBox->mHairStyle + 1); -} diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 0a1b5eac..6d9d1a83 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -32,7 +32,6 @@ #include <guichan/actionlistener.hpp> class LocalPlayer; -class Network; class PlayerBox; /** @@ -47,9 +46,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharSelectDialog(Network *network, - LockedArray<LocalPlayer*> *charInfo, - unsigned char sex); + CharSelectDialog(LockedArray<LocalPlayer*> *charInfo); void action(const std::string& eventId, gcn::Widget* widget); @@ -65,7 +62,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener std::string getName(); private: - Network *mNetwork; LockedArray<LocalPlayer*> *mCharInfo; gcn::Button *mSelectButton; @@ -77,12 +73,10 @@ class CharSelectDialog : public Window, public gcn::ActionListener gcn::Label *mNameLabel; gcn::Label *mLevelLabel; - gcn::Label *mJobLevelLabel; gcn::Label *mMoneyLabel; PlayerBox *mPlayerBox; - unsigned char mSex; bool mCharSelected; /** @@ -107,15 +101,13 @@ class CharCreateDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char sex); + CharCreateDialog(Window *parent, int slot); void action(const std::string& eventId, gcn::Widget* widget); std::string getName(); private: - Network *mNetwork; gcn::TextField *mNameField; gcn::Label *mNameLabel; gcn::Button *mNextHairColorButton; diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp deleted file mode 100644 index 87ed9c17..00000000 --- a/src/gui/char_server.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World 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. - * - * The Mana World 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 The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "char_server.h" - -#include "button.h" -#include "listbox.h" -#include "scrollarea.h" - -#include "../logindata.h" -#include "../main.h" -#include "../serverinfo.h" - -#include "../net/network.h" // TODO this is just for iptostring, move that? - -#include "../utils/tostring.h" - -extern SERVER_INFO **server_info; - -/** - * The list model for the server list. - */ -class ServerListModel : public gcn::ListModel { - public: - virtual ~ServerListModel() {}; - - int getNumberOfElements(); - std::string getElementAt(int i); -}; - -ServerSelectDialog::ServerSelectDialog(LoginData *loginData): - Window("Select Server"), mLoginData(loginData) -{ - mServerListModel = new ServerListModel(); - mServerList = new ListBox(mServerListModel); - ScrollArea *mScrollArea = new ScrollArea(mServerList); - mOkButton = new Button("OK", "ok", this); - Button *mCancelButton = new Button("Cancel", "cancel", this); - - setContentSize(200, 100); - - mCancelButton->setPosition( - 200 - mCancelButton->getWidth() - 5, - 100 - mCancelButton->getHeight() - 5); - mOkButton->setPosition( - mCancelButton->getX() - mOkButton->getWidth() - 5, - 100 - mOkButton->getHeight() - 5); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mScrollArea->setDimension(gcn::Rectangle( - 5, 5, 200 - 2 * 5, - 100 - 3 * 5 - mCancelButton->getHeight() - - mScrollArea->getBorderSize())); - - mServerList->setEventId("ok"); - - //mServerList->addActionListener(this); - - add(mScrollArea); - add(mOkButton); - add(mCancelButton); - - if (n_server == 0) { - // Disable Ok button - mOkButton->setEnabled(false); - } else { - // Select first server - mServerList->setSelected(1); - } - - mOkButton->requestFocus(); - setLocationRelativeTo(getParent()); -} - -ServerSelectDialog::~ServerSelectDialog() -{ - delete mServerListModel; -} - -void -ServerSelectDialog::action(const std::string& eventId, gcn::Widget* widget) -{ - if (eventId == "ok") { - mOkButton->setEnabled(false); - const SERVER_INFO *si = server_info[mServerList->getSelected()]; - mLoginData->hostname = iptostring(si->address); - mLoginData->port = si->port; - state = CHAR_CONNECT_STATE; - } - else if (eventId == "cancel") { - state = LOGIN_STATE; - } -} - -int -ServerListModel::getNumberOfElements() -{ - return n_server; -} - -std::string -ServerListModel::getElementAt(int i) -{ - const SERVER_INFO *si = server_info[i]; - return si->name + " (" + toString(si->online_users) + ")"; -} diff --git a/src/gui/char_server.h b/src/gui/char_server.h deleted file mode 100644 index 3dd66566..00000000 --- a/src/gui/char_server.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World 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. - * - * The Mana World 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 The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _CHAR_SEL_SERVER_H -#define _CHAR_SEL_SERVER_H - -#include <guichan/actionlistener.hpp> -#include <guichan/listmodel.hpp> - -#include "window.h" - -#include "../guichanfwd.h" - -class LoginData; -class ServerListModel; - -/** - * The server select dialog. - * - * \ingroup Interface - */ -class ServerSelectDialog : public Window, public gcn::ActionListener { - public: - /** - * Constructor - * - * @see Window::Window - */ - ServerSelectDialog(LoginData *loginData); - - /** - * Destructor. - */ - ~ServerSelectDialog(); - - /** - * Called when receiving actions from the widgets. - */ - void action(const std::string& eventId, gcn::Widget* widget); - - private: - LoginData *mLoginData; - ServerListModel *mServerListModel; - gcn::ListBox *mServerList; - gcn::Button *mOkButton; -}; - -#endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index f188b90e..3dc252ab 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -36,12 +36,12 @@ #include "../game.h" #include "../localplayer.h" -#include "../net/messageout.h" -#include "../net/protocol.h" +#include "../net/chatserver/chatserver.h" -ChatWindow::ChatWindow(Network *network): +#include "../net/gameserver/player.h" + +ChatWindow::ChatWindow(): Window(""), - mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); @@ -180,7 +180,7 @@ ChatWindow::chatLog(CHATSKILL act) } void -ChatWindow::action(const std::string& eventId, gcn::Widget* widget) +ChatWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "chatinput") { @@ -249,20 +249,12 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) // Prepare ordinary message if (msg.substr(0, 1) != "/") { - msg = nick + " : " + msg; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_CHAT_MESSAGE); - outMsg.writeInt16(msg.length() + 4); - outMsg.writeString(msg, msg.length()); + Net::GameServer::Player::say(msg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0099); - outMsg.writeInt16(msg.length() + 4); - outMsg.writeString(msg, msg.length()); + Net::ChatServer::announce(msg); } else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) { @@ -278,8 +270,10 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00c1); + // XXX Convert for new server + /* + MessageOut outMsg(0x00c1); + */ } else { diff --git a/src/gui/chat.h b/src/gui/chat.h index 20841873..a0a3d1ec 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -35,7 +35,6 @@ #include "../guichanfwd.h" class BrowserBox; -class Network; class ScrollArea; #define BY_GM 0 // those should be self-explanatory =) @@ -116,7 +115,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(Network *network); + ChatWindow(); /** * Logic (updates components' size) @@ -188,7 +187,6 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); private: - Network *mNetwork; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 3bd15589..ed2f8680 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -64,7 +64,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, yesButton->requestFocus(); } -void ConfirmDialog::action(const std::string& eventId, gcn::Widget* widget) +void ConfirmDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index 8da36f20..1e0034fb 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -35,16 +35,25 @@ namespace { struct ConnectionActionListener : public gcn::ActionListener { - void action(const std::string& eventId, gcn::Widget* widget) { state = EXIT_STATE; } - } listener; + ConnectionActionListener(unsigned char previousState): + mPreviousState(previousState) {}; + + void action(const std::string &eventId, gcn::Widget *widget) { + state = mPreviousState; + } + + unsigned char mPreviousState; + }; } -ConnectionDialog::ConnectionDialog(): +ConnectionDialog::ConnectionDialog(unsigned char previousState): Window("Info"), mProgress(0) { setContentSize(200, 100); - Button *cancelButton = new Button("Cancel", "cancelButton", &listener); + ConnectionActionListener *connectionListener = new ConnectionActionListener(previousState); + + Button *cancelButton = new Button("Cancel", "cancelButton", connectionListener); mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128); gcn::Label *label = new gcn::Label("Connecting..."); diff --git a/src/gui/connection.h b/src/gui/connection.h index 7a072d2e..4b3187f6 100644 --- a/src/gui/connection.h +++ b/src/gui/connection.h @@ -41,7 +41,7 @@ class ConnectionDialog : public Window * * @see Window::Window */ - ConnectionDialog(); + ConnectionDialog(unsigned char previousState); void logic(); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 2f788d05..d467d4d3 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -98,7 +98,7 @@ DebugWindow::logic() } void -DebugWindow::action(const std::string& eventId, gcn::Widget* widget) +DebugWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index b7f64274..38b17781 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -55,6 +55,9 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../resources/sdlimageloader.h" +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif // Guichan stuff Gui *gui; @@ -233,7 +236,7 @@ Gui::mousePress(int mx, int my, int button) // Mouse pressed on window container (basically, the map) // Are we in-game yet? - if (state != GAME_STATE) + if (state != STATE_GAME) return; // Check if we are alive and kickin' @@ -244,8 +247,8 @@ Gui::mousePress(int mx, int my, int button) if (current_npc) return; - int tilex = mx / 32 + camera_x; - int tiley = my / 32 + camera_y; + int tilex = (mx + camera_x) / 32; + int tiley = (my + camera_y) / 32; // Right click might open a popup if (button == gcn::MouseInput::RIGHT) @@ -307,13 +310,14 @@ Gui::mousePress(int mx, int my, int button) player_node->pickUp(item); } // Just walk around - else if (engine->getCurrentMap()->getWalk(tilex, tiley)) + else if (engine->getCurrentMap() && + engine->getCurrentMap()->getWalk(tilex, tiley)) { // XXX XXX XXX REALLY UGLY! Uint8 *keys = SDL_GetKeyState(NULL); if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) { - player_node->setDestination(tilex, tiley); + player_node->setDestination(mx + camera_x, my + camera_y); player_node->stopAttack(); } } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 2b9b649a..e7429b29 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -54,7 +54,7 @@ HelpWindow::HelpWindow(): setLocationRelativeTo(getParent()); } -void HelpWindow::action(const std::string& eventId, gcn::Widget* widget) +void HelpWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index eb85220b..452b7c16 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -98,7 +98,7 @@ void InventoryWindow::logic() mWeightLabel->adjustSize(); } -void InventoryWindow::action(const std::string& eventId, gcn::Widget* widget) +void InventoryWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = mItems->getItem(); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 3f8daddd..30c899a8 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -94,7 +94,7 @@ void ItemAmountWindow::resetAmount() mItemAmountTextBox->setInt(1); } -void ItemAmountWindow::action(const std::string& eventId, gcn::Widget* widget) +void ItemAmountWindow::action(const std::string &eventId, gcn::Widget *widget) { int amount = mItemAmountTextBox->getInt(); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 675de078..1d9b6e1e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -43,7 +43,7 @@ WrongDataNoticeListener::setTarget(gcn::TextField *textField) } void -WrongDataNoticeListener::action(const std::string& eventId, gcn::Widget* widget) +WrongDataNoticeListener::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { @@ -59,53 +59,43 @@ LoginDialog::LoginDialog(LoginData *loginData): { gcn::Label *userLabel = new gcn::Label("Name:"); gcn::Label *passLabel = new gcn::Label("Password:"); - gcn::Label *serverLabel = new gcn::Label("Server:"); mUserField = new TextField(mLoginData->username); mPassField = new PasswordField(mLoginData->password); - mServerField = new TextField(mLoginData->hostname); mKeepCheck = new CheckBox("Keep", mLoginData->remember); mOkButton = new Button("OK", "ok", this); mCancelButton = new Button("Cancel", "cancel", this); mRegisterButton = new Button("Register", "register", this); - setContentSize(200, 100); + setContentSize(200, 91); userLabel->setPosition(5, 5); passLabel->setPosition(5, 14 + userLabel->getHeight()); - serverLabel->setPosition( - 5, 23 + userLabel->getHeight() + passLabel->getHeight()); mUserField->setPosition(65, 5); mPassField->setPosition(65, 14 + userLabel->getHeight()); - mServerField->setPosition( - 65, 23 + userLabel->getHeight() + passLabel->getHeight()); mUserField->setWidth(130); mPassField->setWidth(130); - mServerField->setWidth(130); - mKeepCheck->setPosition(4, 77); + mKeepCheck->setPosition(4, 68); mCancelButton->setPosition( 200 - mCancelButton->getWidth() - 5, - 100 - mCancelButton->getHeight() - 5); + 91 - mCancelButton->getHeight() - 5); mOkButton->setPosition( mCancelButton->getX() - mOkButton->getWidth() - 5, - 100 - mOkButton->getHeight() - 5); - mRegisterButton->setPosition(mKeepCheck->getX() + mKeepCheck->getWidth() + 10, - 100 - mRegisterButton->getHeight() - 5); + 91 - mOkButton->getHeight() - 5); + mRegisterButton->setPosition( + mKeepCheck->getX() + mKeepCheck->getWidth() + 10, + 91 - mRegisterButton->getHeight() - 5); mUserField->setEventId("ok"); mPassField->setEventId("ok"); - mServerField->setEventId("ok"); mUserField->addActionListener(this); mPassField->addActionListener(this); - mServerField->addActionListener(this); mKeepCheck->addActionListener(this); add(userLabel); add(passLabel); - add(serverLabel); add(mUserField); add(mPassField); - add(mServerField); add(mKeepCheck); add(mOkButton); add(mCancelButton); @@ -128,7 +118,7 @@ LoginDialog::~LoginDialog() } void -LoginDialog::action(const std::string& eventId, gcn::Widget* widget) +LoginDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { @@ -141,24 +131,22 @@ LoginDialog::action(const std::string& eventId, gcn::Widget* widget) } else { - mLoginData->hostname = mServerField->getText(); mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); mLoginData->remember = mKeepCheck->isMarked(); mOkButton->setEnabled(false); - //mCancelButton->setEnabled(false); mRegisterButton->setEnabled(false); - state = ACCOUNT_STATE; + state = STATE_LOGIN_ATTEMPT; } } else if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_EXIT; } else if (eventId == "register") { - state = REGISTER_STATE; + state = STATE_REGISTER; } } diff --git a/src/gui/login.h b/src/gui/login.h index 7218dca8..6d510da7 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -70,7 +70,6 @@ class LoginDialog : public Window, public gcn::ActionListener { private: gcn::TextField *mUserField; gcn::TextField *mPassField; - gcn::TextField *mServerField; gcn::CheckBox *mKeepCheck; gcn::Button *mOkButton; gcn::Button *mCancelButton; diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 701d9366..a1b342f0 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -39,7 +39,7 @@ namespace { /** * Called when receiving actions from widget. */ - void action(const std::string& eventId, gcn::Widget* widget); + void action(const std::string &eventId, gcn::Widget *widget); } listener; } @@ -75,7 +75,7 @@ void MenuWindow::draw(gcn::Graphics *graphics) } -void MenuWindowListener::action(const std::string& eventId, gcn::Widget* widget) +void MenuWindowListener::action(const std::string &eventId, gcn::Widget *widget) { Window *window = NULL; if (eventId == "Status") diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index 59cdd9db..7f5de543 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -121,7 +121,7 @@ NewSkillDialog::NewSkillDialog(): setLocationRelativeTo(getParent()); } -void NewSkillDialog::action(const std::string& eventId, gcn::Widget* widget) +void NewSkillDialog::action(const std::string &eventId, gcn::Widget *widget) { int osp = startPoint; if (eventId == "close") diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 6b647032..5b7ca439 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -67,7 +67,7 @@ NpcTextDialog::addText(const std::string &text) } void -NpcTextDialog::action(const std::string& eventId, gcn::Widget* widget) +NpcTextDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 895ef1f9..d1c3ddcb 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -91,7 +91,7 @@ NpcListDialog::reset() } void -NpcListDialog::action(const std::string& eventId, gcn::Widget* widget) +NpcListDialog::action(const std::string &eventId, gcn::Widget *widget) { int choice = 0; diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index e527339e..906fd61f 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -54,7 +54,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, okButton->requestFocus(); } -void OkDialog::action(const std::string& eventId, gcn::Widget* widget) +void OkDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 0a155573..46cd7e85 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -94,13 +94,13 @@ void PlayerBox::draw(gcn::Graphics *graphics) playerset[mSex]->get(0), 23, 12); // Draw his hair - if (mHairColor >= 0 && mHairStyle >= 0 && - mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES) + if (mHairStyle > 0 && mHairColor < NR_HAIR_COLORS && + mHairStyle < NR_HAIR_STYLES) { int hf = 5 * mHairColor; if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) { dynamic_cast<Graphics*>(graphics)->drawImage( - hairset[mHairStyle]->get(hf), 35, 7); + hairset[mHairStyle - 1]->get(hf), 35, 7); } } } diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h index 79f7c2aa..ec04eaf6 100644 --- a/src/gui/playerbox.h +++ b/src/gui/playerbox.h @@ -57,10 +57,10 @@ class PlayerBox : public gcn::ScrollArea */ void drawBorder(gcn::Graphics *graphics); - int mHairColor; /**< The hair color index */ - int mHairStyle; /**< The hair style index */ - unsigned char mSex; /**< Sex */ - bool mShowPlayer; /**< Wether to show the player or not */ + unsigned char mHairColor; /**< The hair color index */ + unsigned char mHairStyle; /**< The hair style index */ + unsigned char mSex; /**< Sex */ + bool mShowPlayer; /**< Wether to show the player or not */ private: static int instances; diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 1c1f0a26..7cef62a2 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -44,24 +44,21 @@ RegisterDialog::RegisterDialog(LoginData *loginData): Window("Register"), mWrongDataNoticeListener(new WrongDataNoticeListener()), - mWrongRegisterNotice(0), mLoginData(loginData) { gcn::Label *userLabel = new gcn::Label("Name:"); gcn::Label *passwordLabel = new gcn::Label("Password:"); gcn::Label *confirmLabel = new gcn::Label("Confirm:"); - gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *emailLabel = new gcn::Label("Email:"); mUserField = new TextField("player"); mPasswordField = new PasswordField(); mConfirmField = new PasswordField(); - mServerField = new TextField(); - mMaleButton = new RadioButton("Male", "sex", true); - mFemaleButton = new RadioButton("Female", "sex", false); + mEmailField = new TextField(); mRegisterButton = new Button("Register", "register", this); mCancelButton = new Button("Cancel", "cancel", this); - int width = 200; - int height = 150; + const int width = 200; + const int height = 130; setContentSize(width, height); mUserField->setPosition(65, 5); @@ -72,55 +69,49 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mConfirmField->setPosition( 65, mPasswordField->getY() + mPasswordField->getHeight() + 7); mConfirmField->setWidth(130); - mServerField->setPosition( - 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7); - mServerField->setWidth(130); + mEmailField->setPosition( + 65, mConfirmField->getY() + mConfirmField->getHeight() + 7); + mEmailField->setWidth(130); userLabel->setPosition(5, mUserField->getY() + 1); passwordLabel->setPosition(5, mPasswordField->getY() + 1); confirmLabel->setPosition(5, mConfirmField->getY() + 1); - serverLabel->setPosition(5, mServerField->getY() + 1); + emailLabel->setPosition(5, mEmailField->getY() + 1); - mFemaleButton->setPosition(width - mFemaleButton->getWidth() - 10, - mConfirmField->getY() + mConfirmField->getHeight() + 7); - mMaleButton->setPosition(mFemaleButton->getX() - mMaleButton->getWidth() - 5, - mFemaleButton->getY()); - - mRegisterButton->setPosition(5, height - mRegisterButton->getHeight() - 5); - mCancelButton->setPosition(10 + mRegisterButton->getWidth(), - mRegisterButton->getY()); + mCancelButton->setPosition( + width - 5 - mCancelButton->getWidth(), + height - 5 - mCancelButton->getHeight()); + mRegisterButton->setPosition( + mCancelButton->getX() - 5 - mRegisterButton->getWidth(), + mCancelButton->getY()); add(userLabel); add(passwordLabel); - add(serverLabel); + add(emailLabel); add(confirmLabel); add(mUserField); add(mPasswordField); add(mConfirmField); - add(mServerField); - add(mMaleButton); - add(mFemaleButton); + add(mEmailField); add(mRegisterButton); add(mCancelButton); setLocationRelativeTo(getParent()); mUserField->requestFocus(); mUserField->setCaretPosition(mUserField->getText().length()); - - mServerField->setText(config.getValue("host", "")); } RegisterDialog::~RegisterDialog() { - delete mWrongRegisterNotice; + delete mWrongDataNoticeListener; } void -RegisterDialog::action(const std::string& eventId, gcn::Widget* widget) +RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_LOGIN; } else if (eventId == "register") { @@ -176,6 +167,8 @@ RegisterDialog::action(const std::string& eventId, gcn::Widget* widget) error = 2; } + // TODO: Check if a valid email address was given + if (error > 0) { if (error == 1) @@ -189,22 +182,20 @@ RegisterDialog::action(const std::string& eventId, gcn::Widget* widget) mConfirmField->setText(""); } - delete mWrongRegisterNotice; - mWrongRegisterNotice = new OkDialog("Error", errorMsg.str()); - mWrongRegisterNotice->addActionListener(mWrongDataNoticeListener); + OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + dlg->addActionListener(mWrongDataNoticeListener); } else { // No errors detected, register the new user. mRegisterButton->setEnabled(false); - mLoginData->hostname = config.getValue("host", "animesites.de"); mLoginData->port = (short)config.getValue("port", 0); mLoginData->username = mUserField->getText(); mLoginData->password = mPasswordField->getText(); - mLoginData->username += mFemaleButton->isMarked() ? "_F" : "_M"; + mLoginData->email = mEmailField->getText(); - state = ACCOUNT_STATE; + state = STATE_REGISTER_ATTEMPT; } } } diff --git a/src/gui/register.h b/src/gui/register.h index 5d3f6cd5..4c98788f 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -65,15 +65,12 @@ class RegisterDialog : public Window, public gcn::ActionListener { gcn::TextField *mUserField; gcn::TextField *mPasswordField; gcn::TextField *mConfirmField; - gcn::TextField *mServerField; + gcn::TextField *mEmailField; gcn::Button *mRegisterButton; gcn::Button *mCancelButton; - gcn::RadioButton *mMaleButton; - gcn::RadioButton *mFemaleButton; WrongDataNoticeListener *mWrongDataNoticeListener; - OkDialog *mWrongRegisterNotice; LoginData *mLoginData; }; diff --git a/src/gui/selectionlistener.h b/src/gui/selectionlistener.h index b39672b5..a2fc6533 100644 --- a/src/gui/selectionlistener.h +++ b/src/gui/selectionlistener.h @@ -18,7 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id$ + * $Id: selectionlistener.h 2651 2006-09-03 16:47:48Z b_lindeijer $ */ #ifndef _TMW_SELECTIONLISTENER_H__ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 7f50c1e4..9c25aced 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -28,7 +28,7 @@ #include <guichan/widgets/label.hpp> #include "button.h" -#include "shoplistbox.h" +#include "listbox.h" #include "scrollarea.h" #include "shop.h" #include "slider.h" @@ -39,23 +39,19 @@ #include "../resources/iteminfo.h" #include "../resources/itemmanager.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../utils/tostring.h" -SellDialog::SellDialog(Network *network): +SellDialog::SellDialog(): Window("Sell"), - mNetwork(network), mMaxItems(0), mAmountItems(0) { mShopItems = new ShopItems(); - mShopItemList = new ShopListBox(mShopItems, mShopItems); - ScrollArea *scrollArea = new ScrollArea(mShopItemList); + mItemList = new ListBox(mShopItems); + ScrollArea *scrollArea = new ScrollArea(mItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label("Money: 0 GP / Total: 0 GP"); + mMoneyLabel = new gcn::Label("Price: 0"); mItemDescLabel = new gcn::Label("Description:"); mItemEffectLabel = new gcn::Label("Effect:"); mIncreaseButton = new Button("+", "+", this); @@ -67,7 +63,7 @@ SellDialog::SellDialog(Network *network): setContentSize(260, 210); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); - mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); + mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10)); mSlider->setEnabled(false); @@ -91,13 +87,11 @@ SellDialog::SellDialog(Network *network): quitButton->setPosition(208, 186); - mShopItemList->setEventId("item"); + mItemList->setEventId("item"); mSlider->setEventId("mSlider"); - mShopItemList->setPriceCheck(false); - - mShopItemList->addActionListener(this); - mShopItemList->addSelectionListener(this); + mItemList->addActionListener(this); + mItemList->addSelectionListener(this); mSlider->addActionListener(this); add(scrollArea); @@ -127,14 +121,13 @@ void SellDialog::reset() mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0"); mMoneyLabel->adjustSize(); mItemDescLabel->setCaption(""); mItemEffectLabel->setCaption(""); // Reset Previous Selected Items to prevent failing asserts - mShopItemList->setSelected(-1); + mItemList->setSelected(-1); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); } @@ -151,15 +144,14 @@ void SellDialog::addItem(Item *item, int price) item_shop.index = item->getInvIndex(); item_shop.id = item->getId(); item_shop.quantity = item->getQuantity(); - item_shop.image = item->getInfo().getImage(); mShopItems->push_back(item_shop); - mShopItemList->adjustSize(); + mItemList->adjustSize(); } -void SellDialog::action(const std::string& eventId, gcn::Widget* widget) +void SellDialog::action(const std::string &eventId, gcn::Widget *widget) { - int selectedItem = mShopItemList->getSelected(); + int selectedItem = mItemList->getSelected(); if (eventId == "item") { @@ -168,22 +160,19 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget) mDecreaseButton->setEnabled(false); mSellButton->setEnabled(false); + mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Money: 0 GP / Total: " - + toString(mPlayerMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0"); mMoneyLabel->adjustSize(); if (selectedItem > -1) { mSlider->setEnabled(true); mIncreaseButton->setEnabled(true); mMaxItems = mShopItems->at(selectedItem).quantity; - mQuantityLabel->setCaption("0 / " + toString(mMaxItems)); } else { mSlider->setEnabled(false); mIncreaseButton->setEnabled(false); - mQuantityLabel->setCaption("0"); } - mQuantityLabel->adjustSize(); } else if (eventId == "quit") { @@ -192,7 +181,7 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget) } // The following actions require a valid item selection - if (selectedItem == -1 || selectedItem >= int(mShopItems->getNumberOfElements())) { + if (selectedItem == -1 || selectedItem >= int(mShopItems->size())) { return; } @@ -226,23 +215,23 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget) // Attempt sell assert(mAmountItems > 0 && mAmountItems <= mMaxItems); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mShopItems->at(selectedItem).index); - outMsg.writeInt16(mAmountItems); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_NPC_SELL_REQUEST); + outMsg.writeShort(8); + outMsg.writeShort(mShopItems->at(selectedItem).index); + outMsg.writeShort(mAmountItems); + */ mMaxItems -= mAmountItems; - mShopItems->getShop()->at(selectedItem).quantity = mMaxItems; mAmountItems = 0; mSlider->setValue(0); mSlider->setEnabled(mMaxItems != 0); // All were sold if (!mMaxItems) { - - mShopItemList->setSelected(-1); - mShopItems->getShop()->erase(mShopItems->getShop()->begin() + selectedItem); + mItemList->setSelected(-1); + mShopItems->erase(mShopItems->begin() + selectedItem); } // Update only when there are items left, the entry doesn't exist @@ -254,12 +243,11 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget) if (updateButtonsAndLabels) { // Update labels - mQuantityLabel->setCaption(toString(mAmountItems) + " / " + toString(mMaxItems)); + mQuantityLabel->setCaption(toString(mAmountItems)); mQuantityLabel->adjustSize(); int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Money: " + toString(price) + " GP / Total: " - + toString(price + mPlayerMoney) + " GP"); + mMoneyLabel->setCaption("Price: " + toString(price)); mMoneyLabel->adjustSize(); // Update Buttons @@ -271,7 +259,7 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget) void SellDialog::selectionChanged(const SelectionEvent &event) { - int selectedItem = mShopItemList->getSelected(); + int selectedItem = mItemList->getSelected(); if (selectedItem > -1) { @@ -287,9 +275,3 @@ void SellDialog::selectionChanged(const SelectionEvent &event) mItemEffectLabel->setCaption("Effect"); } } - -void SellDialog::setMoney(int amount) -{ - mPlayerMoney = amount; - mShopItemList->setPlayersMoney(amount); -} diff --git a/src/gui/sell.h b/src/gui/sell.h index f27a9751..69f8b089 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -32,9 +32,8 @@ #include "../guichanfwd.h" class Item; -class Network; class ShopItems; -class ShopListBox; +class ListBox; /** * The sell dialog. @@ -49,7 +48,7 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener * * @see Window::Window */ - SellDialog(Network *network); + SellDialog(); /** * Destructor @@ -78,17 +77,11 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener */ void selectionChanged(const SelectionEvent &event); - /** - * Gives Player's Money amount - */ - void setMoney(int amount); - private: - Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; - ShopListBox *mShopItemList; + ListBox *mItemList; gcn::Label *mMoneyLabel; gcn::Label *mItemDescLabel; gcn::Label *mItemEffectLabel; @@ -96,7 +89,6 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener gcn::Slider *mSlider; ShopItems *mShopItems; - int mPlayerMoney; int mMaxItems; int mAmountItems; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp new file mode 100644 index 00000000..39abd5ed --- /dev/null +++ b/src/gui/serverdialog.cpp @@ -0,0 +1,246 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: login.cpp 2550 2006-08-20 00:56:23Z b_lindeijer $ + */ + +#include "serverdialog.h" + +#include <iostream> +#include <string> + +#include <guichan/widgets/label.hpp> + +#include "button.h" +#include "listbox.h" +#include "ok_dialog.h" +#include "scrollarea.h" +#include "textfield.h" + +#include "../configuration.h" +#include "../log.h" +#include "../logindata.h" +#include "../main.h" + +#include "../utils/tostring.h" + +const short MAX_SERVERLIST = 5; + +void +DropDownListener::action(const std::string &eventId, gcn::Widget *widget) +{ + if (eventId == "ok") + { + // Reset the text fields and give back the server dialog. + mServerNameField->setText(""); + mServerNameField->setCaretPosition(0); + mServerPortField->setText(""); + mServerPortField->setCaretPosition(0); + + mServerNameField->requestFocus(); + } + else if (eventId == "changeSelection") + { + // Change the textField Values according to new selection + if (currentSelectedIndex != mServersListBox->getSelected()) + { + Server myServer; + myServer = mServersListModel->getServer(mServersListBox->getSelected()); + mServerNameField->setText(myServer.serverName); + mServerPortField->setText(toString(myServer.port)); + currentSelectedIndex = mServersListBox->getSelected(); + } + } +} + +int ServersListModel::getNumberOfElements() +{ + return servers.size(); +} + +std::string ServersListModel::getElementAt(int elementIndex) +{ + std::string myServer = ""; + myServer = servers.at(elementIndex).serverName; + myServer += ":"; + myServer += toString(servers.at(elementIndex).port); + return myServer; +} + +void ServersListModel::addFirstElement(Server server) +{ + // Equivalent to push_front + std::vector<Server>::iterator MyIterator = servers.begin(); + servers.insert(MyIterator, 1, server); +} + +void ServersListModel::addElement(Server server) +{ + servers.push_back(server); +} + +ServerDialog::ServerDialog(LoginData *loginData): + Window("Choose your Mana World Server"), mLoginData(loginData) +{ + gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *portLabel = new gcn::Label("Port:"); + mServerNameField = new TextField(mLoginData->hostname); + mPortField = new TextField(toString(mLoginData->port)); + + // Add the most used servers from config + mMostUsedServersListModel = new ServersListModel(); + Server currentServer; + std::string currentConfig = ""; + for (int i=0; i<=MAX_SERVERLIST; i++) + { + currentServer.serverName = ""; + currentServer.port = 0; + + currentConfig = "MostUsedServerName" + toString(i); + currentServer.serverName = config.getValue(currentConfig, ""); + + currentConfig = "MostUsedServerPort" + toString(i); + currentServer.port = (short)atoi(config.getValue(currentConfig, "").c_str()); + if (!currentServer.serverName.empty() || currentServer.port != 0) + { + mMostUsedServersListModel->addElement(currentServer); + } + } + + mMostUsedServersListBox = new ListBox(NULL); + mMostUsedServersListBox->setListModel(mMostUsedServersListModel); + mMostUsedServersScrollArea = new ScrollArea(); + mMostUsedServersDropDown = new DropDown(mMostUsedServersListModel, + mMostUsedServersScrollArea, mMostUsedServersListBox); + + mDropDownListener = new DropDownListener(mServerNameField, mPortField, + mMostUsedServersListModel, mMostUsedServersListBox); + + mOkButton = new Button("OK", "ok", this); + mCancelButton = new Button("Cancel", "cancel", this); + + setContentSize(200, 100); + + serverLabel->setPosition(10, 5); + portLabel->setPosition(10, 14 + serverLabel->getHeight()); + + mServerNameField->setPosition(60, 5); + mPortField->setPosition(60, 14 + serverLabel->getHeight()); + mServerNameField->setWidth(130); + mPortField->setWidth(130); + + mMostUsedServersDropDown->setPosition(10, 10 + + portLabel->getY() + portLabel->getHeight()); + mMostUsedServersDropDown->setWidth(180); + + mCancelButton->setPosition( + 200 - mCancelButton->getWidth() - 5, + 100 - mCancelButton->getHeight() - 5); + mOkButton->setPosition( + mCancelButton->getX() - mOkButton->getWidth() - 5, + 100 - mOkButton->getHeight() - 5); + + mServerNameField->setEventId("ok"); + mPortField->setEventId("ok"); + mMostUsedServersDropDown->setEventId("changeSelection"); + + mServerNameField->addActionListener(this); + mPortField->addActionListener(this); + mMostUsedServersDropDown->addActionListener(mDropDownListener); + + add(serverLabel); + add(portLabel); + add(mServerNameField); + add(mPortField); + add(mMostUsedServersDropDown); + add(mOkButton); + add(mCancelButton); + + setLocationRelativeTo(getParent()); + + if (mServerNameField->getText().empty()) { + mServerNameField->requestFocus(); + } else { + if (mPortField->getText().empty()) { + mPortField->requestFocus(); + } else { + mOkButton->requestFocus(); + } + } +} + +ServerDialog::~ServerDialog() +{ + delete mDropDownListener; +} + +void +ServerDialog::action(const std::string &eventId, gcn::Widget *widget) +{ + if (eventId == "ok") + { + // Check login + if (mServerNameField->getText().empty() || mPortField->getText().empty()) + { + OkDialog *dlg = new OkDialog("Error", "Enter the chosen server."); + dlg->addActionListener(mDropDownListener); + } + else + { + mLoginData->hostname = mServerNameField->getText(); + mLoginData->port = (short) atoi(mPortField->getText().c_str()); + mOkButton->setEnabled(false); + mCancelButton->setEnabled(false); + + // First, look if the entry is a new one. + Server currentServer; + bool newEntry = true; + for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++) + { + currentServer = mMostUsedServersListModel->getServer(i); + if (currentServer.serverName == mLoginData->hostname && + currentServer.port == mLoginData->port) + newEntry = false; + } + // Then, add it to config if it's really new + currentServer.serverName = mLoginData->hostname; + currentServer.port = mLoginData->port; + if (newEntry) + mMostUsedServersListModel->addFirstElement(currentServer); + // Write the entry in config + std::string currentConfig = ""; + for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++) + { + currentServer = mMostUsedServersListModel->getServer(i); + + currentConfig = "MostUsedServerName" + toString(i); + config.setValue(currentConfig, currentServer.serverName); + + currentConfig = "MostUsedServerPort" + toString(i); + config.setValue(currentConfig, toString(currentServer.port)); + } + state = STATE_CONNECT_ACCOUNT; + } + } + else if (eventId == "cancel") + { + state = STATE_EXIT; + } +} diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h new file mode 100644 index 00000000..5b265c17 --- /dev/null +++ b/src/gui/serverdialog.h @@ -0,0 +1,153 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: login.h 2486 2006-07-30 14:33:28Z b_lindeijer $ + */ + +#ifndef _TMW_SERVERDIALOG_H +#define _TMW_SERVERDIALOG_H + +#include <iosfwd> +#include <vector> + +#include <guichan/actionlistener.hpp> +#include <guichan/listmodel.hpp> +#include "./widgets/dropdown.h" + +#include "login.h" +#include "window.h" + +#include "../guichanfwd.h" + +#include "../net/network.h" + +class LoginData; + +/** + * A server structure to keep pairs of servers and ports. + */ +struct Server { + Server(): + serverName(""), + port(0) {}; + + std::string serverName; + short port; +}; + +/** + * Server and Port List Model + */ +class ServersListModel : public gcn::ListModel +{ + public: + /** + * Used to get number of line in the list + */ + int getNumberOfElements(); + /** + * Used to get an element from the list + */ + std::string getElementAt(int elementIndex); + /** + * Used to get the corresponding Server struct + */ + Server getServer(int elementIndex) { return servers[elementIndex]; }; + /** + * Add an Element at the end of the server list + */ + void addElement(Server server); + /** + * Add an Element at the beginning of the server list + */ + void addFirstElement(Server server); + + private: + std::vector<Server> servers; +}; + +/** + * Listener used for handling the DropDown in the server Dialog. + */ +class DropDownListener : public gcn::ActionListener +{ + public: + DropDownListener(gcn::TextField *serverNameField, + gcn::TextField *serverPortField, + ServersListModel *serversListModel, + gcn::ListBox *serversListBox): + currentSelectedIndex(0), + mServerNameField(serverNameField), + mServerPortField(serverPortField), + mServersListModel(serversListModel), + mServersListBox(serversListBox) {}; + void action(const std::string& eventId, + gcn::Widget* widget); + private: + short currentSelectedIndex; + gcn::TextField *mServerNameField; + gcn::TextField *mServerPortField; + ServersListModel *mServersListModel; + gcn::ListBox *mServersListBox; +}; + + +/** + * The server choice dialog. + * + * \ingroup Interface + */ +class ServerDialog : public Window, public gcn::ActionListener +{ + public: + /** + * Constructor + * + * @see Window::Window + */ + ServerDialog(LoginData *loginData); + + /** + * Destructor + */ + ~ServerDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const std::string& eventId, gcn::Widget* widget); + + private: + gcn::TextField *mServerNameField; + gcn::TextField *mPortField; + gcn::Button *mOkButton; + gcn::Button *mCancelButton; + + DropDown *mMostUsedServersDropDown; + gcn::ListBox *mMostUsedServersListBox; + gcn::ScrollArea *mMostUsedServersScrollArea; + ServersListModel *mMostUsedServersListModel; + + DropDownListener *mDropDownListener; + + LoginData *mLoginData; +}; + +#endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 7deb39ff..78b10498 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -85,7 +85,7 @@ Setup::~Setup() for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); } -void Setup::action(const std::string& event, gcn::Widget* widget) +void Setup::action(const std::string& event, gcn::Widget *widget) { if (event == "Apply") { diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index ac5771ad..db88ff64 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -108,7 +108,7 @@ void Setup_Audio::cancel() config.setValue("musicVolume", mMusicVolume); } -void Setup_Audio::action(const std::string& event, gcn::Widget* widget) +void Setup_Audio::action(const std::string& event, gcn::Widget *widget) { if (event == "sfx") { diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 22d0520e..7a4aae03 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -42,6 +42,7 @@ #include "../configuration.h" #include "../graphics.h" #include "../log.h" +#include "../main.h" #include "../utils/tostring.h" diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index df6dc85e..482d1c65 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -44,7 +44,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, void action(const std::string &eventId, gcn::Widget *widget); /** Called when key is pressed */ - void keyPress(const gcn::Key &key); + void keyPress(const gcn::Key& key); private: bool mFullScreenEnabled; diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 3f30732a..3706cdf8 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -22,53 +22,13 @@ */ #include "shop.h" -#include "../utils/tostring.h" -#include "../resources/itemmanager.h" - -ShopItems::~ShopItems() -{ - clear(); -} int ShopItems::getNumberOfElements() { - return mItemsShop.size(); + return size(); } std::string ShopItems::getElementAt(int i) { - return mItemsShop.at(i).name; -} - -void ShopItems::addItem(short id, int price) -{ - ITEM_SHOP item_shop; - - item_shop.name = itemDb->getItemInfo(id).getName() - + " " + toString(price) + " GP"; - item_shop.price = price; - item_shop.id = id; - item_shop.image = itemDb->getItemInfo(id).getImage(); - - mItemsShop.push_back(item_shop); -} - -ITEM_SHOP ShopItems::at(int i) -{ - return mItemsShop.at(i); -} - -void ShopItems::push_back(ITEM_SHOP item_shop) -{ - mItemsShop.push_back(item_shop); -} - -void ShopItems::clear() -{ - mItemsShop.clear(); -} - -std::vector<ITEM_SHOP>* ShopItems::getShop() -{ - return &mItemsShop; + return at(i).name; } diff --git a/src/gui/shop.h b/src/gui/shop.h index de452b5c..fb1f33fd 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -28,34 +28,22 @@ #include <vector> #include <guichan/listmodel.hpp> -#include "../resources/image.h" struct ITEM_SHOP { - short id; std::string name; - Image *image; int price; + short id; int index; int quantity; }; -class ShopItems : public gcn::ListModel +class ShopItems : public std::vector<ITEM_SHOP>, public gcn::ListModel { public: /** * Destructor */ - ~ShopItems(); - - /** - * Adds an item and its associated picture - */ - void addItem(short id, int price); - - /** - * Convenience function for adding items - */ - void push_back(ITEM_SHOP item_shop); + virtual ~ShopItems() {}; /** * Returns the number of items in the shop. @@ -66,25 +54,6 @@ class ShopItems : public gcn::ListModel * Returns the name of item number i in the shop. */ std::string getElementAt(int i); - - /** - * Returns the item number i in the shop. - */ - ITEM_SHOP at(int i); - - /** - * Clear the vector. - */ - void clear(); - - /** - * Direct access to the vector - */ - std::vector<ITEM_SHOP>* getShop(); - - private: - std::vector<ITEM_SHOP> mItemsShop; - }; #endif diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp deleted file mode 100644 index 61abff35..00000000 --- a/src/gui/shoplistbox.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World 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. - * - * The Mana World 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 The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: listbox.cpp 2655 2006-09-03 21:25:02Z b_lindeijer $ - */ - -#include "shoplistbox.h" - -#include "selectionlistener.h" - -#include <guichan/font.hpp> -#include <guichan/graphics.hpp> -#include <guichan/listmodel.hpp> -#include <guichan/mouseinput.hpp> -#include <guichan/imagefont.hpp> -#include <guichan/basiccontainer.hpp> - -#include "../graphics.h" - -const int ITEM_SPRITE_HEIGHT = 32; - -ShopListBox::ShopListBox(gcn::ListModel *listModel): - gcn::ListBox(listModel), - mMousePressed(false), - mPlayerMoney(0) -{ - mRowHeight = getFont()->getHeight(); - mPriceCheck = true; -} - -ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): - gcn::ListBox(listModel), - mMousePressed(false), - mPlayerMoney(0), - mShopItems(shopListModel) -{ - mRowHeight = (getFont()->getHeight() > ITEM_SPRITE_HEIGHT ? - getFont()->getHeight() : ITEM_SPRITE_HEIGHT); - mPriceCheck = true; -} - - -void ShopListBox::setPlayersMoney(int money) -{ - mPlayerMoney = money; -} - -void ShopListBox::draw(gcn::Graphics *graphics) -{ - if (mListModel == NULL) { - return; - } - - graphics->setFont(getFont()); - - // Draw the list elements - for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += mRowHeight) - { - graphics->setColor(gcn::Color(0xffffff)); - if (mShopItems != NULL) - { - if(mPlayerMoney < mShopItems->at(i).price && mPriceCheck) - { - graphics->setColor(gcn::Color(0x919191)); - } - } - graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); - if (mShopItems) - dynamic_cast<Graphics*>(graphics)->drawImage(mShopItems->at(i).image, 1, y); - graphics->drawText(mListModel->getElementAt(i), ITEM_SPRITE_HEIGHT, y); - } - - // Draw rectangle below the selected list element and the list element - // not shown. - if (mSelected >= 0) { - graphics->setColor(gcn::Color(110, 160, 255)); - graphics->fillRectangle(gcn::Rectangle(0, mRowHeight * mSelected, - getWidth(), mRowHeight)); - if (mShopItems) - dynamic_cast<Graphics*>(graphics)->drawImage( - mShopItems->at(mSelected).image, 1, mRowHeight * mSelected); - graphics->drawText(mListModel->getElementAt(mSelected), - ITEM_SPRITE_HEIGHT, mRowHeight * mSelected); - } -} - -void ShopListBox::setSelected(int selected) -{ - gcn::ListBox::setSelected(selected); - if (mListModel != NULL) - { - gcn::BasicContainer *par = getParent(); - if (par == NULL) - { - return; - } - - gcn::Rectangle scroll; - - if (mSelected < 0) - { - scroll.y = 0; - } - else - { - scroll.y = mRowHeight * mSelected; - } - - scroll.height = mRowHeight; - par->showWidgetPart(this, scroll); - } - fireSelectionChangedEvent(); -} - -void ShopListBox::mousePress(int x, int y, int button) -{ - - bool enoughMoney = false; - if (button == gcn::MouseInput::LEFT && hasMouse()) - { - if (mShopItems) - { - if(mPlayerMoney >= mShopItems->at(y / mRowHeight).price) - enoughMoney = true; - } - else // Old Behaviour - enoughMoney = true; - - if (!mPriceCheck) - enoughMoney = true; - - if (enoughMoney) - { - setSelected(y / mRowHeight); - generateAction(); - mMousePressed = true; - } - } -} - -void ShopListBox::mouseRelease(int x, int y, int button) -{ - gcn::ListBox::mouseRelease(x, y, button); - - mMousePressed = false; -} - -void ShopListBox::mouseMotion(int x, int y) -{ - gcn::ListBox::mouseMotion(x, y); - - // Pretend mouse is pressed continuously while dragged. Causes list - // selection to be updated as is default in many GUIs. - if (mMousePressed) - { - mousePress(x, y, gcn::MouseInput::LEFT); - } -} - -void ShopListBox::fireSelectionChangedEvent() -{ - SelectionEvent event(this); - SelectionListeners::iterator i_end = mListeners.end(); - SelectionListeners::iterator i; - - for (i = mListeners.begin(); i != i_end; ++i) - { - (*i)->selectionChanged(event); - } -} - -void ShopListBox::adjustSize() -{ - if (mListModel != NULL) - { - setHeight(mRowHeight * mListModel->getNumberOfElements()); - } -} - -void ShopListBox::setPriceCheck(bool check) -{ - mPriceCheck = check; -} diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h deleted file mode 100644 index 2dff8977..00000000 --- a/src/gui/shoplistbox.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World 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. - * - * The Mana World 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 The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id: listbox.h 2655 2006-09-03 21:25:02Z b_lindeijer $ - */ - -#ifndef _TMW_LISTBOX_H -#define _TMW_LISTBOX_H - -#include <guichan/widgets/listbox.hpp> -#include "shop.h" - -class SelectionListener; - -/** - * A list box, meant to be used inside a scroll area. Same as the Guichan list - * box except this one doesn't have a background, instead completely relying - * on the scroll area. It also adds selection listener functionality. - * - * \ingroup GUI - */ -class ShopListBox : public gcn::ListBox -{ - public: - /** - * Constructor. - */ - ShopListBox(gcn::ListModel *listModel); - - /** - * Constructor with shopitems - */ - ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel); - - /** - * Draws the list box. - */ - void draw(gcn::Graphics *graphics); - - void mousePress(int x, int y, int button); - void mouseRelease(int x, int y, int button); - void mouseMotion(int x, int y); - - /** - * Adds a listener to the list that's notified each time a change to - * the selection occurs. - */ - void addSelectionListener(SelectionListener *listener) - { - mListeners.push_back(listener); - } - - /** - * Removes a listener from the list that's notified each time a change - * to the selection occurs. - */ - void removeSelectionListener(SelectionListener *listener) - { - mListeners.remove(listener); - } - - /** - * Sets the index of the selected element. - */ - void setSelected(int selected); - - /** - * gives information about the current player's money - */ - void setPlayersMoney(int money); - - /** - * Adjust List draw size - */ - void adjustSize(); - - /** - * Set on/off the disabling of too expensive items. - * (Good for selling mode.) - */ - void setPriceCheck(bool check); - - private: - /** - * Sends out selection events to the list of selection listeners. - */ - void fireSelectionChangedEvent(); - - bool mMousePressed; /**< Keeps track of mouse pressed status. */ - - std::list<SelectionListener*> mListeners; - - int mPlayerMoney; - - /** - * Keeps another pointer to the same listModel, permitting to - * use the ShopItems specific functions. - */ - ShopItems *mShopItems; - - int mRowHeight; /**< Row Height */ - - bool mPriceCheck; - -}; - -#endif diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index e824f2f0..4f552fd7 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -103,7 +103,7 @@ SkillDialog::~SkillDialog() cleanList(); } -void SkillDialog::action(const std::string& eventId, gcn::Widget* widget) +void SkillDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "inc") { diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 0f149403..b53e0942 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -48,7 +48,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): // ---------------------- mLvlLabel = new gcn::Label("Level:"); - mGpLabel = new gcn::Label("Money:"); + mMoneyLabel = new gcn::Label("Money:"); mHpLabel = new gcn::Label("HP:"); mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); @@ -71,7 +71,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mLvlLabel->setPosition(x, y); x += mLvlLabel->getWidth() + 40; - mGpLabel->setPosition(x, y); + mMoneyLabel->setPosition(x, y); y += mLvlLabel->getHeight() + 5; // Next Row x = 5; @@ -100,7 +100,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mJobValueLabel->setPosition(290, y); add(mLvlLabel); - add(mGpLabel); + add(mMoneyLabel); add(mHpLabel); add(mHpValueLabel); add(mMpLabel); @@ -227,8 +227,8 @@ void StatusWindow::update() mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel)); mLvlLabel->adjustSize(); - mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP"); - mGpLabel->adjustSize(); + mMoneyLabel->setCaption("Money: " + toString(mPlayer->mMoney) + " GP"); + mMoneyLabel->adjustSize(); mJobXpLabel->setCaption("Job: " + toString(mPlayer->mJobLevel)); mJobXpLabel->adjustSize(); @@ -334,7 +334,7 @@ void StatusWindow::update() mStatsReflexPoints->adjustSize(); // Update Second column widgets position - mGpLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, + mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, mLvlLabel->getY()); mXpLabel->setPosition( @@ -361,34 +361,34 @@ void StatusWindow::draw(gcn::Graphics *g) Window::draw(g); } -void StatusWindow::action(const std::string& eventId, gcn::Widget* widget) +void StatusWindow::action(const std::string &eventId, gcn::Widget *widget) { // Stats Part if (eventId.length() == 3) { if (eventId == "STR") { - player_node->raiseAttribute(LocalPlayer::STR); + mPlayer->raiseAttribute(LocalPlayer::STR); } if (eventId == "AGI") { - player_node->raiseAttribute(LocalPlayer::AGI); + mPlayer->raiseAttribute(LocalPlayer::AGI); } if (eventId == "VIT") { - player_node->raiseAttribute(LocalPlayer::VIT); + mPlayer->raiseAttribute(LocalPlayer::VIT); } if (eventId == "INT") { - player_node->raiseAttribute(LocalPlayer::INT); + mPlayer->raiseAttribute(LocalPlayer::INT); } if (eventId == "DEX") { - player_node->raiseAttribute(LocalPlayer::DEX); + mPlayer->raiseAttribute(LocalPlayer::DEX); } if (eventId == "LUK") { - player_node->raiseAttribute(LocalPlayer::LUK); + mPlayer->raiseAttribute(LocalPlayer::LUK); } } } diff --git a/src/gui/status.h b/src/gui/status.h index 6b963d24..fe2140e3 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -69,7 +69,7 @@ class StatusWindow : public Window, public gcn::ActionListener { /** * Status Part */ - gcn::Label *mLvlLabel, *mGpLabel, *mHpLabel, *mHpValueLabel; + gcn::Label *mLvlLabel, *mMoneyLabel, *mHpLabel, *mHpValueLabel; gcn::Label *mMpLabel, *mMpValueLabel; gcn::Label *mXpLabel, *mXpValueLabel, *mJobXpLabel, *mJobValueLabel; ProgressBar *mHpBar, *mMpBar; diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 5352b23d..2ac56ae5 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -38,16 +38,12 @@ #include "../inventory.h" #include "../item.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../resources/iteminfo.h" #include "../utils/tostring.h" -TradeWindow::TradeWindow(Network *network): +TradeWindow::TradeWindow(): Window("Trade: You"), - mNetwork(network), mMyInventory(new Inventory()), mPartnerInventory(new Inventory()) { @@ -217,10 +213,12 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(item->getInvIndex()); - outMsg.writeInt32(quantity); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); + outMsg.writeShort(item->getInvIndex()); + outMsg.writeLong(quantity); + */ } void TradeWindow::selectionChanged(const SelectionEvent &event) @@ -258,7 +256,7 @@ void TradeWindow::selectionChanged(const SelectionEvent &event) } } -void TradeWindow::action(const std::string& eventId, gcn::Widget* widget) +void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = inventoryWindow->getItem(); @@ -290,8 +288,10 @@ void TradeWindow::action(const std::string& eventId, gcn::Widget* widget) } else if (eventId == "cancel") { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); + */ } else if (eventId == "ok") { @@ -301,20 +301,27 @@ void TradeWindow::action(const std::string& eventId, gcn::Widget* widget) { mMoneyField->setText(toString(tempInt)); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(0); - outMsg.writeInt32(tempInt); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); + outMsg.writeShort(0); + outMsg.writeLong(tempInt); + */ } else { mMoneyField->setText(""); } mMoneyField->setEnabled(false); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_ADD_COMPLETE); + + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE); + */ } else if (eventId == "trade") { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_TRADE_OK); + // XXX Convert for new server + /* + MessageOut outMsg(CMSG_TRADE_OK); + */ } } diff --git a/src/gui/trade.h b/src/gui/trade.h index 339fc4e3..ebd05a52 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -36,7 +36,6 @@ class Inventory; class Item; class ItemContainer; -class Network; class ScrollArea; /** @@ -50,7 +49,7 @@ class TradeWindow : public Window, gcn::ActionListener, SelectionListener /** * Constructor. */ - TradeWindow(Network *network); + TradeWindow(); /** * Destructor. @@ -115,8 +114,6 @@ class TradeWindow : public Window, gcn::ActionListener, SelectionListener void action(const std::string &eventId, gcn::Widget *widget); private: - Network *mNetwork; - typedef std::auto_ptr<Inventory> InventoryPtr; InventoryPtr mMyInventory; InventoryPtr mPartnerInventory; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 89d1793e..510e10ba 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -86,8 +86,7 @@ UpdaterWindow::UpdaterWindow(): mCancelButton->requestFocus(); setLocationRelativeTo(getParent()); - mUpdateHost = - config.getValue("updatehost", "http://updates.themanaworld.org"); + mUpdateHost = config.getValue("updatehost", "themanaworld.org/files"); mBasePath = config.getValue("homeDir", "."); // Try to download the updates list @@ -130,7 +129,7 @@ void UpdaterWindow::enable() mPlayButton->requestFocus(); } -void UpdaterWindow::action(const std::string& eventId, gcn::Widget* widget) +void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { @@ -139,7 +138,7 @@ void UpdaterWindow::action(const std::string& eventId, gcn::Widget* widget) // Skip the updating process if (mDownloadStatus == UPDATE_COMPLETE) { - state = EXIT_STATE; + state = STATE_EXIT; } else { @@ -148,7 +147,7 @@ void UpdaterWindow::action(const std::string& eventId, gcn::Widget* widget) } else if (eventId == "play") { - state = LOGIN_STATE; + state = STATE_LOGIN; } } @@ -182,12 +181,6 @@ void UpdaterWindow::loadNews() setVisible(true); } -void UpdaterWindow::addRow(const std::string &row) -{ - mBrowserBox->addRow(row); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); -} - int UpdaterWindow::updateProgress(void *ptr, double dt, double dn, double ut, double un) { @@ -201,7 +194,7 @@ int UpdaterWindow::updateProgress(void *ptr, uw->mCurrentFile + " (" + toString((int)progress * 100) + "%)"); uw->setProgress(progress); - if (state != UPDATE_STATE || uw->mDownloadStatus == UPDATE_ERROR) + if (state != STATE_UPDATE || uw->mDownloadStatus == UPDATE_ERROR) { // If the action was canceled return an error code to stop the mThread return -1; @@ -343,11 +336,12 @@ void UpdaterWindow::logic() } mThread = NULL; } - addRow(""); - addRow("##1 The update process is incomplete."); - addRow("##1 It is strongly recommended that"); - addRow("##1 you try again later"); - addRow(mCurlError); + mBrowserBox->addRow(""); + mBrowserBox->addRow("##1 The update process is incomplete."); + mBrowserBox->addRow("##1 It is strongly recommended that"); + mBrowserBox->addRow("##1 you try again later"); + mBrowserBox->addRow(mCurlError); + mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); mDownloadStatus = UPDATE_COMPLETE; break; case UPDATE_NEWS: diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 5016036d..16442656 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -81,11 +81,6 @@ class UpdaterWindow : public Window, public gcn::ActionListener void action(const std::string& eventId, gcn::Widget* widget); - /** - * Add a row to the message field. - */ - void addRow(const std::string &row); - void logic(); int updateState; diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp index eb838ead..b503508e 100644 --- a/src/gui/vbox.cpp +++ b/src/gui/vbox.cpp @@ -25,7 +25,7 @@ void VBox::draw(gcn::Graphics *graphics) { - if (mWidgets.size() == 0) + if (mWidgets.empty()) { return; } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp new file mode 100644 index 00000000..34c6b93a --- /dev/null +++ b/src/gui/widgets/dropdown.cpp @@ -0,0 +1,191 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "dropdown.h" + +#include "../../graphics.h" + +#include "../../graphic/imagerect.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +#include "../../utils/dtor.h" + +int DropDown::instances = 0; +Image *DropDown::buttons[2][2]; +ImageRect DropDown::skin; + +DropDown::DropDown(gcn::ListModel *listModel, + gcn::ScrollArea *scrollArea, + gcn::ListBox *listBox): + gcn::DropDown::DropDown(listModel, + scrollArea, listBox) +{ + setBorderSize(2); + + // Initialize graphics + if (instances == 0) + { + // Load the background skin + ResourceManager *resman = ResourceManager::getInstance(); + + // Get the button skin + buttons[1][0] = + resman->getImage("graphics/gui/vscroll_up_default.png"); + buttons[0][0] = + resman->getImage("graphics/gui/vscroll_down_default.png"); + buttons[1][1] = + resman->getImage("graphics/gui/vscroll_up_pressed.png"); + buttons[0][1] = + resman->getImage("graphics/gui/vscroll_down_pressed.png"); + + // get the border skin + Image *boxBorder = resman->getImage("graphics/gui/deepbox.png"); + int gridx[4] = {0, 3, 28, 31}; + int gridy[4] = {0, 3, 28, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + skin.grid[a] = boxBorder->getSubImage( + gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, + gridy[y + 1] - gridy[y] + 1); + a++; + } + } + + boxBorder->decRef(); + } + + instances++; +} + +DropDown::~DropDown() +{ + instances--; + // Free images memory + if (instances == 0) + { + buttons[0][0]->decRef(); + buttons[0][1]->decRef(); + buttons[1][0]->decRef(); + buttons[1][1]->decRef(); + + for_each(skin.grid, skin.grid + 9, dtor<Image*>()); + } +} + +void DropDown::draw(gcn::Graphics* graphics) +{ + int h; + + if (mDroppedDown) + { + h = mOldH; + } + else + { + h = getHeight(); + } + + int alpha = getBaseColor().a; + gcn::Color faceColor = getBaseColor(); + faceColor.a = alpha; + gcn::Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + gcn::Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + if (mListBox->getListModel() && mListBox->getSelected() >= 0) + { + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + } + + if (isFocused()) + { + graphics->setColor(highlightColor); + graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); + } + + drawButton(graphics); + + if (mDroppedDown) + { + drawChildren(graphics); + + // Draw two lines separating the ListBox with se selected + // element view. + graphics->setColor(highlightColor); + graphics->drawLine(0, h, getWidth(), h); + graphics->setColor(shadowColor); + graphics->drawLine(0, h + 1,getWidth(),h + 1); + } +} + +void DropDown::drawBorder(gcn::Graphics *graphics) +{ + int w, h, bs; + bs = getBorderSize(); + w = getWidth() + bs * 2; + h = getHeight() + bs * 2; + + dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, skin); +} + +void DropDown::drawButton(gcn::Graphics *graphics) +{ + + unsigned short state = 0; + unsigned short dir = 0; + gcn::Rectangle dim; + + if (mPushed) + state = 1; + + if (mDroppedDown) + dir = 1; + + int height; + if (mDroppedDown) + { + height = mOldH; + } + else + { + height = getHeight(); + } + int x = getWidth() - height; + int y = 0; + + dynamic_cast<Graphics*>(graphics)->drawImage( + buttons[dir][state], x, y + 1); +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h new file mode 100644 index 00000000..37e754af --- /dev/null +++ b/src/gui/widgets/dropdown.h @@ -0,0 +1,85 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef DROPDOWN_H +#define DROPDOWN_H + +#include <iosfwd> + +#include <guichan/widgets/dropdown.hpp> +#include "../scrollarea.h" +#include "../listbox.h" + +class Image; +class ImageRect; + + /** + * A drop down box from which you can select different values. It is one of + * the most complicated Widgets you will find in Guichan. For drawing the + * DroppedDown box it uses one ScrollArea and one ListBox. It also uses an + * internal FocusHandler to handle the focus of the internal ScollArea and + * ListBox. DropDown uses a ListModel to handle the list. To be able to use + * DropDown you must give DropDown an implemented ListModel which represents + * your list. + */ +class DropDown : public gcn::DropDown +{ + public: + /** + * Contructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(gcn::ListModel *listModel = NULL, + gcn::ScrollArea *scrollArea = NULL, + gcn::ListBox *listBox = NULL); + + /** + * Destructor. + */ + ~DropDown(); + + void draw(gcn::Graphics* graphics); + + void drawBorder(gcn::Graphics* graphics); + + + protected: + /** + * Draws the button with the little down arrow. + * + * @param graphics a Graphics object to draw with. + */ + void drawButton(gcn::Graphics *graphics); + + // Add own Images. + static int instances; + static Image *buttons[2][2]; + static ImageRect skin; +}; + +#endif // end DROPDOWN_H + diff --git a/src/gui/window.cpp b/src/gui/window.cpp index fe23c775..c7860021 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -196,7 +196,7 @@ void Window::setContentHeight(int height) resizeToContent(); } -void Window::setLocationRelativeTo(gcn::Widget* widget) +void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; int x, y; @@ -249,16 +249,18 @@ void Window::setSticky(bool sticky) mSticky = sticky; } -bool Window::isSticky() { +bool Window::isSticky() +{ return mSticky; } -void Window::setVisible(bool visible) { - if(isSticky()) +void Window::setVisible(bool visible) +{ + if (isSticky()) { gcn::Window::setVisible(true); - } - else + } + else { gcn::Window::setVisible(visible); } |