Changed/Fixed Text Windows, Text Message, Hotkeys Manager, Game Interface and Quest Log

* Renamed game_textbooks to game_textwindow.
* Fixed text window from opening multiple times, and is destroyed correctly.
* Added new game_playerdeath module (moved death message and window here).
* Hotkey window will hide on game end.
* Logout/Exit/Stackable Items/Questlog/Hotkeys windows will now close on game end.
This commit is contained in:
BeniS 2012-07-14 22:59:32 +12:00
parent e3298d561c
commit 694a69e1bf
12 changed files with 163 additions and 65 deletions

View File

@ -25,11 +25,12 @@ Module
- game_battle - game_battle
- game_minimap - game_minimap
- game_npctrade - game_npctrade
- game_textbooks - game_textwindow
- game_playertrade - game_playertrade
- game_ruleviolation - game_ruleviolation
- game_bugreport - game_bugreport
- game_shaders - game_shaders
- game_playerdeath
@onLoad: | @onLoad: |
dofile 'const' dofile 'const'

View File

@ -61,6 +61,7 @@ function HotkeysManager.init()
itemWidget:setVisible(false) itemWidget:setVisible(false)
itemWidget:setFocusable(false) itemWidget:setFocusable(false)
connect(g_game, { onGameEnd = HotkeysManager.hide })
connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } ) connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } )
hotkeysManagerLoaded = true hotkeysManagerLoaded = true
@ -104,6 +105,7 @@ end
function HotkeysManager.terminate() function HotkeysManager.terminate()
hotkeysManagerLoaded = false hotkeysManagerLoaded = false
disconnect(g_game, { onGameEnd = HotkeysManager.hide })
g_keyboard.unbindKeyDown('Ctrl+K') g_keyboard.unbindKeyDown('Ctrl+K')
HotkeysManager.save() HotkeysManager.save()

View File

@ -27,8 +27,8 @@ function GameInterface.init()
g_ui.importStyle('styles/logoutwindow.otui') g_ui.importStyle('styles/logoutwindow.otui')
g_ui.importStyle('styles/exitwindow.otui') g_ui.importStyle('styles/exitwindow.otui')
connect(g_game, { onGameStart = GameInterface.show }, true) connect(g_game, { onGameStart = GameInterface.show,
connect(g_game, { onGameEnd = GameInterface.hide }, true) onGameEnd = GameInterface.hide }, true)
gameRootPanel = g_ui.displayUI('gameinterface.otui') gameRootPanel = g_ui.displayUI('gameinterface.otui')
gameRootPanel:hide() gameRootPanel:hide()
@ -88,8 +88,8 @@ function GameInterface.init()
end end
function GameInterface.terminate() function GameInterface.terminate()
disconnect(g_game, { onGameStart = GameInterface.show }) disconnect(g_game, { onGameStart = GameInterface.show,
disconnect(g_game, { onGameEnd = GameInterface.hide }) onGameEnd = GameInterface.hide })
disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange }) disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton:destroy() logoutButton:destroy()
@ -117,6 +117,18 @@ function GameInterface.show()
end end
function GameInterface.hide() function GameInterface.hide()
if(logoutWindow) then
logoutWindow:destroy()
logoutWindow = nil
end
if(exitWindow) then
exitWindow:destroy()
exitWindow = nil
end
if(countWindow) then
countWindow:destroy()
countWindow = nil
end
gameRootPanel:hide() gameRootPanel:hide()
logoutButton:hide() logoutButton:hide()
Background.show() Background.show()

View File

@ -26,4 +26,3 @@ LogoutWindow < 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

@ -0,0 +1,70 @@
PlayerDeath = {}
-- private variables
local deathWindow
-- private functions
-- public functions
function PlayerDeath.init()
g_ui.importStyle('deathwindow.otui')
connect(g_game, { onDeath = PlayerDeath.display,
onGameEnd = PlayerDeath.reset })
end
function PlayerDeath.terminate()
disconnect(g_game, { onDeath = PlayerDeath.display,
onGameEnd = PlayerDeath.reset })
PlayerDeath.reset()
PlayerDeath = nil
end
function PlayerDeath.reset()
GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide()
if(deathWindow) then
deathWindow:destroy()
deathWindow = nil
end
end
function PlayerDeath.display()
PlayerDeath.displayDeadMessage()
PlayerDeath.openWindow()
end
function PlayerDeath.displayDeadMessage()
local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then
return
end
TextMessage.displayEventAdvance(tr('You are dead.'))
end
function PlayerDeath.openWindow()
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

View File

@ -0,0 +1,17 @@
Module
name: game_playerdeath
description: Manage player deaths
author: edubart, BeniS
website: www.otclient.info
dependencies:
- game_interface
- game_textmessage
- client_entergame
@onLoad: |
dofile 'playerdeath'
PlayerDeath.init()
@onUnload: |
PlayerDeath.terminate()

View File

@ -60,8 +60,9 @@ function QuestLog.init()
questLogButton = TopMenu.addLeftGameButton('questLogButton', tr('Quest Log'), 'questlog.png', function() g_game.requestQuestLog() end) questLogButton = TopMenu.addLeftGameButton('questLogButton', tr('Quest Log'), 'questlog.png', function() g_game.requestQuestLog() end)
connect(g_game, { onQuestLog = onGameQuestLog }) connect(g_game, { onQuestLog = onGameQuestLog,
connect(g_game, { onQuestLine= onGameQuestLine }) onQuestLine = onGameQuestLine,
onGameEnd = QuestLog.destroyWindows})
end end
function QuestLog.destroyWindows() function QuestLog.destroyWindows()
@ -77,8 +78,9 @@ function QuestLog.destroyWindows()
end end
function QuestLog.terminate() function QuestLog.terminate()
disconnect(g_game, { onQuestLog = onGameQuestLog }) disconnect(g_game, { onQuestLog = onGameQuestLog,
disconnect(g_game, { onQuestLine= onGameQuestLine }) onQuestLine = onGameQuestLine,
onGameEnd = QuestLog.destroyWindows})
QuestLog.destroyWindows() QuestLog.destroyWindows()

View File

@ -20,7 +20,6 @@ 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)
@ -58,10 +57,7 @@ end
-- public functions -- public functions
function TextMessage.init() function TextMessage.init()
g_ui.importStyle('deathwindow.otui') connect(g_game, { onTextMessage = TextMessage.display,
connect(g_game, { onDeath = TextMessage.displayDeadMessage,
onTextMessage = TextMessage.display,
onGameStart = TextMessage.clearMessages }) onGameStart = TextMessage.clearMessages })
centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel()) centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel())
@ -96,7 +92,6 @@ function TextMessage.terminate()
centerTextMessagePanel = nil centerTextMessagePanel = nil
bottomStatusLabel = nil bottomStatusLabel = nil
privateLabel = nil privateLabel = nil
deathWindow = nil
TextMessage = nil TextMessage = nil
end end
@ -126,33 +121,3 @@ function TextMessage.display(msgtypedesc, msg)
displayMessage(msgtype, msg) displayMessage(msgtype, msg)
end end
end end
function TextMessage.displayDeadMessage()
local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then return end
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

View File

@ -1,7 +1,14 @@
TextBooks = {} TextWindow = {}
-- private variables
local textWindow
-- private functions
local function onGameEditText(id, itemId, maxLength, text, writter, time) local function onGameEditText(id, itemId, maxLength, text, writter, time)
local textWindow = g_ui.createWidget('TextWindow', rootWidget) if(textWindow) then
return
end
textWindow = g_ui.createWidget('TextWindow', rootWidget)
local writeable = (maxLength ~= #text) and maxLength > 0 local writeable = (maxLength ~= #text) and maxLength > 0
local textItem = textWindow:getChildById('textItem') local textItem = textWindow:getChildById('textItem')
@ -41,16 +48,23 @@ local function onGameEditText(id, itemId, maxLength, text, writter, time)
textWindow:setText(tr('Edit Text')) textWindow:setText(tr('Edit Text'))
end end
okButton.onClick = function() doneFunc = function()
if writeable then if writeable then
g_game.editText(id, textEdit:getText()) g_game.editText(id, textEdit:getText())
end end
textWindow:destroy() TextWindow.destroy()
end end
okButton.onClick = doneFunc
textWindow.onEnter = doneFunc
textWindow.onEscape = TextWindow.destroy
end end
local function onGameEditList(id, doorId, text) local function onGameEditList(id, doorId, text)
local textWindow = g_ui.createWidget('TextWindow', rootWidget) if(textWindow) then
return
end
textWindow = g_ui.createWidget('TextWindow', rootWidget)
local textEdit = textWindow:getChildById('text') local textEdit = textWindow:getChildById('text')
local description = textWindow:getChildById('description') local description = textWindow:getChildById('description')
@ -63,20 +77,36 @@ local function onGameEditList(id, doorId, text)
description:setText(tr('Enter one name per line.')) description:setText(tr('Enter one name per line.'))
textWindow:setText(tr('Edit List')) textWindow:setText(tr('Edit List'))
okButton.onClick = function() doneFunc = function()
g_game.editList(id, doorId, textEdit:getText()) g_game.editList(id, doorId, textEdit:getText())
textWindow:destroy() TextWindow.destroy()
end end
okButton.onClick = doneFunc
textWindow.onEnter = doneFunc
textWindow.onEscape = TextWindow.destroy
end end
function TextBooks.init() -- public functions
function TextWindow.init()
g_ui.importStyle('textwindow.otui') g_ui.importStyle('textwindow.otui')
connect(g_game, { onEditText = onGameEditText }) connect(g_game, { onEditText = onGameEditText,
connect(g_game, { onEditList = onGameEditList }) onEditList = onGameEditList,
onGameEnd = TextWindow.destroy })
end end
function TextBooks.terminate() function TextWindow.terminate()
disconnect(g_game, { onEditText = onGameEditText }) disconnect(g_game, { onEditText = onGameEditText,
disconnect(g_game, { onEditList = onGameEditList }) onEditList = onGameEditList,
onGameEnd = TextWindow.destroy })
TextWindow.destroy()
end
function TextWindow.destroy()
if(textWindow) then
textWindow:destroy()
textWindow = nil
end
end end

View File

@ -1,15 +1,15 @@
Module Module
name: game_textbooks name: game_textwindow
description: Allow to edit text books and lists description: Allow to edit text books and lists
author: edubart author: edubart, BeniS
website: www.otclient.info website: www.otclient.info
dependencies: dependencies:
- game_interface - game_interface
@onLoad: | @onLoad: |
dofile 'textbooks' dofile 'textwindow'
TextBooks.init() TextWindow.init()
@onUnload: | @onUnload: |
TextBooks.terminate() TextWindow.terminate()