From 0644076cbb731d1f7a55b66bf6d16a309cccea01 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 22:58:42 -0600 Subject: Forgot the actual storage window --- src/gui/storagewindow.cpp | 213 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 src/gui/storagewindow.cpp (limited to 'src/gui/storagewindow.cpp') diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp new file mode 100644 index 00000000..9cdc2da7 --- /dev/null +++ b/src/gui/storagewindow.cpp @@ -0,0 +1,213 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include + +#include "button.h" +#include "inventorywindow.h" +#include "item_amount.h" +#include "itemcontainer.h" +#include "progressbar.h" +#include "scrollarea.h" +#include "storagewindow.h" +#include "viewport.h" + +#include "widgets/layout.h" + +#include "../inventory.h" +#include "../item.h" +#include "../localplayer.h" +#include "../units.h" + +#include "../net/messageout.h" +#include "../net/protocol.h" + +#include "../resources/iteminfo.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" +#include "../utils/stringutils.h" + +StorageWindow::StorageWindow(Network *network, int invSize): + Window(_("Storage")), + mNetwork(network), + mMaxSlots(invSize), + mItemDesc(false) +{ + setWindowName("Storage"); + setResizable(true); + + // If you adjust these defaults, don't forget to adjust the trade window's. + setDefaultSize(115, 25, 375, 300); + + mCancelButton = new Button(_("Close"), "close", this); + mStoreButton = new Button(_("Store"), "store", this); + mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); + + mItems = new ItemContainer(player_node->getStorage(), 1); + mItems->addSelectionListener(this); + + mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsLabel = new gcn::Label(_("Slots: ")); + + mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); + + setMinHeight(130); + setMinWidth(mSlotsLabel->getWidth()); + + place(0, 0, mSlotsLabel).setPadding(3); + place(1, 0, mSlotsBar, 3); + place(0, 1, mInvenScroll, 4, 4); + place(0, 5, mCancelButton); + place(2, 5, mStoreButton); + place(3, 5, mRetrieveButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, mStoreButton->getHeight()); + + loadWindowState(); + setLocationRelativeTo(getParent()); +} + +StorageWindow::~StorageWindow() +{ + delete mItems; +} + +void StorageWindow::logic() +{ + if (!isVisible()) + return; + + Window::logic(); + + if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed())) + { + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsBar->setProgress((float) + player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots); + + mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots)); + } +} + +void StorageWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "close") + { + close(); + } + else if (event.getId() == "store") + { + Item *item = inventoryWindow->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + addStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_ADD, this, item); + } + } + else if (event.getId() == "retrieve") + { + Item *item = mItems->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + removeStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item); + } + } +} + +void StorageWindow::mouseClicked(gcn::MouseEvent &event) +{ + Window::mouseClicked(event); + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + Item *item = mItems->getSelectedItem(); + + if (!item) { + mRetrieveButton->setEnabled(false); + return; + } + + mRetrieveButton->setEnabled(true); + + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = event.getX() + getX(); + const int my = event.getY() + getY(); + viewport->showPopup(mx, my, item); + } +} + +Item* StorageWindow::getSelectedItem() const +{ + return mItems->getSelectedItem(); +} + +void StorageWindow::addStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_MOVE_TO_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::removeStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CLOSE_STORAGE); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 18:40:48 -0600 Subject: Add an interface for eAthena's storage system --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 5 + src/gui/item_amount.cpp | 19 ++++ src/gui/item_amount.h | 2 + src/gui/itemcontainer.cpp | 4 +- src/gui/itemshortcutcontainer.cpp | 16 --- src/gui/itemshortcutcontainer.h | 5 - src/gui/shortcutcontainer.cpp | 5 +- src/gui/storagewindow.cpp | 213 ++++++++++++++++++++++++++++++++++++++ src/gui/storagewindow.h | 105 +++++++++++++++++++ src/gui/trade.cpp | 4 +- src/gui/window.h | 5 +- src/inventory.cpp | 11 +- src/inventory.h | 4 +- src/localplayer.cpp | 11 +- src/localplayer.h | 5 +- src/net/inventoryhandler.cpp | 84 ++++++++++----- src/net/playerhandler.cpp | 2 + 20 files changed, 437 insertions(+), 69 deletions(-) create mode 100644 src/gui/storagewindow.cpp create mode 100644 src/gui/storagewindow.h (limited to 'src/gui/storagewindow.cpp') diff --git a/aethyra.cbp b/aethyra.cbp index 29bc7227..46034040 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -242,6 +242,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51d6b937..c7003946 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,6 +191,8 @@ SET(SRCS gui/speechbubble.h gui/status.cpp gui/status.h + gui/storagewindow.cpp + gui/storagewindow.h gui/table.cpp gui/table.h gui/table_model.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 6b5dda8b..963e41fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -141,6 +141,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/speechbubble.h \ gui/status.cpp \ gui/status.h \ + gui/storagewindow.cpp \ + gui/storagewindow.h \ gui/table.cpp \ gui/table.h \ gui/table_model.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 110b75cc..ba035ecd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -70,6 +70,7 @@ #include "gui/setup.h" #include "gui/skill.h" #include "gui/status.h" +#include "gui/storagewindow.h" #include "gui/trade.h" #include "gui/viewport.h" @@ -129,6 +130,7 @@ HelpWindow *helpWindow; DebugWindow *debugWindow; ShortcutWindow *itemShortcutWindow; ShortcutWindow *emoteShortcutWindow; +StorageWindow *storageWindow; BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; @@ -213,6 +215,7 @@ void createGuiWindows(Network *network) new ItemShortcutContainer); emoteShortcutWindow = new ShortcutWindow("emoteShortcut", new EmoteShortcutContainer); + storageWindow = new StorageWindow(network); // Set initial window visibility chatWindow->setVisible((bool) config.getValue( @@ -230,6 +233,7 @@ void createGuiWindows(Network *network) emoteShortcutWindow->getWindowName() + "Visible", true)); minimap->setVisible((bool) config.getValue( minimap->getWindowName() + "Visible", true)); + storageWindow->setVisible(false); } /** @@ -260,6 +264,7 @@ void destroyGuiWindows() delete debugWindow; delete itemShortcutWindow; delete emoteShortcutWindow; + delete storageWindow; } Game::Game(Network *network): diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8ab36df0..05dca472 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -24,6 +24,7 @@ #include "inttextfield.h" #include "item_amount.h" #include "slider.h" +#include "storagewindow.h" #include "trade.h" #include "widgets/layout.h" @@ -81,6 +82,14 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): setCaption(_("Select amount of items to drop.")); okButton->setActionEventId("Drop"); break; + case AMOUNT_STORE_ADD: + setCaption(_("Select amount of items to store.")); + okButton->setActionEventId("AddStore"); + break; + case AMOUNT_STORE_REMOVE: + setCaption(_("Select amount of items to remove from storage.")); + okButton->setActionEventId("RemoveStore"); + break; default: break; } @@ -124,6 +133,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); scheduleDelete(); } + else if (event.getId() == "AddStore") + { + storageWindow->addStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } + else if (event.getId() == "RemoveStore") + { + storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 6bec86b3..279c239e 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -32,6 +32,8 @@ class Item; #define AMOUNT_TRADE_ADD 1 #define AMOUNT_ITEM_DROP 2 +#define AMOUNT_STORE_ADD 3 +#define AMOUNT_STORE_REMOVE 4 /** * Window used for selecting the amount of items to drop or trade. diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 02d6e66d..54f1f647 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -57,7 +57,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset): mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); - mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 + mMaxItems = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2 addMouseListener(this); addWidgetListener(this); @@ -76,7 +76,7 @@ void ItemContainer::logic() gcn::Widget::logic(); - int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 + int i = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2 if (i != mMaxItems) { diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index e7a9afbe..abe81537 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -64,22 +64,6 @@ ItemShortcutContainer::~ItemShortcutContainer() delete mItemPopup; } -void ItemShortcutContainer::logic() -{ - if (!isVisible()) - return; - - gcn::Widget::logic(); - - int i = itemShortcut->getItemCount(); - - if (i != mMaxItems) - { - mMaxItems = i; - setWidth(getWidth()); - } -} - void ItemShortcutContainer::draw(gcn::Graphics *graphics) { if (!isVisible()) diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h index f6137af0..0149754e 100644 --- a/src/gui/itemshortcutcontainer.h +++ b/src/gui/itemshortcutcontainer.h @@ -49,11 +49,6 @@ class ItemShortcutContainer : public ShortcutContainer */ virtual ~ItemShortcutContainer(); - /** - * Handles the logic of the ItemContainer - */ - void logic(); - /** * Draws the items. */ diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index 50ec9d06..fcb33279 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -43,13 +43,12 @@ void ShortcutContainer::widgetResized(const gcn::Event &event) if (mGridWidth < 1) mGridWidth = 1; + setHeight((mMaxItems / mGridWidth) * mBoxHeight); + mGridHeight = getHeight() / mBoxHeight; if (mGridHeight < 1) mGridHeight = 1; - - setHeight((mMaxItems / mGridWidth + - (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); } int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp new file mode 100644 index 00000000..856f9166 --- /dev/null +++ b/src/gui/storagewindow.cpp @@ -0,0 +1,213 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include + +#include "button.h" +#include "inventorywindow.h" +#include "item_amount.h" +#include "itemcontainer.h" +#include "progressbar.h" +#include "scrollarea.h" +#include "storagewindow.h" +#include "viewport.h" + +#include "widgets/layout.h" + +#include "../inventory.h" +#include "../item.h" +#include "../localplayer.h" + +#include "../net/messageout.h" +#include "../net/network.h" +#include "../net/protocol.h" + +#include "../resources/iteminfo.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" +#include "../utils/stringutils.h" + +StorageWindow::StorageWindow(Network *network, int invSize): + Window(_("Storage")), + mNetwork(network), + mMaxSlots(invSize), + mItemDesc(false) +{ + setWindowName("Storage"); + setResizable(true); + + // If you adjust these defaults, don't forget to adjust the trade window's. + setDefaultSize(115, 25, 375, 300); + + mCancelButton = new Button(_("Close"), "close", this); + mStoreButton = new Button(_("Store"), "store", this); + mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); + + mItems = new ItemContainer(player_node->getStorage(), 1); + mItems->addSelectionListener(this); + + mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsLabel = new gcn::Label(_("Slots: ")); + + mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); + + setMinHeight(130); + setMinWidth(mSlotsLabel->getWidth()); + + place(0, 0, mSlotsLabel).setPadding(3); + place(1, 0, mSlotsBar, 3); + place(0, 1, mInvenScroll, 4, 4); + place(0, 5, mCancelButton); + place(2, 5, mStoreButton); + place(3, 5, mRetrieveButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, mStoreButton->getHeight()); + + loadWindowState(); + setLocationRelativeTo(getParent()); +} + +StorageWindow::~StorageWindow() +{ + delete mItems; +} + +void StorageWindow::logic() +{ + if (!isVisible()) + return; + + Window::logic(); + + if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed())) + { + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsBar->setProgress((float) + player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots); + + mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots)); + } +} + +void StorageWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "close") + { + close(); + } + else if (event.getId() == "store") + { + Item *item = inventoryWindow->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + addStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_ADD, this, item); + } + } + else if (event.getId() == "retrieve") + { + Item *item = mItems->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + removeStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item); + } + } +} + +void StorageWindow::mouseClicked(gcn::MouseEvent &event) +{ + Window::mouseClicked(event); + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + Item *item = mItems->getSelectedItem(); + + if (!item) { + mRetrieveButton->setEnabled(false); + return; + } + + mRetrieveButton->setEnabled(true); + + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = event.getX() + getX(); + const int my = event.getY() + getY(); + viewport->showPopup(mx, my, item); + } +} + +Item* StorageWindow::getSelectedItem() const +{ + return mItems->getSelectedItem(); +} + +void StorageWindow::addStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_MOVE_TO_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::removeStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CLOSE_STORAGE); +} diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h new file mode 100644 index 00000000..23142ac1 --- /dev/null +++ b/src/gui/storagewindow.h @@ -0,0 +1,105 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef STORAGEWINDOW_H +#define STORAGEWINDOW_H + +#include "window.h" + +#include "../inventory.h" + +#include +#include + +class Item; +class ItemContainer; +class Network; +class ProgressBar; +class TextBox; + +/** + * Storage dialog. + * + * \ingroup Interface + */ +class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener +{ + public: + /** + * Constructor. + */ + StorageWindow(Network *network, int invSize = (STORAGE_SIZE - 1)); + + /** + * Destructor. + */ + ~StorageWindow(); + + /** + * Logic (updates buttons and weight information). + */ + void logic(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Returns the selected item. + */ + Item* getSelectedItem() const; + + void mouseClicked(gcn::MouseEvent &event); + + /** + * Add the specified ammount of the specified item to storage + */ + void addStore(Item* item, int ammount); + + /** + * Remove the specified ammount of the specified item from storage + */ + void removeStore(Item* item, int ammount); + + void close(); + + private: + Network *mNetwork; + ItemContainer *mItems; + + std::string mSlots; + std::string mUsedSlots; + gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::ScrollArea *mInvenScroll; + + gcn::Label *mSlotsLabel; + + ProgressBar *mSlotsBar; + + int mMaxSlots; + + bool mItemDesc; +}; + +extern StorageWindow *storageWindow; + +#endif // STORAGEWINDOW_H diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index a12b94ed..76795688 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -49,8 +49,8 @@ TradeWindow::TradeWindow(Network *network): Window(_("Trade: You")), mNetwork(network), - mMyInventory(new Inventory(INVENTORY_SIZE)), - mPartnerInventory(new Inventory(INVENTORY_SIZE)) + mMyInventory(new Inventory(INVENTORY_SIZE, 2)), + mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); setDefaultSize(115, 227, 342, 209); diff --git a/src/gui/window.h b/src/gui/window.h index 0a0f4be9..a4f56e05 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -63,7 +63,7 @@ class Window : public gcn::Window, gcn::WidgetListener * @param skin The location where the window's skin XML can be found. */ Window(const std::string &caption = "Window", bool modal = false, - Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); + Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); /** * Destructor. Deletes all the added widgets. @@ -153,8 +153,7 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets flag to show a title or not. */ - void setShowTitle(bool flag) - { mShowTitle = flag; } + void setShowTitle(bool flag) { mShowTitle = flag; } /** * Sets whether the window is sticky. A sticky window will not have diff --git a/src/inventory.cpp b/src/inventory.cpp index 4053bc96..d72e0e4a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -34,8 +34,9 @@ struct SlotUsed : public std::unary_function } }; -Inventory::Inventory(int size): - mSize(size) +Inventory::Inventory(int size, int offset): + mSize(size), + mOffset(offset) { mItems = new Item*[mSize]; std::fill_n(mItems, mSize, (Item*) 0); @@ -51,7 +52,7 @@ Inventory::~Inventory() Item* Inventory::getItem(int index) const { - if (index < 0 || index >= INVENTORY_SIZE || !mItems[index] || mItems[index]->getQuantity() <= 0) + if (index < 0 || index >= mSize || !mItems[index] || mItems[index]->getQuantity() <= 0) return 0; return mItems[index]; @@ -127,7 +128,7 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() const { - Item **i = std::find_if(mItems + 2, mItems + mSize, + Item **i = std::find_if(mItems, mItems + mSize, std::not1(SlotUsed())); return (i == mItems + mSize) ? -1 : (i - mItems); } @@ -148,5 +149,5 @@ int Inventory::getLastUsedSlot() const int Inventory::getInventorySize() const { - return INVENTORY_SIZE - 2; + return mSize - mOffset; } diff --git a/src/inventory.h b/src/inventory.h index 3b3ec507..e23f7657 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -26,6 +26,7 @@ class Item; #define INVENTORY_SIZE 102 +#define STORAGE_SIZE 301 class Inventory { @@ -33,7 +34,7 @@ class Inventory /** * Constructor. */ - Inventory(int size); + Inventory(int size, int offset); /** * Destructor. @@ -111,6 +112,7 @@ class Inventory protected: Item **mItems; /**< The holder of items */ int mSize; /**< The max number of inventory items */ + int mOffset; /**< Offset used by the inventory */ }; #endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 76d13a4b..d6acc48f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -37,6 +37,7 @@ #include "text.h" #include "gui/gui.h" +#include "gui/storagewindow.h" #include "net/messageout.h" #include "net/protocol.h" @@ -74,8 +75,8 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): mTargetTime(-1), mLastAction(-1), mLastTarget(-1), mWalkingDir(0), mDestX(0), mDestY(0), - mInventory(new Inventory(INVENTORY_SIZE)), - mStorage(new Inventory(STORAGE_SIZE)) + mInventory(new Inventory(INVENTORY_SIZE, 2)), + mStorage(new Inventory(STORAGE_SIZE, 1)) { // Variable to keep the local player from doing certain actions before a map // is initialized. e.g. drawing a player's name using the TextManager, since @@ -694,3 +695,9 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height, mTargetCursor[index][size] = currentCursor; } +void LocalPlayer::setInStorage(bool inStorage) +{ + mInStorage = inStorage; + + storageWindow->setVisible(inStorage); +} diff --git a/src/localplayer.h b/src/localplayer.h index 2fb8c615..85868750 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -30,9 +30,6 @@ // TODO move into some sane place... #define MAX_SLOT 2 -#define INVENTORY_SIZE 102 -#define STORAGE_SIZE 301 - class Equipment; class FloorItem; class ImageSet; @@ -194,7 +191,7 @@ class LocalPlayer : public Player * Accessors for mInStorage */ bool getInStorage() { return mInStorage; } - void setInStorage(bool inStorage) { mInStorage = inStorage; } + void setInStorage(bool inStorage); /** * Sets the amount of XP. Shows XP gaining effect if the player is on diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index b0511080..553ec8fd 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -34,6 +34,7 @@ #include "../log.h" #include "../gui/chat.h" +#include "../gui/storagewindow.h" #include "../resources/iteminfo.h" @@ -72,7 +73,6 @@ void InventoryHandler::handleMessage(MessageIn *msg) { case SMSG_PLAYER_INVENTORY: case SMSG_PLAYER_STORAGE_ITEMS: - case SMSG_PLAYER_STORAGE_EQUIP: switch (msg->getId()) { case SMSG_PLAYER_INVENTORY: // Clear inventory - this will be a complete refresh @@ -86,11 +86,10 @@ void InventoryHandler::handleMessage(MessageIn *msg) * clear storage here */ storage->clear(); - logger->log("Received SMSG_PLAYER_STORAGE_ITEMS"); break; default: - logger->log("Received SMSG_PLAYER_STORAGE_EQUIP"); - break; + logger->log("HOW DID WE GET HERE?"); + return; } msg->readInt16(); // length number = (msg->getLength() - 4) / 18; @@ -100,17 +99,8 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemId = msg->readInt16(); itemType = msg->readInt8(); identified = msg->readInt8(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - amount = 1; - msg->readInt16(); // Equip Point? - } else { - amount = msg->readInt16(); - } + amount = msg->readInt16(); arrow = msg->readInt16(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - msg->readInt8(); // Attribute (broken) - msg->readInt8(); // Refine level - } for (int i = 0; i < 4; i++) cards[i] = msg->readInt16(); @@ -130,6 +120,29 @@ void InventoryHandler::handleMessage(MessageIn *msg) } break; + case SMSG_PLAYER_STORAGE_EQUIP: + msg->readInt16(); // length + number = (msg->getLength() - 4) / 20; + + for (int loop = 0; loop < number; loop++) { + index = msg->readInt16(); + itemId = msg->readInt16(); + itemType = msg->readInt8(); + identified = msg->readInt8(); + amount = 1; + msg->readInt16(); // Equip Point? + msg->readInt16(); // Another Equip Point? + msg->readInt8(); // Attribute (broken) + msg->readInt8(); // Refine level + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d", + index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]); + storage->setItem(index, itemId, amount, false); + } + break; + case SMSG_PLAYER_INVENTORY_ADD: index = msg->readInt16(); amount = msg->readInt16(); @@ -203,35 +216,54 @@ void InventoryHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STORAGE_STATUS: /* - * Basic slots used vs total slots info - * We don't really need this information, but this is - * the closest we get to an "Open Storage" packet - * from the server. It always comes after the two - * SMSG_PLAYER_STORAGE_... packets that update - * storage contents. + * This is the closest we get to an "Open Storage" packet from the + * server. It always comes after the two SMSG_PLAYER_STORAGE_... + * packets that update storage contents.. */ - logger->log("Received SMSG_PLAYER_STORAGE_STATUS"); player_node->setInStorage(true); + msg->readInt16(); // Storage capacity + msg->readInt16(); // Used count break; case SMSG_PLAYER_STORAGE_ADD: /* * Move an item into storage */ + index = msg->readInt16(); + amount = msg->readInt32(); + itemId = msg->readInt16(); + identified = msg->readInt8(); + msg->readInt8(); // attribute + msg->readInt8(); // refine + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + if (Item *item = storage->getItem(index)) { + item->setId(itemId); + item->increaseQuantity(amount); + } else { + storage->setItem(index, itemId, amount, false); + } break; case SMSG_PLAYER_STORAGE_REMOVE: /* - * Move an item out of storage - */ + * Move an item out of storage + */ + index = msg->readInt16(); + amount = msg->readInt16(); + if (Item *item = storage->getItem(index)) { + item->increaseQuantity(-amount); + if (item->getQuantity() == 0) + storage->removeItemAt(index); + } break; case SMSG_PLAYER_STORAGE_CLOSE: /* - * Storage access has been closed - */ + * Storage access has been closed + */ player_node->setInStorage(false); - logger->log("Received SMSG_PLAYER_STORAGE_CLOSE"); break; } } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 232cf075..6533ac1e 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -39,6 +39,7 @@ #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" +#include "../gui/storagewindow.h" #include "../gui/viewport.h" #include "../utils/stringutils.h" @@ -92,6 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); + if (storageWindow->isVisible()) storageWindow->close(); current_npc = 0; } } deathListener; -- cgit v1.2.3-70-g09d2 From 40883938ceb60b0999f9b693dadbe2239e83f139 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 9 Mar 2009 01:23:14 -0600 Subject: Got rid of an ugly and unified interface breaking cancel button in favor of adding overridable close functionality to the Window class. Now, if you need a close button, but need to do something different, or in addition to the Window close functionality, you can override it and do that action. Signed-off-by: Ira Rice --- src/gui/storagewindow.cpp | 9 ++------- src/gui/storagewindow.h | 2 +- src/gui/window.cpp | 7 ++++++- src/gui/window.h | 2 ++ src/inventory.cpp | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/gui/storagewindow.cpp') diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 856f9166..d3bc7ef8 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -59,11 +59,11 @@ StorageWindow::StorageWindow(Network *network, int invSize): { setWindowName("Storage"); setResizable(true); + setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 375, 300); - mCancelButton = new Button(_("Close"), "close", this); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -85,7 +85,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): place(0, 0, mSlotsLabel).setPadding(3); place(1, 0, mSlotsBar, 3); place(0, 1, mInvenScroll, 4, 4); - place(0, 5, mCancelButton); place(2, 5, mStoreButton); place(3, 5, mRetrieveButton); @@ -121,11 +120,7 @@ void StorageWindow::logic() void StorageWindow::action(const gcn::ActionEvent &event) { - if (event.getId() == "close") - { - close(); - } - else if (event.getId() == "store") + if (event.getId() == "store") { Item *item = inventoryWindow->getSelectedItem(); diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 23142ac1..86451bfe 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -88,7 +88,7 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener std::string mSlots; std::string mUsedSlots; - gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::Button *mStoreButton, *mRetrieveButton; gcn::ScrollArea *mInvenScroll; gcn::Label *mSlotsLabel; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0869368d..2b422f86 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -328,7 +328,7 @@ void Window::mousePressed(gcn::MouseEvent &event) if (closeButtonRect.isPointInRect(x, y)) { - setVisible(false); + close(); } } @@ -337,6 +337,11 @@ void Window::mousePressed(gcn::MouseEvent &event) } } +void Window::close() +{ + setVisible(false); +} + void Window::mouseReleased(gcn::MouseEvent &event) { if (mGrip && mouseResize) diff --git a/src/gui/window.h b/src/gui/window.h index a4f56e05..3a92ac17 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -276,6 +276,8 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + virtual void close(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; diff --git a/src/inventory.cpp b/src/inventory.cpp index d72e0e4a..3d1a4786 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -128,7 +128,7 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() const { - Item **i = std::find_if(mItems, mItems + mSize, + Item **i = std::find_if(mItems + mOffset, mItems + mSize, std::not1(SlotUsed())); return (i == mItems + mSize) ? -1 : (i - mItems); } -- 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/storagewindow.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 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/storagewindow.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 a3d675e1dde4c80e687c7264bc86c6189c13dddb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 11:34:43 -0600 Subject: Don't move stuff from inventory when not visible --- src/gui/itemshortcutcontainer.cpp | 6 +++--- src/gui/storagewindow.cpp | 2 ++ src/gui/trade.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui/storagewindow.cpp') diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 603e7e50..67525140 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" #include "viewport.h" @@ -184,9 +185,8 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) + if (itemShortcut->isItemSelected() && inventoryWindow->isVisible()) { itemShortcut->setItem(index); itemShortcut->setItemSelected(-1); @@ -247,7 +247,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item) + if (item && inventoryWindow->isVisible()) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 2b8ab8f3..5981f121 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -126,6 +126,8 @@ void StorageWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "store") { + if (!inventoryWindow->isVisible()) return; + Item *item = inventoryWindow->getSelectedItem(); if (!item) diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 2deabbf2..30604d6b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -240,6 +240,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (event.getId() == "add") { + if (!inventoryWindow->isVisible()) return; + if (!item) return; -- cgit v1.2.3-70-g09d2 From a34d8a88df817371823e8e036b3a9208f8d5ba85 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 11:34:43 -0600 Subject: Don't move stuff from inventory when not visible --- src/gui/itemshortcutcontainer.cpp | 6 +++--- src/gui/storagewindow.cpp | 2 ++ src/gui/trade.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui/storagewindow.cpp') diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index abe81537..cb709227 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -20,6 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" #include "viewport.h" @@ -168,9 +169,8 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) + if (itemShortcut->isItemSelected() && inventoryWindow->isVisible()) { itemShortcut->setItem(index); itemShortcut->setItemSelected(-1); @@ -231,7 +231,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item) + if (item && inventoryWindow->isVisible()) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index ca7a547f..6a813bc4 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -121,6 +121,8 @@ void StorageWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "store") { + if (!inventoryWindow->isVisible()) return; + Item *item = inventoryWindow->getSelectedItem(); if (!item) diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index a28ff0f9..caae33c0 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -239,6 +239,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (event.getId() == "add") { + if (!inventoryWindow->isVisible()) return; + if (!item) return; -- cgit v1.2.3-70-g09d2 From 3575c7a606c2d24c0d444e9999892c0390fa5ae8 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 13:21:35 -0600 Subject: Made a label class derived from the guichan label class which utilizes the palette colors. While technically, this can be accomplished through other means, it's rather clumsy overall, and is prone to introducing in programmer errors. This commit finally catches every case where text is used, and applies the text color from the color dialog to each of them appropriately. Signed-off-by: Ira Rice --- aethyra.cbp | 2 ++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/gui/button.cpp | 3 +- src/gui/buy.cpp | 11 +++---- src/gui/char_select.cpp | 17 +++++----- src/gui/checkbox.cpp | 13 ++++++++ src/gui/checkbox.h | 5 +++ src/gui/connection.cpp | 5 ++- src/gui/debugwindow.cpp | 15 +++++---- src/gui/inventorywindow.cpp | 7 ++--- src/gui/login.cpp | 13 ++++---- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/register.cpp | 19 +++++------ src/gui/sell.cpp | 11 +++---- src/gui/setup_audio.cpp | 10 +++--- src/gui/setup_colors.cpp | 18 +++++++---- src/gui/setup_joystick.cpp | 5 ++- src/gui/setup_players.cpp | 9 +++--- src/gui/setup_video.cpp | 23 +++++++------- src/gui/skill.cpp | 11 +++---- src/gui/status.cpp | 77 +++++++++++++++++---------------------------- src/gui/storagewindow.cpp | 5 ++- src/gui/textfield.cpp | 29 +++++++---------- src/gui/trade.cpp | 9 +++--- src/gui/updatewindow.cpp | 6 ++-- src/gui/widgets/tab.cpp | 10 ++++-- src/gui/window.cpp | 3 +- src/main.cpp | 7 ++--- 30 files changed, 173 insertions(+), 176 deletions(-) (limited to 'src/gui/storagewindow.cpp') diff --git a/aethyra.cbp b/aethyra.cbp index e88f491d..6e71375c 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -168,6 +168,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7025c2c4..93bac9ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,6 +117,8 @@ SET(SRCS gui/itemshortcutcontainer.h\ gui/item_amount.cpp gui/item_amount.h + gui/label.cpp + gui/label.h gui/linkhandler.h gui/listbox.cpp gui/listbox.h diff --git a/src/Makefile.am b/src/Makefile.am index 069b12f2..5029697a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,6 +69,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/itemshortcutcontainer.h \ gui/item_amount.cpp \ gui/item_amount.h \ + gui/label.cpp \ + gui/label.h \ gui/linkhandler.h \ gui/listbox.cpp \ gui/listbox.h \ diff --git a/src/gui/button.cpp b/src/gui/button.cpp index dbb5f568..592edce5 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -24,6 +24,7 @@ #include #include "button.h" +#include "palette.h" #include "../configuration.h" #include "../graphics.h" @@ -151,7 +152,7 @@ void Button::draw(gcn::Graphics *graphics) static_cast(graphics)-> drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); - graphics->setColor(getForegroundColor()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); int textX; int textY = getHeight() / 2 - getFont()->getHeight() / 2; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 2b5aeeb7..367a041e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "buy.h" +#include "label.h" #include "scrollarea.h" #include "shop.h" #include "shoplistbox.h" @@ -54,14 +53,14 @@ BuyDialog::BuyDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); - mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); + mQuantityLabel = new Label("0"); + mMoneyLabel = new Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mBuyButton = new Button(_("Buy"), "buy", this); mQuitButton = new Button(_("Quit"), "quit", this); - mItemDescLabel = new gcn::Label(strprintf(_("Description: %s"), "")); - mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); + mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index fa0594d6..f88736c1 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -24,11 +24,10 @@ #include -#include - #include "button.h" #include "char_select.h" #include "confirm_dialog.h" +#include "label.h" #include "ok_dialog.h" #include "playerbox.h" #include "textfield.h" @@ -90,10 +89,10 @@ CharSelectDialog::CharSelectDialog(Network *network, mPlayerBox = new PlayerBox; mPlayerBox->setWidth(74); - mNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); - mLevelLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); - mJobLevelLabel = new gcn::Label(strprintf(_("Job Level: %d"), 0)); - mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); + mNameLabel = new Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); + mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %d"), 0)); const std::string tempString = getFont()->getWidth(_("New")) < getFont()->getWidth(_("Delete")) ? @@ -259,13 +258,13 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(), rand() % numberOfHairColors); mNameField = new TextField(""); - mNameLabel = new gcn::Label(_("Name:")); + mNameLabel = new Label(_("Name:")); mNextHairColorButton = new Button(">", "nextcolor", this); mPrevHairColorButton = new Button("<", "prevcolor", this); - mHairColorLabel = new gcn::Label(_("Hair Color:")); + mHairColorLabel = new Label(_("Hair Color:")); mNextHairStyleButton = new Button(">", "nextstyle", this); mPrevHairStyleButton = new Button("<", "prevstyle", this); - mHairStyleLabel = new gcn::Label(_("Hair Style:")); + mHairStyleLabel = new Label(_("Hair Style:")); mCreateButton = new Button(_("Create"), "create", this); mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayerBox = new PlayerBox(mPlayer); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index 413c28d0..f6cce581 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -21,6 +21,7 @@ */ #include "checkbox.h" +#include "palette.h" #include "../configuration.h" #include "../graphics.h" @@ -69,6 +70,18 @@ CheckBox::~CheckBox() } } +void CheckBox::draw(gcn::Graphics* graphics) +{ + drawBox(graphics); + + graphics->setFont(getFont()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); + + const int h = getHeight() + getHeight() / 2; + + graphics->drawText(getCaption(), h - 2, 0); +} + void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box; diff --git a/src/gui/checkbox.h b/src/gui/checkbox.h index 260ed3a1..93b62b9d 100644 --- a/src/gui/checkbox.h +++ b/src/gui/checkbox.h @@ -45,6 +45,11 @@ class CheckBox : public gcn::CheckBox */ ~CheckBox(); + /** + * Draws the caption, then calls drawBox to draw the check box. + */ + void draw(gcn::Graphics* graphics); + /** * Draws the check box, not the caption. */ diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index f6033cd7..d4a2b18a 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -22,10 +22,9 @@ #include -#include - #include "button.h" #include "connection.h" +#include "label.h" #include "progressbar.h" #include "../main.h" @@ -47,7 +46,7 @@ ConnectionDialog::ConnectionDialog(): Button *cancelButton = new Button(_("Cancel"), "cancelButton", &listener); mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128); - gcn::Label *label = new gcn::Label(_("Connecting...")); + gcn::Label *label = new Label(_("Connecting...")); cancelButton->setPosition(5, 100 - 5 - cancelButton->getHeight()); mProgressBar->setPosition(5, cancelButton->getY() - 25); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 71855977..999e00a2 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "debugwindow.h" +#include "label.h" #include "viewport.h" #include "widgets/layout.h" @@ -43,12 +42,12 @@ DebugWindow::DebugWindow(): setCloseButton(true); setDefaultSize(400, 60, ImageRect::CENTER); - mFPSLabel = new gcn::Label("0 FPS"); - mMusicFileLabel = new gcn::Label("Music: "); - mMapLabel = new gcn::Label("Map: "); - mMiniMapLabel = new gcn::Label("Mini-Map: "); - mTileMouseLabel = new gcn::Label("Mouse: 0, 0"); - mParticleCountLabel = new gcn::Label("Particle count: 0"); + mFPSLabel = new Label("0 FPS"); + mMusicFileLabel = new Label("Music: "); + mMapLabel = new Label("Map: "); + mMiniMapLabel = new Label("Mini-Map: "); + mTileMouseLabel = new Label("Mouse: 0, 0"); + mParticleCountLabel = new Label("Particle count: 0"); place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 7e75411e..98916c07 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -25,12 +25,11 @@ #include #include -#include - #include "button.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "viewport.h" @@ -82,8 +81,8 @@ InventoryWindow::InventoryWindow(int invSize): mMaxWeight = toString(player_node->mMaxWeight); mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed()); - mSlotsLabel = new gcn::Label(_("Slots: ")); - mWeightLabel = new gcn::Label(_("Weight: ")); + mSlotsLabel = new Label(_("Slots: ")); + mWeightLabel = new Label(_("Weight: ")); mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); mWeightBar = new ProgressBar(1.0f, 100, 20, 0, 0, 255); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index ce13aaf0..7b9829fb 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "login.h" #include "ok_dialog.h" @@ -49,11 +48,11 @@ static const int FIELD_WIDTH = LOGIN_DIALOG_WIDTH - 70; LoginDialog::LoginDialog(LoginData *loginData): Window(_("Login")), mLoginData(loginData) { - gcn::Label *userLabel = new gcn::Label(_("Name:")); - gcn::Label *passLabel = new gcn::Label(_("Password:")); - gcn::Label *serverLabel = new gcn::Label(_("Server:")); - gcn::Label *portLabel = new gcn::Label(_("Port:")); - gcn::Label *dropdownLabel = new gcn::Label(_("Recent:")); + gcn::Label *userLabel = new Label(_("Name:")); + gcn::Label *passLabel = new Label(_("Password:")); + gcn::Label *serverLabel = new Label(_("Server:")); + gcn::Label *portLabel = new Label(_("Port:")); + gcn::Label *dropdownLabel = new Label(_("Recent:")); std::vector dfltServer; dfltServer.push_back("www.aethyra.org"); dfltServer.push_back("www.aethyra.org"); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index e007dd5c..c155cfe2 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -88,6 +88,7 @@ Palette::Palette() : addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); + addColor(TAB_HIGHLIGHT, 0xff0000, STATIC, indent + _("Tab Highlight")); addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item too expensive")); diff --git a/src/gui/palette.h b/src/gui/palette.h index a91d3605..4d8f7f11 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -53,6 +53,7 @@ class Palette : public gcn::ListModel ENTRY(OUTLINE)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ + ENTRY(TAB_HIGHLIGHT)\ ENTRY(SHOP_WARNING)\ ENTRY(CHAT)\ ENTRY(GM)\ diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 13928e41..63a0d29c 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "../configuration.h" #include "../log.h" #include "../logindata.h" @@ -29,6 +27,7 @@ #include "button.h" #include "checkbox.h" +#include "label.h" #include "login.h" #include "ok_dialog.h" #include "passwordfield.h" @@ -47,7 +46,8 @@ * to the field which contained wrong data when the Ok button was pressed on * the error notice. */ -class WrongDataNoticeListener : public gcn::ActionListener { +class WrongDataNoticeListener : public gcn::ActionListener +{ public: void setTarget(gcn::TextField *textField); void action(const gcn::ActionEvent &event); @@ -63,22 +63,19 @@ void WrongDataNoticeListener::setTarget(gcn::TextField *textField) void WrongDataNoticeListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") - { mTarget->requestFocus(); - } } - RegisterDialog::RegisterDialog(LoginData *loginData): Window(_("Register")), mWrongDataNoticeListener(new WrongDataNoticeListener), mLoginData(loginData) { - gcn::Label *userLabel = new gcn::Label(_("Name:")); - gcn::Label *passwordLabel = new gcn::Label(_("Password:")); - gcn::Label *confirmLabel = new gcn::Label(_("Confirm:")); - gcn::Label *serverLabel = new gcn::Label(_("Server:")); - gcn::Label *portLabel = new gcn::Label(_("Port:")); + gcn::Label *userLabel = new Label(_("Name:")); + gcn::Label *passwordLabel = new Label(_("Password:")); + gcn::Label *confirmLabel = new Label(_("Confirm:")); + gcn::Label *serverLabel = new Label(_("Server:")); + gcn::Label *portLabel = new Label(_("Port:")); mUserField = new TextField(loginData->username); mPasswordField = new PasswordField(loginData->password); mConfirmField = new PasswordField; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 397e29a6..b780b02b 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "scrollarea.h" #include "sell.h" #include "shop.h" @@ -56,15 +55,15 @@ SellDialog::SellDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); - mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label( + mQuantityLabel = new Label("0"); + mMoneyLabel = new Label( strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mSellButton = new Button(_("Sell"), "sell", this); mQuitButton = new Button(_("Quit"), "quit", this); - mItemDescLabel = new gcn::Label(strprintf(_("Description: %s"), "")); - mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); + mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 3c26f14b..08eda848 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "checkbox.h" +#include "label.h" #include "ok_dialog.h" #include "setup_audio.h" #include "slider.h" @@ -45,8 +44,8 @@ Setup_Audio::Setup_Audio(): { setOpaque(false); - gcn::Label *sfxLabel = new gcn::Label(_("Sfx volume")); - gcn::Label *musicLabel = new gcn::Label(_("Music volume")); + gcn::Label *sfxLabel = new Label(_("Sfx volume")); + gcn::Label *musicLabel = new Label(_("Music volume")); mSfxSlider->setActionEventId("sfx"); mMusicSlider->setActionEventId("music"); @@ -80,7 +79,8 @@ void Setup_Audio::apply() if (mSoundCheckBox->isSelected()) { config.setValue("sound", 1); - try { + try + { sound.init(); } catch (const char *err) diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 91b20f5f..09c6a3a9 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -23,12 +23,12 @@ #include #include -#include #include #include "browserbox.h" #include "gui.h" #include "itemlinkhandler.h" +#include "label.h" #include "listbox.h" #include "palette.h" #include "scrollarea.h" @@ -71,7 +71,7 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); - mGradTypeLabel = new gcn::Label(_("Type: ")); + mGradTypeLabel = new Label(_("Type: ")); mGradTypeSlider = new Slider(0, 2); mGradTypeSlider->setWidth(160); @@ -80,9 +80,9 @@ Setup_Colors::Setup_Colors() : mGradTypeSlider->addActionListener(this); mGradTypeSlider->setEnabled(false); - mGradTypeText = new gcn::Label(); + mGradTypeText = new Label(); - mRedLabel = new gcn::Label(_("Red: ")); + mRedLabel = new Label(_("Red: ")); mRedText = new TextField(); mRedText->setWidth(40); @@ -98,7 +98,7 @@ Setup_Colors::Setup_Colors() : mRedSlider->addActionListener(this); mRedSlider->setEnabled(false); - mGreenLabel = new gcn::Label(_("Green: ")); + mGreenLabel = new Label(_("Green: ")); mGreenText = new TextField(); mGreenText->setWidth(40); @@ -114,7 +114,7 @@ Setup_Colors::Setup_Colors() : mGreenSlider->addActionListener(this); mGreenSlider->setEnabled(false); - mBlueLabel = new gcn::Label(_("Blue: ")); + mBlueLabel = new Label(_("Blue: ")); mBlueText = new TextField(); mBlueText->setWidth(40); @@ -194,6 +194,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(type == Palette::SHADOW); mTextPreview->setOutline(type == Palette::OUTLINE); break; + case Palette::TAB_HIGHLIGHT: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; case Palette::BACKGROUND: case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 5bbaa368..4d80e0dd 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "setup_joystick.h" #include "widgets/layouthelper.h" @@ -36,7 +35,7 @@ extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): - mCalibrateLabel(new gcn::Label(_("Press the button to start calibration"))), + mCalibrateLabel(new Label(_("Press the button to start calibration"))), mCalibrateButton(new Button(_("Calibrate"), "calibrate", this)), mJoystickEnabled(new CheckBox(_("Enable joystick"))) { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index faf80640..05748000 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -23,10 +23,9 @@ #include #include -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "ok_dialog.h" #include "scrollarea.h" @@ -138,7 +137,7 @@ public: for (unsigned int r = 0; r < player_names->size(); ++r) { std::string name = (*player_names)[r]; - gcn::Widget *widget = new gcn::Label(name); + gcn::Widget *widget = new Label(name); mWidgets.push_back(widget); gcn::ListModel *playerRelation = new PlayerRelationListModel(); @@ -248,7 +247,7 @@ Setup_Players::Setup_Players(): for (int i = 0; i < COLUMNS_NR; i++) { mPlayerTableTitleModel->set(0, i, - new gcn::Label(gettext(table_titles[i]))); + new Label(gettext(table_titles[i]))); } mPlayerTitleTable->setLinewiseSelection(true); @@ -258,7 +257,7 @@ Setup_Players::Setup_Players(): mPlayerTable->setLinewiseSelection(true); mPlayerTable->addActionListener(this); - gcn::Label *ignore_action_label = new gcn::Label(_("When ignoring:")); + gcn::Label *ignore_action_label = new Label(_("When ignoring:")); mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY); mIgnoreActionChoicesBox->addActionListener(this); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 59eb4096..d1d7e4f8 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -27,9 +27,8 @@ #include #include -#include - #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "ok_dialog.h" #include "scrollarea.h" @@ -123,7 +122,7 @@ Setup_Video::Setup_Video(): mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), mNameCheckBox(new CheckBox(_("Show name"), mNameEnabled)), mSpeechSlider(new Slider(0, 3)), - mSpeechLabel(new gcn::Label("")), + mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), mFpsSlider(new Slider(10, 200)), @@ -136,11 +135,11 @@ Setup_Video::Setup_Video(): mScrollRadiusField(new TextField), mOverlayDetail((int) config.getValue("OverlayDetail", 2)), mOverlayDetailSlider(new Slider(0, 2)), - mOverlayDetailField(new gcn::Label("")), + mOverlayDetailField(new Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")), - mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mParticleDetailField(new Label("")), + mPickupNotifyLabel(new Label(_("Show pickup notification"))), mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)) @@ -150,12 +149,12 @@ Setup_Video::Setup_Video(): ScrollArea *scrollArea = new ScrollArea(mModeList); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - speechLabel = new gcn::Label(_("Overhead text")); - alphaLabel = new gcn::Label(_("Gui opacity")); - scrollRadiusLabel = new gcn::Label(_("Scroll radius")); - scrollLazinessLabel = new gcn::Label(_("Scroll laziness")); - overlayDetailLabel = new gcn::Label(_("Ambient FX")); - particleDetailLabel = new gcn::Label(_("Particle Detail")); + speechLabel = new Label(_("Overhead text")); + alphaLabel = new Label(_("Gui opacity")); + scrollRadiusLabel = new Label(_("Scroll radius")); + scrollLazinessLabel = new Label(_("Scroll laziness")); + overlayDetailLabel = new Label(_("Ambient FX")); + particleDetailLabel = new Label(_("Particle Detail")); mModeList->setEnabled(true); #ifndef USE_OPENGL diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index a8250fce..64214ff5 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "listbox.h" #include "scrollarea.h" #include "skill.h" @@ -100,13 +99,13 @@ public: info = &fakeSkillInfo; sprintf(tmp, "%c%s", info->modifiable? ' ' : '*', info->name.c_str()); - gcn::Label *name_label = new gcn::Label(tmp); + gcn::Label *name_label = new Label(tmp); sprintf(tmp, "Lv:%i", skill->lv); - gcn::Label *lv_label = new gcn::Label(tmp); + gcn::Label *lv_label = new Label(tmp); sprintf(tmp, "Sp:%i", skill->sp); - gcn::Label *sp_label = new gcn::Label(tmp); + gcn::Label *sp_label = new Label(tmp); set(i, 0, name_label); set(i, 1, lv_label); @@ -141,7 +140,7 @@ SkillDialog::SkillDialog(): setMinWidth(200); ScrollArea *skillScrollArea = new ScrollArea(mTable); - mPointsLabel = new gcn::Label(strprintf(_("Skill points: %d"), 0)); + mPointsLabel = new Label(strprintf(_("Skill points: %d"), 0)); mIncButton = new Button(_("Up"), _("inc"), this); mUseButton = new Button(_("Use"), _("use"), this); mUseButton->setEnabled(false); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index e534edb8..3fd62b83 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "progressbar.h" #include "status.h" #include "windowcontainer.h" @@ -47,20 +46,20 @@ StatusWindow::StatusWindow(LocalPlayer *player): // Status Part // ---------------------- - mLvlLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); - mJobLvlLabel = new gcn::Label(strprintf(_("Job: %d"), 0)); - mGpLabel = new gcn::Label(strprintf(_("Money: %d GP"), 0)); + mLvlLabel = new Label(strprintf(_("Level: %d"), 0)); + mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0)); + mGpLabel = new Label(strprintf(_("Money: %d GP"), 0)); - mHpLabel = new gcn::Label(_("HP:")); + mHpLabel = new Label(_("HP:")); mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); - mXpLabel = new gcn::Label(_("Exp:")); + mXpLabel = new Label(_("Exp:")); mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211); - mMpLabel = new gcn::Label(_("MP:")); + mMpLabel = new Label(_("MP:")); mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230); - mJobLabel = new gcn::Label(_("Job:")); + mJobLabel = new Label(_("Job:")); mJobBar = new ProgressBar(1.0f, 80, 15, 220, 135, 203); // ---------------------- @@ -68,35 +67,35 @@ StatusWindow::StatusWindow(LocalPlayer *player): // ---------------------- // Static Labels - gcn::Label *mStatsTitleLabel = new gcn::Label(_("Stats")); - gcn::Label *mStatsTotalLabel = new gcn::Label(_("Total")); - gcn::Label *mStatsCostLabel = new gcn::Label(_("Cost")); + gcn::Label *mStatsTitleLabel = new Label(_("Stats")); + gcn::Label *mStatsTotalLabel = new Label(_("Total")); + gcn::Label *mStatsCostLabel = new Label(_("Cost")); mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER); // Derived Stats - mStatsAttackLabel = new gcn::Label(_("Attack:")); - mStatsDefenseLabel= new gcn::Label(_("Defense:")); - mStatsMagicAttackLabel = new gcn::Label(_("M.Attack:")); - mStatsMagicDefenseLabel = new gcn::Label(_("M.Defense:")); - mStatsAccuracyLabel = new gcn::Label(_("% Accuracy:")); - mStatsEvadeLabel = new gcn::Label(_("% Evade:")); - mStatsReflexLabel = new gcn::Label(_("% Reflex:")); - - mStatsAttackPoints = new gcn::Label; - mStatsDefensePoints = new gcn::Label; - mStatsMagicAttackPoints = new gcn::Label; - mStatsMagicDefensePoints = new gcn::Label; - mStatsAccuracyPoints = new gcn::Label; - mStatsEvadePoints = new gcn::Label; - mStatsReflexPoints = new gcn::Label; + mStatsAttackLabel = new Label(_("Attack:")); + mStatsDefenseLabel= new Label(_("Defense:")); + mStatsMagicAttackLabel = new Label(_("M.Attack:")); + mStatsMagicDefenseLabel = new Label(_("M.Defense:")); + mStatsAccuracyLabel = new Label(_("% Accuracy:")); + mStatsEvadeLabel = new Label(_("% Evade:")); + mStatsReflexLabel = new Label(_("% Reflex:")); + + mStatsAttackPoints = new Label; + mStatsDefensePoints = new Label; + mStatsMagicAttackPoints = new Label; + mStatsMagicDefensePoints = new Label; + mStatsAccuracyPoints = new Label; + mStatsEvadePoints = new Label; + mStatsReflexPoints = new Label; // New labels for (int i = 0; i < 6; i++) { - mStatsLabel[i] = new gcn::Label("0"); + mStatsLabel[i] = new Label("0"); mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER); - mStatsDisplayLabel[i] = new gcn::Label; - mPointsLabel[i] = new gcn::Label("0"); + mStatsDisplayLabel[i] = new Label; + mPointsLabel[i] = new Label("0"); mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER); } mRemainingStatsPointsLabel = new gcn::Label; @@ -185,17 +184,11 @@ void StatusWindow::update() // HP Bar coloration if (mPlayer->mHp < int(mPlayer->mMaxHp / 3)) - { mHpBar->setColor(223, 32, 32); // Red - } else if (mPlayer->mHp < int((mPlayer->mMaxHp / 3) * 2)) - { mHpBar->setColor(230, 171, 34); // Orange - } else - { mHpBar->setColor(0, 171, 34); // Green - } mHpBar->setProgress((float) mPlayer->mHp / (float) mPlayer->mMaxHp); mMpBar->setProgress((float) mPlayer->mMp / (float) mPlayer->mMaxMp); @@ -285,28 +278,16 @@ void StatusWindow::action(const gcn::ActionEvent &event) if (event.getId().length() == 3) { if (event.getId() == "STR") - { player_node->raiseAttribute(LocalPlayer::STR); - } if (event.getId() == "AGI") - { player_node->raiseAttribute(LocalPlayer::AGI); - } if (event.getId() == "VIT") - { player_node->raiseAttribute(LocalPlayer::VIT); - } if (event.getId() == "INT") - { player_node->raiseAttribute(LocalPlayer::INT); - } if (event.getId() == "DEX") - { player_node->raiseAttribute(LocalPlayer::DEX); - } if (event.getId() == "LUK") - { player_node->raiseAttribute(LocalPlayer::LUK); - } } } diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 6a813bc4..5036fc15 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -24,12 +24,11 @@ #include #include -#include - #include "button.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "storagewindow.h" @@ -75,7 +74,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); - mSlotsLabel = new gcn::Label(_("Slots: ")); + mSlotsLabel = new Label(_("Slots: ")); mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 054bc405..257ddaa1 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -22,6 +22,7 @@ #include +#include "palette.h" #include "sdlinput.h" #include "textfield.h" @@ -55,8 +56,10 @@ TextField::TextField(const std::string& text): int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { skin.grid[a] = textbox->getSubImage( gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, @@ -77,9 +80,7 @@ TextField::~TextField() instances--; if (instances == 0) - { for_each(skin.grid, skin.grid + 9, dtor()); - } } void TextField::draw(gcn::Graphics *graphics) @@ -90,11 +91,11 @@ void TextField::draw(gcn::Graphics *graphics) if (isFocused()) { drawCaret(graphics, - getFont()->getWidth(mText.substr(0, mCaretPosition)) - - mXScroll); + getFont()->getWidth(mText.substr(0, mCaretPosition)) - + mXScroll); } - graphics->setColor(getForegroundColor()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->setFont(getFont()); graphics->drawText(mText, 1 - mXScroll, 1); @@ -102,9 +103,7 @@ void TextField::draw(gcn::Graphics *graphics) { mAlpha = config.getValue("guialpha", 0.8); for (int a = 0; a < 9; a++) - { skin.grid[a]->setAlpha(mAlpha); - } } } @@ -122,9 +121,8 @@ void TextField::setNumeric(bool numeric) { mNumeric = numeric; if (!numeric) - { return; - } + const char *text = mText.c_str(); for (const char *textPtr = text; *textPtr; ++textPtr) { @@ -139,18 +137,15 @@ void TextField::setNumeric(bool numeric) int TextField::getValue() const { if (!mNumeric) - { return 0; - } + int value = atoi(mText.c_str()); if (value < mMinimum) - { return mMinimum; - } + if (value > mMaximum) - { return mMaximum; - } + return value; } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index caae33c0..bae0b651 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -22,13 +22,12 @@ #include -#include - #include "button.h" #include "chat.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "scrollarea.h" #include "textfield.h" #include "trade.h" @@ -47,7 +46,7 @@ #include "../utils/stringutils.h" TradeWindow::TradeWindow(Network *network): - Window(_("Trade: You")), + Window("Trade"), mNetwork(network), mMyInventory(new Inventory(INVENTORY_SIZE, 2)), mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) @@ -78,8 +77,8 @@ TradeWindow::TradeWindow(Network *network): mPartnerScroll = new ScrollArea(mPartnerItemContainer); - mMoneyLabel = new gcn::Label(strprintf(_("You get %d GP."), 0)); - mMoneyLabel2 = new gcn::Label(_("You give:")); + mMoneyLabel = new Label(strprintf(_("You get %d GP."), 0)); + mMoneyLabel2 = new Label(_("You give:")); mMoneyField = new TextField; mMoneyField->setWidth(50); diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 81dcb047..927d6eaf 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -25,13 +25,11 @@ #include #include -#include - -// Curl should be included after Guichan to avoid Windows redefinitions #include #include "browserbox.h" #include "button.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "updatewindow.h" @@ -110,7 +108,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mBrowserBox = new BrowserBox(); mScrollArea = new ScrollArea(mBrowserBox); - mLabel = new gcn::Label(_("Connecting...")); + mLabel = new Label(_("Connecting...")); mProgressBar = new ProgressBar(0.0, 310, 20, 168, 116, 31); mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayButton = new Button(_("Play"), "play", this); diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 97f6010c..942ad3ef 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -25,6 +25,8 @@ #include "tab.h" #include "tabbedarea.h" +#include "../palette.h" + #include "../../configuration.h" #include "../../graphics.h" @@ -124,13 +126,17 @@ void Tab::draw(gcn::Graphics *graphics) { mode = TAB_SELECTED; // if tab is selected, it doesnt need to highlight activity - mLabel->setForegroundColor(gcn::Color(0, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); mHighlighted = false; } else if (mHighlighted) { mode = TAB_HIGHLIGHTED; - mLabel->setForegroundColor(gcn::Color(255, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT)); + } + else + { + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f6d23950..144357ca 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -27,6 +27,7 @@ #include #include "gui.h" +#include "palette.h" #include "skin.h" #include "window.h" #include "windowcontainer.h" @@ -153,7 +154,7 @@ void Window::draw(gcn::Graphics *graphics) // Draw title if (mShowTitle) { - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(guiPalette->getColor(Palette::TEXT)); g->setFont(getFont()); g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } diff --git a/src/main.cpp b/src/main.cpp index bed297de..60a4d500 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,8 +29,6 @@ #include -#include - #include #include @@ -57,6 +55,7 @@ #include "gui/char_server.h" #include "gui/char_select.h" #include "gui/gui.h" +#include "gui/label.h" #include "gui/login.h" #include "gui/ok_dialog.h" #include "gui/palette.h" @@ -776,11 +775,11 @@ int main(int argc, char *argv[]) gcn::Container *top = static_cast(gui->getTop()); #ifdef PACKAGE_VERSION - gcn::Label *versionLabel = new gcn::Label(PACKAGE_VERSION); + gcn::Label *versionLabel = new Label(PACKAGE_VERSION); top->add(versionLabel, 2, 2); #endif ProgressBar *progressBar = new ProgressBar(0.0f, 100, 20, 168, 116, 31); - gcn::Label *progressLabel = new gcn::Label(); + gcn::Label *progressLabel = new Label(); top->add(progressBar, 5, top->getHeight() - 5 - progressBar->getHeight()); top->add(progressLabel, 15 + progressBar->getWidth(), progressBar->getY() + 4); -- 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/storagewindow.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