diff --git a/modules/core_lib/core_lib.otmod b/modules/core_lib/core_lib.otmod index c572c817..12845952 100644 --- a/modules/core_lib/core_lib.otmod +++ b/modules/core_lib/core_lib.otmod @@ -38,3 +38,5 @@ Module dofile 'widgets/uipopupmenu' dofile 'widgets/uiwindow' dofile 'widgets/uimessagebox' + dofile 'widgets/uisplitter' + diff --git a/modules/core_lib/mouse.lua b/modules/core_lib/mouse.lua index 8d5bda90..7e63bf7c 100644 --- a/modules/core_lib/mouse.lua +++ b/modules/core_lib/mouse.lua @@ -4,7 +4,14 @@ function Mouse.setTargetCursor() g_window.setMouseCursor('/core_styles/cursors/targetcursor.png', {x=9,y=9}) end +function Mouse.setHorizontalCursor() + g_window.setMouseCursor('/core_styles/cursors/horizontal.png', {x=9,y=4}) +end + +function Mouse.setVerticalCursor() + g_window.setMouseCursor('/core_styles/cursors/vertical.png', {x=4,y=9}) +end + function Mouse.restoreCursor() g_window.restoreMouseCursor() end - diff --git a/modules/core_lib/ui/tooltip.lua b/modules/core_lib/ui/tooltip.lua index 525d41fc..df593d49 100644 --- a/modules/core_lib/ui/tooltip.lua +++ b/modules/core_lib/ui/tooltip.lua @@ -47,7 +47,8 @@ function ToolTip.init() addEvent(function() toolTipLabel = createWidget('Label', rootWidget) toolTipLabel:setId('toolTip') - toolTipLabel:setBackgroundColor('#111111bb') + toolTipLabel:setBackgroundColor('#111111cc') + toolTipLabel:setTextAlign(AlignCenter) toolTipLabel.onMouseMove = moveToolTip end) end diff --git a/modules/core_lib/widgets/uisplitter.lua b/modules/core_lib/widgets/uisplitter.lua new file mode 100644 index 00000000..459ad772 --- /dev/null +++ b/modules/core_lib/widgets/uisplitter.lua @@ -0,0 +1,70 @@ +UISplitter = extends(UIWidget) + +function UISplitter.create() + local splitter = UISplitter.internalCreate() + splitter:setFocusable(false) + splitter.canGrow = true + splitter.canShrink = true + return splitter +end + +function UISplitter:onHoverChange(hovered) + if hovered then + if self:getWidth() > self:getHeight() then + Mouse.setVerticalCursor() + self.vertical = true + else + Mouse.setHorizontalCursor() + self.vertical = false + end + elseif not self:isPressed() then + Mouse.restoreCursor() + end +end + +function UISplitter:getAttachedTo() + local parent = self:getParent() + if parent and self.attachedTo then + return parent:getChildById(self.attachedTo) + end +end + +function UISplitter:onMouseMove(mousePos, mouseMoved) + if self:isPressed() then + local deltay = mousePos.y - (self:getPosition().y + self:getHeight()/2) + local deltax = mousePos.x - (self:getPosition().x + self:getWidth()/2) + local attachedToWidget = self:getAttachedTo() + if not attachedToWidget then return end + if self.vertical then + if deltay == 0 then return end + if not self.canGrow and deltay > 0 then return end + if not self.canShrink and deltay < 0 then return end + attachedToWidget:setHeight(attachedToWidget:getHeight() - deltay) + else + if deltax == 0 then return end + attachedToWidget:setWidth(attachedToWidget:getWidth() - deltax) + end + return true + end +end + +function UISplitter:onMouseRelease(mousePos, mouseButton) + if not self:isHovered() then + Mouse.restoreCursor() + end + self:ungrabMouse() +end + +function UISplitter:onStyleApply(styleName, styleNode) + if styleNode['attached-to'] then + self.attachedTo = styleNode['attached-to'] + end +end + +function UISplitter:setGrow(enabled) + self.canGrow = enabled +end + +function UISplitter:setShrink(enabled) + self.canShrink = enabled +end diff --git a/modules/core_styles/cursors/horizontal.png b/modules/core_styles/cursors/horizontal.png new file mode 100644 index 00000000..6ba0f271 Binary files /dev/null and b/modules/core_styles/cursors/horizontal.png differ diff --git a/modules/core_styles/cursors/vertical.png b/modules/core_styles/cursors/vertical.png new file mode 100644 index 00000000..1f31d1c2 Binary files /dev/null and b/modules/core_styles/cursors/vertical.png differ diff --git a/modules/game/gameinterface.otui b/modules/game/gameinterface.otui index bb989925..cdbcaed3 100644 --- a/modules/game/gameinterface.otui +++ b/modules/game/gameinterface.otui @@ -38,6 +38,7 @@ UIWidget anchors.left: gameLeftPanel.right anchors.right: gameRightPanel.left anchors.bottom: parent.bottom + @onGeometryChange: self:getParent():getChildById('mapSplitter'):setGrow(self:getHeight() > 100) GameMapPanel id: gameMapPanel @@ -46,6 +47,16 @@ UIWidget anchors.top: parent.top anchors.bottom: gameBottomPanel.top focusable: false + @onGeometryChange: self:getParent():getChildById('mapSplitter'):setShrink(self:getHeight() > 300) + + UISplitter + id: mapSplitter + anchors.left: gameBottomPanel.left + anchors.right: gameBottomPanel.right + anchors.top: gameBottomPanel.top + attached-to: gameBottomPanel + height: 4 + margin-top: -2 UIWidget id: mouseGrabber diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 7070d4a4..fcf2f492 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -94,6 +94,10 @@ function TextMessage.terminate() disconnect(g_game, { onDeath = TextMessage.displayDeadMessage, onTextMessage = TextMessage.display, onGameEnd = TextMessage.clearMessages }) + removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerWarning').hideEvent) + removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerAdvance').hideEvent) + removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerInfo').hideEvent) + removeEvent(GameInterface.getMapPanel():recursiveGetChildById('bottomStatus').hideEvent) centerTextMessagePanel:destroy() centerTextMessagePanel = nil bottomStatusLabel:destroy() diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 91fe3c4f..3e655507 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -116,6 +116,8 @@ TilePtr UIMap::getTile(const Point& mousePos) void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect) { + UIWidget::onGeometryChange(oldRect, newRect); + Rect mapRect = getChildrenRect().expanded(-1); Size mapSize = m_mapView->getVisibleSize(); mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);