-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubeNets.cs
178 lines (147 loc) · 4.39 KB
/
CubeNets.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RevengeCube;
using Ballcuber.Modele;
namespace Ballcuber
{
public partial class CubeNets : UserControl
{
private List<CubePartControl> _parts = new List<CubePartControl>();
private IEnumerable<Button> _ctrlButtons;
private IEnumerable<Label> _ctrlLabels;
public CubeNets()
{
InitializeComponent();
_ctrlButtons = tableCube.Controls.OfType<Button>().ToList();
_ctrlLabels = tableCube.Controls.OfType<Label>().ToList();
CreateFacePart(4, 0);
CreateFacePart(0, 4);
CreateFacePart(4, 4);
CreateFacePart(8, 4);
CreateFacePart(12, 4);
CreateFacePart(4, 8);
Clickable = true;
}
public delegate void MoveClickEventHandler(object o, MoveClickEventArgs e);
public event MoveClickEventHandler MoveClick;
private void moveClick(object sender, EventArgs e)
{
var txt = (sender as Button)?.Tag as string;
if (txt?.Length != 3) return; // le tag du bouton doit être de la forme X2+ (X:axe, 2:nieme courronne, +:sens)
Axe axe;
if (!Enum.TryParse<Axe>(txt[0].ToString(), out axe)) return;
var mv = new MotorMove(axe);
int sens;
switch (txt[2])
{
case '+':
sens = 1;
break;
case '-':
sens = -1;
break;
default:
return;
}
Couronne couronne;
switch (txt[1])
{
case '1':
mv.MaxMovesCount = sens;
couronne = Couronne.Max;
break;
case '2':
mv.MidMaxMovesCount = sens;
couronne = Couronne.MidMax;
break;
case '3':
mv.MidMinMovesCount = sens;
couronne = Couronne.MidMin;
break;
default:
return;
}
MoveClick(sender, new MoveClickEventArgs(mv, axe, (Sens)sens, couronne));
}
private bool _Clickable;
[DefaultValue(true)]
public bool Clickable
{
get
{
return _Clickable;
}
set
{
foreach (var part in _parts)
{
part.Clickable = value;
}
_Clickable = value;
}
}
private bool _showControlButtons = true;
[DefaultValue(true)]
public bool ShowControlButtons
{
get
{
return _showControlButtons;
}
set
{
foreach (var btn in _ctrlButtons)
{
btn.Visible = value;
}
foreach (var lbl in _ctrlLabels)
{
lbl.Visible = value;
}
_showControlButtons = value;
}
}
private void CreateFacePart(int column, int row)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
var part = new CubePartControl(_parts.Count);
tableCube.Controls.Add(part, column+j, row+i);
part.Dock = DockStyle.Fill;
part.Margin = new Padding(0);
_parts.Add(part);
}
}
}
public void PeriodicUpdate(ColorCube cube)
{
foreach (var part in _parts)
{
part.PeriodicUpdate(cube);
}
}
}
public class MoveClickEventArgs : EventArgs
{
public MotorMove MotorMove { get; }
public Sens Sens { get; }
public Couronne Couronne { get; }
public Axe Axe { get; }
public MoveClickEventArgs(MotorMove mv, Axe a, Sens s, Couronne c)
{
MotorMove = mv;
Axe = a;
Sens = s;
Couronne = c;
}
}
}