mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-20 06:33:26 +02:00
Updaded modaldialog and bot (added anti push)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
modalDialog = nil
|
||||
lastDialogChoices = 0
|
||||
lastDialogChoice = 0
|
||||
lastDialogAnswer = 0
|
||||
|
||||
function init()
|
||||
g_ui.importStyle('modaldialog')
|
||||
@@ -53,7 +56,13 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c
|
||||
labelHeight = label:getHeight()
|
||||
end
|
||||
end
|
||||
choiceList:focusNextChild()
|
||||
if #choices > 0 then
|
||||
if g_clock.millis() < lastDialogAnswer + 1000 and lastDialogChoices == #choices then
|
||||
choiceList:focusChild(choiceList:getChildByIndex(lastDialogChoice))
|
||||
else
|
||||
choiceList:focusChild(choiceList:getFirstChild())
|
||||
end
|
||||
end
|
||||
|
||||
local buttonsWidth = 0
|
||||
for i = 1, #buttons do
|
||||
@@ -67,6 +76,8 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c
|
||||
local choice = 0xFF
|
||||
if focusedChoice then
|
||||
choice = focusedChoice.choiceId
|
||||
lastDialogChoice = choiceList:getChildIndex(focusedChoice)
|
||||
lastDialogAnswer = g_clock.millis()
|
||||
end
|
||||
g_game.answerModalDialog(id, buttonId, choice)
|
||||
destroyDialog()
|
||||
@@ -85,16 +96,20 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c
|
||||
|
||||
local horizontalPadding = modalDialog:getPaddingLeft() + modalDialog:getPaddingRight()
|
||||
buttonsWidth = buttonsWidth + horizontalPadding
|
||||
|
||||
modalDialog:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), modalDialog.minimumWidth)))
|
||||
messageLabel:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), modalDialog.minimumWidth)) - horizontalPadding)
|
||||
modalDialog:setHeight(modalDialog:getHeight() + additionalHeight + messageLabel:getHeight() - 8)
|
||||
|
||||
local labelWidth = math.min(600, math.floor(message:len() * 1.5))
|
||||
modalDialog:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, labelWidth, modalDialog.minimumWidth)))
|
||||
messageLabel:setTextWrap(true)
|
||||
|
||||
modalDialog:setHeight(90 + additionalHeight + messageLabel:getHeight())
|
||||
|
||||
local enterFunc = function()
|
||||
local focusedChoice = choiceList:getFocusedChild()
|
||||
local choice = 0xFF
|
||||
if focusedChoice then
|
||||
choice = focusedChoice.choiceId
|
||||
lastDialogChoice = choiceList:getChildIndex(focusedChoice)
|
||||
lastDialogAnswer = g_clock.millis()
|
||||
end
|
||||
g_game.answerModalDialog(id, enterButton, choice)
|
||||
destroyDialog()
|
||||
@@ -105,6 +120,8 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c
|
||||
local choice = 0xFF
|
||||
if focusedChoice then
|
||||
choice = focusedChoice.choiceId
|
||||
lastDialogChoice = choiceList:getChildIndex(focusedChoice)
|
||||
lastDialogAnswer = g_clock.millis()
|
||||
end
|
||||
g_game.answerModalDialog(id, escapeButton, choice)
|
||||
destroyDialog()
|
||||
@@ -114,4 +131,6 @@ function onModalDialog(id, title, message, buttons, enterButton, escapeButton, c
|
||||
|
||||
modalDialog.onEnter = enterFunc
|
||||
modalDialog.onEscape = escapeFunc
|
||||
|
||||
lastDialogChoices = #choices
|
||||
end
|
@@ -40,7 +40,7 @@ ModalButton < Button
|
||||
ModalDialog < MainWindow
|
||||
id: modalDialog
|
||||
size: 280 97
|
||||
&minimumWidth: 200
|
||||
&minimumWidth: 300
|
||||
&maximumWidth: 600
|
||||
&minimumChoices: 4
|
||||
&maximumChoices: 10
|
||||
@@ -49,6 +49,7 @@ ModalDialog < MainWindow
|
||||
id: messageLabel
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text-align: left
|
||||
text-auto-resize: true
|
||||
text-wrap: true
|
||||
@@ -59,6 +60,7 @@ ModalDialog < MainWindow
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.top
|
||||
margin-bottom: 5
|
||||
|
||||
Panel
|
||||
id: buttonsPanel
|
||||
|
Reference in New Issue
Block a user