Client LuaCsForBarotrauma
GUIRadioButtonGroup.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using Microsoft.Xna.Framework;
7 
8 namespace Barotrauma
9 {
11  {
12  private Dictionary<int, GUITickBox> radioButtons; //TODO: use children list instead?
13 
14  public GUIRadioButtonGroup() : base(null)
15  {
16  radioButtons = new Dictionary<int, GUITickBox>();
17  selected = null;
18  }
19 
20  public override bool Enabled
21  {
22  get => base.Enabled;
23  set
24  {
25  base.Enabled = value;
26  foreach(KeyValuePair<int, GUITickBox> rbPair in radioButtons)
27  {
28  rbPair.Value.Enabled = value;
29  }
30  }
31  }
32 
33  public void AddRadioButton(int key, GUITickBox radioButton)
34  {
35  if (selected == key) radioButton.Selected = true;
36  else if (radioButton.Selected) selected = key;
37 
38  radioButton.SetRadioButtonGroup(this);
39  radioButtons.Add((int)key, radioButton);
40  }
41 
42  public delegate void RadioButtonGroupDelegate(GUIRadioButtonGroup rbg, int? val);
44 
45  public void SelectRadioButton(GUITickBox radioButton)
46  {
47  foreach (KeyValuePair<int, GUITickBox> rbPair in radioButtons)
48  {
49  if (radioButton == rbPair.Value)
50  {
51  Selected = rbPair.Key;
52  return;
53  }
54  }
55  }
56 
57  // intentional hiding?
58  private new int? selected;
59  public new int? Selected
60  {
61  get
62  {
63  return selected;
64  }
65  set
66  {
67  OnSelect?.Invoke(this, value);
68  if (selected != null && selected.Equals(value)) { return; }
69  selected = value;
70  foreach (KeyValuePair<int, GUITickBox> radioButton in radioButtons)
71  {
72  if (radioButton.Key.Equals(value))
73  {
74  radioButton.Value.Selected = true;
75  }
76  else if (radioButton.Value.Selected)
77  {
78  radioButton.Value.Selected = false;
79  }
80  }
81  }
82  }
83 
85  {
86  get
87  {
88  return selected.HasValue ? radioButtons[selected.Value] : null;
89  }
90  }
91  }
92 }
RadioButtonGroupDelegate OnSelect
delegate void RadioButtonGroupDelegate(GUIRadioButtonGroup rbg, int? val)
void SelectRadioButton(GUITickBox radioButton)
void AddRadioButton(int key, GUITickBox radioButton)
override bool Selected
Definition: GUITickBox.cs:18
void SetRadioButtonGroup(GUIRadioButtonGroup rbg)
Definition: GUITickBox.cs:159