diff options
author | Andrei Karas <akaras@inbox.ru> | 2009-09-29 21:09:13 +0300 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-09-29 15:09:24 -0400 |
commit | 805edb864a489b8af91db18c7b53bd80b60b0fe0 (patch) | |
tree | 6ccf7ece48022e39e3d79fdf04a1215180b34b6f | |
parent | 50c23cbae082f4aba50620e97ab1f08a16f9703d (diff) | |
download | mana-client-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.gz mana-client-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.bz2 mana-client-805edb864a489b8af91db18c7b53bd80b60b0fe0.tar.xz mana-client-805edb864a489b8af91db18c7b53bd80b60b0fe0.zip |
Outfits update
Increased outfits count to 15
Changed unequip outfits feature
Added copy outfits feature
-rw-r--r-- | src/game.cpp | 62 | ||||
-rw-r--r-- | src/gui/outfitwindow.cpp | 100 | ||||
-rw-r--r-- | src/gui/outfitwindow.h | 9 |
3 files changed, 124 insertions, 47 deletions
diff --git a/src/game.cpp b/src/game.cpp index 2acb8bc2..de455b30 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -616,63 +616,83 @@ void Game::handleInput() } } - if (event.key.keysym.mod & KMOD_RCTRL && !chatWindow->isInputFocused()) + if ((event.key.keysym.mod & KMOD_RCTRL || event.key.keysym.mod & KMOD_LCTRL) + && !chatWindow->isInputFocused()) { + int outfitNum = -1; switch (event.key.keysym.sym) { case SDLK_1: - outfitWindow->wearOutfit(0); - used = true; + outfitNum = 0; break; case SDLK_2: - outfitWindow->wearOutfit(1); - used = true; + outfitNum = 1; break; case SDLK_3: - outfitWindow->wearOutfit(2); - used = true; + outfitNum = 2; break; case SDLK_4: - outfitWindow->wearOutfit(3); - used = true; + outfitNum = 3; break; case SDLK_5: - outfitWindow->wearOutfit(4); - used = true; + outfitNum = 4; break; case SDLK_6: - outfitWindow->wearOutfit(5); - used = true; + outfitNum = 5; break; case SDLK_7: - outfitWindow->wearOutfit(6); - used = true; + outfitNum = 6; break; case SDLK_8: - outfitWindow->wearOutfit(7); - used = true; + outfitNum = 7; break; case SDLK_9: - outfitWindow->wearOutfit(8); - used = true; + outfitNum = 8; break; case SDLK_0: - outfitWindow->wearOutfit(9); - used = true; + outfitNum = 9; + break; + + case SDLK_MINUS: + outfitNum = 10; + break; + + case SDLK_EQUALS: + outfitNum = 11; + break; + + case SDLK_BACKSPACE: + outfitNum = 12; + break; + + case SDLK_INSERT: + outfitNum = 13; + break; + + case SDLK_HOME: + outfitNum = 14; break; default: break; } + if (outfitNum >= 0) + { + used = true; + if (event.key.keysym.mod & KMOD_RCTRL) + outfitWindow->wearOutfit(outfitNum); + else if (event.key.keysym.mod & KMOD_LCTRL) + outfitWindow->copyOutfit(outfitNum); + } } const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 67fec9b0..a88003bb 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -27,13 +27,16 @@ #include "inventory.h" #include "equipment.h" #include "item.h" +#include "log.h" #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" +#include "gui/widgets/chattab.h" #include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "net/inventoryhandler.h" +#include "gui/chat.h" #include "net/net.h" #include "resources/image.h" @@ -55,15 +58,19 @@ OutfitWindow::OutfitWindow(): mCurrentOutfit(0) { setWindowName("Outfits"); + setResizable(true); setCloseButton(true); - setDefaultSize(250, 250, 118, 180); //160 + setDefaultSize(250, 250, 118, 180); mPreviousButton = new Button(_("<"), "previous", this); mNextButton = new Button(_(">"), "next", this); mCurrentLabel = new Label(strprintf(_("Outfit: %d"), 1)); mCurrentLabel->setAlignment(gcn::Graphics::CENTER); mUnequipCheck = new CheckBox(_("Unequip first"), - config.getValue("OutfitUnequip", true)); + config.getValue("OutfitUnequip0", true)); + + mUnequipCheck->setActionEventId("unequip"); + mUnequipCheck->addActionListener(this); place(0, 3, mPreviousButton, 1); place(1, 3, mCurrentLabel, 2); @@ -87,7 +94,7 @@ OutfitWindow::~OutfitWindow() void OutfitWindow::load() { memset(mItems, -1, sizeof(mItems)); - for (int o = 0; o < 10; o++) + for (int o = 0; o < OUTFITS_COUNT; o++) { std::string outfit = config.getValue("Outfit" + toString(o), "-1"); std::string buf; @@ -103,69 +110,81 @@ void OutfitWindow::load() { mItems[o][i] = tokens[i]; } + mItemsUnequip[o] = config.getValue("OutfitUnequip" + toString(o), true); } } void OutfitWindow::save() { std::string outfitStr; - for (int o = 0; o < 10; o++) + for (int o = 0; o < OUTFITS_COUNT; o++) { - for (int i = 0; i < 9; i++) + for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) { outfitStr += mItems[o][i] ? toString(mItems[o][i]) : toString(-1); if (i <8) outfitStr += " "; } config.setValue("Outfit" + toString(o), outfitStr); + config.setValue("OutfitUnequip" + toString(o), mItemsUnequip[o]); outfitStr = ""; } - config.setValue("OutfitUnequip", mUnequipCheck->isSelected()); } void OutfitWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "next") { - if (mCurrentOutfit < 9) { + if (mCurrentOutfit < (OUTFITS_COUNT - 1)) { mCurrentOutfit++; } else { mCurrentOutfit = 0; } + mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); + mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]); } else if (event.getId() == "previous") { if (mCurrentOutfit > 0) { mCurrentOutfit--; } else { - mCurrentOutfit = 9; + mCurrentOutfit = OUTFITS_COUNT - 1; } + mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); + mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]); + } + else if (event.getId() == "unequip") + { + mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected(); } - mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1)); } void OutfitWindow::wearOutfit(int outfit) { Item *item; - if (mUnequipCheck->isSelected()) - { - for (int i = 0; i < 11; i++) - { - if (!(item = player_node->mEquipment.get()->getEquipment(i))) - continue; - Net::getInventoryHandler()->unequipItem(item); - } - } - - for (int i = 0; i < 9; i++) + for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) { item = player_node->getInventory()->findItem(mItems[outfit][i]); - if (item && item->getQuantity()) + if (item && !item->isEquipped() && item->getQuantity()) { if (item->isEquipment()) { Net::getInventoryHandler()->equipItem(item); } } } + + if (mItemsUnequip[outfit]) + { + unequipNotInOutfit(outfit); + } +} + +void OutfitWindow::copyOutfit(int outfit) +{ + Item *item; + for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) + { + mItems[mCurrentOutfit][i] = mItems[outfit][i]; + } } void OutfitWindow::draw(gcn::Graphics *graphics) @@ -173,7 +192,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics) Window::draw(graphics); Graphics *g = static_cast<Graphics*>(graphics); - for (int i = 0; i < 9; i++) + for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) { const int itemX = 10 + (i % mGridWidth) * mBoxWidth; const int itemY = 25 + (i / mGridWidth) * mBoxHeight; @@ -184,14 +203,18 @@ void OutfitWindow::draw(gcn::Graphics *graphics) graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); if (mItems[mCurrentOutfit][i] < 0) + { continue; + } Item *item = player_node->getInventory()->findItem(mItems[mCurrentOutfit][i]); - if (item) { + if (item) + { // Draw item icon. Image* image = item->getImage(); - if (image) { + if (image) + { g->drawImage(image, itemX, itemY); } } @@ -288,9 +311,36 @@ int OutfitWindow::getIndexFromGrid(int pointX, int pointY) const } const int index = (((pointY - 25) / mBoxHeight) * mGridWidth) + (pointX - 10) / mBoxWidth; - if (index >= 9) + if (index >= OUTFIT_ITEM_COUNT) { return -1; } return index; } + +void OutfitWindow::unequipNotInOutfit(int outfit) +{ + Inventory *inventory = player_node->getInventory(); + if (!inventory) + return; + + for (int i = 0; i < inventory->getSize(); i++) + { + if (inventory->getItem(i) && inventory->getItem(i)->isEquipped()) + { + bool found = false; + for (int f = 0; f < OUTFIT_ITEM_COUNT; f++) + { + if (inventory->getItem(i)->getId() == mItems[outfit][f]) + { + found = true; + break; + } + } + if (!found) + { + Net::getInventoryHandler()->unequipItem(inventory->getItem(i)); + } + } + } +} diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index 3e70815c..5132abee 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -26,6 +26,9 @@ #include <guichan/actionlistener.hpp> +#define OUTFITS_COUNT 15 +#define OUTFIT_ITEM_COUNT 9 + class Button; class CheckBox; class Item; @@ -63,6 +66,9 @@ class OutfitWindow : public Window, gcn::ActionListener { return mItemSelected > -1; } void wearOutfit(int outfit); + void copyOutfit(int outfit); + + void unequipNotInOutfit(int outfit); private: Button *mPreviousButton; @@ -81,7 +87,8 @@ class OutfitWindow : public Window, gcn::ActionListener void save(); - int mItems[10][9]; + int mItems[OUTFITS_COUNT][OUTFIT_ITEM_COUNT]; + bool mItemsUnequip[OUTFITS_COUNT]; int mItemSelected; int mCurrentOutfit; |