From 249b699ee7d6b80700cd648c4a7634c267b0ee68 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 6 Mar 2009 06:26:15 -0700 Subject: Fix layout of debug window --- src/gui/debugwindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 1e199314..1a805dd4 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -42,7 +42,6 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); setDefaultSize(0, 0, 400, 60); - loadWindowState(); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); @@ -51,14 +50,14 @@ DebugWindow::DebugWindow(): mTileMouseLabel = new gcn::Label("Mouse: 0, 0"); mParticleCountLabel = new gcn::Label("Particle count: 0"); - place(0, 0, mFPSLabel); + place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); place(0, 2, mMapLabel, 4); place(0, 3, mMiniMapLabel, 4); - reflowLayout(375, 0); + loadWindowState(); } void DebugWindow::logic() -- cgit v1.2.3-70-g09d2 From 6ea994477c58912785729e7922eb90862a1ab13c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 6 Mar 2009 08:50:11 -0700 Subject: Cut down on redundant constant int declarations in the windows skinning code. While this shouldn't do too much, if anything, for performance, it makes maintenence easier in the future if only one set of ints needs to be modified rather than 9 when they do the same thing. Signed-off-by: Ira Rice --- src/gui/window.cpp | 74 +++++------------------------------------------------- 1 file changed, 6 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e285c3c4..0869368d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -569,7 +569,7 @@ void Window::loadSkin(const std::string &filename) if (!skinSetImage.empty()) { logger->log("Window::loadSkin(): defines '%s' as a skin image.", skinSetImage.c_str()); - dBorders = resman->getImage("graphics/gui/" + skinSetImage);//"graphics/gui/speech_bubble.png"); + dBorders = resman->getImage("graphics/gui/" + skinSetImage); } else { @@ -593,104 +593,42 @@ void Window::loadSkin(const std::string &filename) for_each_xml_child_node(partNode, widgetNode) { if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - { continue; - } std::string partType; partType = XML::getProperty(partNode, "type", "unknown"); // TOP ROW - if (partType == "top-left-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + if (partType == "top-left-corner") border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "top-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "top-right-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - } // MIDDLE ROW else if (partType == "left-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bg-quad") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "right-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - } // BOTTOM ROW else if (partType == "bottom-left-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bottom-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bottom-right-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - } // Part is of an uknown type. else - { logger->log("Window::loadSkin(): Unknown Part Type '%s'", partType.c_str()); - } } } // Widget is of an uknown type. -- 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') 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') 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 4463387e133b0cd238ebb1ff89b8362fc2adbe75 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 9 Mar 2009 13:26:59 -0600 Subject: Send the correct packet for the NPC close button Both packets do the same, but we should be explicit anyways. Also, seperate out NPC client packets. --- src/gui/npc_text.cpp | 8 ++++++++ src/gui/npc_text.h | 2 ++ src/gui/npclistdialog.cpp | 4 ++-- src/net/npchandler.cpp | 1 + src/net/protocol.h | 18 ++++++++++-------- 5 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index b94e8aa4..ec8a4b6e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -38,6 +38,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Window(_("NPC")), mNetwork(network) { setResizable(true); + setCloseButton(true); setMinWidth(200); setMinHeight(150); @@ -103,6 +104,13 @@ void NpcTextDialog::nextDialog(int npcID) outMsg.writeInt32(npcID); } +void NpcTextDialog::closeDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_CLOSE); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index a72de5d0..615902db 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -76,6 +76,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void nextDialog(int npcID = current_npc); + void closeDialog(int npcID = current_npc); + /** * Called when resizing the window. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 73b00239..c639411d 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -58,8 +58,8 @@ NpcListDialog::NpcListDialog(Network *network): scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); place(0, 0, scrollArea, 5).setPadding(3); - place(3, 1, okButton); - place(4, 1, cancelButton); + place(3, 1, cancelButton); + place(4, 1, okButton); Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 1161bc36..41af4467 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -76,6 +76,7 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == id) current_npc = 0; + npcTextDialog->closeDialog(id); break; case SMSG_NPC_NEXT: diff --git a/src/net/protocol.h b/src/net/protocol.h index 081f8873..645d667f 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -122,30 +122,32 @@ #define CMSG_TRADE_RESPONSE 0x00e6 #define CMSG_ITEM_PICKUP 0x009f #define CMSG_MAP_LOADED 0x007d -#define CMSG_NPC_BUY_REQUEST 0x00c8 -#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 #define CMSG_CHAT_MESSAGE 0x008c #define CMSG_CHAT_WHISPER 0x0096 #define CMSG_CHAT_ANNOUNCE 0x0099 #define CMSG_CHAT_WHO 0x00c1 -#define CMSG_NPC_LIST_CHOICE 0x00b8 -#define CMSG_NPC_NEXT_REQUEST 0x00b9 -#define CMSG_NPC_SELL_REQUEST 0x00c9 -#define CMSG_NPC_INT_RESPONSE 0x0143 -#define CMSG_NPC_STR_RESPONSE 0x01d5 #define CMSG_SKILL_LEVELUP_REQUEST 0x0112 #define CMSG_STAT_UPDATE_REQUEST 0x00bb #define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 #define CMSG_TRADE_CANCEL_REQUEST 0x00ed #define CMSG_TRADE_ADD_COMPLETE 0x00eb #define CMSG_TRADE_OK 0x00ef -#define CMSG_NPC_TALK 0x0090 #define CMSG_TRADE_REQUEST 0x00e4 #define CMSG_PLAYER_INVENTORY_USE 0x00a7 #define CMSG_PLAYER_INVENTORY_DROP 0x00a2 #define CMSG_PLAYER_EQUIP 0x00a9 #define CMSG_PLAYER_UNEQUIP 0x00ab +#define CMSG_NPC_TALK 0x0090 +#define CMSG_NPC_NEXT_REQUEST 0x00b9 +#define CMSG_NPC_CLOSE 0x0146 +#define CMSG_NPC_LIST_CHOICE 0x00b8 +#define CMSG_NPC_INT_RESPONSE 0x0143 +#define CMSG_NPC_STR_RESPONSE 0x01d5 +#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 +#define CMSG_NPC_BUY_REQUEST 0x00c8 +#define CMSG_NPC_SELL_REQUEST 0x00c9 + #define CMSG_PARTY_CREATE 0x00f9 #define CMSG_PARTY_INVITE 0x00fc #define CMSG_PARTY_INVITED 0x00ff -- cgit v1.2.3-70-g09d2 From 2d6e867ba8306bc662b9cf42dd403f2ebcb140a6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:15:20 -0600 Subject: Remove some tabs and trailing whitespace --- src/gui/chat.cpp | 16 ++++++++-------- src/gui/confirm_dialog.cpp | 4 ++-- src/gui/debugwindow.cpp | 2 +- src/gui/listbox.cpp | 2 +- src/gui/ok_dialog.cpp | 6 +++--- src/gui/setup_players.cpp | 4 ++-- src/gui/shop.h | 2 +- src/gui/widgets/dropdown.cpp | 6 +++--- src/map.cpp | 2 +- src/shopitem.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 91e410ce..47fadc8d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2bc330c0..f4b49251 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -57,7 +57,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, { // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); @@ -68,7 +68,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + fontHeight, (2 * fontHeight) + + setContentSize(width + fontHeight, (2 * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 1a805dd4..dafd604a 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -71,7 +71,7 @@ void DebugWindow::logic() mFPSLabel->setCaption(toString(fps) + " FPS"); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 6d5c0ca8..82011239 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -112,7 +112,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } else if (key.getValue() == gcn::Key::UP) { - setSelected(mSelected - 1); + setSelected(mSelected - 1); keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 9621b389..d3e7bec6 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -53,10 +53,10 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, if (numRows > 1) { // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + okButton->getHeight()); - mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * fontHeight))); + mTextArea->setDimension(gcn::Rectangle(4, 5, + mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); } else { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 9105d44a..faf80640 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -330,7 +330,7 @@ void Setup_Players::apply() ~(PlayerRelation::TRADE | PlayerRelation::WHISPER); player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? + | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); @@ -342,7 +342,7 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { - if (event.getId() == ACTION_TABLE) + if (event.getId() == ACTION_TABLE) { // temporarily eliminate ourselves: we are fully aware of this change, // so there is no need for asynchronous updates. (In fact, thouse diff --git a/src/gui/shop.h b/src/gui/shop.h index 26a9429d..118847f9 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -38,7 +38,7 @@ class ShopItem; * The addItem routine can automatically check, if an item already exists and * only adds duplicates to the old item, if one is found. The original * distribution of the duplicates can be retrieved from the item. - * + * * This functionality can be enabled in the constructor. */ class ShopItems : public gcn::ListModel diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 9fcf173c..035ce5d7 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -79,10 +79,10 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, { for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], - gridx[x + 1] - + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - + gridy[y + 1] - gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; diff --git a/src/map.cpp b/src/map.cpp index b780b5cc..bda618e2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -86,7 +86,7 @@ void TileAnimation::update() Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (std::list >::iterator i = + for (std::list >::iterator i = mAffected.begin(); i != mAffected.end(); i++) { i->first->setTile(i->second, img); diff --git a/src/shopitem.h b/src/shopitem.h index 18608a94..afc48bf5 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -96,7 +96,7 @@ class ShopItem : public Item * Reduces the quantity of the topmost duplicate by the specified * amount. Also reduces the total quantity of this DuplicateItem. * Empty duplicates are automatically removed. - * + * * If the amount is bigger than the quantity of the current topmost, * only sell as much as possible. Returns the amount actually sold (do * not ignore the return value!) -- cgit v1.2.3-70-g09d2 From ec838fe4abf3d1003c654d3b6902a4f145d0fb5a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 07:29:56 -0600 Subject: Fixed an indentation error in the last commit. Signed-off-by: Ira Rice --- src/gui/chat.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 47fadc8d..9ae1be2c 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { -- cgit v1.2.3-70-g09d2 From 3f322e9eec45751686c59ec89bee46d1da34c885 Mon Sep 17 00:00:00 2001 From: Kess Vargavind Date: Mon, 16 Feb 2009 17:22:38 +0100 Subject: Expand the scope where item links work This patch makes item links work in any chatLog() message, not only chatSend() as before. I enabled it for the "You picked " message by explicitly adding [] around the item name in the string. --- src/gui/chat.cpp | 62 ++++++++++++++++++++++---------------------- src/net/inventoryhandler.cpp | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9ae1be2c..fd2b05e4 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -221,6 +221,37 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << (int) ((t / 60) % 60) << "] "; + // Check for item link + std::string::size_type start = msg.find('['); + while (start != std::string::npos && msg[start+1] != '@') + { + std::string::size_type end = msg.find(']', start); + if (start+1 != end && end != std::string::npos) + { + // Catch multiple embeds and ignore them + // so it doesn't crash the client. + while ((msg.find('[', start + 1) != std::string::npos) && + (msg.find('[', start + 1) < end)) + { + start = msg.find('[', start + 1); + } + + std::string temp = msg.substr(start + 1, end - start - 1); + + toLower(trim(temp)); + + const ItemInfo itemInfo = ItemDB::get(temp); + if (itemInfo.getName() != _("Unknown item")) + { + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + } + } + start = msg.find('[', start + 1); + } + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before @@ -382,37 +413,6 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) return; } - // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') - { - std::string::size_type end = msg.find(']', start); - if (start+1 != end && end != std::string::npos) - { - // Catch multiple embeds and ignore them - // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) - { - start = msg.find('[', start + 1); - } - - std::string temp = msg.substr(start + 1, end - start - 1); - - toLower(trim(temp)); - - const ItemInfo itemInfo = ItemDB::get(temp); - if (itemInfo.getName() != _("Unknown item")) - { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); - } - } - start = msg.find('[', start + 1); - } - // Prepare ordinary message if (msg.substr(0, 1) != "/") { diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 553ec8fd..9fcfedf1 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -164,7 +164,7 @@ void InventoryHandler::handleMessage(MessageIn *msg) const std::string amountStr = (amount > 1) ? toString(amount) : "a"; if (config.getValue("showpickupchat", true)) { - chatWindow->chatLog(strprintf(_("You picked up %s %s"), + chatWindow->chatLog(strprintf(_("You picked up %s [%s]"), amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); } -- cgit v1.2.3-70-g09d2 From 0fb4dc37c61341a237bab30896bd2c457222ed03 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:25:49 -0600 Subject: Fix typo in item link parsing --- src/gui/chat.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index fd2b05e4..5cf8b739 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -222,34 +222,39 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << "] "; // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') + std::string::size_type start = tmp.text.find('['); + while (start != std::string::npos && tmp.text[start+1] != '@') { - std::string::size_type end = msg.find(']', start); + std::string::size_type end = tmp.text.find(']', start); if (start+1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) + while ((tmp.text.find('[', start + 1) != std::string::npos) && + (tmp.text.find('[', start + 1) < end)) { - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } - std::string temp = msg.substr(start + 1, end - start - 1); + std::string temp = tmp.text.substr(start+1, end - start - 1); - toLower(trim(temp)); + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); + tmp.text.insert(end, "@@"); + tmp.text.insert(start+1, "|"); + tmp.text.insert(start+1, toString(itemInfo.getId())); + tmp.text.insert(start+1, "@@"); } } - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } line = lineColor + timeStr.str() + tmp.nick + tmp.text; -- cgit v1.2.3-70-g09d2 From 03507766fa4ee07491b7ee702093669de6222c9c Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:37:44 +0100 Subject: Fix video config cancel button for "show name". The cancel button in Video configuration window doesn't switch back the "show name" setting to the original state. This patch fixes that. --- src/gui/setup_video.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7e3d483c..59eb4096 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -414,6 +414,8 @@ void Setup_Video::cancel() config.setValue("particleeffects", mParticleEffectsEnabled ? true : false); config.setValue("speech", mSpeechMode); config.setValue("showownname", mNameEnabled ? true : false); + if (player_node) + player_node->mUpdateName = true; config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); config.setValue("showpickupchat", mPickupChatEnabled ? true : false); -- cgit v1.2.3-70-g09d2 From 443a10db52e909c4c2a33543795ec8837547e973 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:11:48 -0600 Subject: Made it so that when windows load previous states, they are never smaller than the minimum width and height (a check that should have been enforced in the first place), as well as modified the NPC list and text dialogs to remember where they were when they were moved or resized last. Signed-off-by: Ira Rice --- src/gui/npc_text.cpp | 11 +++++++++-- src/gui/npc_text.h | 13 +++++++++++++ src/gui/npclistdialog.cpp | 6 +++++- src/gui/npclistdialog.h | 3 ++- src/gui/window.cpp | 41 +++++++++++++++++++++++++---------------- src/gui/window.h | 6 ++++++ src/net/npchandler.cpp | 3 +-- 7 files changed, 61 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ec8a4b6e..58aa0c5e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -35,10 +35,10 @@ #include "../utils/gettext.h" NpcTextDialog::NpcTextDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); - setCloseButton(true); setMinWidth(200); setMinHeight(150); @@ -89,6 +89,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) { clearText(); setVisible(false); + saveWindowState(); if (current_npc) nextDialog(); @@ -118,3 +119,9 @@ void NpcTextDialog::widgetResized(const gcn::Event &event) setText(mText); } +void NpcTextDialog::requestFocus() +{ + loadWindowState(); + setVisible(true); +} + diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 615902db..f01e3602 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -74,10 +74,23 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + /** + * Notifies the server that the client has performed a next action. + */ void nextDialog(int npcID = current_npc); + /** + * Notifies the server that the client has performed a close action. + */ void closeDialog(int npcID = current_npc); + /** + * Initializes window width to the last known setting. Since the dialog + * doesn't need any extra focus outside of what it's given in the Game + * class, this is all it does for now. + */ + void requestFocus(); + /** * Called when resizing the window. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c639411d..f049cba7 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -37,8 +37,9 @@ #include "../utils/gettext.h" NpcListDialog::NpcListDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); setMinWidth(200); @@ -114,6 +115,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event) if (choice) { setVisible(false); + saveWindowState(); reset(); MessageOut outMsg(mNetwork); @@ -129,4 +131,6 @@ void NpcListDialog::requestFocus() { mItemList->requestFocus(); mItemList->setSelected(0); + loadWindowState(); + setVisible(true); } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 0a0e9813..e3cf375b 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -76,7 +76,8 @@ class NpcListDialog : public Window, public gcn::ActionListener, void reset(); /** - * Requests the listbox to take focus for input. + * Requests the listbox to take focus for input and sets window width + * to the last known setting. */ void requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 2b422f86..8faf63a0 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -118,21 +118,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std Window::~Window() { logger->log("Window::~Window(\"%s\")", getCaption().c_str()); - const std::string &name = mWindowName; - // Saving X, Y and Width and Height for resizables in the config - if (!name.empty()) - { - config.setValue(name + "WinX", getX()); - config.setValue(name + "WinY", getY()); - config.setValue(name + "Visible", isVisible()); - - if (mGrip) - { - config.setValue(name + "WinWidth", getWidth()); - config.setValue(name + "WinHeight", getHeight()); - } - } + saveWindowState(); delete mLayout; @@ -478,8 +465,13 @@ void Window::loadWindowState() if (mGrip) { - setSize((int) config.getValue(name + "WinWidth", mDefaultWidth), - (int) config.getValue(name + "WinHeight", mDefaultHeight)); + const int width = (int) config.getValue(name + "WinWidth", + mDefaultWidth); + const int height = (int) config.getValue(name + "WinHeight", + mDefaultHeight); + + setSize(width < getMinWidth() ? getMinWidth() : width, + height < getMinHeight() ? getMinHeight() : height); } else { @@ -487,6 +479,23 @@ void Window::loadWindowState() } } +void Window::saveWindowState() +{ + // Saving X, Y and Width and Height for resizables in the config + if (!mWindowName.empty()) + { + config.setValue(mWindowName + "WinX", getX()); + config.setValue(mWindowName + "WinY", getY()); + config.setValue(mWindowName + "Visible", isVisible()); + + if (mGrip) + { + config.setValue(mWindowName + "WinWidth", getWidth()); + config.setValue(mWindowName + "WinHeight", getHeight()); + } + } +} + void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { diff --git a/src/gui/window.h b/src/gui/window.h index 3a92ac17..bf15dedb 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -233,6 +233,12 @@ class Window : public gcn::Window, gcn::WidgetListener */ void loadWindowState(); + /** + * Saves the window state so that when the window is reloaded, it'll + * maintain its previous state and location. + */ + void saveWindowState(); + /** * Set the default win pos and size. * (which can be different of the actual ones.) diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 41af4467..60a77af1 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,7 +60,6 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(true); npcListDialog->requestFocus(); break; @@ -69,7 +68,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcTextDialog->setVisible(true); + npcTextDialog->requestFocus(); break; case SMSG_NPC_CLOSE: -- cgit v1.2.3-70-g09d2 From 67ea3716f8b01484527ead747c0cc6af3ac0cd76 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:29:49 -0600 Subject: Moved enforcement of minimum widths and heights to the Window class. This was needed in the Minimap class, but not migrated out to the Window class until now. Signed-off-by: Ira Rice --- src/gui/login.cpp | 28 +++++++++------------------- src/gui/minimap.cpp | 12 ------------ src/gui/window.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/gui/login.cpp b/src/gui/login.cpp index cd331322..ce13aaf0 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -117,11 +117,10 @@ LoginDialog::LoginDialog(LoginData *loginData): setLocationRelativeTo(getParent()); setVisible(true); - if (mUserField->getText().empty()) { + if (mUserField->getText().empty()) mUserField->requestFocus(); - } else { + else mPassField->requestFocus(); - } mOkButton->setEnabled(canSubmit()); } @@ -156,14 +155,12 @@ void LoginDialog::action(const gcn::ActionEvent &event) { // Transfer these fields on to the register dialog mLoginData->hostname = mServerField->getText(); + if (isUShort(mPortField->getText())) - { mLoginData->port = getUShort(mPortField->getText()); - } else - { mLoginData->port = 6901; - } + mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); @@ -196,14 +193,12 @@ bool LoginDialog::isUShort(const std::string &str) strPtr != strEnd; ++strPtr) { if (*strPtr < '0' || *strPtr > '9') - { return false; - } + l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative + if (l > 65535) - { return false; - } } return true; } @@ -279,9 +274,7 @@ void LoginDialog::DropDownList::save(const std::string &server, ++sPtr, ++pPtr) { if (*sPtr != server || *pPtr != port) - { saveEntry(*sPtr, *pPtr, position); - } } } @@ -293,26 +286,23 @@ int LoginDialog::DropDownList::getNumberOfElements() std::string LoginDialog::DropDownList::getElementAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return getServerAt(i) + ":" + getPortAt(i); } std::string LoginDialog::DropDownList::getServerAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return mServers.at(i); } std::string LoginDialog::DropDownList::getPortAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return mPorts.at(i); } diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 2a97b949..ecda29ce 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -80,18 +80,6 @@ void Minimap::setMapImage(Image *img) mMapImage->getWidth() + offsetX : titleWidth); setMaxHeight(mMapImage->getHeight() + offsetY); - // Make sure the window is within the minimum and maximum boundaries - // TODO: Shouldn't this be happening automatically within the Window - // class? - if (getMinWidth() > getWidth()) - setWidth(getMinWidth()); - else if (getMaxWidth() < getWidth()) - setWidth(getMaxWidth()); - if (getMinHeight() > getHeight()) - setHeight(getMinHeight()); - else if (getMaxHeight() < getHeight()) - setHeight(getMaxHeight()); - setContentSize(getWidth() - offsetX, getHeight() - offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); resetToDefaultSize(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 8faf63a0..5253dd2e 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -193,8 +193,19 @@ void Window::draw(gcn::Graphics *graphics) void Window::setContentSize(int width, int height) { - setSize(width + 2 * getPadding(), - height + getPadding() + getTitleBarHeight()); + width = width + 2 * getPadding(); + height = height + getPadding() + getTitleBarHeight(); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); } void Window::setLocationRelativeTo(gcn::Widget *widget) @@ -465,13 +476,19 @@ void Window::loadWindowState() if (mGrip) { - const int width = (int) config.getValue(name + "WinWidth", - mDefaultWidth); - const int height = (int) config.getValue(name + "WinHeight", - mDefaultHeight); - - setSize(width < getMinWidth() ? getMinWidth() : width, - height < getMinHeight() ? getMinHeight() : height); + int width = (int) config.getValue(name + "WinWidth", mDefaultWidth); + int height = (int) config.getValue(name + "WinHeight", mDefaultHeight); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); } else { @@ -490,6 +507,15 @@ void Window::saveWindowState() if (mGrip) { + if (getMinWidth() > getWidth()) + setWidth(getMinWidth()); + else if (getMaxWidth() < getWidth()) + setWidth(getMaxWidth()); + if (getMinHeight() > getHeight()) + setHeight(getMinHeight()); + else if (getMaxHeight() < getHeight()) + setHeight(getMaxHeight()); + config.setValue(mWindowName + "WinWidth", getWidth()); config.setValue(mWindowName + "WinHeight", getHeight()); } @@ -499,6 +525,15 @@ void Window::saveWindowState() void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { + if (getMinWidth() > defaultWidth) + defaultWidth = getMinWidth(); + else if (getMaxWidth() < defaultWidth) + defaultWidth = getMaxWidth(); + if (getMinHeight() > defaultHeight) + defaultHeight = getMinHeight(); + else if (getMaxHeight() < defaultHeight) + defaultHeight = getMaxHeight(); + mDefaultX = defaultX; mDefaultY = defaultY; mDefaultWidth = defaultWidth; -- cgit v1.2.3-70-g09d2 From 6b0659b6cc921aa6589681820b431af44f458440 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:37:10 -0600 Subject: Fixed setContentSize in the window class to only care about exceeding the maximum width and height. Exceeding the minumum width and height is a desireable case in some situations. Signed-off-by: Ira Rice --- src/gui/window.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..3c73a586 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -196,13 +196,9 @@ void Window::setContentSize(int width, int height) width = width + 2 * getPadding(); height = height + getPadding() + getTitleBarHeight(); - if (getMinWidth() > width) - width = getMinWidth(); - else if (getMaxWidth() < width) + if (getMaxWidth() < width) width = getMaxWidth(); - if (getMinHeight() > height) - height = getMinHeight(); - else if (getMaxHeight() < height) + if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); -- cgit v1.2.3-70-g09d2 From 1570fb33d5909786ef2997246ada7c46dd6de9e4 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:43:26 -0600 Subject: Reverted last commit (since I confused it with something else) as well as removed a redundant call for sizing in the minimap class. Signed-off-by: Ira Rice --- src/gui/minimap.cpp | 1 - src/gui/window.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index ecda29ce..f3da52c6 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -80,7 +80,6 @@ void Minimap::setMapImage(Image *img) mMapImage->getWidth() + offsetX : titleWidth); setMaxHeight(mMapImage->getHeight() + offsetY); - setContentSize(getWidth() - offsetX, getHeight() - offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); resetToDefaultSize(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 3c73a586..5253dd2e 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -196,9 +196,13 @@ void Window::setContentSize(int width, int height) width = width + 2 * getPadding(); height = height + getPadding() + getTitleBarHeight(); - if (getMaxWidth() < width) + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) width = getMaxWidth(); - if (getMaxHeight() < height) + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); -- cgit v1.2.3-70-g09d2 From 2353f11b75e347c9662c7224f5b3abcd9189a6bb Mon Sep 17 00:00:00 2001 From: sniper Date: Tue, 10 Mar 2009 14:28:31 +0100 Subject: Extended hit type handling The client can now differentiate between the following hit types: - hit (normal) - critical (full attack) - multi (more than one hit at once, currently not used) - reflect (reflected damage, currently not used) - flee (dodging criticals) The Being's showCrit method is now merged into takeDamage. Being's takeDamage and handleAttack now both get the opponent, the amount of damage and the attack type as parameter. --- src/being.cpp | 55 +++++++++++++++++++++--------------------------- src/being.h | 27 +++++++++++++++--------- src/localplayer.h | 8 +++---- src/monster.cpp | 8 +++---- src/monster.h | 13 +++++++----- src/net/beinghandler.cpp | 15 +++++++------ 6 files changed, 66 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index c31dae6d..ad6b2dea 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -219,26 +219,29 @@ void Being::setSpeech(const std::string &text, int time) mSpeechTime = time <= SPEECH_MAX_TIME ? time : SPEECH_MAX_TIME; } -void Being::takeDamage(int amount) +void Being::takeDamage(Being *attacker, int amount, AttackType type) { gcn::Font *font; - std::string damage = amount ? toString(amount) : "miss"; + std::string damage = amount ? toString(amount) : type == FLEE ? + "dodge" : "miss"; int red, green, blue; font = gui->getInfoParticleFont(); // Selecting the right color - if (damage == "miss") + if (type == CRITICAL || type == FLEE) { red = 255; - green = 255; + green = 128; blue = 0; } - else - { - if (getType() == MONSTER) + else if (!amount) + { + if (attacker == player_node) { + // This is intended to be the wrong direction to visually + // differentiate between hits and misses red = 0; green = 100; blue = 255; @@ -246,27 +249,11 @@ void Being::takeDamage(int amount) else { red = 255; - green = 50; - blue = 50; - } - } - - // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); -} - -void Being::showCrit() -{ - gcn::Font *font; - std::string text = "crit!"; - - int red, green, blue; - - font = gui->getInfoParticleFont(); - - // Selecting the right color - if (getType() == MONSTER) + green = 255; + blue = 0; + } + } + else if (getType() == MONSTER) { red = 0; green = 100; @@ -279,12 +266,18 @@ void Being::showCrit() blue = 50; } - // Show crit notice - particleEngine->addTextSplashEffect(text, red, green, blue, font, + if (amount > 0 && type == CRITICAL) + { + particleEngine->addTextSplashEffect("crit!", red, green, blue, font, + mPx + 16, mPy + 16, true); + } + + // Show damage number + particleEngine->addTextSplashEffect(damage, red, green, blue, font, mPx + 16, mPy + 16, true); } -void Being::handleAttack(Being *victim, int damage) +void Being::handleAttack(Being *victim, int damage, AttackType type) { setAction(Being::ATTACK); mFrame = 0; diff --git a/src/being.h b/src/being.h index 9b3bbde4..63e5e07f 100644 --- a/src/being.h +++ b/src/being.h @@ -123,6 +123,15 @@ class Being : public Sprite NUM_SPEECH }; + enum AttackType + { + HIT = 0x00, + CRITICAL = 0x0a, + MULTI = 0x08, + REFLECT = 0x04, + FLEE = 0x0b + }; + /** * Directions, to be used as bitmask values */ @@ -171,22 +180,20 @@ class Being : public Sprite /** * Puts a damage bubble above this being. * - * @param amount The amount of damage. - */ - virtual void takeDamage(int amount); - - /** - * Puts a crit notification bubble above this being. + * @param attacker the attacking being + * @param damage the amount of damage recieved (0 means miss) + * @param type the attack type */ - virtual void showCrit(); + virtual void takeDamage(Being *attacker, int damage, AttackType type); /** * Handles an attack of another being by this being. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage); + virtual void handleAttack(Being *victim, int damage, AttackType type); /** * Returns the name of the being. diff --git a/src/localplayer.h b/src/localplayer.h index 85868750..16e7c124 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -143,11 +143,11 @@ class LocalPlayer : public Player * displayed as soon as the player attacks, not when the server says * the player does. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage) {} - + virtual void handleAttack(Being *victim, int damage, AttackType type) {} /** * Returns the current target of the player. Returns 0 if no being is * currently targeted. diff --git a/src/monster.cpp b/src/monster.cpp index 61c867e9..45d2fbeb 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -161,19 +161,19 @@ void Monster::setAction(Action action) } } -void Monster::handleAttack(Being *victim, int damage) +void Monster::handleAttack(Being *victim, int damage, AttackType type) { - Being::handleAttack(victim, damage); + Being::handleAttack(victim, damage, type); const MonsterInfo &mi = getInfo(); sound.playSfx(mi.getSound((damage > 0) ? MONSTER_EVENT_HIT : MONSTER_EVENT_MISS)); } -void Monster::takeDamage(int amount) +void Monster::takeDamage(Being *attacker, int amount, AttackType type) { if (amount > 0) sound.playSfx(getInfo().getSound(MONSTER_EVENT_HURT)); - Being::takeDamage(amount); + Being::takeDamage(attacker, amount, type); } Being::TargetCursorSize Monster::getTargetCursorSize() const diff --git a/src/monster.h b/src/monster.h index 12297373..afb55769 100644 --- a/src/monster.h +++ b/src/monster.h @@ -48,17 +48,20 @@ class Monster : public Being * Handles an attack of another being by this monster. Plays a hit or * miss sound when appropriate. * - * @param victim The attacked being. - * @param damage The amount of damage dealt (0 means miss). + * @param victim the victim being + * @param damage the amount of damage dealt (0 means miss) + * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage); + virtual void handleAttack(Being *victim, int damage, AttackType type); /** * Puts a damage bubble above this monster and plays the hurt sound * - * @param amount The amount of damage. + * @param attacker the attacking being + * @param damage the amount of damage recieved (0 means miss) + * @param type the attack type */ - virtual void takeDamage(int amount); + virtual void takeDamage(Being *attacker, int amount, AttackType type); /** * Returns the MonsterInfo, with static data about this monster. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 4ff303ab..d1810537 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -229,14 +229,17 @@ void BeingHandler::handleMessage(MessageIn *msg) switch (type) { - case 0x0a: // Critical Damage + case Being::HIT: // Damage + case Being::CRITICAL: // Critical Damage + case Being::MULTI: // Critical Damage + case Being::REFLECT: // Reflected Damage + case Being::FLEE: // Lucky Dodge if (dstBeing) - dstBeing->showCrit(); - case 0x00: // Damage - if (dstBeing) - dstBeing->takeDamage(param1); + dstBeing->takeDamage(srcBeing, param1, + (Being::AttackType)type); if (srcBeing) - srcBeing->handleAttack(dstBeing, param1); + srcBeing->handleAttack(dstBeing, param1, + (Being::AttackType)type); break; case 0x02: // Sit -- cgit v1.2.3-70-g09d2 From 5bbf8219bffbb587cf9a23561734c917bb23f42f Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:43:36 -0600 Subject: Start NPC dialogs out hidden --- src/game.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index ba035ecd..144b059f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -233,6 +233,11 @@ void createGuiWindows(Network *network) emoteShortcutWindow->getWindowName() + "Visible", true)); minimap->setVisible((bool) config.getValue( minimap->getWindowName() + "Visible", true)); + buySellDialog->setVisible(false); + npcTextDialog->setVisible(false); + npcIntegerDialog->setVisible(false); + npcListDialog->setVisible(false); + npcStringDialog->setVisible(false); storageWindow->setVisible(false); } -- 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') 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 9b259c3d502795b2bbbfbe6a275cb503b1fc78b1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 11:03:38 -0600 Subject: Allow null link handlers for browser box --- src/gui/browserbox.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index b8f58dbb..2b690b21 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -226,6 +226,7 @@ struct MouseOverLink void BrowserBox::mousePressed(gcn::MouseEvent &event) { + if (!mLinkHandler) return; LinkIterator i = find_if(mLinks.begin(), mLinks.end(), MouseOverLink(event.getX(), event.getY())); -- cgit v1.2.3-70-g09d2 From 0540c611b48fd8dee14066b13755138192b7084b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 12:09:53 -0600 Subject: Allow for offsets for the enumerated position version of setLocationRelativeTo as well. Signed-off-by: Ira Rice --- src/gui/window.cpp | 31 +++++++++++++++---------------- src/gui/window.h | 3 ++- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f1316b4c..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,51 +220,50 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } -void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +void Window::setLocationRelativeTo(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() - getWidth()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); + offsetX += windowContainer->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - getHeight(); + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = windowContainer->getHeight() - getHeight(); + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = windowContainer->getHeight() - getHeight(); + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += windowContainer->getHeight() - getHeight(); } - setPosition(x, y); + setPosition(offsetX, offsetY); } void Window::setMinWidth(unsigned int width) diff --git a/src/gui/window.h b/src/gui/window.h index c24bde76..4fc6c862 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -92,7 +92,8 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the location relative to the given enumerated position. */ - void setLocationRelativeTo(ImageRect::ImagePosition position); + void setLocationRelativeTo(ImageRect::ImagePosition position, + int offsetX = 0, int offsetY = 0); /** * Sets whether or not the window can be resized. -- cgit v1.2.3-70-g09d2 From 75fc8e62d25ff1d39408588f76d95df4a9a7e663 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 5 +++-- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 11 +++++++++-- src/gui/setup.h | 4 ++++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 24 ++++++++++++++---------- src/player_relations.h | 2 ++ 13 files changed, 48 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3e626d87 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,7 +205,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -339,11 +338,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,6 +351,7 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; + delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..b24aeb5d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea(); @@ -102,6 +102,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -141,3 +143,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..d798162c 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,6 +32,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -51,6 +52,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -58,6 +61,7 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; + gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 31b56b51..ecb5bcf7 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,9 +57,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index a8250fce..c29b70ab 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b2571495..7d0fd48a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..b0bf1c59 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,6 +130,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index f7468d84..a43544bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,7 +1015,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..65219626 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -346,24 +352,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..edfa9b28 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,6 +95,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -233,6 +234,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From cabb9735f2e31b9f1f64b2496e1775d54861da36 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 ----- src/beingmanager.h | 4 +--- src/game.cpp | 5 ++--- src/gui/chat.cpp | 2 -- src/gui/setup.cpp | 11 ++--------- src/gui/setup.h | 4 ---- src/gui/setup_colors.cpp | 5 +++-- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 - src/gui/window.cpp | 2 -- src/main.cpp | 1 + src/player_relations.cpp | 24 ++++++++++-------------- src/player_relations.h | 2 -- 13 files changed, 20 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e5836aa7..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,11 +52,6 @@ BeingManager::BeingManager(Network *network): { } -BeingManager::~BeingManager() -{ - clear(); -} - void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 3284ce16..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,8 +37,6 @@ class BeingManager public: BeingManager(Network *network); - ~BeingManager(); - /** * Sets the map on which beings are created */ @@ -115,7 +113,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 3e626d87..144b059f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,6 +205,7 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); + setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -338,12 +339,11 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); - - setupWindow->setInGame(true); } Game::~Game() { + delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,7 +351,6 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,8 +109,6 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; - delete mItemLinkHandler; - delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b24aeb5d..4798f598 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Store this button, as it needs to be enabled/disabled + // Disable this button when the windows aren't created yet if (!strcmp(*curBtn, "Reset Windows")) - mResetWindows = btn; + btn->setEnabled(statusWindow != NULL); } TabbedArea *panel = new TabbedArea(); @@ -102,8 +102,6 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); - - setInGame(false); } Setup::~Setup() @@ -143,8 +141,3 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } - -void Setup::setInGame(bool inGame) -{ - mResetWindows->setEnabled(inGame); -} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index d798162c..9f1bafc7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,7 +32,6 @@ #include "../guichanfwd.h" class SetupTab; -class Button; /** * The setup dialog. @@ -52,8 +51,6 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); - void setInGame(bool inGame); - /** * Event handling method. */ @@ -61,7 +58,6 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; - gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index ecb5bcf7..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,8 +57,9 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // don't do anything with links - mPreview->setLinkHandler(NULL); + // Replace this later with a more appropriate link handler. For now, this'll + // do, as it'll do nothing when clicked on. + mPreview->setLinkHandler(new ItemLinkHandler()); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index c29b70ab..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete_all(mSkillList); + delete mTable; } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 7d0fd48a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,7 +99,6 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { - uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index b0bf1c59..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,8 +130,6 @@ Window::~Window() delete(w); } - removeWidgetListener(this); - instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index a43544bc..f7468d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,6 +1015,7 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; + delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 65219626..1c1ba669 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,8 +29,6 @@ #include "player.h" #include "player_relations.h" -#include "utils/dtor.h" - #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -40,6 +38,7 @@ #define IGNORE_EMOTE_TIME 100 + // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -94,11 +93,6 @@ PlayerRelationsManager::PlayerRelationsManager() : { } -PlayerRelationsManager::~PlayerRelationsManager() -{ - delete_all(mIgnoreStrategies); -} - void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -352,22 +346,24 @@ private: +static std::vector player_ignore_strategies; + std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (mIgnoreStrategies.size() == 0) { + if (player_ignore_strategies.size() == 0) { // not initialised yet? - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - mIgnoreStrategies.push_back(new PIS_nothing()); - mIgnoreStrategies.push_back(new PIS_dotdotdot()); - mIgnoreStrategies.push_back(new PIS_blinkname()); + player_ignore_strategies.push_back(new PIS_nothing()); + player_ignore_strategies.push_back(new PIS_dotdotdot()); + player_ignore_strategies.push_back(new PIS_blinkname()); } - return &mIgnoreStrategies; + return &player_ignore_strategies; } diff --git a/src/player_relations.h b/src/player_relations.h index edfa9b28..0440cace 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,7 +95,6 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); - ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -234,7 +233,6 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; - std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 4676d0fe6ee938031ce13a65927718f9b53810cf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:43:56 -0600 Subject: Remove some SetupWindow weirdness --- src/game.cpp | 2 -- src/gui/setup.cpp | 13 ++++++++++--- src/gui/setup.h | 8 ++++++++ src/main.cpp | 3 --- 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -122,7 +122,6 @@ NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; -Setup* setupWindow; Minimap *minimap; EquipmentWindow *equipmentWindow; TradeWindow *tradeWindow; @@ -261,7 +260,6 @@ void destroyGuiWindows() delete npcTextDialog; delete npcStringDialog; delete skillDialog; - delete setupWindow; delete minimap; delete equipmentWindow; delete tradeWindow; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..f1e7a6d9 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,12 +65,12 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } - TabbedArea *panel = new TabbedArea(); + TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); SetupTab *tab; @@ -141,3 +141,10 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} + +Setup* setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..663bdfcb 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -56,8 +56,16 @@ class Setup : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); + /** + * Enables the reset button when in game. + */ + void setInGame(bool inGame); + private: std::list mTabs; + gcn::Button* mResetWindows; }; +extern Setup* setupWindow; + #endif diff --git a/src/main.cpp b/src/main.cpp index f7468d84..9e7c91c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,8 +101,6 @@ namespace { - Window *setupWindow = 0; - struct SetupListener : public gcn::ActionListener { /** @@ -1020,7 +1018,6 @@ int main(int argc, char *argv[]) progressLabel = NULL; currentDialog = NULL; setup = NULL; - setupWindow = NULL; login_wallpaper->decRef(); login_wallpaper = NULL; -- cgit v1.2.3-70-g09d2 From 43eca19b045f30c6456dd936b2baddff945cc047 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 16:31:14 -0600 Subject: Set minimum bounds for speech bubbles, based on the skin's minimum dimensions. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d54bf9ad..dcb03dca 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -39,6 +39,9 @@ SpeechBubble::SpeechBubble(): setShowTitle(false); setTitleBarHeight(0); + setMinWidth(29); + setMinHeight(29); + mCaption = new gcn::Label(""); mCaption->setFont(boldFont); mCaption->setPosition(5, 3); -- cgit v1.2.3-70-g09d2 From 265172dc1e7b97611c485752dc10345545c4e296 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 17:33:32 -0600 Subject: Introduced in a Skin holder class, to reduce the amount of needed XML skin loads. Signed-off-by: Ira Rice --- src/gui/window.cpp | 97 +++++++++++++++++++++++++++++++++--------------------- src/gui/window.h | 35 ++++++++++++++++++-- 2 files changed, 91 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..0e91b68d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -40,15 +40,15 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" #include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; -//ImageRect Window::border; -Image *Window::closeImage = NULL; bool Window::mAlphaChanged = false; +Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,6 +58,24 @@ class WindowConfigListener : public ConfigListener } }; +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -71,8 +89,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), - mSkin(skin) + mMaxWinHeight(INT_MAX) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -82,7 +99,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std } // Loads the skin - loadSkin(mSkin); + loadSkin(skin); setGuiAlpha(); @@ -132,20 +149,14 @@ Window::~Window() instances--; - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } + mSkin->instances--; if (instances == 0) { config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - - closeImage->decRef(); + delete_all(mSkins); } } @@ -161,7 +172,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); // Draw title if (mShowTitle) @@ -174,8 +185,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(closeImage, - getWidth() - closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->closeImage, + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding() ); } @@ -183,10 +194,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(border.grid, border.grid + 9, + for_each(mSkin->border.grid, mSkin->border.grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -365,10 +376,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - closeImage->getWidth() - getPadding(), + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding(), - closeImage->getWidth(), - closeImage->getHeight()); + mSkin->closeImage->getWidth(), + mSkin->closeImage->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -679,7 +690,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; @@ -687,14 +698,24 @@ void Window::setGuiAlpha() void Window::loadSkin(const std::string &filename) { + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + mSkin = skinIterator->second; + return; + } + const std::string windowId = Window::getId(); + mSkin = new Skin(); + ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Window Skin '%s'.", filename.c_str()); logger->log("Loading Window ID '%s'.", windowId.c_str()); - if (filename.empty()) logger->error("Window::loadSkin(): Invalid File Name."); @@ -706,16 +727,15 @@ void Window::loadSkin(const std::string &filename) xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - { logger->error("Widget Skinning error"); - } std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; if (!skinSetImage.empty()) { - logger->log("Window::loadSkin(): defines '%s' as a skin image.", skinSetImage.c_str()); + logger->log("Window::loadSkin(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); dBorders = resman->getImage("graphics/gui/" + skinSetImage); } else @@ -735,8 +755,8 @@ void Window::loadSkin(const std::string &filename) { // Iterate through 's // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For now it - // can just be hard-coded. + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. for_each_xml_child_node(partNode, widgetNode) { if (!xmlStrEqual(partNode->name, BAD_CAST "part")) @@ -751,27 +771,27 @@ void Window::loadSkin(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -789,7 +809,8 @@ void Window::loadSkin(const std::string &filename) logger->log("Finished loading Window Skin."); // Hard-coded for now until we update the above code to look for window buttons. - closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = mSkin; } Layout &Window::getLayout() diff --git a/src/gui/window.h b/src/gui/window.h index 4fc6c862..c5660c58 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,6 +23,8 @@ #ifndef WINDOW_H #define WINDOW_H +#include + #include #include @@ -39,6 +41,18 @@ class LayoutCell; class ResizeGrip; class WindowContainer; +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -297,7 +311,23 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Overrideable functionality for when the window is to close. This + * allows for class implementations to clean up or do certain actions + * on window close they couldn't do otherwise. + */ virtual void close(); + + /** + * Map containing all window skins + */ + typedef std::map Skins; + + /** + * Iterator for window skins + */ + typedef Skins::iterator SkinIterator; + protected: /** The window container windows add themselves to. */ @@ -341,7 +371,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultY; /**< Default window Y position */ int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - std::string mSkin; /**< Name of the skin to use */ /** * The config listener that listens to changes relevant to all windows. @@ -350,8 +379,8 @@ class Window : public gcn::Window, gcn::WidgetListener static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ - ImageRect border; /**< The window border and background */ - static Image *closeImage; /**< Close Button Image */ + + Skin* mSkin; /**< Skin in use by this window */ /** * The width of the resize border. Is independent of the actual window -- cgit v1.2.3-70-g09d2 From bb45b6a8ca4ea751bceb5853060251a3eefcd4fc Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 16:36:34 -0600 Subject: Delete local player earlier and fix a rare crash Rare crash is in KeyboardConfig, where the active keys array is accessed before it's initialized. Also remove some debug prints that made it into a previous commit. --- src/game.cpp | 1 + src/keyboardconfig.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 3b621acd..13be3663 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -345,6 +345,7 @@ Game::~Game() destroyGuiWindows(); delete beingManager; + delete player_node; delete floorItemManager; delete joystick; delete particleEngine; diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 8187bef7..8ed23c65 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -198,7 +198,8 @@ int KeyboardConfig::getKeyEmoteOffset(int keyValue) const bool KeyboardConfig::isKeyActive(int index) { - return mActiveKeys[ mKey[index].value]; + if (!mActiveKeys) return false; + return mActiveKeys[mKey[index].value]; } void KeyboardConfig::refreshActiveKeys() -- cgit v1.2.3-70-g09d2 From 2a6b52f6467bfb4babb2a33205752f58554b651b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 14:38:26 -0600 Subject: Moved the Skin class outside of the Window class, in order to allow other widget containers to use skins as well, and to make it easier to extend later. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 1 - src/gui/gui.cpp | 1 + src/gui/skin.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/skin.h | 67 +++++++++++++++++++++ src/gui/window.cpp | 156 +++-------------------------------------------- src/gui/window.h | 33 +--------- src/main.cpp | 54 +++++++++-------- 10 files changed, 288 insertions(+), 204 deletions(-) create mode 100644 src/gui/skin.cpp create mode 100644 src/gui/skin.h (limited to 'src') diff --git a/aethyra.cbp b/aethyra.cbp index 46034040..6bae4561 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -236,6 +236,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7003946..171ec7ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -185,6 +185,8 @@ SET(SRCS gui/shortcutcontainer.h gui/skill.cpp gui/skill.h + gui/skin.cpp + gui/skin.h gui/slider.cpp gui/slider.h gui/speechbubble.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 963e41fb..440c020e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -135,6 +135,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/shortcutcontainer.h \ gui/skill.cpp \ gui/skill.h \ + gui/skin.cpp \ + gui/skin.h \ gui/slider.cpp \ gui/slider.h \ gui/speechbubble.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 13be3663..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -345,7 +345,6 @@ Game::~Game() destroyGuiWindows(); delete beingManager; - delete player_node; delete floorItemManager; delete joystick; delete particleEngine; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 85a33218..2c0ddee9 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,6 +27,7 @@ #include "focushandler.h" #include "gui.h" #include "sdlinput.h" +#include "skin.h" #include "truetypefont.h" #include "viewport.h" #include "window.h" diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp new file mode 100644 index 00000000..e9d081e9 --- /dev/null +++ b/src/gui/skin.cpp @@ -0,0 +1,174 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * 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 "skin.h" + +#include "../log.h" + +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + +#include "../utils/dtor.h" +#include "../utils/xml.h" + +SkinLoader* skinLoader = NULL; + +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + +Skin* SkinLoader::load(const std::string &filename) +{ + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } + + Skin* skin = new Skin(); + + ResourceManager *resman = ResourceManager::getInstance(); + + logger->log("Loading Skin '%s'.", filename.c_str()); + + if (filename.empty()) + logger->error("SkinLoader::load(): Invalid File Name."); + + // TODO: + // If there is an error loading the specified file, we should try to revert + // to a 'default' skin file. Only if the 'default' skin file can't be loaded + // should we have a terminating error. + XML::Document doc(filename); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + logger->error("Widget Skinning error"); + + std::string skinSetImage; + skinSetImage = XML::getProperty(rootNode, "image", ""); + Image *dBorders = NULL; + if (!skinSetImage.empty()) + { + logger->log("SkinLoader::load(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); + dBorders = resman->getImage("graphics/gui/" + skinSetImage); + } + else + { + logger->error("SkinLoader::load(): Skinset does not define an image!"); + } + + //iterate 's + for_each_xml_child_node(widgetNode, rootNode) + { + if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) + continue; + + std::string widgetType; + widgetType = XML::getProperty(widgetNode, "type", "unknown"); + if (widgetType == "Window") + { + // Iterate through 's + // LEEOR / TODO: + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. + for_each_xml_child_node(partNode, widgetNode) + { + if (!xmlStrEqual(partNode->name, BAD_CAST "part")) + continue; + + std::string partType; + partType = XML::getProperty(partNode, "type", "unknown"); + // TOP ROW + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + + if (partType == "top-left-corner") + skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-edge") + skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-right-corner") + skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + + // MIDDLE ROW + else if (partType == "left-edge") + skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bg-quad") + skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "right-edge") + skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + + // BOTTOM ROW + else if (partType == "bottom-left-corner") + skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-edge") + skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-right-corner") + skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + + // Part is of an uknown type. + else + logger->log("SkinLoader::load(): Unknown Part Type '%s'", partType.c_str()); + } + } + // Widget is of an uknown type. + else + { + logger->log("SkinLoader::load(): Unknown Widget Type '%s'", widgetType.c_str()); + } + } + dBorders->decRef(); + + logger->log("Finished loading Skin."); + + // Hard-coded for now until we update the above code to look for window buttons. + skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = skin; + return skin; +} + +SkinLoader::SkinLoader() +{ +} + +SkinLoader::~SkinLoader() +{ + delete_all(mSkins); +} + diff --git a/src/gui/skin.h b/src/gui/skin.h new file mode 100644 index 00000000..6dddb4a8 --- /dev/null +++ b/src/gui/skin.h @@ -0,0 +1,67 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * 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 SKIN_H +#define SKIN_H + +#include +#include + +#include "../graphics.h" + +class Image; + +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + +// Map containing all window skins +typedef std::map Skins; + +// Iterator for window skins +typedef Skins::iterator SkinIterator; + +class SkinLoader +{ + public: + SkinLoader(); + ~SkinLoader(); + + /** + * Loads a skin + */ + Skin* load(const std::string &filename); + + private: + Skins mSkins; +}; + +extern SkinLoader* skinLoader; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0e91b68d..def81c53 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -27,6 +27,7 @@ #include #include "gui.h" +#include "skin.h" #include "window.h" #include "windowcontainer.h" @@ -38,17 +39,12 @@ #include "../log.h" #include "../resources/image.h" -#include "../resources/resourcemanager.h" - -#include "../utils/dtor.h" -#include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; -Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,24 +54,6 @@ class WindowConfigListener : public ConfigListener } }; -Skin::Skin(): - closeImage(NULL), - instances(0) -{ -} - -Skin::~Skin() -{ - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } - - closeImage->decRef(); -} - Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -94,17 +72,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std logger->log("Window::Window(\"%s\")", caption.c_str()); if (!windowContainer) - { throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); - } - - // Loads the skin - loadSkin(skin); - - setGuiAlpha(); if (instances == 0) { + skinLoader = new SkinLoader(); windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization windowConfigListener->optionChanged("guialpha"); @@ -117,6 +89,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std setPadding(3); setTitleBarHeight(20); + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + // Add this window to the window container windowContainer->add(this); @@ -153,10 +130,10 @@ Window::~Window() if (instances == 0) { + delete skinLoader; config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - delete_all(mSkins); } } @@ -696,123 +673,6 @@ void Window::setGuiAlpha() mAlphaChanged = false; } -void Window::loadSkin(const std::string &filename) -{ - SkinIterator skinIterator = mSkins.find(filename); - - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - mSkin = skinIterator->second; - return; - } - - const std::string windowId = Window::getId(); - - mSkin = new Skin(); - - ResourceManager *resman = ResourceManager::getInstance(); - - logger->log("Loading Window Skin '%s'.", filename.c_str()); - logger->log("Loading Window ID '%s'.", windowId.c_str()); - - if (filename.empty()) - logger->error("Window::loadSkin(): Invalid File Name."); - - // TODO: - // If there is an error loading the specified file, we should try to revert - // to a 'default' skin file. Only if the 'default' skin file can't be loaded - // should we have a terminating error. - XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - logger->error("Widget Skinning error"); - - std::string skinSetImage; - skinSetImage = XML::getProperty(rootNode, "image", ""); - Image *dBorders = NULL; - if (!skinSetImage.empty()) - { - logger->log("Window::loadSkin(): defines " - "'%s' as a skin image.", skinSetImage.c_str()); - dBorders = resman->getImage("graphics/gui/" + skinSetImage); - } - else - { - logger->error("Window::loadSkin(): Skinset does not define an image!"); - } - - //iterate 's - for_each_xml_child_node(widgetNode, rootNode) - { - if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) - continue; - - std::string widgetType; - widgetType = XML::getProperty(widgetNode, "type", "unknown"); - if (widgetType == "Window") - { - // Iterate through 's - // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For - // now it can just be hard-coded. - for_each_xml_child_node(partNode, widgetNode) - { - if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - continue; - - std::string partType; - partType = XML::getProperty(partNode, "type", "unknown"); - // TOP ROW - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - - if (partType == "top-left-corner") - mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-edge") - mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-right-corner") - mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - - // MIDDLE ROW - else if (partType == "left-edge") - mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bg-quad") - mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "right-edge") - mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - - // BOTTOM ROW - else if (partType == "bottom-left-corner") - mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-edge") - mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-right-corner") - mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - - // Part is of an uknown type. - else - logger->log("Window::loadSkin(): Unknown Part Type '%s'", partType.c_str()); - } - } - // Widget is of an uknown type. - else - { - logger->log("Window::loadSkin(): Unknown Widget Type '%s'", widgetType.c_str()); - } - } - dBorders->decRef(); - - logger->log("Finished loading Window Skin."); - - // Hard-coded for now until we update the above code to look for window buttons. - mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); - mSkins[filename] = mSkin; -} - Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index c5660c58..7ae7ebba 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,8 +23,6 @@ #ifndef WINDOW_H #define WINDOW_H -#include - #include #include @@ -35,24 +33,13 @@ class ConfigListener; class GCContainer; class ContainerPlacer; -class Image; class Layout; class LayoutCell; class ResizeGrip; +class Skin; +class SkinLoader; class WindowContainer; -class Skin -{ - public: - Skin(); - ~Skin(); - - std::string mName; /**< Name of the skin to use */ - ImageRect border; /**< The window border and background */ - Image *closeImage; /**< Close Button Image */ - int instances; -}; - /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -296,11 +283,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ void reflowLayout(int w = 0, int h = 0); - /** - * Loads a window skin - */ - void loadSkin(const std::string &filename); - /** * Adds a widget to the window and sets it at given cell. */ @@ -317,17 +299,6 @@ class Window : public gcn::Window, gcn::WidgetListener * on window close they couldn't do otherwise. */ virtual void close(); - - /** - * Map containing all window skins - */ - typedef std::map Skins; - - /** - * Iterator for window skins - */ - typedef Skins::iterator SkinIterator; - protected: /** The window container windows add themselves to. */ diff --git a/src/main.cpp b/src/main.cpp index 9e7c91c0..a7032fb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -437,16 +437,18 @@ void init_engine(const Options &options) state = LOGIN_STATE; /**< Initial game state */ // Initialize sound engine - try { - if (config.getValue("sound", 0) == 1) { + try + { + if (config.getValue("sound", 0) == 1) sound.init(); - } + sound.setSfxVolume((int) config.getValue("sfxVolume", defaultSfxVolume)); sound.setMusicVolume((int) config.getValue("musicVolume", defaultMusicVolume)); } - catch (const char *err) { + catch (const char *err) + { state = ERROR_STATE; errorMessage = err; logger->log("Warning: %s", err); @@ -830,17 +832,18 @@ int main(int argc, char *argv[]) while (state != EXIT_STATE) { // Handle SDL events - while (SDL_PollEvent(&event)) { - switch (event.type) { + while (SDL_PollEvent(&event)) + { + switch (event.type) + { case SDL_QUIT: state = EXIT_STATE; break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) - { state = EXIT_STATE; - } + break; } @@ -855,11 +858,10 @@ int main(int argc, char *argv[]) { state = ERROR_STATE; - if (!network->getError().empty()) { + if (!network->getError().empty()) errorMessage = network->getError(); - } else { + else errorMessage = _("Got disconnected from server!"); - } } if (progressBar->isVisible()) @@ -882,7 +884,8 @@ int main(int argc, char *argv[]) gui->draw(); graphics->updateScreen(); - if (state != oldstate) { + if (state != oldstate) + { switch (oldstate) { case UPDATE_STATE: @@ -913,12 +916,14 @@ int main(int argc, char *argv[]) oldstate = state; if (currentDialog && state != ACCOUNT_STATE && - state != CHAR_CONNECT_STATE) { + state != CHAR_CONNECT_STATE) + { delete currentDialog; currentDialog = NULL; } - switch (state) { + switch (state) + { case LOADDATA_STATE: logger->log("State: LOADDATA"); @@ -941,10 +946,13 @@ int main(int argc, char *argv[]) case LOGIN_STATE: logger->log("State: LOGIN"); - if (!loginData.password.empty()) { + if (!loginData.password.empty()) + { loginData.registerLogin = false; state = ACCOUNT_STATE; - } else { + } + else + { currentDialog = new LoginDialog(&loginData); positionDialog(currentDialog, screenWidth, screenHeight); @@ -1029,9 +1037,12 @@ int main(int argc, char *argv[]) break; case UPDATE_STATE: - if (options.skipUpdate) { + if (options.skipUpdate) + { state = LOADDATA_STATE; - } else { + } + else + { // Determine which source to use for the update host if (!options.updateHost.empty()) updateHost = options.updateHost; @@ -1109,9 +1120,8 @@ int main(int argc, char *argv[]) SDLNet_Quit(); if (nullFile) - { fclose(nullFile); - } + logger->log("State: EXIT"); exit_engine(); PHYSFS_deinit(); @@ -1123,16 +1133,12 @@ void SetupListener::action(const gcn::ActionEvent &event) Window *window = NULL; if (event.getId() == "Setup") - { window = setupWindow; - } if (window) { window->setVisible(!window->isVisible()); if (window->isVisible()) - { window->requestMoveToTop(); - } } } -- cgit v1.2.3-70-g09d2 From 9935a143cc9c2cd672889965b5db647921cf0210 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 13:21:37 -0600 Subject: Fix segfault when being count reaches 0 too often --- src/being.cpp | 56 +++++++++++++++++++++++++++----------------------------- src/being.h | 5 ++++- src/main.cpp | 3 +++ 3 files changed, 34 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index ad6b2dea..d94d50d9 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -54,7 +54,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -int Being::instances = 0; int Being::mNumberOfHairstyles = 1; std::vector Being::emotionSet; @@ -94,29 +93,6 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble(); - if (instances == 0) - { - // Setup emote sprites - for (int i = 0; i <= EmoteDB::getLast(); i++) - { - EmoteInfo info = EmoteDB::get(i); - - std::string file = "graphics/sprites/" + info.sprites.front()->sprite; - int variant = info.sprites.front()->variant; - emotionSet.push_back(AnimatedSprite::load(file, variant)); - } - - // Hairstyles are encoded as negative numbers. Count how far negative - // we can go. - int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") - { - hairstyles++; - } - mNumberOfHairstyles = hairstyles; - } - - instances++; mSpeech = ""; mNameColor = 0x202020; mText = 0; @@ -133,11 +109,6 @@ Being::~Being() setMap(NULL); - instances--; - - if (instances == 0) - delete_all(emotionSet); - delete mSpeechBubble; delete mText; } @@ -608,3 +579,30 @@ void Being::setTargetAnimation(SimpleAnimation* animation) mUsedTargetCursor = animation; mUsedTargetCursor->reset(); } + +void Being::load() +{ + // Setup emote sprites + for (int i = 0; i <= EmoteDB::getLast(); i++) + { + EmoteInfo info = EmoteDB::get(i); + + std::string file = "graphics/sprites/" + info.sprites.front()->sprite; + int variant = info.sprites.front()->variant; + emotionSet.push_back(AnimatedSprite::load(file, variant)); + } + + // Hairstyles are encoded as negative numbers. Count how far negative + // we can go. + int hairstyles = 1; + while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") + { + hairstyles++; + } + mNumberOfHairstyles = hairstyles; +} + +void Being::cleanup() +{ + delete_all(emotionSet); +} diff --git a/src/being.h b/src/being.h index 63e5e07f..85e0c080 100644 --- a/src/being.h +++ b/src/being.h @@ -404,6 +404,10 @@ class Being : public Sprite virtual AnimatedSprite* getSprite(int index) const { return mSprites[index]; } + static void load(); + + static void cleanup(); + protected: /** * Sets the new path for this being. @@ -471,7 +475,6 @@ class Being : public Sprite // Target cursor being used SimpleAnimation* mUsedTargetCursor; - static int instances; /**< Number of Being instances */ static std::vector emotionSet; /**< Emoticons used by beings */ }; diff --git a/src/main.cpp b/src/main.cpp index a7032fb1..ec075a4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -479,6 +479,8 @@ void exit_engine() // Shutdown sound sound.close(); + Being::cleanup(); + // Unload XML databases ColorDB::unload(); EmoteDB::unload(); @@ -939,6 +941,7 @@ int main(int argc, char *argv[]) MonsterDB::load(); NPCDB::load(); EmoteDB::load(); + Being::load(); // Hairstyles and emotions state = CHAR_CONNECT_STATE; break; -- 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') 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 6b538196a799525d8ad4bf5cb5affe87745d4242 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 13:37:38 -0600 Subject: Fix a memory leak in dropdown --- src/gui/widgets/dropdown.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 035ce5d7..7036c2ee 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -108,6 +108,9 @@ DropDown::~DropDown() for_each(skin.grid, skin.grid + 9, dtor()); } + + gcn::ListModel *listModel = getListModel(); + if (listModel) delete listModel; } void DropDown::draw(gcn::Graphics* graphics) -- cgit v1.2.3-70-g09d2 From c2ae6d9cea9fc3d861e73d4cf7eca5284519758e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:06:30 -0600 Subject: Added a new Popup class, which overall is functionally similar to the Window class, but stripped down to the bare essential functionality to just draw and position them. This means no resizing, no close buttons, no ability to move them, etc. This should help reduce the overhead in drawing speech bubbles, as well as other popup type dialogs, but is also not a drop in replacement for the Window class as well. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 4 +- src/gui/itempopup.cpp | 13 +-- src/gui/itempopup.h | 4 +- src/gui/itemshortcutcontainer.cpp | 2 +- src/gui/menuwindow.cpp | 13 +-- src/gui/menuwindow.h | 4 +- src/gui/ministatus.cpp | 15 +-- src/gui/ministatus.h | 4 +- src/gui/popup.cpp | 211 ++++++++++++++++++++++++++++++++++++++ src/gui/popup.h | 196 +++++++++++++++++++++++++++++++++++ src/gui/popupmenu.cpp | 10 +- src/gui/speechbubble.cpp | 5 +- src/gui/speechbubble.h | 4 +- src/gui/window.cpp | 61 ++++++----- src/gui/window.h | 4 - src/gui/windowcontainer.cpp | 2 + src/gui/windowcontainer.h | 7 ++ 20 files changed, 479 insertions(+), 86 deletions(-) create mode 100644 src/gui/popup.cpp create mode 100644 src/gui/popup.h (limited to 'src') diff --git a/aethyra.cbp b/aethyra.cbp index 6bae4561..aa1737b7 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -195,6 +195,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 171ec7ff..9fdca23a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,6 +144,8 @@ SET(SRCS gui/passwordfield.h gui/playerbox.cpp gui/playerbox.h + gui/popup.cpp + gui/popup.h gui/popupmenu.cpp gui/popupmenu.h gui/progressbar.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 440c020e..c4265dec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ gui/playerbox.h \ + gui/popup.cpp \ + gui/popup.h \ gui/popupmenu.cpp \ gui/popupmenu.h \ gui/progressbar.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 3b621acd..47f4ffd2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -220,12 +220,12 @@ void createGuiWindows(Network *network) chatWindow->setVisible((bool) config.getValue( chatWindow->getWindowName() + "Visible", true)); miniStatusWindow->setVisible((bool) config.getValue( - miniStatusWindow->getWindowName() + "Visible", true)); + miniStatusWindow->getPopupName() + "Visible", true)); buyDialog->setVisible(false); sellDialog->setVisible(false); tradeWindow->setVisible(false); menuWindow->setVisible((bool) config.getValue( - menuWindow->getWindowName() + "Visible", true)); + menuWindow->getPopupName() + "Visible", true)); itemShortcutWindow->setVisible((bool) config.getValue( itemShortcutWindow->getWindowName() + "Visible", true)); emoteShortcutWindow->setVisible((bool) config.getValue( diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0f7e2d11..ebbc6af3 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -29,9 +29,8 @@ #include "itempopup.h" #include "scrollarea.h" #include "textbox.h" -#include "windowcontainer.h" -#include "widgets/layout.h" +#include "../graphics.h" #include "../resources/iteminfo.h" @@ -39,12 +38,8 @@ #include "../utils/stringutils.h" ItemPopup::ItemPopup(): - Window() + Popup() { - setResizable(false); - setShowTitle(false); - setTitleBarHeight(0); - // Item Name mItemName = new gcn::Label("Label"); mItemName->setFont(boldFont); @@ -208,8 +203,8 @@ unsigned int ItemPopup::getNumRows() void ItemPopup::view(int x, int y) { - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); if ((y - getHeight() - 10) < 0) y = 0; else diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index a91d8c6f..97da4cbb 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -24,13 +24,13 @@ #ifndef ITEMPOPUP_H #define ITEMPOPUP_H -#include "window.h" +#include "popup.h" class ItemInfo; class ScrollArea; class TextBox; -class ItemPopup : public Window +class ItemPopup : public Popup { public: ItemPopup(); diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index cb709227..c1baca76 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -231,7 +231,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item && inventoryWindow->isVisible()) + if (item) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 8a695865..e1be908b 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -26,7 +26,9 @@ #include "button.h" #include "menuwindow.h" -#include "windowcontainer.h" +#include "window.h" + +#include "../graphics.h" #include "../utils/gettext.h" @@ -50,13 +52,8 @@ namespace { } MenuWindow::MenuWindow(): - Window("") + Popup("Menu") { - setResizable(false); - setWindowName("Menu"); - setMovable(false); - setTitleBarHeight(0); - // Buttons static const char *buttonNames[] = { @@ -81,7 +78,7 @@ MenuWindow::MenuWindow(): h = btn->getHeight(); } - setPosition(windowContainer->getWidth() - x - 3, 3); + setPosition(graphics->getWidth() - x - 3, 3); setContentSize(x - 3, h); } diff --git a/src/gui/menuwindow.h b/src/gui/menuwindow.h index f70a332e..e8dc0b2e 100644 --- a/src/gui/menuwindow.h +++ b/src/gui/menuwindow.h @@ -23,14 +23,14 @@ #ifndef MENU_H #define MENU_H -#include "window.h" +#include "popup.h" /** * The Button Menu. * * \ingroup Interface */ -class MenuWindow : public Window +class MenuWindow : public Popup { public: /** diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 6537b48e..18b9d714 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -31,13 +31,8 @@ #include "../utils/stringutils.h" MiniStatusWindow::MiniStatusWindow(): - Window("") + Popup("MiniStatus") { - setWindowName("MiniStatus"); - setResizable(false); - setMovable(false); - setTitleBarHeight(0); - mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); @@ -52,25 +47,17 @@ MiniStatusWindow::MiniStatusWindow(): setContentSize(mXpBar->getX() + mXpBar->getWidth(), mXpBar->getY() + mXpBar->getHeight()); - setDefaultSize(0, 0, getWidth(), getHeight()); - loadWindowState(); } void MiniStatusWindow::update() { // HP Bar coloration if (player_node->mHp < int(player_node->mMaxHp / 3)) - { mHpBar->setColor(223, 32, 32); // Red - } else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2)) - { mHpBar->setColor(230, 171, 34); // Orange - } else - { mHpBar->setColor(0, 171, 34); // Green - } float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 33ee548d..b3fc58fc 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -23,7 +23,7 @@ #ifndef MINISTATUS_H #define MINISTATUS_H -#include "window.h" +#include "popup.h" class ProgressBar; @@ -32,7 +32,7 @@ class ProgressBar; * * \ingroup Interface */ -class MiniStatusWindow : public Window +class MiniStatusWindow : public Popup { public: /** diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp new file mode 100644 index 00000000..906f7a2e --- /dev/null +++ b/src/gui/popup.cpp @@ -0,0 +1,211 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from 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 "gui.h" +#include "skin.h" +#include "popup.h" +#include "window.h" +#include "windowcontainer.h" + +#include "../configlistener.h" +#include "../configuration.h" +#include "../log.h" + +#include "../resources/image.h" + +ConfigListener *Popup::popupConfigListener = 0; +int Popup::instances = 0; +bool Popup::mAlphaChanged = false; + +class PopupConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + Popup::mAlphaChanged = true; + } +}; + +Popup::Popup(const std::string& name, Window *parent, + const std::string& skin): + mParent(parent), + mPopupName(name), + mMinWidth(100), + mMinHeight(40), + mMaxWidth(INT_MAX), + mMaxHeight(INT_MAX) +{ + logger->log("Popup::Popup(\"%s\")", name.c_str()); + + if (!windowContainer) + throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); + + if (instances == 0) + { + popupConfigListener = new PopupConfigListener(); + // Send GUI alpha changed for initialization + popupConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", popupConfigListener); + } + + setPadding(3); + + instances++; + + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + + // Add this window to the window container + windowContainer->add(this); + + // Popups are invisible by default + setVisible(false); + + addWidgetListener(this); +} + +Popup::~Popup() +{ + logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + + instances--; + + mSkin->instances--; + + if (instances == 0) + { + config.removeListener("guialpha", popupConfigListener); + delete popupConfigListener; + popupConfigListener = NULL; + } +} + +void Popup::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + +void Popup::draw(gcn::Graphics *graphics) +{ + if (!isVisible()) + return; + + Graphics *g = static_cast(graphics); + + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + + // Update Popup alpha values + if (mAlphaChanged) + { + for_each(mSkin->border.grid, mSkin->border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), + config.getValue("guialpha", 0.8))); + } + drawChildren(graphics); +} + +gcn::Rectangle Popup::getChildrenArea() +{ + return gcn::Rectangle(getPadding(), 0, getWidth() - getPadding() * 2, + getHeight() - getPadding() * 2); +} + +void Popup::setContentSize(int width, int height) +{ + width += 2 * getPadding(); + height += 2 * getPadding(); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); +} + +void Popup::setLocationRelativeTo(gcn::Widget *widget) +{ + int wx, wy; + int x, y; + + widget->getAbsolutePosition(wx, wy); + getAbsolutePosition(x, y); + + setPosition(getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x), + getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); +} + +void Popup::setMinWidth(unsigned int width) +{ + mMinWidth = width; +} + +void Popup::setMinHeight(unsigned int height) +{ + mMinHeight = height; +} + +void Popup::setMaxWidth(unsigned int width) +{ + mMaxWidth = width; +} + +void Popup::setMaxHeight(unsigned int height) +{ + mMaxHeight = height; +} + +void Popup::scheduleDelete() +{ + windowContainer->scheduleDelete(this); +} + +void Popup::setGuiAlpha() +{ + //logger->log("Popup::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); + for (int i = 0; i < 9; i++) + { + //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + } + + mAlphaChanged = false; +} + diff --git a/src/gui/popup.h b/src/gui/popup.h new file mode 100644 index 00000000..0f7eebbf --- /dev/null +++ b/src/gui/popup.h @@ -0,0 +1,196 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from 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 POPUP_H +#define POPUP_H + +#include + +#include + +#include "../graphics.h" +#include "../guichanfwd.h" + +class ConfigListener; +class Skin; +class SkinLoader; +class Window; +class WindowContainer; + +/** + * A rather reduced down version of the Window class that is particularly suited + * for + * + * \ingroup GUI + */ +class Popup : public gcn::Container, gcn::WidgetListener +{ + public: + friend class PopupConfigListener; + + /** + * Constructor. Initializes the title to the given text and hooks + * itself into the popup container. + * + * @param name A human readable name for the popup. Only useful for + * debugging purposes. + * @param parent The parent Window. This is the Window standing above + * this one in the Window hiearchy. When reordering, + * a Popup will never go below its parent Window. + * @param skin The location where the Popup's skin XML can be found. + */ + Popup(const std::string& name = "", Window *parent = NULL, + const std::string &skin = "graphics/gui/gui.xml"); + + /** + * Destructor. Deletes all the added widgets. + */ + ~Popup(); + + /** + * Sets the window container to be used by new popups. + */ + static void setWindowContainer(WindowContainer *windowContainer); + + /** + * Draws the popup. + */ + void draw(gcn::Graphics *graphics); + + /** + * Sets the size of this popup. + */ + void setContentSize(int width, int height); + + /** + * Sets the location relative to the given widget. + */ + void setLocationRelativeTo(gcn::Widget *widget); + + /** + * Sets the minimum width of the popup. + */ + void setMinWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMinHeight(unsigned int height); + + /** + * Sets the maximum width of the popup. + */ + void setMaxWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMaxHeight(unsigned int height); + + /** + * Gets the minimum width of the popup. + */ + int getMinWidth() { return mMinWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMinHeight() { return mMinHeight; } + + /** + * Gets the maximum width of the popup. + */ + int getMaxWidth() { return mMaxWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMaxHeight() { return mMaxHeight; } + + /** + * Gets the padding of the popup. The padding is the distance between + * the popup border and the content. + * + * @return The padding of the popup. + * @see setPadding + */ + unsigned int getPadding() const { return mPadding; } + + /** + * Sets the padding of the popup. The padding is the distance between the + * popup border and the content. + * + * @param padding The padding of the popup. + * @see getPadding + */ + void setPadding(unsigned int padding) { mPadding = padding; } + + /** + * Returns the parent Window. + * + * @return The parent Window or NULL if there is none. + */ + Window* getParentWindow() { return mParent; } + + /** + * Sets the name of the popup. This is only useful for debug purposes. + */ + void setPopupName(const std::string &name) { mPopupName = name; } + + /** + * Returns the name of the popup. This is only useful for debug purposes. + */ + const std::string& getPopupName() { return mPopupName; } + + /** + * Schedule this popup for deletion. It will be deleted at the start + * of the next logic update. + */ + void scheduleDelete(); + + // Inherited from BasicContainer + + virtual gcn::Rectangle getChildrenArea(); + + private: + void setGuiAlpha(); + + Window *mParent; /**< The parent Window (if there is one) */ + std::string mPopupName; /**< Name of the Popup */ + static bool mAlphaChanged; /**< Whether the alpha percent was changed */ + int mMinWidth; /**< Minimum Popup width */ + int mMinHeight; /**< Minimum Popup height */ + int mMaxWidth; /**< Maximum Popup width */ + int mMaxHeight; /**< Maximum Popup height */ + unsigned int mPadding; /**< Holds the padding of the window. */ + + /** + * The config listener that listens to changes relevant to all Popups. + */ + static ConfigListener *popupConfigListener; + + static int instances; /**< Number of Popup instances */ + + Skin* mSkin; /**< Skin in use by this Popup */ +}; + +#endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index cead20ed..02be3055 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,11 +27,11 @@ #include "inventorywindow.h" #include "item_amount.h" #include "popupmenu.h" -#include "windowcontainer.h" #include "../being.h" #include "../beingmanager.h" #include "../floor_item.h" +#include "../graphics.h" #include "../item.h" #include "../localplayer.h" #include "../npc.h" @@ -292,10 +292,10 @@ void PopupMenu::showPopup(int x, int y, Item *item) void PopupMenu::showPopup(int x, int y) { setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); - if (windowContainer->getHeight() < (y + getHeight() + 5)) - y = windowContainer->getHeight() - getHeight(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); + if (graphics->getHeight() < (y + getHeight() + 5)) + y = graphics->getHeight() - getHeight(); setPosition(x, y); setVisible(true); requestMoveToTop(); diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index dcb03dca..0b18209e 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -32,13 +32,10 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"), + Popup("Speech", NULL, "graphics/gui/speechbubble.xml"), mText("") { setContentSize(140, 46); - setShowTitle(false); - setTitleBarHeight(0); - setMinWidth(29); setMinHeight(29); diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index 6b03cc85..a1a597c1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,12 +23,12 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H -#include "window.h" +#include "popup.h" class ScrollArea; class TextBox; -class SpeechBubble : public Window +class SpeechBubble : public Popup { public: SpeechBubble(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index def81c53..76c19751 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -41,7 +41,6 @@ #include "../resources/image.h" ConfigListener *Window::windowConfigListener = 0; -WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; @@ -216,39 +215,39 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, } else if (position == ImageRect::UPPER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); + offsetX += graphics->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += graphics->getWidth() - getWidth(); + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - offsetY += windowContainer->getHeight() - getHeight(); + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += graphics->getWidth() - getWidth(); + offsetY += graphics->getHeight() - getHeight(); } setPosition(offsetX, offsetY); @@ -429,8 +428,8 @@ void Window::mouseDragged(gcn::MouseEvent &event) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); - newX = std::min(windowContainer->getWidth() - getWidth(), newX); - newY = std::min(windowContainer->getHeight() - getHeight(), newY); + newX = std::min(graphics->getWidth() - getWidth(), newX); + newY = std::min(graphics->getHeight() - getHeight(), newY); setPosition(newX, newY); } @@ -475,13 +474,13 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height += newDim.y; newDim.y = 0; } - if (newDim.x + newDim.width > windowContainer->getWidth()) + if (newDim.x + newDim.width > graphics->getWidth()) { - newDim.width = windowContainer->getWidth() - newDim.x; + newDim.width = graphics->getWidth() - newDim.x; } - if (newDim.y + newDim.height > windowContainer->getHeight()) + if (newDim.y + newDim.height > graphics->getHeight()) { - newDim.height = windowContainer->getHeight() - newDim.y; + newDim.height = graphics->getHeight() - newDim.y; } // Update mouse offset when dragging bottom or right border @@ -585,39 +584,39 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight, } else if (position == ImageRect::UPPER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; + x = graphics->getWidth() - defaultWidth; } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - defaultHeight) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = graphics->getWidth() - defaultWidth; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - defaultHeight; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = windowContainer->getHeight() - defaultHeight; + x = (graphics->getWidth() - defaultWidth) / 2; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = windowContainer->getHeight() - defaultHeight; + x = graphics->getWidth() - defaultWidth; + y = graphics->getHeight() - defaultHeight; } mDefaultX = x - offsetX; diff --git a/src/gui/window.h b/src/gui/window.h index 7ae7ebba..d573d85f 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,10 +300,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); - protected: - /** The window container windows add themselves to. */ - static WindowContainer *windowContainer; - private: enum ResizeHandles { diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 0aa61965..ad86a253 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -24,6 +24,8 @@ #include "../utils/dtor.h" +WindowContainer *windowContainer = NULL; + void WindowContainer::logic() { delete_all(mDeathList); diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h index 09f34cf5..23b221cf 100644 --- a/src/gui/windowcontainer.h +++ b/src/gui/windowcontainer.h @@ -46,6 +46,11 @@ class WindowContainer : public gcn::Container */ void scheduleDelete(gcn::Widget *widget); + /** + * Get the number of widget instances + */ + int getNumberOfInstances() { return mDeathList.size(); } + private: /** * List of widgets that are scheduled to be deleted. @@ -55,4 +60,6 @@ class WindowContainer : public gcn::Container Widgets mDeathList; }; +extern WindowContainer* windowContainer; + #endif -- cgit v1.2.3-70-g09d2 From 0d50333f996a4d5c4bb28032e52a3c57f31805b6 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:20:54 -0600 Subject: Only check for name and descriptions in items with positive ID's in the ItemDB. This helps reduce the junk logging for the player and hair sprites. Signed-off-by: Ira Rice --- src/resources/itemdb.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 2eff514c..2b94bd61 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -145,9 +145,12 @@ void ItemDB::load() if (param == error_value) \ logger->log("ItemDB: Missing " #param " attribute for item %i!",id) - CHECK_PARAM(name, ""); + if (id >= 0) + { + CHECK_PARAM(name, ""); + CHECK_PARAM(description, ""); + } CHECK_PARAM(image, ""); - CHECK_PARAM(description, ""); // CHECK_PARAM(effect, ""); // CHECK_PARAM(type, 0); // CHECK_PARAM(weight, 0); -- cgit v1.2.3-70-g09d2 From 951fc647b291b38a3e4652b326ed4c4867c7ec0b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:28:40 -0600 Subject: Fixed up speech bubbles slightly so that it respects different padding values. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 0b18209e..d342328e 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -79,7 +79,7 @@ void SpeechBubble::setText(std::string text, bool showName) const int fontHeight = getFont()->getHeight(); const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 : mSpeechBox->getNumberOfRows(); - int yPos = showName ? fontHeight + 3 : 3; + int yPos = showName ? fontHeight + getPadding() : getPadding(); int height = (numRows * fontHeight); if (width < mSpeechBox->getMinWidth()) @@ -87,11 +87,11 @@ void SpeechBubble::setText(std::string text, bool showName) if (numRows == 1) { - yPos = (fontHeight / 4) + 3; + yPos = (fontHeight / 4) + getPadding(); height = ((3 * fontHeight) / 2) + 1; } - setContentSize(width + fontHeight, height + 6); + setContentSize(width + fontHeight, height + getPadding()); mSpeechArea->setDimension(gcn::Rectangle(4, yPos, width + 5, height)); } -- cgit v1.2.3-70-g09d2 From daf0d9e183456b30ffebfddfbcb2da2946c32e1d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:34:09 -0600 Subject: Removed widget listeners from the popup class. Tests have shown that at least for popup type functionality, this isn't needed. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 2 -- src/gui/popup.h | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 906f7a2e..4cf6bbf0 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -86,8 +86,6 @@ Popup::Popup(const std::string& name, Window *parent, // Popups are invisible by default setVisible(false); - - addWidgetListener(this); } Popup::~Popup() diff --git a/src/gui/popup.h b/src/gui/popup.h index 0f7eebbf..bfe8d7e9 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -23,8 +23,6 @@ #ifndef POPUP_H #define POPUP_H -#include - #include #include "../graphics.h" @@ -42,7 +40,7 @@ class WindowContainer; * * \ingroup GUI */ -class Popup : public gcn::Container, gcn::WidgetListener +class Popup : public gcn::Container { public: friend class PopupConfigListener; -- cgit v1.2.3-70-g09d2 From 1e2fbea2e6d4ab319763c6ffb35e4e4acdd4d5f5 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 20:47:09 -0600 Subject: Centered buy/sell dialog. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index f7684670..2022b040 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -51,6 +51,8 @@ BuySellDialog::BuySellDialog(Network *network): setContentSize(x, 2 * y + buyButton->getHeight()); + setLocationRelativeTo(ImageRect::CENTER); + requestFocus(); } -- cgit v1.2.3-70-g09d2 From c410a861fddc7829408d687e61c67c6101555067 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 21:38:17 -0600 Subject: Modified Skin class to use proper encapsulation, instead of leaving its skin variables public. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 6 +++--- src/gui/skin.cpp | 47 ++++++++++++++++++++++++++++++++--------------- src/gui/skin.h | 40 +++++++++++++++++++++++++++++++++++++--- src/gui/window.cpp | 18 +++++++++--------- 4 files changed, 81 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 4cf6bbf0..8e0c8fb9 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -123,12 +123,12 @@ void Popup::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Update Popup alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); } @@ -201,7 +201,7 @@ void Popup::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index e9d081e9..8787770c 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,9 +31,11 @@ SkinLoader* skinLoader = NULL; -Skin::Skin(): - closeImage(NULL), - instances(0) +Skin::Skin(ImageRect skin, Image* close, std::string name): + instances(0), + mName(name), + border(skin), + closeImage(close) { } @@ -49,6 +51,18 @@ Skin::~Skin() closeImage->decRef(); } +int Skin::getMinWidth() +{ + return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + + border.grid[2]->getWidth(); +} + +int Skin::getMinHeight() +{ + return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + + border.grid[6]->getHeight(); +} + Skin* SkinLoader::load(const std::string &filename) { SkinIterator skinIterator = mSkins.find(filename); @@ -59,8 +73,6 @@ Skin* SkinLoader::load(const std::string &filename) return skinIterator->second; } - Skin* skin = new Skin(); - ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Skin '%s'.", filename.c_str()); @@ -81,6 +93,8 @@ Skin* SkinLoader::load(const std::string &filename) std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; + ImageRect border; + if (!skinSetImage.empty()) { logger->log("SkinLoader::load(): defines " @@ -120,27 +134,27 @@ Skin* SkinLoader::load(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -158,7 +172,10 @@ Skin* SkinLoader::load(const std::string &filename) logger->log("Finished loading Skin."); // Hard-coded for now until we update the above code to look for window buttons. - skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + Image* closeImage = resman->getImage("graphics/gui/close_button.png"); + + Skin* skin = new Skin(border, closeImage); + mSkins[filename] = skin; return skin; } diff --git a/src/gui/skin.h b/src/gui/skin.h index 6dddb4a8..b7e70330 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -32,13 +32,47 @@ class Image; class Skin { public: - Skin(); + Skin(ImageRect skin, Image* close, std::string name = ""); ~Skin(); + /** + * Returns the skin's name. Useful for giving a human friendly skin + * name if a dialog for skin selection for a specific window type is + * done. + */ + std::string getName() { return mName; } + + /** + * Returns the background skin. + */ + ImageRect getBorder() { return border; } + + /** + * Returns the image used by a close button for this skin. + */ + Image* getCloseImage() { return closeImage; } + + /** + * Returns the number of instances which use this skin. + */ + int getNumberOfInstances() { return instances; } + + /** + * Returns the minimum width which can be used with this skin. + */ + int getMinWidth(); + + /** + * Returns the minimum height which can be used with this skin. + */ + int getMinHeight(); + + int instances; + + private: std::string mName; /**< Name of the skin to use */ ImageRect border; /**< The window border and background */ Image *closeImage; /**< Close Button Image */ - int instances; }; // Map containing all window skins @@ -47,7 +81,7 @@ typedef std::map Skins; // Iterator for window skins typedef Skins::iterator SkinIterator; -class SkinLoader +class SkinLoader { public: SkinLoader(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 76c19751..5c01daf3 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -148,7 +148,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Draw title if (mShowTitle) @@ -161,8 +161,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(mSkin->closeImage, - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->getCloseImage(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding() ); } @@ -170,10 +170,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getCloseImage()->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -352,10 +352,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding(), - mSkin->closeImage->getWidth(), - mSkin->closeImage->getHeight()); + mSkin->getCloseImage()->getWidth(), + mSkin->getCloseImage()->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -666,7 +666,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; -- cgit v1.2.3-70-g09d2 From 5b1e2aae6391edc99425ed7671d59eddd774212e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 21:46:22 -0600 Subject: Enforce minimum widths and heights to be at least as big as the minumum width and height for the skin used. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 4 ++-- src/gui/skin.cpp | 4 ++-- src/gui/skin.h | 4 ++-- src/gui/window.cpp | 5 +++-- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 8e0c8fb9..17d299a5 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -172,12 +172,12 @@ void Popup::setLocationRelativeTo(gcn::Widget *widget) void Popup::setMinWidth(unsigned int width) { - mMinWidth = width; + mMinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } void Popup::setMinHeight(unsigned int height) { - mMinHeight = height; + mMinHeight = height > mSkin->getMinHeight() ? height : mSkin->getMinHeight(); } void Popup::setMaxWidth(unsigned int width) diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index 8787770c..d44c54a8 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -51,13 +51,13 @@ Skin::~Skin() closeImage->decRef(); } -int Skin::getMinWidth() +unsigned int Skin::getMinWidth() { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + border.grid[2]->getWidth(); } -int Skin::getMinHeight() +unsigned int Skin::getMinHeight() { return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + border.grid[6]->getHeight(); diff --git a/src/gui/skin.h b/src/gui/skin.h index b7e70330..b8a1242e 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -60,12 +60,12 @@ class Skin /** * Returns the minimum width which can be used with this skin. */ - int getMinWidth(); + unsigned int getMinWidth(); /** * Returns the minimum height which can be used with this skin. */ - int getMinHeight(); + unsigned int getMinHeight(); int instances; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5c01daf3..d40ebca6 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -255,12 +255,13 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, void Window::setMinWidth(unsigned int width) { - mMinWinWidth = width; + mMinWinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } void Window::setMinHeight(unsigned int height) { - mMinWinHeight = height; + mMinWinHeight = height > mSkin->getMinHeight() ? + height : mSkin->getMinHeight(); } void Window::setMaxWidth(unsigned int width) -- cgit v1.2.3-70-g09d2 From 37b812f2892a9b11a88abcbcde0b47aca76f4a71 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 12 Mar 2009 06:44:16 -0600 Subject: Move emote sprite loading into EmoteDB --- src/being.cpp | 30 +----------------------------- src/being.h | 10 ---------- src/gui/emotecontainer.cpp | 2 +- src/gui/emotecontainer.h | 2 +- src/gui/emoteshortcutcontainer.cpp | 4 ++-- src/gui/emoteshortcutcontainer.h | 2 +- src/main.cpp | 3 --- src/resources/emotedb.cpp | 24 +++++++++++++++++------- src/resources/emotedb.h | 9 ++++++--- 9 files changed, 29 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index d94d50d9..54908b07 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -52,10 +52,8 @@ #include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/xml.h" int Being::mNumberOfHairstyles = 1; -std::vector Being::emotionSet; static const int X_SPEECH_OFFSET = 18; static const int Y_SPEECH_OFFSET = 60; @@ -461,7 +459,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) - emotionSet[emotionIndex]->draw(graphics, px, py); + EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py); } void Being::drawSpeech(int offsetX, int offsetY) @@ -580,29 +578,3 @@ void Being::setTargetAnimation(SimpleAnimation* animation) mUsedTargetCursor->reset(); } -void Being::load() -{ - // Setup emote sprites - for (int i = 0; i <= EmoteDB::getLast(); i++) - { - EmoteInfo info = EmoteDB::get(i); - - std::string file = "graphics/sprites/" + info.sprites.front()->sprite; - int variant = info.sprites.front()->variant; - emotionSet.push_back(AnimatedSprite::load(file, variant)); - } - - // Hairstyles are encoded as negative numbers. Count how far negative - // we can go. - int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") - { - hairstyles++; - } - mNumberOfHairstyles = hairstyles; -} - -void Being::cleanup() -{ - delete_all(emotionSet); -} diff --git a/src/being.h b/src/being.h index 85e0c080..6f3125c8 100644 --- a/src/being.h +++ b/src/being.h @@ -387,8 +387,6 @@ class Being : public Sprite */ void untarget() { mUsedTargetCursor = NULL; } - AnimatedSprite* getEmote(int index) { return emotionSet[index]; } - void setEmote(Uint8 emotion, Uint8 emote_time) { mEmotion = emotion; @@ -404,10 +402,6 @@ class Being : public Sprite virtual AnimatedSprite* getSprite(int index) const { return mSprites[index]; } - static void load(); - - static void cleanup(); - protected: /** * Sets the new path for this being. @@ -450,8 +444,6 @@ class Being : public Sprite Uint16 mHairStyle, mHairColor; Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - Uint16 mStunMode; /**< Stun mode; zero if not stunned */ - StatusEffects mStatusEffects; /**< Bitset of active status effects */ gcn::Color mNameColor; @@ -474,8 +466,6 @@ class Being : public Sprite // Target cursor being used SimpleAnimation* mUsedTargetCursor; - - static std::vector emotionSet; /**< Emoticons used by beings */ }; #endif diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index 9764ab9c..22b4cf50 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -54,7 +54,7 @@ EmoteContainer::EmoteContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mSelImg = resman->getImage("graphics/gui/selection.png"); diff --git a/src/gui/emotecontainer.h b/src/gui/emotecontainer.h index 260f1754..7e88cb71 100644 --- a/src/gui/emotecontainer.h +++ b/src/gui/emotecontainer.h @@ -122,7 +122,7 @@ class EmoteContainer : public gcn::Widget, */ void distributeValueChangedEvent(void); - std::vector mEmoteImg; + std::vector mEmoteImg; Image *mSelImg; int mSelectedEmoteIndex; diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index f4cef106..8c9df14e 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -60,7 +60,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS; @@ -113,7 +113,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (mEmoteMoved) { // Draw the emote image being dragged by the cursor. - AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; + const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; if (sprite) { const int tPosX = mCursorPosX - (sprite->getWidth() / 2); diff --git a/src/gui/emoteshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h index 4c4b3614..ff9f929c 100644 --- a/src/gui/emoteshortcutcontainer.h +++ b/src/gui/emoteshortcutcontainer.h @@ -69,7 +69,7 @@ class EmoteShortcutContainer : public ShortcutContainer void mouseReleased(gcn::MouseEvent &event); private: - std::vector mEmoteImg; + std::vector mEmoteImg; bool mEmoteClicked; int mEmoteMoved; diff --git a/src/main.cpp b/src/main.cpp index ec075a4c..a7032fb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -479,8 +479,6 @@ void exit_engine() // Shutdown sound sound.close(); - Being::cleanup(); - // Unload XML databases ColorDB::unload(); EmoteDB::unload(); @@ -941,7 +939,6 @@ int main(int argc, char *argv[]) MonsterDB::load(); NPCDB::load(); EmoteDB::load(); - Being::load(); // Hairstyles and emotions state = CHAR_CONNECT_STATE; break; diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 23a7833c..ec87c5cd 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -21,6 +21,7 @@ #include "emotedb.h" +#include "../animatedsprite.h" #include "../log.h" #include "../utils/xml.h" @@ -41,9 +42,8 @@ void EmoteDB::load() mLastEmote = 0; EmoteSprite *unknownSprite = new EmoteSprite; - unknownSprite->sprite = "error.xml"; + unknownSprite->sprite = AnimatedSprite::load("error.xml"); unknownSprite->name = "unknown"; - unknownSprite->variant = 0; mUnknown.sprites.push_back(unknownSprite); logger->log("Initializing emote database..."); @@ -77,8 +77,10 @@ void EmoteDB::load() if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { EmoteSprite *currentSprite = new EmoteSprite; - currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + std::string file = "graphics/sprites/" + (std::string) + (const char*) spriteNode->xmlChildrenNode->content; + currentSprite->sprite = AnimatedSprite::load(file, + XML::getProperty(spriteNode, "variant", 0)); currentInfo->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) @@ -102,6 +104,7 @@ void EmoteDB::unload() { while (!i->second->sprites.empty()) { + delete i->second->sprites.front()->sprite; delete i->second->sprites.front(); i->second->sprites.pop_front(); } @@ -112,6 +115,7 @@ void EmoteDB::unload() while (!mUnknown.sprites.empty()) { + delete mUnknown.sprites.front()->sprite; delete mUnknown.sprites.front(); mUnknown.sprites.pop_front(); } @@ -119,21 +123,27 @@ void EmoteDB::unload() mLoaded = false; } -const EmoteInfo& EmoteDB::get(int id) +const EmoteInfo *EmoteDB::get(int id) { EmoteInfosIterator i = mEmoteInfos.find(id); if (i == mEmoteInfos.end()) { logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); - return mUnknown; + return &mUnknown; } else { - return *(i->second); + return i->second; } } +const AnimatedSprite* EmoteDB::getAnimation(int id) +{ + const EmoteInfo *info = get(id); + return info->sprites.front()->sprite; +} + const int& EmoteDB::getLast() { return mLastEmote; diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h index d0cd4d71..48e1d53c 100644 --- a/src/resources/emotedb.h +++ b/src/resources/emotedb.h @@ -26,11 +26,12 @@ #include #include +class AnimatedSprite; + struct EmoteSprite { - std::string sprite; + const AnimatedSprite *sprite; std::string name; - int variant; }; struct EmoteInfo @@ -50,7 +51,9 @@ namespace EmoteDB void unload(); - const EmoteInfo& get(int id); + const EmoteInfo *get(int id); + + const AnimatedSprite *getAnimation(int id); const int& getLast(); -- cgit v1.2.3-70-g09d2 From f9a06a168a4c4354dcffdba7243b4eff783adb5b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 09:03:24 -0600 Subject: Made hair load again (commit e2d60401eaf55abe9e2251854f3174ffe0f4ad9e from TMW broke this, as it deleted the Being::load() method, which also loaded the hair styles). Also removed some unused variables in the being class. Signed-off-by: Ira Rice --- src/being.cpp | 16 ++++++++++++++-- src/being.h | 4 ++-- src/main.cpp | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 54908b07..64972912 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -83,8 +83,7 @@ Being::Being(int id, int job, Map *map): mSprites(VECTOREND_SPRITE, NULL), mSpriteIDs(VECTOREND_SPRITE, 0), mSpriteColors(VECTOREND_SPRITE, ""), - mStatusParticleEffects(&mStunParticleEffects, false), - mChildParticleEffects(&mStatusParticleEffects, false), + mChildParticleEffects(), mUsedTargetCursor(NULL) { setMap(map); @@ -578,3 +577,16 @@ void Being::setTargetAnimation(SimpleAnimation* animation) mUsedTargetCursor->reset(); } +void Being::load() +{ + // Hairstyles are encoded as negative numbers. Count how far negative + // we can go. + int hairstyles = 1; + + while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") + { + hairstyles++; + } + mNumberOfHairstyles = hairstyles; +} + diff --git a/src/being.h b/src/being.h index 6f3125c8..d7a7d1d5 100644 --- a/src/being.h +++ b/src/being.h @@ -402,6 +402,8 @@ class Being : public Sprite virtual AnimatedSprite* getSprite(int index) const { return mSprites[index]; } + static void load(); + protected: /** * Sets the new path for this being. @@ -450,8 +452,6 @@ class Being : public Sprite std::vector mSprites; std::vector mSpriteIDs; std::vector mSpriteColors; - ParticleList mStunParticleEffects; - ParticleVector mStatusParticleEffects; ParticleList mChildParticleEffects; private: diff --git a/src/main.cpp b/src/main.cpp index a7032fb1..fab7ed95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -939,6 +939,7 @@ int main(int argc, char *argv[]) MonsterDB::load(); NPCDB::load(); EmoteDB::load(); + Being::load(); // Hairstyles state = CHAR_CONNECT_STATE; break; -- cgit v1.2.3-70-g09d2 From 3ea4f74915184c08398bdf15e62d9667321ab15c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 10:52:26 -0600 Subject: Removed some unneeded stub code. Signed-off-by: Ira Rice --- src/being.h | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/being.h b/src/being.h index d7a7d1d5..4b30b6c5 100644 --- a/src/being.h +++ b/src/being.h @@ -210,14 +210,12 @@ class Being : public Sprite /** * Gets the hair color for this being. */ - int getHairColor() const - { return mHairColor; } + int getHairColor() const { return mHairColor; } /** * Gets the hair style for this being. */ - int getHairStyle() const - { return mHairStyle; } + int getHairStyle() const { return mHairStyle; } /** * Get the number of hairstyles implemented @@ -393,12 +391,6 @@ class Being : public Sprite mEmotionTime = emote_time; } - static int getHairColorsNr(void); - - static int getHairStylesNr(void); - - static std::string getHairColor(int index); - virtual AnimatedSprite* getSprite(int index) const { return mSprites[index]; } @@ -415,15 +407,6 @@ class Being : public Sprite */ virtual void updateCoords() {} - /** - * Trigger visual effect, with components - * - * \param effectId ID of the effect to trigger - * \param sfx Whether to trigger sound effects - * \param gfx Whether to trigger graphical effects - */ - void internalTriggerEffect(int effectId, bool sfx, bool gfx); - int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ @@ -433,12 +416,10 @@ class Being : public Sprite bool mIsGM; bool mParticleEffects; /**< Whether to display particles or not */ - typedef std::bitset StatusEffects; - /** Engine-related infos about weapon. */ const ItemInfo* mEquippedWeapon; - static int mNumberOfHairstyles; /** Number of hair styles in use */ + static int mNumberOfHairstyles; /** Number of hair styles in use */ Path mPath; std::string mSpeech; -- cgit v1.2.3-70-g09d2 From 393c1085ed1cb24092778594d2945a39428e41ad Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 17:19:31 +0100 Subject: Added a class for rendering of floating text This is a header only-class that merges the textrendering of the TextParticle and Text classes. It is done to reduce code duplication and to prepare some color configuration gui. --- src/gui/textrenderer.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.cpp | 1 + src/text.cpp | 24 ++++----------- src/textparticle.cpp | 30 +++++-------------- 4 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 src/gui/textrenderer.h (limited to 'src') diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h new file mode 100644 index 00000000..599e85a3 --- /dev/null +++ b/src/gui/textrenderer.h @@ -0,0 +1,81 @@ +/* + * Text Renderer + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra based on code from 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 TEXT_RENDERER_H +#define TEXT_RENDERER_H + +#include "graphics.h" +#include "palette.h" + +/** + * Class for text rendering. Used by the TextParticle, the Text and FlashText + * objects and the Preview in the color dialog. + */ +class TextRenderer +{ + public: + /** + * Renders a specified text. + */ + static inline void renderText(gcn::Graphics *graphics, const std::string& + text, int x, int y, gcn::Graphics::Alignment align, + const gcn::Color* color, gcn::Font *font, bool outline = false, + bool shadow = false, int alpha = 255) + { + graphics->setFont(font); + + // Text shadow + if (shadow) + { + graphics->setColor(guiPalette->getColor(Palette::SHADOW, + alpha / 2)); + if (outline) + { + graphics->drawText(text, x + 2, y + 2, align); + } + else + { + graphics->drawText(text, x + 1, y + 1, align); + } + } + + if (outline) { +/* graphics->setColor(guiPalette->getColor(Palette::OUTLINE, + alpha/4)); + // TODO: Reanable when we can draw it nicely in software mode + graphics->drawText(text, x + 2, y + 2, align); + graphics->drawText(text, x + 1, y + 2, align); + graphics->drawText(text, x + 2, y + 1, align);*/ + + // Text outline + graphics->setColor(guiPalette->getColor(Palette::OUTLINE, alpha)); + graphics->drawText(text, x + 1, y, align); + graphics->drawText(text, x - 1, y, align); + graphics->drawText(text, x, y + 1, align); + graphics->drawText(text, x, y - 1, align); + } + + graphics->setColor(*color); + graphics->drawText(text, x, y, align); + } +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index d40ebca6..f6d23950 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -630,6 +630,7 @@ void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); setSize(mDefaultWidth, mDefaultHeight); + saveWindowState(); } int Window::getResizeHandles(gcn::MouseEvent &event) diff --git a/src/text.cpp b/src/text.cpp index e5e40235..c167701a 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -26,6 +26,8 @@ #include "textmanager.h" #include "gui/gui.h" +#include "gui/palette.h" +#include "gui/textrenderer.h" int Text::mInstances = 0; @@ -76,23 +78,9 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) { graphics->setFont(boldFont); - // Text shadow - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, mX - xOff + 1, mY - yOff + 1, - gcn::Graphics::LEFT); - - // Text outline - graphics->drawText(mText, mX - xOff + 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff - 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff + 1, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff - 1, - gcn::Graphics::LEFT); - - graphics->setColor(mColor); - graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); + TextRenderer::renderText(graphics, mText, + mX - xOff, mY - yOff, gcn::Graphics::LEFT, + &mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, @@ -107,9 +95,7 @@ void FlashText::draw(gcn::Graphics *graphics, int xOff, int yOff) if (mTime) { if ((--mTime & 4) == 0) - { return; - } } Text::draw(graphics, xOff, yOff); } diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 8a8948f4..a065eadd 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,10 +22,12 @@ #include -#include "graphics.h" -#include "textparticle.h" #include +#include "textparticle.h" + +#include "gui/textrenderer.h" + TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, bool outline): @@ -61,24 +63,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const alpha /= mFadeIn; } - graphics->setFont(mTextFont); - if (mOutline) - { - graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); - // Text outline - graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); - graphics->drawText(mText, screenX + 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX - 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY + 1, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY - 1, - gcn::Graphics::CENTER); - } - graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); - graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); + TextRenderer::renderText(graphics, mText, + screenX, screenY, gcn::Graphics::CENTER, + &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, + (int) alpha); } -- cgit v1.2.3-70-g09d2 From 7d20381b7b9abdf0934ee0fbbb196c788ea93a0d Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 15:35:54 +0100 Subject: Extending the internal handling of colors The internal storage for colors was in the file color.h/color.cpp. It mainly managed the colors in the chat. The Color class was extended to be more generic now and it stores gcn::Color objects instead of integers now. A lot of new colortypes are now available, though not many of them are used for now, that will come in the next patches. The Color class was renamed to Palette and color.{h,cpp} to palette.{h,cpp} to better describe its purpose. The color config gui now lists the new colors, even changes them, but the result is not displayed properly for now. --- aethyra.cbp | 5 +- src/CMakeLists.txt | 5 +- src/Makefile.am | 5 +- src/gui/browserbox.cpp | 21 ++- src/gui/listbox.cpp | 11 +- src/gui/palette.cpp | 317 +++++++++++++++++++++++++++++++++++++++++++ src/gui/palette.h | 297 ++++++++++++++++++++++++++++++++++++++++ src/gui/setup_colors.cpp | 55 ++++---- src/gui/setup_colors.h | 2 + src/gui/shoplistbox.cpp | 40 +++--- src/gui/table.cpp | 31 +---- src/gui/widgets/dropdown.cpp | 21 ++- src/main.cpp | 8 +- src/text.cpp | 2 +- 14 files changed, 714 insertions(+), 106 deletions(-) create mode 100644 src/gui/palette.cpp create mode 100644 src/gui/palette.h (limited to 'src') diff --git a/aethyra.cbp b/aethyra.cbp index aa1737b7..b9e80430 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -132,8 +132,6 @@ - - @@ -191,6 +189,8 @@ + + @@ -256,6 +256,7 @@ + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9fdca23a..6565a1b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,8 +81,6 @@ SET(SRCS gui/chatinput.h gui/checkbox.cpp gui/checkbox.h - gui/color.cpp - gui/color.h gui/confirm_dialog.cpp gui/confirm_dialog.h gui/connection.cpp @@ -140,6 +138,8 @@ SET(SRCS gui/npc_text.h gui/ok_dialog.cpp gui/ok_dialog.h + gui/palette.cpp + gui/palette.h gui/passwordfield.cpp gui/passwordfield.h gui/playerbox.cpp @@ -205,6 +205,7 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h + gui/textrenderer.h gui/trade.cpp gui/trade.h gui/truetypefont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c4265dec..b3bdde9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,8 +31,6 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/chatinput.h \ gui/checkbox.cpp \ gui/checkbox.h \ - gui/color.cpp \ - gui/color.h \ gui/confirm_dialog.cpp \ gui/confirm_dialog.h \ gui/connection.cpp \ @@ -90,6 +88,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/npc_text.h \ gui/ok_dialog.cpp \ gui/ok_dialog.h \ + gui/palette.cpp \ + gui/palette.h \ gui/passwordfield.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ @@ -155,6 +155,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 2b690b21..46c8bdf1 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -25,8 +25,8 @@ #include #include "browserbox.h" -#include "color.h" #include "linkhandler.h" +#include "palette.h" #include "truetypefont.h" BrowserBox::BrowserBox(unsigned int mode, bool opaque): @@ -250,16 +250,15 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mOpaque) { - graphics->setColor(gcn::Color(BGCOLOR)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } if (mSelectedLink >= 0) { - bool valid; if ((mHighMode & BACKGROUND)) { - graphics->setColor(gcn::Color(textColor->getColor('H', valid))); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT)); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -270,7 +269,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(gcn::Color(textColor->getColor('<', valid))); + graphics->setColor(guiPalette->getColor(Palette::HYPERLINK)); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, @@ -284,11 +283,11 @@ void BrowserBox::draw(gcn::Graphics *graphics) int link = 0; TrueTypeFont *font = static_cast(getFont()); - graphics->setColor(BLACK); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) { - int selColor = BLACK; - int prevColor = selColor; + const gcn::Color *selColor = &guiPalette->getColor(Palette::TEXT); + const gcn::Color *prevColor = selColor; std::string row = *(i); bool wrapped = false; x = 0; @@ -336,7 +335,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) else { bool valid; - int rgb = textColor->getColor(c, valid); + const gcn::Color *col = &guiPalette->getColor(c, valid); if (c == '<') { const int size = mLinks[link].x2 - mLinks[link].x1; @@ -349,7 +348,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) } if (valid) { - selColor = rgb; + selColor = col; } } start += 3; @@ -359,7 +358,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) break; } } - graphics->setColor(gcn::Color(selColor)); + graphics->setColor(*selColor); } std::string::size_type len = diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 82011239..e53a1652 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -25,8 +25,8 @@ #include #include -#include "color.h" #include "listbox.h" +#include "palette.h" #include "../configuration.h" @@ -45,13 +45,8 @@ void ListBox::draw(gcn::Graphics *graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); graphics->setFont(getFont()); const int fontHeight = getFont()->getHeight(); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp new file mode 100644 index 00000000..a79f2050 --- /dev/null +++ b/src/gui/palette.cpp @@ -0,0 +1,317 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * 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 "palette.h" +#include "gui.h" + +#include "../configuration.h" +#include "../game.h" + +#include "../utils/gettext.h" +#include "../utils/stringutils.h" + +const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); + +const gcn::Color Palette::RAINBOW_COLORS[8] = { + gcn::Color(255, 0, 0), + gcn::Color(255, 153, 0), + gcn::Color(255, 255, 0), + gcn::Color(0, 153, 0), + gcn::Color(0, 204, 204), + gcn::Color(51, 0, 153), + gcn::Color(153, 0, 153) +}; +/** Number of Elemets of RAINBOW_COLORS */ +const int Palette::RAINBOW_COLOR_COUNT = 7; + +std::string Palette::getConfigName(const std::string& typeName) +{ + std::string res = "Color" + typeName; + + int pos = 5; + for (unsigned int i = 0; i < typeName.length(); i++) + { + if (i==0 || typeName[i] == '_') + { + if (i > 0) + { + i++; + } + res[pos] = typeName[i]; + } + else + { + res[pos] = tolower(typeName[i]); + } + pos++; + } + res.erase(pos, res.length() - pos); + + return res; +} + +DEFENUMNAMES(ColorType, COLOR_TYPE); + +const int Palette::GRADIENT_DELAY = 20; + +Palette::Palette() : + mRainbowTime(tick_time), + mColVector(ColVector(TYPE_COUNT)), + mGradVector() +{ + std::string indent = " "; + addColor(TEXT, 0x000000, STATIC, _("Text")); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + + addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); + + addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); + addColor(SHOP_WARNING, 0x910000, STATIC, indent + + _("Item too expensive")); + + addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C'); + addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G'); + addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y'); + addColor(WHISPER, 0x0000ff, STATIC, indent + _("Whisper"), 'W'); + addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I'); + addColor(PARTY, 0xff00d8, STATIC, indent + _("Party"), 'P'); + addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S'); + addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); + addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); + + addColor(BEING, 0xffffff, STATIC, _("Being"), 0); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); + + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), + 0); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, + indent + _("Player hits Monster"), 0); + addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, + indent + _("Monster hits Player"), 0); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, + indent + _("Critical Hit"), 0); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + commit(true); +} + +Palette::~Palette() +{ + const std::string *configName; + for (ColVector::iterator col = mColVector.begin(), + colEnd = mColVector.end(); col != colEnd; ++col) + { + configName = &ColorTypeNames[col->type]; + config.setValue(*configName + "Gradient", col->grad); + if (col->grad == STATIC) + { + config.setValue(*configName, toString(col->getRGB())); + } + } +} + +const gcn::Color& Palette::getColor(char c, bool &valid) + { + for (ColVector::const_iterator col = mColVector.begin(), + colEnd = mColVector.end(); col != colEnd; ++col) + { + if (col->ch == c) + { + valid = true; + return col->color; + } + } + valid = false; + return BLACK; +} + +void Palette::setColor(ColorType type, int r, int g, int b) +{ + mColVector[type].color.r = r; + mColVector[type].color.g = g; + mColVector[type].color.b = b; +} + +void Palette::setGradient(ColorType type, GradientType grad) +{ + ColorElem *elem = &mColVector[type]; + if (elem->grad != STATIC && grad == STATIC) + { + for (unsigned int i = 0; i < mGradVector.size(); i++) + { + if (mGradVector[i] == elem) + { + mGradVector.erase(mGradVector.begin() + i); + break; + } + } + } + else if (elem->grad == STATIC && grad != STATIC) + { + mGradVector.push_back(elem); + } + + if (elem->grad != grad) + { + elem->grad = grad; + } +} + +std::string Palette::getElementAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mColVector[i].text; +} + +Palette::ColorType Palette::getColorTypeAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return CHAT; + } + return mColVector[i].type; +} + +void Palette::commit(bool commitNonStatic) +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; ++i) + { + i->committedGrad = i->grad; + if (commitNonStatic || i->grad == STATIC) + { + i->committedColor = i->color; + } + } +} + +void Palette::rollback() +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; + ++i) + { + i->grad = i->committedGrad; + if (i->grad == STATIC) + { + i->color = i->committedColor; + } + } +} + +void Palette::addColor(Palette::ColorType type, int rgb, + Palette::GradientType grad, + const std::string &text, char c) +{ + const std::string *configName = &ColorTypeNames[type]; + gcn::Color trueCol = (int)config.getValue(*configName, rgb); + grad = (GradientType)config.getValue(*configName + "Gradient", grad); + mColVector[type].set(type, trueCol, grad, text, c); + if (grad != STATIC) + { + mGradVector.push_back(&mColVector[type]); + } +} + +void Palette::advanceGradient () +{ + if (get_elapsed_time(mRainbowTime) > 5) + { + int pos, colIndex, colVal; + // For slower systems, advance can be greater than one (adcanve > 1 + // skips advance-1 steps). Should make gradient look the same + // independent of the framerate. + int advance = get_elapsed_time(mRainbowTime) / 5; + double startColVal, destColVal; + + for (unsigned int i = 0; i < mGradVector.size(); i++) + { + mGradVector[i]->gradientIndex = + (mGradVector[i]->gradientIndex + advance) % + (GRADIENT_DELAY * + ((mGradVector[i]->grad == SPECTRUM) ? 6 : + RAINBOW_COLOR_COUNT)); + + pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY; + colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY; + + if (mGradVector[i]->grad == SPECTRUM) + { + if (colIndex % 2) + { // falling curve + colVal = (int)(255.0 * + (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + } + else + { // ascending curve + colVal = (int)(255.0 * + (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + + 1) / 2); + } + + mGradVector[i]->color.r = + (colIndex == 0 || colIndex == 5) ? 255 : + (colIndex == 1 || colIndex == 4) ? colVal : 0; + mGradVector[i]->color.g = + (colIndex == 1 || colIndex == 2) ? 255 : + (colIndex == 0 || colIndex == 3) ? colVal : 0; + mGradVector[i]->color.b = + (colIndex == 3 || colIndex == 4) ? 255 : + (colIndex == 2 || colIndex == 5) ? colVal : 0; + } + else + { + const gcn::Color* startCol = &RAINBOW_COLORS[colIndex]; + const gcn::Color* destCol = + &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT]; + + startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2; + destColVal = 1 - startColVal; + + mGradVector[i]->color.r =(int)( + startColVal * startCol->r + + destColVal * destCol->r); + + mGradVector[i]->color.g =(int)( + startColVal * startCol->g + + destColVal * destCol->g); + + mGradVector[i]->color.b =(int)( + startColVal * startCol->b + + destColVal * destCol->b); + } + } + + mRainbowTime = tick_time; + } +} diff --git a/src/gui/palette.h b/src/gui/palette.h new file mode 100644 index 00000000..a372d6cd --- /dev/null +++ b/src/gui/palette.h @@ -0,0 +1,297 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * 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 PALETTE_H +#define PALETTE_H + +#include +#include +#include + +#include +#include + +// Generate strings from an enum ... some preprocessor fun. +#define EDEF(a) a, +#define ECONFIGSTR(a) Palette::getConfigName(#a), + +#define TEXTENUM(name,def)\ + enum name { def(EDEF) };\ + static const std::string name ## Names[]; +#define DEFENUMNAMES(name,def)\ + const std::string Palette::name ## Names[] = { def(ECONFIGSTR) "" }; + +/** + * Class controlling the game's color palette. + */ +class Palette : public gcn::ListModel +{ + public: + /** List of all colors that are configurable. */ + #define COLOR_TYPE(ENTRY)\ + ENTRY(TEXT)\ + ENTRY(SHADOW)\ + ENTRY(OUTLINE)\ + ENTRY(BACKGROUND)\ + ENTRY(HIGHLIGHT)\ + ENTRY(SHOP_WARNING)\ + ENTRY(CHAT)\ + ENTRY(GM)\ + ENTRY(PLAYER)\ + ENTRY(WHISPER)\ + ENTRY(IS)\ + ENTRY(PARTY)\ + ENTRY(SERVER)\ + ENTRY(LOGGER)\ + ENTRY(HYPERLINK)\ + ENTRY(BEING)\ + ENTRY(PC)\ + ENTRY(SELF)\ + ENTRY(GM_NAME)\ + ENTRY(NPC)\ + ENTRY(MONSTER)\ + ENTRY(PARTICLE)\ + ENTRY(EXP_INFO)\ + ENTRY(PICKUP_INFO)\ + ENTRY(HIT_PLAYER_MONSTER)\ + ENTRY(HIT_MONSTER_PLAYER)\ + ENTRY(HIT_CRITICAL)\ + ENTRY(MISS)\ + ENTRY(TYPE_COUNT)\ + + TEXTENUM(ColorType, COLOR_TYPE); + + /** Colors can be static or can alter over time. */ + enum GradientType { + STATIC, + SPECTRUM, + RAINBOW + }; + + /** + * Constructor + */ + Palette(); + + /** + * Destructor + */ + ~Palette(); + + /** + * Returns the color associated with a character, if it exists. Returns + * Palette::BLACK if the character is not found. + * + * @param c character requested + * @param valid indicate whether character is known + * + * @return the requested color or Palette::BLACK + */ + const gcn::Color& getColor(char c, bool &valid); + + /** + * Gets the color with the associated type. Sets the alpha channel + * before returning. + * + * @param type the color type requested + * @param alpha alpha channel to use + * + * @return the requested color + */ + inline const gcn::Color& getColor(ColorType type, int alpha = 255) + { + gcn::Color* col = &mColVector[type].color; + col->a = alpha; + return *col; + } + + /** + * Gets the GradientType used by the specified color. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ + inline GradientType getGradientType(ColorType type) + { + return mColVector[type].grad; + } + + /** + * Get the character used by the specified color. + * + * @param type the color type of the color + * + * @return the color char of the color with the given index + */ + inline char getColorChar(ColorType type) + { + return mColVector[type].ch; + } + + /** + * Sets the color for the specified type. + * + * @param type color to be set + * @param r red component + * @param g green component + * @param b blue component + */ + void setColor(ColorType type, int r, int g, int b); + + /** + * Sets the gradient type for the specified color. + * + * @param grad gradient type to set + */ + void setGradient(ColorType type, GradientType grad); + + /** + * Returns the number of colors known. + * + * @return the number of colors known + */ + inline int getNumberOfElements() { return mColVector.size(); } + + /** + * Returns the name of the ith color. + * + * @param i index of color interested in + * + * @return the name of the color + */ + std::string getElementAt(int i); + + /** + * Gets the ColorType used by the color for the element at index i in + * the current color model. + * + * @param i the index of the color + * + * @return the color type of the color with the given index + */ + ColorType getColorTypeAt(int i); + + /** + * Commit the colors + */ + inline void commit() + { + commit(false); + } + + /** + * Rollback the colors + */ + void rollback(); + + /** + * Updates all colors, that are non-static. + */ + void advanceGradient(); + + private: + /** Black Color Constant */ + static const gcn::Color BLACK; + + /** Colors used for the rainbow gradient */ + static const gcn::Color RAINBOW_COLORS[]; + static const int RAINBOW_COLOR_COUNT; + /** Parameter to control the speed of the gradient */ + static const int GRADIENT_DELAY; + /** Time tick, that gradient-type colors were updated the last time. */ + int mRainbowTime; + + /** + * Define a color replacement. + * + * @param i the index of the color to replace + * @param r red component + * @param g green component + * @param b blue component + */ + void setColorAt(int i, int r, int g, int b); + + /** + * Commit the colors. Commit the non-static color values, if + * commitNonStatic is true. Only needed in the constructor. + */ + void commit(bool commitNonStatic); + + struct ColorElem + { + ColorType type; + gcn::Color color; + gcn::Color committedColor; + std::string text; + char ch; + GradientType grad; + GradientType committedGrad; + int gradientIndex; + + void set(ColorType type, gcn::Color& color, GradientType grad, + const std::string &text, char c) + { + ColorElem::type = type; + ColorElem::color = color; + ColorElem::text = text; + ColorElem::ch = c; + ColorElem::grad = grad; + ColorElem::gradientIndex = rand(); + } + + inline int getRGB() { + return (committedColor.r << 16) | (committedColor.g << 8) | + committedColor.b; + } + }; + typedef std::vector ColVector; + /** Vector containing the colors. */ + ColVector mColVector; + std::vector mGradVector; + + /** + * Initialise color + * + * @param c character that needs initialising + * @param rgb default color if not found in config + * @param text identifier of color + */ + void addColor(ColorType type, int rgb, GradientType grad, + const std::string &text, char c = 0); + + /** + * Prefixes the given string with "Color", lowercases all letters but + * the first and all following a '_'. All '_'s will be removed. + * + * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster + * + * @param typeName string to transform + * + * @return the transformed string + */ + static std::string getConfigName(const std::string& typeName); +}; + +extern Palette *guiPalette; + +#endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 31b56b51..4f017e15 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,9 +27,9 @@ #include #include "browserbox.h" -#include "color.h" #include "itemlinkhandler.h" #include "listbox.h" +#include "palette.h" #include "scrollarea.h" #include "setup_colors.h" #include "slider.h" @@ -42,12 +42,14 @@ #include "../utils/gettext.h" #include "../utils/stringutils.h" +const std::string Setup_Colors::rawmsg = _("This is what the color looks like"); + Setup_Colors::Setup_Colors() : mSelected(-1) { setOpaque(false); - mColorBox = new ListBox(textColor); + mColorBox = new ListBox(guiPalette); mColorBox->setActionEventId("color_box"); mColorBox->addActionListener(this); @@ -131,6 +133,9 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { + delete mPreview; + delete mPreviewBox; + delete mRedLabel; delete mRedSlider; delete mRedText; @@ -143,6 +148,7 @@ Setup_Colors::~Setup_Colors() delete mBlueSlider; delete mBlueText; + delete mColorBox; delete mScroll; } @@ -151,22 +157,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event) if (event.getId() == "color_box") { mSelected = mColorBox->getSelected(); - int col = textColor->getColorAt(mSelected); - char ch = textColor->getColorCharAt(mSelected); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + std::string msg; + mPreview->clearRows(); + char ch = guiPalette->getColorChar(type); if (ch == '<') - msg = toString("@@|") + - _("This is what the color looks like") + "@@"; + msg = toString("@@|") + rawmsg + "@@"; else - msg = "##" + toString(ch) + - _("This is what the color looks like"); - - mPreview->clearRows(); + msg = "##" + toString(ch) + rawmsg; mPreview->addRow(msg); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); return; } @@ -202,16 +208,17 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value) void Setup_Colors::apply() { - textColor->commit(); + guiPalette->commit(); } void Setup_Colors::cancel() { - textColor->rollback(); - int col = textColor->getColorAt(mSelected); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + guiPalette->rollback(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); } void Setup_Colors::listen(const TextField *tf) @@ -242,8 +249,10 @@ void Setup_Colors::updateColor() { return; } - int rgb = static_cast(mRedSlider->getValue()) << 16 | - static_cast(mGreenSlider->getValue()) << 8 | - static_cast(mBlueSlider->getValue()); - textColor->setColorAt(mSelected, rgb); + + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 98a2d18b..6cf59b6d 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -48,6 +48,8 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void listen(const TextField *tf); private: + static const std::string rawmsg; + gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 776f26bc..74209122 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -23,7 +23,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "shop.h" #include "shoplistbox.h" @@ -64,11 +64,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); + int alpha = (int)(mAlpha * 255.0f); + const gcn::Color* highlightColor = + &guiPalette->getColor(Palette::HIGHLIGHT, alpha); Graphics *graphics = static_cast(gcnGraphics); @@ -79,19 +77,27 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) i < mListModel->getNumberOfElements(); ++i, y += mRowHeight) { - gcn::Color backgroundColor = gcn::Color(255, 255, 255, alpha); + gcn::Color temp; + const gcn::Color* backgroundColor = + &guiPalette->getColor(Palette::BACKGROUND, alpha); - if (i == mSelected) - { - backgroundColor = gcn::Color(red, green, blue, alpha); - } - else if (mShopItems && + if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) - { - backgroundColor = gcn::Color(145, 145, 145, alpha); - } + if (i != mSelected) + backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING, + alpha); + else + { + temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha); + temp.r = (temp.r + highlightColor->r) / 2; + temp.g = (temp.g + highlightColor->g) / 2; + temp.b = (temp.g + highlightColor->b) / 2; + backgroundColor = &temp; + } + else if (i == mSelected) + backgroundColor = highlightColor; - graphics->setColor(backgroundColor); + graphics->setColor(*backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); if (mShopItems) @@ -102,7 +108,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->drawImage(icon, 1, y); } } - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b2571495..144e7e21 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -24,7 +24,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "table.h" #include "../configuration.h" @@ -273,11 +273,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mOpaque) { - const int red = getBackgroundColor().r; - const int green = getBackgroundColor().g; - const int blue = getBackgroundColor().b; - const int alpha = (int)(mAlpha * 255.0f); - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -324,15 +321,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); graphics->fillRectangle(bounds); } @@ -346,15 +336,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mLinewiseMode && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); graphics->fillRectangle(gcn::Rectangle(0, y_offset, x_offset, height)); } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 7036c2ee..076a167f 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -24,8 +24,8 @@ #include "dropdown.h" -#include "../color.h" #include "../listbox.h" +#include "../palette.h" #include "../scrollarea.h" #include "../../configuration.h" @@ -140,27 +140,24 @@ void DropDown::draw(gcn::Graphics* graphics) } } - bool valid; +// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = textColor->getColor('H', valid); - highlightColor.a = alpha; + gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - int red = getBackgroundColor().r; - int green = getBackgroundColor().g; - int blue = getBackgroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + gcn::Color col = getBackgroundColor(); + col.a = alpha; + graphics->setColor(col); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - red = getForegroundColor().r; - green = getForegroundColor().g; - blue = getForegroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + col = getForegroundColor(); + col.a = alpha; + graphics->setColor(col); } graphics->setFont(getFont()); diff --git a/src/main.cpp b/src/main.cpp index fab7ed95..bed297de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,10 +56,10 @@ #include "gui/button.h" #include "gui/char_server.h" #include "gui/char_select.h" -#include "gui/color.h" #include "gui/gui.h" #include "gui/login.h" #include "gui/ok_dialog.h" +#include "gui/palette.h" #include "gui/progressbar.h" #include "gui/register.h" #include "gui/sdlinput.h" @@ -134,7 +134,7 @@ CharServerHandler charServerHandler; LoginData loginData; LockedArray charInfo(MAX_SLOT + 1); -Color *textColor; +Palette *guiPalette; // This anonymous namespace hides whatever is inside from other modules. namespace { @@ -767,7 +767,7 @@ int main(int argc, char *argv[]) unsigned int oldstate = !state; // We start with a status change. // Needs to be created in main, as the updater uses it - textColor = new Color(); + guiPalette = new Palette; Game *game = NULL; Window *currentDialog = NULL; @@ -1108,7 +1108,7 @@ int main(int argc, char *argv[]) usleep(50000); } - delete textColor; + delete guiPalette; #ifdef PACKAGE_VERSION delete versionLabel; #endif diff --git a/src/text.cpp b/src/text.cpp index c167701a..2d96152b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -80,7 +80,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, !mIsSpeech, true); + &mColor, boldFont, true, true); } FlashText::FlashText(const std::string &text, int x, int y, -- cgit v1.2.3-70-g09d2 From 5207b4cbb462cfa962a6f566897a6affd92eef94 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 16:48:03 +0100 Subject: Extend color config gui to support the new colors The new color palette supports many more colors that the browserbox can display. So a change to the color config gui was needed. --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 4 +- src/gui/gui.cpp | 8 +- src/gui/palette.h | 26 ++++-- src/gui/setup_colors.cpp | 185 +++++++++++++++++++++++++++++++++------- src/gui/setup_colors.h | 8 ++ src/gui/widgets/textpreview.cpp | 58 +++++++++++++ src/gui/widgets/textpreview.h | 115 +++++++++++++++++++++++++ 9 files changed, 363 insertions(+), 45 deletions(-) create mode 100644 src/gui/widgets/textpreview.cpp create mode 100644 src/gui/widgets/textpreview.h (limited to 'src') diff --git a/aethyra.cbp b/aethyra.cbp index b9e80430..e88f491d 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -256,6 +256,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6565a1b0..7025c2c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,8 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h + gui/textpreview.cpp + gui/textpreview.h gui/textrenderer.h gui/trade.cpp gui/trade.h diff --git a/src/Makefile.am b/src/Makefile.am index b3bdde9d..069b12f2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/tab.h \ gui/widgets/tabbedarea.cpp \ gui/widgets/tabbedarea.h \ + gui/widgets/textpreview.cpp \ + gui/widgets/textpreview.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/button.cpp \ @@ -155,7 +157,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ - gui/textrenderer.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2c0ddee9..434fc1e1 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -26,6 +26,7 @@ #include "focushandler.h" #include "gui.h" +#include "palette.h" #include "sdlinput.h" #include "skin.h" #include "truetypefont.h" @@ -48,11 +49,6 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; -// Fonts used in showing hits -gcn::Font *hitRedFont = 0; -gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0; - // Bolded font gcn::Font *boldFont = 0; @@ -177,6 +173,8 @@ void Gui::logic() else mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + guiPalette->advanceGradient(); + gcn::Gui::logic(); } diff --git a/src/gui/palette.h b/src/gui/palette.h index a372d6cd..02489686 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -109,7 +109,7 @@ class Palette : public gcn::ListModel const gcn::Color& getColor(char c, bool &valid); /** - * Gets the color with the associated type. Sets the alpha channel + * Gets the color associated with the type. Sets the alpha channel * before returning. * * @param type the color type requested @@ -125,12 +125,24 @@ class Palette : public gcn::ListModel } /** - * Gets the GradientType used by the specified color. - * - * @param type the color type of the color - * - * @return the gradient type of the color with the given index - */ + * Gets the committed color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested committed color + */ + inline const gcn::Color& getCommittedColor(ColorType type) + { + return mColVector[type].committedColor; + } + + /** + * Gets the GradientType associated with the specified type. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ inline GradientType getGradientType(ColorType type) { return mColVector[type].grad; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 4f017e15..5019a61a 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,6 +27,7 @@ #include #include "browserbox.h" +#include "gui.h" #include "itemlinkhandler.h" #include "listbox.h" #include "palette.h" @@ -56,8 +57,10 @@ Setup_Colors::Setup_Colors() : mScroll = new ScrollArea(mColorBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mTextPreview = new TextPreview(&rawmsg); + mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(false); + mPreview->setOpaque(true); // Replace this later with a more appropriate link handler. For now, this'll // do, as it'll do nothing when clicked on. @@ -68,6 +71,17 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); + mGradTypeLabel = new gcn::Label(_("Type: ")); + + mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider->setWidth(160); + mGradTypeSlider->setActionEventId("slider_grad"); + mGradTypeSlider->setValue(0); + mGradTypeSlider->addActionListener(this); + mGradTypeSlider->setEnabled(false); + + mGradTypeText = new gcn::Label(); + mRedLabel = new gcn::Label(_("Red: ")); mRedText = new TextField(); @@ -75,12 +89,14 @@ Setup_Colors::Setup_Colors() : mRedText->setRange(0, 255); mRedText->setNumeric(true); mRedText->addListener(this); + mRedText->setEnabled(false); mRedSlider = new Slider(0, 255); mRedSlider->setWidth(160); mRedSlider->setValue(mRedText->getValue()); mRedSlider->setActionEventId("slider_red"); mRedSlider->addActionListener(this); + mRedSlider->setEnabled(false); mGreenLabel = new gcn::Label(_("Green: ")); @@ -89,12 +105,14 @@ Setup_Colors::Setup_Colors() : mGreenText->setRange(0, 255); mGreenText->setNumeric(true); mGreenText->addListener(this); + mGreenText->setEnabled(false); mGreenSlider = new Slider(0, 255); mGreenSlider->setWidth(160); mGreenSlider->setValue(mGreenText->getValue()); mGreenSlider->setActionEventId("slider_green"); mGreenSlider->addActionListener(this); + mGreenSlider->setEnabled(false); mBlueLabel = new gcn::Label(_("Blue: ")); @@ -103,12 +121,14 @@ Setup_Colors::Setup_Colors() : mBlueText->setRange(0, 255); mBlueText->setNumeric(true); mBlueText->addListener(this); + mBlueText->setEnabled(false); mBlueSlider = new Slider(0, 255); mBlueSlider->setWidth(160); mBlueSlider->setValue(mBlueText->getValue()); mBlueSlider->setActionEventId("slider_blue"); mBlueSlider->addActionListener(this); + mBlueSlider->setEnabled(false); setOpaque(false); @@ -116,8 +136,11 @@ Setup_Colors::Setup_Colors() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 7).setPadding(2); - place(0, 7, mPreviewBox, 4).setPadding(2); + place(0, 0, mScroll, 4, 6).setPadding(2); + place(0, 6, mPreviewBox, 4).setPadding(2); + place(0, 7, mGradTypeLabel, 2); + place(2, 7, mGradTypeSlider); + place(3, 7, mGradTypeText); place(0, 8, mRedLabel, 2); place(2, 8, mRedSlider); place(3, 8, mRedText).setPadding(1); @@ -133,23 +156,10 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { - delete mPreview; - delete mPreviewBox; - - delete mRedLabel; - delete mRedSlider; - delete mRedText; - - delete mGreenLabel; - delete mGreenSlider; - delete mGreenText; - - delete mBlueLabel; - delete mBlueSlider; - delete mBlueText; - - delete mColorBox; - delete mScroll; + if (mPreviewBox->getContent() == mPreview) + delete mTextPreview; + else + delete mPreview; } void Setup_Colors::action(const gcn::ActionEvent &event) @@ -159,20 +169,103 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mSelected = mColorBox->getSelected(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + Palette::GradientType grad = guiPalette->getGradientType(type); std::string msg; + char ch = guiPalette->getColorChar(type); mPreview->clearRows(); - char ch = guiPalette->getColorChar(type); - if (ch == '<') - msg = toString("@@|") + rawmsg + "@@"; - else - msg = "##" + toString(ch) + rawmsg; - mPreview->addRow(msg); + mPreviewBox->setContent(mTextPreview); + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor( + &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextBGColor(NULL); + mTextPreview->setShadow(true); + mTextPreview->setOutline(true); + + switch (type) + { + case Palette::TEXT: + case Palette::SHADOW: + case Palette::OUTLINE: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setOutline(true); + mTextPreview->setShadow(type == Palette::SHADOW); + mTextPreview->setOutline(type == Palette::OUTLINE); + break; + case Palette::BACKGROUND: + case Palette::HIGHLIGHT: + case Palette::SHOP_WARNING: + mTextPreview->setTextBGColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; + case Palette::CHAT: + case Palette::GM: + case Palette::PLAYER: + case Palette::WHISPER: + case Palette::IS: + case Palette::PARTY: + case Palette::SERVER: + case Palette::LOGGER: + case Palette::HYPERLINK: + mPreviewBox->setContent(mPreview); + mPreview->clearRows(); + //char ch = guiPalette->getColorCharAt(mSelected); + //std::string msg; + + if (ch == '<') + { + msg = toString("@@|") + rawmsg + "@@"; + } + else + { + msg = "##" + toString(ch) + rawmsg; + } + //std::cout << msg << std::endl; + mPreview->addRow(msg); + break; + case Palette::PARTICLE: + case Palette::EXP_INFO: + case Palette::PICKUP_INFO: + case Palette::HIT_PLAYER_MONSTER: + case Palette::HIT_MONSTER_PLAYER: + case Palette::HIT_CRITICAL: + case Palette::MISS: + mTextPreview->setShadow(false); + case Palette::BEING: + case Palette::PC: + case Palette::SELF: + case Palette::GM_NAME: + case Palette::NPC: + case Palette::MONSTER: + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + break; + } + + if (grad != Palette::STATIC) + { // If nonstatic color, don't display the current, but the committed + // color at the sliders + col = &guiPalette->getCommittedColor(type); + } setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); + + mGradTypeSlider->setValue(grad); + updateGradType(); + mGradTypeSlider->setEnabled(true); + + return; + } + + if (event.getId() == "slider_grad") + { + updateGradType(); + updateColor(); return; } @@ -216,6 +309,7 @@ void Setup_Colors::cancel() guiPalette->rollback(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + mGradTypeSlider->setValue(guiPalette->getGradientType(type)); setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); @@ -243,16 +337,43 @@ void Setup_Colors::listen(const TextField *tf) } } +void Setup_Colors::updateGradType() +{ + if (mSelected == -1) + return; + + mSelected = mColorBox->getSelected(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + Palette::GradientType grad = guiPalette->getGradientType(type); + + mGradTypeText->setCaption( + (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); + + bool enable = (grad == Palette::STATIC); + mRedText->setEnabled(enable); + mRedSlider->setEnabled(enable); + mGreenText->setEnabled(enable); + mGreenSlider->setEnabled(enable); + mBlueText->setEnabled(enable); + mBlueSlider->setEnabled(enable); +} + void Setup_Colors::updateColor() { if (mSelected == -1) - { return; - } Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); - guiPalette->setColor(type, - static_cast(mRedSlider->getValue()), - static_cast(mGreenSlider->getValue()), - static_cast(mBlueSlider->getValue())); + Palette::GradientType grad = + static_cast(mGradTypeSlider->getValue()); + guiPalette->setGradient(type, grad); + + if (grad == Palette::STATIC) + { + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); + } } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 6cf59b6d..00f77d57 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -34,6 +34,8 @@ #include "../guichanfwd.h" +#include "widgets/textpreview.h" + class BrowserBox; class Setup_Colors : public SetupTab, public gcn::ActionListener, @@ -53,9 +55,14 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; + TextPreview *mTextPreview; gcn::ScrollArea *mPreviewBox; int mSelected; + gcn::Label *mGradTypeLabel; + gcn::Slider *mGradTypeSlider; + gcn::Label *mGradTypeText; + gcn::Label *mRedLabel; gcn::Slider *mRedSlider; TextField *mRedText; @@ -73,5 +80,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void setEntry(gcn::Slider *s, TextField *t, int value); void updateColor(); + void updateGradType(); }; #endif diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp new file mode 100644 index 00000000..f77657c2 --- /dev/null +++ b/src/gui/widgets/textpreview.cpp @@ -0,0 +1,58 @@ +/* + * The Mana World + * Copyright (C) 2006 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 "textpreview.h" + +#include "../gui.h" +#include "../palette.h" +#include "../textrenderer.h" +#include "../truetypefont.h" + +TextPreview::TextPreview(const std::string* text) +{ + mText = text; + mFont = gui->getFont(); + mTextColor = &guiPalette->getColor(Palette::TEXT); + mTextBGColor = NULL; + mBGColor = &guiPalette->getColor(Palette::BACKGROUND); +} + +void TextPreview::draw(gcn::Graphics* graphics) +{ + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + + const std::string ttf = "TrueTypeFont"; + + if (mTextBGColor && typeid(*mFont).name() == ttf) + { + TrueTypeFont *font = static_cast(mFont); + graphics->setColor(*mTextBGColor); + int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); + int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + } + + TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, + mTextColor, mFont, mOutline, mShadow); +} diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h new file mode 100644 index 00000000..12db9f3f --- /dev/null +++ b/src/gui/widgets/textpreview.h @@ -0,0 +1,115 @@ +/* + * The Mana World + * Copyright (C) 2006 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 TEXTPREVIEW_H +#define TEXTPREVIEW_H + +#include +#include +#include + +/** + * Preview widget for particle colors, etc. + */ +class TextPreview : public gcn::Widget +{ + public: + TextPreview(const std::string* text); + + /** + * Sets the color the text is printed in. + * + * @param color the color to set + */ + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + + /** + * Sets the color the text background is drawn in. This is only the + * rectangle directly behind the text, not to full widget. + * + * @param color the color to set + */ + inline void setTextBGColor(const gcn::Color* color) + { + mTextBGColor = color; + } + + /** + * Sets the background color of the widget. + * + * @param color the color to set + */ + inline void setBGColor(const gcn::Color* color) + { + mBGColor = color; + } + + /** + * Sets the font to render the text in. + * + * @param font the font to use. + */ + inline void setFont(gcn::Font *font) + { + mFont = font; + } + + /** + * Sets whether to use a shadow while rendering. + * + * @param shadow true, if a shadow is wanted, false else + */ + inline void setShadow(bool shadow) + { + mShadow = shadow; + } + + /** + * Sets whether to use an outline while rendering. + * + * @param outline true, if an outline is wanted, false else + */ + inline void setOutline(bool outline) + { + mOutline = outline; + } + + /** + * Widget's draw method. Does the actual job. + * + * @param graphics graphics to draw into + */ + void draw(gcn::Graphics *graphics); + + private: + gcn::Font *mFont; + const std::string* mText; + const gcn::Color* mTextColor; + const gcn::Color* mBGColor; + const gcn::Color* mTextBGColor; + bool mShadow; + bool mOutline; +}; + +#endif -- cgit v1.2.3-70-g09d2 From f0d5e3da15a308fcc962590330e7d8e39e8874b9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 22:42:42 +0100 Subject: Make use of the new available colors This patch lets all being derivatives use the palette to set their name's colors. Text Particle Effects all respect the new settings. Some widgets were updated to use the colors. --- src/being.cpp | 41 ++++++++++++++++------------------------- src/being.h | 2 +- src/gui/listbox.cpp | 2 +- src/gui/shoplistbox.cpp | 2 +- src/gui/speechbubble.cpp | 5 +++-- src/gui/speechbubble.h | 4 +++- src/gui/textbox.cpp | 5 +++-- src/gui/textbox.h | 15 +++++++++++++++ src/gui/widgets/dropdown.cpp | 16 ++++++---------- src/localplayer.cpp | 19 ++++++++++--------- src/monster.cpp | 7 +++++-- src/npc.cpp | 6 ++++-- src/particle.cpp | 17 +++++------------ src/particle.h | 14 ++++++-------- src/player.cpp | 13 +++++++++---- src/text.cpp | 10 ++++++---- src/text.h | 8 +++++--- src/textparticle.cpp | 11 +++-------- src/textparticle.h | 7 +++---- 19 files changed, 105 insertions(+), 99 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 64972912..3a772fbd 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -47,6 +47,7 @@ #include "resources/resourcemanager.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/speechbubble.h" #include "utils/dtor.h" @@ -91,7 +92,7 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble(); mSpeech = ""; - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::CHAT); mText = 0; } @@ -192,17 +193,14 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font; std::string damage = amount ? toString(amount) : type == FLEE ? "dodge" : "miss"; - - int red, green, blue; + const gcn::Color* color; font = gui->getInfoParticleFont(); // Selecting the right color if (type == CRITICAL || type == FLEE) { - red = 255; - green = 128; - blue = 0; + color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) { @@ -210,39 +208,31 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } else { - red = 255; - green = 255; - blue = 0; - } - } + color = &guiPalette->getColor(Palette::MISS); + } + } else if (getType() == MONSTER) { - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER); } else { - red = 255; - green = 50; - blue = 50; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } if (amount > 0 && type == CRITICAL) { - particleEngine->addTextSplashEffect("crit!", red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect("crit!", mPx + 16, mPy + 16, + color, font, true); } // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect(damage, mPx + 16, mPy + 16, + color, font, true); } void Being::handleAttack(Being *victim, int damage, AttackType type) @@ -503,7 +493,8 @@ void Being::drawSpeech(int offsetX, int offsetY) delete mText; mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, gcn::Color(255, 255, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::PARTICLE)); } else if (speech == NO_SPEECH) { diff --git a/src/being.h b/src/being.h index 4b30b6c5..689eda02 100644 --- a/src/being.h +++ b/src/being.h @@ -428,7 +428,7 @@ class Being : public Sprite Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - gcn::Color mNameColor; + const gcn::Color* mNameColor; std::vector mSprites; std::vector mSpriteIDs; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index e53a1652..71e92eaf 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -57,7 +57,7 @@ void ListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); // Draw the list elements - graphics->setColor(gcn::Color(0, 0, 0, 255)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 74209122..5c55069f 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -79,7 +79,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color temp; const gcn::Color* backgroundColor = - &guiPalette->getColor(Palette::BACKGROUND, alpha); + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d342328e..cb1724c8 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -46,6 +46,7 @@ SpeechBubble::SpeechBubble(): mSpeechBox = new TextBox(); mSpeechBox->setEditable(false); mSpeechBox->setOpaque(false); + mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); mSpeechArea = new ScrollArea(mSpeechBox); @@ -61,11 +62,11 @@ SpeechBubble::SpeechBubble(): setLocationRelativeTo(getParent()); } -void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) +void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) { mCaption->setCaption(name); mCaption->adjustSize(); - mCaption->setForegroundColor(color); + mCaption->setForegroundColor(*color); } void SpeechBubble::setText(std::string text, bool showName) diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index a1a597c1..d356dac1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,6 +23,7 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H +#include "palette.h" #include "popup.h" class ScrollArea; @@ -34,7 +35,8 @@ class SpeechBubble : public Popup SpeechBubble(); void setCaption(const std::string &name, - const gcn::Color &color = 0x000000); + const gcn::Color *color = + &guiPalette->getColor(Palette::TEXT)); void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 589986cd..51a8efc6 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -24,10 +24,11 @@ #include +#include "palette.h" #include "textbox.h" -TextBox::TextBox(): - gcn::TextBox() +TextBox::TextBox() : + gcn::TextBox(), mTextColor(&guiPalette->getColor(Palette::TEXT)) { setOpaque(false); setFrameSize(0); diff --git a/src/gui/textbox.h b/src/gui/textbox.h index 33ea42f9..20f4ebe2 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -40,6 +40,11 @@ class TextBox : public gcn::TextBox */ TextBox(); + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + /** * Sets the text after wrapping it to the current width of the widget. */ @@ -50,8 +55,18 @@ class TextBox : public gcn::TextBox */ int getMinWidth() { return mMinWidth; } + /** + * Draws the text. + */ + inline void draw(gcn::Graphics *graphics) + { + setForegroundColor(*mTextColor); + gcn::TextBox::draw(graphics); + } + private: int mMinWidth; + const gcn::Color* mTextColor; }; #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 076a167f..0015beed 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -140,24 +140,20 @@ void DropDown::draw(gcn::Graphics* graphics) } } -// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); + const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, + alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - gcn::Color col = getBackgroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - col = getForegroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); } graphics->setFont(getFont()); @@ -169,7 +165,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (isFocused()) { - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -181,7 +177,7 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawLine(0, h, getWidth(), h); graphics->setColor(shadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index d6acc48f..f72aa59a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -37,6 +37,7 @@ #include "text.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/storagewindow.h" #include "net/messageout.h" @@ -201,7 +202,9 @@ void LocalPlayer::logic() void LocalPlayer::setGM() { mIsGM = !mIsGM; - mNameColor = mIsGM ? 0x009000: 0x202020; + mNameColor = mIsGM ? + &guiPalette->getColor(Palette::GM) : + &guiPalette->getColor(Palette::PLAYER); setName(getName()); config.setValue(getName() + "GMassert", mIsGM); } @@ -608,10 +611,9 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, - gui->getInfoParticleFont(), - mPx + 16, mPy - 16, - 255, 255, 0, true); + particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::EXP_INFO), + gui->getInfoParticleFont(), true); } mXp = xp; } @@ -621,10 +623,9 @@ void LocalPlayer::pickedUp(std::string item) if (mMap) { // Show pickup notification - particleEngine->addTextRiseFadeOutEffect(item, - gui->getInfoParticleFont (), - mPx + 16, mPy - 16, - 40, 220, 40, true); + particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::PICKUP_INFO), + gui->getInfoParticleFont (), true); } } diff --git a/src/monster.cpp b/src/monster.cpp index 45d2fbeb..f71457df 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -28,6 +28,8 @@ #include "sound.h" #include "text.h" +#include "gui/palette.h" + #include "resources/monsterdb.h" #include "resources/monsterinfo.h" @@ -72,7 +74,7 @@ Monster::Monster(int id, Uint16 job, Map *map): } } - mNameColor = 0xff2020; + mNameColor = &guiPalette->getColor(Palette::MONSTER); } Monster::~Monster() @@ -196,7 +198,8 @@ void Monster::showName(bool show) { mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), - gcn::Graphics::CENTER, gcn::Color(255, 32, 32)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::MONSTER)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index c9250415..a6d60dbb 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -27,6 +27,7 @@ #include "text.h" #include "gui/npc_text.h" +#include "gui/palette.h" #include "net/messageout.h" #include "net/protocol.h" @@ -72,7 +73,7 @@ NPC::NPC(int id, Uint16 job, Map *map, Network *network): } mName = 0; - mNameColor = 0x21bbbb; + mNameColor = &guiPalette->getColor(Palette::NPC); } NPC::~NPC() @@ -86,7 +87,8 @@ void NPC::setName(const std::string &name) delete mName; mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::NPC)); Being::setName(displayName + " (NPC)"); } diff --git a/src/particle.cpp b/src/particle.cpp index 8bc764ba..e56435ed 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -325,12 +325,10 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -346,13 +344,8 @@ Particle *Particle::addTextSplashEffect(const std::string &text, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, - int colorR, int colorG, - int colorB, bool outline) -{ - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index f03f081d..76beb8d1 100644 --- a/src/particle.h +++ b/src/particle.h @@ -106,19 +106,17 @@ class Particle : public Sprite /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, int colorR = 255, - int colorG = 255, int colorB = 255, - bool outline = false); + int x, int y, const gcn::Color *color, gcn::Font *font, + bool outline = false); + /** * Adds an emitter to the particle. */ diff --git a/src/player.cpp b/src/player.cpp index 61e91613..b289c3e5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -22,10 +22,13 @@ #include "animatedsprite.h" #include "game.h" +#include "localplayer.h" #include "particle.h" #include "player.h" #include "text.h" +#include "gui/palette.h" + #include "resources/colordb.h" #include "resources/itemdb.h" @@ -51,17 +54,19 @@ void Player::setName(const std::string &name) { if (mIsGM) { - mNameColor = 0x009000; + mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(0, 255, 0)); + &guiPalette->getColor(Palette::GM)); } else { - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::PLAYER); mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(255, 255, 255)); + (this == player_node) ? + &guiPalette->getColor(Palette::SELF) : + &guiPalette->getColor(Palette::PC)); } Being::setName(name); } diff --git a/src/text.cpp b/src/text.cpp index 2d96152b..420eeb8b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -32,8 +32,9 @@ int Text::mInstances = 0; Text::Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : - mText(text), mColor(color) + gcn::Graphics::Alignment alignment, const gcn::Color* color) : + mText(text), + mColor(color) { if (textManager == 0) { @@ -80,11 +81,12 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, true, true); + mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : + gcn::Graphics::Alignment alignment, + const gcn::Color *color) : Text(text, x, y, alignment, color), mTime(0) { diff --git a/src/text.h b/src/text.h index 0b53dd48..cf0aac48 100644 --- a/src/text.h +++ b/src/text.h @@ -39,7 +39,8 @@ class Text * Constructor creates a text object to display on the screen. */ Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color *color); /** * Destructor. The text is removed from the screen. @@ -64,14 +65,15 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColor; /**< The color of the text. */ + const gcn::Color *mColor; /**< The color of the text. */ }; class FlashText : public Text { public: FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color* color); /** * Remove the text from the screen diff --git a/src/textparticle.cpp b/src/textparticle.cpp index a065eadd..865c6764 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,21 +22,17 @@ #include -#include - #include "textparticle.h" #include "gui/textrenderer.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), - mColorR(colorR), - mColorG(colorG), - mColorB(colorB), + mColor(color), mOutline(outline) { } @@ -65,6 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, - (int) alpha); + mColor, mTextFont, mOutline, false, (int) alpha); } diff --git a/src/textparticle.h b/src/textparticle.h index 26b92a50..1a49b5ef 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,7 +33,7 @@ class TextParticle : public Particle * Constructor. */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline = false); /** @@ -48,9 +48,8 @@ class TextParticle : public Particle private: std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ - bool mOutline; /**< Make the text readable - draw it the way - a Text is usually drawn: with outline */ + const gcn::Color* mColor; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text better readable */ }; #endif -- cgit v1.2.3-70-g09d2 From 14fbd95172a6c41abc8e985680c684c40e9e50a8 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 22:07:29 -0600 Subject: Added in option for opacity for the text preview widget, which all of the other widgets have as well. Also set the preview widget to have opacity off, like all of the other widgets (if it is on, then opacity can't be applied to it. Also looks rather tacky with it) Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 4 +--- src/gui/widgets/textpreview.cpp | 13 +++++++++---- src/gui/widgets/textpreview.h | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 5019a61a..f0f7a529 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -60,7 +60,7 @@ Setup_Colors::Setup_Colors() : mTextPreview = new TextPreview(&rawmsg); mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(true); + mPreview->setOpaque(false); // Replace this later with a more appropriate link handler. For now, this'll // do, as it'll do nothing when clicked on. @@ -212,8 +212,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HYPERLINK: mPreviewBox->setContent(mPreview); mPreview->clearRows(); - //char ch = guiPalette->getColorCharAt(mSelected); - //std::string msg; if (ch == '<') { diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index f77657c2..b13d12e4 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -2,7 +2,7 @@ * The Mana World * Copyright (C) 2006 The Mana World Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra based on code from 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 @@ -35,12 +35,16 @@ TextPreview::TextPreview(const std::string* text) mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; mBGColor = &guiPalette->getColor(Palette::BACKGROUND); + mOpaque = false; } void TextPreview::draw(gcn::Graphics* graphics) { - graphics->setColor(*mBGColor); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + if (mOpaque) + { + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + } const std::string ttf = "TrueTypeFont"; @@ -50,7 +54,8 @@ void TextPreview::draw(gcn::Graphics* graphics) graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + if (mOpaque) + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index 12db9f3f..7e7e461c 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -2,7 +2,7 @@ * The Mana World * Copyright (C) 2006 The Mana World Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra based on code from 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 @@ -102,12 +102,27 @@ class TextPreview : public gcn::Widget */ void draw(gcn::Graphics *graphics); + /** + * Set opacity for this widget (whether or not to show the background + * color) + * + * @param opaque Whether the widget should be opaque or not + */ + void setOpaque(bool opaque) { mOpaque = opaque; } + + /** + * Gets opacity for this widget (whether or not the background color + * is shown below the widget) + */ + bool isOpaque() { return mOpaque; } + private: gcn::Font *mFont; const std::string* mText; const gcn::Color* mTextColor; const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; + bool mOpaque; bool mShadow; bool mOutline; }; -- cgit v1.2.3-70-g09d2 From 9df0ea3ab0faeb3e9fce71dccb76624d7737798f Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 23:59:28 -0600 Subject: Fixed an incorrect palette reference, as well as a break that was introduced from the palette code. TODO: Cancel is effectively broken, and broken badly in the Colors setup pane. Fix this. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 5 +++++ src/player.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index cb1724c8..944bae42 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -25,10 +25,13 @@ #include #include "gui.h" +#include "palette.h" #include "scrollarea.h" #include "speechbubble.h" #include "textbox.h" +#include "../graphics.h" + #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): @@ -74,6 +77,8 @@ void SpeechBubble::setText(std::string text, bool showName) if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth())) return; + graphics->setColor(guiPalette->getColor(Palette::TEXT)); + int width = mCaption->getWidth(); mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width); diff --git a/src/player.cpp b/src/player.cpp index b289c3e5..ba4ed1ff 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -57,7 +57,7 @@ void Player::setName(const std::string &name) mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - &guiPalette->getColor(Palette::GM)); + &guiPalette->getColor(Palette::GM_NAME)); } else { -- cgit v1.2.3-70-g09d2 From 011133ef09dd4340c7649100cea170e2595b6b2f Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 13 Mar 2009 00:47:50 -0600 Subject: Made the TextPreview widget respect alpha values. Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 3 ++- src/gui/widgets/textpreview.cpp | 24 +++++++++++++++++------- src/gui/widgets/textpreview.h | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index f0f7a529..038b21c6 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -180,6 +180,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setTextColor( &guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); @@ -197,6 +198,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: mTextPreview->setTextBGColor(col); + //mTextPreview->setOpaque(true); mTextPreview->setOutline(false); mTextPreview->setShadow(false); mPreview->addRow(rawmsg); @@ -221,7 +223,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) { msg = "##" + toString(ch) + rawmsg; } - //std::cout << msg << std::endl; mPreview->addRow(msg); break; case Palette::PARTICLE: diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index b13d12e4..e34bb5cb 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -28,6 +28,10 @@ #include "../textrenderer.h" #include "../truetypefont.h" +#include "../../configuration.h" + +float TextPreview::mAlpha = config.getValue("guialpha", 0.8); + TextPreview::TextPreview(const std::string* text) { mText = text; @@ -40,22 +44,28 @@ TextPreview::TextPreview(const std::string* text) void TextPreview::draw(gcn::Graphics* graphics) { + if (config.getValue("guialpha", 0.8) != mAlpha) + mAlpha = config.getValue("guialpha", 0.8); + if (mOpaque) { - graphics->setColor(*mBGColor); + graphics->setColor(gcn::Color((int) mBGColor->r, + (int) mBGColor->g, + (int) mBGColor->b, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } - const std::string ttf = "TrueTypeFont"; - - if (mTextBGColor && typeid(*mFont).name() == ttf) + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { TrueTypeFont *font = static_cast(mFont); - graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - if (mOpaque) - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + graphics->setColor(gcn::Color((int) mTextBGColor->r, + (int) mTextBGColor->g, + (int) mTextBGColor->b, + (int)(mAlpha * 255.0f))); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index 7e7e461c..a73eb638 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -122,6 +122,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mTextColor; const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; + static float mAlpha; bool mOpaque; bool mShadow; bool mOutline; -- cgit v1.2.3-70-g09d2 From 90e29d12a044030c140382c038c4b01e722113e7 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 13 Mar 2009 01:16:21 -0600 Subject: Added item types to the palette class. Signed-off-by: Ira Rice --- src/gui/itempopup.cpp | 27 ++++++++++++++------------- src/gui/palette.cpp | 26 ++++++++++++++++++++------ src/gui/palette.h | 13 +++++++++++++ src/gui/setup_colors.cpp | 17 +++++++++++++++++ 4 files changed, 64 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index ebbc6af3..b3002290 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -27,6 +27,7 @@ #include "gui.h" #include "itempopup.h" +#include "palette.h" #include "scrollarea.h" #include "textbox.h" @@ -166,31 +167,31 @@ gcn::Color ItemPopup::getColor(const std::string& type) gcn::Color color; if (type.compare("generic") == 0) - color = 0x21a5b1; + color = guiPalette->getColor(Palette::GENERIC); else if (type.compare("equip-head") == 0) - color = 0x527fa4; + color = guiPalette->getColor(Palette::HEAD); else if (type.compare("usable") == 0) - color = 0x268d24; + color = guiPalette->getColor(Palette::USABLE); else if (type.compare("equip-torso") == 0) - color = 0xd12aa4; + color = guiPalette->getColor(Palette::TORSO); else if (type.compare("equip-1hand") == 0) - color = 0xf42a2a; + color = guiPalette->getColor(Palette::ONEHAND); else if (type.compare("equip-legs") == 0) - color = 0x699900; + color = guiPalette->getColor(Palette::LEGS); else if (type.compare("equip-feet") == 0) - color = 0xaa1d48; + color = guiPalette->getColor(Palette::FEET); else if (type.compare("equip-2hand") == 0) - color = 0xf46d0e; + color = guiPalette->getColor(Palette::TWOHAND); else if (type.compare("equip-shield") == 0) - color = 0x9c2424; + color = guiPalette->getColor(Palette::SHIELD); else if (type.compare("equip-ring") == 0) - color = 0x0000ff; + color = guiPalette->getColor(Palette::RING); else if (type.compare("equip-arms") == 0) - color = 0x9c24e8; + color = guiPalette->getColor(Palette::ARMS); else if (type.compare("equip-ammo") == 0) - color = 0x8b6311; + color = guiPalette->getColor(Palette::AMMO); else - color = 0x000000; + color = guiPalette->getColor(Palette::UNKNOWN_ITEM); return color; } diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a79f2050..80b5f1f1 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -101,12 +101,26 @@ Palette::Palette() : addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); - addColor(BEING, 0xffffff, STATIC, _("Being"), 0); - addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); - addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); - addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); - addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); - addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); + addColor(BEING, 0xffffff, STATIC, _("Being")); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names")); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name")); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names")); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs")); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters")); + + addColor(UNKNOWN_ITEM, 0x000000, STATIC, _("Unknown Item Type")); + addColor(GENERIC, 0x21a5b1, STATIC, indent + _("Generic")); + addColor(HEAD, 0x527fa4, STATIC, indent + _("Hat")); + addColor(USABLE, 0x268d24, STATIC, indent + _("Usable")); + addColor(TORSO, 0xd12aa4, STATIC, indent + _("Shirt")); + addColor(ONEHAND, 0xf42a2a, STATIC, indent + _("1 Handed Weapons")); + addColor(LEGS, 0x699900, STATIC, indent + _("Pants")); + addColor(FEET, 0xaa1d48, STATIC, indent + _("Shoes")); + addColor(TWOHAND, 0xf46d0e, STATIC, indent + _("2 Handed Weapons")); + addColor(SHIELD, 0x9c2424, STATIC, indent + _("Shield")); + addColor(RING, 0x0000ff, STATIC, indent + _("Ring")); + addColor(ARMS, 0x9c24e8, STATIC, indent + _("Arms")); + addColor(AMMO, 0x8b6311, STATIC, indent + _("Ammo")); addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), diff --git a/src/gui/palette.h b/src/gui/palette.h index 02489686..a91d3605 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -69,6 +69,19 @@ class Palette : public gcn::ListModel ENTRY(GM_NAME)\ ENTRY(NPC)\ ENTRY(MONSTER)\ + ENTRY(UNKNOWN_ITEM)\ + ENTRY(GENERIC)\ + ENTRY(HEAD)\ + ENTRY(USABLE)\ + ENTRY(TORSO)\ + ENTRY(ONEHAND)\ + ENTRY(LEGS)\ + ENTRY(FEET)\ + ENTRY(TWOHAND)\ + ENTRY(SHIELD)\ + ENTRY(RING)\ + ENTRY(ARMS)\ + ENTRY(AMMO)\ ENTRY(PARTICLE)\ ENTRY(EXP_INFO)\ ENTRY(PICKUP_INFO)\ diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 038b21c6..0dfaf7a6 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -225,6 +225,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event) } mPreview->addRow(msg); break; + case Palette::UNKNOWN_ITEM: + case Palette::GENERIC: + case Palette::HEAD: + case Palette::USABLE: + case Palette::TORSO: + case Palette::ONEHAND: + case Palette::LEGS: + case Palette::FEET: + case Palette::TWOHAND: + case Palette::SHIELD: + case Palette::RING: + case Palette::ARMS: + case Palette::AMMO: + mTextPreview->setFont(boldFont); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: @@ -241,6 +257,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::MONSTER: mTextPreview->setFont(boldFont); mTextPreview->setTextColor(col); + case Palette::TYPE_COUNT: break; } -- cgit v1.2.3-70-g09d2 From 90c43c8d53c4e50f09cf3bf6bc8518e0d27b8e57 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 14:50:10 +0100 Subject: Fix cancel button in color config dialog Also save the committed gradient, not the one currently used. --- src/gui/palette.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 80b5f1f1..162081e1 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -143,7 +143,7 @@ Palette::~Palette() colEnd = mColVector.end(); col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->grad); + config.setValue(*configName + "Gradient", col->comittedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); @@ -235,11 +235,12 @@ void Palette::rollback() i != iEnd; ++i) { - i->grad = i->committedGrad; - if (i->grad == STATIC) + if (i->grad != i->committedGrad) { - i->color = i->committedColor; + setGradient(i->type, i->committedGrad); } + setColor(i->type, i->committedColor.r, i->committedColor.g, + i->committedColor.b); } } -- cgit v1.2.3-70-g09d2 From a1b399ad3956b03ce26416abd906f22e3c3d2d82 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 14 Mar 2009 08:16:49 -0600 Subject: Fix a spelling error in palette --- src/gui/palette.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 162081e1..8cc9c57b 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -143,7 +143,7 @@ Palette::~Palette() colEnd = mColVector.end(); col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->comittedGrad); + config.setValue(*configName + "Gradient", col->committedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); -- cgit v1.2.3-70-g09d2 From 698e166377fa4e7e4e4a971af33458c68bd70809 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:33:48 -0600 Subject: Commented up item popups, speech bubbles, as well as only update item info on item change. Also fixed color updating for item shortcuts and item links, as the displayed colors wouldn't update on change on color change in the setup color dialog. Signed-off-by: Ira Rice --- src/gui/itemcontainer.cpp | 9 ++++++--- src/gui/itemlinkhandler.cpp | 9 ++++++++- src/gui/itempopup.cpp | 17 +++++++++++++++-- src/gui/itempopup.h | 29 +++++++++++++++++++++++++++++ src/gui/itemshortcutcontainer.cpp | 6 ++++-- src/gui/speechbubble.cpp | 1 - src/gui/speechbubble.h | 18 ++++++++++++++++++ 7 files changed, 80 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 54f1f647..8139e85e 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -25,6 +25,7 @@ #include "itemcontainer.h" #include "itempopup.h" +#include "palette.h" #include "viewport.h" #include "../graphics.h" @@ -51,6 +52,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset): mOffset(offset) { mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); ResourceManager *resman = ResourceManager::getInstance(); @@ -123,7 +125,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) // Draw item caption graphics->setFont(getFont()); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText( (item->isEquipped() ? "Eq." : toString(item->getQuantity())), itemX + gridWidth / 2, itemY + gridHeight - 11, @@ -255,8 +257,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp index 06263ce2..e9993c2d 100644 --- a/src/gui/itemlinkhandler.cpp +++ b/src/gui/itemlinkhandler.cpp @@ -33,6 +33,7 @@ ItemLinkHandler::ItemLinkHandler() { mItemPopup = new ItemPopup; + mItemPopup->setOpaque(false); } ItemLinkHandler::~ItemLinkHandler() @@ -50,11 +51,17 @@ void ItemLinkHandler::handleLink(const std::string &link) { const ItemInfo &iteminfo = ItemDB::get(id); - mItemPopup->setItem(iteminfo); + if (iteminfo.getName() != mItemPopup->getItemName()) + mItemPopup->setItem(iteminfo); if (mItemPopup->isVisible()) + { mItemPopup->setVisible(false); + } else + { + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + } } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index b3002290..c76c3750 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -41,8 +41,10 @@ ItemPopup::ItemPopup(): Popup() { + mItemType = ""; + // Item Name - mItemName = new gcn::Label("Label"); + mItemName = new gcn::Label(""); mItemName->setFont(boldFont); mItemName->setPosition(2, 2); @@ -104,12 +106,12 @@ void ItemPopup::setItem(const ItemInfo &item) return; mItemName->setCaption(item.getName()); - mItemName->setForegroundColor(getColor(item.getType())); mItemName->setWidth(boldFont->getWidth(item.getName())); mItemDesc->setTextWrapped(item.getDescription(), 196); mItemEffect->setTextWrapped(item.getEffect(), 196); mItemWeight->setTextWrapped(_("Weight: ") + toString(item.getWeight()) + _(" grams"), 196); + mItemType = item.getType(); int minWidth = mItemName->getWidth(); @@ -162,6 +164,12 @@ void ItemPopup::setItem(const ItemInfo &item) (2 * getFont()->getHeight())); } +void ItemPopup::updateColors() +{ + mItemName->setForegroundColor(getColor(mItemType)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); +} + gcn::Color ItemPopup::getColor(const std::string& type) { gcn::Color color; @@ -196,6 +204,11 @@ gcn::Color ItemPopup::getColor(const std::string& type) return color; } +std::string ItemPopup::getItemName() +{ + return mItemName->getCaption(); +} + unsigned int ItemPopup::getNumRows() { return mItemDesc->getNumberOfRows() + mItemEffect->getNumberOfRows() + diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index 97da4cbb..29fd127a 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -33,11 +33,39 @@ class TextBox; class ItemPopup : public Popup { public: + /** + * Constructor. Initializes the item popup. + */ ItemPopup(); + + /** + * Destructor. Cleans up the item popup on deletion. + */ ~ItemPopup(); + /** + * Sets the info to be displayed given a particular item. + */ void setItem(const ItemInfo &item); + + /** + * Gets the number of rows that the item popup currently has. + */ unsigned int getNumRows(); + + /** + * Gets the name of the currently stored item in this popup. + */ + std::string getItemName(); + + /** + * Updates the colors used within the item popup. + */ + void updateColors(); + + /** + * Sets the location to display the item popup. + */ void view(int x, int y); private: @@ -45,6 +73,7 @@ class ItemPopup : public Popup TextBox *mItemDesc; TextBox *mItemEffect; TextBox *mItemWeight; + std::string mItemType; ScrollArea *mItemDescScroll; ScrollArea *mItemEffectScroll; ScrollArea *mItemWeightScroll; diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index c1baca76..cbbbaf60 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -47,6 +47,7 @@ ItemShortcutContainer::ItemShortcutContainer(): addWidgetListener(this); mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); ResourceManager *resman = ResourceManager::getInstance(); @@ -233,8 +234,9 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 944bae42..811fddfa 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -25,7 +25,6 @@ #include #include "gui.h" -#include "palette.h" #include "scrollarea.h" #include "speechbubble.h" #include "textbox.h" diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index d356dac1..9eb400fb 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -32,13 +32,31 @@ class TextBox; class SpeechBubble : public Popup { public: + /** + * Constructor. Initializes the speech bubble. + */ SpeechBubble(); + /** + * Sets the name displayed for the speech bubble, and in what color. + */ void setCaption(const std::string &name, const gcn::Color *color = &guiPalette->getColor(Palette::TEXT)); + + /** + * Sets the text to be displayed. + */ void setText(std::string text, bool showName = true); + + /** + * Sets the location in which the speech bubble will be displayed. + */ void setLocation(int x, int y); + + /** + * Gets the number of rows the speech bubble has. + */ unsigned int getNumRows(); private: -- cgit v1.2.3-70-g09d2 From 998a63d41fcb9cc7b9ac04ed20ca02f4f83775c9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 15:47:31 +0100 Subject: Code cleanup in the color/palette code --- src/gui/palette.cpp | 20 +++++++++----------- src/gui/setup_colors.cpp | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 8cc9c57b..e007dd5c 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -82,8 +82,8 @@ Palette::Palette() : { std::string indent = " "; addColor(TEXT, 0x000000, STATIC, _("Text")); - addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); - addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); @@ -122,17 +122,15 @@ Palette::Palette() : addColor(ARMS, 0x9c24e8, STATIC, indent + _("Arms")); addColor(AMMO, 0x8b6311, STATIC, indent + _("Ammo")); - addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); - addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), - 0); - addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification")); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification")); addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, - indent + _("Player hits Monster"), 0); + indent + _("Player hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, - indent + _("Monster hits Player"), 0); - addColor(HIT_CRITICAL, 0xff0000, RAINBOW, - indent + _("Critical Hit"), 0); - addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + indent + _("Monster hits Player")); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit")); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses")); commit(true); } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 0dfaf7a6..91b20f5f 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -198,7 +198,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: mTextPreview->setTextBGColor(col); - //mTextPreview->setOpaque(true); mTextPreview->setOutline(false); mTextPreview->setShadow(false); mPreview->addRow(rawmsg); -- cgit v1.2.3-70-g09d2 From f754da1e3a3a4d2c377cb8d1b61899783dff5736 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:47:20 -0600 Subject: Got rid of two direct references to the color black. These now always pull from the stored text color. This should help in situations in which the user has their own custom skin in the future, and needs to adjust text colors to be more friendly to a darker skin. Signed-off-by: Ira Rice --- src/gui/emoteshortcutcontainer.cpp | 3 ++- src/gui/itemshortcutcontainer.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index 8c9df14e..47fb9b06 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -21,6 +21,7 @@ */ #include "emoteshortcutcontainer.h" +#include "palette.h" #include "../animatedsprite.h" #include "../configuration.h" @@ -99,7 +100,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) // Draw emote keyboard shortcut. const char *key = SDL_GetKeyName( (SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i)); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); if (emoteShortcut->getEmote(i)) diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index cbbbaf60..a0697c5d 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -23,6 +23,7 @@ #include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" +#include "palette.h" #include "viewport.h" #include "../configuration.h" @@ -91,7 +92,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. const char *key = SDL_GetKeyName( (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i)); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); if (itemShortcut->getItem(i) < 0) -- cgit v1.2.3-70-g09d2 From f0c6bed3d879e1c7b9a6d5b7e676a4f1c6a29a54 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:52:31 -0600 Subject: Fixed sliders to initialize their alpha values on loading, instead of only using alpha values after the first change. Signed-off-by: Ira Rice --- src/gui/slider.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index db34cc6a..a2df59a4 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -96,6 +96,16 @@ void Slider::init() vGrip = slider->getSubImage(x, y, w, h); slider->decRef(); + + hStart->setAlpha(mAlpha); + hMid->setAlpha(mAlpha); + hEnd->setAlpha(mAlpha); + hGrip->setAlpha(mAlpha); + + vStart->setAlpha(mAlpha); + vMid->setAlpha(mAlpha); + vEnd->setAlpha(mAlpha); + vGrip->setAlpha(mAlpha); } mInstances++; -- 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') 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 20ad38045482254b9875ee80de44a9b6f9367d2d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:28:26 -0600 Subject: Exposed the progress bar colors to the color management tab. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/progressbar.cpp | 13 ++++++++++--- src/gui/setup_colors.cpp | 27 ++++++++++++++++++--------- src/gui/textrenderer.h | 7 +++---- src/gui/widgets/textpreview.cpp | 10 +++++++++- src/gui/widgets/textpreview.h | 11 +++++++++++ src/gui/window.cpp | 6 ++++++ src/gui/window.h | 5 +++++ src/text.cpp | 2 +- src/textparticle.cpp | 2 +- 11 files changed, 66 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index c155cfe2..a3d654be 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -84,6 +84,7 @@ Palette::Palette() : addColor(TEXT, 0x000000, STATIC, _("Text")); addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); + addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); diff --git a/src/gui/palette.h b/src/gui/palette.h index 4d8f7f11..f0a3d541 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -51,6 +51,7 @@ class Palette : public gcn::ListModel ENTRY(TEXT)\ ENTRY(SHADOW)\ ENTRY(OUTLINE)\ + ENTRY(PROGRESS_BAR)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ ENTRY(TAB_HIGHLIGHT)\ diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index bec86bb1..025e0ec5 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -23,6 +23,7 @@ #include #include "gui.h" +#include "palette.h" #include "progressbar.h" #include "../configuration.h" @@ -133,18 +134,24 @@ void ProgressBar::draw(gcn::Graphics *graphics) const int textX = getWidth() / 2; const int textY = (getHeight() - f->getHeight()) / 2; + gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); + graphics->setFont(f); - graphics->setColor(gcn::Color(0, 0, 0, alpha)); + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(255, 255, 255, alpha)); + tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); + + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 09c6a3a9..b7c408d1 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -177,12 +177,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); mPreviewBox->setContent(mTextPreview); mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor( - &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); - mTextPreview->setOpaque(false); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); + mTextPreview->useTextAlpha(false); switch (type) { @@ -190,10 +190,16 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::SHADOW: case Palette::OUTLINE: mTextPreview->setFont(gui->getFont()); - mTextPreview->setOutline(true); mTextPreview->setShadow(type == Palette::SHADOW); mTextPreview->setOutline(type == Palette::OUTLINE); break; + case Palette::PROGRESS_BAR: + mTextPreview->useTextAlpha(true); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + break; case Palette::TAB_HIGHLIGHT: mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); @@ -201,8 +207,13 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(false); break; case Palette::BACKGROUND: - case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: + mTextPreview->setBGColor(col); + mTextPreview->setOpaque(true); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::HIGHLIGHT: mTextPreview->setTextBGColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); @@ -221,13 +232,10 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); if (ch == '<') - { msg = toString("@@|") + rawmsg + "@@"; - } else - { msg = "##" + toString(ch) + rawmsg; - } + mPreview->addRow(msg); break; case Palette::UNKNOWN_ITEM: @@ -246,6 +254,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setFont(boldFont); mTextPreview->setOutline(false); mTextPreview->setShadow(false); + break; case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h index 599e85a3..c0f5a0e9 100644 --- a/src/gui/textrenderer.h +++ b/src/gui/textrenderer.h @@ -37,7 +37,7 @@ class TextRenderer */ static inline void renderText(gcn::Graphics *graphics, const std::string& text, int x, int y, gcn::Graphics::Alignment align, - const gcn::Color* color, gcn::Font *font, bool outline = false, + const gcn::Color color, gcn::Font *font, bool outline = false, bool shadow = false, int alpha = 255) { graphics->setFont(font); @@ -45,8 +45,7 @@ class TextRenderer // Text shadow if (shadow) { - graphics->setColor(guiPalette->getColor(Palette::SHADOW, - alpha / 2)); + graphics->setColor(guiPalette->getColor(Palette::SHADOW, alpha / 2)); if (outline) { graphics->drawText(text, x + 2, y + 2, align); @@ -73,7 +72,7 @@ class TextRenderer graphics->drawText(text, x, y - 1, align); } - graphics->setColor(*color); + graphics->setColor(color); graphics->drawText(text, x, y, align); } }; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index e34bb5cb..5408eebe 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -35,6 +35,7 @@ float TextPreview::mAlpha = config.getValue("guialpha", 0.8); TextPreview::TextPreview(const std::string* text) { mText = text; + mTextAlpha = false; mFont = gui->getFont(); mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; @@ -47,6 +48,11 @@ void TextPreview::draw(gcn::Graphics* graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); + int alpha = (int) (mAlpha * 255.0f); + + if (!mTextAlpha) + alpha = 255; + if (mOpaque) { graphics->setColor(gcn::Color((int) mBGColor->r, @@ -69,5 +75,7 @@ void TextPreview::draw(gcn::Graphics* graphics) } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, - mTextColor, mFont, mOutline, mShadow); + gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), + mFont, mOutline, mShadow, alpha); } diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index a73eb638..8e116262 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -44,6 +44,16 @@ class TextPreview : public gcn::Widget mTextColor = color; } + /** + * Sets the text to use the set alpha value. + * + * @param alpha whether to use alpha values for the text or not + */ + inline void useTextAlpha(bool alpha) + { + mTextAlpha = alpha; + } + /** * Sets the color the text background is drawn in. This is only the * rectangle directly behind the text, not to full widget. @@ -123,6 +133,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; static float mAlpha; + bool mTextAlpha; bool mOpaque; bool mShadow; bool mOutline; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 144357ca..e6e79b45 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -675,6 +675,12 @@ void Window::setGuiAlpha() mAlphaChanged = false; } +int Window::getGuiAlpha() +{ + float alpha = config.getValue("guialpha", 0.8); + return (int) (alpha * 255.0f); +} + Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index d573d85f..e04fcfc3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,6 +300,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); + /** + * Gets the alpha value used by the window, in a GUIChan usable format. + */ + int getGuiAlpha(); + private: enum ResizeHandles { diff --git a/src/text.cpp b/src/text.cpp index 420eeb8b..4e697f15 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -81,7 +81,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - mColor, boldFont, true); + *mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 865c6764..957d67c0 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -61,5 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - mColor, mTextFont, mOutline, false, (int) alpha); + *mColor, mTextFont, mOutline, false, (int) alpha); } -- cgit v1.2.3-70-g09d2 From 1a0703fe7e90638efac2e7be1cf115c5e243fa9b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:29:15 -0600 Subject: Added the label classes that were accidently left out in commit 3575c7a606c2d24c0d444e9999892c0390fa5ae8 Signed-off-by: Ira Rice --- src/gui/label.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/label.h | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/gui/label.cpp create mode 100644 src/gui/label.h (limited to 'src') diff --git a/src/gui/label.cpp b/src/gui/label.cpp new file mode 100644 index 00000000..bab8c465 --- /dev/null +++ b/src/gui/label.cpp @@ -0,0 +1,68 @@ +/* + * Aethyra + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * Copyright (c) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from GUIChan. + * + * 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 "gui.h" +#include "label.h" +#include "palette.h" + +#include "../graphics.h" + +Label::Label() : + gcn::Label() +{ +} + +Label::Label(const std::string& caption) : + gcn::Label(caption) +{ +} + +void Label::draw(gcn::Graphics* graphics) +{ + int textX; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; + + switch (getAlignment()) + { + case gcn::Graphics::LEFT: + textX = 0; + break; + case gcn::Graphics::CENTER: + textX = getWidth() / 2; + break; + case gcn::Graphics::RIGHT: + textX = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + setForegroundColor(guiPalette->getColor(Palette::TEXT)); + + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->drawText(getCaption(), textX, textY, getAlignment()); +} diff --git a/src/gui/label.h b/src/gui/label.h new file mode 100644 index 00000000..961286e0 --- /dev/null +++ b/src/gui/label.h @@ -0,0 +1,55 @@ +/* + * Aethyra + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * Copyright (c) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from GUIChan. + * + * 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 LABEL_H +#define LABEL_H + +#include + +/** + * Label widget. Same as the Guichan label but modified to use the palette + * system. + * + * \ingroup GUI + */ +class Label : public gcn::Label +{ + public: + /** + * Constructor. + */ + Label(); + + /** + * Constructor. This version of the constructor sets the label with an + * inintialization string. + */ + Label(const std::string& caption); + + /** + * Draws the label. + */ + void draw(gcn::Graphics* graphics); +}; + +#endif -- cgit v1.2.3-70-g09d2 From 01c1c1874a4ebeef1f4c9ad7844e0eb5afd34217 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:57:14 -0600 Subject: Fixed a label in the status window to use the label widget inside the gui folder. Signed-off-by: Ira Rice --- src/gui/status.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 3fd62b83..8dd32039 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -98,7 +98,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mPointsLabel[i] = new Label("0"); mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER); } - mRemainingStatsPointsLabel = new gcn::Label; + mRemainingStatsPointsLabel = new Label; // Set button events Id mStatsButton[0] = new Button("+", "STR", this); -- cgit v1.2.3-70-g09d2 From 78c607671bc62daf0901417ffc557f50bbf63f76 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 15:06:53 -0600 Subject: Fixed item popups in the equipment window to display the proper item type colors. Signed-off-by: Ira Rice --- src/gui/equipmentwindow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 0d2097f8..1d9b4721 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -63,6 +63,7 @@ EquipmentWindow::EquipmentWindow(): mSelected(-1) { mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); // Control that shows the Player mPlayerBox = new PlayerBox; @@ -235,8 +236,9 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(x + getX(), y + getY()); } else -- cgit v1.2.3-70-g09d2 From 79fa5a629426888f51241914d90ca8599373f2d0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 15:17:38 -0600 Subject: Modified the equipment window to use the highlight color for selections. Signed-off-by: Ira Rice --- src/gui/equipmentwindow.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 1d9b4721..31fe3b8b 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -28,6 +28,7 @@ #include "button.h" #include "equipmentwindow.h" #include "itempopup.h" +#include "palette.h" #include "playerbox.h" #include "viewport.h" @@ -114,6 +115,22 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) { + if (i == mSelected) + { + const gcn::Color color = guiPalette->getColor(Palette::HIGHLIGHT); + + // Set color to the highligh color + g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); + g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + } + + // Set color black. + g->setColor(gcn::Color(0, 0, 0)); + // Draw box border. + g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + item = (i != EQUIP_AMMO_SLOT) ? mInventory->getItem(mEquipment->getEquipment(i)) : mInventory->getItem(mEquipment->getArrows()); @@ -124,28 +141,13 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawImage(image, mEquipBox[i].posX, mEquipBox[i].posY); if (i == EQUIP_AMMO_SLOT) { - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(toString(item->getQuantity()), mEquipBox[i].posX + (BOX_WIDTH / 2), mEquipBox[i].posY - getFont()->getHeight(), gcn::Graphics::CENTER); } } - - if (i == mSelected) - { - // Set color red. - g->setColor(gcn::Color(255, 0, 0)); - } - else - { - // Set color black. - g->setColor(gcn::Color(0, 0, 0)); - } - - // Draw box border. - g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT)); } } -- cgit v1.2.3-70-g09d2 From 8fb5276dcc5c527a3daf99c18826d6d9bf9802be Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 20:20:04 -0600 Subject: Added a pulse effect into the palette class, which uses the set color and pulsates back and forth between it and black. Added directly after the spectrum effect. Also modified the gradient delay to be a lot farther out, so that we don't end up with a Pokemon seizure causing disaster (the speed was the same, as well as the colors. The new speed should be a lot more considerate of people who are prone to having issues from that speed of color changing). TODO: Modify the palette class to allow for updating the color for the pulse gradient without needing to have it applied first. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 55 ++++++++++++++++++++++++++---------------------- src/gui/palette.h | 22 ++++++------------- src/gui/setup_colors.cpp | 3 ++- 3 files changed, 39 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a3d654be..412550c7 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -33,7 +33,7 @@ const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); -const gcn::Color Palette::RAINBOW_COLORS[8] = { +const gcn::Color Palette::RAINBOW_COLORS[7] = { gcn::Color(255, 0, 0), gcn::Color(255, 153, 0), gcn::Color(255, 255, 0), @@ -73,7 +73,7 @@ std::string Palette::getConfigName(const std::string& typeName) DEFENUMNAMES(ColorType, COLOR_TYPE); -const int Palette::GRADIENT_DELAY = 20; +const int Palette::GRADIENT_DELAY = 40; Palette::Palette() : mRainbowTime(tick_time), @@ -89,7 +89,7 @@ Palette::Palette() : addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); - addColor(TAB_HIGHLIGHT, 0xff0000, STATIC, indent + _("Tab Highlight")); + addColor(TAB_HIGHLIGHT, 0xff0000, PULSE, indent + _("Tab Highlight")); addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item too expensive")); @@ -222,7 +222,7 @@ void Palette::commit(bool commitNonStatic) i != iEnd; ++i) { i->committedGrad = i->grad; - if (commitNonStatic || i->grad == STATIC) + if (commitNonStatic || i->grad == STATIC || i->grad == PULSE) { i->committedColor = i->color; } @@ -245,8 +245,8 @@ void Palette::rollback() } void Palette::addColor(Palette::ColorType type, int rgb, - Palette::GradientType grad, - const std::string &text, char c) + Palette::GradientType grad, + const std::string &text, char c) { const std::string *configName = &ColorTypeNames[type]; gcn::Color trueCol = (int)config.getValue(*configName, rgb); @@ -263,7 +263,7 @@ void Palette::advanceGradient () if (get_elapsed_time(mRainbowTime) > 5) { int pos, colIndex, colVal; - // For slower systems, advance can be greater than one (adcanve > 1 + // For slower systems, advance can be greater than one (advance > 1 // skips advance-1 steps). Should make gradient look the same // independent of the framerate. int advance = get_elapsed_time(mRainbowTime) / 5; @@ -273,25 +273,32 @@ void Palette::advanceGradient () { mGradVector[i]->gradientIndex = (mGradVector[i]->gradientIndex + advance) % - (GRADIENT_DELAY * - ((mGradVector[i]->grad == SPECTRUM) ? 6 : - RAINBOW_COLOR_COUNT)); + (GRADIENT_DELAY * ((mGradVector[i]->grad == SPECTRUM) ? + (mGradVector[i]->grad == PULSE) ? 255 : 6 : + RAINBOW_COLOR_COUNT)); pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY; colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY; + if (mGradVector[i]->grad == PULSE) + { + colVal = (int) (255.0 * (sin(M_PI * (mGradVector[i]->gradientIndex) / 255) + 1) / 2); + + const gcn::Color* col = &mGradVector[i]->committedColor; + + mGradVector[i]->color.r = (colVal) % (col->r + 1); + mGradVector[i]->color.g = (colVal) % (col->g + 1); + mGradVector[i]->color.b = (colVal) % (col->b + 1); + } if (mGradVector[i]->grad == SPECTRUM) { if (colIndex % 2) { // falling curve - colVal = (int)(255.0 * - (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); } else { // ascending curve - colVal = (int)(255.0 * - (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + - 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + 1) / 2); } mGradVector[i]->color.r = @@ -304,7 +311,7 @@ void Palette::advanceGradient () (colIndex == 3 || colIndex == 4) ? 255 : (colIndex == 2 || colIndex == 5) ? colVal : 0; } - else + else if (mGradVector[i]->grad == RAINBOW) { const gcn::Color* startCol = &RAINBOW_COLORS[colIndex]; const gcn::Color* destCol = @@ -313,20 +320,18 @@ void Palette::advanceGradient () startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2; destColVal = 1 - startColVal; - mGradVector[i]->color.r =(int)( - startColVal * startCol->r + - destColVal * destCol->r); + mGradVector[i]->color.r =(int)(startColVal * startCol->r + + destColVal * destCol->r); - mGradVector[i]->color.g =(int)( - startColVal * startCol->g + - destColVal * destCol->g); + mGradVector[i]->color.g =(int)(startColVal * startCol->g + + destColVal * destCol->g); - mGradVector[i]->color.b =(int)( - startColVal * startCol->b + - destColVal * destCol->b); + mGradVector[i]->color.b =(int)(startColVal * startCol->b + + destColVal * destCol->b); } } mRainbowTime = tick_time; } } + diff --git a/src/gui/palette.h b/src/gui/palette.h index f0a3d541..0947aa58 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -98,6 +98,7 @@ class Palette : public gcn::ListModel /** Colors can be static or can alter over time. */ enum GradientType { STATIC, + PULSE, SPECTRUM, RAINBOW }; @@ -147,9 +148,7 @@ class Palette : public gcn::ListModel * @return the requested committed color */ inline const gcn::Color& getCommittedColor(ColorType type) - { - return mColVector[type].committedColor; - } + { return mColVector[type].committedColor; } /** * Gets the GradientType associated with the specified type. @@ -159,9 +158,7 @@ class Palette : public gcn::ListModel * @return the gradient type of the color with the given index */ inline GradientType getGradientType(ColorType type) - { - return mColVector[type].grad; - } + { return mColVector[type].grad; } /** * Get the character used by the specified color. @@ -170,10 +167,7 @@ class Palette : public gcn::ListModel * * @return the color char of the color with the given index */ - inline char getColorChar(ColorType type) - { - return mColVector[type].ch; - } + inline char getColorChar(ColorType type) { return mColVector[type].ch; } /** * Sets the color for the specified type. @@ -221,10 +215,7 @@ class Palette : public gcn::ListModel /** * Commit the colors */ - inline void commit() - { - commit(false); - } + inline void commit() { commit(false); } /** * Rollback the colors @@ -286,7 +277,8 @@ class Palette : public gcn::ListModel ColorElem::gradientIndex = rand(); } - inline int getRGB() { + inline int getRGB() + { return (committedColor.r << 16) | (committedColor.g << 8) | committedColor.b; } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index b7c408d1..79c4fcb5 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -73,7 +73,7 @@ Setup_Colors::Setup_Colors() : mGradTypeLabel = new Label(_("Type: ")); - mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider = new Slider(0, 3); mGradTypeSlider->setWidth(160); mGradTypeSlider->setActionEventId("slider_grad"); mGradTypeSlider->setValue(0); @@ -378,6 +378,7 @@ void Setup_Colors::updateGradType() mGradTypeText->setCaption( (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::PULSE) ? _("Pulse") : (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); bool enable = (grad == Palette::STATIC); -- cgit v1.2.3-70-g09d2 From 6d6fd0cec10601a51cab67e623a579a14af775fc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 20:54:35 -0600 Subject: Made the slider editable when pulse gradient is selected. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 34 +++++++++++++++++++++++----------- src/gui/palette.h | 20 ++++++++++++++++++++ src/gui/setup_colors.cpp | 15 +++++++++++++-- 3 files changed, 56 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 412550c7..5b98f403 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -52,12 +52,11 @@ std::string Palette::getConfigName(const std::string& typeName) int pos = 5; for (unsigned int i = 0; i < typeName.length(); i++) { - if (i==0 || typeName[i] == '_') + if (i == 0 || typeName[i] == '_') { if (i > 0) - { i++; - } + res[pos] = typeName[i]; } else @@ -144,7 +143,7 @@ Palette::~Palette() { configName = &ColorTypeNames[col->type]; config.setValue(*configName + "Gradient", col->committedGrad); - if (col->grad == STATIC) + if (col->grad == STATIC || col->grad == PULSE) { config.setValue(*configName, toString(col->getRGB())); } @@ -154,7 +153,7 @@ Palette::~Palette() const gcn::Color& Palette::getColor(char c, bool &valid) { for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); col != colEnd; ++col) + colEnd = mColVector.end(); col != colEnd; ++col) { if (col->ch == c) { @@ -222,10 +221,14 @@ void Palette::commit(bool commitNonStatic) i != iEnd; ++i) { i->committedGrad = i->grad; - if (commitNonStatic || i->grad == STATIC || i->grad == PULSE) + if (commitNonStatic || i->grad == STATIC) { i->committedColor = i->color; } + else if (i->grad == PULSE) + { + i->committedColor = i->testColor; + } } } @@ -240,7 +243,13 @@ void Palette::rollback() setGradient(i->type, i->committedGrad); } setColor(i->type, i->committedColor.r, i->committedColor.g, - i->committedColor.b); + i->committedColor.b); + if (i->grad == PULSE) + { + i->testColor.r = i->committedColor.r; + i->testColor.g = i->committedColor.g; + i->testColor.b = i->committedColor.b; + } } } @@ -282,9 +291,10 @@ void Palette::advanceGradient () if (mGradVector[i]->grad == PULSE) { - colVal = (int) (255.0 * (sin(M_PI * (mGradVector[i]->gradientIndex) / 255) + 1) / 2); + colVal = (int) (255.0 * (sin(M_PI * + (mGradVector[i]->gradientIndex) / 255) + 1) / 2); - const gcn::Color* col = &mGradVector[i]->committedColor; + const gcn::Color* col = &mGradVector[i]->testColor; mGradVector[i]->color.r = (colVal) % (col->r + 1); mGradVector[i]->color.g = (colVal) % (col->g + 1); @@ -294,11 +304,13 @@ void Palette::advanceGradient () { if (colIndex % 2) { // falling curve - colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + + 1) / 2); } else { // ascending curve - colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / + GRADIENT_DELAY) + 1) / 2); } mGradVector[i]->color.r = diff --git a/src/gui/palette.h b/src/gui/palette.h index 0947aa58..ccef231e 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -150,6 +150,25 @@ class Palette : public gcn::ListModel inline const gcn::Color& getCommittedColor(ColorType type) { return mColVector[type].committedColor; } + /** + * Gets the test color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested test color + */ + inline const gcn::Color& getTestColor(ColorType type) + { return mColVector[type].testColor; } + + /** + * Sets the test color associated with the specified type. + * + * @param type the color type requested + * @param color the color that should be tested + */ + inline void setTestColor(ColorType type, gcn::Color color) + { mColVector[type].testColor = color; } + /** * Gets the GradientType associated with the specified type. * @@ -259,6 +278,7 @@ class Palette : public gcn::ListModel { ColorType type; gcn::Color color; + gcn::Color testColor; gcn::Color committedColor; std::string text; char ch; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 79c4fcb5..760fdc1f 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -275,11 +275,15 @@ void Setup_Colors::action(const gcn::ActionEvent &event) break; } - if (grad != Palette::STATIC) + if (grad != Palette::STATIC && grad != Palette::PULSE) { // If nonstatic color, don't display the current, but the committed // color at the sliders col = &guiPalette->getCommittedColor(type); } + else if (grad == Palette::PULSE) + { + col = &guiPalette->getTestColor(type); + } setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); @@ -381,7 +385,7 @@ void Setup_Colors::updateGradType() (grad == Palette::PULSE) ? _("Pulse") : (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); - bool enable = (grad == Palette::STATIC); + bool enable = (grad == Palette::STATIC || grad == Palette::PULSE); mRedText->setEnabled(enable); mRedSlider->setEnabled(enable); mGreenText->setEnabled(enable); @@ -407,4 +411,11 @@ void Setup_Colors::updateColor() static_cast(mGreenSlider->getValue()), static_cast(mBlueSlider->getValue())); } + else if (grad == Palette::PULSE) + { + guiPalette->setTestColor(type, gcn::Color( + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue()))); + } } -- cgit v1.2.3-70-g09d2 From 73fa81961d141b7592862a50993cd998fbd4de31 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 21:50:58 -0600 Subject: Exposed a few more windows to the reset window button under the setup dialog. Signed-off-by: Ira Rice --- src/gui/npcstringdialog.cpp | 1 - src/gui/setup.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 58a5c0c8..f50136ba 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,7 +47,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - //reflowLayout(175, 0); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index f1e7a6d9..5fe35a6c 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -45,6 +45,9 @@ extern Window *itemShortcutWindow; extern Window *emoteShortcutWindow; extern Window *emoteWindow; extern Window *tradeWindow; +extern Window *npcTextDialog; +extern Window *npcStringDialog; +extern Window *storageWindow; Setup::Setup(): Window(_("Setup")) @@ -139,6 +142,9 @@ void Setup::action(const gcn::ActionEvent &event) emoteShortcutWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); tradeWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From a9a1ed080289185cc5e71a127d7fdf35c920de8a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:03:30 -0600 Subject: Exposed a few more windows to the reset button on the setup window. These windows required an external declaration to reset. Signed-off-by: Ira Rice --- src/gui/buy.h | 2 ++ src/gui/chat.h | 12 ++++++------ src/gui/debugwindow.h | 2 ++ src/gui/sell.h | 2 ++ src/gui/setup.cpp | 36 +++++++++++++++++++++--------------- 5 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/gui/buy.h b/src/gui/buy.h index 9029fe9d..17ab6e19 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -117,4 +117,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif diff --git a/src/gui/chat.h b/src/gui/chat.h index 45d0c92f..28408b93 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -236,12 +236,12 @@ class ChatWindow : public Window, public gcn::ActionListener, typedef std::list History; typedef History::iterator HistoryIterator; History mHistory; /**< Command history */ - HistoryIterator mCurHist; /**< History iterator */ - Recorder *mRecorder; /**< Recording class */ - char mPartyPrefix; /**< Messages beginning with the prefix are sent to - the party */ - bool mReturnToggles; /**< Marks whether toggles the chat log - or not */ + HistoryIterator mCurHist; /**< History iterator */ + Recorder *mRecorder; /**< Recording class */ + char mPartyPrefix; /**< Messages beginning with the prefix are + sent to the party */ + bool mReturnToggles; /**< Marks whether toggles the chat + log or not */ Party *mParty; }; extern ChatWindow *chatWindow; diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 95e8b5e4..c82521f9 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -51,4 +51,6 @@ class DebugWindow : public Window gcn::Label *mParticleCountLabel; }; +extern DebugWindow *debugWindow; + #endif diff --git a/src/gui/sell.h b/src/gui/sell.h index 3776477f..5fb94c4e 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -108,4 +108,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener int mAmountItems; }; +extern SellDialog *sellDialog; + #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 5fe35a6c..ab0b2245 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -35,18 +35,21 @@ #include "../utils/gettext.h" extern Window *chatWindow; -extern Window *equipmentWindow; -extern Window *helpWindow; -extern Window *inventoryWindow; -extern Window *minimap; -extern Window *skillDialog; extern Window *statusWindow; -extern Window *itemShortcutWindow; -extern Window *emoteShortcutWindow; +extern Window *buyDialog; +extern Window *sellDialog; +extern Window *inventoryWindow; extern Window *emoteWindow; -extern Window *tradeWindow; extern Window *npcTextDialog; extern Window *npcStringDialog; +extern Window *skillDialog; +extern Window *minimap; +extern Window *equipmentWindow; +extern Window *tradeWindow; +extern Window *helpWindow; +extern Window *debugWindow; +extern Window *itemShortcutWindow; +extern Window *emoteShortcutWindow; extern Window *storageWindow; Setup::Setup(): @@ -131,19 +134,22 @@ void Setup::action(const gcn::ActionEvent &event) if (!statusWindow) return; - statusWindow->resetToDefaultSize(); - minimap->resetToDefaultSize(); chatWindow->resetToDefaultSize(); + statusWindow->resetToDefaultSize(); + buyDialog->resetToDefaultSize(); + sellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); + emoteWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + skillDialog->resetToDefaultSize(); + minimap->resetToDefaultSize(); equipmentWindow->resetToDefaultSize(); + tradeWindow->resetToDefaultSize(); helpWindow->resetToDefaultSize(); - skillDialog->resetToDefaultSize(); + debugWindow->resetToDefaultSize(); itemShortcutWindow->resetToDefaultSize(); emoteShortcutWindow->resetToDefaultSize(); - emoteWindow->resetToDefaultSize(); - tradeWindow->resetToDefaultSize(); - npcTextDialog->resetToDefaultSize(); - npcStringDialog->resetToDefaultSize(); storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From ebd128d47a3bcdf0b0bc03f179c4365c7c23a084 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:20:12 -0600 Subject: Removed a redundant widget resize function in the shortcut window. Signed-off-by: Ira Rice --- src/gui/shortcutwindow.cpp | 18 +++++++----------- src/gui/shortcutwindow.h | 5 ----- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index c2df1f9c..8342465a 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -24,6 +24,8 @@ #include "shortcutcontainer.h" #include "shortcutwindow.h" +#include "widgets/layout.h" + #include "../configuration.h" static const int SCROLL_PADDING = 0; @@ -57,7 +59,11 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setOpaque(false); - add(mScrollArea); + place(0, 0, mScrollArea, 5, 5).setPadding(0); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + layout.setMargin(0); loadWindowState(); } @@ -67,13 +73,3 @@ ShortcutWindow::~ShortcutWindow() delete mItems; } -void ShortcutWindow::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - const gcn::Rectangle &area = getChildrenArea(); - - mScrollArea->setSize( - area.width - SCROLL_PADDING, - area.height - SCROLL_PADDING); -} diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h index 42077d9c..d79fffd2 100644 --- a/src/gui/shortcutwindow.h +++ b/src/gui/shortcutwindow.h @@ -46,11 +46,6 @@ class ShortcutWindow : public Window */ ~ShortcutWindow(); - /** - * Called whenever the widget changes size. - */ - void widgetResized(const gcn::Event &event); - private: ShortcutWindow(); ShortcutContainer *mItems; -- cgit v1.2.3-70-g09d2 From 4a5c8c418703a65c8f6576a6dcdbb2529c26764d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:27:45 -0600 Subject: Fixed default size for the debug window. Signed-off-by: Ira Rice --- src/gui/debugwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 999e00a2..9b8ea6bd 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -40,7 +40,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(400, 60, ImageRect::CENTER); + setDefaultSize(400, 100, ImageRect::CENTER); mFPSLabel = new Label("0 FPS"); mMusicFileLabel = new Label("Music: "); -- cgit v1.2.3-70-g09d2 From 4b459b50521f5d7a0518e229a20f14ed2f1d22f9 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 23:34:18 -0600 Subject: Improved pulsating algorithm to look better for impure colors. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 5b98f403..d3e06902 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -296,9 +296,9 @@ void Palette::advanceGradient () const gcn::Color* col = &mGradVector[i]->testColor; - mGradVector[i]->color.r = (colVal) % (col->r + 1); - mGradVector[i]->color.g = (colVal) % (col->g + 1); - mGradVector[i]->color.b = (colVal) % (col->b + 1); + mGradVector[i]->color.r = ((colVal * col->r) / 255) % (col->r + 1); + mGradVector[i]->color.g = ((colVal * col->g) / 255) % (col->g + 1); + mGradVector[i]->color.b = ((colVal * col->b) / 255) % (col->b + 1); } if (mGradVector[i]->grad == SPECTRUM) { -- cgit v1.2.3-70-g09d2 From d6f89802e5aa32f266e881e43d6005e821040c57 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 3 ++- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 2 ++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 31 +++++++++++++++++++------------ src/player_relations.h | 6 +++--- 12 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 47f4ffd2..a346616f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -337,6 +336,8 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index ab0b2245..dc232296 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -108,6 +108,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 760fdc1f..148fd679 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -62,9 +62,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 64214ff5..9fbae7a6 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -161,7 +161,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 144e7e21..fa801865 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e6e79b45..404f5746 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -124,6 +124,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; mSkin->instances--; diff --git a/src/main.cpp b/src/main.cpp index 60a4d500..7ee2f6b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1021,7 +1021,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..eec4153c 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -351,19 +357,20 @@ static std::vector player_ignore_strategies; std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) + { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, - "floating '...' bubble", - PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, - "floating bubble", - "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + "floating '...' bubble", + PLAYER_IGNORE_STRATEGY_EMOTE0)); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + "floating bubble", + "emote1")); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..f4860e08 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -96,6 +96,8 @@ class PlayerRelationsManager public: PlayerRelationsManager(); + ~PlayerRelationsManager(); + /** * Initialise player relations manager (load config file etc.) */ @@ -143,7 +145,6 @@ public: */ void removePlayer(const std::string &name); - /** * Retrieves the default permissions. */ @@ -154,8 +155,6 @@ public: */ void setDefault(unsigned int permissions); - - /** * Retrieves all known player ignore strategies. * @@ -233,6 +232,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 3123c8ce5f882f0bfb99a2d2efa45d760237ebcc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:35:02 -0600 Subject: Fixed color previews for item types. Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 148fd679..108067f5 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -251,6 +251,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::ARMS: case Palette::AMMO: mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); break; -- cgit v1.2.3-70-g09d2 From a9b1eccdd2c719f86475c6ce01d4b8eea7dede6c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:56:40 -0600 Subject: Overrode the reset window function in the chat window to also reset the position of the recorder, as well as fixed resetting the help window, and exposing the buy/sell window to being resettable, as well as remembering its previous position. All windows should now be covered by the reset button on the setup pane. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 5 +++-- src/gui/buysell.h | 2 ++ src/gui/chat.cpp | 6 ++++++ src/gui/chat.h | 6 ++++++ src/gui/help.cpp | 13 +++++++------ src/gui/setup.cpp | 2 ++ src/gui/window.h | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 2022b040..4ac06220 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,10 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + setDefaultSize(x + getPadding(), (2 * y + buyButton->getHeight() + + getTitleBarHeight()), ImageRect::CENTER); - setLocationRelativeTo(ImageRect::CENTER); + loadWindowState(); requestFocus(); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 747066a7..0842c0e1 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -54,4 +54,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..5ff9ed46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -113,6 +113,12 @@ ChatWindow::~ChatWindow() delete mParty; } +void ChatWindow::resetToDefaultSize() +{ + mRecorder->resetToDefaultSize(); + Window::resetToDefaultSize(); +} + void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) { // Trim whitespace diff --git a/src/gui/chat.h b/src/gui/chat.h index 28408b93..8b710dc8 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -119,6 +119,12 @@ class ChatWindow : public Window, public gcn::ActionListener, */ ~ChatWindow(); + /** + * Reset the chat window and recorder window attached to it to their + * default positions. + */ + void resetToDefaultSize(); + /** * Adds a line of text to our message list. Parameters: * diff --git a/src/gui/help.cpp b/src/gui/help.cpp index fec39199..0974abf7 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -40,16 +40,17 @@ HelpWindow::HelpWindow(): setWindowName(_("Help")); setResizable(true); + setDefaultSize(500, 400, ImageRect::CENTER); + mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); mScrollArea = new ScrollArea(mBrowserBox); Button *okButton = new Button(_("Close"), "close", this); - mScrollArea->setDimension(gcn::Rectangle( - 5, 5, 445, 335 - okButton->getHeight())); - okButton->setPosition( - 450 - okButton->getWidth(), - 345 - okButton->getHeight()); + mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, + 335 - okButton->getHeight())); + okButton->setPosition(450 - okButton->getWidth(), + 345 - okButton->getHeight()); mBrowserBox->setLinkHandler(this); @@ -59,7 +60,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + loadWindowState(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index dc232296..ca6b4010 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -38,6 +38,7 @@ extern Window *chatWindow; extern Window *statusWindow; extern Window *buyDialog; extern Window *sellDialog; +extern Window *buySellDialog; extern Window *inventoryWindow; extern Window *emoteWindow; extern Window *npcTextDialog; @@ -140,6 +141,7 @@ void Setup::action(const gcn::ActionEvent &event) statusWindow->resetToDefaultSize(); buyDialog->resetToDefaultSize(); sellDialog->resetToDefaultSize(); + buySellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); npcTextDialog->resetToDefaultSize(); diff --git a/src/gui/window.h b/src/gui/window.h index e04fcfc3..518e1ec2 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -266,7 +266,7 @@ class Window : public gcn::Window, gcn::WidgetListener * Reset the win pos and size to default. Don't forget to set defaults * first. */ - void resetToDefaultSize(); + virtual void resetToDefaultSize(); /** * Gets the layout handler for this window. -- cgit v1.2.3-70-g09d2 From 94495012ea5919cddaf47e7a7818fd8ba4e76708 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 14:08:14 -0600 Subject: Fixed BuySell dialog to remember its position. For proper configuration saving, this needed a window name set. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 4ac06220..64ffdc3f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -33,6 +33,7 @@ BuySellDialog::BuySellDialog(Network *network): Window(_("Shop")), mNetwork(network) { + setWindowName("BuySell"); Button *buyButton = 0; static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 -- cgit v1.2.3-70-g09d2 From 13b064998c0f7142a134817c9dde08ad29db97fe Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Mon, 16 Mar 2009 19:04:38 +0000 Subject: Code reformatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-picking changes from Bjørn's 1b3cb122be1a418ce82b66fb9ce1ecf3aa5813fb Mainly making sure 'const std::string &' is used everywhere instead of 'std::string const &'. The former has always been the preferred order in this project. --- src/resources/dye.cpp | 6 +++--- src/resources/dye.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index a5998017..92176852 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -26,7 +26,7 @@ #include "../log.h" -Palette::Palette(std::string const &description) +Palette::Palette(const std::string &description) { int size = description.length(); if (size == 0) return; @@ -109,7 +109,7 @@ void Palette::getColor(int intensity, int color[3]) const color[2] = ((255 - t) * b1 + t * b2) / 255; } -Dye::Dye(std::string const &description) +Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) mPalettes[i] = 0; @@ -175,7 +175,7 @@ void Dye::update(int color[3]) const mPalettes[i - 1]->getColor(cmax, color); } -void Dye::instantiate(std::string &target, std::string const &palettes) +void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type next_pos = target.find('|'); if (next_pos == std::string::npos || palettes.empty()) return; diff --git a/src/resources/dye.h b/src/resources/dye.h index 48254b6f..ef867058 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -38,7 +38,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(std::string const &pallete); + Palette(const std::string &pallete); /** * Gets a pixel color depending on its intensity. @@ -65,7 +65,7 @@ class Dye * The parts of string are separated by semi-colons. Each part starts * by an uppercase letter, followed by a colon and then a palette name. */ - Dye(std::string const &dye); + Dye(const std::string &dye); /** * Destroys the associated palettes. @@ -81,7 +81,7 @@ class Dye * Fills the blank in a dye placeholder with some palette names. */ static void instantiate(std::string &target, - std::string const &palettes); + const std::string &palettes); private: -- cgit v1.2.3-70-g09d2 From e90b7ba7d85edf9e5e020f3781f45ac318e7ea22 Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Mon, 16 Mar 2009 18:35:22 +0000 Subject: Rename the old Palette class to DyePalette Having two classes called Palette makes the program crash, when compiled without optimisation. --- src/resources/dye.cpp | 14 +++++++------- src/resources/dye.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 92176852..38249ddb 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -26,7 +26,7 @@ #include "../log.h" -Palette::Palette(const std::string &description) +DyePalette::DyePalette(const std::string &description) { int size = description.length(); if (size == 0) return; @@ -63,7 +63,7 @@ Palette::Palette(const std::string &description) logger->log("Error, invalid embedded palette: %s", description.c_str()); } -void Palette::getColor(int intensity, int color[3]) const +void DyePalette::getColor(int intensity, int color[3]) const { if (intensity == 0) { @@ -112,7 +112,7 @@ void Palette::getColor(int intensity, int color[3]) const Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) - mPalettes[i] = 0; + mDyePalettes[i] = 0; if (description.empty()) return; @@ -142,7 +142,7 @@ Dye::Dye(const std::string &description) logger->log("Error, invalid dye: %s", description.c_str()); return; } - mPalettes[i] = new Palette(description.substr(pos + 2, next_pos - pos - 2)); + mDyePalettes[i] = new DyePalette(description.substr(pos + 2, next_pos - pos - 2)); ++next_pos; } while (next_pos < length); @@ -151,7 +151,7 @@ Dye::Dye(const std::string &description) Dye::~Dye() { for (int i = 0; i < 7; ++i) - delete mPalettes[i]; + delete mDyePalettes[i]; } void Dye::update(int color[3]) const @@ -171,8 +171,8 @@ void Dye::update(int color[3]) const int i = (color[0] != 0) | ((color[1] != 0) << 1) | ((color[2] != 0) << 2); - if (mPalettes[i - 1]) - mPalettes[i - 1]->getColor(cmax, color); + if (mDyePalettes[i - 1]) + mDyePalettes[i - 1]->getColor(cmax, color); } void Dye::instantiate(std::string &target, const std::string &palettes) diff --git a/src/resources/dye.h b/src/resources/dye.h index ef867058..f39ba043 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -29,7 +29,7 @@ /** * Class for performing a linear interpolation between colors. */ -class Palette +class DyePalette { public: @@ -38,7 +38,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(const std::string &pallete); + DyePalette(const std::string &pallete); /** * Gets a pixel color depending on its intensity. @@ -90,7 +90,7 @@ class Dye * * Red, Green, Yellow, Blue, Magenta, White (or rather gray). */ - Palette *mPalettes[7]; + DyePalette *mDyePalettes[7]; }; #endif -- cgit v1.2.3-70-g09d2 From d654758ef63f6515d678ceaf77d63a2693e08fb7 Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Mon, 16 Mar 2009 20:46:21 +0000 Subject: Optimising OpenGLGraphics::drawImagePattern --- src/openglgraphics.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/openglgraphics.h | 4 ++++ 2 files changed, 57 insertions(+) (limited to 'src') diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 9bd3ab2f..d436e7a5 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -162,6 +162,59 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, return true; } +/* Optimising the functions that Graphics::drawImagePattern would call, + * so that glBegin...glEnd are outside the main loop. */ +void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) +{ + if (Image::mTextureType == GL_TEXTURE_2D) + { + /* I'm not seeing this get called at all, so no point in optimising it. */ + Graphics::drawImagePattern(image, x, y, w, h); + return; + } + + const int srcX = image->mBounds.x; + const int srcY = image->mBounds.y; + + int iw = image->getWidth(); + int ih = image->getHeight(); + if (iw == 0 || ih == 0) + return; + + glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); + + glBindTexture(Image::mTextureType, image->mGLImage); + setTexturingAndBlending(true); + + // Draw a set of textured rectangles + glBegin(GL_QUADS); + + for (int py = 0; py < h; py += ih) + { + int height = (py + ih >= h) ? h - py : ih; + int dstY = y+py; + for (int px = 0; px < w; px += iw) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x+px; + + glTexCoord2i(srcX, srcY); + glVertex2i(dstX, dstY); + glTexCoord2i(srcX + width, srcY); + glVertex2i(dstX + width, dstY); + glTexCoord2i(srcX + width, srcY + height); + glVertex2i(dstX + width, dstY + height); + glTexCoord2i(srcX, srcY + height); + glVertex2i(dstX, dstY + height); + } + } + + glEnd(); + + glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); +} + + void OpenGLGraphics::updateScreen() { glFlush(); diff --git a/src/openglgraphics.h b/src/openglgraphics.h index 207d6725..a7181420 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -47,6 +47,10 @@ class OpenGLGraphics : public Graphics int width, int height, bool useColor); + void drawImagePattern(Image *image, + int x, int y, + int w, int h); + void updateScreen(); void _beginDraw(); -- cgit v1.2.3-70-g09d2 From a1eb62126bae54557e03682cac70c8331e359e01 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 16 Mar 2009 22:45:49 -0600 Subject: Applied a similar optimization as in commit d654758ef63f6515d678ceaf77d63a2693e08fb7, but for SDL instead. This currently doesn't buy too much, but it's a little better than it used to be. TODO: Find out why SDL is bottlenecked, and try to bring its performance up to OpenGL levels, if possible. Signed-off-by: Ira Rice --- src/graphics.cpp | 34 ++++++++++++++++++++------------ src/openglgraphics.cpp | 53 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/graphics.cpp b/src/graphics.cpp index 48fd1340..ca86f536 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -154,24 +154,34 @@ void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) { - int iw = image->getWidth(); - int ih = image->getHeight(); - if (iw == 0 || ih == 0) return; + // Check that preconditions for blitting are met. + if (!mScreen || !image || !image->mImage) return; - int px = 0; // X position on pattern plane - int py = 0; // Y position on pattern plane + const int iw = image->getWidth(); + const int ih = image->getHeight(); + + if (iw == 0 || ih == 0) return; - while (py < h) + for (int py = 0; py < h; py += ih) // Y position on pattern plane { - while (px < w) + int dh = (py + ih >= h) ? h - py : ih; + int srcY = image->mBounds.y; + int dstY = y + py + mClipStack.top().yOffset; + + for (int px = 0; px < w; px += iw) // X position on pattern plane { 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); - px += iw; + int srcX = image->mBounds.x; + int dstX = x + px + mClipStack.top().xOffset; + + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = srcX; srcRect.y = srcY; + srcRect.w = dw; srcRect.h = dh; + + SDL_BlitSurface(image->mImage, &srcRect, mScreen, &dstRect); } - py += ih; - px = 0; } } diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index d436e7a5..78b502ea 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -110,6 +110,8 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height, bool useColor) { + if (!image) return false; + srcX += image->mBounds.x; srcY += image->mBounds.y; @@ -166,16 +168,14 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, * so that glBegin...glEnd are outside the main loop. */ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) { - if (Image::mTextureType == GL_TEXTURE_2D) - { - /* I'm not seeing this get called at all, so no point in optimising it. */ - Graphics::drawImagePattern(image, x, y, w, h); - return; - } + if (!image) return; const int srcX = image->mBounds.x; const int srcY = image->mBounds.y; + const float texX1 = srcX / (float)image->mTexWidth; + const float texY1 = srcY / (float)image->mTexHeight; + int iw = image->getWidth(); int ih = image->getHeight(); if (iw == 0 || ih == 0) @@ -184,6 +184,7 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); glBindTexture(Image::mTextureType, image->mGLImage); + setTexturingAndBlending(true); // Draw a set of textured rectangles @@ -192,20 +193,38 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) for (int py = 0; py < h; py += ih) { int height = (py + ih >= h) ? h - py : ih; - int dstY = y+py; + int dstY = y + py; for (int px = 0; px < w; px += iw) { int width = (px + iw >= w) ? w - px : iw; - int dstX = x+px; - - glTexCoord2i(srcX, srcY); - glVertex2i(dstX, dstY); - glTexCoord2i(srcX + width, srcY); - glVertex2i(dstX + width, dstY); - glTexCoord2i(srcX + width, srcY + height); - glVertex2i(dstX + width, dstY + height); - glTexCoord2i(srcX, srcY + height); - glVertex2i(dstX, dstY + height); + int dstX = x + px; + + if (Image::mTextureType == GL_TEXTURE_2D) + { + // Find OpenGL normalized texture coordinates. + float texX2 = (srcX + width) / (float) image->mTexWidth; + float texY2 = (srcY + height) / (float) image->mTexHeight; + + glTexCoord2f(texX1, texY1); + glVertex2i(dstX, dstY); + glTexCoord2f(texX2, texY1); + glVertex2i(dstX + width, dstY); + glTexCoord2f(texX2, texY2); + glVertex2i(dstX + width, dstY + height); + glTexCoord2f(texX1, texY2); + glVertex2i(dstX, dstY + height); + } + else + { + glTexCoord2i(srcX, srcY); + glVertex2i(dstX, dstY); + glTexCoord2i(srcX + width, srcY); + glVertex2i(dstX + width, dstY); + glTexCoord2i(srcX + width, srcY + height); + glVertex2i(dstX + width, dstY + height); + glTexCoord2i(srcX, srcY + height); + glVertex2i(dstX, dstY + height); + } } } -- cgit v1.2.3-70-g09d2 From 72daf0bf49c0ff994aeff357f6e52140887bce30 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 17 Mar 2009 20:18:41 -0600 Subject: Added an image merge feature loosely based on a merge function found in the open source project Wormux. To improve SDL performance, the number of layers that are pushed out to the hardware or software buffers should be reduced, which is where this function comes into play, as it combines two surfaces together so that the number of blit operations is reduced. This function is currently not used, but will be used once a good way to link each of the target systems is determined so that it only initiates when SDL is enabled, as well as making sure that each hook that uses this function is benefiting from it sufficiently. At the moment, it's suspected that the particle engine will likely be the most likely to benefit from this function, followed by tile drawing, then sprite drawing. Signed-off-by: Ira Rice --- src/map.cpp | 12 ++++---- src/openglgraphics.cpp | 1 - src/particle.cpp | 44 ++++++++++++++------------- src/resources/image.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++-- src/resources/image.h | 10 +++++++ 5 files changed, 117 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/map.cpp b/src/map.cpp index bda618e2..877a8ba9 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -120,10 +120,8 @@ Image* MapLayer::getTile(int x, int y) const return mTiles[x + y * mWidth]; } -void MapLayer::draw(Graphics *graphics, - int startX, int startY, - int endX, int endY, - int scrollX, int scrollY, +void MapLayer::draw(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, const Sprites &sprites) const { startX -= mX; @@ -164,8 +162,10 @@ void MapLayer::draw(Graphics *graphics, } // Draw any remaining sprites - if (mIsFringeLayer) { - while (si != sprites.end()) { + if (mIsFringeLayer) + { + while (si != sprites.end()) + { (*si)->draw(graphics, -scrollX, -scrollY); si++; } diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 78b502ea..df8d264f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -233,7 +233,6 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); } - void OpenGLGraphics::updateScreen() { glFlush(); diff --git a/src/particle.cpp b/src/particle.cpp index e56435ed..0e412ada 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -177,7 +177,8 @@ bool Particle::update() mVelocity *= mBounce; mVelocity.z = -mVelocity.z; } - else { + else + { mAlive = false; } } @@ -185,16 +186,12 @@ bool Particle::update() // Update child emitters if ((mLifetimePast-1)%Particle::emitterSkip == 0) { - for ( EmitterIterator e = mChildEmitters.begin(); - e != mChildEmitters.end(); - e++ - ) + for (EmitterIterator e = mChildEmitters.begin(); + e != mChildEmitters.end(); e++) { Particles newParticles = (*e)->createParticles(mLifetimePast); - for ( ParticleIterator p = newParticles.begin(); - p != newParticles.end(); - p++ - ) + for (ParticleIterator p = newParticles.begin(); + p != newParticles.end(); p++) { (*p)->moveBy(mPos); mChildParticles.push_back (*p); @@ -219,7 +216,9 @@ bool Particle::update() if ((*p)->update()) { p++; - } else { + } + else + { delete (*p); p = mChildParticles.erase(p); } @@ -237,8 +236,7 @@ void Particle::moveBy(const Vector &change) { mPos += change; for (ParticleIterator p = mChildParticles.begin(); - p != mChildParticles.end(); - p++) + p != mChildParticles.end(); p++) { if ((*p)->doesFollow()) { @@ -279,20 +277,21 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, xmlNodePtr node; // Animation - if ((node = XML::findFirstChildByName( - effectChildNode, "animation"))) { + if ((node = XML::findFirstChildByName(effectChildNode, "animation"))) + { newParticle = new AnimationParticle(mMap, node); } // Image - else if ((node = XML::findFirstChildByName( - effectChildNode, "image"))) { + else if ((node = XML::findFirstChildByName(effectChildNode, "image"))) + { Image *img= resman->getImage((const char*) node->xmlChildrenNode->content); newParticle = new ImageParticle(mMap, img); } // Other - else { + else + { newParticle = new Particle(mMap); } @@ -315,7 +314,8 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, continue; ParticleEmitter *newEmitter; - newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, rotation); + newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, + rotation); newParticle->addEmitter(newEmitter); } @@ -326,7 +326,8 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, } Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, - const gcn::Color *color, gcn::Font *font, bool outline) + const gcn::Color *color, + gcn::Font *font, bool outline) { Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); @@ -344,7 +345,10 @@ Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + int x, int y, + const gcn::Color *color, + gcn::Font *font, bool outline) +{ Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 7a15b762..cff40197 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -26,6 +26,7 @@ #include "image.h" #include "../log.h" +#include "../position.h" #ifdef USE_OPENGL bool Image::mUseOpenGL = false; @@ -47,8 +48,7 @@ Image::Image(SDL_Surface *image): } #ifdef USE_OPENGL -Image::Image(GLuint glimage, int width, int height, - int texWidth, int texHeight): +Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight): mGLImage(glimage), mTexWidth(texWidth), mTexHeight(texHeight), @@ -316,6 +316,81 @@ void Image::setAlpha(float a) } } +Image* Image::merge(Image* image, const Position& pos) +{ + SDL_Surface* surface = new SDL_Surface(*(image->mImage)); + + Uint32 surface_pix, cur_pix; + Uint8 r, g, b, a, p_r, p_g, p_b, p_a; + double f_a, f_ca, f_pa; + SDL_PixelFormat *current_fmt = mImage->format; + SDL_PixelFormat *surface_fmt = surface->format; + int current_offset, surface_offset; + Position offset(0, 0); + + SDL_LockSurface(surface); + SDL_LockSurface(mImage); + // for each pixel lines of a source image + for (offset.x = (pos.x > 0 ? 0 : -pos.x); offset.x < image->getWidth() && + pos.x + offset.x < getWidth(); offset.x++) + { + for (offset.y = (pos.y > 0 ? 0 : -pos.y); offset.y < image->getHeight() + && pos.y + offset.y < getHeight(); offset.y++) + { + // Computing offset on both images + current_offset = (pos.y + offset.y) * getWidth() + pos.x + offset.x; + surface_offset = offset.y * surface->w + offset.x; + + // Retrieving a pixel to merge + surface_pix = ((Uint32*) surface->pixels)[surface_offset]; + cur_pix = ((Uint32*) mImage->pixels)[current_offset]; + + // Retreiving each channel of the pixel using pixel format + r = (Uint8)(((surface_pix & surface_fmt->Rmask) >> + surface_fmt->Rshift) << surface_fmt->Rloss); + g = (Uint8)(((surface_pix & surface_fmt->Gmask) >> + surface_fmt->Gshift) << surface_fmt->Gloss); + b = (Uint8)(((surface_pix & surface_fmt->Bmask) >> + surface_fmt->Bshift) << surface_fmt->Bloss); + a = (Uint8)(((surface_pix & surface_fmt->Amask) >> + surface_fmt->Ashift) << surface_fmt->Aloss); + + // Retreiving previous alpha value + p_a = (Uint8)(((cur_pix & current_fmt->Amask) >> + current_fmt->Ashift) << current_fmt->Aloss); + + // new pixel with no alpha or nothing on previous pixel + if (a == SDL_ALPHA_OPAQUE || (p_a == 0 && a > 0)) + ((Uint32 *)(surface->pixels))[current_offset] = + SDL_MapRGBA(current_fmt, r, g, b, a); + else if (a > 0) + { // alpha is lower => merge color with previous value + f_a = (double) a / 255.0; + f_ca = 1.0 - f_a; + f_pa = (double) p_a / 255.0; + p_r = (Uint8)(((cur_pix & current_fmt->Rmask) >> + current_fmt->Rshift) << current_fmt->Rloss); + p_g = (Uint8)(((cur_pix & current_fmt->Gmask) >> + current_fmt->Gshift) << current_fmt->Gloss); + p_b = (Uint8)(((cur_pix & current_fmt->Bmask) >> + current_fmt->Bshift) << current_fmt->Bloss); + r = (Uint8)((double) p_r * f_ca * f_pa + (double)r * f_a); + g = (Uint8)((double) p_g * f_ca * f_pa + (double)g * f_a); + b = (Uint8)((double) p_b * f_ca * f_pa + (double)b * f_a); + a = (a > p_a ? a : p_a); + ((Uint32 *)(surface->pixels))[current_offset] = + SDL_MapRGBA(current_fmt, r, g, b, a); + } + } + } + SDL_UnlockSurface(surface); + SDL_UnlockSurface(mImage); + + Image* newImage = new Image(surface); + + return newImage; +} + float Image::getAlpha() { return mAlpha; diff --git a/src/resources/image.h b/src/resources/image.h index 596917ce..f6b77f26 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -41,6 +41,7 @@ #include "resource.h" class Dye; +class Position; class SDL_Rect; class SDL_Surface; @@ -132,6 +133,15 @@ class Image : public Resource static void setLoadAsOpenGL(bool useOpenGL); #endif + /** + * Merges two image SDL_Surfaces together. This is for SDL use only, as + * reducing the number of surfaces that SDL has to render can cut down + * on the number of blit operations necessary, which in turn can help + * improve overall framerates. Don't use unless you are using it to + * reduce the number of overall layers that need to be drawn through SDL. + */ + Image* merge(Image* image, const Position& pos); + protected: /** * Constructor. -- cgit v1.2.3-70-g09d2 From 74fa304602e0e7ad845e606db8868b32f1d10864 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 18:06:21 -0600 Subject: Clean up TtemAmount dialog and add an All button --- src/gui/item_amount.cpp | 58 ++++++++++++++++++++++++++----------------------- src/gui/item_amount.h | 2 ++ 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 05dca472..8208d323 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,19 +36,17 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item) + mItem(item), mUsage(usage), mMax(mItem->getQuantity()) { - const int maxRange = mItem->getQuantity(); - // Integer field mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, maxRange); + mItemAmountTextField->setRange(1, mMax); mItemAmountTextField->setWidth(30); mItemAmountTextField->setActionEventId("Dummy"); mItemAmountTextField->addActionListener(this); // Slider - mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide = new Slider(1.0, mMax); mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); mItemAmountSlide->addActionListener(this); @@ -60,11 +58,13 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): plusButton->setSize(20, 20); Button *okButton = new Button(_("Ok"), "Drop", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); + Button *addAllButton = new Button(_("All"), "All", this); // Set positions place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); + place(4, 0, addAllButton, 2); place(0, 1, mItemAmountSlide, 6); place(4, 2, okButton); place(5, 2, cancelButton); @@ -76,19 +76,15 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): { case AMOUNT_TRADE_ADD: setCaption(_("Select amount of items to trade.")); - okButton->setActionEventId("AddTrade"); break; case AMOUNT_ITEM_DROP: 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"); + setCaption(_("Select amount of items to retrieve.")); break; default: break; @@ -123,26 +119,34 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { amount = static_cast(mItemAmountSlide->getValue()); } - else if (event.getId() == "Drop") - { - player_node->dropItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddTrade") - { - tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddStore") + else if (event.getId() == "Ok" || event.getId() == "All") { - storageWindow->addStore(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "RemoveStore") - { - storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + if (event.getId() == "All") { + amount = mMax; + } + + switch (mUsage) + { + case AMOUNT_TRADE_ADD: + tradeWindow->tradeItem(mItem, amount); + break; + case AMOUNT_ITEM_DROP: + player_node->dropItem(mItem, amount); + break; + case AMOUNT_STORE_ADD: + storageWindow->addStore(mItem, amount); + break; + case AMOUNT_STORE_REMOVE: + storageWindow->removeStore(mItem, amount); + break; + default: + return; + break; + } + scheduleDelete(); } + mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 279c239e..b802f71c 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -62,6 +62,8 @@ class ItemAmountWindow : public Window, public gcn::ActionListener IntTextField *mItemAmountTextField; /**< Item amount caption. */ Item *mItem; + int mMax, mUsage; + /** * Item Amount buttons. */ -- cgit v1.2.3-70-g09d2 From 6f0d88e781c8b1a75858c769b3641aa8cd477314 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 1 + src/gui/buysell.cpp | 16 +++++++++++++++- src/gui/buysell.h | 10 ++++++++++ src/gui/item_amount.cpp | 24 ++++++++++++------------ src/gui/npcstringdialog.cpp | 2 -- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 1 + src/gui/storagewindow.h | 4 ++++ src/gui/trade.cpp | 27 ++++++++++++++------------- src/gui/trade.h | 13 ++++++------- src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 14 files changed, 81 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 367a041e..ea1df204 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -236,3 +236,10 @@ void BuyDialog::updateButtonsAndLabels() mMoneyLabel->setCaption (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 17ab6e19..08697889 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,6 +96,7 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + void setVisible(bool visible); private: Network *mNetwork; gcn::Button *mBuyButton; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 64ffdc3f..df222797 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -54,8 +54,22 @@ BuySellDialog::BuySellDialog(Network *network): getTitleBarHeight()), ImageRect::CENTER); loadWindowState(); +} + +void BuySellDialog::logic() +{ + Window::logic(); + + if (isVisible() && !current_npc) + setVisible(false); +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); - requestFocus(); + if (visible) + requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 0842c0e1..c6989709 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -46,6 +46,16 @@ class BuySellDialog : public Window, public gcn::ActionListener BuySellDialog(Network *network); /** +<<<<<<< HEAD:src/gui/buysell.h +======= + * Check for current NPC + */ + void logic(); + + void setVisible(bool visible); + + /** +>>>>>>> f64903f... Fix up the NPC interraction widnows a bit:src/gui/buysell.h * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8208d323..c5b27524 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,7 +36,9 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item), mUsage(usage), mMax(mItem->getQuantity()) + mItem(item), + mMax(item->getQuantity()), + mUsage(usage) { // Integer field mItemAmountTextField = new IntTextField(1); @@ -53,10 +55,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): // Buttons Button *minusButton = new Button("-", "Minus", this); - minusButton->setSize(20, 20); Button *plusButton = new Button("+", "Plus", this); - plusButton->setSize(20, 20); - Button *okButton = new Button(_("Ok"), "Drop", this); + Button *okButton = new Button(_("Ok"), "Ok", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); @@ -64,10 +64,10 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); - place(4, 0, addAllButton, 2); + place(5, 0, addAllButton); place(0, 1, mItemAmountSlide, 6); - place(4, 2, okButton); - place(5, 2, cancelButton); + place(4, 2, cancelButton); + place(5, 2, okButton); reflowLayout(250, 0); resetAmount(); @@ -101,17 +101,17 @@ void ItemAmountWindow::resetAmount() void ItemAmountWindow::action(const gcn::ActionEvent &event) { - int amount = mItemAmountTextField->getValue(); + int amount = mItemAmountSlide->getValue(); if (event.getId() == "Cancel") { scheduleDelete(); } - else if (event.getId() == "Plus") + else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus") + else if (event.getId() == "Minus" && amount > 0) { amount--; } @@ -121,9 +121,8 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "Ok" || event.getId() == "All") { - if (event.getId() == "All") { + if (event.getId() == "All") amount = mMax; - } switch (mUsage) { @@ -145,6 +144,7 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } scheduleDelete(); + return; } mItemAmountTextField->setValue(amount); diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f50136ba..43d0722f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,9 +64,7 @@ void NpcStringDialog::setValue(const std::string &value) void NpcStringDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "cancel") - { mValueField->setText(""); - } setVisible(false); NPC::mTalking = false; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b780b02b..ed023227 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -265,3 +265,10 @@ void SellDialog::updateButtonsAndLabels() (strprintf(_("Price: %d GP / Total: %d GP"), income, mPlayerMoney + income)); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 5fb94c4e..c67a25b9 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + void setVisible(bool visible); private: /** * Updates the state of buttons and labels. diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 86451bfe..8f02a618 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -80,6 +80,10 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void removeStore(Item* item, int ammount); + /** + * Closes the Storage Window, as well as telling the server that the + * window has been closed. + */ void close(); private: diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index bae0b651..18b86d4b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -54,6 +54,7 @@ TradeWindow::TradeWindow(Network *network): setWindowName(_("Trade")); setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); + setCloseButton(true); setMinWidth(342); setMinHeight(209); @@ -90,10 +91,10 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(0, 0, mAddButton); - place(1, 0, mOkButton); - place(2, 0, mTradeButton); - place(3, 0, mCancelButton); + place(4, 0, mCancelButton); + place(5, 0, mTradeButton); + place(6, 0, mAddButton); + place(7, 0, mOkButton); Layout &layout = getLayout(); layout.extend(0, 2, 2, 1); layout.setRowHeight(1, Layout::AUTO_SET); @@ -108,14 +109,6 @@ TradeWindow::~TradeWindow() { } -void TradeWindow::widgetResized(const gcn::Event &event) -{ - mMyItemContainer->setWidth(mMyScroll->getWidth()); - mPartnerItemContainer->setWidth(mPartnerScroll->getWidth()); - - Window::widgetResized(event); -} - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); @@ -212,6 +205,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { + addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); @@ -249,7 +243,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (mMyInventory->contains(item)) { chatWindow->chatLog(_("Failed adding item. You can not " - "overlap one kind of item on the window."), BY_SERVER); + "overlap one kind of item on the window."), + BY_SERVER); return; } @@ -295,3 +290,9 @@ void TradeWindow::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_TRADE_OK); } } + +void TradeWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); +} diff --git a/src/gui/trade.h b/src/gui/trade.h index f4a6b5cd..c4d3076a 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -56,13 +56,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ ~TradeWindow(); - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - /** * Add money to the trade window. */ @@ -119,6 +112,12 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void action(const gcn::ActionEvent &event); + /** + * Closes the Trade Window, as well as telling the server that the + * window has been closed. + */ + void close(); + private: Network *mNetwork; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 404f5746..13c8f4ce 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -536,7 +536,7 @@ void Window::loadWindowState() void Window::saveWindowState() { // Saving X, Y and Width and Height for resizables in the config - if (!mWindowName.empty()) + if (!mWindowName.empty() && mWindowName != "window") { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 5b8f0b68..287e5400 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -33,15 +33,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -65,8 +62,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 6533ac1e..60d58a37 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-70-g09d2 From 0221ab5dc5236e9e35fe6c832a52020551dafa85 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 19 Mar 2009 18:58:11 +0100 Subject: Port Progressbar to TextRenderer --- src/gui/progressbar.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 025e0ec5..1f21df79 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -25,6 +25,7 @@ #include "gui.h" #include "palette.h" #include "progressbar.h" +#include "textrenderer.h" #include "../configuration.h" #include "../graphics.h" @@ -120,38 +121,22 @@ void ProgressBar::draw(gcn::Graphics *graphics) // The bar if (mProgress > 0) { - graphics->setColor(gcn::Color(mRed, mGreen, mBlue, alpha)); graphics->fillRectangle(gcn::Rectangle(4, 4, - (int) (mProgress * (getWidth() - 8)), - getHeight() - 8)); + (int) (mProgress * (getWidth() - 8)), + getHeight() - 8)); } // The label if (!mText.empty()) { - gcn::Font *f = boldFont; const int textX = getWidth() / 2; - const int textY = (getHeight() - f->getHeight()) / 2; - - gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); - - graphics->setFont(f); - - graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, - (int) tempColor.b, alpha)); - graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - - tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); - - graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, - (int) tempColor.b, alpha)); - graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); + const int textY = (getHeight() - boldFont->getHeight()) / 2; - graphics->setColor(guiPalette->getColor(Palette::TEXT)); + TextRenderer::renderText(graphics, mText, textX, textY, + gcn::Graphics::CENTER, + guiPalette->getColor(Palette::PROGRESS_BAR, + alpha), boldFont, true, false); } } -- cgit v1.2.3-70-g09d2 From a7a8ec7961fd7b1c8f83b92905f85c5a6e0358c0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 17:31:47 -0600 Subject: Some minor cleanups in a few windows and build scripts, as well as fixing tables to correct the highlights to draw where they're supposed to, as well as at the opacity they're supposed to. Signed-off-by: Ira Rice --- aethyra.cbp | 4 +- src/CMakeLists.txt | 8 +-- src/gui/color.cpp | 146 ----------------------------------------------- src/gui/color.h | 136 ------------------------------------------- src/gui/itempopup.cpp | 2 - src/gui/speechbubble.cpp | 2 - src/gui/table.cpp | 25 ++++---- 7 files changed, 18 insertions(+), 305 deletions(-) delete mode 100644 src/gui/color.cpp delete mode 100644 src/gui/color.h (limited to 'src') diff --git a/aethyra.cbp b/aethyra.cbp index 6e71375c..8ccdaa35 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -258,8 +258,6 @@ - - @@ -281,6 +279,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93bac9ae..0176e617 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,10 +61,10 @@ SET(SRCS gui/widgets/tab.h gui/widgets/tabbedarea.cpp gui/widgets/tabbedarea.h + gui/widgets/textpreview.cpp + gui/widgets/textpreview.h gui/browserbox.cpp gui/browserbox.h - gui/buddywindow.cpp - gui/buddywindow.h gui/button.cpp gui/button.h gui/buy.cpp @@ -114,7 +114,7 @@ SET(SRCS gui/itempopup.cpp gui/itempopup.h gui/itemshortcutcontainer.cpp - gui/itemshortcutcontainer.h\ + gui/itemshortcutcontainer.h gui/item_amount.cpp gui/item_amount.h gui/label.cpp @@ -207,8 +207,6 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h - gui/textpreview.cpp - gui/textpreview.h gui/textrenderer.h gui/trade.cpp gui/trade.h diff --git a/src/gui/color.cpp b/src/gui/color.cpp deleted file mode 100644 index b68bf68b..00000000 --- a/src/gui/color.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 "color.h" - -#include "../configuration.h" - -#include "../utils/gettext.h" -#include "../utils/stringutils.h" - -Color::Color() -{ - addColor('C', 0x000000, _("Chat")); - addColor('G', 0xff0000, _("GM")); - addColor('H', 0xebc873, _("Highlight")); - addColor('Y', 0x1fa052, _("Player")); - addColor('W', 0x0000ff, _("Whisper")); - addColor('I', 0xa08527, _("Is")); - addColor('P', 0xff00d8, _("Party")); - addColor('S', 0x8415e2, _("Server")); - addColor('L', 0x919191, _("Logger")); - addColor('<', 0xe50d0d, _("Hyperlink")); - commit(); -} - -Color::~Color() -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - config.setValue("Color" + col->text, toString(col->rgb)); - } -} - -void Color::setColor(const char c, const int rgb) -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - col->rgb = rgb; - return; - } - } -} - -int Color::getColor(const char c, bool &valid) const -{ - for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - valid = true; - return col->rgb; - } - } - valid = false; - return 0x000000; -} - -std::string Color::getElementAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return ""; - } - return mColVector[i].text; -} - -char Color::getColorCharAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 'C'; - } - return mColVector[i].ch; -} - -void Color::addColor(const char c, const int rgb, const std::string &text) -{ - int trueRgb = (int) config.getValue("Color" + text, rgb); - mColVector.push_back(ColorElem(c, trueRgb, text)); -} - -int Color::getColorAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 0; - } - return mColVector[i].rgb; -} - -void Color::setColorAt(int i, int rgb) -{ - if (i >= 0 && i < getNumberOfElements()) - { - mColVector[i].rgb = rgb; - } -} - -void Color::commit() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->committedRgb = i->rgb; - } -} - -void Color::rollback() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->rgb = i->committedRgb; - } -} diff --git a/src/gui/color.h b/src/gui/color.h deleted file mode 100644 index aca3d045..00000000 --- a/src/gui/color.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 COLOR_H -#define COLOR_H - -#include -#include - -#include - -class Color : public gcn::ListModel -{ - public: - /** - * Constructor - */ - Color(); - - /** - * Destructor - */ - ~Color(); - - /** - * Define the color replacement for a character - * - * @param c charater to be replaced - * @param rgb color to replace character - */ - void setColor(const char c, const int rgb); - - /** - * Define the color replacement for a character - * - * @param c character to be replaced - * @param r red component - * @param g green component - * @param b blue component - */ - void setColor(const char c, const int r, const int g, const int b) - { - setColor(c, (r << 16) | (g << 8) | b); - } - - /** - * Return the color associated with a character, if exists - * - * @param c character requested - * @param valid indicate whether character is known - */ - int getColor(const char c, bool &valid) const; - - /** - * Return the number of colors known - */ - int getNumberOfElements() {return mColVector.size(); } - - /** - * Return the name of the ith color - * - * @param i index of color interested in - */ - std::string getElementAt(int i); - - /** - * Get the color for the element at index i in the current color - * model - */ - int getColorAt(int i); - - /** - * Get the character used by the color for the element at index i in - * the current color model - */ - char getColorCharAt(int i); - - /** - * Set the color for the element at index i - */ - void setColorAt(int i, int rgb); - - /** - * Commit the colors - */ - void commit(); - - /** - * Rollback the colors - */ - void rollback(); - - private: - struct ColorElem - { - ColorElem(const char c, const int rgb, const std::string &text) : - ch(c), rgb(rgb), text(text) {} - char ch; - int rgb; - int committedRgb; - std::string text; - }; - typedef std::vector ColVector; - ColVector mColVector; - - /** - * Initialise color - * - * @param c character that needs initialising - * @param rgb default color if not found in config - * @param text identifier of color - */ - void addColor(const char c, const int rgb, const std::string &text); -}; - -extern Color *textColor; - -#endif diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index c76c3750..a4042ae2 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -85,8 +85,6 @@ ItemPopup::ItemPopup(): add(mItemDescScroll); add(mItemEffectScroll); add(mItemWeightScroll); - - setLocationRelativeTo(getParent()); } ItemPopup::~ItemPopup() diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 811fddfa..9e4c9234 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -60,8 +60,6 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); - - setLocationRelativeTo(getParent()); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index fa801865..17d8bfbf 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -320,29 +320,30 @@ void GuiTable::draw(gcn::Graphics* graphics) widget->setDimension(bounds); - if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); + + if (mLinewiseMode && r == mSelectedRow && c == 0) + { + graphics->fillRectangle(gcn::Rectangle(0, y_offset, + getWidth(), height)); + } + else if (!mLinewiseMode && + c == mSelectedColumn && r == mSelectedRow) { - graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, - (int)(mAlpha * 127.0f))); - graphics->fillRectangle(bounds); + graphics->fillRectangle(gcn::Rectangle(x_offset, y_offset, + width, height)); } graphics->pushClipArea(bounds); widget->draw(graphics); graphics->popClipArea(); + } x_offset += width; } - if (mLinewiseMode && r == mSelectedRow) - { - graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, - (int)(mAlpha * 127.0f))); - graphics->fillRectangle(gcn::Rectangle(0, y_offset, - x_offset, height)); - } - y_offset += height; } -- cgit v1.2.3-70-g09d2 From abeaa1184ae1f30adeeb6684748b3cf8e3f16b11 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 18:13:12 -0600 Subject: Simplified trading dialog controls. Signed-off-by: Ira Rice --- src/gui/button.cpp | 4 ++-- src/gui/trade.cpp | 47 +++++++++++++++++++---------------------------- src/gui/trade.h | 7 +------ 3 files changed, 22 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 592edce5..1b206161 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -74,9 +74,9 @@ Button::Button(const std::string& caption, const std::string &actionEventId, { init(); setActionEventId(actionEventId); - if (listener) { + + if (listener) addActionListener(listener); - } } void Button::init() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 18b86d4b..82ac4647 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -22,6 +22,8 @@ #include +#include + #include "button.h" #include "chat.h" #include "inventorywindow.h" @@ -59,12 +61,12 @@ TradeWindow::TradeWindow(Network *network): setMinWidth(342); setMinHeight(209); - mAddButton = new Button(_("Add"), "add", this); - mOkButton = new Button(_("Ok"), "ok", this); - mCancelButton = new Button(_("Cancel"), "cancel", this); - mTradeButton = new Button(_("Trade"), "trade", this); + std::string longestName = getFont()->getWidth(_("OK")) > + getFont()->getWidth(_("Trade")) ? + _("OK") : _("Trade"); - mTradeButton->setEnabled(false); + mAddButton = new Button(_("Add"), "add", this); + mOkButton = new Button(longestName, "ok", this); mMyItemContainer = new ItemContainer(mMyInventory.get(), 2); mMyItemContainer->setWidth(160); @@ -91,8 +93,6 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(4, 0, mCancelButton); - place(5, 0, mTradeButton); place(6, 0, mAddButton); place(7, 0, mOkButton); Layout &layout = getLayout(); @@ -102,6 +102,8 @@ TradeWindow::TradeWindow(Network *network): layout.setColWidth(0, Layout::AUTO_SET); layout.setColWidth(1, Layout::AUTO_SET); + mOkButton->setCaption(_("OK")); + loadWindowState(); } @@ -157,7 +159,8 @@ void TradeWindow::reset() { mMyInventory->clear(); mPartnerInventory->clear(); - mTradeButton->setEnabled(false); + mOkButton->setCaption(_("OK")); + mOkButton->setActionEventId("ok"); mOkButton->setEnabled(true); mOkOther = false; mOkMe = false; @@ -166,11 +169,6 @@ void TradeWindow::reset() mMoneyField->setText(""); } -void TradeWindow::setTradeButton(bool enabled) -{ - mTradeButton->setEnabled(enabled); -} - void TradeWindow::receivedOk(bool own) { if (own) @@ -178,13 +176,8 @@ void TradeWindow::receivedOk(bool own) mOkMe = true; if (mOkOther) { - mTradeButton->setEnabled(true); - mOkButton->setEnabled(false); - } - else - { - mTradeButton->setEnabled(false); - mOkButton->setEnabled(false); + mOkButton->setCaption(_("Trade")); + mOkButton->setActionEventId("trade"); } } else @@ -192,20 +185,18 @@ void TradeWindow::receivedOk(bool own) mOkOther = true; if (mOkMe) { - mTradeButton->setEnabled(true); - mOkButton->setEnabled(false); - } - else - { - mTradeButton->setEnabled(false); - mOkButton->setEnabled(true); + mOkButton->setCaption(_("Trade")); + mOkButton->setActionEventId("trade"); } } } void TradeWindow::tradeItem(Item *item, int quantity) { - addItem(item->getId(), true, quantity, item->isEquipment()); + // TODO: Our newer version of eAthena doesn't register this following + // function. Detect the actual server version, and re-enable this + // for that version only. + //addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); diff --git a/src/gui/trade.h b/src/gui/trade.h index c4d3076a..76ba5a4c 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -86,11 +86,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void increaseQuantity(int index, bool own, int quantity); - /** - * Set trade Button disabled - */ - void setTradeButton(bool enabled); - /** * Player received ok message from server */ @@ -130,7 +125,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener gcn::Label *mMoneyLabel; gcn::Label *mMoneyLabel2; - gcn::Button *mAddButton, *mOkButton, *mCancelButton, *mTradeButton; + gcn::Button *mAddButton, *mOkButton; ScrollArea *mMyScroll, *mPartnerScroll; gcn::TextField *mMoneyField; bool mOkOther, mOkMe; -- cgit v1.2.3-70-g09d2 From abffda81e5bab1fbf4870238e803bb5bae9d0df0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:20:11 -0600 Subject: Reformatted the item amount window and the buy/sell windows so that their guis are similarly laid out. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 62 ++++++++++++++++++++++++++++------------- src/gui/buy.h | 9 ++++++ src/gui/gui.cpp | 5 ++++ src/gui/gui.h | 5 ++++ src/gui/inventorywindow.cpp | 2 +- src/gui/item_amount.cpp | 48 ++++++++++++++++++++------------ src/gui/item_amount.h | 7 ++++- src/gui/npcintegerdialog.cpp | 5 ++-- src/gui/sell.cpp | 66 +++++++++++++++++++++++++++++--------------- src/gui/sell.h | 9 ++++++ 10 files changed, 156 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index ea1df204..c2c8cfed 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -22,6 +22,7 @@ #include "button.h" #include "buy.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "shop.h" @@ -39,11 +40,12 @@ #include "../utils/strprintf.h" BuyDialog::BuyDialog(Network *network): - Window(_("Buy")), mNetwork(network), + Window("Buy"), mNetwork(network), mMoney(0), mAmountItems(0), mMaxItems(0) { setWindowName(_("Buy")); setResizable(true); + setCloseButton(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); @@ -52,20 +54,25 @@ BuyDialog::BuyDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mSlider = new Slider(1.0); - mQuantityLabel = new Label("0"); + + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); 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); + mAddMaxButton = new Button(_("Max"), "max", this); mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(20, 20); - mDecreaseButton->setSize(20, 20); + mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mBuyButton->setEnabled(false); @@ -75,16 +82,21 @@ BuyDialog::BuyDialog(Network *network): mSlider->addActionListener(this); mShopItemList->addSelectionListener(this); - place(0, 0, mScrollArea, 5).setPadding(3); - place(0, 1, mQuantityLabel, 2); - place(2, 1, mSlider, 3); - place(0, 2, mMoneyLabel, 5); - place(0, 3, mItemEffectLabel, 5); - place(0, 4, mItemDescLabel, 5); + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 8, 5).setPadding(3); place(0, 5, mDecreaseButton); - place(1, 5, mIncreaseButton); - place(3, 5, mBuyButton); - place(4, 5, mQuitButton); + place(1, 5, mSlider, 3); + place(4, 5, mIncreaseButton); + place(5, 5, mQuantityLabel, 2); + place(7, 5, mAddMaxButton); + place(0, 6, mMoneyLabel, 8); + place(0, 7, mItemEffectLabel, 8); + place(0, 8, mItemDescLabel, 8); + place(6, 9, mBuyButton); + place(7, 9, mQuitButton); + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -124,15 +136,14 @@ void BuyDialog::addItem(int id, int price) void BuyDialog::action(const gcn::ActionEvent &event) { - int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "quit") { - setVisible(false); - current_npc = 0; + close(); return; } + int selectedItem = mShopItemList->getSelected(); + // The following actions require a valid selection if (selectedItem < 0 || selectedItem >= (int) mShopItems->getNumberOfElements()) @@ -157,6 +168,12 @@ void BuyDialog::action(const gcn::ActionEvent &event) mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } + else if (event.getId() == "max") + { + mAmountItems = mMaxItems; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } // TODO: Actually we'd have a bug elsewhere if this check for the number // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obvious_ way in C++? @@ -241,5 +258,12 @@ void BuyDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void BuyDialog::close() +{ + setVisible(false); + current_npc = 0; } diff --git a/src/gui/buy.h b/src/gui/buy.h index 08697889..ffd3f5c9 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,11 +96,20 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 434fc1e1..5bdab453 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -241,3 +241,8 @@ void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) gcn::Gui::handleMouseMoved(mouseInput); mMouseInactivityTimer = 0; } + +const int Gui::getFontHeight() const +{ + return mGuiFont->getHeight(); +} diff --git a/src/gui/gui.h b/src/gui/gui.h index afa358be..609648fd 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,11 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return game font height. + */ + const int getFontHeight() const; + /** * Return the Font used for "Info Particles", i.e. ones showing, what * you picked up, etc. diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 98916c07..f6e81fc5 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -99,7 +99,7 @@ InventoryWindow::InventoryWindow(int invSize): place(6, 5, mUseButton); Layout &layout = getLayout(); - layout.setRowHeight(0, mDropButton->getHeight()); + layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); } diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index c5b27524..5a7cf18f 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -21,8 +21,9 @@ */ #include "button.h" -#include "inttextfield.h" +#include "gui.h" #include "item_amount.h" +#include "label.h" #include "slider.h" #include "storagewindow.h" #include "trade.h" @@ -33,6 +34,7 @@ #include "../localplayer.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), @@ -40,12 +42,12 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): mMax(item->getQuantity()), mUsage(usage) { + setCloseButton(true); + // Integer field - mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, mMax); - mItemAmountTextField->setWidth(30); - mItemAmountTextField->setActionEventId("Dummy"); - mItemAmountTextField->addActionListener(this); + + mItemAmountLabel = new Label(strprintf("%d / %d", 1, mMax)); + mItemAmountLabel->setAlignment(gcn::Graphics::CENTER); // Slider mItemAmountSlide = new Slider(1.0, mMax); @@ -60,15 +62,22 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); + minusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + plusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + // Set positions + ContainerPlacer place; + place = getPlacer(0, 0); + place(0, 0, minusButton); - place(1, 0, mItemAmountTextField).setPadding(2); - place(2, 0, plusButton); - place(5, 0, addAllButton); - place(0, 1, mItemAmountSlide, 6); - place(4, 2, cancelButton); - place(5, 2, okButton); - reflowLayout(250, 0); + place(1, 0, mItemAmountSlide, 3); + place(4, 0, plusButton); + place(5, 0, mItemAmountLabel, 2); + place(7, 0, addAllButton); + place = getPlacer(0, 1); + place(4, 0, cancelButton); + place(5, 0, okButton); + reflowLayout(225, 0); resetAmount(); @@ -96,7 +105,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): void ItemAmountWindow::resetAmount() { - mItemAmountTextField->setValue(1); + mItemAmountLabel->setCaption(strprintf("%d / %d", 1, mMax)); } void ItemAmountWindow::action(const gcn::ActionEvent &event) @@ -105,13 +114,13 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) if (event.getId() == "Cancel") { - scheduleDelete(); + close(); } else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus" && amount > 0) + else if (event.getId() == "Minus" && amount > 1) { amount--; } @@ -147,6 +156,11 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) return; } - mItemAmountTextField->setValue(amount); + mItemAmountLabel->setCaption(strprintf("%d / %d", amount, mMax)); mItemAmountSlide->setValue(amount); } + +void ItemAmountWindow::close() +{ + scheduleDelete(); +} diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index b802f71c..34b33b37 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -58,8 +58,13 @@ class ItemAmountWindow : public Window, public gcn::ActionListener */ void resetAmount(); + /** + * Schedules the Item Amount window for deletion. + */ + void close(); + private: - IntTextField *mItemAmountTextField; /**< Item amount caption. */ + gcn::Label *mItemAmountLabel; /**< Item amount caption. */ Item *mItem; int mMax, mUsage; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 5b3e05aa..5332d196 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "inttextfield.h" #include "npcintegerdialog.h" @@ -47,8 +48,8 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); - mDecButton->setSize(20, 20); - mIncButton->setSize(20, 20); + mIncButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecButton->setSize(gui->getFontHeight(), gui->getFontHeight()); ContainerPlacer place; place = getPlacer(0, 0); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index ed023227..47e44ffe 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "sell.h" @@ -39,12 +40,13 @@ #include "../utils/strprintf.h" SellDialog::SellDialog(Network *network): - Window(_("Sell")), + Window("Sell"), mNetwork(network), mMaxItems(0), mAmountItems(0) { - setWindowName("Sell"); + setWindowName(_("Sell")); setResizable(true); + setCloseButton(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); @@ -54,21 +56,26 @@ SellDialog::SellDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mSlider = new Slider(1.0); - mQuantityLabel = new Label("0"); + + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); 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); + mAddMaxButton = new Button(_("Max"), "max", this); mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(20, 20); - mDecreaseButton->setSize(20, 20); + mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mSellButton->setEnabled(false); @@ -79,16 +86,21 @@ SellDialog::SellDialog(Network *network): mSlider->setActionEventId("slider"); mSlider->addActionListener(this); - place(0, 0, mScrollArea, 5).setPadding(3); - place(0, 1, mQuantityLabel, 2); - place(2, 1, mSlider, 3); - place(0, 2, mMoneyLabel, 5); - place(0, 3, mItemEffectLabel, 5); - place(0, 4, mItemDescLabel, 5); + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 8, 5).setPadding(3); place(0, 5, mDecreaseButton); - place(1, 5, mIncreaseButton); - place(3, 5, mSellButton); - place(4, 5, mQuitButton); + place(1, 5, mSlider, 3); + place(4, 5, mIncreaseButton); + place(5, 5, mQuantityLabel, 2); + place(7, 5, mAddMaxButton); + place(0, 6, mMoneyLabel, 8); + place(0, 7, mItemEffectLabel, 8); + place(0, 8, mItemDescLabel, 8); + place(6, 9, mSellButton); + place(7, 9, mQuitButton); + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -114,9 +126,7 @@ void SellDialog::reset() void SellDialog::addItem(const Item *item, int price) { if (!item) - { return; - } mShopItems->addItem(item->getInvIndex(), item->getId(), item->getQuantity(), price); @@ -126,15 +136,14 @@ void SellDialog::addItem(const Item *item, int price) void SellDialog::action(const gcn::ActionEvent &event) { - int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "quit") { - setVisible(false); - current_npc = 0; + close(); return; } + int selectedItem = mShopItemList->getSelected(); + // The following actions require a valid item selection if (selectedItem == -1 || selectedItem >= (int) mShopItems->getNumberOfElements()) @@ -159,6 +168,12 @@ void SellDialog::action(const gcn::ActionEvent &event) mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } + else if (event.getId() == "max") + { + mAmountItems = mMaxItems; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } else if (event.getId() == "sell" && mAmountItems > 0 && mAmountItems <= mMaxItems) { @@ -270,5 +285,12 @@ void SellDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void SellDialog::close() +{ + setVisible(false); + current_npc = 0; } diff --git a/src/gui/sell.h b/src/gui/sell.h index c67a25b9..930f8bc1 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,7 +82,15 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: /** * Updates the state of buttons and labels. @@ -92,6 +100,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; -- cgit v1.2.3-70-g09d2 From 0b076a2dd247cd128599bf24eeba31f372f89585 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:39:12 -0600 Subject: Made the plus and minus buttons in the last commit look more aesthetically pleasing. Signed-off-by: Ira Rice --- src/gui/button.cpp | 6 ++++-- src/gui/buy.cpp | 4 ++-- src/gui/item_amount.cpp | 4 ++-- src/gui/npcintegerdialog.cpp | 4 ++-- src/gui/sell.cpp | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 1b206161..16a2853c 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -95,8 +95,10 @@ void Button::init() { btn[mode] = resman->getImage(data[mode].file); a = 0; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { button[mode].grid[a] = btn[mode]->getSubImage( data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c2c8cfed..a0944086 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -70,8 +70,8 @@ BuyDialog::BuyDialog(Network *network): mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->adjustSize(); + mDecreaseButton->setWidth(mIncreaseButton->getWidth()); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 5a7cf18f..41122229 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -62,8 +62,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); - minusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - plusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + minusButton->adjustSize(); + minusButton->setWidth(plusButton->getWidth()); // Set positions ContainerPlacer place; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 5332d196..b4498b31 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -48,8 +48,8 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); - mIncButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecButton->adjustSize(); + mDecButton->setWidth(mIncButton->getWidth()); ContainerPlacer place; place = getPlacer(0, 0); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 47e44ffe..4b58d075 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -73,8 +73,8 @@ SellDialog::SellDialog(Network *network): mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->adjustSize(); + mDecreaseButton->setWidth(mIncreaseButton->getWidth()); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); -- cgit v1.2.3-70-g09d2 From 5022aad7e787777e6fd3e8e34956e53aabb41c21 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:40:58 -0600 Subject: Forgot to remove some now unneeded includes. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 1 - src/gui/item_amount.cpp | 1 - src/gui/npcintegerdialog.cpp | 1 - src/gui/sell.cpp | 1 - 4 files changed, 4 deletions(-) (limited to 'src') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a0944086..43c423f1 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -22,7 +22,6 @@ #include "button.h" #include "buy.h" -#include "gui.h" #include "label.h" #include "scrollarea.h" #include "shop.h" diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 41122229..5b3380c2 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "item_amount.h" #include "label.h" #include "slider.h" diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index b4498b31..27721f0c 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "inttextfield.h" #include "npcintegerdialog.h" diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 4b58d075..591cf97b 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "label.h" #include "scrollarea.h" #include "sell.h" -- cgit v1.2.3-70-g09d2 From c2c0a9fa8476b9335a6198b41cc702da82fd40bd Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:55:42 -0600 Subject: Reduced down label code. Signed-off-by: Ira Rice --- src/gui/label.cpp | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'src') diff --git a/src/gui/label.cpp b/src/gui/label.cpp index bab8c465..e8d72ace 100644 --- a/src/gui/label.cpp +++ b/src/gui/label.cpp @@ -20,16 +20,9 @@ * 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 "gui.h" #include "label.h" #include "palette.h" -#include "../graphics.h" - Label::Label() : gcn::Label() { @@ -42,27 +35,6 @@ Label::Label(const std::string& caption) : void Label::draw(gcn::Graphics* graphics) { - int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; - - switch (getAlignment()) - { - case gcn::Graphics::LEFT: - textX = 0; - break; - case gcn::Graphics::CENTER: - textX = getWidth() / 2; - break; - case gcn::Graphics::RIGHT: - textX = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - setForegroundColor(guiPalette->getColor(Palette::TEXT)); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + gcn::Label::draw(static_cast(graphics)); } -- cgit v1.2.3-70-g09d2 From 4b7755fcae0de15951c508ec034158007c8b6cf3 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 23:05:20 -0600 Subject: Throttle framerates down to save CPU cycles. Now that we're getting high framerates in OpenGL even on older hardware, this should be done to conserve on CPU usage, rather than stressing it with more frames than the monitor can render. Signed-off-by: Ira Rice --- src/game.cpp | 7 +++++-- src/gui/setup_video.cpp | 32 ++++++++++++++++++-------------- src/main.cpp | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index a346616f..7f0186d1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -408,8 +408,11 @@ void Game::optionChanged(const std::string &name) { int fpsLimit = (int) config.getValue("fpslimit", 0); - // Calculate new minimum frame time - mMinFrameTime = fpsLimit ? 1000 / fpsLimit : 0; + // Calculate new minimum frame time. If one isn't set, use 60 FPS. + // (1000 / 60 is 16.66) Since the client can go well above the refresh + // rates for monitors now in OpenGL mode, this cutoff is done to help + // conserve on CPU time. + mMinFrameTime = fpsLimit ? 1000 / fpsLimit : 16; // Reset draw time to current time mDrawTime = tick_time * 10; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index d1d7e4f8..e181f744 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -88,13 +88,15 @@ ModeListModel::ModeListModel() SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); /* Check which modes are available */ - if (modes == (SDL_Rect **)0) { + if (modes == (SDL_Rect **)0) logger->log("No modes available"); - } else if (modes == (SDL_Rect **)-1) { + else if (modes == (SDL_Rect **)-1) logger->log("All resolutions available"); - } else { + else + { //logger->log("Available Modes"); - for (int i = 0; modes[i]; ++i) { + for (int i = 0; modes[i]; ++i) + { const std::string modeString = toString((int)modes[i]->w) + "x" + toString((int)modes[i]->h); //logger->log(modeString.c_str()); @@ -125,7 +127,7 @@ Setup_Video::Setup_Video(): mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), - mFpsSlider(new Slider(10, 200)), + mFpsSlider(new Slider(10, 120)), mFpsField(new TextField), mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 16)), mScrollLazinessSlider(new Slider(1, 64)), @@ -337,9 +339,11 @@ void Setup_Video::apply() } } #ifdef WIN32 - } else { + } + else + { new OkDialog(_("Switching to full screen"), - _("Restart needed for changes to take effect.")); + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen ? true : false); @@ -352,7 +356,7 @@ void Setup_Video::apply() // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing OpenGL"), - _("Applying change to OpenGL requires restart.")); + _("Applying change to OpenGL requires restart.")); } // FPS change @@ -450,8 +454,9 @@ void Setup_Video::action(const gcn::ActionEvent &event) { config.setValue("particleeffects", mParticleEffectsCheckBox->isSelected() ? true : false); - new OkDialog(_("Particle effect settings changed"), - _("Restart your client or change maps for the change to take effect.")); + new OkDialog(_("Particle effect settings changed."), + _("Restart your client or change maps " + "for the change to take effect.")); } else if (event.getId() == "pickupchat") { @@ -461,8 +466,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) else if (event.getId() == "pickupparticle") { config.setValue("showpickupparticle", - mPickupParticleCheckBox->isSelected() - ? true : false); + mPickupParticleCheckBox->isSelected() ? true : false); } else if (event.getId() == "speech") { @@ -576,9 +580,9 @@ void Setup_Video::keyPressed(gcn::KeyEvent &event) { mFps = 10; } - else if (mFps > 200) + else if (mFps > 120) { - mFps = 200; + mFps = 120; } mFpsField->setText(toString(mFps)); mFpsSlider->setValue(mFps); diff --git a/src/main.cpp b/src/main.cpp index 7ee2f6b4..a04c8696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1101,9 +1101,9 @@ int main(int argc, char *argv[]) /* * This loop can really stress the CPU, for no reason since it's * just constantly redrawing the wallpaper. Added the following - * usleep to limit it to 20 FPS during the login sequence + * usleep to limit it to 40 FPS during the login sequence */ - usleep(50000); + usleep(25000); } delete guiPalette; -- cgit v1.2.3-70-g09d2 From 347452b9b69ef3af29c577b7751082822e900c01 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Mar 2009 22:27:13 -0600 Subject: Be sure to free the window icon --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index a04c8696..2ecde05d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -145,6 +145,8 @@ std::string updatesDir; LoginHandler loginHandler; MapLoginHandler mapLoginHandler; +SDL_Surface *icon; + /** * A structure holding the values of various options that can be passed from * the command line. @@ -387,7 +389,7 @@ void init_engine(const Options &options) SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); } #else - SDL_Surface *icon = IMG_Load(PKG_DATADIR "data/icons/aethyra.png"); + icon = IMG_Load(PKG_DATADIR "data/icons/aethyra.png"); if (icon) { SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); @@ -487,6 +489,8 @@ void exit_engine() ResourceManager::deleteInstance(); delete logger; + + SDL_FreeSurface(icon); } void printHelp() -- cgit v1.2.3-70-g09d2