From 79a1d66f3f752403ba72e25e60dc456e36935241 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 22 Mar 2012 22:52:31 -0300 Subject: [PATCH] add splitter widget * add horizontal/vertical cursor * possibildiade to resize game map with the new splitter widget * fix reload warnings in textmessage --- modules/core_lib/core_lib.otmod | 2 + modules/core_lib/mouse.lua | 9 ++- modules/core_lib/ui/tooltip.lua | 3 +- modules/core_lib/widgets/uisplitter.lua | 70 +++++++++++++++++++++ modules/core_styles/cursors/horizontal.png | Bin 0 -> 230 bytes modules/core_styles/cursors/vertical.png | Bin 0 -> 238 bytes modules/game/gameinterface.otui | 11 ++++ modules/game_textmessage/textmessage.lua | 4 ++ src/otclient/ui/uimap.cpp | 2 + 9 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 modules/core_lib/widgets/uisplitter.lua create mode 100644 modules/core_styles/cursors/horizontal.png create mode 100644 modules/core_styles/cursors/vertical.png 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 0000000000000000000000000000000000000000..6ba0f271fa98526646db8d8a40a2668ae97e5669 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPavp9n}@7WLgyMaP!o-U3d5r^Mi zvgB(p;BmS5bLaoL&djW08lAG7U6otQBe{NgGH)(a))ix2HkmQBJ>%xH-E9w6{><4s z!#Rn0)9n3!j(!rDAOGN6!=ztdAMAeI?$0q{W$@iSt&{b51MPOt1cAQ?8B;Gry|9Y3 R+y}Ig!PC{xWt~$(69BJGQy>5U literal 0 HcmV?d00001 diff --git a/modules/core_styles/cursors/vertical.png b/modules/core_styles/cursors/vertical.png new file mode 100644 index 0000000000000000000000000000000000000000..1f31d1c2d20408c05617dd5c4e20036673a81d32 GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPavp9nVr!Q-IEKn%V)5S3);_%yP zj$8*6cvvF((ldd{E+QUAAu$IvC!Tn)GfFkM? z38fEJm7DLlIh^;Kmo22Vzl-y&u b{|QU(iL9e5wm5zO+RWhT>gTe~DWM4ffhAGI literal 0 HcmV?d00001 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);