diff options
author | Ira Rice <irarice@gmail.com> | 2008-09-25 00:15:44 +0000 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2008-09-25 00:15:44 +0000 |
commit | 489a429bea6739dfa25503b9329bd9e33bffb856 (patch) | |
tree | 8112f6fd988fdc0610329b6bc14ee3f9d5801092 /src/gui | |
parent | 2dc8eadff1e67bb70b1772ecc19c9e1e2e40a5b4 (diff) | |
download | mana-489a429bea6739dfa25503b9329bd9e33bffb856.tar.gz mana-489a429bea6739dfa25503b9329bd9e33bffb856.tar.bz2 mana-489a429bea6739dfa25503b9329bd9e33bffb856.tar.xz mana-489a429bea6739dfa25503b9329bd9e33bffb856.zip |
Merged the Tametomo branch into trunk.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/setup.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 22 | ||||
-rw-r--r-- | src/gui/shop.cpp | 4 | ||||
-rw-r--r-- | src/gui/skill.cpp | 4 | ||||
-rw-r--r-- | src/gui/textbox.cpp | 12 | ||||
-rw-r--r-- | src/gui/textbox.h | 13 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 143 | ||||
-rw-r--r-- | src/gui/viewport.h | 25 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 2 | ||||
-rw-r--r-- | src/gui/window.cpp | 246 | ||||
-rw-r--r-- | src/gui/window.h | 14 | ||||
-rw-r--r-- | src/gui/windowcontainer.cpp | 4 |
13 files changed, 336 insertions, 157 deletions
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 9c562b68..8ec3bfd8 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -102,7 +102,7 @@ Setup::Setup(): Setup::~Setup() { - for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); + delete_all(mTabs); } void Setup::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 0e85138c..dd56ee2f 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -280,15 +280,17 @@ void Setup_Video::apply() bool fullscreen = mFsCheckBox->isSelected(); if (fullscreen != (config.getValue("screen", 0) == 1)) { + + /* Commented out the openGL test because + * the fullscreen mode change works fine, but + * will need to test it on windows so not + * deleting entirely until then --kraant*/ - /*Commented out the openGL test because - * the fullscreen mode change works fine, but - * will need to test it on windows so not - * deleting entirely until then --kraant*/ - +#ifdef WIN32 // checks for opengl usage - /*if (!(config.getValue("opengl", 0) == 1)) - {*/ + if (!(config.getValue("opengl", 0) == 1)) + { +#endif if (!graphics->setFullscreen(fullscreen)) { fullscreen = !fullscreen; @@ -302,10 +304,12 @@ void Setup_Video::apply() logger->error(error.str()); } } - /*} else { +#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/shop.cpp b/src/gui/shop.cpp index 015e70d5..e7619547 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -25,8 +25,6 @@ #include "../utils/dtor.h" -#include <algorithm> - ShopItems::~ShopItems() { clear(); @@ -61,7 +59,7 @@ ShopItem* ShopItems::at(int i) const void ShopItems::clear() { - std::for_each(mShopItems.begin(), mShopItems.end(), make_dtor(mShopItems)); + delete_all(mShopItems); mShopItems.clear(); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index e70fb3ef..8cf1e06d 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -21,8 +21,6 @@ * $Id: skill.cpp 3754 2007-11-20 15:19:50Z b_lindeijer $ */ -#include <algorithm> - #include <guichan/widgets/label.hpp> #include "skill.h" @@ -186,6 +184,6 @@ void SkillDialog::setSkill(int id, int lvl, int mp) void SkillDialog::cleanList() { - for_each(mSkillList.begin(), mSkillList.end(), make_dtor(mSkillList)); + delete_all(mSkillList); mSkillList.clear(); } diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 743d88b6..4976549f 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -60,6 +60,8 @@ void TextBox::setTextWrapped(const std::string &text) text.substr(lastNewlinePos, newlinePos - lastNewlinePos); std::string::size_type spacePos, lastSpacePos = 0; int xpos = 0; + mMinWidth = getWidth(); + bool longWord = false; do { @@ -75,22 +77,28 @@ void TextBox::setTextWrapped(const std::string &text) int width = getFont()->getWidth(word); - if (xpos != 0 && xpos + width < getWidth()) + if (xpos != 0 && xpos + width + getFont()->getWidth(" ") < getWidth()) { xpos += width + getFont()->getWidth(" "); wrappedStream << " " << word; } else if (lastSpacePos == 0) { + if (xpos > mMinWidth) + { + longWord = true; + mMinWidth = xpos; + } xpos += width; wrappedStream << word; } else { + if ((xpos < mMinWidth) && !longWord && spacePos != line.size()) + mMinWidth = xpos; xpos = width; wrappedStream << "\n" << word; } - lastSpacePos = spacePos + 1; } while (spacePos != line.size()); diff --git a/src/gui/textbox.h b/src/gui/textbox.h index 7df30fd9..09819360 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -44,6 +44,19 @@ class TextBox : public gcn::TextBox { * Sets the text after wrapping it to the current width of the widget. */ void setTextWrapped(const std::string &text); + + /** + * Get the minimum text width for the text box. + */ + int getMinWidth() { return mMinWidth; } + + /** + * Set the minimum text width for the text box. + */ + void setMinWidth(int width) { mMinWidth = width; } + + private: + int mMinWidth; }; #endif diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 22e361c5..b052e4b6 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -115,7 +115,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mBrowserBox = new BrowserBox(); mScrollArea = new ScrollArea(mBrowserBox); mLabel = new gcn::Label("Connecting..."); - mProgressBar = new ProgressBar(0.0, w - 10, 20, 37, 70, 200); + mProgressBar = new ProgressBar(0.0, w - 10, 20, 168, 116, 31); mCancelButton = new Button("Cancel", "cancel", this); mPlayButton = new Button("Play", "play", this); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 568c1ea3..95e0d2b6 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -33,6 +33,7 @@ #include "../configuration.h" #include "../flooritemmanager.h" #include "../graphics.h" +#include "../keyboardconfig.h" #include "../localplayer.h" #include "../map.h" #include "../monster.h" @@ -49,6 +50,8 @@ #include <cassert> +extern volatile int tick_time; + Viewport::Viewport(): mMap(0), mPixelViewX(0.0f), @@ -112,7 +115,8 @@ Viewport::loadTargetCursor(std::string filename, int width, int height, mOutRangeImages[size] = currentImageSet; mTargetCursorOutRange[size] = currentCursor; } - else { + else + { mInRangeImages[size] = currentImageSet; mTargetCursorInRange[size] = currentCursor; } @@ -223,52 +227,46 @@ Viewport::draw(gcn::Graphics *gcnGraphics) // Draw tiles and sprites if (mMap) { - mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY, 0); - drawTargetCursor(graphics); - mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY, 1); - mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY, 2); - mMap->drawOverlay(graphics, mPixelViewX, mPixelViewY, - (int) config.getValue("OverlayDetail", 2)); - } + mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); + drawTargetCursor(graphics); // TODO: Draw the cursor with the sprite - // Find a path from the player to the mouse, and draw it. This is for debug - // purposes. - if (mShowDebugPath && mMap) - { - // Get the current mouse position - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = mouseX / 32 + mTileViewX; - int mouseTileY = mouseY / 32 + mTileViewY; + // Find a path from the player to the mouse, and draw it. This is for debug + // purposes. + if (mShowDebugPath) + { + // Get the current mouse position + int mouseX, mouseY; + SDL_GetMouseState(&mouseX, &mouseY); - Path debugPath = mMap->findPath( - player_node->mX, player_node->mY, - mouseTileX, mouseTileY); + int mouseTileX = mouseX / 32 + mTileViewX; + int mouseTileY = mouseY / 32 + mTileViewY; - graphics->setColor(gcn::Color(255, 0, 0)); - for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) - { - int squareX = i->x * 32 - (int) mPixelViewX + 12; - int squareY = i->y * 32 - (int) mPixelViewY + 12; + Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY); - graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); - graphics->drawText( - toString(mMap->getMetaTile(i->x, i->y)->Gcost), - squareX + 4, squareY + 12, gcn::Graphics::CENTER); + graphics->setColor(gcn::Color(255, 0, 0)); + for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) + { + int squareX = i->x * 32 - (int) mPixelViewX + 12; + int squareY = i->y * 32 - (int) mPixelViewY + 12; + + graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); + graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), squareX + 4, squareY + 12, gcn::Graphics::CENTER); + } } } - // Draw text + // Draw names if (textManager) { textManager->draw(graphics, mPixelViewX, mPixelViewY); } - // Draw player nickname, speech, and emotion sprite as needed + // Draw player speech, and emotion sprite as needed Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) { + (*i)->drawSpeech(graphics, -(int) mPixelViewX, -(int) mPixelViewY); (*i)->drawEmotion(graphics, -(int) mPixelViewX, -(int) mPixelViewY); } @@ -276,8 +274,7 @@ Viewport::draw(gcn::Graphics *gcnGraphics) WindowContainer::draw(gcnGraphics); } -void -Viewport::logic() +void Viewport::logic() { WindowContainer::logic(); @@ -295,15 +292,14 @@ Viewport::logic() mWalkTime = player_node->mWalkTime; } - for (int i = 0; i < 3; i++) + for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++) { mTargetCursorInRange[i]->update(10); mTargetCursorOutRange[i]->update(10); } } -void -Viewport::drawTargetCursor(Graphics *graphics) +void Viewport::drawTargetCursor(Graphics *graphics) { // Draw target marker if needed Being *target = player_node->getTarget(); @@ -323,7 +319,8 @@ Viewport::drawTargetCursor(Graphics *graphics) { targetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage(); } - else { + else + { targetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage(); } @@ -332,11 +329,10 @@ Viewport::drawTargetCursor(Graphics *graphics) int posY = target->getPixelY() + 16 - targetCursor->getHeight() / 2 - (int) mPixelViewY; graphics->drawImage(targetCursor, posX, posY); - } + } } -void -Viewport::mousePressed(gcn::MouseEvent &event) +void Viewport::mousePressed(gcn::MouseEvent &event) { // Check if we are alive and kickin' if (!mMap || !player_node || player_node->mAction == Being::DEAD) @@ -348,8 +344,10 @@ Viewport::mousePressed(gcn::MouseEvent &event) mPlayerFollowMouse = false; - int tilex = event.getX() / 32 + mTileViewX; - int tiley = event.getY() / 32 + mTileViewY; + const int tilex = event.getX() / 32 + mTileViewX; + const int tiley = event.getY() / 32 + mTileViewY; + const int x = (int)((float) event.getX() + mPixelViewX); + const int y = (int)((float) event.getY() + mPixelViewY); // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) @@ -357,11 +355,11 @@ Viewport::mousePressed(gcn::MouseEvent &event) Being *being; FloorItem *floorItem; - if ((being = beingManager->findBeing(tilex, tiley)) && - being != player_node) + if ((being = beingManager->findBeingByPixel(x, y)) && + being != player_node) { - mPopupMenu->showPopup(event.getX(), event.getY(), being); - return; + mPopupMenu->showPopup(event.getX(), event.getY(), being); + return; } else if((floorItem = floorItemManager->findByCoordinates(tilex, tiley))) { @@ -382,12 +380,10 @@ Viewport::mousePressed(gcn::MouseEvent &event) { Being *being; FloorItem *item; - + // Interact with some being -// int x = (int)((float) event.getX() + mPixelViewX); -// int y = (int)((float) event.getY() + mPixelViewY); -// if ((being = beingManager->findBeingByPixel(x, y))) - if ((being = beingManager->findBeing(tilex, tiley))) +// if ((being = beingManager->findBeing(tilex, tiley))) + if ((being = beingManager->findBeingByPixel(x, y))) { switch (being->getType()) { @@ -400,59 +396,49 @@ Viewport::mousePressed(gcn::MouseEvent &event) if (being->mAction == Being::DEAD) break; - if (player_node->withinAttackRange(being)) + if (keyboard.isKeyActive(keyboard.KEY_TARGET) || player_node->withinAttackRange(being)) { + player_node->stopAttack(); + player_node->setGotoTarget(being); player_node->attack(being, true); } else { - Uint8 *keys = SDL_GetKeyState(NULL); - if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) - { - player_node->stopAttack(); - player_node->setGotoTarget(being); - } + player_node->setDestination(tilex, tiley); + player_node->stopAttack(); } break; default: break; - } + } } // Pick up some item else if ((item = floorItemManager->findByCoordinates(tilex, tiley))) { - player_node->pickUp(item); + player_node->pickUp(item); } // Just walk around else { - // XXX XXX XXX REALLY UGLY! - Uint8 *keys = SDL_GetKeyState(NULL); - if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) - { - player_node->setDestination(tilex, tiley); - player_node->stopAttack(); - } + player_node->stopAttack(); + player_node->setDestination(tilex, tiley); mPlayerFollowMouse = true; } } else if (event.getButton() == gcn::MouseEvent::MIDDLE) { // Find the being nearest to the clicked position - Being *target = beingManager->findNearestLivingBeing( - tilex, tiley, - 20, Being::MONSTER); - + Being *target = beingManager->findBeingByPixel(x, y); + if (target) { - player_node->setTarget(target); + player_node->setTarget(target); } } } -void -Viewport::mouseDragged(gcn::MouseEvent &event) +void Viewport::mouseDragged(gcn::MouseEvent &event) { if (!mMap || !player_node) return; @@ -465,20 +451,17 @@ Viewport::mouseDragged(gcn::MouseEvent &event) } } -void -Viewport::mouseReleased(gcn::MouseEvent &event) +void Viewport::mouseReleased(gcn::MouseEvent &event) { mPlayerFollowMouse = false; } -void -Viewport::showPopup(int x, int y, Item *item) +void Viewport::showPopup(int x, int y, Item *item) { mPopupMenu->showPopup(x, y, item); } -void -Viewport::optionChanged(const std::string &name) +void Viewport::optionChanged(const std::string &name) { mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); mScrollRadius = (int) config.getValue("ScrollRadius", 32); diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 44a877a6..325a7221 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -18,7 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: viewport.h 4247 2008-05-19 10:48:18Z b_lindeijer $ + * $Id$ */ #ifndef _TMW_VIEWPORT_H_ @@ -117,16 +117,16 @@ class Viewport : public WindowContainer, public gcn::MouseListener, optionChanged(const std::string &name); /** - * Returns camera x offset in tiles. + * Returns camera x offset in pixels. */ int - getCameraX() { return mTileViewX; } + getCameraX() const { return (int) mPixelViewX; } /** - * Returns camera y offset in tiles. + * Returns camera y offset in pixels. */ int - getCameraY() { return mTileViewY; } + getCameraY() const { return (int) mPixelViewY; } /** * Changes viewpoint by relative pixel coordinates. @@ -138,22 +138,13 @@ class Viewport : public WindowContainer, public gcn::MouseListener, /** * Helper function for loading target cursors */ - void - loadTargetCursor(std::string filename, int width, int height, - bool outRange, Being::TargetCursorSize size); + void loadTargetCursor(std::string filename, int width, int height, + bool outRange, Being::TargetCursorSize size); /** * Draws range based target cursor */ - void - drawTargetCursor(Graphics *graphics); - - /** - * Draws target name - */ - void - drawTargetName(Graphics *graphics); - + void drawTargetCursor(Graphics *graphics); Map *mMap; /**< The current map. */ diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index b33a55cf..9bf7452d 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -165,5 +165,5 @@ void DropDown::drawButton(gcn::Graphics *graphics) int height = mDroppedDown ? mFoldedUpHeight : getHeight(); static_cast<Graphics*>(graphics)-> - drawImage(buttons[mDroppedDown][mPushed], getWidth() - height, 1); + drawImage(buttons[mDroppedDown][mPushed], getWidth() - height + 2, 1); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 55dac5e0..1a6f1ac6 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -18,11 +18,12 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: window.cpp 4207 2008-04-29 09:10:43Z b_lindeijer $ + * $Id$ */ #include <algorithm> #include <climits> +#include <cassert> #include <guichan/exception.hpp> #include <guichan/widgets/icon.hpp> @@ -43,24 +44,28 @@ #include "../resources/image.h" #include "../resources/resourcemanager.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; class WindowConfigListener : public ConfigListener { void optionChanged(const std::string &) { + Window::mAlphaChanged = true; for_each(Window::border.grid, Window::border.grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); } }; -Window::Window(const std::string& caption, bool modal, Window *parent): +Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), mParent(parent), @@ -72,7 +77,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX) + mMaxWinHeight(INT_MAX), + mSkin(skin) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -80,23 +86,13 @@ Window::Window(const std::string& caption, bool modal, Window *parent): throw GCN_EXCEPTION("Window::Window. no windowContainer set"); } + // Loads the skin + loadSkin(mSkin); + + setGuiAlpha(); + if (instances == 0) { - // Load static resources - ResourceManager *resman = ResourceManager::getInstance(); - Image *dBorders = resman->getImage("graphics/gui/vscroll_grey.png"); - border.grid[0] = dBorders->getSubImage(0, 0, 4, 4); - border.grid[1] = dBorders->getSubImage(4, 0, 3, 4); - border.grid[2] = dBorders->getSubImage(7, 0, 4, 4); - border.grid[3] = dBorders->getSubImage(0, 4, 4, 10); - border.grid[4] = resman->getImage("graphics/gui/bg_quad_dis.png"); - border.grid[5] = dBorders->getSubImage(7, 4, 4, 10); - border.grid[6] = dBorders->getSubImage(0, 15, 4, 4); - border.grid[7] = dBorders->getSubImage(4, 15, 3, 4); - border.grid[8] = dBorders->getSubImage(7, 15, 4, 4); - dBorders->decRef(); - closeImage = resman->getImage("graphics/gui/close_button.png"); - windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization windowConfigListener->optionChanged("guialpha"); @@ -135,14 +131,15 @@ Window::~Window() const std::string &name = mWindowName; // 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) - { - config.setValue(name + "WinWidth", getWidth()); - config.setValue(name + "WinHeight", getHeight()); + 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()); + } } instances--; @@ -154,15 +151,11 @@ Window::~Window() windowConfigListener = NULL; // Clean up static resources - delete border.grid[0]; - delete border.grid[1]; - delete border.grid[2]; - delete border.grid[3]; - border.grid[4]->decRef(); - delete border.grid[5]; - delete border.grid[6]; - delete border.grid[7]; - delete border.grid[8]; + for( int i = 0; i < 9; i++ ) + { + delete border.grid[i]; + border.grid[i] = NULL; + } closeImage->decRef(); } @@ -474,6 +467,7 @@ void Window::loadWindowState() { const std::string &name = mWindowName; + assert(!name.empty()); setPosition((int) config.getValue(name + "WinX", mDefaultX), (int) config.getValue(name + "WinY", mDefaultY)); @@ -536,3 +530,185 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } + +void Window::setGuiAlpha() +{ + //logger->log("Window::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); + for(int i = 0; i < 9; i++) + { + //logger->log("Window::setGuiAlpha: Border Image (%i)", i); + border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + } + + mAlphaChanged = false; +} + +void Window::loadSkin(const std::string filename) +{ + const std::string windowId = Window::getId(); + + ResourceManager *resman = ResourceManager::getInstance(); + + logger->log("Loading Window Skin '%s'.", filename.c_str()); + logger->log("Loading Window ID '%s'.", windowId.c_str()); + + + if(filename == "") + 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 != "") + { + logger->log("Window::loadSkin(): <skinset> defines '%s' as a skin image.", skinSetImage.c_str()); + dBorders = resman->getImage("graphics/gui/" + skinSetImage);//"graphics/gui/speech_bubble.png"); + } + else + { + logger->error("Window::loadSkin(): Skinset does not define an image!"); + } + + //iterate <widget>'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 <part>'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 + 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); + + 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. + 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. + closeImage = resman->getImage("graphics/gui/close_button.png"); +} + diff --git a/src/gui/window.h b/src/gui/window.h index 8f288991..228cc37b 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -18,7 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: window.h 4207 2008-04-29 09:10:43Z b_lindeijer $ + * $Id$ */ #ifndef _TMW_WINDOW_H__ @@ -56,9 +56,10 @@ class Window : public gcn::Window, gcn::WidgetListener * @param parent The parent window. This is the window standing above * this one in the window hiearchy. When reordering, * a window will never go below its parent window. + * @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); + Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); /** * Destructor. @@ -237,6 +238,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void resetToDefaultSize(); + /** + * Loads a window skin + */ + void loadSkin(const std::string filename); + enum ResizeHandles { TOP = 0x01, @@ -255,6 +261,8 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); + void setGuiAlpha(); + GCContainer *mChrome; /**< Contained container */ ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ @@ -263,6 +271,7 @@ class Window : public gcn::Window, gcn::WidgetListener bool mModal; /**< Window is modal */ bool mCloseButton; /**< Window has a close button */ bool mSticky; /**< Window resists minimization */ + static bool mAlphaChanged; /**< Whether the alpha percent was changed */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ @@ -271,6 +280,7 @@ 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 window container windows add themselves to. */ static WindowContainer *windowContainer; diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 0a0a0a55..05c2b5e9 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -21,15 +21,13 @@ * $Id: windowcontainer.cpp 3754 2007-11-20 15:19:50Z b_lindeijer $ */ -#include <algorithm> - #include "windowcontainer.h" #include "../utils/dtor.h" void WindowContainer::logic() { - for_each(mDeathList.begin(), mDeathList.end(), make_dtor(mDeathList)); + delete_all(mDeathList); mDeathList.clear(); gcn::Container::logic(); |