OTC now supports showing and answering modal dialogs. addDialog(modaldialog, dialogId, cid, callback) TODO: -find out what the "popup" value does.. (Maybe someone knows)master
parent
bce8e90ede
commit
eb979ef7cd
@ -0,0 +1,69 @@
|
||||
function init()
|
||||
g_ui.importStyle('modaldialog.otui')
|
||||
|
||||
connect(g_game, { onModalDialog = onModalDialog,
|
||||
onGameEnd = destroy })
|
||||
end
|
||||
|
||||
function terminate()
|
||||
disconnect(g_game, { onModalDialog = onModalDialog,
|
||||
onGameEnd = destroy })
|
||||
|
||||
destroy()
|
||||
end
|
||||
|
||||
function destroy()
|
||||
if modalDialog then
|
||||
modalDialog:destroy()
|
||||
modalDialog = nil
|
||||
end
|
||||
end
|
||||
|
||||
function onModalDialog(id, title, message, enterId, enterText, escapeId, escapeText, choices)
|
||||
if modalDialog then return end
|
||||
|
||||
modalDialog = g_ui.createWidget('ModalDialog', rootWidget)
|
||||
|
||||
local enterButton = modalDialog:getChildById('enterButton')
|
||||
local escapeButton = modalDialog:getChildById('escapeButton')
|
||||
local messageLabel = modalDialog:getChildById('messageLabel')
|
||||
local choiceList = modalDialog:getChildById('choiceList')
|
||||
|
||||
modalDialog:setText(title)
|
||||
messageLabel:setText(message)
|
||||
enterButton:setText(enterText)
|
||||
escapeButton:setText(escapeText)
|
||||
|
||||
local focusLabel = nil
|
||||
for k, v in pairs(choices) do
|
||||
local choiceId = v[1]
|
||||
local choiceName = v[2]
|
||||
|
||||
local label = g_ui.createWidget('ChoiceListLabel', choiceList)
|
||||
label.choiceId = choiceId
|
||||
label:setText(choiceName)
|
||||
label:setPhantom(false)
|
||||
|
||||
if not focusLabel then
|
||||
focusLabel = label
|
||||
end
|
||||
end
|
||||
choiceList:focusChild(focusLabel)
|
||||
|
||||
local enterFunc = function()
|
||||
g_game.answerModalDialog(id, enterId, choiceList:getFocusedChild().choiceId)
|
||||
destroy()
|
||||
end
|
||||
|
||||
local escapeFunc = function()
|
||||
g_game.answerModalDialog(id, escapeId, choiceList:getFocusedChild().choiceId)
|
||||
destroy()
|
||||
end
|
||||
|
||||
enterButton.onClick = enterFunc
|
||||
modalDialog.onEnter = enterFunc
|
||||
|
||||
escapeButton.onClick = escapeFunc
|
||||
modalDialog.onEscape = escapeFunc
|
||||
return
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
Module
|
||||
name: game_modaldialog
|
||||
description: Show and process modal dialogs
|
||||
author: Summ
|
||||
website: www.otclient.info
|
||||
sandboxed: true
|
||||
dependencies: [ game_interface ]
|
||||
scripts: [ modaldialog.lua ]
|
||||
@onLoad: init()
|
||||
@onUnload: terminate()
|
@ -0,0 +1,61 @@
|
||||
TextScrollbar < VerticalScrollBar
|
||||
|
||||
ChoiceListLabel < Label
|
||||
font: verdana-11px-monochrome
|
||||
background-color: alpha
|
||||
text-offset: 2 0
|
||||
focusable: true
|
||||
|
||||
$focus:
|
||||
background-color: #ffffff22
|
||||
color: #ffffff
|
||||
|
||||
ModalDialog < MainWindow
|
||||
id: modalDialog
|
||||
!text: tr('Title')
|
||||
size: 280 230
|
||||
@onEscape: self:destroy()
|
||||
|
||||
Label
|
||||
id: messageLabel
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text-align: left
|
||||
text: Message
|
||||
height: 60
|
||||
|
||||
TextList
|
||||
id: choiceList
|
||||
vertical-scrollbar: choiceScrollBar
|
||||
anchors.fill: parent
|
||||
anchors.top: prev.bottom
|
||||
anchors.bottom: next.top
|
||||
margin-bottom: 10
|
||||
margin-top: 10
|
||||
padding: 1
|
||||
focusable: false
|
||||
|
||||
Button
|
||||
id: enterButton
|
||||
!text: tr('Ok')
|
||||
anchors.top: next.top
|
||||
anchors.right: next.left
|
||||
margin-right: 8
|
||||
width: 60
|
||||
|
||||
Button
|
||||
id: escapeButton
|
||||
!text: tr('Cancel')
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
margin-top: 10
|
||||
width: 60
|
||||
|
||||
VerticalScrollBar
|
||||
id: choiceScrollBar
|
||||
anchors.top: choiceList.top
|
||||
anchors.bottom: choiceList.bottom
|
||||
anchors.right: choiceList.right
|
||||
step: 14
|
||||
pixels-scroll: true
|
Loading…
Reference in new issue