diff --git a/modules/client_entergame/characterlist.otui b/modules/client_entergame/characterlist.otui index 801e18fc..707d6df1 100644 --- a/modules/client_entergame/characterlist.otui +++ b/modules/client_entergame/characterlist.otui @@ -17,7 +17,9 @@ MainWindow TextList id: characterList - anchors.fill: parent + anchors.top: parent.top + anchors.left: parent.left + anchors.right: characterListScrollBar.left anchors.bottom: accountStatusLabel.top margin-bottom: 5 padding: 1 @@ -26,9 +28,10 @@ MainWindow VerticalScrollBar id: characterListScrollBar - anchors.top: characterList.top - anchors.bottom: characterList.bottom - anchors.right: characterList.right + anchors.top: parent.top + anchors.bottom: accountStatusLabel.top + anchors.right: parent.right + margin-bottom: 5 step: 14 pixels-scroll: true diff --git a/modules/client_skins/skins/default/styles/messageboxes.otui b/modules/client_skins/skins/default/styles/messageboxes.otui index 6e3a6f92..a0898f7f 100644 --- a/modules/client_skins/skins/default/styles/messageboxes.otui +++ b/modules/client_skins/skins/default/styles/messageboxes.otui @@ -1,11 +1,14 @@ MessageBoxLabel < Label id: messageBoxLabel + text-auto-resize: true anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top -MessageBoxRightButton < Button - id: messageBoxRightButton +MessageBoxButtonHolder < UIWidget + id: buttonHolder + margin-top: 10 anchors.bottom: parent.bottom - anchors.right: parent.right - width: 64 - visible: true + +MessageBoxButton < Button + margin-left: 10 + width: 80 diff --git a/modules/corelib/ui/uimessagebox.lua b/modules/corelib/ui/uimessagebox.lua index a778943c..652baaa8 100644 --- a/modules/corelib/ui/uimessagebox.lua +++ b/modules/corelib/ui/uimessagebox.lua @@ -3,56 +3,78 @@ if not UIWindow then dofile 'uiwindow' end -- @docclass UIMessageBox = extends(UIWindow) -MessageBoxOk = 1 -MessageBoxCancel = 2 - -- messagebox cannot be created from otui files UIMessageBox.create = nil -function UIMessageBox.display(title, message, flags) - local messagebox = UIMessageBox.internalCreate() - rootWidget:addChild(messagebox) +function UIMessageBox.display(title, message, buttons, onEnterCallback, onEscapeCallback) + local messageBox = UIMessageBox.internalCreate() + rootWidget:addChild(messageBox) - messagebox:setStyle('MainWindow') - messagebox:setText(title) + messageBox:setStyle('MainWindow') + messageBox:setText(title) - local messageLabel = g_ui.createWidget('MessageBoxLabel', messagebox) + local messageLabel = g_ui.createWidget('MessageBoxLabel', messageBox) messageLabel:setText(message) - messageLabel:resizeToText() - - -- setup messagebox first button - local buttonRight = g_ui.createWidget('MessageBoxRightButton', messagebox) - - if flags == MessageBoxOk then - buttonRight:setText('Ok') - connect(buttonRight, { onClick = function(self) self:getParent():ok() end }) - connect(messagebox, { onEnter = function(self) self:ok() end }) - connect(messagebox, { onEscape = function(self) self:ok() end }) - elseif flags == MessageBoxCancel then - buttonRight:setText('Cancel') - connect(buttonRight, { onClick = function(self) self:getParent():cancel() end }) - connect(messagebox, { onEnter = function(self) self:cancel() end }) - connect(messagebox, { onEscape = function(self) self:cancel() end }) + + local buttonsWidth = 0 + local buttonsHeight = 0 + + local anchor = AnchorRight + if buttons.anchor then anchor = buttons.anchor end + + local buttonHolder = g_ui.createWidget('MessageBoxButtonHolder', messageBox) + buttonHolder:addAnchor(anchor, 'parent', anchor) + + for i=1,#buttons do + local button = messageBox:addButton(buttons[i].text, buttons[i].callback) + if i == 1 then + button:setMarginLeft(0) + button:addAnchor(AnchorBottom, 'parent', AnchorBottom) + button:addAnchor(AnchorLeft, 'parent', AnchorLeft) + buttonsHeight = button:getHeight() + else + button:addAnchor(AnchorBottom, 'prev', AnchorBottom) + button:addAnchor(AnchorLeft, 'prev', AnchorRight) + end + buttonsWidth = buttonsWidth + button:getWidth() + button:getMarginLeft() end - messagebox:setWidth(math.max(messageLabel:getWidth(), messagebox:getTextSize().width) + messagebox:getPaddingLeft() + messagebox:getPaddingRight()) - messagebox:setHeight(messageLabel:getHeight() + messagebox:getPaddingTop() + messagebox:getPaddingBottom() + buttonRight:getHeight() + 10) + buttonHolder:setWidth(buttonsWidth) + buttonHolder:setHeight(buttonsHeight) - --messagebox:lock() + if onEnterCallback then connect(messageBox, { onEnter = onEnterCallback }) end + if onEscapeCallback then connect(messageBox, { onEscape = onEscapeCallback }) end - return messagebox + messageBox:setWidth(math.max(messageLabel:getWidth(), messageBox:getTextSize().width, buttonHolder:getWidth()) + messageBox:getPaddingLeft() + messageBox:getPaddingRight()) + messageBox:setHeight(messageLabel:getHeight() + messageBox:getPaddingTop() + messageBox:getPaddingBottom() + buttonHolder:getHeight() + buttonHolder:getMarginTop()) + return messageBox end function displayInfoBox(title, message) - return UIMessageBox.display(title, message, MessageBoxOk) + local defaultCallback = function(self) self:ok() end + return UIMessageBox.display(title, message, {{text='Ok', callback=defaultCallback}}, defaultCallback, defaultCallback) end function displayErrorBox(title, message) - return UIMessageBox.display(title, message, MessageBoxOk) + local defaultCallback = function(self) self:ok() end + return UIMessageBox.display(title, message, {{text='Ok', callback=defaultCallback}}, defaultCallback, defaultCallback) end function displayCancelBox(title, message) - return UIMessageBox.display(title, message, MessageBoxCancel) + local defaultCallback = function(self) self:cancel() end + return UIMessageBox.display(title, message, {{text='Cancel', callback=defaultCallback}}, defaultCallback, defaultCallback) +end + +function displayGeneralBox(title, message, buttons, onEnterCallback, onEscapeCallback) + return UIMessageBox.display(title, message, buttons, onEnterCallback, onEscapeCallback) +end + +function UIMessageBox:addButton(text, callback) + local buttonHolder = self:getChildById('buttonHolder') + local button = g_ui.createWidget('MessageBoxButton', buttonHolder) + button:setText(text) + connect(button, { onClick = callback }) + return button end function UIMessageBox:ok() diff --git a/modules/corelib/util.lua b/modules/corelib/util.lua index 3f20e982..97089875 100644 --- a/modules/corelib/util.lua +++ b/modules/corelib/util.lua @@ -263,4 +263,21 @@ function tr(s, ...) return string.format(s, ...) end +function getOppositeAnchor(anchor) + if anchor == AnchorLeft then + return AnchorRight + elseif anchor == AnchorRight then + return AnchorLeft + elseif anchor == AnchorTop then + return AnchorBottom + elseif anchor == AnchorBottom then + return AnchorTop + elseif anchor == AnchorVerticalCenter then + return AnchorHorizontalCenter + elseif anchor == AnchorHorizontalCenter then + return AnchorVerticalCenter + end + return anchor +end + -- @} \ No newline at end of file diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 4bd6247f..9c9c32a4 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -13,8 +13,6 @@ exitWindow = nil function init() g_ui.importStyle('styles/countwindow.otui') - g_ui.importStyle('styles/logoutwindow.otui') - g_ui.importStyle('styles/exitwindow.otui') connect(g_game, { onGameStart = show, onGameEnd = hide }, true) @@ -122,32 +120,18 @@ function tryExit() if exitWindow then return true end - exitWindow = g_ui.createWidget('ExitWindow', rootWidget) - local exitButton = exitWindow:getChildById('buttonExit') - local logButton = exitWindow:getChildById('buttonLogout') - local cancelButton = exitWindow:getChildById('buttonCancel') - - local exitFunc = function() - logout() -- try logout anyway - forceExit() - end - local logoutFunc = function() - logout() - logButton:getParent():destroy() - exitWindow = nil - end - local cancelFunc = function() - cancelButton:getParent():destroy() - exitWindow = nil - end - exitWindow.onEscape = cancelFunc - exitWindow.onEnter = logoutFunc + local exitFunc = function() logout() forceExit() end + local logoutFunc = function() logout() exitWindow:destroy() exitWindow = nil end + local cancelFunc = function() exitWindow:destroy() exitWindow = nil end - exitButton.onClick = exitFunc - logButton.onClick = logoutFunc - cancelButton.onClick = cancelFunc - return true -- signal closing + exitWindow = displayGeneralBox('Exit', tr("If you shut down the program, your character might stay in the game.\nClick on 'Logout' to ensure that you character leaves the game properly.\nClick on 'Exit' if you want to exit the program without logging out your character."), { + { text='Force Exit', callback=exitFunc }, + { text='Logout', callback=logoutFunc }, + { text='Cancel', callback=cancelFunc }, + anchor=AnchorHorizontalCenter}, logoutFunc, cancelFunc) + + return true end function logout() @@ -161,25 +145,14 @@ function tryLogout() if logoutWindow then return end - logoutWindow = g_ui.createWidget('LogoutWindow', rootWidget) - local yesButton = logoutWindow:getChildById('buttonYes') - local noButton = logoutWindow:getChildById('buttonNo') - - local logoutFunc = function() - logout() - yesButton:getParent():destroy() - logoutWindow = nil - end - local cancelFunc = function() - noButton:getParent():destroy() - logoutWindow = nil - end - logoutWindow.onEnter = logoutFunc - logoutWindow.onEscape = cancelFunc + local yesCallback = function() logout() logoutWindow:destroy() logoutWindow=nil end + local noCallback = function() logoutWindow:destroy() logoutWindow=nil end - yesButton.onClick = logoutFunc - noButton.onClick = cancelFunc + logoutWindow = displayGeneralBox('Logout', tr('Are you sure you want to logout?'), { + { text='Yes', callback=yesCallback }, + { text='No', callback=noCallback }, + anchor=AnchorHorizontalCenter}, yesCallback, noCallback) end function onMouseGrabberRelease(self, mousePosition, mouseButton) diff --git a/modules/game_interface/styles/exitwindow.otui b/modules/game_interface/styles/exitwindow.otui deleted file mode 100644 index 14a89449..00000000 --- a/modules/game_interface/styles/exitwindow.otui +++ /dev/null @@ -1,35 +0,0 @@ -ExitWindow < MainWindow - id: exitWindow - !text: tr('Exit') - size: 570 135 - - Label - !text: tr("If you shut down the program, your character might stay in the game.\nClick on 'Logout' to ensure that you character leaves the game properly.\nClick on 'Exit' if you want to exit the program without logging out your character.") - text-auto-resize: true - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - margin-top: 2 - - Button - id: buttonExit - !text: tr('Force Exit') - width: 80 - anchors.right: next.left - anchors.bottom: parent.bottom - margin-right: 5 - - Button - id: buttonLogout - !text: tr('Logout') - width: 80 - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom - margin-left: 5 - - Button - id: buttonCancel - !text: tr('Cancel') - width: 80 - anchors.left: prev.right - anchors.bottom: parent.bottom - margin-left: 5 diff --git a/modules/game_interface/styles/logoutwindow.otui b/modules/game_interface/styles/logoutwindow.otui deleted file mode 100644 index 6e3188f8..00000000 --- a/modules/game_interface/styles/logoutwindow.otui +++ /dev/null @@ -1,27 +0,0 @@ -LogoutWindow < MainWindow - id: logoutWindow - !text: tr('Logout') - size: 230 100 - - Label - !text: tr('Are you sure you want to logout?') - text-auto-resize: true - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - margin-top: 2 - - Button - id: buttonYes - !text: tr('Yes') - width: 64 - anchors.right: parent.horizontalCenter - anchors.bottom: parent.bottom - margin-right: 5 - - Button - id: buttonNo - !text: tr('No') - width: 64 - anchors.left: parent.horizontalCenter - anchors.bottom: parent.bottom - margin-left: 5 diff --git a/modules/game_interface/widgets/uigamemap.lua b/modules/game_interface/widgets/uigamemap.lua index d0bbf7fb..607c0963 100644 --- a/modules/game_interface/widgets/uigamemap.lua +++ b/modules/game_interface/widgets/uigamemap.lua @@ -22,6 +22,7 @@ end function UIGameMap:onDragLeave(droppedWidget, mousePos) self.currentDragThing = nil + self.hoveredWho = nil g_mouse.restoreCursor() return true end