drag fixes

This commit is contained in:
Eduardo Bart 2012-02-07 00:06:48 -02:00
parent 53ead20de5
commit 71c706157a
5 changed files with 11 additions and 11 deletions

View File

@ -53,9 +53,11 @@ end
function UIItem:onHoverChange(hovered)
if self:isVirtual() then return end
local dragginWidget = g_ui.getDraggingWidget()
if dragginWidget and self ~= dragginWidget then
if dragginWidget:getClassName() == 'UIItem' and not dragginWidget:isVirtual() and hovered then
local draggingWidget = g_ui.getDraggingWidget()
if draggingWidget and self ~= draggingWidget then
local gotMap = draggingWidget:getClassName() == 'UIMap'
local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
if hovered and (gotItem or gotMap) then
self:setBorderWidth(1)
else
self:setBorderWidth(0)

View File

@ -11,7 +11,7 @@ function UIMap:onDragEnter(mousePos)
return true
end
function UIMap:onDragLeave(widget, mousePos)
function UIMap:onDragLeave(droppedWidget, mousePos)
if not self.parsed then
self.currentDragThing = nil
end
@ -27,7 +27,7 @@ function UIMap:onDrop(widget, mousePos)
if not tile then return false end
local count = widget.currentDragThing:getCount()
if widget.currentDragThing:isStackable() and data > 1 then
if widget.currentDragThing:isStackable() and count > 1 then
widget.parsed = true
local moveWindow = displayUI('/game/movewindow.otui')
local spinbox = moveWindow:getChildById('spinbox')

View File

@ -83,13 +83,11 @@ void UIManager::inputEvent(const InputEvent& event)
auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos);
UIWidgetPtr droppedWidget;
for(const UIWidgetPtr& child : clickedChildren) {
if(child != m_draggingWidget) {
if(child->onDrop(m_draggingWidget, event.mousePos)) {
droppedWidget = child;
break;
}
}
if(droppedWidget)
droppedWidget->onDrop(m_draggingWidget, event.mousePos);
m_draggingWidget->onDragLeave(droppedWidget, event.mousePos);
m_draggingWidget->setDragging(false);

View File

@ -1156,9 +1156,9 @@ bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
return callLuaField("onDragMove", mousePos, mouseMoved);
}
void UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
bool UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
{
callLuaField("onDrop", draggedWidget, mousePos);
return callLuaField<bool>("onDrop", draggedWidget, mousePos);
}
bool UIWidget::onKeyText(const std::string& keyText)

View File

@ -177,7 +177,7 @@ protected:
virtual void onDragEnter(const Point& mousePos);
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
virtual bool onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
virtual bool onKeyText(const std::string& keyText);
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);