diff options
-rw-r--r-- | src/engine.cpp | 12 | ||||
-rw-r--r-- | src/engine.h | 6 | ||||
-rw-r--r-- | src/game.cpp | 8 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 64 | ||||
-rw-r--r-- | src/gui/inventory.h | 5 | ||||
-rw-r--r-- | src/gui/item_amount.cpp | 71 | ||||
-rw-r--r-- | src/gui/item_amount.h | 15 | ||||
-rw-r--r-- | src/gui/newskill.cpp | 8 | ||||
-rw-r--r-- | src/gui/ok_dialog.cpp | 6 | ||||
-rw-r--r-- | src/gui/requesttrade.cpp | 4 | ||||
-rw-r--r-- | src/gui/trade.cpp | 83 | ||||
-rw-r--r-- | src/gui/trade.h | 24 | ||||
-rw-r--r-- | src/gui/window.cpp | 7 | ||||
-rw-r--r-- | src/gui/window.h | 17 | ||||
-rw-r--r-- | src/map.cpp | 109 | ||||
-rw-r--r-- | src/map.h | 5 |
16 files changed, 150 insertions, 294 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 459af137..7a777f86 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -28,7 +28,6 @@ #include "gui/minimap.h" #include "gui/chargedialog.h" #include "gui/itemcontainer.h" -#include "gui/item_amount.h" #include "gui/trade.h" #include "gui/buddywindow.h" #include "main.h" @@ -53,7 +52,6 @@ BuyDialog *buyDialog; SellDialog *sellDialog; BuySellDialog *buySellDialog; InventoryWindow *inventoryWindow; -ItemAmountWindow *itemAmountWindow; NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; SkillDialog *skillDialog; @@ -153,7 +151,6 @@ Engine::Engine() sellDialog = new SellDialog(); buySellDialog = new BuySellDialog(); inventoryWindow = new InventoryWindow(); - itemAmountWindow = new ItemAmountWindow(); npcTextDialog = new NpcTextDialog(); npcListDialog = new NpcListDialog(); skillDialog = new SkillDialog(); @@ -166,20 +163,17 @@ Engine::Engine() tradeWindow = new TradeWindow(); buddyWindow = new BuddyWindow(); requestTradeDialog = new RequestTradeDialog(); - + /* Menu items */ std::vector<MenuItem> items; items.push_back(MenuItem("First")); menu = new Menu("Menu", items); - + // Initialize window posisitons chatWindow->setPosition(0, screen->h - chatWindow->getHeight()); statusWindow->setPosition(screen->w - statusWindow->getWidth() - 5, 5); inventoryWindow->setPosition(screen->w - statusWindow->getWidth() - inventoryWindow->getWidth() - 10, 5); - itemAmountWindow->setPosition(screen->w - statusWindow->getWidth() - - inventoryWindow->getWidth() - 10, inventoryWindow->getHeight() + - 10); statsWindow->setPosition( screen->w - 5 - statsWindow->getWidth(), statusWindow->getHeight() + 20); @@ -204,7 +198,6 @@ Engine::Engine() sellDialog->setVisible(false); buySellDialog->setVisible(false); inventoryWindow->setVisible(false); - itemAmountWindow->setVisible(false); npcTextDialog->setVisible(false); npcListDialog->setVisible(false); skillDialog->setVisible(false); @@ -259,7 +252,6 @@ Engine::~Engine() delete minimap; delete equipmentWindow; delete newSkillWindow; - delete itemAmountWindow; delete tradeWindow; delete buddyWindow; delete requestTradeDialog; diff --git a/src/engine.h b/src/engine.h index 0f69e04e..f8edd270 100644 --- a/src/engine.h +++ b/src/engine.h @@ -41,11 +41,9 @@ #include "gui/setup.h" #include "gui/equipment.h" #include "gui/chargedialog.h" -#include "gui/item_amount.h" #include "gui/menu.h" #include "gui/trade.h" #include "gui/requesttrade.h" -#include "gui/confirm_dialog.h" #include "resources/resourcemanager.h" #include "map.h" #include "graphic/spriteset.h" @@ -64,7 +62,6 @@ extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern BuySellDialog *buySellDialog; extern InventoryWindow *inventoryWindow; -extern ItemAmountWindow *itemAmountWindow; extern NpcListDialog *npcListDialog; extern NpcTextDialog *npcTextDialog; extern SkillDialog *skillDialog; @@ -76,7 +73,6 @@ extern ChargeDialog* chargeDialog; extern RequestTradeDialog *requestTradeDialog; extern TradeWindow *tradeWindow; extern BuddyWindow *buddyWindow; -extern ConfirmDialog *quitDialog; extern Menu *menu; extern std::map<int, Spriteset*> monsterset; char get_x_offset(char, char); @@ -88,7 +84,7 @@ char get_y_offset(char, char); class Engine { private: Spriteset *emotionset, *npcset, *weaponset, *itemset; - + public: Engine(); ~Engine(); diff --git a/src/game.cpp b/src/game.cpp index b849fcdd..7b7bbd98 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -36,6 +36,7 @@ #include "gui/npc.h" #include "gui/stats.h" #include "gui/ok_dialog.h" +#include "gui/confirm_dialog.h" #include "net/protocol.h" #include "resources/mapreader.h" #include <SDL.h> @@ -155,14 +156,13 @@ void do_init() // Try .tmx map file pathDir.insert(pathDir.size(), ".tmx"); - tiledMap = Map::load(pathDir); - + tiledMap = MapReader::readMap(pathDir); if (!tiledMap) { // Try .tmx.gz map file pathDir.insert(pathDir.size(), ".gz"); - tiledMap = Map::load(pathDir); + tiledMap = MapReader::readMap(pathDir); if (!tiledMap) { @@ -976,7 +976,7 @@ void do_parse() strcpy(strrchr(map_path, '.') + 1, "tmx.gz"); if (tiledMap) delete tiledMap; - tiledMap = Map::load(map_path); + tiledMap = MapReader::readMap(map_path); if (tiledMap) { // Delete all beings except the local player diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index bb8b7bf5..4a1c0ca3 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -41,8 +41,6 @@ InventoryWindow::InventoryWindow(): dropButton = new Button("Drop"); items = new ItemContainer(); - items->setPosition(2, 2); - invenScroll = new ScrollArea(items); invenScroll->setPosition(8, 8); @@ -54,7 +52,6 @@ InventoryWindow::InventoryWindow(): itemNameLabel = new gcn::Label("Name:"); itemDescriptionLabel = new gcn::Label("Description:"); - add(useButton); add(dropButton); add(invenScroll); @@ -67,47 +64,46 @@ InventoryWindow::InventoryWindow(): updateWidgets(); useButton->setSize(48, useButton->getHeight()); - } InventoryWindow::~InventoryWindow() { delete useButton; delete dropButton; + delete invenScroll; + delete items; delete itemNameLabel; delete itemDescriptionLabel; } -void InventoryWindow::draw(gcn::Graphics *graphics) +int InventoryWindow::addItem(int index, int id, int quantity, bool equipment) { - // Draw window graphics - Window::draw(graphics); -} - - -int InventoryWindow::addItem(int index, int id, int quantity, bool equipment) { items->addItem(index, id, quantity, equipment); return 0; } -int InventoryWindow::removeItem(int id) { +int InventoryWindow::removeItem(int id) +{ items->removeItem(id); return 0; } -int InventoryWindow::changeQuantity(int index, int quantity) { +int InventoryWindow::changeQuantity(int index, int quantity) +{ //items[index].quantity = quantity; items->changeQuantity(index, quantity); return 0; } -int InventoryWindow::increaseQuantity(int index, int quantity) { +int InventoryWindow::increaseQuantity(int index, int quantity) +{ //items[index].quantity += quantity; items->increaseQuantity(index, quantity); return 0; } -int InventoryWindow::useItem(int index, int id) { +int InventoryWindow::useItem(int index, int id) +{ WFIFOW(0) = net_w_value(0x00a7); WFIFOW(2) = net_w_value(index); WFIFOL(4) = net_l_value(id); @@ -117,7 +113,8 @@ int InventoryWindow::useItem(int index, int id) { return 0; } -int InventoryWindow::dropItem(int index, int quantity) { +int InventoryWindow::dropItem(int index, int quantity) +{ // TODO: Fix wrong coordinates of drops, serverside? WFIFOW(0) = net_w_value(0x00a2); WFIFOW(2) = net_w_value(index); @@ -127,7 +124,8 @@ int InventoryWindow::dropItem(int index, int quantity) { return 0; } -void InventoryWindow::equipItem(int index) { +void InventoryWindow::equipItem(int index) +{ WFIFOW(0) = net_w_value(0x00a9); WFIFOW(2) = net_w_value(index); WFIFOW(4) = net_w_value(0); @@ -135,7 +133,8 @@ void InventoryWindow::equipItem(int index) { while ((out_size > 0)) flush(); } -void InventoryWindow::unequipItem(int index) { +void InventoryWindow::unequipItem(int index) +{ WFIFOW(0) = net_w_value(0x00ab); WFIFOW(2) = net_w_value(index); WFIFOSET(4); @@ -144,25 +143,26 @@ void InventoryWindow::unequipItem(int index) { void InventoryWindow::action(const std::string &eventId) { - //if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) { - if (items->getIndex() != -1) { + int selectedItem = items->getIndex(); + + if (selectedItem != -1) { if (eventId == "use") { - if(items->isEquipment(items->getIndex())) { - if(items->isEquipped(items->getIndex())) { - unequipItem(items->getIndex()); + if(items->isEquipment(selectedItem)) { + if(items->isEquipped(selectedItem)) { + unequipItem(selectedItem); } else { - equipItem(items->getIndex()); + equipItem(selectedItem); } } else { - useItem(items->getIndex(), items->getId()); - } + useItem(selectedItem, items->getId()); + } } - else if (eventId == "drop") { - itemAmountWindow->setUsage(AMOUNT_ITEM_DROP); - itemAmountWindow->setVisible(true); - itemAmountWindow->requestMoveToTop(); + else if (eventId == "drop") + { + // Choose amount of items to drop + new ItemAmountWindow(AMOUNT_ITEM_DROP, this); } updateUseButton(); @@ -172,7 +172,7 @@ void InventoryWindow::action(const std::string &eventId) void InventoryWindow::mouseClick(int x, int y, int button, int count) { Window::mouseClick(x, y, button, count); - + updateUseButton(); if (items->getIndex() != -1) @@ -227,6 +227,6 @@ void InventoryWindow::updateUseButton() else { useButton ->setCaption("Use"); } - + useButton->setEnabled(items->getIndex() != -1); } diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 177b5662..43a23ede 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -50,11 +50,6 @@ class InventoryWindow : public Window, gcn::ActionListener { ~InventoryWindow(); /** - * Draws the inventory window. - */ - void draw(gcn::Graphics *graphics); - - /** * Add an item the inventory. */ int addItem(int index, int id, int quantity, bool equipment); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8cd51b10..a2aabfb4 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -26,8 +26,8 @@ #include "../engine.h" #include "../main.h" -ItemAmountWindow::ItemAmountWindow(): - Window("Select amount of items to drop.") +ItemAmountWindow::ItemAmountWindow(int usage, Window *parent): + Window("Select amount of items to drop.", true, parent) { // New labels itemAmountLabel = new gcn::Label("1"); @@ -37,20 +37,20 @@ ItemAmountWindow::ItemAmountWindow(): itemAmountPlusButton = new Button("+"); itemAmountOkButton = new Button("Okay"); itemAmountCancelButton = new Button("Cancel"); - + // Set button events Id itemAmountMinusButton->setEventId("Minus"); itemAmountPlusButton->setEventId("Plus"); itemAmountOkButton->setEventId("Drop"); itemAmountCancelButton->setEventId("Cancel"); - + // Set position itemAmountLabel->setPosition(35, 10); itemAmountPlusButton->setPosition(60, 5); itemAmountMinusButton->setPosition(10, 5); itemAmountOkButton->setPosition(10, 40); itemAmountCancelButton->setPosition(60, 40); - + // Assemble add(itemAmountLabel); add(itemAmountPlusButton); @@ -62,28 +62,9 @@ ItemAmountWindow::ItemAmountWindow(): itemAmountMinusButton->addActionListener(this); itemAmountOkButton->addActionListener(this); itemAmountCancelButton->addActionListener(this); - - resetAmount(); - - setContentSize(200, 80); - setLocationRelativeTo(getParent()); -} -ItemAmountWindow::~ItemAmountWindow() { - delete itemAmountLabel; - delete itemAmountPlusButton; - delete itemAmountMinusButton; - delete itemAmountOkButton; - delete itemAmountCancelButton; -} - -void ItemAmountWindow::resetAmount() { - amount = 1; - itemAmountLabel->setCaption("1"); -} - -void ItemAmountWindow::setUsage(int usage) { resetAmount(); + switch (usage) { case AMOUNT_TRADE_ADD: setCaption("Select amount of items to trade."); @@ -94,28 +75,45 @@ void ItemAmountWindow::setUsage(int usage) { itemAmountOkButton->setEventId("Drop"); break; default: - break; } + + setContentSize(200, 80); + setLocationRelativeTo(getParentWindow()); +} + +ItemAmountWindow::~ItemAmountWindow() +{ + delete itemAmountLabel; + delete itemAmountPlusButton; + delete itemAmountMinusButton; + delete itemAmountOkButton; + delete itemAmountCancelButton; +} + +void ItemAmountWindow::resetAmount() +{ + amount = 1; + itemAmountLabel->setCaption("1"); } void ItemAmountWindow::action(const std::string& eventId) { if (eventId == "Cancel") { - resetAmount(); - setVisible(false); - } else if (eventId == "Drop") + scheduleDelete(); + } + else if (eventId == "Drop") { inventoryWindow->dropItem(inventoryWindow->items->getIndex(), amount); - resetAmount(); - setVisible(false); - } else if (eventId == "AddTrade") + scheduleDelete(); + } + else if (eventId == "AddTrade") { tradeWindow->tradeItem(inventoryWindow->items->getIndex(), amount); - resetAmount(); - setVisible(false); - } else if (eventId == "Plus") + scheduleDelete(); + } + else if (eventId == "Plus") { if (amount < inventoryWindow->items->getQuantity()) { @@ -125,7 +123,8 @@ void ItemAmountWindow::action(const std::string& eventId) itemAmountLabel->setCaption(tmpplus); itemAmountLabel->adjustSize(); } - } else if (eventId == "Minus") + } + else if (eventId == "Minus") { if (amount > 1) { diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 4b889b86..d01f2006 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -42,7 +42,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener /** * Constructor. */ - ItemAmountWindow(); + ItemAmountWindow(int usage, Window *parent); /** * Destructor. @@ -55,11 +55,6 @@ class ItemAmountWindow : public Window, public gcn::ActionListener void action(const std::string& eventId); /** - * Has to be called before setVisible(true). - */ - void ItemAmountWindow::setUsage(int usage); - - /** * Sets default amount value. */ void resetAmount(); @@ -68,13 +63,13 @@ class ItemAmountWindow : public Window, public gcn::ActionListener int amount; /**< Amount of items to be dropped. */ gcn::Label *itemAmountLabel; /**< Item amount caption. */ - /** + /** * Item Amount buttons. */ gcn::Button *itemAmountPlusButton; - gcn::Button *itemAmountMinusButton; - gcn::Button *itemAmountOkButton; - gcn::Button *itemAmountCancelButton; + gcn::Button *itemAmountMinusButton; + gcn::Button *itemAmountOkButton; + gcn::Button *itemAmountCancelButton; }; #endif /* _TMW_ITEM_AMOUNT_WINDOW_H */ diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index b826d753..5849e020 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -70,7 +70,7 @@ char *skill_name[] = { NewSkillDialog::NewSkillDialog(): Window("Skills") { - startPoint = 0; + startPoint = 0; for ( int i = 0; i < N_SKILL_CAT_SIZE; i++) { skillLabel[i] = new gcn::Label("Empty "); @@ -88,7 +88,7 @@ NewSkillDialog::NewSkillDialog(): playerSkill[i].exp = 0; } resetNSD(); - + // create controls catButton[0] = new Button("Weapons"); catButton[1] = new Button("Magic"); @@ -102,7 +102,7 @@ NewSkillDialog::NewSkillDialog(): closeButton = new Button("Close"); // captions - + // events catButton[0]->setEventId("g1"); catButton[1]->setEventId("g2"); @@ -169,7 +169,7 @@ NewSkillDialog::NewSkillDialog(): NewSkillDialog::~NewSkillDialog() { for (int i = 0; i < N_SKILL_CAT_SIZE; i++) - { + { delete skillbar[i]; delete skillLabel[i]; delete skillLevel[i]; diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index e7ff1449..8b7ef6d4 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -56,15 +56,15 @@ void OkDialog::init(const std::string &msg, gcn::ActionListener *listener) (w - okButton->getWidth()) / 2, h - 5 - okButton->getHeight()); - okButton->setEventId("ok"); + okButton->setEventId("ok"); okButton->addActionListener(this); if (listener) { okButton->addActionListener(listener); } - + add(userLabel); add(okButton); - + setLocationRelativeTo(getParent()); okButton->requestFocus(); } diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp index 431f6922..9cbdf7b2 100644 --- a/src/gui/requesttrade.cpp +++ b/src/gui/requesttrade.cpp @@ -35,7 +35,7 @@ RequestTradeDialog::RequestTradeDialog(): cancelButton = new Button("Cancel"); setContentSize(260, 75); - + nameLabel[0]->setPosition(5, 30); nameLabel[1]->setPosition(5, 40); cancelButton->setPosition( @@ -44,7 +44,7 @@ RequestTradeDialog::RequestTradeDialog(): acceptButton->setPosition( cancelButton->getX() - 5 - acceptButton->getWidth(), cancelButton->getY()); - + acceptButton->setEventId("accept"); cancelButton->setEventId("cancel"); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index ee947e4f..bcc5f8ce 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -37,39 +37,39 @@ TradeWindow::TradeWindow(): Window("Trade: You") { setContentSize(322, 150); - + addButton = new Button("Add"); okButton = new Button("Ok"); cancelButton = new Button("Cancel"); tradeButton = new Button("Trade"); - + myItems = new ItemContainer(); myItems->setPosition(2, 2); - + myScroll = new ScrollArea(myItems); myScroll->setPosition(8, 8); - + partnerItems = new ItemContainer(); partnerItems->setPosition(2, 58); partnerScroll = new ScrollArea(partnerItems); partnerScroll->setPosition(8, 64); - + addButton->setEventId("add"); okButton->setEventId("ok"); cancelButton->setEventId("cancel"); tradeButton->setEventId("trade"); - + addButton->addActionListener(this); okButton->addActionListener(this); cancelButton->addActionListener(this); tradeButton->addActionListener(this); tradeButton->setEnabled(false); - + itemNameLabel = new gcn::Label("Name:"); itemDescriptionLabel = new gcn::Label("Description:"); - + add(myScroll); add(partnerScroll); add(addButton); @@ -78,12 +78,12 @@ TradeWindow::TradeWindow(): add(tradeButton); add(itemNameLabel); add(itemDescriptionLabel); - + addButton->setPosition(8, getHeight() - 24); okButton->setPosition(48 + 16, getHeight() - 24); tradeButton->setPosition(getWidth() - 92, getHeight() - 24); cancelButton->setPosition(getWidth() - 52, getHeight() - 24); - + myItems->setSize(getWidth() - 24 - 12 - 1, (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); myScroll->setSize(getWidth() - 16, (getHeight() - 76) / 2); @@ -91,7 +91,7 @@ TradeWindow::TradeWindow(): partnerItems->setSize(getWidth() - 24 - 12 - 1, (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); partnerScroll->setSize(getWidth() - 16, (getHeight() - 76) / 2); - + itemNameLabel->setPosition(8, partnerScroll->getY() + partnerScroll->getHeight() + 4); itemDescriptionLabel->setPosition(8, @@ -106,19 +106,17 @@ TradeWindow::~TradeWindow() delete okButton; delete cancelButton; delete tradeButton; + delete myItems; + delete myScroll; + delete partnerItems; + delete partnerScroll; delete itemNameLabel; delete itemDescriptionLabel; } -void TradeWindow::draw(gcn::Graphics *graphics) -{ - // Draw window graphics - Window::draw(graphics); -} - - void TradeWindow::addItem(int index, int id, bool own, int quantity, - bool equipment) { + bool equipment) +{ if (own) { myItems->addItem(index, id, quantity, equipment); } else { @@ -126,7 +124,8 @@ void TradeWindow::addItem(int index, int id, bool own, int quantity, } } -void TradeWindow::removeItem(int id, bool own) { +void TradeWindow::removeItem(int id, bool own) +{ if (own) { myItems->removeItem(id); } else { @@ -134,7 +133,8 @@ void TradeWindow::removeItem(int id, bool own) { } } -void TradeWindow::changeQuantity(int index, bool own, int quantity) { +void TradeWindow::changeQuantity(int index, bool own, int quantity) +{ if (own) { myItems->changeQuantity(index, quantity); } else { @@ -142,7 +142,8 @@ void TradeWindow::changeQuantity(int index, bool own, int quantity) { } } -void TradeWindow::increaseQuantity(int index, bool own, int quantity) { +void TradeWindow::increaseQuantity(int index, bool own, int quantity) +{ if (own) { myItems->increaseQuantity(index, quantity); } else { @@ -150,7 +151,8 @@ void TradeWindow::increaseQuantity(int index, bool own, int quantity) { } } -void TradeWindow::reset() { +void TradeWindow::reset() +{ myItems->resetItems(); partnerItems->resetItems(); tradeButton->setEnabled(false); @@ -159,11 +161,13 @@ void TradeWindow::reset() { ok_me = false; } -void TradeWindow::setTradeButton(bool enabled) { +void TradeWindow::setTradeButton(bool enabled) +{ tradeButton->setEnabled(enabled); } -void TradeWindow::receivedOk(bool own) { +void TradeWindow::receivedOk(bool own) +{ if (own) { ok_me = true; if (ok_other) { @@ -198,7 +202,7 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) { Window::mouseClick(x, y, button, count); - + // myItems selected if (x >= myScroll->getX() + 3 && x <= myScroll->getX() + myScroll->getWidth() - 10 @@ -208,7 +212,7 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) if (myItems->getIndex() != -1) { partnerItems->selectNone(); - + // Show Name and Description std::string SomeText; SomeText = "Name: " + @@ -221,15 +225,16 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) itemDescriptionLabel->adjustSize(); } // partnerItems selected - } else if (x >= partnerScroll->getX() + 3 + } + else if (x >= partnerScroll->getX() + 3 && x <= partnerScroll->getX() + partnerScroll->getWidth() - 20 && y >= partnerScroll->getY() + 16 && y <= partnerScroll->getY() + partnerScroll->getHeight() + 15) { if (partnerItems->getIndex() != -1) - { + { myItems->selectNone(); - + // Show Name and Description std::string SomeText; SomeText = "Name: " + @@ -246,7 +251,6 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) void TradeWindow::action(const std::string &eventId) { - if (eventId == "add") { if (inventoryWindow->items->getIndex() >= 0 && inventoryWindow->items->getIndex() <= INVENTORY_SIZE) { @@ -255,21 +259,26 @@ void TradeWindow::action(const std::string &eventId) tradeItem(inventoryWindow->items->getIndex(), 1); } else { - itemAmountWindow->setUsage(AMOUNT_TRADE_ADD); - itemAmountWindow->setVisible(true); - itemAmountWindow->requestMoveToTop(); + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_TRADE_ADD, this); } } } - } else if (eventId == "cancel") { + } + else if (eventId == "cancel") + { WFIFOW(0) = net_w_value(0x00ed); WFIFOSET(2); while ((out_size > 0)) flush(); - } else if (eventId == "ok") { + } + else if (eventId == "ok") + { WFIFOW(0) = net_w_value(0x00eb); WFIFOSET(2); while ((out_size > 0)) flush(); - } else if (eventId == "trade") { + } + else if (eventId == "trade") + { WFIFOW(0) = net_w_value(0x00ef); WFIFOSET(2); while ((out_size > 0)) flush(); diff --git a/src/gui/trade.h b/src/gui/trade.h index 09e56d06..90c688c3 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -22,7 +22,7 @@ */ #ifndef _TMW_TRADE_H -#define _TMW_TRADE_H +#define _TMW_TRADE_H #include "../log.h" #include "../net/network.h" @@ -37,7 +37,8 @@ * * \ingroup Interface */ -class TradeWindow : public Window, gcn::ActionListener { +class TradeWindow : public Window, gcn::ActionListener +{ public: /** * Constructor. @@ -50,11 +51,6 @@ class TradeWindow : public Window, gcn::ActionListener { ~TradeWindow(); /** - * Draws the trade window. - */ - void draw(gcn::Graphics *graphics); - - /** * Add an item the trade window. */ void addItem(int index, int id, bool own, int quantity, bool equipment); @@ -78,35 +74,35 @@ class TradeWindow : public Window, gcn::ActionListener { * Increase quantity of an item. */ void increaseQuantity(int index, bool own, int quantity); - + /** * Set trade Button disabled */ void setTradeButton(bool enabled); - + /** * Player received ok message from server */ void receivedOk(bool own); - + /** * Send trade packet. */ void TradeWindow::tradeItem(int index, int quantity); - + /** * Called on mouse click. */ void mouseClick(int x, int y, int button, int count); - + /** * Called when receiving actions from the widgets. */ void action(const std::string& eventId); - + ItemContainer *myItems; ItemContainer *partnerItems; - + private: gcn::Label *itemNameLabel; gcn::Label *itemDescriptionLabel; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 54bce746..1245c977 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -122,8 +122,7 @@ Window::~Window() if (prevModal) { - gcn::FocusHandler *focusHandler = _getFocusHandler(); - focusHandler->requestModalFocus(prevModal); + prevModal->requestModalFocus(); } } @@ -221,9 +220,9 @@ Window *Window::getParentWindow() return parent; } -bool Window::isModal() +void Window::scheduleDelete() { - return modal; + windowContainer->scheduleDelete(this); } void Window::add(gcn::Widget *w) diff --git a/src/gui/window.h b/src/gui/window.h index d0112e97..c9fa1f12 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -127,7 +127,6 @@ class Window : public gcn::Window, public ConfigListener */ void setMaxHeight(unsigned int height); - /** * Returns the parent window. * @@ -136,10 +135,10 @@ class Window : public gcn::Window, public ConfigListener Window *getParentWindow(); /** - * Returns whether this window is modal. This doesn't necessarily mean - * that is gets input as a child modal window could get it. + * Schedule this window for deletion. It will be deleted at the start + * of the next logic update. */ - bool isModal(); + void scheduleDelete(); /** * Window dragging. This method also makes sure the window is not @@ -169,16 +168,6 @@ class Window : public gcn::Window, public ConfigListener static int instances; /**< Number of Window instances */ static ImageRect border; /**< The window border and background */ - - /** - * Loads window resources. - */ - void loadResources(); - - /** - * Unloads window resources. - */ - void unloadResources(); }; #endif diff --git a/src/map.cpp b/src/map.cpp index 81540e98..5f522dfb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -31,44 +31,6 @@ #include <queue> -#define OLD_MAP_WIDTH 200 -#define OLD_MAP_HEIGHT 200 - -/** - * Old tile structure. Used for loading the old map format. - */ -struct TILE { - /** - * Data field filled at follows: - * - * <pre> - * 1st byte: [1][1][1][1][1][1][1][1] - * 2nd byte: [1][1][2][2][2][2][2][2] - * 3rd byte: [2][2][2][2][3][3][3][3] - * 4th byte: [3][3][3][3][3][3][W][A] - * </pre> - * - * Legend: - * 1 - Ground layer (grass, water, ...) - * 2 - Fringe layer (decoration on top of ground layer, but below beings) - * 3 - Over layer (roofs, tree leaves, ...) - * W - Walkability flag - * A - Animated tile flag - */ - char data[4]; - char flags; -}; - -/** - * Old map structure. Used for loading the old map format. - */ -struct MAP { - TILE tiles[OLD_MAP_WIDTH][OLD_MAP_HEIGHT]; - char tileset[20]; - char bg_music[20]; -}; - - MetaTile::MetaTile(): whichList(0) { @@ -110,77 +72,6 @@ Map::~Map() delete[] tiles; } -Map *Map::load(const std::string &mapFile) -{ - logger->log("Map::load(%s)", mapFile.c_str()); - - if (mapFile.find(".tmx", 0) != std::string::npos) - { - // New map file format assumed - return MapReader::readMap(mapFile); - } - - FILE *file = fopen(mapFile.c_str(), "r"); - - if (!file) { - logger->log("Warning: %s", mapFile.c_str()); - return NULL; - } - - MAP oldMap; - fread(&oldMap, sizeof(MAP), 1, file); - fclose(file); - - Map *map = new Map(OLD_MAP_WIDTH, OLD_MAP_HEIGHT); - - // Load the default tileset - ResourceManager *resman = ResourceManager::getInstance(); - Image *tilesetbmp = resman->getImage("graphics/tiles/desert.png"); - if (!tilesetbmp) logger->error("Unable to load desert.png"); - Spriteset *tileset = new Spriteset(tilesetbmp, 32, 32); - - // Transfer tile data - int x, y, a; - for (y = 0; y < OLD_MAP_HEIGHT; y++) { - for (x = 0; x < OLD_MAP_WIDTH; x++) { - unsigned short id = 0; - - for (a = 0; a < 3; a++) { - // Different interpretation for each layer - switch (a) { - case 0: - id = MAKEWORD(oldMap.tiles[x][y].data[1] & 0x00c0, - oldMap.tiles[x][y].data[0]); - id >>= 6; - break; - case 1: - id = MAKEWORD(oldMap.tiles[x][y].data[2] & 0x00f0, - oldMap.tiles[x][y].data[1] & 0x003f); - id >>= 4; - break; - case 2: - id = MAKEWORD(oldMap.tiles[x][y].data[3] & 0x00fc, - oldMap.tiles[x][y].data[2] & 0x000f); - id >>= 2; - break; - } - - if (id < tileset->spriteset.size() && (a == 0 || id > 0)) { - map->setTile(x, y, a, tileset->spriteset[id]); - } - else { - map->setTile(x, y, a, NULL); - } - } - - // Walkability - map->setWalk(x, y, (oldMap.tiles[x][y].data[3] & 0x0002) > 0); - } - } - - return map; -} - void Map::setSize(int width, int height) { this->width = width; @@ -94,11 +94,6 @@ class Map ~Map(); /** - * Loads a map file (gat). - */ - static Map *load(const std::string &mapFile); - - /** * Draws the map to the given graphics output. */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); |