-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPermissionLimitBox.cs
66 lines (52 loc) · 1.98 KB
/
PermissionLimitBox.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
// Copyright 2009-2013 Matvei Stefarov <[email protected]>
using System;
using System.Windows.Forms;
namespace fCraft.ConfigGUI {
public sealed partial class PermissionLimitBox : UserControl {
public Permission Permission { get; private set; }
public string FirstItem { get; private set; }
public Rank Rank { get; private set; }
public PermissionLimitBox( string labelText, Permission permission, string firstItem ) {
InitializeComponent();
label.Text = labelText;
label.Left = ( comboBox.Left - comboBox.Margin.Left ) - ( label.Width + label.Margin.Right );
Permission = permission;
FirstItem = firstItem;
RebuildList();
comboBox.SelectedIndexChanged += OnPermissionLimitChanged;
}
private void OnPermissionLimitChanged( object sender, EventArgs args ) {
if ( Rank == null )
return;
Rank rankLimit = RankManager.FindRank( comboBox.SelectedIndex - 1 );
if ( rankLimit == null ) {
Rank.ResetLimit( Permission );
} else {
Rank.SetLimit( Permission, rankLimit );
}
}
public void Reset() {
comboBox.SelectedIndex = 0;
}
public void RebuildList() {
comboBox.Items.Clear();
comboBox.Items.Add( FirstItem );
foreach ( Rank rank in RankManager.Ranks ) {
comboBox.Items.Add( MainForm.ToComboBoxOption( rank ) );
}
}
public void SelectRank( Rank rank ) {
Rank = rank;
if ( rank == null ) {
comboBox.SelectedIndex = -1;
Visible = false;
} else {
comboBox.SelectedIndex = rank.GetLimitIndex( Permission );
Visible = rank.Can( Permission );
}
}
public void PermissionToggled( bool isOn ) {
Visible = isOn;
}
}
}