Updaded modaldialog and bot (added anti push)

This commit is contained in:
OTCv8
2019-11-08 05:31:38 +01:00
parent 7d9a81d871
commit d78af570ea
8 changed files with 109 additions and 16 deletions

View File

@@ -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

View File

@@ -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