2012-07-14 12:59:32 +02:00
|
|
|
TextWindow = {}
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
-- private variables
|
|
|
|
local textWindow
|
|
|
|
|
|
|
|
-- private functions
|
2012-05-01 02:20:27 +02:00
|
|
|
local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
2012-07-15 13:49:28 +02:00
|
|
|
if textWindow then
|
2012-07-14 12:59:32 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2012-05-01 02:53:02 +02:00
|
|
|
local writeable = (maxLength ~= #text) and maxLength > 0
|
2012-05-01 02:20:27 +02:00
|
|
|
local textItem = textWindow:getChildById('textItem')
|
|
|
|
local description = textWindow:getChildById('description')
|
|
|
|
local textEdit = textWindow:getChildById('text')
|
|
|
|
local okButton = textWindow:getChildById('okButton')
|
|
|
|
local cancelButton = textWindow:getChildById('cancelButton')
|
|
|
|
|
|
|
|
textItem:setItemId(itemId)
|
|
|
|
textEdit:setMaxLength(maxLength)
|
|
|
|
textEdit:setText(text)
|
|
|
|
textEdit:setEnabled(writeable)
|
|
|
|
|
2012-05-01 15:06:38 +02:00
|
|
|
local desc = ''
|
2012-05-01 02:20:27 +02:00
|
|
|
if #writter > 0 then
|
2012-05-01 15:06:38 +02:00
|
|
|
desc = tr('You read the following, written by \n%s\n', writter)
|
2012-05-01 02:20:27 +02:00
|
|
|
|
|
|
|
if #time > 0 then
|
|
|
|
desc = desc .. tr('on %s.\n', time)
|
|
|
|
end
|
|
|
|
elseif #time > 0 then
|
2012-05-01 15:06:38 +02:00
|
|
|
desc = tr('You read the following, written on %s.\n', time)
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if #text == 0 and not writeable then
|
|
|
|
desc = tr("It is empty.\n")
|
|
|
|
elseif writeable then
|
|
|
|
desc = desc .. tr('You can enter new text.')
|
|
|
|
end
|
|
|
|
|
|
|
|
description:setText(desc)
|
2012-05-01 02:53:02 +02:00
|
|
|
|
|
|
|
if not writeable then
|
|
|
|
textWindow:setText(tr('Show Text'))
|
|
|
|
cancelButton:hide()
|
|
|
|
else
|
|
|
|
textWindow:setText(tr('Edit Text'))
|
|
|
|
end
|
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
doneFunc = function()
|
2012-05-01 02:53:02 +02:00
|
|
|
if writeable then
|
|
|
|
g_game.editText(id, textEdit:getText())
|
|
|
|
end
|
2012-07-14 12:59:32 +02:00
|
|
|
TextWindow.destroy()
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
2012-07-14 12:59:32 +02:00
|
|
|
|
|
|
|
okButton.onClick = doneFunc
|
|
|
|
textWindow.onEnter = doneFunc
|
|
|
|
textWindow.onEscape = TextWindow.destroy
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
2012-05-01 02:53:02 +02:00
|
|
|
local function onGameEditList(id, doorId, text)
|
2012-07-15 13:49:28 +02:00
|
|
|
if textWindow then
|
2012-07-14 12:59:32 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
2012-05-01 02:53:02 +02:00
|
|
|
|
|
|
|
local textEdit = textWindow:getChildById('text')
|
|
|
|
local description = textWindow:getChildById('description')
|
|
|
|
local okButton = textWindow:getChildById('okButton')
|
|
|
|
local cancelButton = textWindow:getChildById('cancelButton')
|
|
|
|
|
|
|
|
textEdit:setMaxLength(8192)
|
|
|
|
textEdit:setText(text)
|
|
|
|
textEdit:setEnabled(true)
|
2012-05-01 04:00:07 +02:00
|
|
|
description:setText(tr('Enter one name per line.'))
|
2012-05-01 02:53:02 +02:00
|
|
|
textWindow:setText(tr('Edit List'))
|
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
doneFunc = function()
|
2012-05-01 02:53:02 +02:00
|
|
|
g_game.editList(id, doorId, textEdit:getText())
|
2012-07-14 12:59:32 +02:00
|
|
|
TextWindow.destroy()
|
2012-05-01 02:53:02 +02:00
|
|
|
end
|
2012-07-14 12:59:32 +02:00
|
|
|
|
|
|
|
okButton.onClick = doneFunc
|
|
|
|
textWindow.onEnter = doneFunc
|
|
|
|
textWindow.onEscape = TextWindow.destroy
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
-- public functions
|
|
|
|
function TextWindow.init()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_ui.importStyle('textwindow.otui')
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
connect(g_game, { onEditText = onGameEditText,
|
|
|
|
onEditList = onGameEditList,
|
|
|
|
onGameEnd = TextWindow.destroy })
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
function TextWindow.terminate()
|
|
|
|
disconnect(g_game, { onEditText = onGameEditText,
|
|
|
|
onEditList = onGameEditList,
|
|
|
|
onGameEnd = TextWindow.destroy })
|
|
|
|
|
|
|
|
TextWindow.destroy()
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
2012-07-14 12:59:32 +02:00
|
|
|
|
|
|
|
function TextWindow.destroy()
|
2012-07-15 13:49:28 +02:00
|
|
|
if textWindow then
|
2012-07-14 12:59:32 +02:00
|
|
|
textWindow:destroy()
|
|
|
|
textWindow = nil
|
|
|
|
end
|
|
|
|
end
|