diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/palette.cpp | 11 | ||||
-rw-r--r-- | src/gui/palette.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 4 | ||||
-rw-r--r-- | src/gui/windowmenu.cpp | 6 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 51 | ||||
-rw-r--r-- | src/gui/windows/inventorywindow.h | 6 | ||||
-rw-r--r-- | src/gui/windows/maileditwindow.cpp | 62 | ||||
-rw-r--r-- | src/gui/windows/mailviewwindow.cpp | 17 | ||||
-rw-r--r-- | src/gui/windows/mailviewwindow.h | 8 | ||||
-rw-r--r-- | src/gui/windows/mailwindow.cpp | 54 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/whoisonline.cpp | 27 |
14 files changed, 158 insertions, 97 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index f0f97b6f1..36fde8761 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -41,7 +41,7 @@ const Color Palette::BLACK = Color(0, 0, 0, 255); Palette::Palettes Palette::mInstances; -const Color Palette::RAINBOW_COLORS[7] = +const Color Palette::RAINBOW_COLORS[] = { Color(255, 0, 0, 255), Color(255, 153, 0, 255), @@ -52,8 +52,6 @@ const Color Palette::RAINBOW_COLORS[7] = Color(153, 0, 153, 255) }; -const int Palette::RAINBOW_COLOR_COUNT = 7; - Palette::Palette(const int size) : mRainbowTime(tick_time), mColors(Colors(size)), @@ -111,7 +109,7 @@ void Palette::advanceGradient() const int numOfColors = (elem->grad == GradientType::SPECTRUM ? 6 : grad == GradientType::PULSE ? 127 : - RAINBOW_COLOR_COUNT); + NUM_ELEMENTS(RAINBOW_COLORS)); elem->gradientIndex = (elem->gradientIndex + advance) % (delay * numOfColors); @@ -177,8 +175,9 @@ void Palette::advanceGradient() else if (elem->grad == GradientType::RAINBOW) { const Color &startCol = RAINBOW_COLORS[colIndex]; - const Color &destCol - = RAINBOW_COLORS[(colIndex + 1) % numOfColors]; + const int destIndex + = (colIndex + 1) % NUM_ELEMENTS(RAINBOW_COLORS); + const Color &destCol = RAINBOW_COLORS[destIndex]; double startColVal; double destColVal; diff --git a/src/gui/palette.h b/src/gui/palette.h index afd4a0456..3a56c3d97 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -79,7 +79,6 @@ class Palette notfinal protected: /** Colors used for the rainbow gradient */ static const Color RAINBOW_COLORS[7]; - static const int RAINBOW_COLOR_COUNT; /** Time tick, that gradient-type colors were updated the last time. */ int mRainbowTime; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 0092221c7..0e1bfda59 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -864,7 +864,7 @@ void ItemContainer::mouseReleased(MouseEvent &event) if (index == mSelectedIndex || mSelectedIndex == -1) return; if (inventoryWindow != nullptr) - inventoryWindow->combineItems(index, mSelectedIndex); + inventoryWindow->combineItems(mSelectedIndex, index); return; } else if (src == DragDropSource::Cart && diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index 5129b1f88..dcf286bcf 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -217,8 +217,8 @@ void Setup_Colors::action(const ActionEvent &event) const std::string &eventId = event.getId(); if (eventId == "slider_grad") { - updateGradType(); updateColor(); + updateGradType(); return; } diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 3b4843cac..5eb4df526 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -441,8 +441,8 @@ class Window notfinal : public BasicContainer2, LayoutCell &place(const int x, const int y, Widget *const wg, - const int w, - const int h); + const int w = 1, + const int h = 1); /** * Returns a proxy for adding widgets in an inner table of the layout. diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index fa64a34e3..64a70ea58 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -150,7 +150,7 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : 11, // TRANSLATORS: long button name for cart window. _("Cart"), x, h, InputAction::WINDOW_CART, - Visible_true); + Visible_false); // TRANSLATORS: short button name for map window. addButton(N_("MAP"), 19, @@ -233,7 +233,7 @@ WindowMenu::WindowMenu(const Widget2 *const widget) : 4, // TRANSLATORS: long button name for clan window. _("Clan"), x, h, InputAction::WINDOW_CLAN, - Visible_true); + Visible_false); // TRANSLATORS: short button name for server info window. addButton(N_("SI"), 8, @@ -490,6 +490,8 @@ void WindowMenu::updateButtons() void WindowMenu::loadButtons() { + // windowmenu<N> -> <button text> config keys tell which buttons are + // hidden. This overrides default visibility set in constructor. if (!mSmallWindow) { if (config.getValue("windowmenu0", "").empty()) diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index ef6cee215..5681e8e04 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -1137,38 +1137,53 @@ void InventoryWindow::attributeChanged(const AttributesT id, } } -void InventoryWindow::combineItems(const int index1, - const int index2) +void InventoryWindow::combineItems(const int srcIndex, + const int dstIndex) { if (mInventory == nullptr) return; - const Item *item1 = mInventory->getItem(index1); - if (item1 == nullptr) + const Item *srcItem = mInventory->getItem(srcIndex); + if (srcItem == nullptr) return; - const Item *item2 = mInventory->getItem(index2); - if (item2 == nullptr) + const Item *dstItem = mInventory->getItem(dstIndex); + if (dstItem == nullptr) return; - if (item1->getType() != ItemType::Card) - { - const Item *tmpItem = item1; - item1 = item2; - item2 = tmpItem; - } + // Build up a total all-that-could-go-wrong list of messages. (note: + // this is a small subset of all the checks that hercules does). + // This way insertion will continue to work even if server removes + // some checks (I would prefer if the server sent failure messages + // itself, but it fails silently). + std::string question + = strprintf( + // TRANSLATORS: question dialog message + _("Insert %s into %s?"), + srcItem->getName().c_str(), + dstItem->getName().c_str()); + + if (srcItem->getType() != ItemType::Card) + // TRANSLATORS: failure reason appended to card insert question + (question += ' ') += _(" Item to be inserted may not be insertable."); + + if (dstItem->isEquipped() == Equipped_true) + // TRANSLATORS: failure reason appended to card insert question + (question += ' ') += _(" Destination item is equipped."); + + if (dstItem->isEquipment() == Equipm_false) + // TRANSLATORS: failure reason appended to card insert question + (question += " ") += _("Inserting into non-equipment items may fail."); ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog, // TRANSLATORS: question dialog title _("Insert card request"), - // TRANSLATORS: question dialog message - strprintf(_("Insert %s into %s?"), - item1->getName().c_str(), - item2->getName().c_str()), + question, SOUND_REQUEST, false, Modal_true, nullptr); - insertCardListener.itemIndex = item2->getInvIndex(); - insertCardListener.cardIndex = item1->getInvIndex(); + + insertCardListener.itemIndex = dstItem->getInvIndex(); + insertCardListener.cardIndex = srcItem->getInvIndex(); confirmDlg->addActionListener(&insertCardListener); } diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h index 96698d72f..0f4c13b46 100644 --- a/src/gui/windows/inventorywindow.h +++ b/src/gui/windows/inventorywindow.h @@ -158,8 +158,10 @@ class InventoryWindow final : public Window, const int64_t oldVal, const int64_t newVal) override final; - void combineItems(const int index1, - const int index2); + /* + * Attempt inserting one item (card) into another + */ + void combineItems(const int srcIndex, const int dstIndex); void moveItemToCraft(const int craftSlot); diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp index e7fad6aab..bc2574c64 100644 --- a/src/gui/windows/maileditwindow.cpp +++ b/src/gui/windows/maileditwindow.cpp @@ -25,6 +25,8 @@ #include "being/playerinfo.h" +#include "enums/gui/layouttype.h" + #include "gui/windows/inventorywindow.h" #include "gui/windows/itemamountwindow.h" @@ -33,6 +35,7 @@ #include "gui/widgets/inttextfield.h" #include "gui/widgets/itemcontainer.h" #include "gui/widgets/label.h" +#include "gui/widgets/layout.h" #include "gui/widgets/scrollarea.h" #include "resources/item/item.h" @@ -67,7 +70,7 @@ MailEditWindow::MailEditWindow() : // TRANSLATORS: mail edit window label mMoneyLabel(new Label(this, _("Money:"))), // TRANSLATORS: mail edit window label - mItemLabel(new Label(this, _("Item:"))), + mItemLabel(new Label(this, _("Items:"))), // TRANSLATORS: mail edit window label mMessageLabel(new Label(this, _("Message:"))), mToField(new TextField(this, std::string(), LoseFocusOnTab_true, @@ -95,35 +98,46 @@ MailEditWindow::MailEditWindow() : setStickyButtonLock(true); setVisible(Visible_true); - setDefaultSize(380, 200, ImagePosition::CENTER, 0, 0); - setMinWidth(200); - setMinHeight(200); - center(); - - ContainerPlacer placer(nullptr, nullptr); - placer = getPlacer(0, 0); - mToField->setWidth(100); mSubjectField->setWidth(100); mMessageField->setWidth(100); - mItemScrollArea->setHeight(100); + // 1x3 items (current ML limit) times some padding + // + a handful of pixels to cover scrollbar/padding + mItemScrollArea->setHeight(43); // same as itemcontainer default + mItemScrollArea->setWidth(3 * (32 + 2) + 5 + 10); mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mToField->addFocusListener(this); - placer(0, 0, mToLabel, 1, 1); - placer(1, 0, mToField, 3, 1); - placer(0, 1, mSubjectLabel, 1, 1); - placer(1, 1, mSubjectField, 3, 1); - placer(0, 2, mMoneyLabel, 1, 1); - placer(1, 2, mMoneyField, 3, 1); - placer(0, 3, mItemLabel, 1, 1); - placer(1, 3, mItemScrollArea, 2, 2); - placer(3, 4, mAddButton, 1, 1); - - placer(0, 5, mMessageLabel, 1, 1); - placer(1, 5, mMessageField, 3, 1); - placer(0, 6, mSendButton, 1, 1); - placer(3, 6, mCloseButton, 1, 1); + place(0, 0, mToLabel); + place(1, 0, mToField, 2, 1); + place(0, 1, mSubjectLabel); + place(1, 1, mSubjectField, 2, 1); + place(0, 2, mMoneyLabel); + place(1, 2, mMoneyField, 2, 1); + place(0, 3, mItemLabel); + place(1, 3, mItemScrollArea, 1, 2); + place(2, 4, mAddButton); + + place(0, 5, mMessageLabel); + place(1, 5, mMessageField, 2, 1); + place(0, 6, mSendButton); + place(2, 6, mCloseButton); + + Layout &layout = getLayout(); + // mid column shall eat all remaining available window space. + layout.setColWidth(1, LayoutType::SET); + layout.setRowHeight(3, LayoutType::SET); + + // Enforce a minimum size. + int width = 0; + int height = 0; + layout.reflow(width, height); + setContentSize(width, height); + + setMinWidth(getWidth()); + setMinHeight(getHeight()); + setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER, 0, 0); + center(); loadWindowState(); if (mUseMail2) diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp index e534ce4b4..bddd03f74 100644 --- a/src/gui/windows/mailviewwindow.cpp +++ b/src/gui/windows/mailviewwindow.cpp @@ -50,7 +50,7 @@ MailViewWindow *mailViewWindow = nullptr; MailViewWindow::MailViewWindow(MailMessage *const message, const int itemsCount) : // TRANSLATORS: mail view window name - Window(_("View mail"), Modal_false, nullptr, "mailview.xml"), + Window(_("View Mail"), Modal_false, nullptr, "mailview.xml"), ActionListener(), mMessage(message), mGetAttachButton(new Button(this, @@ -153,6 +153,8 @@ MailViewWindow::~MailViewWindow() { if (mUseMail2) { + if (mDeleted) + delete mMessage; mMessage = nullptr; } else @@ -282,3 +284,16 @@ void MailViewWindow::removeMoney(const int64_t mailId) if (mailWindow != nullptr) mailWindow->refreshMailNames(); } + +bool MailViewWindow::notifyDeleteAndTransferOwnership(const int64_t mailId) +{ + if (mailId != mMessage->id) + return false; + setCaption("View Mail (DELETED)"); + mDeleted = true; + // this mail's ID no longer exists, so it no longer has a defined + // predecessor or successor. + mPrevButton->setEnabled(false); + mNextButton->setEnabled(false); + return true; +} diff --git a/src/gui/windows/mailviewwindow.h b/src/gui/windows/mailviewwindow.h index e275a55ed..edb939b33 100644 --- a/src/gui/windows/mailviewwindow.h +++ b/src/gui/windows/mailviewwindow.h @@ -55,6 +55,13 @@ class MailViewWindow final : public Window, void removeMoney(const int64_t mailId); + /** + * notify view window that mail has been deleted. + * MailViewWindow will delete the message when it is destroyed. + * returns true if mailId is the one being viewed (and thus ownership + * was transfered). + */ + bool notifyDeleteAndTransferOwnership(const int64_t mailId); private: void updateAttachButton(); @@ -75,6 +82,7 @@ class MailViewWindow final : public Window, ItemContainer *mItemContainer; ScrollArea *mItemScrollArea; bool mUseMail2; + bool mDeleted = false; }; extern MailViewWindow *mailViewWindow; diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp index da5192aee..cd3c8c6cf 100644 --- a/src/gui/windows/mailwindow.cpp +++ b/src/gui/windows/mailwindow.cpp @@ -92,25 +92,38 @@ MailWindow::MailWindow() : if (setupWindow != nullptr) setupWindow->registerWindowForReset(this); - setDefaultSize(310, 180, ImagePosition::CENTER, 0, 0); - setMinWidth(310); - setMinHeight(250); - center(); - + // use line wrapping of mail subjects, instead. mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); - - ContainerPlacer placer(nullptr, nullptr); - placer = getPlacer(0, 0); - - placer(0, 0, mListScrollArea, 4, 5).setPadding(3); - placer(4, 0, mRefreshButton, 1, 1); - placer(4, 1, mOpenButton, 1, 1); - placer(4, 2, mNewButton, 1, 1); - placer(4, 3, mDeleteButton, 1, 1); - placer(4, 4, mReturnButton, 1, 1); + // set reasonable minimum width for calculations below + mListScrollArea->setWidth(200); + + // at 0,0 and spawns/spans 4 columns and 6 rows + place(0, 0, mListScrollArea, 1, 6).setPadding(3); + // at column 5 and row 0... + place(1, 0, mRefreshButton, 1, 1); + place(1, 1, mOpenButton, 1, 1); + place(1, 2, mNewButton, 1, 1); + // Leave intentional gap in grid so that the button column (and thus, + // the whole window) can be resized without resizing any of the buttons. + // note: the empty cell still seems to enforce some padding, but this + // is fine. + place(1, 4, mDeleteButton, 1, 1); + place(1, 5, mReturnButton, 1, 1); Layout &layout = getLayout(); - layout.setRowHeight(0, LayoutType::SET); + // scrollarea column and 4th row eat all remaining available screen space. + layout.setColWidth(0, LayoutType::SET); + layout.setRowHeight(3, LayoutType::SET); + + // Enforce a minimum size. + int width = 0; + int height = 0; + layout.reflow(width, height); + setContentSize(width, height); + setMinWidth(getWidth()); + setMinHeight(getHeight()); + setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER, 0, 0); + center(); loadWindowState(); enableVisibleSound(true); @@ -244,7 +257,14 @@ void MailWindow::removeMail(const int64_t id) if ((message != nullptr) && message->id == id) { mMessages.erase(it); - delete message; + // passes ownership of message pointer to mailViewWindow, + // which will signal to reader that the mail is deleted and + // will do the final delete of the message upon destruction. + if (mailViewWindow == nullptr || + !mailViewWindow->notifyDeleteAndTransferOwnership(id)) + { + delete message; + } break; } } diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index 85e2c9dbf..9c5636bea 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -88,9 +88,7 @@ Minimap::Minimap() : setDefaultVisible(true); setSaveVisible(true); - - setStickyButton(true); - setSticky(false); + setStickyButtonLock(true); loadWindowState(); setVisible(fromBool(mShow, Visible), isSticky()); diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index 8417e5dc8..2cb1c1e16 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -251,33 +251,22 @@ void WhoIsOnline::updateWindow(size_t numOnline) std::sort(mFriends.begin(), mFriends.end(), nameCompare); std::sort(mNeutral.begin(), mNeutral.end(), nameCompare); std::sort(mDisregard.begin(), mDisregard.end(), nameCompare); - bool addedFromSection(false); FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mFriends) - { mBrowserBox->addRow((*it)->getText(), false); - addedFromSection = true; - } - if (addedFromSection == true) - { + + if (!mFriends.empty()) mBrowserBox->addRow("---", false); - addedFromSection = false; - } + FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mEnemy) - { mBrowserBox->addRow((*it)->getText(), false); - addedFromSection = true; - } - if (addedFromSection == true) - { + + if (!mEnemy.empty()) mBrowserBox->addRow("---", false); - addedFromSection = false; - } + FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mNeutral) - { mBrowserBox->addRow((*it)->getText(), false); - addedFromSection = true; - } - if (addedFromSection == true && !mDisregard.empty()) + + if (!mNeutral.empty() && !mDisregard.empty()) mBrowserBox->addRow("---", false); FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mDisregard) |