summaryrefslogtreecommitdiff
path: root/src/gui/windows/inventorywindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-01-24 14:26:15 +0300
committerAndrei Karas <akaras@inbox.ru>2015-01-24 14:28:39 +0300
commit1cd50987bce69ada9ccea8c822ccd0ffb34cedde (patch)
tree58858017e679e053905775ef5cad3a711851edea /src/gui/windows/inventorywindow.cpp
parentb7bb27910303ef1538e2cbb4093e452c77567739 (diff)
downloadmv-1cd50987bce69ada9ccea8c822ccd0ffb34cedde.tar.gz
mv-1cd50987bce69ada9ccea8c822ccd0ffb34cedde.tar.bz2
mv-1cd50987bce69ada9ccea8c822ccd0ffb34cedde.tar.xz
mv-1cd50987bce69ada9ccea8c822ccd0ffb34cedde.zip
Add partial support for cart window.
Diffstat (limited to 'src/gui/windows/inventorywindow.cpp')
-rw-r--r--src/gui/windows/inventorywindow.cpp213
1 files changed, 134 insertions, 79 deletions
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index e0dd2e8f0..944c35f24 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -89,6 +89,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
mSplitButton(nullptr),
mOutfitButton(nullptr),
mShopButton(nullptr),
+ mCartButton(nullptr),
mEquipmentButton(nullptr),
mStoreButton(nullptr),
mRetrieveButton(nullptr),
@@ -117,7 +118,6 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
switch (inventory->getType())
{
case Inventory::INVENTORY:
- case Inventory::CART:
case Inventory::TRADE:
case Inventory::NPC:
default:
@@ -128,6 +128,10 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
mSortDropDown->setSelected(config.getIntValue(
"storageSortOrder"));
break;
+ case Inventory::CART:
+ mSortDropDown->setSelected(config.getIntValue(
+ "cartSortOrder"));
+ break;
};
}
else
@@ -170,78 +174,114 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) :
for (size_t f = 0; f < sz; f ++)
mFilter->addButton(tags[f], tags[f], false);
- if (isMainInventory())
+ switch (mInventory->getType())
{
- // TRANSLATORS: inventory button
- const std::string equip = _("Equip");
- // TRANSLATORS: inventory button
- const std::string use = _("Use");
- // TRANSLATORS: inventory button
- const std::string unequip = _("Unequip");
-
- std::string longestUseString = getFont()->getWidth(equip) >
- getFont()->getWidth(use) ? equip : use;
-
- if (getFont()->getWidth(longestUseString) <
- getFont()->getWidth(unequip))
+ case Inventory::INVENTORY:
{
- longestUseString = unequip;
- }
+ // TRANSLATORS: inventory button
+ const std::string equip = _("Equip");
+ // TRANSLATORS: inventory button
+ const std::string use = _("Use");
+ // TRANSLATORS: inventory button
+ const std::string unequip = _("Unequip");
- mUseButton = new Button(this, longestUseString, "use", this);
- // TRANSLATORS: inventory button
- mDropButton = new Button(this, _("Drop..."), "drop", this);
- // TRANSLATORS: inventory button
- mSplitButton = new Button(this, _("Split"), "split", this);
- // TRANSLATORS: inventory outfits button
- mOutfitButton = new Button(this, _("O"), "outfit", this);
- // TRANSLATORS: inventory shop button
- mShopButton = new Button(this, _("S"), "shop", this);
- // TRANSLATORS: inventory equipment button
- mEquipmentButton = new Button(this, _("E"), "equipment", this);
- mWeightBar = new ProgressBar(this, 0.0F, 100, 0, Theme::PROG_WEIGHT,
- "weightprogressbar.xml", "weightprogressbar_fill.xml");
- mWeightBar->setColor(getThemeColor(Theme::WEIGHT_BAR),
- getThemeColor(Theme::WEIGHT_BAR_OUTLINE));
-
- place(0, 0, mWeightBar, 4);
- mSlotsBarCell = &place(4, 0, mSlotsBar, 4);
- mSortDropDownCell = &place(8, 0, mSortDropDown, 3);
-
- mFilterCell = &place(0, 1, mFilter, 10).setPadding(3);
- mNameFilterCell = &place(8, 1, mNameFilter, 3);
-
- place(0, 2, invenScroll, 11).setPadding(3);
- place(0, 3, mUseButton);
- place(1, 3, mDropButton);
- place(8, 2, mSplitButton);
- ContainerPlacer placer = getPlacer(10, 3);
- placer(0, 0, mShopButton);
- placer(1, 0, mOutfitButton);
- placer(2, 0, mEquipmentButton);
+ std::string longestUseString = getFont()->getWidth(equip) >
+ getFont()->getWidth(use) ? equip : use;
- updateWeight();
- }
- else
- {
- // TRANSLATORS: storage button
- mStoreButton = new Button(this, _("Store"), "store", this);
- // TRANSLATORS: storage button
- mRetrieveButton = new Button(this, _("Retrieve"), "retrieve", this);
- // TRANSLATORS: storage button
- mInvCloseButton = new Button(this, _("Close"), "close", this);
+ if (getFont()->getWidth(longestUseString) <
+ getFont()->getWidth(unequip))
+ {
+ longestUseString = unequip;
+ }
+
+ mUseButton = new Button(this, longestUseString, "use", this);
+ // TRANSLATORS: inventory button
+ mDropButton = new Button(this, _("Drop..."), "drop", this);
+ // TRANSLATORS: inventory button
+ mSplitButton = new Button(this, _("Split"), "split", this);
+ // TRANSLATORS: inventory outfits button
+ mOutfitButton = new Button(this, _("O"), "outfit", this);
+ // TRANSLATORS: inventory cart button
+ mCartButton = new Button(this, _("C"), "cart", this);
+ // TRANSLATORS: inventory shop button
+ mShopButton = new Button(this, _("S"), "shop", this);
+ // TRANSLATORS: inventory equipment button
+ mEquipmentButton = new Button(this, _("E"), "equipment", this);
+ mWeightBar = new ProgressBar(this, 0.0F, 100, 0, Theme::PROG_WEIGHT,
+ "weightprogressbar.xml", "weightprogressbar_fill.xml");
+ mWeightBar->setColor(getThemeColor(Theme::WEIGHT_BAR),
+ getThemeColor(Theme::WEIGHT_BAR_OUTLINE));
+
+ place(0, 0, mWeightBar, 4);
+ mSlotsBarCell = &place(4, 0, mSlotsBar, 4);
+ mSortDropDownCell = &place(8, 0, mSortDropDown, 3);
+
+ mFilterCell = &place(0, 1, mFilter, 10).setPadding(3);
+ mNameFilterCell = &place(8, 1, mNameFilter, 3);
+
+ place(0, 2, invenScroll, 11).setPadding(3);
+ place(0, 3, mUseButton);
+ place(1, 3, mDropButton);
+ place(8, 2, mSplitButton);
+ ContainerPlacer placer = getPlacer(10, 3);
+ placer(0, 0, mShopButton);
+ placer(1, 0, mOutfitButton);
+ placer(2, 0, mCartButton);
+ placer(3, 0, mEquipmentButton);
+
+ updateWeight();
+ break;
+ }
- mSlotsBarCell = &place(0, 0, mSlotsBar, 6);
- mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
+ case Inventory::STORAGE:
+ {
+ // TRANSLATORS: storage button
+ mStoreButton = new Button(this, _("Store"), "store", this);
+ // TRANSLATORS: storage button
+ mRetrieveButton = new Button(this, _("Retrieve"), "retrieve", this);
+ // TRANSLATORS: storage button
+ mInvCloseButton = new Button(this, _("Close"), "close", this);
+
+ mSlotsBarCell = &place(0, 0, mSlotsBar, 6);
+ mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
+
+ mFilterCell = &place(0, 1, mFilter, 7).setPadding(3);
+ mNameFilterCell = &place(6, 1, mNameFilter, 1);
+
+ place(0, 2, invenScroll, 7, 4);
+ place(0, 6, mStoreButton);
+ place(1, 6, mRetrieveButton);
+ place(6, 6, mInvCloseButton);
+ break;
+ }
- mFilterCell = &place(0, 1, mFilter, 7).setPadding(3);
- mNameFilterCell = &place(6, 1, mNameFilter, 1);
+ case Inventory::CART:
+ {
+ // TRANSLATORS: storage button
+ mStoreButton = new Button(this, _("Store"), "store", this);
+ // TRANSLATORS: storage button
+ mRetrieveButton = new Button(this, _("Retrieve"), "retrieve", this);
+ // TRANSLATORS: storage button
+ mInvCloseButton = new Button(this, _("Close"), "close", this);
+
+ mSlotsBarCell = &place(0, 0, mSlotsBar, 6);
+ mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
+
+ mFilterCell = &place(0, 1, mFilter, 7).setPadding(3);
+ mNameFilterCell = &place(6, 1, mNameFilter, 1);
+
+ place(0, 2, invenScroll, 7, 4);
+ place(0, 6, mStoreButton);
+ place(1, 6, mRetrieveButton);
+ place(6, 6, mInvCloseButton);
+ break;
+ }
- place(0, 2, invenScroll, 7, 4);
- place(0, 6, mStoreButton);
- place(1, 6, mRetrieveButton);
- place(6, 6, mInvCloseButton);
- }
+ default:
+ case Inventory::TRADE:
+ case Inventory::NPC:
+ break;
+ };
Layout &layout = getLayout();
layout.setRowHeight(2, LayoutType::SET);
@@ -270,7 +310,7 @@ void InventoryWindow::postInit()
mItems->setSortType(mSortDropDown->getSelected());
widgetResized(Event(nullptr));
- if (!isMainInventory())
+ if (mInventory->getType() == Inventory::INVENTORY)
setVisible(true);
}
@@ -293,7 +333,6 @@ void InventoryWindow::storeSortOrder() const
switch (mInventory->getType())
{
case Inventory::INVENTORY:
- case Inventory::CART:
case Inventory::TRADE:
case Inventory::NPC:
default:
@@ -304,6 +343,10 @@ void InventoryWindow::storeSortOrder() const
config.setValue("storageSortOrder",
mSortDropDown->getSelected());
break;
+ case Inventory::CART:
+ config.setValue("cartSortOrder",
+ mSortDropDown->getSelected());
+ break;
};
}
}
@@ -323,6 +366,10 @@ void InventoryWindow::action(const ActionEvent &event)
{
inputManager.executeAction(InputAction::WINDOW_EQUIPMENT);
}
+ else if (eventId == "cart")
+ {
+ inputManager.executeAction(InputAction::WINDOW_CART);
+ }
else if (eventId == "close")
{
close();
@@ -662,18 +709,26 @@ void InventoryWindow::setSplitAllowed(const bool allowed)
void InventoryWindow::close()
{
- if (this == inventoryWindow)
- {
- setVisible(false);
- }
- else
+ switch (mInventory->getType())
{
- if (inventoryHandler)
- {
- inventoryHandler->closeStorage(Inventory::STORAGE);
- inventoryHandler->forgotStorage();
- }
- scheduleDelete();
+ case Inventory::INVENTORY:
+ case Inventory::CART:
+ setVisible(false);
+ break;
+
+ case Inventory::STORAGE:
+ if (inventoryHandler)
+ {
+ inventoryHandler->closeStorage(Inventory::STORAGE);
+ inventoryHandler->forgotStorage();
+ }
+ scheduleDelete();
+ break;
+
+ default:
+ case Inventory::TRADE:
+ case Inventory::NPC:
+ break;
}
}