diff options
-rw-r--r-- | src/dragdrop.h | 32 | ||||
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/gui/gui.h | 3 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 64 |
4 files changed, 95 insertions, 7 deletions
diff --git a/src/dragdrop.h b/src/dragdrop.h index 845420968..2405b151e 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -24,6 +24,8 @@ #include "item.h" #include "textcommand.h" +#include "gui/widgets/skillinfo.h" + #include "resources/image.h" #include "localconsts.h" @@ -37,6 +39,7 @@ enum DragDropSource DRAGDROP_SOURCE_TRADE, DRAGDROP_SOURCE_OUTFIT, DRAGDROP_SOURCE_SPELLS, + DRAGDROP_SOURCE_SKILLS, DRAGDROP_SOURCE_GROUND, DRAGDROP_SOURCE_DROP, DRAGDROP_SOURCE_SHORTCUTS, @@ -127,7 +130,7 @@ class DragDrop } else if (mText.empty()) { - mSource = DRAGDROP_SOURCE_EMPTY; + mSource = source; mTag = 0; return; } @@ -141,6 +144,33 @@ class DragDrop mTag = tag; } + void dragSkill(const SkillInfo *const info, + const DragDropSource source, + const int tag = 0) + { + if (mItemImage) + mItemImage->decRef(); + mItem = 0; + mItemColor = 1; + mText.clear(); + mItemImage = nullptr; + mSource = DRAGDROP_SOURCE_EMPTY; + mTag = 0; + if (info) + { + const SkillData *const data = info->data; + if (data) + { + mText = data->name; + mItemImage = data->icon; + if (mItemImage) + mItemImage->incRef(); + mSource = source; + mTag = tag; + } + } + } + void clear() { if (mItemImage) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index debbe342f..1032e7e4e 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -95,6 +95,8 @@ Gui::Gui(Graphics *const graphics) : mLastMouseRealY(0), #endif mFocusListeners(), + mForegroundColor(Theme::getThemeColor(Theme::TEXT)), + mForegroundColor2(Theme::getThemeColor(Theme::TEXT_OUTLINE)), mCustomCursor(false) { logger->log1("Initializing GUI..."); @@ -449,6 +451,7 @@ void Gui::draw() { const int posX = mouseX - mGuiFont->getWidth(str) / 2; const int posY = mouseY + (image ? image->mBounds.h / 2 : 0); + g2->setColorAll(mForegroundColor, mForegroundColor2); mGuiFont->drawString(g2, str, posX, posY); } } diff --git a/src/gui/gui.h b/src/gui/gui.h index 94dbf638f..129dedfce 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -26,6 +26,7 @@ #include "resources/cursor.h" #include "resources/image.h" +#include <guichan/color.hpp> #include <guichan/focuslistener.hpp> #include <guichan/gui.hpp> @@ -182,6 +183,8 @@ class Gui final : public gcn::Gui typedef std::list<gcn::FocusListener*> FocusListenerList; typedef FocusListenerList::iterator FocusListenerIterator; FocusListenerList mFocusListeners; + gcn::Color mForegroundColor; + gcn::Color mForegroundColor2; bool mCustomCursor; /**< Show custom cursor */ }; diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 6365efcd8..d6fc3656c 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,6 +22,8 @@ #include "gui/skilldialog.h" +#include "dragdrop.h" + #include "gui/widgets/skillmodel.h" #include "debug.h" @@ -40,7 +42,8 @@ class SkillListBox final : public ListBox mTextColor2(getThemeColor(Theme::TEXT_OUTLINE)), mTextPadding(mSkin ? mSkin->getOption("textPadding", 34) : 34), mSpacing(mSkin ? mSkin->getOption("spacing", 0) : 0), - mRowHeight(getFont()->getHeight() * 2 + mSpacing + 2 * mPadding) + mRowHeight(getFont()->getHeight() * 2 + mSpacing + 2 * mPadding), + mSkillClicked(false) { if (mRowHeight < 34) mRowHeight = 34; @@ -127,16 +130,24 @@ class SkillListBox final : public ListBox unsigned int getRowHeight() const override { return mRowHeight; } + const SkillInfo *getSkillByEvent(const gcn::MouseEvent &event) const + { + const int y = (event.getY() + mPadding) / getRowHeight(); + if (!mModel || y >= mModel->getNumberOfElements()) + return nullptr; + const SkillInfo *const skill = mModel->getSkillAt(y); + if (!skill) + return nullptr; + return skill; + } + void mouseMoved(gcn::MouseEvent &event) override { ListBox::mouseMoved(event); - if (!viewport) + if (!viewport || !dragDrop.isEmpty()) return; - const int y = (event.getY() + mPadding) / getRowHeight(); - if (!mModel || y >= mModel->getNumberOfElements()) - return; - const SkillInfo *const skill = mModel->getSkillAt(y); + const SkillInfo *const skill = getSkillByEvent(event); if (!skill) return; @@ -144,6 +155,46 @@ class SkillListBox final : public ListBox skill->data->dispName, skill->data->description); } + void mouseDragged(gcn::MouseEvent &event) + { + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (dragDrop.isEmpty()) + { + if (mSkillClicked) + { + mSkillClicked = false; + const SkillInfo *const skill = getSkillByEvent(event); + if (!skill) + return; + dragDrop.dragSkill(skill, DRAGDROP_SOURCE_SKILLS); + } + ListBox::mouseDragged(event); + } + } + else + { + ListBox::mouseDragged(event); + } + } + + void mousePressed(gcn::MouseEvent &event) + { + ListBox::mousePressed(event); + if (event.getButton() == gcn::MouseEvent::LEFT) + { + const SkillInfo *const skill = getSkillByEvent(event); + if (!skill) + return; + mSkillClicked = true; + } + } + + void mouseReleased(gcn::MouseEvent &event) + { + ListBox::mouseReleased(event); + } + void mouseExited(gcn::MouseEvent &event A_UNUSED) override { mPopup->hide(); @@ -158,6 +209,7 @@ class SkillListBox final : public ListBox int mTextPadding; int mSpacing; int mRowHeight; + bool mSkillClicked; }; class SkillTab final : public Tab |