Browse Source

Make text windows stackable, fix #152

Eduardo Bart 8 years ago
parent
commit
52ede065fc
2 changed files with 25 additions and 16 deletions
  1. 1
    3
      .travis.yml
  2. 24
    13
      modules/game_textwindow/textwindow.lua

+ 1
- 3
.travis.yml View File

@@ -2,9 +2,7 @@ language: cpp
2 2
 compiler:
3 3
   - gcc
4 4
 before_script:
5
-  - sudo apt-add-repository ppa:28msec/boost -y
6
-  - sudo apt-get update -y
7
-  - sudo apt-get install libboost-all-dev libphysfs-dev libssl-dev liblua5.1-dev libglew1.6-dev libvorbis-dev libopenal-dev libz-dev -y
5
+  - sudo apt-get install libboost1.48-all-dev libphysfs-dev libssl-dev liblua5.1-dev libglew1.6-dev libvorbis-dev libopenal-dev libz-dev -y
8 6
 script: |
9 7
   cmake . -DCMAKE_BUILD_TYPE=Release
10 8
   make

+ 24
- 13
modules/game_textwindow/textwindow.lua View File

@@ -1,31 +1,30 @@
1
-local textWindow = nil
1
+local windows = {}
2 2
 
3 3
 function init()
4 4
   g_ui.importStyle('textwindow.otui')
5 5
 
6 6
   connect(g_game, { onEditText = onGameEditText,
7 7
                     onEditList = onGameEditList,
8
-                    onGameEnd = destroy })
8
+                    onGameEnd = destroyWindows })
9 9
 end
10 10
 
11 11
 function terminate()
12 12
   disconnect(g_game, { onEditText = onGameEditText,
13 13
                        onEditList = onGameEditList,
14
-                       onGameEnd = destroy })
14
+                       onGameEnd = destroyWindows })
15 15
 
16
-  destroy()
16
+  destroyWindows()
17 17
 end
18 18
 
19
-function destroy()
20
-  if textWindow then
21
-    textWindow:destroy()
22
-    textWindow = nil
19
+function destroyWindows()
20
+  for _,window in pairs(windows) do
21
+    window:destroy()
23 22
   end
23
+  windows = {}
24 24
 end
25 25
 
26 26
 function onGameEditText(id, itemId, maxLength, text, writter, time)
27
-  if textWindow then return end
28
-  textWindow = g_ui.createWidget('TextWindow', rootWidget)
27
+  local textWindow = g_ui.createWidget('TextWindow', rootWidget)
29 28
 
30 29
   local writeable = (maxLength ~= #text) and maxLength > 0
31 30
   local textItem = textWindow:getChildById('textItem')
@@ -72,6 +71,11 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
72 71
     textWindow:setText(tr('Edit Text'))
73 72
   end
74 73
 
74
+  local function destroy()
75
+    textWindow:destroy()
76
+    table.removevalue(windows, textWindow)
77
+  end
78
+
75 79
   local doneFunc = function()
76 80
     if writeable then
77 81
       g_game.editText(id, textEdit:getText())
@@ -87,11 +91,12 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
87 91
   end
88 92
 
89 93
   textWindow.onEscape = destroy
94
+
95
+  table.insert(windows, textWindow)
90 96
 end
91 97
 
92 98
 function onGameEditList(id, doorId, text)
93
-  if textWindow then return end
94
-  textWindow = g_ui.createWidget('TextWindow', rootWidget)
99
+  local textWindow = g_ui.createWidget('TextWindow', rootWidget)
95 100
 
96 101
   local textEdit = textWindow:getChildById('text')
97 102
   local description = textWindow:getChildById('description')
@@ -104,6 +109,11 @@ function onGameEditList(id, doorId, text)
104 109
   description:setText(tr('Enter one name per line.'))
105 110
   textWindow:setText(tr('Edit List'))
106 111
 
112
+  local function destroy()
113
+    textWindow:destroy()
114
+    table.removevalue(windows, textWindow)
115
+  end
116
+
107 117
   doneFunc = function()
108 118
     g_game.editList(id, doorId, textEdit:getText())
109 119
     destroy()
@@ -112,5 +122,6 @@ function onGameEditList(id, doorId, text)
112 122
   okButton.onClick = doneFunc
113 123
   textWindow.onEnter = doneFunc
114 124
   textWindow.onEscape = destroy
115
-end
116 125
 
126
+  table.insert(windows, textWindow)
127
+end

Loading…
Cancel
Save