diff options
Diffstat (limited to 'src/gui')
40 files changed, 344 insertions, 584 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a948b136..008c7bb9 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -40,6 +40,7 @@ BuyDialog::BuyDialog(): Window(_("Buy")), mMoney(0), mAmountItems(0), mMaxItems(0) { + setWindowName("Buy"); setResizable(true); setMinWidth(260); setMinHeight(230); @@ -85,7 +86,7 @@ BuyDialog::BuyDialog(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - loadWindowState("Buy"); + loadWindowState(); setLocationRelativeTo(getParent()); } diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 3adfbc08..67cb3c7b 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -266,7 +266,8 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window(_("Create Character"), true, parent), mSlot(slot) { mPlayer = new Player(0, 0, NULL); - mPlayer->setHairStyle(rand() % NR_HAIR_STYLES, rand() % NR_HAIR_COLORS); + mPlayer->setHairStyle(rand() % Being::getHairStylesNr(), + rand() % Being::getHairColorsNr()); mPlayer->setGender(GENDER_MALE); mNameField = new TextField(""); @@ -422,13 +423,13 @@ CharCreateDialog::action(const gcn::ActionEvent &event) mPlayer->setHairStyle(-1, mPlayer->getHairColor() + 1); } else if (event.getId() == "prevcolor") { - mPlayer->setHairStyle(-1, mPlayer->getHairColor() + NR_HAIR_COLORS - 1); + mPlayer->setHairStyle(-1, mPlayer->getHairColor() + Being::getHairColorsNr() - 1); } else if (event.getId() == "nextstyle") { mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, -1); } else if (event.getId() == "prevstyle") { - mPlayer->setHairStyle(mPlayer->getHairStyle() + NR_HAIR_STYLES - 1, -1); + mPlayer->setHairStyle(mPlayer->getHairStyle() + Being::getHairStylesNr() - 1, -1); } else if (event.getId() == "statslider") { UpdateSliders(); diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp deleted file mode 100644 index 1c9edf45..00000000 --- a/src/gui/chargedialog.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - /* The window supported by this class shows player stats and keeps a charging - * action bar in queue. - */ - -#include "chargedialog.h" - -#include "progressbar.h" - -#include "../localplayer.h" - -ChargeDialog::ChargeDialog(): - Window("") -{ - setContentSize(180, 70); - mProgBar = new ProgressBar(0.0f, 140, 25, 128, 128, 128); - mProgBar->setPosition(20, 40); - add(mProgBar); - setVisible(true); -} - -// update the dialog -void ChargeDialog::logic() -{ - // calculate time since the last attack was made - player_node->mLastAttackTime += .01; // this a hack until someone explains - // to me how to work the timer - if (player_node->mLastAttackTime > 1) - { - player_node->mLastAttackTime = 1; - } - - // reset the progress bar to display accurate time since attack - mProgBar->setProgress(player_node->mLastAttackTime); - - Window::logic(); -} diff --git a/src/gui/chargedialog.h b/src/gui/chargedialog.h deleted file mode 100644 index 9517ef6a..00000000 --- a/src/gui/chargedialog.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _TMW_CHARGE_H -#define _TMW_CHARGE_H - -#include "window.h" - -class ProgressBar; - -#define CHARGE_TIME 1000 // time in milliseconds it takes to charge up an attack - -/** - * \ingroup Interface - */ -class ChargeDialog : public Window -{ - public: - /** - * Constructor. - */ - ChargeDialog(); - - void logic(); - - private: - ProgressBar* mProgBar; -}; - -#endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index c94429c8..888dd27d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -52,11 +52,12 @@ ChatWindow::ChatWindow(): Window("Chat"), mTmpVisible(false) { + setWindowName("Chat"); setResizable(true); - setDefaultSize(0, (windowContainer->getHeight() - 105), 400, 100); + setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); setOpaque(false); - mChatInput = new ChatInput(); + mChatInput = new ChatInput; mChatInput->setActionEventId("chatinput"); mChatInput->addActionListener(this); @@ -88,7 +89,7 @@ ChatWindow::ChatWindow(): mChatInput->addKeyListener(this); mCurHist = mHistory.end(); - loadWindowState("Chat"); + loadWindowState(); } ChatWindow::~ChatWindow() @@ -97,7 +98,7 @@ ChatWindow::~ChatWindow() delete mChatTabs; } -const std::string& ChatWindow::getFocused() const +const std::string &ChatWindow::getFocused() const { return mChatTabs->getSelectedTab()->getCaption(); } @@ -151,8 +152,7 @@ void ChatWindow::logic() } } -void -ChatWindow::chatLog(std::string line, int own, std::string channelName) +void ChatWindow::chatLog(std::string line, int own, std::string channelName) { if(channelName.empty()) channelName = getFocused(); @@ -240,8 +240,7 @@ ChatWindow::chatLog(std::string line, int own, std::string channelName) scroll->logic(); } -void -ChatWindow::action(const gcn::ActionEvent &event) +void ChatWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "chatinput") { @@ -274,8 +273,7 @@ ChatWindow::action(const gcn::ActionEvent &event) } } -void -ChatWindow::requestChatFocus() +void ChatWindow::requestChatFocus() { // Make sure chatWindow is visible if (!isVisible()) @@ -295,13 +293,12 @@ ChatWindow::requestChatFocus() mChatInput->requestFocus(); } -bool -ChatWindow::isInputFocused() +bool ChatWindow::isInputFocused() { return mChatInput->isFocused(); } -void ChatWindow::chatSend(std::string const &msg) +void ChatWindow::chatSend(const std::string &msg) { if (msg.empty()) return; @@ -327,20 +324,17 @@ void ChatWindow::chatSend(std::string const &msg) } } -void -ChatWindow::removeChannel(short channelId) +void ChatWindow::removeChannel(short channelId) { removeChannel(channelManager->findById(channelId)); } -void -ChatWindow::removeChannel(const std::string &channelName) +void ChatWindow::removeChannel(const std::string &channelName) { removeChannel(channelManager->findByName(channelName)); } -void -ChatWindow::removeChannel(Channel *channel) +void ChatWindow::removeChannel(Channel *channel) { if (channel) { @@ -356,8 +350,7 @@ ChatWindow::removeChannel(Channel *channel) } } -void -ChatWindow::createNewChannelTab(const std::string &channelName) +void ChatWindow::createNewChannelTab(const std::string &channelName) { // Create new channel BrowserBox *textOutput = new BrowserBox(BrowserBox::AUTO_WRAP); @@ -384,8 +377,9 @@ ChatWindow::createNewChannelTab(const std::string &channelName) logic(); } -void -ChatWindow::sendToChannel(short channelId, const std::string &user, const std::string &msg) +void ChatWindow::sendToChannel(short channelId, + const std::string &user, + const std::string &msg) { Channel *channel = channelManager->findById(channelId); if (channel) @@ -395,8 +389,7 @@ ChatWindow::sendToChannel(short channelId, const std::string &user, const std::s } } -void -ChatWindow::keyPressed(gcn::KeyEvent &event) +void ChatWindow::keyPressed(gcn::KeyEvent &event) { if (event.getKey().getValue() == Key::DOWN && mCurHist != mHistory.end()) @@ -421,15 +414,13 @@ ChatWindow::keyPressed(gcn::KeyEvent &event) } } -void -ChatWindow::setInputText(std::string input_str) +void ChatWindow::setInputText(std::string input_str) { mChatInput->setText(input_str + " "); requestChatFocus(); } -void -ChatWindow::setVisible(bool isVisible) +void ChatWindow::setVisible(bool isVisible) { Window::setVisible(isVisible); @@ -440,11 +431,8 @@ ChatWindow::setVisible(bool isVisible) mTmpVisible = false; } -bool -ChatWindow::tabExists(const std::string &tabName) +bool ChatWindow::tabExists(const std::string &tabName) { Tab *tab = mChatTabs->getTab(tabName); - if (tab) - return true; - return false; + return tab != 0; } diff --git a/src/gui/chat.h b/src/gui/chat.h index a41b11fb..8ca0e4c9 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -118,41 +118,34 @@ class ChatWindow : public Window, * @param msg The message text which is to be sent. * */ - void chatSend(std::string const &msg); + void chatSend(const std::string &msg); /** Called to remove the channel from the channel manager */ - void - removeChannel(short channelId); + void removeChannel(short channelId); - void - removeChannel(const std::string &channelName); + void removeChannel(const std::string &channelName); - void - removeChannel(Channel *channel); + void removeChannel(Channel *channel); /** Called to create a new channel tab */ - void - createNewChannelTab(const std::string &channelName); + void createNewChannelTab(const std::string &channelName); /** Called to output text to a specific channel */ - void - sendToChannel(short channel, const std::string &user, const std::string &msg); + void sendToChannel(short channel, + const std::string &user, + const std::string &msg); /** Called when key is pressed */ - void - keyPressed(gcn::KeyEvent &event); + void keyPressed(gcn::KeyEvent &event); /** Called to set current text */ - void - setInputText(std::string input_str); + void setInputText(std::string input_str); /** Override to reset mTmpVisible */ - void - setVisible(bool visible); + void setVisible(bool visible); /** Check if tab with that name already exists */ - bool - tabExists(const std::string &tabName); + bool tabExists(const std::string &tabName); void logic(); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index d92c3575..36e4c8e1 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -39,10 +39,11 @@ DebugWindow::DebugWindow(): Window("Debug") { + setWindowName("Debug"); setResizable(true); setCloseButton(true); setDefaultSize(0, 0, 400, 100); - loadWindowState("Debug"); + loadWindowState(); mFPSLabel = new gcn::Label("[0 FPS]"); mFPSLabel->setPosition(0,0); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index aee262d0..6848b4d8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -51,15 +51,15 @@ static const int boxPosition[][2] = { }; EquipmentWindow::EquipmentWindow(Equipment *equipment): - Window(_("Equipment")), mEquipment(equipment), mBackground(NULL), mSelected(-1) { + setWindowName("Equipment"); setCloseButton(true); setDefaultSize(5, 195, 216, 260); - loadWindowState("Equipment"); + loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); gcn::Rectangle const &area = getChildrenArea(); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 930d4939..dc6306b4 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -37,6 +37,7 @@ #include "../graphics.h" #include "../log.h" +#include "../resources/image.h" #include "../resources/imageset.h" #include "../resources/resourcemanager.h" #include "../resources/imageloader.h" @@ -74,6 +75,8 @@ class GuiConfigListener : public ConfigListener Gui::Gui(Graphics *graphics): mCustomCursor(false), mMouseCursors(NULL), + mMouseCursorAlpha(1.0f), + mMouseInactivityTimer(0), mCursorType(CURSOR_POINTER) { logger->log("Initializing GUI..."); @@ -157,32 +160,47 @@ Gui::~Gui() delete hitBlueFont; delete hitYellowFont; - if (mMouseCursors) { + if (mMouseCursors) mMouseCursors->decRef(); - } delete mGuiFont; delete speechFont; delete viewport; - delete mTop; + delete getTop(); delete guiInput; } -void -Gui::draw() +void Gui::logic() +{ + // Fade out mouse cursor after extended inactivity + if (mMouseInactivityTimer < 100 * 15) { + ++mMouseInactivityTimer; + mMouseCursorAlpha = std::min(1.0f, mMouseCursorAlpha + 0.05f); + } else { + mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + } + + gcn::Gui::logic(); +} + +void Gui::draw() { - mGraphics->pushClipArea(mTop->getDimension()); - mTop->draw(mGraphics); + mGraphics->pushClipArea(getTop()->getDimension()); + getTop()->draw(mGraphics); int mouseX, mouseY; Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); - if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) && - mCustomCursor) + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) + && mCustomCursor + && mMouseCursorAlpha > 0.0f) { + Image *mouseCursor = mMouseCursors->get(mCursorType); + mouseCursor->setAlpha(mMouseCursorAlpha); + static_cast<Graphics*>(mGraphics)->drawImage( - mMouseCursors->get(mCursorType), + mouseCursor, mouseX - 15, mouseY - 17); } @@ -190,8 +208,7 @@ Gui::draw() mGraphics->popClipArea(); } -void -Gui::setUseCustomCursor(bool customCursor) +void Gui::setUseCustomCursor(bool customCursor) { if (customCursor != mCustomCursor) { @@ -224,3 +241,9 @@ Gui::setUseCustomCursor(bool customCursor) } } } + +void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) +{ + gcn::Gui::handleMouseMoved(mouseInput); + mMouseInactivityTimer = 0; +} diff --git a/src/gui/gui.h b/src/gui/gui.h index a07d236f..7d390df9 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -59,6 +59,12 @@ class Gui : public gcn::Gui ~Gui(); /** + * Performs logic of the GUI. Overridden to track mouse pointer + * activity. + */ + void logic(); + + /** * Draws the whole Gui by calling draw functions down in the * Gui hierarchy. It also draws the mouse pointer. */ @@ -95,11 +101,16 @@ class Gui : public gcn::Gui CURSOR_TOTAL }; + protected: + void handleMouseMoved(const gcn::MouseInput &mouseInput); + private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ + float mMouseCursorAlpha; + int mMouseInactivityTimer; int mCursorType; }; diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index ae9684df..0596c75e 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -49,6 +49,7 @@ GuildWindow::GuildWindow(): Window(_("Guild")), mFocus(false) { + setWindowName("Guild"); setCaption(_("Guild")); setResizable(false); setCloseButton(true); @@ -73,7 +74,7 @@ GuildWindow::GuildWindow(): layout.setColWidth(0, 48); layout.setColWidth(1, 65); - loadWindowState("Guild"); + loadWindowState(); } GuildWindow::~GuildWindow() diff --git a/src/gui/help.cpp b/src/gui/help.cpp index ffe9c02d..290679b9 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -31,6 +31,7 @@ HelpWindow::HelpWindow(): Window("Help") { setContentSize(455, 350); + setWindowName("Help"); mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 0fda7945..1e3c4084 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -53,6 +53,7 @@ InventoryWindow::InventoryWindow(): Window(_("Inventory")), mSplit(false) { + setWindowName("Inventory"); setResizable(false); setCloseButton(true); // LEEOR/TODO: Since this window is not resizable, do we really need to set these @@ -60,7 +61,7 @@ InventoryWindow::InventoryWindow(): setMinWidth(375); setMinHeight(283); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 283); + setDefaultSize(115, 30, 375, 283); addKeyListener(this); mUseButton = new Button(_("Use"), "use", this); @@ -82,7 +83,7 @@ InventoryWindow::InventoryWindow(): layout.setColWidth(2, 48); layout.setRowHeight(0, Layout::AUTO_SET); - loadWindowState("Inventory"); + loadWindowState(); } void InventoryWindow::logic() diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 5fb99ffc..141b4360 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -82,8 +82,7 @@ ItemContainer::~ItemContainer() mSelImg->decRef(); } -void -ItemContainer::draw(gcn::Graphics *graphics) +void ItemContainer::draw(gcn::Graphics *graphics) { Graphics *g = static_cast<Graphics*>(graphics); @@ -147,8 +146,7 @@ ItemContainer::draw(gcn::Graphics *graphics) } } -void -ItemContainer::selectNone() +void ItemContainer::selectNone() { setSelectedItem(NULL); } @@ -324,8 +322,7 @@ int ItemContainer::getSlotIndex(const int posX, const int posY) const return Inventory::NO_SLOT_INDEX; } -void -ItemContainer::keyAction() +void ItemContainer::keyAction() { // If there is no highlight then return. if (!mHighlightedItem) @@ -362,8 +359,7 @@ ItemContainer::keyAction() } } -void -ItemContainer::moveHighlight(int direction) +void ItemContainer::moveHighlight(int direction) { if (!mHighlightedItem) { diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 76104e12..e0604c78 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -85,7 +85,7 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0+i)); + (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0 + i)); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); if (itemShortcut->getItem(i) < 0) @@ -96,9 +96,11 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item icon. Image* image = item->getImage(); if (image) { + // TODO: Have label indicate equipped status + const std::string label = toString(item->getQuantity()); g->drawImage(image, itemX, itemY); g->drawText( - toString(item->getQuantity()), + label, itemX + mBoxWidth / 2, itemY + mBoxHeight - 14, gcn::Graphics::CENTER); diff --git a/src/gui/itemshortcutwindow.cpp b/src/gui/itemshortcutwindow.cpp index e4d352fe..e21f421b 100644 --- a/src/gui/itemshortcutwindow.cpp +++ b/src/gui/itemshortcutwindow.cpp @@ -28,13 +28,14 @@ static const int SCROLL_PADDING = 0; ItemShortcutWindow::ItemShortcutWindow() { + setWindowName("ItemShortcut"); // no title presented, title bar is padding so window can be moved. gcn::Window::setTitleBarHeight(gcn::Window::getPadding()); setShowTitle(false); setResizable(true); setDefaultSize(758, 174, 42, 426); - mItems = new ItemShortcutContainer(); + mItems = new ItemShortcutContainer; const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); @@ -49,7 +50,7 @@ ItemShortcutWindow::ItemShortcutWindow() add(mScrollArea); - loadWindowState("ItemShortcut"); + loadWindowState(); } ItemShortcutWindow::~ItemShortcutWindow() diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 24c55e37..b4289984 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -71,12 +71,9 @@ LoginDialog::LoginDialog(LoginData *loginData) : Window(_("Login")), mLoginData( setLocationRelativeTo(getParent()); setVisible(true); - if (mUserField->getText().empty()) - { + if (mUserField->getText().empty()) { mUserField->requestFocus(); - } - else - { + } else { mPassField->requestFocus(); } diff --git a/src/gui/magic.cpp b/src/gui/magic.cpp index ca7b5489..2c81321b 100644 --- a/src/gui/magic.cpp +++ b/src/gui/magic.cpp @@ -35,8 +35,9 @@ MagicDialog::MagicDialog(): Window(_("Magic")) { + setWindowName("Magic"); setCloseButton(true); - setDefaultSize(255, 25, 175, 225); + setDefaultSize(255, 30, 175, 225); gcn::Button *spellButton1 = new Button(_("Cast Test Spell 1"), "spell_1", this); gcn::Button *spellButton2 = new Button(_("Cast Test Spell 2"), "spell_2", this); @@ -53,7 +54,7 @@ MagicDialog::MagicDialog(): update(); setLocationRelativeTo(getParent()); - loadWindowState(_("Magic")); + loadWindowState(); } MagicDialog::~MagicDialog() diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 501530f1..f7749755 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -34,8 +34,9 @@ Minimap::Minimap(): Window(_("MiniMap")), mMapImage(NULL) { - setDefaultSize(0, 0, 100, 100); - loadWindowState("MiniMap"); + setWindowName("MiniMap"); + setDefaultSize(5, 25, 100, 100); + loadWindowState(); // LEEOR: The Window class needs to modified to accept // setAlignment calls. setAlignment(gcn::Graphics::CENTER); @@ -44,49 +45,50 @@ Minimap::Minimap(): Minimap::~Minimap() { if (mMapImage) - { mMapImage->decRef(); - } } void Minimap::setMapImage(Image *img) { if (mMapImage) - { mMapImage->decRef(); - } mMapImage = img; - if (mMapImage) - { + if (mMapImage) { mMapImage->setAlpha(0.7); - setSize( mMapImage->getWidth() + 6, mMapImage->getHeight() + 23 ); - setVisible(true); + setContentSize(mMapImage->getWidth(), mMapImage->getHeight()); } - else - { - setVisible(false); - } - } void Minimap::draw(gcn::Graphics *graphics) { Window::draw(graphics); + const gcn::Rectangle a = getChildrenArea(); + + int mapOriginX = a.x; + int mapOriginY = a.y; + if (mMapImage) { - static_cast<Graphics*>(graphics)->drawImage( - mMapImage, getPadding(), getTitleBarHeight()); + if (mMapImage->getWidth() > a.width || + mMapImage->getHeight() > a.height) + { + const Vector &pos = player_node->getPosition(); + mapOriginX += (a.width - (int) (pos.x / 32)) / 2; + mapOriginY += (a.height - (int) (pos.y / 32)) / 2; + } + static_cast<Graphics*>(graphics)-> + drawImage(mMapImage, mapOriginX, mapOriginY); } - Beings &beings = beingManager->getAll(); - BeingIterator bi; + const Beings &beings = beingManager->getAll(); + Beings::const_iterator bi; for (bi = beings.begin(); bi != beings.end(); bi++) { - Being *being = (*bi); + const Being *being = (*bi); int dotSize = 2; switch (being->getType()) { @@ -116,8 +118,8 @@ void Minimap::draw(gcn::Graphics *graphics) const Vector &pos = being->getPosition(); graphics->fillRectangle(gcn::Rectangle( - (int) pos.x / 64 + getPadding() - offset, - (int) pos.y / 64 + getTitleBarHeight() - offset, + (int) pos.x / 64 + mapOriginX - offset, + (int) pos.x / 64 + mapOriginY - offset, dotSize, dotSize)); } } diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 424c3558..86e5a8f1 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -32,8 +32,7 @@ #include "../utils/tostring.h" -MiniStatusWindow::MiniStatusWindow(): - Window() +MiniStatusWindow::MiniStatusWindow() { setResizable(false); setMovable(false); diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp deleted file mode 100644 index 20fc01bd..00000000 --- a/src/gui/newskill.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - /* This file implements the new skill dialog for use under the latest - * version of the skill system as of 2005/02/20 - */ - -#include "newskill.h" - -#include <guichan/widgets/label.hpp> - -#include "button.h" -#include "progressbar.h" - -#include "../graphics.h" - -const char *skill_name[] = { - // 0-99 - // weapon skills 0-9 - "Short Blades", "Long Blades", "Hammers", "Archery", "Whip", - "Staves", "Throwing", "Piercing", "Hand to Hand", NULL, - // magic skills 10-19 - "Epyri (Fire)", "Merene (Water)", "Geon (Earth)", "Izurial (Air)", - "Lumine (Light)", "Tenebrae (Dark)", "Chronos (Time)", "Teless (Space)", - "Gen (Mana)", NULL, - // craft skills 20-29 - "Metalworking", "Woodworking", "Jeweler", "Cook", "Tailor", - "Alchemist", "Artisan", "Synthesis", NULL, NULL, - // general skills 30-39 - "Running", "Searching", "Sneak", "Trading", "Intimidate", - "Athletics", NULL, NULL, NULL,NULL, - // combat skills 40-49 - "Dodge", "Accuracy", "Critical", "Block", "Parry", "Diehard", "Magic Aura", - "Counter", NULL, NULL, - // resistance skills 50-59 - "Poison", "Silence", "Petrify", "Paralyze", "Blind", "Slow", "Zombie", - "Critical", NULL, NULL, - // element reistance 60-69 - "Heat (Fire)", "Chill (Water)", "Stone (Earth)", "Wind (Air)", - "Shine (Light)", "Shadow (Dark)", "Decay (Time)", "Chaos (Space)", NULL, - NULL, - // hunting skills 70-79 - "Insects", "Birds", "Lizards", "Amorphs", "Undead", "Machines", "Arcana", - "Humanoids", "Plantoids", NULL, - // stats 80-89 - "Strength", "Fortitude", "Vitality", "Menality", "Awareness", "Mana", - "Dexterity", NULL, NULL, NULL, - // unused (reserved) 90-99 - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; - - -NewSkillDialog::NewSkillDialog(): - Window("Skills") -{ - startPoint = 0; - for (int i = 0; i < N_SKILL_CAT_SIZE; i++) - { - mSkillLabel[i] = new gcn::Label("Empty "); - mSkillLevel[i] = new gcn::Label("00000"); - mSkillbar[i] = new ProgressBar(0.0f,100,15,0,0,255); - mSkillLevel[i]->setAlignment(Graphics::RIGHT); - add(mSkillLabel[i],40,5+i*25); - add(mSkillLevel[i],150,5+i*25); - add(mSkillbar[i],180,5+i*25); - } - // initialize the skills - for (int i = 0; i < N_SKILL; i++) - { - mPlayerSkill[i].level = 0; - mPlayerSkill[i].exp = 0; - } - resetNSD(); - - // create controls - Button *catButton[N_SKILL_CAT]; - catButton[0] = new Button("Weapons", "g1", this); - catButton[1] = new Button("Magic", "g2", this); - catButton[2] = new Button("Craft", "g3", this); - catButton[3] = new Button("General", "g4", this); - catButton[4] = new Button("Combat", "g5", this); - catButton[5] = new Button("E. Resist", "g6", this); - catButton[6] = new Button("S. Resist", "g7", this); - catButton[7] = new Button("Hunting", "g8", this); - catButton[8] = new Button("Stat", "g9", this); - - setContentSize(350, 250); - - for (int i = 0; i < 9; ++i) { - catButton[i]->setDimension(gcn::Rectangle(0, 0, 60, 20)); - catButton[i]->setPosition(290, 20 * i); - add(catButton[i]); - } - - Button *closeButton = new Button("Close", "close", this); - closeButton->setDimension(gcn::Rectangle(0,0,60,20)); - closeButton->setPosition(290, 230); - add(closeButton); - - // finsihing touches - setLocationRelativeTo(getParent()); -} - -void NewSkillDialog::action(const gcn::ActionEvent &event) -{ - int osp = startPoint; - if (event.getId() == "close") - { - setVisible(false); - } - else if (event.getId() == "g1") // weapons group 0-9 - { - startPoint =0; - } - else if (event.getId() == "g2") // magic group 10-19 - { - startPoint =10; - } - else if (event.getId() == "g3") // craft group 20-29 - { - startPoint =20; - } - else if (event.getId() == "g4") // general group 30-39 - { - startPoint =30; - } - else if (event.getId() == "g5") // combat group 40-49 - { - startPoint =40; - } - else if (event.getId() == "g6") // e. resist group 50-59 - { - startPoint =50; - } - else if (event.getId() == "g7") // s resist group 60-69 - { - startPoint =60; - } - else if (event.getId() == "g8") // hunting group 70-79 - { - startPoint =70; - } - else if (event.getId() == "g9") // stats group 80-89 - { - startPoint =80; - } - if (osp != startPoint) - { - resetNSD(); - } -} - -void NewSkillDialog::resetNSD() -{ - for (int a = 0; a < N_SKILL_CAT_SIZE; a++) - { - if (skill_name[a + startPoint]) - { - mSkillLabel[a]->setCaption(skill_name[a + startPoint]); - mSkillLabel[a]->setVisible(true); - char tmp[5]; - sprintf(tmp, "%d", mPlayerSkill[a+startPoint].level); - mSkillLevel[a]->setCaption(tmp); - mSkillLevel[a]->setVisible(true); - mSkillbar[a]->setProgress(0.0f); - mSkillbar[a]->setVisible(true); - } - else - { - mSkillLevel[a]->setVisible(false); - mSkillLabel[a]->setVisible(false); - mSkillbar[a]->setVisible(false); - } - } -} diff --git a/src/gui/newskill.h b/src/gui/newskill.h deleted file mode 100644 index 49476e5e..00000000 --- a/src/gui/newskill.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _TMW_NSKILL_H -#define _TMW_NSKILL_H - -#include <guichan/actionlistener.hpp> - -#include "window.h" - -#include "../guichanfwd.h" - -class ProgressBar; - -#define N_SKILL 100 // skill count constant -#define N_SKILL_CAT 9 // skill category count -#define N_SKILL_CAT_SIZE 10 // skill category maximum size - -struct nSkill { - short level; - short exp; -}; - -/** - * Dialog showing the skills in the planned skill model. - * - * \ingroup Interface - */ -class NewSkillDialog : public Window, public gcn::ActionListener -{ - public: - /** - * Constructor. - */ - NewSkillDialog(); - - // action listener - void action(const gcn::ActionEvent &event); - - private: - void resetNSD(); // updates the values in the dialog box - - // members - int startPoint; // starting point of skill listing - ProgressBar *mSkillbar[N_SKILL_CAT_SIZE]; - gcn::Label *mSkillLabel[N_SKILL_CAT_SIZE]; - gcn::Label *mSkillLevel[N_SKILL_CAT_SIZE]; - nSkill mPlayerSkill[N_SKILL]; // pointer to an array of skill values -}; - -#endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index c593feb1..c9ace303 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -34,10 +34,16 @@ NpcTextDialog::NpcTextDialog(): Window(_("NPC")) { + setResizable(true); + + setMinWidth(200); + setMinHeight(150); + mTextBox = new TextBox; mTextBox->setEditable(false); - gcn::ScrollArea *scrollArea = new ScrollArea(mTextBox); - Button *okButton = new Button(_("Ok"), "ok", this); + + scrollArea = new ScrollArea(mTextBox); + okButton = new Button(_("OK"), "ok", this); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -54,20 +60,36 @@ NpcTextDialog::NpcTextDialog(): setLocationRelativeTo(getParent()); } -void -NpcTextDialog::setText(const std::string &text) +void NpcTextDialog::setText(const std::string &text) +{ + mText = text; + mTextBox->setTextWrapped(mText); +} + +void NpcTextDialog::addText(const std::string &text) { - mTextBox->setTextWrapped(text); + setText(mText + text + "\n"); } -void -NpcTextDialog::addText(const std::string &text) +void NpcTextDialog::widgetResized(const gcn::Event &event) { - mTextBox->setTextWrapped(mTextBox->getText() + text + "\n"); + Window::widgetResized(event); + + const gcn::Rectangle &area = getChildrenArea(); + const int width = area.width; + const int height = area.height; + + scrollArea->setDimension(gcn::Rectangle( + 5, 5, width - 10, height - 15 - okButton->getHeight())); + okButton->setPosition( + width - 5 - okButton->getWidth(), + height - 5 - okButton->getHeight()); + + // Set the text again so that it gets wrapped according to the new size + mTextBox->setTextWrapped(mText); } -void -NpcTextDialog::action(const gcn::ActionEvent &event) +void NpcTextDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 2c9771d3..76161f88 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -45,18 +45,23 @@ class NpcTextDialog : public Window, public gcn::ActionListener NpcTextDialog(); /** + * Called when resizing the window + * + * @param event The calling event + */ + void widgetResized(const gcn::Event &event); + + /** * Called when receiving actions from the widgets. */ - void - action(const gcn::ActionEvent &event); + void action(const gcn::ActionEvent &event); /** * Sets the text shows in the dialog. * * @param string The new text. */ - void - setText(const std::string &string); + void setText(const std::string &string); /** * Adds the text to the text shows in the dialog. Also adds a newline @@ -64,11 +69,14 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @param string The text to add. */ - void - addText(const std::string &string); + void addText(const std::string &string); private: + gcn::Button *okButton; + gcn::ScrollArea *scrollArea; TextBox *mTextBox; + + std::string mText; }; -#endif +#endif // _TMW_NPC_TEXT_H diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 918031b4..c55255ea 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -34,10 +34,15 @@ NpcListDialog::NpcListDialog(): Window(_("NPC")) { + setResizable(true); + + setMinWidth(200); + setMinHeight(150); + mItemList = new ListBox(this); - ScrollArea *scrollArea = new ScrollArea(mItemList); - Button *okButton = new Button(_("Ok"), "ok", this); - Button *cancelButton = new Button(_("Cancel"), "cancel", this); + scrollArea = new ScrollArea(mItemList); + okButton = new Button(_("OK"), "ok", this); + cancelButton = new Button(_("Cancel"), "cancel", this); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -61,31 +66,45 @@ NpcListDialog::NpcListDialog(): setLocationRelativeTo(getParent()); } -int -NpcListDialog::getNumberOfElements() +int NpcListDialog::getNumberOfElements() { return mItems.size(); } -std::string -NpcListDialog::getElementAt(int i) +std::string NpcListDialog::getElementAt(int i) { return mItems[i]; } -void NpcListDialog::addItem(std::string const &item) +void NpcListDialog::addItem(const std::string &item) { mItems.push_back(item); } -void -NpcListDialog::reset() +void NpcListDialog::reset() { mItems.clear(); } -void -NpcListDialog::action(const gcn::ActionEvent &event) +void NpcListDialog::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + + const gcn::Rectangle &area = getChildrenArea(); + const int width = area.width; + const int height = area.height; + + scrollArea->setDimension(gcn::Rectangle( + 5, 5, width - 10, height - 15 - okButton->getHeight())); + cancelButton->setPosition( + width - 5 - cancelButton->getWidth(), + height - 5 - cancelButton->getHeight()); + okButton->setPosition( + cancelButton->getX() - 5 - okButton->getWidth(), + cancelButton->getY()); +} + +void NpcListDialog::action(const gcn::ActionEvent &event) { int choice = 0; diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index e21f9e8c..65281f58 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -49,38 +49,44 @@ class NpcListDialog : public Window, public gcn::ActionListener, NpcListDialog(); /** + * Called when resizing the window + * + * @param event The calling event + */ + void widgetResized(const gcn::Event &event); + + /** * Called when receiving actions from the widgets. */ - void - action(const gcn::ActionEvent &event); + void action(const gcn::ActionEvent &event); /** * Returns the number of items in the choices list. */ - int - getNumberOfElements(); + int getNumberOfElements(); /** * Returns the name of item number i of the choices list. */ - std::string - getElementAt(int i); + std::string getElementAt(int i); /** * Adds an item to the option list. */ - void addItem(std::string const &); + void addItem(const std::string &); /** * Resets the list by removing all items. */ - void - reset(); + void reset(); private: gcn::ListBox *mItemList; + gcn::ScrollArea *scrollArea; + gcn::Button *okButton; + gcn::Button *cancelButton; std::vector<std::string> mItems; }; -#endif +#endif // _TMW_GUI_NPCLISTDIALOG_H diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp index 262e3b2e..c4a1c780 100644 --- a/src/gui/partywindow.cpp +++ b/src/gui/partywindow.cpp @@ -29,6 +29,7 @@ PartyWindow::PartyWindow() : Window(_("Party")) { + setWindowName("Party"); setVisible(false); setResizable(false); setCaption(_("Party")); @@ -37,7 +38,7 @@ PartyWindow::PartyWindow() : Window(_("Party")) setMinHeight(200); setDefaultSize(620, 300, 110, 200); - loadWindowState("Party"); + loadWindowState(); } PartyWindow::~PartyWindow() diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 30e78368..24391458 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -44,6 +44,7 @@ SellDialog::SellDialog(): Window(_("Sell")), mMaxItems(0), mAmountItems(0) { + setWindowName("Sell"); setResizable(true); setMinWidth(260); setMinHeight(230); @@ -90,7 +91,7 @@ SellDialog::SellDialog(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - loadWindowState("Sell"); + loadWindowState(); setLocationRelativeTo(getParent()); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 2a60308b..e062f674 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,6 +43,7 @@ extern Window *helpWindow; extern Window *skillDialog; extern Window *magicDialog; extern Window *guildWindow; +extern Window *itemShortcutWindow; Setup::Setup(): Window(_("Setup")) @@ -117,5 +118,6 @@ void Setup::action(const gcn::ActionEvent &event) skillDialog->resetToDefaultSize(); magicDialog->resetToDefaultSize(); guildWindow->resetToDefaultSize(); + itemShortcutWindow->resetToDefaultSize(); } } diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 51cee8e3..bac342a0 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -106,8 +106,8 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", 1)), mVisibleNamesEnabled(config.getValue("visiblenames", 1)), mOpacity(config.getValue("guialpha", 0.8)), - mFps((int)config.getValue("fpslimit", 60)), - mModeListModel(new ModeListModel()), + mFps((int) config.getValue("fpslimit", 0)), + mModeListModel(new ModeListModel), mModeList(new ListBox(mModeListModel)), mFsCheckBox(new CheckBox(_("Full screen"), mFullScreenEnabled)), mOpenGLCheckBox(new CheckBox(_("OpenGL"), mOpenGLEnabled)), @@ -116,13 +116,13 @@ Setup_Video::Setup_Video(): mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), mFpsSlider(new Slider(10, 200)), - mFpsField(new TextField()), - mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 32)), + mFpsField(new TextField), + mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 16)), mScrollLazinessSlider(new Slider(1, 64)), - mScrollLazinessField(new TextField()), - mOriginalScrollRadius((int) config.getValue("ScrollRadius", 32)), + mScrollLazinessField(new TextField), + mOriginalScrollRadius((int) config.getValue("ScrollRadius", 0)), mScrollRadiusSlider(new Slider(0, 128)), - mScrollRadiusField(new TextField()), + mScrollRadiusField(new TextField), mOverlayDetail((int) config.getValue("OverlayDetail", 2)), mOverlayDetailSlider(new Slider(0, 2)), mOverlayDetailField(new gcn::Label("")) @@ -189,7 +189,7 @@ Setup_Video::Setup_Video(): mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); gcn::Label *scrollRadiusLabel = new gcn::Label(_("Scroll radius")); scrollRadiusLabel->setPosition(90, 140); - mScrollRadiusField->setPosition(180, 140); + mScrollRadiusField->setPosition(mFpsField->getX(), 140); mScrollRadiusField->setWidth(30); mScrollRadiusField->setText(toString(mOriginalScrollRadius)); mScrollRadiusSlider->setValue(mOriginalScrollRadius); @@ -197,7 +197,7 @@ Setup_Video::Setup_Video(): mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 160, 75, 10)); gcn::Label *scrollLazinessLabel = new gcn::Label(_("Scroll laziness")); scrollLazinessLabel->setPosition(90, 160); - mScrollLazinessField->setPosition(180, 160); + mScrollLazinessField->setPosition(mFpsField->getX(), 160); mScrollLazinessField->setWidth(30); mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); mScrollLazinessSlider->setValue(mOriginalScrollLaziness); @@ -253,9 +253,18 @@ void Setup_Video::apply() bool fullscreen = mFsCheckBox->isSelected(); if (fullscreen != (config.getValue("screen", 0) == 1)) { + /* The OpenGL test is only necessary on Windows, since switching + * to/from full screen works fine on Linux. On Windows we'd have to + * reinitialize the OpenGL state and reload all textures. + * + * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode + */ + +#ifdef WIN32 // checks for opengl usage if (!(config.getValue("opengl", 0) == 1)) { +#endif if (!graphics->setFullscreen(fullscreen)) { fullscreen = !fullscreen; @@ -269,10 +278,12 @@ void Setup_Video::apply() logger->error(error.str()); } } +#ifdef WIN32 } else { new OkDialog(_("Switching to full screen"), _("Restart needed for changes to take effect.")); } +#endif config.setValue("screen", fullscreen ? 1 : 0); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 49bacaf0..6d747641 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -43,8 +43,9 @@ SkillDialog::SkillDialog(): Window(_("Skills")) { + setWindowName("Skills"); setCloseButton(true); - setDefaultSize(windowContainer->getWidth() - 255, 25, 275, 425); + setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); TabbedArea *panel = new TabbedArea(); panel->setDimension(gcn::Rectangle(5, 5, 270, 420)); @@ -69,7 +70,7 @@ SkillDialog::SkillDialog(): update(); setLocationRelativeTo(getParent()); - loadWindowState(_("Skills")); + loadWindowState(); } SkillDialog::~SkillDialog() diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 43f81135..283a771b 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -36,11 +36,12 @@ StatusWindow::StatusWindow(LocalPlayer *player): Window(player->getName()), mPlayer(player) { + setWindowName("Status"); setResizable(true); setCloseButton(true); setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 365, 280); - loadWindowState("Status"); + (windowContainer->getHeight() - 255) / 2, 365, 275); + loadWindowState(); // ---------------------- // Status Part diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 38064f48..7d5051c7 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -53,6 +53,7 @@ TradeWindow::TradeWindow(): mPartnerInventory(new Inventory), mStatus(PREPARING) { + setWindowName("Trade"); setResizable(true); setDefaultSize(115, 197, 332, 209); @@ -102,7 +103,7 @@ TradeWindow::TradeWindow(): layout.setColWidth(0, Layout::AUTO_SET); layout.setColWidth(1, Layout::AUTO_SET); - loadWindowState("Trade"); + loadWindowState(); } TradeWindow::~TradeWindow() diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index ff1e600c..997a9b82 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -47,7 +47,7 @@ /** * Calculates the Alder-32 checksum for the given file. */ -unsigned long fadler32(FILE *file) +static unsigned long fadler32(FILE *file) { // Obtain file size fseek(file, 0, SEEK_END); @@ -146,15 +146,9 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, UpdaterWindow::~UpdaterWindow() { if (mThread) - { - SDL_WaitThread(mThread, NULL); - mThread = NULL; - } + SDL_WaitThread(mThread, NULL); - if (mMemoryBuffer) - { - free(mMemoryBuffer); - } + free(mMemoryBuffer); // Remove possibly leftover temporary download ::remove((mUpdatesDir + "/download.temp").c_str()); @@ -169,8 +163,9 @@ void UpdaterWindow::setProgress(float p) void UpdaterWindow::setLabel(const std::string &str) { - mLabel->setCaption(str); - mLabel->adjustSize(); + // Do delayed label text update, since Guichan isn't thread-safe + MutexLocker lock(&mLabelMutex); + mNewLabelCaption = str; } void UpdaterWindow::enable() @@ -315,6 +310,17 @@ int UpdaterWindow::downloadThread(void *ptr) curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15); + struct curl_slist *pHeaders = NULL; + if (uw->mDownloadStatus != UPDATE_RESOURCES) + { + // Make sure the resources2.txt and news.txt aren't cached, + // in order to always get the latest version. + pHeaders = curl_slist_append(pHeaders, "pragma: no-cache"); + pHeaders = + curl_slist_append(pHeaders, "Cache-Control: no-cache"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders); + } + if ((res = curl_easy_perform(curl)) != 0) { uw->mDownloadStatus = UPDATE_ERROR; @@ -339,6 +345,11 @@ int UpdaterWindow::downloadThread(void *ptr) curl_easy_cleanup(curl); + if (uw->mDownloadStatus != UPDATE_RESOURCES) + { + curl_slist_free_all(pHeaders); + } + if (!uw->mStoreInMemory) { // Don't check resources2.txt checksum @@ -413,6 +424,17 @@ void UpdaterWindow::logic() // Update Scroll logic mScrollArea->logic(); + // Synchronize label caption when necessary + { + MutexLocker lock(&mLabelMutex); + + if (mLabel->getCaption() != mNewLabelCaption) + { + mLabel->setCaption(mNewLabelCaption); + mLabel->adjustSize(); + } + } + switch (mDownloadStatus) { case UPDATE_ERROR: @@ -434,7 +456,8 @@ void UpdaterWindow::logic() mBrowserBox->addRow("##1 It is strongly recommended that"); mBrowserBox->addRow("##1 you try again later"); mBrowserBox->addRow(mCurlError); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); + mScrollArea->setVerticalScrollAmount( + mScrollArea->getVerticalMaxScroll()); mDownloadStatus = UPDATE_COMPLETE; break; case UPDATE_NEWS: diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index d7e3c4c7..a7dfe2cb 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -30,12 +30,13 @@ #include "../guichanfwd.h" +#include "../utils/mutex.h" + class BrowserBox; class Button; class ProgressBar; class ScrollArea; -struct SDL_mutex; struct SDL_Thread; /** @@ -88,7 +89,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener int updateState; - protected: +private: void download(); /** @@ -133,6 +134,12 @@ class UpdaterWindow : public Window, public gcn::ActionListener /** The file currently downloading. */ std::string mCurrentFile; + /** The new label caption to be set in the logic method. */ + std::string mNewLabelCaption; + + /** The mutex used to guard access to mNewLabelCaption. */ + Mutex mLabelMutex; + /** The Adler32 checksum of the file currently downloading. */ unsigned long mCurrentChecksum; @@ -164,7 +171,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener Button *mCancelButton; /**< Button to stop the update process. */ Button *mPlayButton; /**< Button to start playing. */ ProgressBar *mProgressBar; /**< Update progress bar. */ - BrowserBox* mBrowserBox; /**< Box to display news. */ + BrowserBox *mBrowserBox; /**< Box to display news. */ ScrollArea *mScrollArea; /**< Used to scroll news box. */ }; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a6092c7a..a746fb03 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -61,8 +61,8 @@ Viewport::Viewport(): setOpaque(false); addMouseListener(this); - mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); - mScrollRadius = (int) config.getValue("ScrollRadius", 32); + mScrollLaziness = (int) config.getValue("ScrollLaziness", 16); + mScrollRadius = (int) config.getValue("ScrollRadius", 0); mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0); mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0); mVisibleNames = config.getValue("visiblenames", 1); diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp index 68ce5243..9fcd00a6 100644 --- a/src/gui/widgets/avatar.cpp +++ b/src/gui/widgets/avatar.cpp @@ -33,23 +33,17 @@ Avatar::Avatar(const std::string &name): mLabel = new gcn::Label(name); mLabel->setSize(85, 12); mLabel->setPosition(25, 0); - mStatusOffline = ResourceManager::getInstance()->getImage("graphics/gui/circle-gray.png"); - mStatusOnline = ResourceManager::getInstance()->getImage("graphics/gui/circle-green.png"); + ResourceManager *resman = ResourceManager::getInstance(); + mStatusOffline = resman->getImage("graphics/gui/circle-gray.png"); + mStatusOnline = resman->getImage("graphics/gui/circle-green.png"); mStatus = new Icon(mStatusOffline); mStatus->setSize(25, 12); mStatus->setPosition(0, 0); } -void Avatar::setOnline(bool status) +void Avatar::setOnline(bool online) { - if (status) - { - mStatus->setImage(mStatusOnline); - } - else - { - mStatus->setImage(mStatusOffline); - } + mStatus->setImage(online ? mStatusOnline : mStatusOffline); } void Avatar::draw(gcn::Graphics *g) diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h index 0f657895..c6151020 100644 --- a/src/gui/widgets/avatar.h +++ b/src/gui/widgets/avatar.h @@ -33,18 +33,18 @@ class Avatar : public gcn::Widget { public: /** - * Constructor + * Constructor. * @param name Character name */ Avatar(const std::string &name); /** - * Set the avatar online status + * Set the avatar online status. */ - void setOnline(bool status); + void setOnline(bool online); /** - * Draws the Avatar + * Draws the avatar. */ void draw(gcn::Graphics *g); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e498236a..582e4a67 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -129,12 +129,13 @@ Window::~Window() { logger->log("UNLOAD: Window::~Window(\"%s\")", getCaption().c_str()); - std::string const &name = mConfigName; + const std::string &name = mWindowName; if (!name.empty()) { // Saving X, Y and Width and Height for resizables in the config config.setValue(name + "WinX", getX()); config.setValue(name + "WinY", getY()); + config.setValue(name + "Visible", isVisible()); if (mGrip) { @@ -179,10 +180,9 @@ void Window::setWindowContainer(WindowContainer *wc) void Window::draw(gcn::Graphics *graphics) { - if(mAlphaChanged) + if (mAlphaChanged) setGuiAlpha(); - Graphics *g = static_cast<Graphics*>(graphics); //g->drawImageRect(0, 0, getWidth(), getHeight(), border); @@ -248,7 +248,7 @@ void Window::setMaxHeight(unsigned int height) void Window::setResizable(bool r) { - if ((bool)mGrip == r) return; + if ((bool) mGrip == r) return; if (r) { @@ -269,7 +269,7 @@ void Window::widgetResized(const gcn::Event &event) { if (mGrip) { - gcn::Rectangle const &area = getChildrenArea(); + const gcn::Rectangle area = getChildrenArea(); mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x, getHeight() - mGrip->getHeight() - area.y); } @@ -467,12 +467,14 @@ void Window::mouseDragged(gcn::MouseEvent &event) } } -void Window::loadWindowState(std::string const &name) +void Window::loadWindowState() { - mConfigName = name; + const std::string &name = mWindowName; + assert(!name.empty()); setPosition((int) config.getValue(name + "WinX", mDefaultX), (int) config.getValue(name + "WinY", mDefaultY)); + setVisible((bool) config.getValue(name + "Visible", false)); if (mGrip) { @@ -497,7 +499,7 @@ void Window::setDefaultSize(int defaultX, int defaultY, void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); - setContentSize(mDefaultWidth, mDefaultHeight); + setSize(mDefaultWidth, mDefaultHeight); } int Window::getResizeHandles(gcn::MouseEvent &event) diff --git a/src/gui/window.h b/src/gui/window.h index 22355572..6f49e062 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -153,8 +153,7 @@ class Window : public gcn::Window, gcn::WidgetListener * * @return The parent window or <code>NULL</code> if there is none. */ - Window* - getParentWindow() { return mParent; } + Window *getParentWindow() { return mParent; } /** * Schedule this window for deletion. It will be deleted at the start @@ -192,13 +191,23 @@ class Window : public gcn::Window, gcn::WidgetListener void mouseExited(gcn::MouseEvent &event); /** + * Sets the name of the window. This is not the window title. + */ + void setWindowName(const std::string &name) { mWindowName = name; } + + /** + * Returns the name of the window. This is not the window title. + */ + const std::string &getWindowName() { return mWindowName; } + + /** * Reads the position (and the size for resizable windows) in the * configuration based on the given string. * Uses the default values when config values are missing. * Don't forget to set these default values and resizable before * calling this function. */ - void loadWindowState(std::string const &); + void loadWindowState(); /** * Set the default win pos and size. @@ -267,7 +276,7 @@ class Window : public gcn::Window, gcn::WidgetListener ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ Layout *mLayout; /**< Layout handler */ - std::string mConfigName; /**< Name used for saving window-related data */ + std::string mWindowName; /**< Name of the window */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ bool mCloseButton; /**< Window has a close button */ |