You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
12 years ago
|
TextWindow = {}
|
||
12 years ago
|
|
||
12 years ago
|
-- private variables
|
||
|
local textWindow
|
||
|
|
||
|
-- private functions
|
||
12 years ago
|
local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||
12 years ago
|
if(textWindow) then
|
||
|
return
|
||
|
end
|
||
|
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
||
12 years ago
|
|
||
12 years ago
|
local writeable = (maxLength ~= #text) and maxLength > 0
|
||
12 years ago
|
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)
|
||
|
|
||
12 years ago
|
local desc = ''
|
||
12 years ago
|
if #writter > 0 then
|
||
12 years ago
|
desc = tr('You read the following, written by \n%s\n', writter)
|
||
12 years ago
|
|
||
|
if #time > 0 then
|
||
|
desc = desc .. tr('on %s.\n', time)
|
||
|
end
|
||
|
elseif #time > 0 then
|
||
12 years ago
|
desc = tr('You read the following, written on %s.\n', time)
|
||
12 years ago
|
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)
|
||
12 years ago
|
|
||
|
if not writeable then
|
||
|
textWindow:setText(tr('Show Text'))
|
||
|
cancelButton:hide()
|
||
|
else
|
||
|
textWindow:setText(tr('Edit Text'))
|
||
|
end
|
||
|
|
||
12 years ago
|
doneFunc = function()
|
||
12 years ago
|
if writeable then
|
||
|
g_game.editText(id, textEdit:getText())
|
||
|
end
|
||
12 years ago
|
TextWindow.destroy()
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
|
okButton.onClick = doneFunc
|
||
|
textWindow.onEnter = doneFunc
|
||
|
textWindow.onEscape = TextWindow.destroy
|
||
12 years ago
|
end
|
||
|
|
||
12 years ago
|
local function onGameEditList(id, doorId, text)
|
||
12 years ago
|
if(textWindow) then
|
||
|
return
|
||
|
end
|
||
|
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
||
12 years ago
|
|
||
|
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)
|
||
12 years ago
|
description:setText(tr('Enter one name per line.'))
|
||
12 years ago
|
textWindow:setText(tr('Edit List'))
|
||
|
|
||
12 years ago
|
doneFunc = function()
|
||
12 years ago
|
g_game.editList(id, doorId, textEdit:getText())
|
||
12 years ago
|
TextWindow.destroy()
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
|
okButton.onClick = doneFunc
|
||
|
textWindow.onEnter = doneFunc
|
||
|
textWindow.onEscape = TextWindow.destroy
|
||
12 years ago
|
end
|
||
|
|
||
12 years ago
|
-- public functions
|
||
|
function TextWindow.init()
|
||
12 years ago
|
g_ui.importStyle('textwindow.otui')
|
||
12 years ago
|
|
||
12 years ago
|
connect(g_game, { onEditText = onGameEditText,
|
||
|
onEditList = onGameEditList,
|
||
|
onGameEnd = TextWindow.destroy })
|
||
12 years ago
|
end
|
||
|
|
||
12 years ago
|
function TextWindow.terminate()
|
||
|
disconnect(g_game, { onEditText = onGameEditText,
|
||
|
onEditList = onGameEditList,
|
||
|
onGameEnd = TextWindow.destroy })
|
||
|
|
||
|
TextWindow.destroy()
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
|
function TextWindow.destroy()
|
||
|
if(textWindow) then
|
||
|
textWindow:destroy()
|
||
|
textWindow = nil
|
||
|
end
|
||
|
end
|