Make text windows stackable, fix #152

This commit is contained in:
Eduardo Bart 2013-01-16 16:27:02 -02:00
parent a80e758e32
commit 52ede065fc
2 changed files with 25 additions and 16 deletions

View File

@ -2,9 +2,7 @@ language: cpp
compiler: compiler:
- gcc - gcc
before_script: before_script:
- sudo apt-add-repository ppa:28msec/boost -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
- 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
script: | script: |
cmake . -DCMAKE_BUILD_TYPE=Release cmake . -DCMAKE_BUILD_TYPE=Release
make make

View File

@ -1,31 +1,30 @@
local textWindow = nil local windows = {}
function init() function init()
g_ui.importStyle('textwindow.otui') g_ui.importStyle('textwindow.otui')
connect(g_game, { onEditText = onGameEditText, connect(g_game, { onEditText = onGameEditText,
onEditList = onGameEditList, onEditList = onGameEditList,
onGameEnd = destroy }) onGameEnd = destroyWindows })
end end
function terminate() function terminate()
disconnect(g_game, { onEditText = onGameEditText, disconnect(g_game, { onEditText = onGameEditText,
onEditList = onGameEditList, onEditList = onGameEditList,
onGameEnd = destroy }) onGameEnd = destroyWindows })
destroy() destroyWindows()
end end
function destroy() function destroyWindows()
if textWindow then for _,window in pairs(windows) do
textWindow:destroy() window:destroy()
textWindow = nil
end end
windows = {}
end end
function onGameEditText(id, itemId, maxLength, text, writter, time) function onGameEditText(id, itemId, maxLength, text, writter, time)
if textWindow then return end local textWindow = g_ui.createWidget('TextWindow', rootWidget)
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')
@ -72,6 +71,11 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
textWindow:setText(tr('Edit Text')) textWindow:setText(tr('Edit Text'))
end end
local function destroy()
textWindow:destroy()
table.removevalue(windows, textWindow)
end
local doneFunc = function() local doneFunc = function()
if writeable then if writeable then
g_game.editText(id, textEdit:getText()) g_game.editText(id, textEdit:getText())
@ -87,11 +91,12 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
end end
textWindow.onEscape = destroy textWindow.onEscape = destroy
table.insert(windows, textWindow)
end end
function onGameEditList(id, doorId, text) function onGameEditList(id, doorId, text)
if textWindow then return end local textWindow = g_ui.createWidget('TextWindow', rootWidget)
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')
@ -104,6 +109,11 @@ 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'))
local function destroy()
textWindow:destroy()
table.removevalue(windows, textWindow)
end
doneFunc = function() doneFunc = function()
g_game.editList(id, doorId, textEdit:getText()) g_game.editList(id, doorId, textEdit:getText())
destroy() destroy()
@ -112,5 +122,6 @@ function onGameEditList(id, doorId, text)
okButton.onClick = doneFunc okButton.onClick = doneFunc
textWindow.onEnter = doneFunc textWindow.onEnter = doneFunc
textWindow.onEscape = destroy textWindow.onEscape = destroy
end
table.insert(windows, textWindow)
end