-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathMultipleChoiceForm.cs
88 lines (62 loc) · 2.18 KB
/
MultipleChoiceForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using InlineAndReplyCombination.Forms;
using InlineAndReplyCombination.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TelegramBotBase.Attributes;
using TelegramBotBase.Controls.Hybrid;
using TelegramBotBase.Form;
namespace InlineAndReplyCombination.Baseclasses
{
public class MultipleChoiceForm : AutoCleanForm
{
[SaveState]
public UserDetails? UserDetails { get; set; }
ButtonGrid? ReplyButtonGrid;
public String ReplyButtonTitle { get; set; } = "Restart";
protected int CurrentStep = 1;
protected int MaxSteps = 3;
public MultipleChoiceForm()
{
this.Init += MultipleChoiceForm_Init;
}
private Task MultipleChoiceForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
{
//Reply keyboard
var bf = new ButtonForm();
bf.AddButtonRow(ReplyButtonTitle, "replyButtonID");
ReplyButtonGrid = new ButtonGrid(bf);
ReplyButtonGrid.Title = $"Step {CurrentStep} / {MaxSteps}";
ReplyButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.ReplyKeyboard;
ReplyButtonGrid.ButtonClicked += ReplyButtonGrid_ButtonClicked;
AddControl(ReplyButtonGrid);
return Task.CompletedTask;
}
private async Task ReplyButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
{
if (e.Button == null)
return;
switch (e.Button.Value)
{
case "replyButtonID":
await PressReplyButton();
break;
}
}
public virtual Task PressReplyButton()
{
return Task.CompletedTask;
}
public override Task NavigateTo(FormBase newForm, params object[] args)
{
//Move user details over to navigating form
if (newForm is MultipleChoiceForm mcf)
{
mcf.UserDetails = UserDetails;
}
return base.NavigateTo(newForm, args);
}
}
}