Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion data/styles/10-items.otui
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,10 @@ MainInventoryItem < UIWidget
focusable: false
visible: false
image-smooth: true


UIDragIcon < UIItem
size: 34 34
border-color: alpha
virtual: true
focusable: false
phantom: true
3 changes: 3 additions & 0 deletions modules/client_options/data_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ return {
panels.gameMapPanel:setDrawHighlightTarget(value)
end
},
showDragIcon = {
value = true,
},
antialiasingMode = {
value = 1,
action = function(value, options, controller, panels, extraWidgets)
Expand Down
11 changes: 11 additions & 0 deletions modules/client_options/styles/interface/interface.otui
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ UIWidget
id: enableHighlightMouseTarget
!text: tr('Highlight mouse target')

SmallReversedQtPanel
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin-top: 7
height: 22

OptionCheckBox
id: showDragIcon
!text: tr('Show item icon while dragging')

SmallReversedQtPanel
anchors.left: parent.left
anchors.right: parent.right
Expand Down
27 changes: 27 additions & 0 deletions modules/corelib/ui/uidragicon.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
UIDragIcon = {}
local uiIcon = nil

function UIDragIcon:display(item)
if modules.client_options.getOption('showDragIcon') then
uiIcon = g_ui.createWidget('UIDragIcon', rootWidget)
uiIcon:setItem(item)
uiIcon:setVirtual(true)
uiIcon:setShowCount(false)
uiIcon:show()
end

connect(rootWidget, { onMouseMove = onMouseMove })
end

function UIDragIcon:hide()
if uiIcon ~= nil then
uiIcon:hide()
end
disconnect(rootWidget, { onMouseMove = onMouseMove })
end

function onMouseMove(self, mousePos, mouseMoved)
if uiIcon ~= nil then
uiIcon:setPosition(mousePos)
end
end
6 changes: 6 additions & 0 deletions modules/game_interface/widgets/uigamemap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function UIGameMap:onDragEnter(mousePos)
return false
end

if not thing:isNotMoveable() then
UIDragIcon:display(thing)
end

self.currentDragThing = thing

g_mouse.pushCursor('target')
Expand All @@ -33,6 +37,7 @@ function UIGameMap:onDragLeave(droppedWidget, mousePos)
self.currentDragThing = nil
self.hoveredWho = nil
g_mouse.popCursor('target')
UIDragIcon:hide()
return true
end

Expand Down Expand Up @@ -68,6 +73,7 @@ function UIGameMap:onDrop(widget, mousePos)
g_game.move(thing, toPos, 1)
end

UIDragIcon:hide()
return true
end

Expand Down
12 changes: 12 additions & 0 deletions modules/game_interface/widgets/uiitem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function UIItem:onDragEnter(mousePos)
return false
end

UIDragIcon:display(item)
self:setBorderWidth(1)
self.currentDragThing = item
g_mouse.pushCursor('target')
Expand All @@ -20,6 +21,7 @@ function UIItem:onDragLeave(droppedWidget, mousePos)
end
self.currentDragThing = nil
g_mouse.popCursor('target')
UIDragIcon:hide()
self:setBorderWidth(0)
self.hoveredWho = nil
return true
Expand All @@ -37,6 +39,10 @@ function UIItem:onDrop(widget, mousePos)
return false
end

if self.isVirtual() then
UIDragIcon:hide()
end

local itemPos = item:getPosition()
local itemTile = item:getTile()
local toPos = self.position
Expand Down Expand Up @@ -77,6 +83,10 @@ function UIItem:onDestroy()
self.hoveredWho:setBorderWidth(0)
end

if self.isVirtual() then
UIDragIcon:hide()
end

if self.hoveredWho then
self.hoveredWho = nil
end
Expand All @@ -86,6 +96,7 @@ function UIItem:onHoverChange(hovered)
UIWidget.onHoverChange(self, hovered)

if self:isVirtual() or not self:isDraggable() then
UIDragIcon:hide()
return
end

Expand Down Expand Up @@ -141,6 +152,7 @@ function UIItem:onMouseRelease(mousePosition, mouseButton)
end

if self:isVirtual() then
UIDragIcon:hide()
return false
end

Expand Down
4 changes: 2 additions & 2 deletions src/client/uiitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void UIItem::drawSelf(const DrawPoolType drawPane)
m_item->draw(Point(exactSize - g_gameConfig.getSpriteSize()) + m_item->getDisplacement());
g_drawPool.releaseFrameBuffer(getPaddingRect());

if (m_font && (m_alwaysShowCount || m_item->isStackable() || m_item->isChargeable()) && m_item->getCountOrSubType() > 1) {
if (m_font && (m_alwaysShowCount && (m_item->isStackable() || m_item->isChargeable())) && m_item->getCountOrSubType() > 1) {
static constexpr Color STACK_COLOR(231, 231, 231);
const auto& count = m_item->getCountOrSubType();
const auto& countText = count < 1000 ? std::to_string(count) : fmt::format("{}k", count / 1000.f);
Expand Down Expand Up @@ -143,4 +143,4 @@ void UIItem::setShader(std::string_view name) {
if (getItem()) getItem()->setShader(name);
}

bool UIItem::hasShader() { return getItem() ? getItem()->getShader() != nullptr : false; }
bool UIItem::hasShader() { return getItem() ? getItem()->getShader() != nullptr : false; }
2 changes: 1 addition & 1 deletion src/client/uiitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ class UIItem final : public UIWidget
bool m_virtual{ false };
bool m_showId{ false };
bool m_itemVisible{ true };
bool m_alwaysShowCount{ false };
bool m_alwaysShowCount{ true };
};
Loading