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:
BeniS
2012-07-14 22:59:32 +12:00
parent e3298d561c
commit 694a69e1bf
12 changed files with 163 additions and 65 deletions

View 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

View 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()

View 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