Hộp thoại trong Lua
Mọi thứ các khối hộp thoại làm được đều có sẵn trong Lua. Một script hộp thoại gồm ba phần: bắt đầu một hộp thoại mới, thêm các câu hỏi, hiển thị nó. Sau đó đọc các câu trả lời theo id.
Dialog:init()
Dialog:setTitle("Farm helper")
Dialog:add(TextView("Set it up once. You can change it later."))
Dialog:add(CheckBox(1, "Collect daily rewards", true))
Dialog:add(NumberInput(2, "Runs", 10):setRange(1, 999))
local mode = RadioGroup(3, 1)
mode:add(RadioButton(1, "Farm"))
mode:add(RadioButton(2, "Arena"))
Dialog:add(mode)
Dialog:add(TapPicker(4, "Tap the Attack button"):showWhen(3, 2))
Dialog:add(GestureRecorder(5, "Play your route once"))
local advanced = Section("Advanced", true)
advanced:add(Slider(6, "Delay (ms)", 0, 1000, 300):setStep(50):setHelp("Wait between actions"))
Dialog:add(advanced)
Dialog:showIfNeeded()
local runs = Dialog:getValueById(2)
local delay = Dialog:getValueById(6)
for i = 1, runs do
if Dialog:getValueById(3) == 2 then
Screen:click(Dialog:getValueById(4), ClickParams())
end
Record:play(Dialog:getValueById(5))
sleep(delay)
end
Đây là hộp thoại mà nó hiển thị:
Các phần
| Bước | Hàm |
|---|---|
| Bắt đầu một hộp thoại mới | Dialog:init(), Dialog:setTitle(), Dialog:setMessage() |
| Thêm câu hỏi | Dialog:add() với TextView, CheckBox, EditText, NumberInput, Slider, RadioGroup, TapPicker, TapListPicker, GestureRecorder |
| Sắp xếp chúng | Page, Section, Row, Column |
| Tinh chỉnh một câu hỏi | showWhen, hideWhen, setHelp, setRequired, setRange, setStep, showAsDropdown |
| Hiển thị nó | Dialog:show() hoặc Dialog:showIfNeeded() |
| Đọc các câu trả lời | Dialog:getValueById() |
Những điều nên biết
- Gọi
Dialog:init()trước tiên. Nó bắt đầu một hộp thoại mới, rỗng, nên một macro có thể hiển thị nhiều hộp thoại. - Các hàm setter trả về câu hỏi, nên có thể nối chuỗi:
Slider(6, "Delay", 0, 1000):setStep(50):showWhen(1). - Các vùng chứa được nạp trước rồi thêm sau:
page:add(...), sau đóDialog:add(page). - Id phải khác nhau cho mọi câu hỏi trong macro, vì câu trả lời được lưu theo id.
Dialog:show()dừng macro nếu người dùng nhấn Cancel.- Đọc câu trả lời sau
show()hoặcshowIfNeeded().