From 52ede065fc449e3bd87b207d0c15fe79f0ea964e Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 16 Jan 2013 16:27:02 -0200 Subject: [PATCH] Make text windows stackable, fix #152 --- .travis.yml | 4 +-- modules/game_textwindow/textwindow.lua | 37 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8138f7d6..451ceb7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,7 @@ language: cpp compiler: - gcc before_script: - - sudo apt-add-repository ppa:28msec/boost -y - - sudo apt-get update -y - - sudo apt-get install libboost-all-dev libphysfs-dev libssl-dev liblua5.1-dev libglew1.6-dev libvorbis-dev libopenal-dev libz-dev -y + - 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 script: | cmake . -DCMAKE_BUILD_TYPE=Release make diff --git a/modules/game_textwindow/textwindow.lua b/modules/game_textwindow/textwindow.lua index cf58e89b..cc236fd2 100644 --- a/modules/game_textwindow/textwindow.lua +++ b/modules/game_textwindow/textwindow.lua @@ -1,31 +1,30 @@ -local textWindow = nil +local windows = {} function init() g_ui.importStyle('textwindow.otui') connect(g_game, { onEditText = onGameEditText, onEditList = onGameEditList, - onGameEnd = destroy }) + onGameEnd = destroyWindows }) end function terminate() disconnect(g_game, { onEditText = onGameEditText, onEditList = onGameEditList, - onGameEnd = destroy }) + onGameEnd = destroyWindows }) - destroy() + destroyWindows() end -function destroy() - if textWindow then - textWindow:destroy() - textWindow = nil +function destroyWindows() + for _,window in pairs(windows) do + window:destroy() end + windows = {} end function onGameEditText(id, itemId, maxLength, text, writter, time) - if textWindow then return end - textWindow = g_ui.createWidget('TextWindow', rootWidget) + local textWindow = g_ui.createWidget('TextWindow', rootWidget) local writeable = (maxLength ~= #text) and maxLength > 0 local textItem = textWindow:getChildById('textItem') @@ -72,6 +71,11 @@ function onGameEditText(id, itemId, maxLength, text, writter, time) textWindow:setText(tr('Edit Text')) end + local function destroy() + textWindow:destroy() + table.removevalue(windows, textWindow) + end + local doneFunc = function() if writeable then g_game.editText(id, textEdit:getText()) @@ -87,11 +91,12 @@ function onGameEditText(id, itemId, maxLength, text, writter, time) end textWindow.onEscape = destroy + + table.insert(windows, textWindow) end function onGameEditList(id, doorId, text) - if textWindow then return end - textWindow = g_ui.createWidget('TextWindow', rootWidget) + local textWindow = g_ui.createWidget('TextWindow', rootWidget) local textEdit = textWindow:getChildById('text') local description = textWindow:getChildById('description') @@ -104,6 +109,11 @@ function onGameEditList(id, doorId, text) description:setText(tr('Enter one name per line.')) textWindow:setText(tr('Edit List')) + local function destroy() + textWindow:destroy() + table.removevalue(windows, textWindow) + end + doneFunc = function() g_game.editList(id, doorId, textEdit:getText()) destroy() @@ -112,5 +122,6 @@ function onGameEditList(id, doorId, text) okButton.onClick = doneFunc textWindow.onEnter = doneFunc textWindow.onEscape = destroy -end + table.insert(windows, textWindow) +end