diff options
-rw-r--r-- | src/gui/itemcontainer.cpp | 26 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 65 | ||||
-rw-r--r-- | src/gui/setup.cpp | 27 | ||||
-rw-r--r-- | src/main.cpp | 29 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 9 |
5 files changed, 80 insertions, 76 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index f727d820..51d093b7 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -34,16 +34,18 @@ ItemContainer::ItemContainer() itemset = new Spriteset(itemImg, 20, 20); selImg = resman->getImage("graphics/gui/selection.png", IMG_ALPHA); - if (!selImg) logger.error("Unable to load items.png"); + if (!selImg) logger.error("Unable to load selection.png"); + + selectedItem = -1; // No item selected - selectedItem = -1; /**< No item selected */ - for (int i = 0; i < INVENTORY_SIZE; i++) { items[i].id = -1; items[i].quantity = 0; items[i].equipment = false; items[i].equipped = false; } + + addMouseListener(this); } ItemContainer::~ItemContainer() @@ -60,12 +62,12 @@ void ItemContainer::draw(gcn::Graphics* graphics) if (items[selectedItem].quantity <= 0) { selectedItem = -1; } - + if (selectedItem >= 0) { int itemX = (((selectedItem - 2) * 24) % (getWidth() - 24)); int itemY = (((selectedItem - 2) * 24) / (getWidth() - 24)) * 24; itemX -= itemX % 24; - selImg->draw(screen, x + itemX, y+itemY); + selImg->draw(screen, x + itemX, y+itemY); } for (int i = 0; i < INVENTORY_SIZE; i++) { @@ -183,17 +185,11 @@ void ItemContainer::increaseQuantity(int index, int quantity) void ItemContainer::mousePress(int mx, int my, int button) { - if (button == gcn::MouseInput::LEFT) + if (button == gcn::MouseInput::LEFT) { selectedItem = ((mx + 48) / 24) + ((my / 24) * (getWidth() / 24)); - if (selectedItem > INVENTORY_SIZE) + } + if (selectedItem > INVENTORY_SIZE) { selectedItem = INVENTORY_SIZE; -} - -void ItemContainer::_mouseInputMessage(const gcn::MouseInput &mouseInput) -{ - if (mouseInput.getButton() == gcn::MouseInput::LEFT) { - gcn::Widget::_mouseInputMessage(mouseInput); - mousePress(mouseInput.x, mouseInput.y, mouseInput.getButton()); } } @@ -227,7 +223,7 @@ int ItemContainer::getNumberOfSlotsUsed() NumberOfFilledSlot++; } } - + return NumberOfFilledSlot; } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index ed332345..849bd252 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -32,11 +32,15 @@ #define INVENTORY_SIZE 100 -struct ITEM_HOLDER { // the holder of a item - int id; // the id of the item - int quantity; // number of items - bool equipment; - bool equipped; +/** + * The holder of a item. + */ +struct ITEM_HOLDER +{ + int id; /**< The id of the item */ + int quantity; /**< The number of items */ + bool equipment; /**< Whether this item is equipment */ + bool equipped; /**< Whether this item is equipped */ }; /** @@ -44,15 +48,14 @@ struct ITEM_HOLDER { // the holder of a item * * \ingroup GUI */ -class ItemContainer : public gcn::Widget +class ItemContainer : public gcn::Widget, public gcn::MouseListener { private: - Spriteset *itemset; - Image *selImg; + Image *selImg; int selectedItem; int itemNumber; - ITEM_HOLDER items[INVENTORY_SIZE]; /**< this is the holder of items */ + ITEM_HOLDER items[INVENTORY_SIZE]; /**< The holder of items */ public: /** @@ -74,52 +77,52 @@ class ItemContainer : public gcn::Widget * Handles mouse click. */ void mousePress(int mx, int my, int button); - + /** * Returns index of the selected item. */ int getIndex(); - + /** * Finds the index of an item. */ int getIndex(int id); - + /** * Returns the id of the selected item. */ int getId(); - + /** * Returns the id of an item. */ int getId(int index); - + /** * Returns the quantity of the selected item. */ int getQuantity(); - + /** * Returns the quantity of an item. */ int getQuantity(int index); - + /** * Returns id of next free slot or -1 if all occupied. */ int getFreeSlot(); - + /** * Adds a new item. */ void addItem(int index, int id, int quantity, bool equipment); - + /** * Reset all item slots. */ void resetItems(); - + /** * Remove a item from the inventory. */ @@ -134,17 +137,27 @@ class ItemContainer : public gcn::Widget * Increase quantity of an item. */ void increaseQuantity(int index, int quantity); - - void _mouseInputMessage(const gcn::MouseInput &mouseInput); - + + /** + * Returns whether the item at the specified index is equipment. + */ bool isEquipment(int index); - + + /** + * Returns whether the item at the specified index is equipped. + */ bool isEquipped(int index); - + + /** + * Sets whether the item at the specified index is equipped. + */ void setEquipped(int index, bool equipped); - + + /** + * Sets whether the item at the specified index is equipment. + */ void setEquipment(int index, bool equipment); - + /** * Get the number of slots filled with an item */ diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 42b770f9..a0be66cc 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -39,15 +39,15 @@ ModeListModel::ModeListModel() SDL_Rect **modes; /* Get available fullscreen/hardware modes */ - modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); - + modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); + /* Check is there are any modes available */ - if(modes == (SDL_Rect **)0) { + if (modes == (SDL_Rect **)0) { logger.log("No modes available"); } - + /* Check if our resolution is restricted */ - if(modes == (SDL_Rect **)-1) { + if (modes == (SDL_Rect **)-1) { logger.log("All resolutions available"); } else{ @@ -64,7 +64,6 @@ ModeListModel::ModeListModel() ModeListModel::~ModeListModel() { - //delete videoModes; } int ModeListModel::getNumberOfElements() @@ -89,7 +88,7 @@ Setup::Setup(): fsCheckBox = new CheckBox("Full screen", false); openGlCheckBox = new CheckBox("OpenGL", false); openGlCheckBox->setEnabled(false); - alphaLabel = new gcn::Label("Gui opacity:"); + alphaLabel = new gcn::Label("Gui opacity"); alphaSlider = new Slider(0.2, 1.0); audioLabel = new gcn::Label("Audio settings"); soundCheckBox = new CheckBox("Sound", false); @@ -128,14 +127,14 @@ Setup::Setup(): applyButton->setPosition( cancelButton->getX() - 5 - applyButton->getWidth(), 216 - 5 - applyButton->getHeight()); - + // Listen for actions applyButton->addActionListener(this); cancelButton->addActionListener(this); alphaSlider->addActionListener(this); sfxSlider->addActionListener(this); musicSlider->addActionListener(this); - + // Assemble dialog add(videoLabel); add(scrollArea); @@ -202,7 +201,7 @@ void Setup::action(const std::string &eventId) else if (eventId == "apply") { setVisible(false); - + if (fsCheckBox->isMarked()) { // Fullscreen config.setValue("screen", 1); displayFlags |= SDL_FULLSCREEN; @@ -211,16 +210,16 @@ void Setup::action(const std::string &eventId) config.setValue("screen", 0); displayFlags &= ~SDL_FULLSCREEN; } - + displayFlags |= SDL_DOUBLEBUF; - + 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); } - + // Sound settings if (soundCheckBox->isMarked()) { config.setValue("sound", 1); @@ -229,7 +228,7 @@ void Setup::action(const std::string &eventId) } catch (const char *err) { new OkDialog(this, "Sound Engine", err); - logger.log("Warning: %s", err); + logger.log("Warning: %s", err); } } else { config.setValue("sound", 0); diff --git a/src/main.cpp b/src/main.cpp index 9cbc2871..5f4595f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,10 +143,10 @@ void init_engine() // Checking if homeuser/.manaworld folder exists. sprintf(dir, "%s/.manaworld", userHome); - if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && + if ((mkdir(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST)) { - printf("%s can't be made... And doesn't exist ! Exitting ...", dir); + printf("%s can't be made, but it doesn't exist! Exitting.\n", dir); exit(1); } sprintf(dir, "%s/.manaworld/config.xml", userHome); @@ -221,11 +221,10 @@ void init_engine() } } - // TODO: the following variables should be loaded from config file screenW = (int)config.getValue("screenwidth", 800); screenH = (int)config.getValue("screenheight", 600); - bitDepth = (int)config.getValue("bitdepth", 16); - + bitDepth = (int)config.getValue("colordepth", 16); + SDL_WM_SetIcon(IMG_Load("data/icons/tmw-icon.png"), NULL); screen = SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags); @@ -295,8 +294,8 @@ void init_engine() if (config.getValue("sound", 0) == 1) { sound.init(); } - sound.setSfxVolume(config.getValue("sfxVolume", 100)); - sound.setMusicVolume(config.getValue("musicVolume", 60)); + sound.setSfxVolume((int)config.getValue("sfxVolume", 100)); + sound.setMusicVolume((int)config.getValue("musicVolume", 60)); } catch (const char *err) { state = ERROR; @@ -346,7 +345,7 @@ int main(int argc, char *argv[]) guiInput->pushInput(event); } - + ResourceManager *resman = ResourceManager::getInstance(); switch (state) { @@ -366,7 +365,7 @@ int main(int argc, char *argv[]) charSelect(); break; case GAME: - sound.fadeOutMusic(3000); + sound.fadeOutMusic(1000); //bgm->stop(); logger.log("State: GAME"); try { @@ -406,11 +405,11 @@ int PLAYER_INFO::GetSkill(int n_ID, int n_XP, int n_base) { if (n_ID > N_SKILLS || n_ID < 0) // out of cheese error, abort function return 0; - // 1. raise the exp value - m_Skill[n_ID].exp += (short)(n_XP * m_Skill[n_ID].mod); + // 1. raise the exp value + m_Skill[n_ID].exp += (short)(n_XP * m_Skill[n_ID].mod); - // 2. Check for level up - if (m_Skill[n_ID].exp >= 20 * ((m_Skill[n_ID].level)^(6/5))) + // 2. Check for level up + if (m_Skill[n_ID].exp >= 20 * ((m_Skill[n_ID].level)^(6/5))) { m_Skill[n_ID].level += 1; m_Skill[n_ID].exp = 0; @@ -423,8 +422,8 @@ int PLAYER_INFO::GetSkill(int n_ID, int n_XP, int n_base) if (n_base) { // TO DO: alter values based on equipment bonuses - } + } - return r; // return the value + return r; // return the value } */ diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 47c4daa4..b26aeb5d 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -103,8 +103,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, if (buffer != NULL) { // Let the music class load it - resource = reinterpret_cast<Resource*>(Music::load(buffer, - fileSize)); + resource = Music::load(buffer, fileSize); // Cleanup free(buffer); @@ -123,8 +122,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, if (buffer != NULL) { // Let the image class load it - resource = reinterpret_cast<Resource*>(Image::load(buffer, - fileSize, flags)); + resource = Image::load(buffer, fileSize, flags); // Cleanup free(buffer); @@ -149,8 +147,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type, if (buffer != NULL) { // Let the sound effect class load it - resource = reinterpret_cast<Resource*>(SoundEffect::load( - buffer, fileSize)); + resource = SoundEffect::load(buffer, fileSize); // Cleanup free(buffer); |