ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, int maxRange): Window("", true, parent), mItem(item), mMax(maxRange), mUsage(usage) { if (!mMax) mMax = mItem->getQuantity(); // Save keyboard state mEnabledKeyboard = keyboard.isEnabled(); keyboard.setEnabled(false); // Integer field mItemAmountTextField = new IntTextField(1); mItemAmountTextField->setRange(1, mMax); mItemAmountTextField->setWidth(35); mItemAmountTextField->addKeyListener(this); // Slider mItemAmountSlide = new Slider(1.0, mMax); mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("slide"); mItemAmountSlide->addActionListener(this); //Item icon Image *image = item->getImage(); mItemIcon = new Icon(image); // Buttons Button *minusButton = new Button(_("-"), "dec", this); Button *plusButton = new Button(_("+"), "inc", this); Button *okButton = new Button(_("OK"), "ok", this); Button *cancelButton = new Button(_("Cancel"), "cancel", this); Button *addAllButton = new Button(_("All"), "all", this); minusButton->adjustSize(); minusButton->setWidth(plusButton->getWidth()); // Set positions ContainerPlacer place; place = getPlacer(0, 0); place(1, 0, minusButton); place(2, 0, mItemAmountTextField); place(3, 0, plusButton); place(4, 0, addAllButton); place(0, 0, mItemIcon, 1, 3); place(1, 1, mItemAmountSlide, 5); place(4, 2, cancelButton); place(5, 2, okButton); reflowLayout(225, 0); resetAmount(); switch (usage) { case TradeAdd: setCaption(_("Select amount of items to trade.")); break; case ItemDrop: setCaption(_("Select amount of items to drop.")); break; case StoreAdd: setCaption(_("Select amount of items to store.")); break; case StoreRemove: setCaption(_("Select amount of items to retrieve.")); break; case ItemSplit: setCaption(_("Select amount of items to split.")); break; } setLocationRelativeTo(getParentWindow()); setVisible(true); mItemPopup = new ItemPopup; mItemIcon->addMouseListener(this); }
ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, int maxRange): Window("", true, parent, "amount.xml"), mItemPriceTextField(nullptr), mGPLabel(nullptr), mItem(item), mMax(maxRange), mUsage(usage), mItemPriceSlide(nullptr), mItemsModal(nullptr), mPrice(0) { if (!mItem) { setVisible(false); return; } if (usage == ShopBuyAdd) mMax = 10000; else if (!mMax) mMax = mItem->getQuantity(); // Save keyboard state mEnabledKeyboard = keyboard.isEnabled(); keyboard.setEnabled(false); // Integer field mItemAmountTextField = new IntTextField(1); mItemAmountTextField->setRange(1, mMax); mItemAmountTextField->setWidth(35); mItemAmountTextField->addKeyListener(this); // Slider mItemAmountSlide = new Slider(1.0, mMax); mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("slide"); mItemAmountSlide->addActionListener(this); if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) { // Integer field mItemPriceTextField = new IntTextField(1); mItemPriceTextField->setRange(1, 10000000); mItemPriceTextField->setWidth(35); mItemPriceTextField->addKeyListener(this); // Slider mItemPriceSlide = new Slider(1.0, 10000000); mItemPriceSlide->setHeight(10); mItemPriceSlide->setActionEventId("slidePrice"); mItemPriceSlide->addActionListener(this); mGPLabel = new Label(" GP"); } if (mUsage == ShopBuyAdd) { mItemsModal = new ItemsModal; mItemDropDown = new DropDown(mItemsModal); mItemDropDown->setActionEventId("itemType"); mItemDropDown->addActionListener(this); } //Item icon Image *image = item->getImage(); mItemIcon = new Icon(image); // Buttons Button *minusAmountButton = new Button(_("-"), "dec", this); Button *plusAmountButton = new Button(_("+"), "inc", this); Button *okButton = new Button(_("OK"), "ok", this); Button *cancelButton = new Button(_("Cancel"), "cancel", this); Button *addAllButton = new Button(_("All"), "all", this); minusAmountButton->adjustSize(); minusAmountButton->setWidth(plusAmountButton->getWidth()); // Set positions ContainerPlacer placer; placer = getPlacer(0, 0); int n = 0; if (mUsage == ShopBuyAdd) { placer(0, n, mItemDropDown, 8); n++; } placer(1, n, minusAmountButton); placer(2, n, mItemAmountTextField, 3); placer(5, n, plusAmountButton); placer(6, n, addAllButton); placer(0, n, mItemIcon, 1, 3); placer(1, n + 1, mItemAmountSlide, 7); if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd) { Button *minusPriceButton = new Button(_("-"), "decPrice", this); Button *plusPriceButton = new Button(_("+"), "incPrice", this); minusPriceButton->adjustSize(); minusPriceButton->setWidth(plusPriceButton->getWidth()); placer(1, n + 2, minusPriceButton); placer(2, n + 2, mItemPriceTextField, 3); placer(5, n + 2, plusPriceButton); placer(6, n + 2, mGPLabel); placer(1, n + 3, mItemPriceSlide, 7); placer(4, n + 5, cancelButton); placer(5, n + 5, okButton); } else { placer(4, n + 2, cancelButton); placer(5, n + 2, okButton); } reflowLayout(225, 0); resetAmount(); switch (usage) { case TradeAdd: setCaption(_("Select amount of items to trade.")); break; case ItemDrop: setCaption(_("Select amount of items to drop.")); break; case StoreAdd: setCaption(_("Select amount of items to store.")); break; case StoreRemove: setCaption(_("Select amount of items to retrieve.")); break; case ItemSplit: setCaption(_("Select amount of items to split.")); break; case ShopBuyAdd: setCaption(_("Add to buy shop.")); break; case ShopSellAdd: setCaption(_("Add to sell shop.")); break; default: setCaption(_("Unknown.")); break; } setLocationRelativeTo(getParentWindow()); setVisible(true); mItemPopup = new ItemPopup; mItemIcon->addMouseListener(this); }