tibia-client/modules/game_textbooks/textbooks.lua

83 lines
2.3 KiB
Lua
Raw Normal View History

TextBooks = {}
local function onGameEditText(id, itemId, maxLength, text, writter, time)
2012-06-26 00:13:30 +02:00
local 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
desc = tr('You read the following, written on %s.\n', time)
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
okButton.onClick = function()
2012-05-01 02:53:02 +02:00
if writeable then
g_game.editText(id, textEdit:getText())
end
textWindow:destroy()
end
end
2012-05-01 02:53:02 +02:00
local function onGameEditList(id, doorId, text)
2012-06-26 00:13:30 +02: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)
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'))
okButton.onClick = function()
g_game.editList(id, doorId, textEdit:getText())
textWindow:destroy()
end
end
function TextBooks.init()
2012-06-26 00:13:30 +02:00
g_ui.importStyle('textwindow.otui')
connect(g_game, { onEditText = onGameEditText })
connect(g_game, { onEditList = onGameEditList })
end
function TextBooks.terminate()
disconnect(g_game, { onEditText = onGameEditText })
disconnect(g_game, { onEditList = onGameEditList })
end