Merge pull request #38 from BeniS/master

This commit is contained in:
Eduardo Bart 2012-07-13 14:09:37 -07:00
commit 099716fe03
11 changed files with 132 additions and 41 deletions

View File

@ -22,7 +22,7 @@ local function tryLogin(charInfo, tries)
if g_game.isOnline() then if g_game.isOnline() then
g_game.safeLogout() g_game.safeLogout()
if tries == 1 then if tries == 1 then
loadBox = displayCancelBox(tr('Please wait'), tr('Loggin out...')) loadBox = displayCancelBox(tr('Please wait'), tr('Logging out...'))
end end
scheduleEvent(function() tryLogin(charInfo, tries+1) end, 250) scheduleEvent(function() tryLogin(charInfo, tries+1) end, 250)
return return

View File

@ -32,14 +32,18 @@ function g_mouse.isPressed(button)
return g_window.isMouseButtonPressed(button) return g_window.isMouseButtonPressed(button)
end end
function g_mouse.bindAutoPress(widget, callback, delay) function g_mouse.bindAutoPress(widget, callback, delay, button)
local button = button or MouseLeftButton
connect(widget, { onMousePress = function(widget, mousePos, mouseButton) connect(widget, { onMousePress = function(widget, mousePos, mouseButton)
if(mouseButton ~= button) then
return false
end
local startTime = g_clock.millis() local startTime = g_clock.millis()
callback(widget, mousePos, mouseButton, 0) callback(widget, mousePos, mouseButton, 0)
periodicalEvent(function() periodicalEvent(function()
callback(widget, g_window.getMousePosition(), mouseButton, g_clock.millis() - startTime) callback(widget, g_window.getMousePosition(), mouseButton, g_clock.millis() - startTime)
end, function() end, function()
return widget:isPressed() return g_mouse.isPressed(mouseButton)
end, 30, delay) end, 30, delay)
return true return true
end }) end })

View File

@ -334,6 +334,7 @@ function HotkeysManager.checkSelectedHotkey(focused)
if hotkeyLabelSelectedOnList.itemId == nil then if hotkeyLabelSelectedOnList.itemId == nil then
hotkeyText:enable() hotkeyText:enable()
hotkeyText:focus()
hotKeyTextLabel:enable() hotKeyTextLabel:enable()
hotkeyText:setText(hotkeyLabelSelectedOnList.value) hotkeyText:setText(hotkeyLabelSelectedOnList.value)

View File

@ -9,6 +9,10 @@ local gameBottomPanel
local logoutButton local logoutButton
local mouseGrabberWidget local mouseGrabberWidget
local countWindow
local logoutWindow
local exitWindow
local function onLeftPanelVisibilityChange(leftPanel, visible) local function onLeftPanelVisibilityChange(leftPanel, visible)
if not visible then if not visible then
local children = leftPanel:getChildren() local children = leftPanel:getChildren()
@ -97,6 +101,9 @@ function GameInterface.terminate()
gameLeftPanel = nil gameLeftPanel = nil
gameBottomPanel = nil gameBottomPanel = nil
mouseGrabberWidget = nil mouseGrabberWidget = nil
countWindow = nil
logoutWindow = nil
exitWindow = nil
GameInterface = nil GameInterface = nil
end end
@ -125,23 +132,34 @@ function GameInterface.exit()
end end
function GameInterface.tryExit() function GameInterface.tryExit()
local exitWindow = g_ui.createWidget('ExitWindow', rootWidget) if(exitWindow) then
return true
end
exitWindow = g_ui.createWidget('ExitWindow', rootWidget)
local exitButton = exitWindow:getChildById('buttonExit') local exitButton = exitWindow:getChildById('buttonExit')
local logoutButton = exitWindow:getChildById('buttonLogout') local logButton = exitWindow:getChildById('buttonLogout')
local cancelButton = exitWindow:getChildById('buttonCancel')
local exitFunc = function() local exitFunc = function()
GameInterface.exit() GameInterface.exit()
exitButton:getParent():destroy() exitButton:getParent():destroy()
end end
local logoutFunc = function() local logoutFunc = function()
GameInterface.logout() GameInterface.logout()
logoutButton:getParent():destroy() logButton:getParent():destroy()
exitWindow = nil
end
local cancelFunc = function()
cancelButton:getParent():destroy()
exitWindow = nil
end end
exitWindow.onEscape = cancelFunc
exitWindow.onEnter = logoutFunc exitWindow.onEnter = logoutFunc
exitButton.onClick = exitFunc exitButton.onClick = exitFunc
logoutButton.onClick = logoutFunc logButton.onClick = logoutFunc
cancelButton.onClick = cancelFunc
return true -- signal closing return true -- signal closing
end end
@ -153,16 +171,28 @@ function GameInterface.logout()
end end
function GameInterface.tryLogout() function GameInterface.tryLogout()
local logoutWindow = g_ui.createWidget('LogoutWindow', rootWidget) if(logoutWindow) then
return
end
logoutWindow = g_ui.createWidget('LogoutWindow', rootWidget)
local yesButton = logoutWindow:getChildById('buttonYes') local yesButton = logoutWindow:getChildById('buttonYes')
local noButton = logoutWindow:getChildById('buttonNo')
local logoutFunc = function() local logoutFunc = function()
GameInterface.logout() GameInterface.logout()
yesButton:getParent():destroy() yesButton:getParent():destroy()
logoutWindow = nil
end
local cancelFunc = function()
noButton:getParent():destroy()
logoutWindow = nil
end end
logoutWindow.onEnter = logoutFunc logoutWindow.onEnter = logoutFunc
logoutWindow.onEscape = cancelFunc
yesButton.onClick = logoutFunc yesButton.onClick = logoutFunc
noButton.onClick = cancelFunc
end end
function GameInterface.onMouseGrabberRelease(self, mousePosition, mouseButton) function GameInterface.onMouseGrabberRelease(self, mousePosition, mouseButton)
@ -375,7 +405,8 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalkPos
end end
else else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
if multiUseThing:asCreature() then local player = g_game.getLocalPlayer()
if multiUseThing:asCreature() and multiUseThing:asCreature() ~= player then
g_game.attack(multiUseThing:asCreature()) g_game.attack(multiUseThing:asCreature())
return true return true
elseif multiUseThing:isContainer() then elseif multiUseThing:isContainer() then
@ -422,6 +453,9 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalkPos
end end
function GameInterface.moveStackableItem(item, toPos) function GameInterface.moveStackableItem(item, toPos)
if(countWindow) then
return
end
if g_keyboard.isCtrlPressed() then if g_keyboard.isCtrlPressed() then
g_game.move(item, toPos, item:getCount()) g_game.move(item, toPos, item:getCount())
return return
@ -431,7 +465,7 @@ function GameInterface.moveStackableItem(item, toPos)
end end
local count = item:getCount() local count = item:getCount()
local countWindow = g_ui.createWidget('CountWindow', rootWidget) countWindow = g_ui.createWidget('CountWindow', rootWidget)
local spinbox = countWindow:getChildById('countSpinBox') local spinbox = countWindow:getChildById('countSpinBox')
local scrollbar = countWindow:getChildById('countScrollBar') local scrollbar = countWindow:getChildById('countScrollBar')
spinbox:setMaximum(count) spinbox:setMaximum(count)
@ -447,10 +481,19 @@ function GameInterface.moveStackableItem(item, toPos)
local moveFunc = function() local moveFunc = function()
g_game.move(item, toPos, spinbox:getValue()) g_game.move(item, toPos, spinbox:getValue())
okButton:getParent():destroy() okButton:getParent():destroy()
countWindow = nil
end
local cancelButton = countWindow:getChildById('buttonCancel')
local cancelFunc = function()
cancelButton:getParent():destroy()
countWindow = nil
end end
countWindow.onEnter = moveFunc countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc
okButton.onClick = moveFunc okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
end end
function GameInterface.getRootPanel() function GameInterface.getRootPanel()

View File

@ -2,7 +2,6 @@ CountWindow < MainWindow
id: countWindow id: countWindow
!text: tr('Move Stackable Item') !text: tr('Move Stackable Item')
size: 196 112 size: 196 112
@onEscape: self:destroy()
Label Label
!text: tr('Amount:') !text: tr('Amount:')
@ -38,4 +37,3 @@ CountWindow < MainWindow
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: self:getParent():destroy()

View File

@ -2,39 +2,23 @@ ExitWindow < MainWindow
id: exitWindow id: exitWindow
!text: tr('Exit') !text: tr('Exit')
size: 550 135 size: 550 135
@onEscape: self:destroy()
Label Label
!text: tr('If you shut down the program, you character might stay in the game.') !text: tr('If you shut down the program, you character might stay in the game.\nClick on "Logout" to ensure that you character leaves the game property.\nClick on "Exit" if you want to exit the program without logging out your character.')
width: 550 width: 550
height: 110
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
margin-left: 10 margin-left: 10
margin-top: 2 margin-top: 2
Label
!text: tr('Click on "Logout" to ensure that you character leaves the game property.')
width: 550
anchors.left: parent.left
anchors.top: prev.bottom
margin-left: 10
margin-top: 2
Label
!text: tr('Click on "Exit" if you want to exit the program without logging out your character.')
width: 550
anchors.left: parent.left
anchors.top: prev.bottom
margin-left: 10
margin-top: 2
Button Button
id: buttonExit id: buttonExit
!text: tr('Exit') !text: tr('Exit')
width: 64 width: 64
anchors.left: parent.left anchors.left: parent.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
margin-left: 155 margin-left: 160
Button Button
id: buttonLogout id: buttonLogout
@ -51,4 +35,3 @@ ExitWindow < MainWindow
anchors.left: prev.right anchors.left: prev.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
margin-left: 5 margin-left: 5
@onClick: self:getParent():destroy()

View File

@ -2,7 +2,6 @@ LogoutWindow < MainWindow
id: logoutWindow id: logoutWindow
!text: tr('Logout') !text: tr('Logout')
size: 300 100 size: 300 100
@onEscape: self:destroy()
Label Label
!text: tr('Are you sure you want to logout?') !text: tr('Are you sure you want to logout?')

View File

@ -5,6 +5,8 @@ local minimapWidget
local minimapButton local minimapButton
local minimapWindow local minimapWindow
local DEFAULT_ZOOM = 60 local DEFAULT_ZOOM = 60
local MAX_FLOOR_UP = 0
local MAX_FLOOR_DOWN = 15
local navigating = false local navigating = false
minimapFirstLoad = true minimapFirstLoad = true
@ -54,7 +56,7 @@ function Minimap.init()
minimapWidget = minimapWindow:recursiveGetChildById('minimap') minimapWidget = minimapWindow:recursiveGetChildById('minimap')
g_mouse.bindAutoPress(minimapWidget, Minimap.compassClick) g_mouse.bindAutoPress(minimapWidget, Minimap.compassClick, nil, MouseRightButton)
minimapWidget:setAutoViewMode(false) minimapWidget:setAutoViewMode(false)
minimapWidget:setViewMode(1) -- mid view minimapWidget:setViewMode(1) -- mid view
minimapWidget:setDrawMinimapColors(true) minimapWidget:setDrawMinimapColors(true)
@ -125,8 +127,8 @@ function Minimap.compassClick(self, mousePos, mouseButton, elapsed)
local dx = px - self:getWidth()/2 local dx = px - self:getWidth()/2
local dy = -(py - self:getHeight()/2) local dy = -(py - self:getHeight()/2)
local radius = math.sqrt(dx*dx+dy*dy) local radius = math.sqrt(dx*dx+dy*dy)
local movex=0 local movex = 0
local movey=0 local movey = 0
dx = dx/radius dx = dx/radius
dy = dy/radius dy = dy/radius
@ -148,11 +150,15 @@ function Minimap.onButtonClick(id)
elseif id == "floorUp" then elseif id == "floorUp" then
local pos = minimapWidget:getCameraPosition() local pos = minimapWidget:getCameraPosition()
pos.z = pos.z - 1 pos.z = pos.z - 1
minimapWidget:setCameraPosition(pos) if(pos.z > MAX_FLOOR_UP) then
minimapWidget:setCameraPosition(pos)
end
elseif id == "floorDown" then elseif id == "floorDown" then
local pos = minimapWidget:getCameraPosition() local pos = minimapWidget:getCameraPosition()
pos.z = pos.z + 1 pos.z = pos.z + 1
minimapWidget:setCameraPosition(pos) if(pos.z < MAX_FLOOR_DOWN) then
minimapWidget:setCameraPosition(pos)
end
end end
end end

View File

@ -34,7 +34,7 @@ MiniWindow
text: ? text: ?
text-align: center text-align: center
phantom: false phantom: false
!tooltip: tr('Hold left mouse button to navigate\nScroll mouse middle button to zoom') !tooltip: tr('Hold right mouse button to navigate\nScroll mouse middle button to zoom')
anchors.top: minimizeButton.top anchors.top: minimizeButton.top
anchors.right: minimizeButton.left anchors.right: minimizeButton.left
margin-right: 3 margin-right: 3

View File

@ -0,0 +1,29 @@
DeathWindow < MainWindow
id: deathWindow
!text: tr('You are dead')
size: 350 155
Label
!text: tr('Alas! Brave adventurer, you have met a sad fate.\nBut do not despair, for the gods will bring you back\ninto this world in exchange for a small sacrifice\n\nSimply click on Ok to resume your journeys!')
width: 550
height: 140
anchors.left: parent.left
anchors.top: parent.top
margin-left: 10
margin-top: 2
Button
id: buttonOk
!text: tr('Ok')
width: 64
anchors.left: parent.left
anchors.bottom: parent.bottom
margin-left: 160
Button
id: buttonCancel
!text: tr('Cancel')
width: 64
anchors.left: prev.right
anchors.bottom: parent.bottom
margin-left: 5

View File

@ -20,6 +20,7 @@ local MessageTypes = {
local centerTextMessagePanel local centerTextMessagePanel
local bottomStatusLabel local bottomStatusLabel
local privateLabel local privateLabel
local deathWindow
-- private functions -- private functions
local function displayMessage(msgtype, msg, time) local function displayMessage(msgtype, msg, time)
@ -57,6 +58,8 @@ end
-- public functions -- public functions
function TextMessage.init() function TextMessage.init()
g_ui.importStyle('deathwindow.otui')
connect(g_game, { onDeath = TextMessage.displayDeadMessage, connect(g_game, { onDeath = TextMessage.displayDeadMessage,
onTextMessage = TextMessage.display, onTextMessage = TextMessage.display,
onGameStart = TextMessage.clearMessages }) onGameStart = TextMessage.clearMessages })
@ -93,6 +96,7 @@ function TextMessage.terminate()
centerTextMessagePanel = nil centerTextMessagePanel = nil
bottomStatusLabel = nil bottomStatusLabel = nil
privateLabel = nil privateLabel = nil
deathWindow = nil
TextMessage = nil TextMessage = nil
end end
@ -127,4 +131,28 @@ function TextMessage.displayDeadMessage()
local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance') local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then return end if advanceLabel:isVisible() then return end
TextMessage.displayEventAdvance(tr('You are dead.')) TextMessage.displayEventAdvance(tr('You are dead.'))
if(deathWindow) then
return
end
deathWindow = g_ui.createWidget('DeathWindow', rootWidget)
local okButton = deathWindow:getChildById('buttonOk')
local cancelButton = deathWindow:getChildById('buttonCancel')
local okFunc = function()
CharacterList.doLogin()
okButton:getParent():destroy()
deathWindow = nil
end
local cancelFunc = function()
GameInterface.logout()
cancelButton:getParent():destroy()
deathWindow = nil
end
deathWindow.onEnter = okFunc
deathWindow.onEscape = cancelFunc
okButton.onClick = okFunc
cancelButton.onClick = cancelFunc
end end