Skip to content

Commit

Permalink
Added option to fix windows on panels (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoContreiras authored and DSpeichert committed Feb 23, 2019
1 parent 406281e commit d291c7c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 4 additions & 0 deletions modules/client_options/game.otui
Expand Up @@ -26,6 +26,10 @@ Panel
id: showLeftPanel
!text: tr('Show left panel')

OptionCheckBox
id: moveWindowsToPanel
!text: tr('Move windows to panel')

OptionCheckBox
id: displayNames
!text: tr('Display creature names')
Expand Down
3 changes: 3 additions & 0 deletions modules/client_options/options.lua
Expand Up @@ -15,6 +15,7 @@ local defaultOptions = {
showPrivateMessagesInConsole = true,
showPrivateMessagesOnScreen = true,
showLeftPanel = false,
moveWindowsToPanel = false,
foregroundFrameRate = 61,
backgroundFrameRate = 201,
painterEngine = 0,
Expand Down Expand Up @@ -203,6 +204,8 @@ function setOption(key, value, force)
audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
elseif key == 'showLeftPanel' then
modules.game_interface.getLeftPanel():setOn(value)
elseif key == 'moveWindowsToPanel' then
g_settings.set('moveWindowsToPanel', true)
elseif key == 'backgroundFrameRate' then
local text, v = value, value
if value <= 0 or value >= 201 then text = 'max' v = 0 end
Expand Down
43 changes: 35 additions & 8 deletions modules/corelib/ui/uiminiwindow.lua
Expand Up @@ -162,15 +162,42 @@ function UIMiniWindow:onDragEnter(mousePos)
end

function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
if self.movedWidget then
self.setMovedChildMargin(self.movedOldMargin or 0)
self.movedWidget = nil
self.setMovedChildMargin = nil
self.movedOldMargin = nil
self.movedIndex = nil
end

self:saveParent(self:getParent())
if g_settings.getBoolean('moveWindowsToPanel') then
local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos)
local dropInPanel = 0

for i=1,#children do
local child = children[i]
if child:getId() == 'gameLeftPanel' or child:getId() == 'gameRightPanel' then
dropInPanel = 1
end
end

if dropInPanel == 0 then
tmpp = self
if(modules.game_interface.getLeftPanel():isVisible()) then
if modules.game_interface.getRootPanel():getWidth() / 2 < mousePos.x then
addEvent(function() tmpp:setParent(modules.game_interface.getRightPanel()) end)
else
addEvent(function() tmpp:setParent(modules.game_interface.getLeftPanel()) end)
end
else
addEvent(function() tmpp:setParent(modules.game_interface.getRightPanel()) end)
end
end

else
if self.movedWidget then
self.setMovedChildMargin(self.movedOldMargin or 0)
self.movedWidget = nil
self.setMovedChildMargin = nil
self.movedOldMargin = nil
self.movedIndex = nil
end

self:saveParent(self:getParent())
end
end

function UIMiniWindow:onDragMove(mousePos, mouseMoved)
Expand Down

0 comments on commit d291c7c

Please sign in to comment.