diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 3657c795..5e556f35 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -25,11 +25,12 @@ Module - game_battle - game_minimap - game_npctrade - - game_textbooks + - game_textwindow - game_playertrade - game_ruleviolation - game_bugreport - game_shaders + - game_playerdeath @onLoad: | dofile 'const' diff --git a/modules/game_hotkeys/hotkeys_manager.lua b/modules/game_hotkeys/hotkeys_manager.lua index 7b834281..b9ccc5a2 100644 --- a/modules/game_hotkeys/hotkeys_manager.lua +++ b/modules/game_hotkeys/hotkeys_manager.lua @@ -61,6 +61,7 @@ function HotkeysManager.init() itemWidget:setVisible(false) itemWidget:setFocusable(false) + connect(g_game, { onGameEnd = HotkeysManager.hide }) connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } ) hotkeysManagerLoaded = true @@ -104,6 +105,7 @@ end function HotkeysManager.terminate() hotkeysManagerLoaded = false + disconnect(g_game, { onGameEnd = HotkeysManager.hide }) g_keyboard.unbindKeyDown('Ctrl+K') HotkeysManager.save() diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 2497446f..8bcd501d 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -27,8 +27,8 @@ function GameInterface.init() g_ui.importStyle('styles/logoutwindow.otui') g_ui.importStyle('styles/exitwindow.otui') - connect(g_game, { onGameStart = GameInterface.show }, true) - connect(g_game, { onGameEnd = GameInterface.hide }, true) + connect(g_game, { onGameStart = GameInterface.show, + onGameEnd = GameInterface.hide }, true) gameRootPanel = g_ui.displayUI('gameinterface.otui') gameRootPanel:hide() @@ -88,8 +88,8 @@ function GameInterface.init() end function GameInterface.terminate() - disconnect(g_game, { onGameStart = GameInterface.show }) - disconnect(g_game, { onGameEnd = GameInterface.hide }) + disconnect(g_game, { onGameStart = GameInterface.show, + onGameEnd = GameInterface.hide }) disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange }) logoutButton:destroy() @@ -117,6 +117,18 @@ function GameInterface.show() end 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() logoutButton:hide() Background.show() diff --git a/modules/game_interface/styles/logoutwindow.otui b/modules/game_interface/styles/logoutwindow.otui index ab11375f..985ddb98 100644 --- a/modules/game_interface/styles/logoutwindow.otui +++ b/modules/game_interface/styles/logoutwindow.otui @@ -26,4 +26,3 @@ LogoutWindow < MainWindow anchors.left: prev.right anchors.bottom: parent.bottom margin-left: 5 - @onClick: self:getParent():destroy() diff --git a/modules/game_textmessage/deathwindow.otui b/modules/game_playerdeath/deathwindow.otui similarity index 100% rename from modules/game_textmessage/deathwindow.otui rename to modules/game_playerdeath/deathwindow.otui diff --git a/modules/game_playerdeath/playerdeath.lua b/modules/game_playerdeath/playerdeath.lua new file mode 100644 index 00000000..9700f1b7 --- /dev/null +++ b/modules/game_playerdeath/playerdeath.lua @@ -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 \ No newline at end of file diff --git a/modules/game_playerdeath/playerdeath.otmod b/modules/game_playerdeath/playerdeath.otmod new file mode 100644 index 00000000..a9c98b5c --- /dev/null +++ b/modules/game_playerdeath/playerdeath.otmod @@ -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() diff --git a/modules/game_questlog/questlog.lua b/modules/game_questlog/questlog.lua index bb3a110c..35812b77 100644 --- a/modules/game_questlog/questlog.lua +++ b/modules/game_questlog/questlog.lua @@ -60,8 +60,9 @@ function QuestLog.init() questLogButton = TopMenu.addLeftGameButton('questLogButton', tr('Quest Log'), 'questlog.png', function() g_game.requestQuestLog() end) - connect(g_game, { onQuestLog = onGameQuestLog }) - connect(g_game, { onQuestLine= onGameQuestLine }) + connect(g_game, { onQuestLog = onGameQuestLog, + onQuestLine = onGameQuestLine, + onGameEnd = QuestLog.destroyWindows}) end function QuestLog.destroyWindows() @@ -77,8 +78,9 @@ function QuestLog.destroyWindows() end function QuestLog.terminate() - disconnect(g_game, { onQuestLog = onGameQuestLog }) - disconnect(g_game, { onQuestLine= onGameQuestLine }) + disconnect(g_game, { onQuestLog = onGameQuestLog, + onQuestLine = onGameQuestLine, + onGameEnd = QuestLog.destroyWindows}) QuestLog.destroyWindows() diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index e3587c76..391a6d5d 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -20,7 +20,6 @@ local MessageTypes = { local centerTextMessagePanel local bottomStatusLabel local privateLabel -local deathWindow -- private functions local function displayMessage(msgtype, msg, time) @@ -57,11 +56,8 @@ local function createTextMessageLabel(id, parent, class) end -- public functions -function TextMessage.init() - g_ui.importStyle('deathwindow.otui') - - connect(g_game, { onDeath = TextMessage.displayDeadMessage, - onTextMessage = TextMessage.display, +function TextMessage.init() + connect(g_game, { onTextMessage = TextMessage.display, onGameStart = TextMessage.clearMessages }) centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel()) @@ -96,7 +92,6 @@ function TextMessage.terminate() centerTextMessagePanel = nil bottomStatusLabel = nil privateLabel = nil - deathWindow = nil TextMessage = nil end @@ -126,33 +121,3 @@ function TextMessage.display(msgtypedesc, msg) displayMessage(msgtype, msg) 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 diff --git a/modules/game_textbooks/textbooks.lua b/modules/game_textwindow/textwindow.lua similarity index 62% rename from modules/game_textbooks/textbooks.lua rename to modules/game_textwindow/textwindow.lua index 88cd92e0..c2ff43d9 100644 --- a/modules/game_textbooks/textbooks.lua +++ b/modules/game_textwindow/textwindow.lua @@ -1,7 +1,14 @@ -TextBooks = {} +TextWindow = {} +-- private variables +local textWindow + +-- private functions 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 textItem = textWindow:getChildById('textItem') @@ -41,16 +48,23 @@ local function onGameEditText(id, itemId, maxLength, text, writter, time) textWindow:setText(tr('Edit Text')) end - okButton.onClick = function() + doneFunc = function() if writeable then g_game.editText(id, textEdit:getText()) end - textWindow:destroy() + TextWindow.destroy() end + + okButton.onClick = doneFunc + textWindow.onEnter = doneFunc + textWindow.onEscape = TextWindow.destroy end 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 description = textWindow:getChildById('description') @@ -63,20 +77,36 @@ local function onGameEditList(id, doorId, text) description:setText(tr('Enter one name per line.')) textWindow:setText(tr('Edit List')) - okButton.onClick = function() + doneFunc = function() g_game.editList(id, doorId, textEdit:getText()) - textWindow:destroy() + TextWindow.destroy() end + + okButton.onClick = doneFunc + textWindow.onEnter = doneFunc + textWindow.onEscape = TextWindow.destroy end -function TextBooks.init() +-- public functions +function TextWindow.init() g_ui.importStyle('textwindow.otui') - connect(g_game, { onEditText = onGameEditText }) - connect(g_game, { onEditList = onGameEditList }) + connect(g_game, { onEditText = onGameEditText, + onEditList = onGameEditList, + onGameEnd = TextWindow.destroy }) end -function TextBooks.terminate() - disconnect(g_game, { onEditText = onGameEditText }) - disconnect(g_game, { onEditList = onGameEditList }) +function TextWindow.terminate() + disconnect(g_game, { onEditText = onGameEditText, + onEditList = onGameEditList, + onGameEnd = TextWindow.destroy }) + + TextWindow.destroy() end + +function TextWindow.destroy() + if(textWindow) then + textWindow:destroy() + textWindow = nil + end +end \ No newline at end of file diff --git a/modules/game_textbooks/textbooks.otmod b/modules/game_textwindow/textwindow.otmod similarity index 55% rename from modules/game_textbooks/textbooks.otmod rename to modules/game_textwindow/textwindow.otmod index c0891d62..c5eb0ad6 100644 --- a/modules/game_textbooks/textbooks.otmod +++ b/modules/game_textwindow/textwindow.otmod @@ -1,15 +1,15 @@ Module - name: game_textbooks + name: game_textwindow description: Allow to edit text books and lists - author: edubart + author: edubart, BeniS website: www.otclient.info dependencies: - game_interface @onLoad: | - dofile 'textbooks' - TextBooks.init() + dofile 'textwindow' + TextWindow.init() @onUnload: | - TextBooks.terminate() + TextWindow.terminate() diff --git a/modules/game_textbooks/textwindow.otui b/modules/game_textwindow/textwindow.otui similarity index 100% rename from modules/game_textbooks/textwindow.otui rename to modules/game_textwindow/textwindow.otui