Browse Source

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.
BeniS 8 years ago
parent
commit
694a69e1bf

+ 2
- 1
modules/game/game.otmod View File

@@ -25,11 +25,12 @@ Module
25 25
     - game_battle
26 26
     - game_minimap
27 27
     - game_npctrade
28
-    - game_textbooks
28
+    - game_textwindow
29 29
     - game_playertrade
30 30
     - game_ruleviolation
31 31
     - game_bugreport
32 32
     - game_shaders
33
+    - game_playerdeath
33 34
 
34 35
   @onLoad: |
35 36
     dofile 'const'

+ 2
- 0
modules/game_hotkeys/hotkeys_manager.lua View File

@@ -61,6 +61,7 @@ function HotkeysManager.init()
61 61
   itemWidget:setVisible(false)
62 62
   itemWidget:setFocusable(false)
63 63
 
64
+  connect(g_game, { onGameEnd = HotkeysManager.hide })
64 65
   connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } )
65 66
 
66 67
   hotkeysManagerLoaded = true
@@ -104,6 +105,7 @@ end
104 105
 function HotkeysManager.terminate()
105 106
   hotkeysManagerLoaded = false
106 107
 
108
+  disconnect(g_game, { onGameEnd = HotkeysManager.hide })
107 109
   g_keyboard.unbindKeyDown('Ctrl+K')
108 110
 
109 111
   HotkeysManager.save()

+ 16
- 4
modules/game_interface/gameinterface.lua View File

@@ -27,8 +27,8 @@ function GameInterface.init()
27 27
   g_ui.importStyle('styles/logoutwindow.otui')
28 28
   g_ui.importStyle('styles/exitwindow.otui')
29 29
 
30
-  connect(g_game, { onGameStart = GameInterface.show }, true)
31
-  connect(g_game, { onGameEnd = GameInterface.hide }, true)
30
+  connect(g_game, { onGameStart = GameInterface.show,
31
+                    onGameEnd = GameInterface.hide }, true)
32 32
 
33 33
   gameRootPanel = g_ui.displayUI('gameinterface.otui')
34 34
   gameRootPanel:hide()
@@ -88,8 +88,8 @@ function GameInterface.init()
88 88
 end
89 89
 
90 90
 function GameInterface.terminate()
91
-  disconnect(g_game, { onGameStart = GameInterface.show })
92
-  disconnect(g_game, { onGameEnd = GameInterface.hide })
91
+  disconnect(g_game, { onGameStart = GameInterface.show,
92
+                       onGameEnd = GameInterface.hide })
93 93
   disconnect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
94 94
 
95 95
   logoutButton:destroy()
@@ -117,6 +117,18 @@ function GameInterface.show()
117 117
 end
118 118
 
119 119
 function GameInterface.hide()
120
+  if(logoutWindow) then
121
+    logoutWindow:destroy()
122
+    logoutWindow = nil
123
+  end
124
+  if(exitWindow) then
125
+    exitWindow:destroy()
126
+    exitWindow = nil
127
+  end
128
+  if(countWindow) then 
129
+    countWindow:destroy()
130
+    countWindow = nil
131
+  end
120 132
   gameRootPanel:hide()
121 133
   logoutButton:hide()
122 134
   Background.show()

+ 0
- 1
modules/game_interface/styles/logoutwindow.otui View File

@@ -26,4 +26,3 @@ LogoutWindow < MainWindow
26 26
     anchors.left: prev.right
27 27
     anchors.bottom: parent.bottom
28 28
     margin-left: 5
29
-    @onClick: self:getParent():destroy()

modules/game_textmessage/deathwindow.otui → modules/game_playerdeath/deathwindow.otui View File


+ 70
- 0
modules/game_playerdeath/playerdeath.lua View File

@@ -0,0 +1,70 @@
1
+PlayerDeath = {}
2
+
3
+-- private variables
4
+local deathWindow
5
+
6
+-- private functions
7
+
8
+-- public functions
9
+function PlayerDeath.init()
10
+  g_ui.importStyle('deathwindow.otui')
11
+  
12
+  connect(g_game, { onDeath = PlayerDeath.display,
13
+                    onGameEnd = PlayerDeath.reset })
14
+end
15
+
16
+function PlayerDeath.terminate()
17
+  disconnect(g_game, { onDeath = PlayerDeath.display,
18
+                       onGameEnd = PlayerDeath.reset })
19
+
20
+  PlayerDeath.reset()
21
+  PlayerDeath = nil
22
+end
23
+
24
+function PlayerDeath.reset()
25
+  GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide()
26
+  if(deathWindow) then
27
+    deathWindow:destroy()
28
+    deathWindow = nil
29
+  end
30
+end
31
+
32
+function PlayerDeath.display()
33
+  PlayerDeath.displayDeadMessage()
34
+  PlayerDeath.openWindow()
35
+end
36
+
37
+function PlayerDeath.displayDeadMessage()
38
+  local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
39
+  if advanceLabel:isVisible() then
40
+    return 
41
+  end
42
+  
43
+  TextMessage.displayEventAdvance(tr('You are dead.'))
44
+end
45
+
46
+function PlayerDeath.openWindow()
47
+  if(deathWindow) then
48
+    return
49
+  end
50
+  deathWindow = g_ui.createWidget('DeathWindow', rootWidget)
51
+  local okButton = deathWindow:getChildById('buttonOk')
52
+  local cancelButton = deathWindow:getChildById('buttonCancel')
53
+
54
+  local okFunc = function()
55
+    CharacterList.doLogin()
56
+    okButton:getParent():destroy()
57
+    deathWindow = nil
58
+  end
59
+  local cancelFunc = function()
60
+    GameInterface.logout()
61
+    cancelButton:getParent():destroy()
62
+    deathWindow = nil
63
+  end
64
+
65
+  deathWindow.onEnter = okFunc
66
+  deathWindow.onEscape = cancelFunc
67
+  
68
+  okButton.onClick = okFunc
69
+  cancelButton.onClick = cancelFunc
70
+end

+ 17
- 0
modules/game_playerdeath/playerdeath.otmod View File

@@ -0,0 +1,17 @@
1
+Module
2
+  name: game_playerdeath
3
+  description: Manage player deaths
4
+  author: edubart, BeniS
5
+  website: www.otclient.info
6
+
7
+  dependencies:
8
+    - game_interface
9
+    - game_textmessage
10
+    - client_entergame
11
+
12
+  @onLoad: |
13
+    dofile 'playerdeath'
14
+    PlayerDeath.init()
15
+
16
+  @onUnload: |
17
+    PlayerDeath.terminate()

+ 6
- 4
modules/game_questlog/questlog.lua View File

@@ -60,8 +60,9 @@ function QuestLog.init()
60 60
 
61 61
   questLogButton = TopMenu.addLeftGameButton('questLogButton', tr('Quest Log'), 'questlog.png', function() g_game.requestQuestLog() end)
62 62
 
63
-  connect(g_game, { onQuestLog = onGameQuestLog })
64
-  connect(g_game, { onQuestLine= onGameQuestLine })
63
+  connect(g_game, { onQuestLog = onGameQuestLog,
64
+                    onQuestLine = onGameQuestLine,
65
+                    onGameEnd = QuestLog.destroyWindows})
65 66
 end
66 67
 
67 68
 function QuestLog.destroyWindows()
@@ -77,8 +78,9 @@ function QuestLog.destroyWindows()
77 78
 end
78 79
 
79 80
 function QuestLog.terminate()
80
-  disconnect(g_game, { onQuestLog = onGameQuestLog })
81
-  disconnect(g_game, { onQuestLine= onGameQuestLine })
81
+  disconnect(g_game, { onQuestLog = onGameQuestLog,
82
+                       onQuestLine = onGameQuestLine,
83
+                       onGameEnd = QuestLog.destroyWindows})
82 84
 
83 85
   QuestLog.destroyWindows()
84 86
 

+ 2
- 37
modules/game_textmessage/textmessage.lua View File

@@ -20,7 +20,6 @@ local MessageTypes = {
20 20
 local centerTextMessagePanel
21 21
 local bottomStatusLabel
22 22
 local privateLabel
23
-local deathWindow
24 23
 
25 24
 -- private functions
26 25
 local function displayMessage(msgtype, msg, time)
@@ -57,11 +56,8 @@ local function createTextMessageLabel(id, parent, class)
57 56
 end
58 57
 
59 58
 -- public functions
60
-function TextMessage.init()
61
-  g_ui.importStyle('deathwindow.otui')
62
-  
63
-  connect(g_game, { onDeath = TextMessage.displayDeadMessage,
64
-                    onTextMessage = TextMessage.display,
59
+function TextMessage.init()  
60
+  connect(g_game, { onTextMessage = TextMessage.display,
65 61
                     onGameStart = TextMessage.clearMessages })
66 62
 
67 63
   centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel())
@@ -96,7 +92,6 @@ function TextMessage.terminate()
96 92
   centerTextMessagePanel = nil
97 93
   bottomStatusLabel = nil
98 94
   privateLabel = nil
99
-  deathWindow = nil
100 95
   TextMessage = nil
101 96
 end
102 97
 
@@ -126,33 +121,3 @@ function TextMessage.display(msgtypedesc, msg)
126 121
     displayMessage(msgtype, msg)
127 122
   end
128 123
 end
129
-
130
-function TextMessage.displayDeadMessage()
131
-  local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
132
-  if advanceLabel:isVisible() then return end
133
-  TextMessage.displayEventAdvance(tr('You are dead.'))
134
-  
135
-  if(deathWindow) then
136
-    return
137
-  end
138
-  deathWindow = g_ui.createWidget('DeathWindow', rootWidget)
139
-  local okButton = deathWindow:getChildById('buttonOk')
140
-  local cancelButton = deathWindow:getChildById('buttonCancel')
141
-
142
-  local okFunc = function()
143
-    CharacterList.doLogin()
144
-    okButton:getParent():destroy()
145
-    deathWindow = nil
146
-  end
147
-  local cancelFunc = function()
148
-    GameInterface.logout()
149
-    cancelButton:getParent():destroy()
150
-    deathWindow = nil
151
-  end
152
-
153
-  deathWindow.onEnter = okFunc
154
-  deathWindow.onEscape = cancelFunc
155
-  
156
-  okButton.onClick = okFunc
157
-  cancelButton.onClick = cancelFunc
158
-end

modules/game_textbooks/textbooks.lua → modules/game_textwindow/textwindow.lua View File

@@ -1,7 +1,14 @@
1
-TextBooks = {}
1
+TextWindow = {}
2 2
 
3
+-- private variables
4
+local textWindow
5
+
6
+-- private functions
3 7
 local function onGameEditText(id, itemId, maxLength, text, writter, time)
4
-  local textWindow = g_ui.createWidget('TextWindow', rootWidget)
8
+  if(textWindow) then
9
+    return
10
+  end
11
+  textWindow = g_ui.createWidget('TextWindow', rootWidget)
5 12
 
6 13
   local writeable = (maxLength ~= #text) and maxLength > 0
7 14
   local textItem = textWindow:getChildById('textItem')
@@ -41,16 +48,23 @@ local function onGameEditText(id, itemId, maxLength, text, writter, time)
41 48
     textWindow:setText(tr('Edit Text'))
42 49
   end
43 50
 
44
-  okButton.onClick = function()
51
+  doneFunc = function()
45 52
     if writeable then
46 53
       g_game.editText(id, textEdit:getText())
47 54
     end
48
-    textWindow:destroy()
55
+    TextWindow.destroy()
49 56
   end
57
+  
58
+  okButton.onClick = doneFunc
59
+  textWindow.onEnter = doneFunc
60
+  textWindow.onEscape = TextWindow.destroy
50 61
 end
51 62
 
52 63
 local function onGameEditList(id, doorId, text)
53
-  local textWindow = g_ui.createWidget('TextWindow', rootWidget)
64
+  if(textWindow) then
65
+    return
66
+  end
67
+  textWindow = g_ui.createWidget('TextWindow', rootWidget)
54 68
 
55 69
   local textEdit = textWindow:getChildById('text')
56 70
   local description = textWindow:getChildById('description')
@@ -63,20 +77,36 @@ local function onGameEditList(id, doorId, text)
63 77
   description:setText(tr('Enter one name per line.'))
64 78
   textWindow:setText(tr('Edit List'))
65 79
 
66
-  okButton.onClick = function()
80
+  doneFunc = function()
67 81
     g_game.editList(id, doorId, textEdit:getText())
68
-    textWindow:destroy()
82
+    TextWindow.destroy()
69 83
   end
84
+  
85
+  okButton.onClick = doneFunc
86
+  textWindow.onEnter = doneFunc
87
+  textWindow.onEscape = TextWindow.destroy
70 88
 end
71 89
 
72
-function TextBooks.init()
90
+-- public functions
91
+function TextWindow.init()
73 92
   g_ui.importStyle('textwindow.otui')
74 93
 
75
-  connect(g_game, { onEditText = onGameEditText })
76
-  connect(g_game, { onEditList = onGameEditList })
94
+  connect(g_game, { onEditText = onGameEditText,
95
+                    onEditList = onGameEditList,
96
+                    onGameEnd = TextWindow.destroy })
77 97
 end
78 98
 
79
-function TextBooks.terminate()
80
-  disconnect(g_game, { onEditText = onGameEditText })
81
-  disconnect(g_game, { onEditList = onGameEditList })
99
+function TextWindow.terminate()
100
+  disconnect(g_game, { onEditText = onGameEditText,
101
+                       onEditList = onGameEditList,
102
+                       onGameEnd = TextWindow.destroy })
103
+      
104
+  TextWindow.destroy()
82 105
 end
106
+
107
+function TextWindow.destroy()
108
+  if(textWindow) then
109
+    textWindow:destroy()
110
+    textWindow = nil
111
+  end
112
+end

modules/game_textbooks/textbooks.otmod → modules/game_textwindow/textwindow.otmod View File

@@ -1,15 +1,15 @@
1 1
 Module
2
-  name: game_textbooks
2
+  name: game_textwindow
3 3
   description: Allow to edit text books and lists
4
-  author: edubart
4
+  author: edubart, BeniS
5 5
   website: www.otclient.info
6 6
 
7 7
   dependencies:
8 8
     - game_interface
9 9
 
10 10
   @onLoad: |
11
-    dofile 'textbooks'
12
-    TextBooks.init()
11
+    dofile 'textwindow'
12
+    TextWindow.init()
13 13
 
14 14
   @onUnload: |
15
-    TextBooks.terminate()
15
+    TextWindow.terminate()

modules/game_textbooks/textwindow.otui → modules/game_textwindow/textwindow.otui View File


Loading…
Cancel
Save