2013-01-16 19:27:02 +01:00
|
|
|
local windows = {}
|
2013-01-03 09:24:07 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
2013-01-18 23:39:11 +01:00
|
|
|
g_ui.importStyle('textwindow')
|
2012-07-24 07:30:08 +02:00
|
|
|
|
|
|
|
connect(g_game, { onEditText = onGameEditText,
|
|
|
|
onEditList = onGameEditList,
|
2013-01-16 19:27:02 +01:00
|
|
|
onGameEnd = destroyWindows })
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
|
|
|
disconnect(g_game, { onEditText = onGameEditText,
|
|
|
|
onEditList = onGameEditList,
|
2013-01-16 19:27:02 +01:00
|
|
|
onGameEnd = destroyWindows })
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2013-01-16 19:27:02 +01:00
|
|
|
destroyWindows()
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
2012-07-14 12:59:32 +02:00
|
|
|
|
2013-01-16 19:27:02 +01:00
|
|
|
function destroyWindows()
|
|
|
|
for _,window in pairs(windows) do
|
|
|
|
window:destroy()
|
2012-07-14 12:59:32 +02:00
|
|
|
end
|
2013-01-16 19:27:02 +01:00
|
|
|
windows = {}
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onGameEditText(id, itemId, maxLength, text, writter, time)
|
2013-01-16 19:27:02 +01:00
|
|
|
local textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2013-01-17 12:34:13 +01:00
|
|
|
local writeable = #text < maxLength 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')
|
|
|
|
|
2012-09-30 05:16:57 +02:00
|
|
|
local textScroll = textWindow:getChildById('textScroll')
|
|
|
|
|
2012-05-01 02:20:27 +02:00
|
|
|
textItem:setItemId(itemId)
|
|
|
|
textEdit:setMaxLength(maxLength)
|
|
|
|
textEdit:setText(text)
|
2013-01-17 12:34:13 +01:00
|
|
|
textEdit:setEditable(writeable)
|
|
|
|
textEdit:setCursorVisible(writeable)
|
|
|
|
textEdit:wrapText()
|
2012-09-30 05:16:57 +02:00
|
|
|
|
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-09-06 02:37:52 +02:00
|
|
|
desc = tr('You read the following, written on \n%s.\n', time)
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if #text == 0 and not writeable then
|
2012-09-06 02:37:52 +02:00
|
|
|
desc = tr("It is empty.")
|
2012-05-01 02:20:27 +02:00
|
|
|
elseif writeable then
|
|
|
|
desc = desc .. tr('You can enter new text.')
|
|
|
|
end
|
|
|
|
|
2012-09-06 02:37:52 +02:00
|
|
|
local lines = #{string.find(desc, '\n')}
|
|
|
|
if lines < 2 then desc = desc .. '\n' end
|
|
|
|
|
2012-05-01 02:20:27 +02:00
|
|
|
description:setText(desc)
|
2012-05-01 02:53:02 +02:00
|
|
|
|
|
|
|
if not writeable then
|
|
|
|
textWindow:setText(tr('Show Text'))
|
|
|
|
cancelButton:hide()
|
2012-09-06 02:37:52 +02:00
|
|
|
cancelButton:setWidth(0)
|
|
|
|
okButton:setMarginRight(0)
|
2012-05-01 02:53:02 +02:00
|
|
|
else
|
|
|
|
textWindow:setText(tr('Edit Text'))
|
|
|
|
end
|
|
|
|
|
2013-01-16 19:27:02 +01:00
|
|
|
local function destroy()
|
|
|
|
textWindow:destroy()
|
|
|
|
table.removevalue(windows, textWindow)
|
|
|
|
end
|
|
|
|
|
2012-09-06 02:37:52 +02:00
|
|
|
local doneFunc = function()
|
2012-05-01 02:53:02 +02:00
|
|
|
if writeable then
|
|
|
|
g_game.editText(id, textEdit:getText())
|
|
|
|
end
|
2012-09-06 02:37:52 +02:00
|
|
|
destroy()
|
|
|
|
end
|
2012-10-03 17:51:07 +02:00
|
|
|
|
2012-09-06 02:37:52 +02:00
|
|
|
okButton.onClick = doneFunc
|
2013-01-18 06:27:29 +01:00
|
|
|
cancelButton.onClick = destroy
|
2012-09-06 02:37:52 +02:00
|
|
|
|
2013-01-16 17:20:17 +01:00
|
|
|
if not writeable then
|
|
|
|
textWindow.onEnter = doneFunc
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
2012-07-24 07:30:08 +02:00
|
|
|
|
2013-01-18 06:27:29 +01:00
|
|
|
textWindow.onEscape = destroy
|
2013-01-16 19:27:02 +01:00
|
|
|
|
|
|
|
table.insert(windows, textWindow)
|
2012-05-01 02:20:27 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onGameEditList(id, doorId, text)
|
2013-01-16 19:27:02 +01:00
|
|
|
local 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)
|
2013-01-17 12:34:13 +01:00
|
|
|
textEdit:setEditable(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'))
|
|
|
|
|
2013-01-16 19:27:02 +01:00
|
|
|
local function destroy()
|
|
|
|
textWindow:destroy()
|
|
|
|
table.removevalue(windows, textWindow)
|
|
|
|
end
|
|
|
|
|
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-24 07:30:08 +02:00
|
|
|
destroy()
|
2012-05-01 02:53:02 +02:00
|
|
|
end
|
2012-07-24 07:30:08 +02:00
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
okButton.onClick = doneFunc
|
2013-01-18 06:27:29 +01:00
|
|
|
cancelButton.onClick = destroy
|
2013-01-17 15:23:01 +01:00
|
|
|
|
2012-07-14 12:59:32 +02:00
|
|
|
textWindow.onEnter = doneFunc
|
2013-01-18 06:27:29 +01:00
|
|
|
textWindow.onEscape = destroy
|
2013-01-16 17:20:17 +01:00
|
|
|
|
2013-01-16 19:27:02 +01:00
|
|
|
table.insert(windows, textWindow)
|
|
|
|
end
|