From b32ee882097905faea84ed73aa86620248fdefae Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 20:19:34 -0700 Subject: Small dialog visibility fix Basically ensures that the NPC text dialog is visible before making NPC input dialogs visible --- src/gui/npcstringdialog.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index d9bf5682..679c93e5 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -87,3 +87,10 @@ void NpcStringDialog::requestFocus() { mValueField->requestFocus(); } + +void NpcStringDialog::setVisible(bool visible) +{ + if (visible) npcTextDialog->setVisible(true); + + Window::setVisible(visible); +} -- cgit v1.2.3-70-g09d2 From d8bc3a6418c5027d7f6c42ce8f8dceca8dee8971 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 00:50:33 -0700 Subject: Fixed up NPC list dialogs to be navigatable by keyboard (scrolling through the list requires the use of the mouse wheel at the moment), fixed wrapping behavior for wrapping around lists to actually wrap around lists properly, and placed a few checks for current_npc where they were assumed before which could cause the client to hang or crash in case the NPC is no longer around. Signed-off-by: Ira Rice --- src/game.cpp | 2 +- src/gui/listbox.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/listbox.h | 19 ++++++++++ src/gui/npcintegerdialog.cpp | 11 +++--- src/gui/npclistdialog.cpp | 16 +++++++-- src/gui/npclistdialog.h | 5 +++ src/gui/npcstringdialog.cpp | 5 ++- src/gui/table.cpp | 6 +--- src/net/npchandler.cpp | 2 +- 9 files changed, 136 insertions(+), 15 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/game.cpp b/src/game.cpp index e5f7b22b..16790cac 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -490,7 +490,7 @@ void Game::handleInput() gcn::Window *requestedWindow = NULL; if (setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) { keyboard.setNewKey((int) event.key.keysym.sym); keyboard.callbackNewKey(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index f16857ce..8ae68e09 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include "color.h" @@ -69,6 +70,90 @@ void ListBox::draw(gcn::Graphics *graphics) } } +void ListBox::setSelected(int selected) +{ + if (!mListModel) + { + mSelected = -1; + } + else + { + if (selected < 0 && !mWrappingEnabled) + { + mSelected = -1; + } + else if (selected >= mListModel->getNumberOfElements() && + mWrappingEnabled) + { + mSelected = 0; + } + else if ((selected >= mListModel->getNumberOfElements() && + !mWrappingEnabled) || (selected < 0 && mWrappingEnabled)) + { + mSelected = mListModel->getNumberOfElements() - 1; + } + else + { + mSelected = selected; + } + } +} + +// -- KeyListener notifications +void ListBox::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == gcn::Key::ENTER || key.getValue() == gcn::Key::SPACE) + { + distributeActionEvent(); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::UP) + { + setSelected(mSelected - 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::DOWN) + { + setSelected(mSelected + 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::END) + { + setSelected(getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } +} + +void ListBox::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + if (getSelected() > 0 || (getSelected() == 0 && mWrappingEnabled)) + { + setSelected(getSelected() - 1); + } + + mouseEvent.consume(); + } +} + +void ListBox::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + setSelected(getSelected() + 1); + + mouseEvent.consume(); + } +} + void ListBox::mouseDragged(gcn::MouseEvent &event) { // Pretend mouse is pressed continuously while dragged. Causes list diff --git a/src/gui/listbox.h b/src/gui/listbox.h index e783083f..a6392a94 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -49,6 +49,25 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); + // Inherited from KeyListener + + virtual void keyPressed(gcn::KeyEvent& keyEvent); + + // Inherited from MouseListener + + virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); + private: static float mAlpha; }; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index ea3398c9..d0a7c7be 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -72,15 +72,15 @@ int NpcIntegerDialog::getValue() void NpcIntegerDialog::action(const gcn::ActionEvent &event) { - int finish = 0; + bool finish = false; if (event.getId() == "ok") { - finish = 1; + finish = true; } else if (event.getId() == "cancel") { - finish = 1; + finish = true; mValueField->reset(); } else if (event.getId() == "decvalue") @@ -99,7 +99,10 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + if (current_npc) + current_npc->integerInput(mValueField->getValue()); + current_npc = NULL; mValueField->reset(); } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 81c33049..f3bb949a 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,9 @@ NpcListDialog::NpcListDialog(): mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); + scrollArea = new ScrollArea(mItemList); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); @@ -95,10 +97,9 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { // Send the selected index back to the server int selectedIndex = mItemList->getSelected(); + if (selectedIndex > -1) - { choice = selectedIndex + 1; - } } else if (event.getId() == "cancel") { @@ -109,7 +110,16 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + + if (current_npc) + current_npc->dialogChoice(choice); + current_npc = NULL; } } + +void NpcListDialog::requestFocus() +{ + mItemList->requestFocus(); + mItemList->setSelected(0); +} diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index a30bec28..de3a7a77 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -73,6 +73,11 @@ class NpcListDialog : public Window, public gcn::ActionListener, */ void reset(); + /** + * Requests the listbox to take focus for input. + */ + void requestFocus(); + private: gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index ef2de73a..140ca40f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,7 +64,10 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + + if (current_npc) + current_npc->stringInput(mValueField->getText()); + current_npc = NULL; mValueField->setText(""); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 8acbc4f4..29a33b7a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -402,25 +402,21 @@ void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) else if (key.getValue() == gcn::Key::UP) { setSelectedRow(mSelectedRow - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) { setSelectedRow(mSelectedRow + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::LEFT) { setSelectedColumn(mSelectedColumn - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::RIGHT) { setSelectedColumn(mSelectedColumn + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::HOME) @@ -460,7 +456,7 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) { if (isFocused()) { - if (getSelectedRow() >= 0 ) + if (getSelectedRow() > 0 || (getSelectedRow() == 0 && mWrappingEnabled)) { setSelectedRow(getSelectedRow() - 1); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 94e145b4..26250d9e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,6 +60,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); + npcListDialog->requestFocus(); break; case SMSG_NPC_MESSAGE: @@ -68,7 +69,6 @@ void NPCHandler::handleMessage(MessageIn *msg) player_node->setAction(LocalPlayer::STAND); current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(false); npcTextDialog->setVisible(true); break; -- cgit v1.2.3-70-g09d2 From f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:38:55 -0700 Subject: Fix NPC handling to not need a handle on the NPC The Being ID is used instead, as that is all that was ever really needed. --- src/beingmanager.cpp | 21 +++++++------- src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buy.cpp | 2 +- src/gui/buysell.cpp | 22 +++++++++++---- src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 21 ++++++++++---- src/gui/npc_text.h | 8 +++++- src/gui/npcintegerdialog.cpp | 14 +++++++-- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 12 ++++++-- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 16 +++++++++-- src/gui/npcstringdialog.h | 5 +++- src/gui/sell.cpp | 2 +- src/net/beinghandler.cpp | 14 ++++++--- src/net/buysellhandler.cpp | 4 +-- src/net/npchandler.cpp | 27 ++++++++---------- src/net/playerhandler.cpp | 4 +-- src/npc.cpp | 67 ++------------------------------------------ src/npc.h | 15 +--------- 21 files changed, 142 insertions(+), 148 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3b73d29f..273436bf 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,10 +96,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - if (being == current_npc) - current_npc->handleDeath(); - else - delete being; + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -196,12 +193,6 @@ void BeingManager::clear() mBeings.remove(player_node); } - if (current_npc) - { - mBeings.remove(current_npc); - current_npc->handleDeath(); - } - delete_all(mBeings); mBeings.clear(); @@ -264,3 +255,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 11721709..02c83725 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -98,13 +98,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index cb85fc5c..6f9dbb88 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -198,13 +198,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow; buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog; + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow; emoteWindow = new EmoteWindow; - npcTextDialog = new NpcTextDialog; - npcIntegerDialog = new NpcIntegerDialog; - npcListDialog = new NpcListDialog; - npcStringDialog = new NpcStringDialog; + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog; setupWindow = new Setup; minimap = new Minimap; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c084c7c2..cad21ab5 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -132,7 +132,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 8bf5f1f4..c1c934d1 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -24,10 +24,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -60,12 +63,19 @@ void BuySellDialog::logic() void BuySellDialog::action(const gcn::ActionEvent &event) { + setVisible(false); + int action; if (event.getId() == "Buy") { - current_npc->buy(); + action = 0; } else if (event.getId() == "Sell") { - current_npc->sell(); + action = 1; } else if (event.getId() == "Cancel") { - if (current_npc) current_npc->handleDeath(); + current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 754bb551..197c1a2b 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -26,6 +26,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -40,7 +42,7 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Check for current NPC @@ -51,6 +53,9 @@ class BuySellDialog : public Window, public gcn::ActionListener * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 1750cbd4..db0015e9 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")), +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network), mState(NPC_TEXT_STATE_WAITING) { setResizable(true); @@ -97,14 +100,14 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok") { if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - current_npc->nextDialog(); + nextDialog(); addText("\n> Next\n"); } else if (mState == NPC_TEXT_STATE_CLOSE || (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); - if (current_npc) current_npc->nextDialog(); + if (current_npc) nextDialog(); setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } else return; } else return; @@ -114,10 +117,16 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) mState = NPC_TEXT_STATE_WAITING; } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); setText(mText); } - diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 00b11b3c..62486fff 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -28,6 +28,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -43,7 +46,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -74,6 +77,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void showCloseButton(); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -82,6 +87,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index f91b42da..f6d788df 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField; @@ -104,7 +107,12 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); + mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 6083338c..80a21848 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -26,6 +26,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -41,7 +42,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -81,6 +82,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 8349cb4a..fc7d2979 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,13 +31,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -115,7 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index e7e2f9a9..a7b49506 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -29,6 +29,8 @@ #include +class Network; + /** * The npc list dialog. * @@ -43,7 +45,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -75,6 +77,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); private: + Network *mNetwork; gcn::ListBox *mItemList; std::vector mItems; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 679c93e5..7ed05288 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -74,8 +77,15 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 31f9c9a0..43283219 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -26,6 +26,8 @@ #include +class Network; + /** * The npc integer input dialog. * @@ -39,7 +41,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +73,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::TextField *mValueField; std::string mDefault; }; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 14620aa6..51fc8f9f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -133,7 +133,7 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 3e746eb5..982667d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -35,6 +35,10 @@ #include "../npc.h" #include "../player_relations.h" +#include "../gui/npc_text.h" + +extern NpcTextDialog *npcTextDialog; + const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler(bool enableSync): @@ -204,7 +208,12 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + + if (id == current_npc) + npcTextDialog->showCloseButton(); + + dstBeing = beingManager->findBeing(id); if (!dstBeing) break; @@ -213,9 +222,6 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc->handleDeath(); - if (msg->readInt8() == 1) dstBeing->setAction(Being::DEAD); else diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index a2442d70..714bc0ea 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -65,7 +65,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) } else { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } break; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ae521bd5..405217bb 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -54,24 +54,21 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { int id; - NPC *temporaryNPC; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); @@ -79,30 +76,28 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the close button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - temporaryNPC->nextDialog(); + npcTextDialog->nextDialog(id); break; case SMSG_NPC_NEXT: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the next button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showNextButton(); - else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help - temporaryNPC->nextDialog(); + else + npcTextDialog->nextDialog(id); break; case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setDefaultValue(0); npcIntegerDialog->setVisible(true); @@ -111,8 +106,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ee1b2fd9..550753b7 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -93,7 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } } deathListener; } @@ -147,8 +147,6 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); - if (current_npc) current_npc->handleDeath(); - float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; diff --git a/src/npc.cpp b/src/npc.cpp index ecac2509..8fd8a86b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -20,6 +20,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -33,7 +34,7 @@ extern NpcTextDialog *npcTextDialog; -NPC *current_npc = NULL; +int current_npc = NULL; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -113,60 +114,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!this || !mNetwork) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) @@ -174,13 +121,3 @@ void NPC::updateCoords() mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); } } - -void NPC::handleDeath() -{ - if (this != current_npc) return; - - if (npcTextDialog->isVisible()) - npcTextDialog->showCloseButton(); - else - current_npc = NULL; -} diff --git a/src/npc.h b/src/npc.h index 81b6d51e..ef9fdc7d 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,19 +42,6 @@ class NPC : public Player virtual Type getType() const; void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); - - /** - * Call this to ease clean up of the current NPC, without causing - * interface problems - */ - void handleDeath(); protected: Network *mNetwork; void updateCoords(); @@ -62,6 +49,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern int current_npc; #endif -- cgit v1.2.3-70-g09d2 From 0dde31c3db09113639fa443142995b6efcff6646 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 19:04:39 -0700 Subject: Fix NPC handling to not need a handle on the NPC Loosely based on TMW commit f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Signed-off-by: Ira Rice --- src/beingmanager.cpp | 10 +++++++ src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buysell.cpp | 34 +++++++++++++++++------ src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 18 +++++++++--- src/gui/npc_text.h | 9 ++++-- src/gui/npcintegerdialog.cpp | 16 +++++++---- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 16 +++++++---- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 22 +++++++++++---- src/gui/npcstringdialog.h | 5 +++- src/net/beinghandler.cpp | 13 ++++----- src/net/buysellhandler.cpp | 25 ++++++++++------- src/net/npchandler.cpp | 22 +++++++-------- src/net/playerhandler.cpp | 2 +- src/npc.cpp | 65 ++------------------------------------------ src/npc.h | 13 +++------ 19 files changed, 165 insertions(+), 141 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index b4ffa76c..d63e0dc5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -253,3 +253,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 59a7c76a..32ba6242 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -99,13 +99,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 16790cac..110b75cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -195,13 +195,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow(); buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog(); + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow(); emoteWindow = new EmoteWindow(); - npcTextDialog = new NpcTextDialog(); - npcIntegerDialog = new NpcIntegerDialog(); - npcListDialog = new NpcListDialog(); - npcStringDialog = new NpcStringDialog(); + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); setupWindow = new Setup(); minimap = new Minimap(); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 7d63f184..dc7deef6 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -25,10 +25,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -54,12 +57,27 @@ BuySellDialog::BuySellDialog(): void BuySellDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "Buy") { - current_npc->buy(); - } else if (event.getId() == "Sell") { - current_npc->sell(); - } else if (event.getId() == "Cancel") { + setVisible(false); + int action = 0; + + NPC::mTalking = false; + + if (event.getId() == "Buy") + { + action = 0; + } + else if (event.getId() == "Sell") + { + action = 1; + } + else if (event.getId() == "Cancel") + { current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index c12e3c9b..747066a7 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -41,12 +43,15 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index c28f1403..b94e8aa4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -29,10 +29,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")) +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -87,12 +90,19 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) setVisible(false); if (current_npc) - current_npc->nextDialog(); + nextDialog(); - current_npc = NULL; + current_npc = 0; } } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 63d41cd6..a72de5d0 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -29,6 +29,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -44,7 +47,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +74,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -79,7 +84,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: - gcn::Button *okButton; + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9c49a630..132a7608 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); @@ -104,11 +107,14 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->integerInput(mValueField->getValue()); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); - current_npc = NULL; + current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index cca8cb32..15bdee48 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -27,6 +27,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -42,7 +43,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -78,6 +79,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2c4dfc04..73b00239 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,10 +31,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -86,6 +89,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + NPC::mTalking = false; mItemList->setSelected(-1); mItems.clear(); } @@ -112,10 +116,12 @@ void NpcListDialog::action(const gcn::ActionEvent &event) setVisible(false); reset(); - if (current_npc) - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); - current_npc = NULL; + current_npc = 0; } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index de3a7a77..0a0e9813 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -30,6 +30,8 @@ #include "window.h" +class Network; + /** * The npc list dialog. * @@ -44,7 +46,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -79,6 +81,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void requestFocus(); private: + Network *mNetwork; gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; gcn::Button *okButton; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 140ca40f..f2c7434c 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -64,12 +67,19 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->stringInput(mValueField->getText()); - - current_npc = NULL; + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); + + current_npc = 0; } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index c8871184..ee620daf 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * The npc integer input dialog. * @@ -40,7 +42,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -70,6 +72,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::TextField *mValueField; gcn::Button *okButton; gcn::Button *cancelButton; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index c11d22e7..bae14a05 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -196,7 +196,11 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + dstBeing = beingManager->findBeing(id); + + if (id == current_npc) + current_npc = 0; if (!dstBeing) break; @@ -205,12 +209,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc = NULL; - - if (msg->readInt8() == 1) - dstBeing->setAction(Being::DEAD); - else + if (!(msg->readInt8() == 1)) beingManager->destroyBeing(dstBeing); break; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 245b8a50..e9255540 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -66,7 +66,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -89,7 +89,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) case SMSG_NPC_SELL: msg->readInt16(); // length n_items = (msg->getLength() - 4) / 10; - if (n_items > 0) { + if (n_items > 0) + { sellDialog->setMoney(player_node->mGp); sellDialog->reset(); sellDialog->setVisible(true); @@ -101,21 +102,25 @@ void BuySellHandler::handleMessage(MessageIn *msg) msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); - if (item && !(item->isEquipped())) { + + if (item && !(item->isEquipped())) sellDialog->addItem(item, value); - } } } - else { + else + { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); current_npc = 0; } break; case SMSG_NPC_BUY_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) + { chatWindow->chatLog(_("Thanks for buying"), BY_SERVER); - } else { + } + else + { // Reset player money since buy dialog already assumed purchase // would go fine buyDialog->setMoney(player_node->mGp); @@ -124,11 +129,11 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_SELL_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) chatWindow->chatLog(_("Thanks for selling"), BY_SERVER); - } else { + else chatWindow->chatLog(_("Unable to sell"), BY_SERVER); - } + break; } } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index a59ee814..1067a57e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "messagein.h" #include "npchandler.h" #include "protocol.h" @@ -49,15 +51,14 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - int id; + Uint32 id; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); npcListDialog->requestFocus(); @@ -65,17 +66,16 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcTextDialog->setVisible(true); break; case SMSG_NPC_CLOSE: id = msg->readInt32(); - if (current_npc == dynamic_cast(beingManager->findBeing(id))) - current_npc = NULL; + if (current_npc == id) + current_npc = 0; break; case SMSG_NPC_NEXT: @@ -84,8 +84,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); npcIntegerDialog->requestFocus(); @@ -93,8 +93,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index f18c5d82..ffeb3fab 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -92,7 +92,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = NULL; + current_npc = 0; } } deathListener; } diff --git a/src/npc.cpp b/src/npc.cpp index 832e6926..92ef4d82 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -21,6 +21,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -32,8 +33,8 @@ #include "resources/npcdb.h" -NPC *current_npc = 0; bool NPC::mTalking = false; +Uint32 current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -117,68 +118,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) diff --git a/src/npc.h b/src/npc.h index 0dc9c742..e1bf9737 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,6 +23,8 @@ #ifndef NPC_H #define NPC_H +#include + #include "player.h" class Network; @@ -42,14 +44,7 @@ class NPC : public Player virtual Type getType() const; - void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); + void talk();; static bool mTalking; @@ -60,6 +55,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern Uint32 current_npc; #endif -- cgit v1.2.3-70-g09d2 From 071b1c3126362967b0b6a837349b7c5e327574e9 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 26 Feb 2009 13:47:55 -0700 Subject: Don't clear current NPC early --- src/gui/npcintegerdialog.cpp | 1 - src/gui/npclistdialog.cpp | 2 -- src/gui/npcstringdialog.cpp | 2 -- 3 files changed, 5 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9dc3660b..9778d790 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -119,7 +119,6 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) outMsg.writeInt32(current_npc); outMsg.writeInt32(mValueField->getValue()); - current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 53d4f21f..f5479efc 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -128,8 +128,6 @@ void NpcListDialog::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(current_npc); outMsg.writeInt8(choice); - - current_npc = 0; } } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index fb3b43db..aec30826 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -88,8 +88,6 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) outMsg.writeInt32(current_npc); outMsg.writeString(text, text.length()); outMsg.writeInt8(0); - - current_npc = 0; } bool NpcStringDialog::isInputFocused() -- cgit v1.2.3-70-g09d2 From 343d290f639646b9a3a90c9402dfc8e76989bdcb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:29:15 -0600 Subject: Don't center the NPC interraction dialogs Use the last location the user gave instead. Also, do the same for the inventory dialog. --- src/gui/buy.cpp | 1 - src/gui/buysell.cpp | 1 - src/gui/inventorywindow.cpp | 1 - src/gui/npc_text.cpp | 2 +- src/gui/npcintegerdialog.cpp | 3 +-- src/gui/npclistdialog.cpp | 2 +- src/gui/npcstringdialog.cpp | 3 +-- src/gui/sell.cpp | 1 - src/gui/storagewindow.cpp | 1 - 9 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 768dab4d..d267e5ad 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -91,7 +91,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 818413c2..0550a822 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,7 +49,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index e5450748..80017d28 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 61f3e510..53c64a54 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -37,6 +37,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Window(_("NPC")), mNetwork(network), mState(NPC_TEXT_STATE_WAITING) { + setWindowName("NPCText"); setResizable(true); setMinWidth(200); @@ -61,7 +62,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::clearText() diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9778d790..ea06ca8d 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -39,6 +39,7 @@ extern NpcTextDialog *npcTextDialog; NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { + setWindowName("NPCInteger"); mValueField = new IntTextField; mDecButton = new Button("-", "decvalue", this); @@ -62,8 +63,6 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(2, 0, cancelButton); place(3, 0, okButton); reflowLayout(175, 0); - - setLocationRelativeTo(getParent()); } void NpcIntegerDialog::setRange(int min, int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 66c2d9a0..c1493afd 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -42,6 +42,7 @@ extern NpcTextDialog *npcTextDialog; NpcListDialog::NpcListDialog(Network *network): Window(_("NPC")), mNetwork(network) { + setWindowName("NPCList"); setResizable(true); setMinWidth(200); @@ -69,7 +70,6 @@ NpcListDialog::NpcListDialog(Network *network): loadWindowState(); resetToDefaultSize(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index aec30826..525a73a0 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -39,6 +39,7 @@ extern NpcTextDialog *npcTextDialog; NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCList"); mValueField = new TextField(""); gcn::Button *okButton = new Button(_("OK"), "ok", this); @@ -48,8 +49,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(1, 1, cancelButton); place(2, 1, okButton); reflowLayout(175, 0); - - setLocationRelativeTo(getParent()); } std::string NpcStringDialog::getValue() diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 1aa0e2d3..b53a23c1 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 9cdc2da7..2b8ab8f3 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -93,7 +93,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() -- cgit v1.2.3-70-g09d2 From 171198999b4290f3e2adadd019c8d914212ecf47 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:34:07 -0600 Subject: Make sure NPC input dialogs get focus --- src/gui/npcintegerdialog.cpp | 5 ++++- src/gui/npclistdialog.cpp | 5 ++++- src/gui/npcstringdialog.cpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index ea06ca8d..fad37700 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -139,7 +139,10 @@ void NpcIntegerDialog::requestFocus() void NpcIntegerDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c1493afd..94dfabeb 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -134,7 +134,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) void NpcListDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 525a73a0..7c9f78af 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -101,7 +101,10 @@ void NpcStringDialog::requestFocus() void NpcStringDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } -- cgit v1.2.3-70-g09d2 From 58ee835c3763e7bf088fa6c7e31dda1d687589cc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 11:50:27 -0600 Subject: Extended window layout to take relative positions, as well as offsets to that position. This makes it so that when resolutions are changed, the default locations stay relative to the window's position, and not the 800x600 screen resolution. Signed-off-by: Ira Rice --- src/graphics.cpp | 30 ++++++-------- src/graphics.h | 13 ++++++ src/gui/buy.cpp | 3 +- src/gui/buysell.cpp | 1 - src/gui/chat.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inventorywindow.cpp | 3 +- src/gui/npc_text.cpp | 3 +- src/gui/npcintegerdialog.cpp | 7 +++- src/gui/npclistdialog.cpp | 3 +- src/gui/npcstringdialog.cpp | 7 +++- src/gui/recorder.cpp | 8 ++-- src/gui/sell.cpp | 3 +- src/gui/shortcutwindow.cpp | 13 ++---- src/gui/skill.cpp | 2 +- src/gui/status.cpp | 3 +- src/gui/storagewindow.cpp | 3 +- src/gui/trade.cpp | 2 +- src/gui/window.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.h | 16 ++++++- src/openglgraphics.cpp | 42 ++++++++++--------- 23 files changed, 194 insertions(+), 75 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/graphics.cpp b/src/graphics.cpp index 3c507f4b..48fd1340 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -50,30 +50,25 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } - if (hwaccel) { + if (hwaccel) displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - } else { + else displayFlags |= SDL_SWSURFACE; - } mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags); - if (!mScreen) { + if (!mScreen) return false; - } char videoDriverName[64]; - if (SDL_VideoDriverName(videoDriverName, 64)) { + if (SDL_VideoDriverName(videoDriverName, 64)) logger->log("Using video driver: %s", videoDriverName); - } - else { + else logger->log("Using video driver: unknown"); - } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -104,9 +99,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) bool Graphics::setFullscreen(bool fs) { - if (mFullscreen == fs) { + if (mFullscreen == fs) return true; - } return setVideoMode(mScreen->w, mScreen->h, mScreen->format->BitsPerPixel, fs, mHWAccel); @@ -128,7 +122,7 @@ bool Graphics::drawImage(Image *image, int x, int y) } bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, - int width, int height, bool) + int width, int height, bool) { // Check that preconditions for blitting are met. if (!mScreen || !image || !image->mImage) return false; @@ -150,7 +144,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, } void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height) + int dstX, int dstY, int width, int height) { ProxyImage const *srcImage = dynamic_cast< ProxyImage const * >(image); @@ -167,8 +161,10 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) int px = 0; // X position on pattern plane int py = 0; // Y position on pattern plane - while (py < h) { - while (px < w) { + while (py < h) + { + while (px < w) + { int dw = (px + iw >= w) ? w - px : iw; int dh = (py + ih >= h) ? h - py : ih; drawImage(image, 0, 0, x + px, y + py, dw, dh); diff --git a/src/graphics.h b/src/graphics.h index 3ad3b85c..ec0b5e9c 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -49,6 +49,19 @@ struct SDL_Surface; */ struct ImageRect { + enum ImagePosition + { + UPPER_LEFT = 0, + UPPER_CENTER = 1, + UPPER_RIGHT = 2, + LEFT = 3, + CENTER = 4, + RIGHT = 5, + LOWER_LEFT = 6, + LOWER_CENTER = 7, + LOWER_RIGHT = 8, + }; + Image *grid[9]; }; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 5a57dcc6..2b5aeeb7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -47,7 +47,7 @@ BuyDialog::BuyDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); mShopItems = new ShopItems; @@ -90,7 +90,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index dc7deef6..f7684670 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5cf8b739..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -55,7 +55,7 @@ Window(""), mNetwork(network), mTmpVisible(false) setWindowName(_("Chat")); setResizable(true); - setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); setMinWidth(150); setMinHeight(90); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index dafd604a..71855977 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -41,7 +41,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(0, 0, 400, 60); + setDefaultSize(400, 60, ImageRect::CENTER); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 30129941..77168993 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -40,7 +40,7 @@ EmoteWindow::EmoteWindow(): setCloseButton(true); setMinWidth(80); setMinHeight(130); - setDefaultSize(115, 25, 322, 200); + setDefaultSize(322, 200, ImageRect::CENTER); mUseButton = new Button(_("Use"), "use", this); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 27ea38ff..0d2097f8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -71,7 +71,7 @@ EquipmentWindow::EquipmentWindow(): setWindowName("Equipment"); setCloseButton(true); - setDefaultSize(5, 195, 180, 300); + setDefaultSize(180, 300, ImageRect::CENTER); loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 226b3178..7e75411e 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -57,7 +57,7 @@ InventoryWindow::InventoryWindow(int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); std::string longestUseString = getFont()->getWidth(_("Equip")) > getFont()->getWidth(_("Use")) ? @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 58aa0c5e..f524f8ea 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -43,7 +43,7 @@ NpcTextDialog::NpcTextDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mTextBox = new TextBox; mTextBox->setEditable(false); @@ -63,7 +63,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::setText(const std::string &text) diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 132a7608..5b3e05aa 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -37,6 +37,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); + setWindowName("NPCInput"); + + setDefaultSize(175, 75, ImageRect::CENTER); mDecButton = new Button("-", "decvalue", this); mIncButton = new Button("+", "incvalue", this); @@ -58,9 +61,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(0, 0, resetButton); place(2, 0, cancelButton); place(3, 0, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } void NpcIntegerDialog::setRange(const int min, const int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f049cba7..505912ac 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,7 @@ NpcListDialog::NpcListDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); @@ -66,7 +66,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f2c7434c..58a5c0c8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -36,17 +36,20 @@ NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCInput"); mValueField = new TextField(""); + setDefaultSize(175, 75, ImageRect::CENTER); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index ff8825ef..9320e020 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -40,9 +40,11 @@ Recorder::Recorder(ChatWindow *chat, const std::string &title, mChat = chat; Button *button = new Button(buttonTxt, "activate", this); - setDefaultSize(0, windowContainer->getHeight() - 123 - button->getHeight() - - offsetY, button->getWidth() + offsetX, button->getHeight() + - offsetY); + + // 123 is the default chat window height. If you change this in Chat, please + // change it here as well + setDefaultSize(button->getWidth() + offsetX, button->getHeight() + + offsetY, ImageRect::LOWER_LEFT, 0, 123); place(0, 0, button); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 154d1a57..397e29a6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -48,7 +48,7 @@ SellDialog::SellDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); // Create a ShopItems instance, that is aware of duplicate entries. mShopItems = new ShopItems(true); @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index ee32ca70..c2df1f9c 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -40,22 +40,17 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mItems = content; - mInstances++; - const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); setMinHeight(mItems->getBoxHeight() + border); setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border); - const int width = (int) config.getValue("screenwidth", 800); - const int height = (int) config.getValue("screenheight", 600); + setDefaultSize(mItems->getBoxWidth() + border, (mItems->getBoxHeight() * + mItems->getMaxItems()) + border, ImageRect::LOWER_RIGHT, + mInstances * mItems->getBoxWidth(), 0); - setDefaultSize(width - (mInstances * mItems->getBoxWidth()) - - (mInstances * border), height - (mItems->getBoxHeight() * - mItems->getMaxItems()) - border, mItems->getBoxWidth() + - border, (mItems->getBoxHeight() * mItems->getMaxItems()) + - border); + mInstances++; mScrollArea = new ScrollArea(mItems); mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 42ac4d86..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -135,7 +135,7 @@ SkillDialog::SkillDialog(): setWindowName(_("Skills")); setCloseButton(true); - setDefaultSize(windowContainer->getWidth() - 260, 25, 255, 260); + setDefaultSize(255, 260, ImageRect::CENTER); setMinHeight(50 + mTableModel->getHeight()); setMinWidth(200); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 6419eabb..e534edb8 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -41,8 +41,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): { setWindowName(_("Status")); setCloseButton(true); - setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 400, 345); + setDefaultSize(400, 345, ImageRect::CENTER); // ---------------------- // Status Part diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index d3bc7ef8..ca7a547f 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -62,7 +62,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -92,7 +92,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 76795688..a28ff0f9 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -53,7 +53,7 @@ TradeWindow::TradeWindow(Network *network): mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); - setDefaultSize(115, 227, 342, 209); + setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); setMinWidth(342); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..f1316b4c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,6 +220,53 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } +void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = windowContainer->getHeight() - getHeight(); + } + + setPosition(x, y); +} + void Window::setMinWidth(unsigned int width) { mMinWinWidth = width; @@ -540,6 +587,58 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetX, int offsetY) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = windowContainer->getHeight() - defaultHeight; + } + + mDefaultX = x - offsetX; + mDefaultY = y - offsetY; + mDefaultWidth = defaultWidth; + mDefaultHeight = defaultHeight; +} + void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); diff --git a/src/gui/window.h b/src/gui/window.h index bf15dedb..c24bde76 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -34,7 +34,6 @@ class ConfigListener; class GCContainer; class ContainerPlacer; class Image; -class ImageRect; class Layout; class LayoutCell; class ResizeGrip; @@ -90,6 +89,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ void setLocationRelativeTo(gcn::Widget *widget); + /** + * Sets the location relative to the given enumerated position. + */ + void setLocationRelativeTo(ImageRect::ImagePosition position); + /** * Sets whether or not the window can be resized. */ @@ -246,6 +250,16 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size. + * (which can be different of the actual ones.) + * This version of setDefaultSize sets the window's position based + * on a relative enumerated position, rather than a coordinate position. + */ + void setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetx = 0, int offsetY = 0); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 71ab2fe3..9bd3ab2f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -63,18 +63,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) { + if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) return false; - } #ifdef __APPLE__ - if (mSync) { + if (mSync) + { const GLint VBL = 1; CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); } @@ -158,9 +157,7 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, glEnd(); if (!useColor) - { glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); - } return true; } @@ -206,9 +203,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); - } // Grap the pixel buffer and write it to the SDL surface glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -230,9 +226,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() free(buf); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_UnlockSurface(screenshot); - } return screenshot; } @@ -242,7 +237,8 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) int transX = 0; int transY = 0; - if (!mClipStack.empty()) { + if (!mClipStack.empty()) + { transX = -mClipStack.top().xOffset; transY = -mClipStack.top().yOffset; } @@ -267,9 +263,7 @@ void OpenGLGraphics::popClipArea() gcn::Graphics::popClipArea(); if (mClipStack.empty()) - { return; - } glPopMatrix(); glScissor(mClipStack.top().x, @@ -325,8 +319,10 @@ void OpenGLGraphics::setTargetPlane(int width, int height) void OpenGLGraphics::setTexturingAndBlending(bool enable) { - if (enable) { - if (!mTexture) { + if (enable) + { + if (!mTexture) + { glEnable(Image::mTextureType); mTexture = true; } @@ -336,16 +332,22 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) glEnable(GL_BLEND); mAlpha = true; } - } else { - if (mAlpha && !mColorAlpha) { + } + else + { + if (mAlpha && !mColorAlpha) + { glDisable(GL_BLEND); mAlpha = false; - } else if (!mAlpha && mColorAlpha) { + } + else if (!mAlpha && mColorAlpha) + { glEnable(GL_BLEND); mAlpha = true; } - if (mTexture) { + if (mTexture) + { glDisable(Image::mTextureType); mTexture = false; } -- cgit v1.2.3-70-g09d2 From 73fa81961d141b7592862a50993cd998fbd4de31 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 21:50:58 -0600 Subject: Exposed a few more windows to the reset window button under the setup dialog. Signed-off-by: Ira Rice --- src/gui/npcstringdialog.cpp | 1 - src/gui/setup.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 58a5c0c8..f50136ba 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,7 +47,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - //reflowLayout(175, 0); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index f1e7a6d9..5fe35a6c 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -45,6 +45,9 @@ extern Window *itemShortcutWindow; extern Window *emoteShortcutWindow; extern Window *emoteWindow; extern Window *tradeWindow; +extern Window *npcTextDialog; +extern Window *npcStringDialog; +extern Window *storageWindow; Setup::Setup(): Window(_("Setup")) @@ -139,6 +142,9 @@ void Setup::action(const gcn::ActionEvent &event) emoteShortcutWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); tradeWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From f64903f3f139ba83e94c6260c39f88b8d31b793b Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 4 ++++ src/gui/buysell.cpp | 16 +++++++++++++--- src/gui/buysell.h | 4 ++++ src/gui/npcintegerdialog.cpp | 2 -- src/gui/npclistdialog.cpp | 3 --- src/gui/npcstringdialog.cpp | 4 +--- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 4 ++++ src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 12 files changed, 44 insertions(+), 21 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index d267e5ad..3107c529 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -247,3 +247,10 @@ void BuyDialog::logic() if (!current_npc) setVisible(false); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 2555e139..5e2f0b8f 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -100,6 +100,8 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void logic(); + void setVisible(bool visible); + private: Network *mNetwork; gcn::Button *mBuyButton; @@ -121,4 +123,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 0550a822..75c49b1f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -32,6 +32,7 @@ BuySellDialog::BuySellDialog(Network *network): Window(_("Shop")), mNetwork(network) { + setWindowName("BuySell"); Button *buyButton = 0; static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 @@ -48,16 +49,25 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + loadWindowState(); - requestFocus(); + setContentSize(x, 2 * y + buyButton->getHeight()); } void BuySellDialog::logic() { Window::logic(); - if (!current_npc) setVisible(false); + if (isVisible() && !current_npc) { + setVisible(false); + } +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 197c1a2b..4b137554 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -49,6 +49,8 @@ class BuySellDialog : public Window, public gcn::ActionListener */ void logic(); + void setVisible(bool visible); + /** * Called when receiving actions from the widgets. */ @@ -58,4 +60,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index fad37700..c1460f8d 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -34,8 +34,6 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 95fe5983..3960cb21 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -37,8 +37,6 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcListDialog::NpcListDialog(Network *network): Window(_("NPC")), mNetwork(network) { @@ -69,7 +67,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - resetToDefaultSize(false); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 7c9f78af..4d170208 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -34,12 +34,10 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { - setWindowName("NPCList"); + setWindowName("NPCString"); mValueField = new TextField(""); gcn::Button *okButton = new Button(_("OK"), "ok", this); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b53a23c1..4cdabe68 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -273,3 +273,10 @@ void SellDialog::logic() if (!current_npc) setVisible(false); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 3777b91e..3ae5e320 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -86,6 +86,8 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void logic(); + void setVisible(bool visible); + private: /** * Updates the state of buttons and labels. @@ -112,4 +114,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener int mAmountItems; }; +extern SellDialog *sellDialog; + #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index be63ff21..4bc0e4d0 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -120,7 +120,7 @@ Window::~Window() const std::string &name = mWindowName; // Saving X, Y and Width and Height for resizables in the config - if (!name.empty()) + if (!name.empty() && name != "window") { config.setValue(name + "WinX", getX()); config.setValue(name + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 520a1fe6..dcefe905 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -32,15 +32,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -64,8 +61,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 4cc29568..aa0ef16c 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../units.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-70-g09d2 From 6f0d88e781c8b1a75858c769b3641aa8cd477314 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 1 + src/gui/buysell.cpp | 16 +++++++++++++++- src/gui/buysell.h | 10 ++++++++++ src/gui/item_amount.cpp | 24 ++++++++++++------------ src/gui/npcstringdialog.cpp | 2 -- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 1 + src/gui/storagewindow.h | 4 ++++ src/gui/trade.cpp | 27 ++++++++++++++------------- src/gui/trade.h | 13 ++++++------- src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 14 files changed, 81 insertions(+), 45 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 367a041e..ea1df204 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -236,3 +236,10 @@ void BuyDialog::updateButtonsAndLabels() mMoneyLabel->setCaption (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 17ab6e19..08697889 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,6 +96,7 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + void setVisible(bool visible); private: Network *mNetwork; gcn::Button *mBuyButton; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 64ffdc3f..df222797 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -54,8 +54,22 @@ BuySellDialog::BuySellDialog(Network *network): getTitleBarHeight()), ImageRect::CENTER); loadWindowState(); +} + +void BuySellDialog::logic() +{ + Window::logic(); + + if (isVisible() && !current_npc) + setVisible(false); +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); - requestFocus(); + if (visible) + requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 0842c0e1..c6989709 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -46,6 +46,16 @@ class BuySellDialog : public Window, public gcn::ActionListener BuySellDialog(Network *network); /** +<<<<<<< HEAD:src/gui/buysell.h +======= + * Check for current NPC + */ + void logic(); + + void setVisible(bool visible); + + /** +>>>>>>> f64903f... Fix up the NPC interraction widnows a bit:src/gui/buysell.h * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8208d323..c5b27524 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,7 +36,9 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item), mUsage(usage), mMax(mItem->getQuantity()) + mItem(item), + mMax(item->getQuantity()), + mUsage(usage) { // Integer field mItemAmountTextField = new IntTextField(1); @@ -53,10 +55,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): // Buttons Button *minusButton = new Button("-", "Minus", this); - minusButton->setSize(20, 20); Button *plusButton = new Button("+", "Plus", this); - plusButton->setSize(20, 20); - Button *okButton = new Button(_("Ok"), "Drop", this); + Button *okButton = new Button(_("Ok"), "Ok", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); @@ -64,10 +64,10 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); - place(4, 0, addAllButton, 2); + place(5, 0, addAllButton); place(0, 1, mItemAmountSlide, 6); - place(4, 2, okButton); - place(5, 2, cancelButton); + place(4, 2, cancelButton); + place(5, 2, okButton); reflowLayout(250, 0); resetAmount(); @@ -101,17 +101,17 @@ void ItemAmountWindow::resetAmount() void ItemAmountWindow::action(const gcn::ActionEvent &event) { - int amount = mItemAmountTextField->getValue(); + int amount = mItemAmountSlide->getValue(); if (event.getId() == "Cancel") { scheduleDelete(); } - else if (event.getId() == "Plus") + else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus") + else if (event.getId() == "Minus" && amount > 0) { amount--; } @@ -121,9 +121,8 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "Ok" || event.getId() == "All") { - if (event.getId() == "All") { + if (event.getId() == "All") amount = mMax; - } switch (mUsage) { @@ -145,6 +144,7 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } scheduleDelete(); + return; } mItemAmountTextField->setValue(amount); diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f50136ba..43d0722f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,9 +64,7 @@ void NpcStringDialog::setValue(const std::string &value) void NpcStringDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "cancel") - { mValueField->setText(""); - } setVisible(false); NPC::mTalking = false; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b780b02b..ed023227 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -265,3 +265,10 @@ void SellDialog::updateButtonsAndLabels() (strprintf(_("Price: %d GP / Total: %d GP"), income, mPlayerMoney + income)); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 5fb94c4e..c67a25b9 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + void setVisible(bool visible); private: /** * Updates the state of buttons and labels. diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 86451bfe..8f02a618 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -80,6 +80,10 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void removeStore(Item* item, int ammount); + /** + * Closes the Storage Window, as well as telling the server that the + * window has been closed. + */ void close(); private: diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index bae0b651..18b86d4b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -54,6 +54,7 @@ TradeWindow::TradeWindow(Network *network): setWindowName(_("Trade")); setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); + setCloseButton(true); setMinWidth(342); setMinHeight(209); @@ -90,10 +91,10 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(0, 0, mAddButton); - place(1, 0, mOkButton); - place(2, 0, mTradeButton); - place(3, 0, mCancelButton); + place(4, 0, mCancelButton); + place(5, 0, mTradeButton); + place(6, 0, mAddButton); + place(7, 0, mOkButton); Layout &layout = getLayout(); layout.extend(0, 2, 2, 1); layout.setRowHeight(1, Layout::AUTO_SET); @@ -108,14 +109,6 @@ TradeWindow::~TradeWindow() { } -void TradeWindow::widgetResized(const gcn::Event &event) -{ - mMyItemContainer->setWidth(mMyScroll->getWidth()); - mPartnerItemContainer->setWidth(mPartnerScroll->getWidth()); - - Window::widgetResized(event); -} - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); @@ -212,6 +205,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { + addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); @@ -249,7 +243,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (mMyInventory->contains(item)) { chatWindow->chatLog(_("Failed adding item. You can not " - "overlap one kind of item on the window."), BY_SERVER); + "overlap one kind of item on the window."), + BY_SERVER); return; } @@ -295,3 +290,9 @@ void TradeWindow::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_TRADE_OK); } } + +void TradeWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); +} diff --git a/src/gui/trade.h b/src/gui/trade.h index f4a6b5cd..c4d3076a 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -56,13 +56,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ ~TradeWindow(); - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - /** * Add money to the trade window. */ @@ -119,6 +112,12 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void action(const gcn::ActionEvent &event); + /** + * Closes the Trade Window, as well as telling the server that the + * window has been closed. + */ + void close(); + private: Network *mNetwork; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 404f5746..13c8f4ce 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -536,7 +536,7 @@ void Window::loadWindowState() void Window::saveWindowState() { // Saving X, Y and Width and Height for resizables in the config - if (!mWindowName.empty()) + if (!mWindowName.empty() && mWindowName != "window") { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 5b8f0b68..287e5400 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -33,15 +33,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -65,8 +62,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 6533ac1e..60d58a37 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-70-g09d2 From 61f4e3b9838ac7a0e06cd066ea07224670f1b851 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Mar 2009 16:27:51 -0600 Subject: Make sure positionable dialogs start out centered --- src/gui/buy.cpp | 1 + src/gui/buysell.cpp | 6 ++++-- src/gui/char_select.cpp | 4 ++-- src/gui/char_server.cpp | 2 +- src/gui/confirm_dialog.cpp | 2 +- src/gui/connection.cpp | 2 +- src/gui/help.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/login.cpp | 2 +- src/gui/npc_text.cpp | 1 + src/gui/npcintegerdialog.cpp | 4 ++++ src/gui/npclistdialog.cpp | 1 + src/gui/npcstringdialog.cpp | 4 ++++ src/gui/ok_dialog.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/sell.cpp | 1 + src/gui/setup.cpp | 2 +- src/gui/skill.cpp | 2 +- src/gui/speechbubble.cpp | 2 +- src/gui/storagewindow.cpp | 1 + src/gui/updatewindow.cpp | 2 +- src/gui/window.cpp | 20 ++++++++++++++++---- src/gui/window.h | 10 ++++++++++ 23 files changed, 57 insertions(+), 20 deletions(-) (limited to 'src/gui/npcstringdialog.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 3107c529..7e03c591 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -90,6 +90,7 @@ BuyDialog::BuyDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 75c49b1f..e6dc7c1f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,11 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - loadWindowState(); - setContentSize(x, 2 * y + buyButton->getHeight()); + + center(); + setDefaultSize(); + loadWindowState(); } void BuySellDialog::logic() diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 6d5e082a..709988a3 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -127,7 +127,7 @@ CharSelectDialog::CharSelectDialog(Network *network, reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mSelectButton->requestFocus(); updatePlayerInfo(); @@ -306,7 +306,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, reflowLayout(225, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mNameField->requestFocus(); } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 89bfa93a..22b0e7aa 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -85,7 +85,7 @@ ServerSelectDialog::ServerSelectDialog(LoginData *loginData, int nextState): // Select first server mServerList->setSelected(1); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mOkButton->requestFocus(); } diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 0d41525a..a40593e3 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -85,7 +85,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, if (getParent()) { - setLocationRelativeTo(getParent()); + center(); getParent()->moveToTop(this); } setVisible(true); diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index a69698e9..981100f9 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -56,7 +56,7 @@ ConnectionDialog::ConnectionDialog(): add(cancelButton); add(mProgressBar); - setLocationRelativeTo(getParent()); + center(); setVisible(true); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 30c6a9c4..78b3c93a 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -58,7 +58,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0e0dd9e6..efbee6b0 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -89,7 +89,7 @@ ItemPopup::ItemPopup(): add(mItemEffectScroll); add(mItemWeightScroll); - setLocationRelativeTo(getParent()); + center(); } ItemPopup::~ItemPopup() diff --git a/src/gui/login.cpp b/src/gui/login.cpp index e91f7616..414de40e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -110,7 +110,7 @@ LoginDialog::LoginDialog(LoginData *loginData): place(3, 6, mOkButton); reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); if (mUserField->getText().empty()) { diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 53c64a54..5bc654b8 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -61,6 +61,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index c1460f8d..643a7ef8 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -61,6 +61,10 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(2, 0, cancelButton); place(3, 0, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } void NpcIntegerDialog::setRange(int min, int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 3960cb21..d280a982 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -66,6 +66,7 @@ NpcListDialog::NpcListDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 4d170208..7ae2d5ed 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,6 +47,10 @@ NpcStringDialog::NpcStringDialog(Network *network): place(1, 1, cancelButton); place(2, 1, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 4f4f1117..f1a97b49 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -74,7 +74,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, add(mTextArea); add(okButton); - setLocationRelativeTo(getParent()); + center(); setVisible(true); okButton->requestFocus(); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index c2190501..25c97713 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -130,7 +130,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mServerField->addActionListener(this); mPortField->addActionListener(this); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mUserField->requestFocus(); mUserField->setCaretPosition(mUserField->getText().length()); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 4cdabe68..e1b15bac 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -93,6 +93,7 @@ SellDialog::SellDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 68bc3a4b..872596b0 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -101,7 +101,7 @@ Setup::Setup(): add(panel); - setLocationRelativeTo(getParent()); + center(); setInGame(false); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 6112f0e3..ed374a31 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -157,7 +157,7 @@ SkillDialog::SkillDialog(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); loadWindowState(); } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 5f05971d..fb0d7684 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -58,7 +58,7 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); - setLocationRelativeTo(getParent()); + center(); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 5981f121..663ad784 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -92,6 +92,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): Layout &layout = getLayout(); layout.setRowHeight(0, mStoreButton->getHeight()); + center(); loadWindowState(); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 6ec62337..df0a1f80 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -131,7 +131,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mCancelButton->requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 4bc0e4d0..d4665427 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -67,10 +67,9 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mModal(modal), mCloseButton(false), mSticky(false), - mMinWinWidth(100), - mMinWinHeight(40), - mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), + mMinWinWidth(100), mDefaultWidth(100), mMaxWinWidth(INT_MAX), + mMinWinHeight(40), mDefaultHeight(40), mMaxWinHeight(INT_MAX), + mDefaultX(100), mDefaultY(100), mSkin(skin) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -492,6 +491,14 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize() +{ + mDefaultX = getX(); + mDefaultY = getY(); + mDefaultWidth = getWidth(); + mDefaultHeight = getHeight(); +} + void Window::resetToDefaultSize(bool changePosition) { if (changePosition) setPosition(mDefaultX, mDefaultY); @@ -733,3 +740,8 @@ void Window::reflowLayout(int w, int h) mLayout = NULL; setContentSize(w, h); } + +void Window::center() +{ + setLocationRelativeTo(getParent()); +} diff --git a/src/gui/window.h b/src/gui/window.h index 9977aff4..95fe2174 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -239,6 +239,11 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size tot he current ones. + */ + void setDefaultSize(); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. @@ -275,6 +280,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Positions the window in the center of it's parent. + */ + void center(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; -- cgit v1.2.3-70-g09d2