tibia-client/modules/game_textwindow/textwindow.lua

134 lines
3.6 KiB
Lua
Raw Normal View History

function init()
g_ui.importStyle('textwindow.otui')
connect(g_game, { onEditText = onGameEditText,
onEditList = onGameEditList,
onGameEnd = destroy })
end
function terminate()
disconnect(g_game, { onEditText = onGameEditText,
onEditList = onGameEditList,
onGameEnd = destroy })
destroy()
end
function destroy()
if textWindow then
textWindow:destroy()
textWindow = nil
end
end
function onGameEditText(id, itemId, maxLength, text, writter, time)
if textWindow then return end
textWindow = g_ui.createWidget('TextWindow', rootWidget)
2012-05-01 02:53:02 +02:00
local writeable = (maxLength ~= #text) and maxLength > 0
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)
local desc = ''
if #writter > 0 then
desc = tr('You read the following, written by \n%s\n', writter)
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)
end
if #text == 0 and not writeable then
2012-09-06 02:37:52 +02:00
desc = tr("It is empty.")
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
description:setText(desc)
2012-05-01 02:53:02 +02:00
if not writeable then
textWindow:setText(tr('Show Text'))
2012-09-06 02:37:52 +02:00
--textEdit:wrapText()
2012-05-01 02:53:02 +02:00
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
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
okButton.onClick = doneFunc
cancelButton.onClick = destroy
--textWindow.onEnter = doneFunc -- this should be '\n'
textWindow.onEscape = destroy
end
function onGameEditList(id, doorId, text)
if textWindow then return end
textWindow = g_ui.createWidget('TextWindow', rootWidget)
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)
description:setText(tr('Enter one name per line.'))
textWindow:setText(tr('Edit List'))
doneFunc = function()
g_game.editList(id, doorId, textEdit:getText())
destroy()
end
okButton.onClick = doneFunc
textWindow.onEnter = doneFunc
textWindow.onEscape = destroy
end
2012-09-06 02:37:52 +02:00
function onGameEditList(id, doorId, text)
if textWindow then 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'))
doneFunc = function()
2012-05-01 02:53:02 +02:00
g_game.editList(id, doorId, textEdit:getText())
destroy()
2012-05-01 02:53:02 +02:00
end
okButton.onClick = doneFunc
textWindow.onEnter = doneFunc
textWindow.onEscape = destroy
end