bpm91
Advanced OT User
- Joined
- May 23, 2019
- Messages
- 1,046
- Solutions
- 7
- Reaction score
- 180
- Location
- Brazil
- YouTube
- caruniawikibr
Does this happend on OTC only or on CIP CLient too?i have same issue can open letters repeatedly how to fix this?
otc onlyDoes this happend on OTC only or on CIP CLient too?
windows = {}
local activeTextWindow = nil
function init()
g_ui.importStyle('textwindow')
connect(g_game, {
onEditText = onGameEditText,
onEditList = onGameEditList,
onGameEnd = destroyWindows
})
end
function terminate()
disconnect(g_game, {
onEditText = onGameEditText,
onEditList = onGameEditList,
onGameEnd = destroyWindows
})
destroyWindows()
end
function destroyWindows()
for _, window in pairs(windows) do
window:destroy()
end
windows = {}
activeTextWindow = nil
end
function onGameEditText(id, itemId, maxLength, text, writer, time)
if activeTextWindow then
return
end
local writeable = maxLength > 0 and #text < maxLength
local textWindow = g_ui.createWidget('TextWindow', rootWidget)
activeTextWindow = textWindow
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')
local thing = g_things.getThingType(itemId)
if writeable and thing and thing:hasAttribute(ThingAttrWritableOnce) and #writer > 0 then
writeable = false
end
textItem:setItemId(itemId)
textEdit:setMaxLength(maxLength)
textEdit:setText(text)
textEdit:setEditable(writeable)
textEdit:setCursorVisible(writeable)
local desc = tr('You read the following.')
if #writer > 0 then
desc = tr('You read the following, written by \n%s', writer)
if #time > 0 then
desc = desc .. tr(' on %s.\n', time)
else
desc = desc .. '.\n'
end
elseif #time > 0 then
desc = tr('You read the following, written on \n%s.\n', time)
end
if #text == 0 and not writeable then
desc = tr('It is empty.')
elseif writeable and #text == 0 then
desc = tr('It is currently empty.\nYou can enter new text.')
elseif writeable then
desc = desc .. tr('You can enter new text.')
end
description:setText(desc)
if not writeable then
textWindow:setText(tr('Show Text'))
cancelButton:hide()
cancelButton:setWidth(0)
else
textWindow:setText(tr('Edit Text'))
end
local function destroy()
activeTextWindow = nil
textWindow:destroy()
table.removevalue(windows, textWindow)
end
okButton.onClick = function()
if writeable then
g_game.editText(id, textEdit:getText())
end
destroy()
end
cancelButton.onClick = destroy
textWindow.onEscape = destroy
table.insert(windows, textWindow)
end
function onGameEditList(id, doorId, text)
if activeTextWindow then
return
end
local textWindow = g_ui.createWidget('TextWindow', rootWidget)
activeTextWindow = textWindow
local textEdit = textWindow:getChildById('text')
local description = textWindow:getChildById('description')
local okButton = textWindow:getChildById('okButton')
local cancelButton= textWindow:getChildById('cancelButton')
local textItem = textWindow:getChildById('textItem')
if textItem then textItem:hide() end
textEdit:setMaxLength(8192)
textEdit:setText(text)
textEdit:setEditable(true)
description:setText(tr('Enter one name per line.'))
textWindow:setText(tr('Edit List'))
local function destroy()
activeTextWindow = nil
textWindow:destroy()
table.removevalue(windows, textWindow)
end
okButton.onClick = function()
g_game.editList(id, doorId, textEdit:getText())
destroy()
end
cancelButton.onClick = destroy
textWindow.onEscape = destroy
table.insert(windows, textWindow)
end
ty broI'm not sure if anyone is still looking for this, but this was my solution to this problem:
modules\game_textwindow\textwindow.lua
LUA:windows = {} local activeTextWindow = nil function init() g_ui.importStyle('textwindow') connect(g_game, { onEditText = onGameEditText, onEditList = onGameEditList, onGameEnd = destroyWindows }) end function terminate() disconnect(g_game, { onEditText = onGameEditText, onEditList = onGameEditList, onGameEnd = destroyWindows }) destroyWindows() end function destroyWindows() for _, window in pairs(windows) do window:destroy() end windows = {} activeTextWindow = nil end function onGameEditText(id, itemId, maxLength, text, writer, time) if activeTextWindow then return end local writeable = maxLength > 0 and #text < maxLength local textWindow = g_ui.createWidget('TextWindow', rootWidget) activeTextWindow = textWindow 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') local thing = g_things.getThingType(itemId) if writeable and thing and thing:hasAttribute(ThingAttrWritableOnce) and #writer > 0 then writeable = false end textItem:setItemId(itemId) textEdit:setMaxLength(maxLength) textEdit:setText(text) textEdit:setEditable(writeable) textEdit:setCursorVisible(writeable) local desc = tr('You read the following.') if #writer > 0 then desc = tr('You read the following, written by \n%s', writer) if #time > 0 then desc = desc .. tr(' on %s.\n', time) else desc = desc .. '.\n' end elseif #time > 0 then desc = tr('You read the following, written on \n%s.\n', time) end if #text == 0 and not writeable then desc = tr('It is empty.') elseif writeable and #text == 0 then desc = tr('It is currently empty.\nYou can enter new text.') elseif writeable then desc = desc .. tr('You can enter new text.') end description:setText(desc) if not writeable then textWindow:setText(tr('Show Text')) cancelButton:hide() cancelButton:setWidth(0) else textWindow:setText(tr('Edit Text')) end local function destroy() activeTextWindow = nil textWindow:destroy() table.removevalue(windows, textWindow) end okButton.onClick = function() if writeable then g_game.editText(id, textEdit:getText()) end destroy() end cancelButton.onClick = destroy textWindow.onEscape = destroy table.insert(windows, textWindow) end function onGameEditList(id, doorId, text) if activeTextWindow then return end local textWindow = g_ui.createWidget('TextWindow', rootWidget) activeTextWindow = textWindow local textEdit = textWindow:getChildById('text') local description = textWindow:getChildById('description') local okButton = textWindow:getChildById('okButton') local cancelButton= textWindow:getChildById('cancelButton') local textItem = textWindow:getChildById('textItem') if textItem then textItem:hide() end textEdit:setMaxLength(8192) textEdit:setText(text) textEdit:setEditable(true) description:setText(tr('Enter one name per line.')) textWindow:setText(tr('Edit List')) local function destroy() activeTextWindow = nil textWindow:destroy() table.removevalue(windows, textWindow) end okButton.onClick = function() g_game.editList(id, doorId, textEdit:getText()) destroy() end cancelButton.onClick = destroy textWindow.onEscape = destroy table.insert(windows, textWindow) end