diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-07-16 19:26:59 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-07-16 19:26:59 +0000 |
commit | a6db4d8004da5ad985a5ff26c0c01976a5618449 (patch) | |
tree | 5ed3dea6a28222de87840a4d1966338098123993 | |
parent | f4aedad02e8994f89a4137d175dba2666a7005bc (diff) | |
download | Mana-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.gz Mana-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.bz2 Mana-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.xz Mana-a6db4d8004da5ad985a5ff26c0c01976a5618449.zip |
Updated changelog, got rid of remaining extern SDL_Surface *screen cases,
fixed double free and cleaned up a bit.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/engine.cpp | 26 | ||||
-rw-r--r-- | src/graphics.cpp | 22 | ||||
-rw-r--r-- | src/graphics.h | 12 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 26 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 9 | ||||
-rw-r--r-- | src/gui/setup.cpp | 11 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 50 | ||||
-rw-r--r-- | src/gui/updatewindow.h | 16 | ||||
-rw-r--r-- | src/gui/window.cpp | 16 | ||||
-rw-r--r-- | src/main.cpp | 9 | ||||
-rw-r--r-- | src/main.h | 1 |
12 files changed, 101 insertions, 105 deletions
@@ -1,3 +1,11 @@ +0.0.15 (31 July 2005) +- Added dynamic updating of client data +- Added much better font for chat and names +- Added option not to use the custom mouse cursor +- Added joystick support +- Improved mouse attack by not walking while pressing shift +- Fixed items being shown as equipped in inventory although they are not + 0.0.14.1 (7 July 2005) - Fixed two map files not included in the source release diff --git a/src/engine.cpp b/src/engine.cpp index 91c1eb3a..8992dfc8 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -50,9 +50,6 @@ #include "resources/resourcemanager.h" #include "resources/itemmanager.h" -// TODO Check if we can get rid of this -extern SDL_Surface *screen; - extern Being* autoTarget; extern Graphics* graphics; @@ -183,23 +180,26 @@ Engine::Engine(): popupMenu = new PopupMenu(); // Initialize window posisitons - chatWindow->setPosition(0, screen->h - chatWindow->getHeight()); - statusWindow->setPosition(screen->w - statusWindow->getWidth() - 5, 5); - inventoryWindow->setPosition(screen->w - statusWindow->getWidth() - + int screenW = guiGraphics->getWidth(); + int screenH = guiGraphics->getHeight(); + + chatWindow->setPosition(0, screenH - chatWindow->getHeight()); + statusWindow->setPosition(screenW - statusWindow->getWidth() - 5, 5); + inventoryWindow->setPosition(screenW - statusWindow->getWidth() - inventoryWindow->getWidth() - 10, 5); statsWindow->setPosition( - screen->w - 5 - statsWindow->getWidth(), + screenW - 5 - statsWindow->getWidth(), statusWindow->getHeight() + 20); chargeDialog->setPosition( - screen->w - 5 - chargeDialog->getWidth(), - screen->h - chargeDialog->getHeight() - 15); - tradeWindow->setPosition(screen->w - statusWindow->getWidth() - + screenW - 5 - chargeDialog->getWidth(), + screenH - chargeDialog->getHeight() - 15); + tradeWindow->setPosition(screenW - statusWindow->getWidth() - tradeWindow->getWidth() - 10, inventoryWindow->getY() + inventoryWindow->getHeight()); /*buddyWindow->setPosition(10, minimap->getHeight() + 30);*/ equipmentWindow->setPosition(5,140); - + // Set initial window visibility chatWindow->setVisible(true); statusWindow->setVisible(true); @@ -398,7 +398,7 @@ void Engine::draw() sx * 32 - 8 - offset_x, sy * 32 - 52 - offset_y); } - + // Draw a player else if (being->isPlayer()) { @@ -442,7 +442,7 @@ void Engine::draw() sx * 32 + 5 + get_x_offset(being) - offset_x, sy * 32 - 65 + get_y_offset(being) - offset_y); } - + graphics->setFont(speechFont); graphics->drawText(being->name, being->text_x + 15, being->text_y + 30, diff --git a/src/graphics.cpp b/src/graphics.cpp index 9f8981e3..2ebbc146 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -28,10 +28,9 @@ extern volatile int framesToDraw; -SDL_Surface *screen; - -Graphics::Graphics() +Graphics::Graphics(SDL_Surface *screen): + mScreen(screen) { if (useOpenGL) { #ifdef USE_OPENGL @@ -48,7 +47,7 @@ Graphics::Graphics() } else { #ifndef USE_OPENGL - setTarget(SDL_GetVideoSurface()); + setTarget(mScreen); #endif } @@ -64,17 +63,17 @@ Graphics::~Graphics() int Graphics::getWidth() { - return screen->w; + return mScreen->w; } int Graphics::getHeight() { - return screen->h; + return mScreen->h; } void Graphics::drawImage(Image *image, int x, int y) { - image->draw_deprecated(screen, x, y); + image->draw_deprecated(mScreen, x, y); } void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) @@ -90,7 +89,7 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) while (px < w) { int dw = (px + iw >= w) ? w - px : iw; int dh = (py + ih >= h) ? h - py : ih; - image->draw_deprecated(screen, 0, 0, x + px, y + py, dw, dh); + image->draw_deprecated(mScreen, 0, 0, x + px, y + py, dw, dh); px += iw; } py += ih; @@ -159,7 +158,7 @@ void Graphics::updateScreen() #endif } else { - SDL_Flip(screen); + SDL_Flip(mScreen); } // Decrement frame counter when using framerate limiting @@ -171,3 +170,8 @@ void Graphics::updateScreen() SDL_Delay(10); } } + +void Graphics::setScreen(SDL_Surface *screen) +{ + mScreen = screen; +} diff --git a/src/graphics.h b/src/graphics.h index 662fc83c..26b83692 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -65,7 +65,7 @@ class Graphics : public gcn::SDLGraphics { /** * Constructor. */ - Graphics(); + Graphics(SDL_Surface *screen); /** * Destructor. @@ -110,6 +110,16 @@ class Graphics : public gcn::SDLGraphics { * Returns the height of the screen. */ int getHeight(); + + /** + * Sets a new screen pointer. This is necessary after switching screen + * modes, which probably should happen by this class instead of in the + * setup window. + */ + void setScreen(SDL_Surface *screen); + + private: + SDL_Surface *mScreen; }; #endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index ea8034d8..dbaa1e70 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -22,6 +22,7 @@ */ #include "popupmenu.h" +#include "gui.h" #include "../graphics.h" #include "../game.h" #include "../engine.h" @@ -29,9 +30,6 @@ #include "../resources/itemmanager.h" #include <iostream> -// TODO Remove this once setVisible doesn't need it anymore -extern SDL_Surface *screen; - PopupMenu::PopupMenu(): Window() { @@ -58,20 +56,6 @@ PopupMenu::~PopupMenu() delete floorItem; } -void PopupMenu::setVisible(bool visible) -{ - if (visible == false) - { - if (hasFocus()) - { - mFocusHandler->focusNone(); - } - setPosition(screen->w, screen->h); - } - - mVisible = visible; -} - void PopupMenu::showPopup(int mx, int my) { being = findNode(mx, my); @@ -108,7 +92,7 @@ void PopupMenu::showPopup(int mx, int my) // If there is nothing of interest, don't display menu. return; } - + //browserBox->addRow("@@look|Look To@@"); browserBox->addRow("##3---"); browserBox->addRow("@@cancel|Cancel@@"); @@ -116,9 +100,9 @@ void PopupMenu::showPopup(int mx, int my) setContentSize(browserBox->getWidth() + 8, browserBox->getHeight() + 8); mx = (mx - camera_x) * 32 + 25; my = (my - camera_y) * 32 + 25; - if (screen->w < (mx + getWidth() + 5)) + if (guiGraphics->getWidth() < (mx + getWidth() + 5)) mx -= (getWidth() + 50); - if (screen->h < (my + getHeight() + 5)) + if (guiGraphics->getHeight() < (my + getHeight() + 5)) my -= (getHeight() + 50); setPosition(mx, my); setVisible(true); @@ -149,7 +133,7 @@ void PopupMenu::handleLink(const std::string& link) else if (link == "follow") { }*/ - + /* // Add Buddy action else if ((link == "buddy") && being && being->isPlayer()) diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index bb68852b..cfafc739 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -48,11 +48,6 @@ class PopupMenu : public Window, public LinkHandler ~PopupMenu(); /** - * Sets the visibility of popup - */ - void setVisible(bool visible); - - /** * Shows the related popup menu specifies by the mouse click coords. */ void showPopup(int mx, int my); @@ -61,11 +56,11 @@ class PopupMenu : public Window, public LinkHandler * Handles link action. */ void handleLink(const std::string& link); - + private: BrowserBox* browserBox; int mX, mY; - + Being* being; FloorItem* floorItem; }; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index eb9121bc..cda9ae31 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -22,6 +22,7 @@ */ #include "setup.h" +#include "gui.h" #include "button.h" #include "checkbox.h" #include "scrollarea.h" @@ -34,8 +35,6 @@ #define SETUP_WIDTH 240 -extern SDL_Surface *screen; - ModeListModel::ModeListModel() { SDL_Rect **modes; @@ -236,14 +235,18 @@ void Setup::action(const std::string &eventId) //displayFlags |= SDL_OPENGL; //SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } - - screen = SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags); + + SDL_Surface *screen = + SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags); + if (screen == NULL) { std::cerr << "Couldn't set " << screenW << "x" << screenH << "x" << bitDepth << " video mode: " << SDL_GetError() << std::endl; exit(1); } + + guiGraphics->setScreen(screen); } // Sound settings diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 66839451..64f99dd0 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -43,15 +43,15 @@ std::string basePath = ""; bool memoryTransfer = true; int downloadedBytes = 0; char *memoryBuffer = NULL; -int fileIndex = 0; +unsigned int fileIndex = 0; -UpdaterWindow::UpdaterWindow() - : Window("Updating...") +UpdaterWindow::UpdaterWindow(): + Window("Updating...") { int h = 300; int w = 320; setContentSize(w, h); - + browserBox = new BrowserBox(); browserBox->setOpaque(false); scrollArea = new ScrollArea(browserBox); @@ -69,13 +69,13 @@ UpdaterWindow::UpdaterWindow() playButton->setEventId("play"); playButton->setEnabled(false); playButton->addActionListener(this); - + add(scrollArea); add(label); add(progressBar); add(cancelButton); add(playButton); - + cancelButton->requestFocus(); setLocationRelativeTo(getParent()); } @@ -105,11 +105,6 @@ void UpdaterWindow::enable() playButton->requestFocus(); } -void UpdaterWindow::draw(gcn::Graphics *graphics) -{ - Window::draw(graphics); -} - void UpdaterWindow::action(const std::string& eventId) { if (eventId == "cancel") { @@ -141,7 +136,7 @@ void UpdaterWindow::loadNews() // Reallocate and include terminating 0 character fileContents = (char*)realloc(fileContents, contentsLength + 1); fileContents[contentsLength] = '\0'; - + browserBox->clearRows(); // Tokenize and add each line separately @@ -152,16 +147,16 @@ void UpdaterWindow::loadNews() line = strtok(NULL, "\n"); } - free(fileContents); + //free(fileContents); scrollArea->setVerticalScrollAmount(0); setVisible(true); } -void UpdaterWindow::setText(std::string row) { +void UpdaterWindow::addRow(const std::string &row) +{ browserBox->addRow(row); - scrollArea->setVerticalScrollAmount( - scrollArea->getVerticalMaxScroll()); + scrollArea->setVerticalScrollAmount(scrollArea->getVerticalMaxScroll()); } int updateProgress(void *ptr, double dt, double dn, double ut, double un) @@ -259,7 +254,8 @@ void download() } } -void checkFile(std::ifstream &in) { +void checkFile(std::ifstream &in) +{ // Check for XML tag (if it is XML tag it is error) // WARNING: this way we can't use an XML file for resources listing if (!in.eof()) @@ -284,13 +280,13 @@ void updateData() updaterWindow = new UpdaterWindow(); state = UPDATE; - + updateHost = config.getValue("updatehost", "themanaworld.org/files"); basePath = config.getValue("homeDir", "."); - + // Try to download the updates list download(); - + while (state == UPDATE) { // Handle SDL events @@ -308,17 +304,17 @@ void updateData() } break; } - + guiInput->pushInput(event); } - + switch (downloadStatus) { case UPDATE_ERROR: SDL_WaitThread(thread, NULL); - updaterWindow->setText(""); - updaterWindow->setText("##1 The update process is incomplete."); - updaterWindow->setText("##1 It is strongly recommended that"); - updaterWindow->setText("##1 you try again later"); + updaterWindow->addRow(""); + updaterWindow->addRow("##1 The update process is incomplete."); + updaterWindow->addRow("##1 It is strongly recommended that"); + updaterWindow->addRow("##1 you try again later"); downloadStatus = UPDATE_COMPLETE; break; case UPDATE_NEWS: @@ -395,7 +391,7 @@ void updateData() gui->draw(); guiGraphics->updateScreen(); } - + free(memoryBuffer); in.close(); // Remove downloaded files diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index f1d460a2..062dc191 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -77,25 +77,27 @@ class UpdaterWindow : public Window, public gcn::ActionListener * Set's label above progress */ void setLabel(const std::string &); - + /** * Enables play button */ void enable(); - + /** * Loads and display news */ void loadNews(); - + void action(const std::string& eventId); - void draw(gcn::Graphics *); - - void setText(std:: string row); - + /** + * Add a row to the message field. + */ + void addRow(const std::string &row); + int updateState; }; void updateData(); + #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e6a55ea0..158e9272 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -22,13 +22,11 @@ */ #include "window.h" +#include "gui.h" #include "../resources/resourcemanager.h" #include "../log.h" #include "../main.h" -// TODO Check if we can get rid of this -extern SDL_Surface *screen; - WindowContainer *Window::windowContainer = NULL; int Window::instances = 0; ImageRect Window::border; @@ -302,26 +300,26 @@ void Window::mouseMotion(int x, int y) newDim.y = 0; } - if (newDim.x + newDim.width > screen->w) + if (newDim.x + newDim.width > guiGraphics->getWidth()) { if (mMouseResize) { - newDim.width = screen->w - newDim.x; + newDim.width = guiGraphics->getWidth() - newDim.x; } else { - newDim.x = screen->w - newDim.width; + newDim.x = guiGraphics->getWidth() - newDim.width; } } - if (newDim.y + newDim.height > screen->h) + if (newDim.y + newDim.height > guiGraphics->getHeight()) { if (mMouseResize) { - newDim.height = screen->h - newDim.y; + newDim.height = guiGraphics->getHeight() - newDim.y; } else { - newDim.y = screen->h - newDim.height; + newDim.y = guiGraphics->getHeight() - newDim.height; } } diff --git a/src/main.cpp b/src/main.cpp index 1f2ac73f..908be46a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,9 +58,6 @@ #include <errno.h> #endif -// TODO Check if we can get rid of this -extern SDL_Surface *screen; - // Account infos int account_ID, session_ID1, session_ID2; char sex, n_server, n_character; @@ -252,7 +249,7 @@ void init_engine() SDL_WM_SetIcon(IMG_Load(TMW_DATADIR "data/icons/tmw-icon.png"), NULL); - screen = SDL_SetVideoMode(screenW, screenH, 0, displayFlags); + SDL_Surface *screen = SDL_SetVideoMode(screenW, screenH, 0, displayFlags); if (screen == NULL) { std::cerr << "Couldn't set " << screenW << "x" << screenH << "x" << bitDepth << " video mode: " << SDL_GetError() << std::endl; @@ -296,7 +293,7 @@ void init_engine() itemDb = new ItemManager(); // Create the graphics context - graphics = new Graphics(); + graphics = new Graphics(screen); ResourceManager *resman = ResourceManager::getInstance(); @@ -330,7 +327,7 @@ void init_engine() new OkDialog("Sound Engine", err, &initWarningListener); logger->log("Warning: %s", err); } - + // Set frame counter when using fps limit int fpsLimit = (int)config.getValue("fpslimit", 0); if (fpsLimit) @@ -71,6 +71,5 @@ extern unsigned char state; extern Sound sound; extern int screenW, screenH, bitDepth, displayFlags; extern bool useOpenGL; -extern Configuration config; #endif |