drag fixes
This commit is contained in:
parent
53ead20de5
commit
71c706157a
|
@ -53,9 +53,11 @@ end
|
||||||
function UIItem:onHoverChange(hovered)
|
function UIItem:onHoverChange(hovered)
|
||||||
if self:isVirtual() then return end
|
if self:isVirtual() then return end
|
||||||
|
|
||||||
local dragginWidget = g_ui.getDraggingWidget()
|
local draggingWidget = g_ui.getDraggingWidget()
|
||||||
if dragginWidget and self ~= dragginWidget then
|
if draggingWidget and self ~= draggingWidget then
|
||||||
if dragginWidget:getClassName() == 'UIItem' and not dragginWidget:isVirtual() and hovered 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)
|
self:setBorderWidth(1)
|
||||||
else
|
else
|
||||||
self:setBorderWidth(0)
|
self:setBorderWidth(0)
|
||||||
|
|
|
@ -11,7 +11,7 @@ function UIMap:onDragEnter(mousePos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIMap:onDragLeave(widget, mousePos)
|
function UIMap:onDragLeave(droppedWidget, mousePos)
|
||||||
if not self.parsed then
|
if not self.parsed then
|
||||||
self.currentDragThing = nil
|
self.currentDragThing = nil
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ function UIMap:onDrop(widget, mousePos)
|
||||||
if not tile then return false end
|
if not tile then return false end
|
||||||
|
|
||||||
local count = widget.currentDragThing:getCount()
|
local count = widget.currentDragThing:getCount()
|
||||||
if widget.currentDragThing:isStackable() and data > 1 then
|
if widget.currentDragThing:isStackable() and count > 1 then
|
||||||
widget.parsed = true
|
widget.parsed = true
|
||||||
local moveWindow = displayUI('/game/movewindow.otui')
|
local moveWindow = displayUI('/game/movewindow.otui')
|
||||||
local spinbox = moveWindow:getChildById('spinbox')
|
local spinbox = moveWindow:getChildById('spinbox')
|
||||||
|
|
|
@ -83,13 +83,11 @@ void UIManager::inputEvent(const InputEvent& event)
|
||||||
auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos);
|
auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos);
|
||||||
UIWidgetPtr droppedWidget;
|
UIWidgetPtr droppedWidget;
|
||||||
for(const UIWidgetPtr& child : clickedChildren) {
|
for(const UIWidgetPtr& child : clickedChildren) {
|
||||||
if(child != m_draggingWidget) {
|
if(child->onDrop(m_draggingWidget, event.mousePos)) {
|
||||||
droppedWidget = child;
|
droppedWidget = child;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(droppedWidget)
|
|
||||||
droppedWidget->onDrop(m_draggingWidget, event.mousePos);
|
|
||||||
|
|
||||||
m_draggingWidget->onDragLeave(droppedWidget, event.mousePos);
|
m_draggingWidget->onDragLeave(droppedWidget, event.mousePos);
|
||||||
m_draggingWidget->setDragging(false);
|
m_draggingWidget->setDragging(false);
|
||||||
|
|
|
@ -1156,9 +1156,9 @@ bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
|
||||||
return callLuaField("onDragMove", mousePos, 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)
|
bool UIWidget::onKeyText(const std::string& keyText)
|
||||||
|
|
|
@ -177,7 +177,7 @@ protected:
|
||||||
virtual void onDragEnter(const Point& mousePos);
|
virtual void onDragEnter(const Point& mousePos);
|
||||||
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
||||||
virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
|
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 onKeyText(const std::string& keyText);
|
||||||
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
|
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
|
||||||
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
||||||
|
|
Loading…
Reference in New Issue