mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
Changed/Fixed Text Windows, Text Message, Hotkeys Manager, Game Interface and Quest Log
* Renamed game_textbooks to game_textwindow. * Fixed text window from opening multiple times, and is destroyed correctly. * Added new game_playerdeath module (moved death message and window here). * Hotkey window will hide on game end. * Logout/Exit/Stackable Items/Questlog/Hotkeys windows will now close on game end.
This commit is contained in:
112
modules/game_textwindow/textwindow.lua
Normal file
112
modules/game_textwindow/textwindow.lua
Normal file
@@ -0,0 +1,112 @@
|
||||
TextWindow = {}
|
||||
|
||||
-- private variables
|
||||
local textWindow
|
||||
|
||||
-- private functions
|
||||
local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||
if(textWindow) then
|
||||
return
|
||||
end
|
||||
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
||||
|
||||
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)
|
||||
|
||||
if not writeable then
|
||||
textWindow:setText(tr('Show Text'))
|
||||
cancelButton:hide()
|
||||
else
|
||||
textWindow:setText(tr('Edit Text'))
|
||||
end
|
||||
|
||||
doneFunc = function()
|
||||
if writeable then
|
||||
g_game.editText(id, textEdit:getText())
|
||||
end
|
||||
TextWindow.destroy()
|
||||
end
|
||||
|
||||
okButton.onClick = doneFunc
|
||||
textWindow.onEnter = doneFunc
|
||||
textWindow.onEscape = TextWindow.destroy
|
||||
end
|
||||
|
||||
local 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())
|
||||
TextWindow.destroy()
|
||||
end
|
||||
|
||||
okButton.onClick = doneFunc
|
||||
textWindow.onEnter = doneFunc
|
||||
textWindow.onEscape = TextWindow.destroy
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function TextWindow.init()
|
||||
g_ui.importStyle('textwindow.otui')
|
||||
|
||||
connect(g_game, { onEditText = onGameEditText,
|
||||
onEditList = onGameEditList,
|
||||
onGameEnd = TextWindow.destroy })
|
||||
end
|
||||
|
||||
function TextWindow.terminate()
|
||||
disconnect(g_game, { onEditText = onGameEditText,
|
||||
onEditList = onGameEditList,
|
||||
onGameEnd = TextWindow.destroy })
|
||||
|
||||
TextWindow.destroy()
|
||||
end
|
||||
|
||||
function TextWindow.destroy()
|
||||
if(textWindow) then
|
||||
textWindow:destroy()
|
||||
textWindow = nil
|
||||
end
|
||||
end
|
15
modules/game_textwindow/textwindow.otmod
Normal file
15
modules/game_textwindow/textwindow.otmod
Normal file
@@ -0,0 +1,15 @@
|
||||
Module
|
||||
name: game_textwindow
|
||||
description: Allow to edit text books and lists
|
||||
author: edubart, BeniS
|
||||
website: www.otclient.info
|
||||
|
||||
dependencies:
|
||||
- game_interface
|
||||
|
||||
@onLoad: |
|
||||
dofile 'textwindow'
|
||||
TextWindow.init()
|
||||
|
||||
@onUnload: |
|
||||
TextWindow.terminate()
|
46
modules/game_textwindow/textwindow.otui
Normal file
46
modules/game_textwindow/textwindow.otui
Normal file
@@ -0,0 +1,46 @@
|
||||
TextWindow < MainWindow
|
||||
id: textWindow
|
||||
size: 280 280
|
||||
@onEscape: self:destroy()
|
||||
|
||||
UIItem
|
||||
id: textItem
|
||||
virtual: true
|
||||
item-id: 173
|
||||
size: 32 32
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
|
||||
Label
|
||||
id: description
|
||||
anchors.top: parent.top
|
||||
anchors.left: textItem.right
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: text.top
|
||||
text-align: left
|
||||
margin-left: 8
|
||||
margin-bottom: 10
|
||||
|
||||
MultilineTextEdit
|
||||
id: text
|
||||
anchors.fill: parent
|
||||
anchors.top: textItem.bottom
|
||||
margin-top: 30
|
||||
margin-bottom: 30
|
||||
|
||||
Button
|
||||
id: cancelButton
|
||||
!text: tr('Cancel')
|
||||
anchors.top: next.top
|
||||
anchors.right: next.left
|
||||
margin-right: 8
|
||||
width: 60
|
||||
@onClick: self:getParent():destroy()
|
||||
|
||||
Button
|
||||
id: okButton
|
||||
!text: tr('Ok')
|
||||
anchors.top: text.bottom
|
||||
anchors.right: text.right
|
||||
margin-top: 10
|
||||
width: 60
|
Reference in New Issue
Block a user