Client LuaCsForBarotrauma
CreditsPlayer.cs
1 using Microsoft.Xna.Framework;
2 
3 namespace Barotrauma
4 {
6  {
7  private GUIListBox listBox;
8 
9  private readonly ContentXElement configElement;
10 
11  private float scrollSpeed;
12 
13  public bool AutoRestart = true;
14 
15  public bool Finished
16  {
17  get { return listBox.BarScroll >= 1.0f; }
18  }
19 
20  public bool ScrollBarEnabled
21  {
22  get { return listBox.ScrollBarEnabled; }
23  set { listBox.ScrollBarEnabled = value; }
24  }
25 
27  {
28  get { return listBox.AllowMouseWheelScroll; }
29  set { listBox.AllowMouseWheelScroll = value; }
30  }
31 
32  public float Scroll
33  {
34  get { return listBox.BarScroll; }
35  set { listBox.BarScroll = value; }
36  }
37 
38  public readonly GUIButton CloseButton;
39 
40 
41  public CreditsPlayer(RectTransform rectT, string configFile) : base(null, rectT)
42  {
44  {
45  ClearChildren();
46  Load();
47  };
48 
49  var doc = XMLExtensions.TryLoadXml(configFile);
50  if (doc == null) { return; }
51  configElement = doc.Root.FromPackage(ContentPackageManager.VanillaCorePackage);
52 
53  Load();
54 
55  CloseButton = new GUIButton(new RectTransform(new Vector2(0.1f), RectTransform, Anchor.BottomRight, maxSize: new Point(GUI.IntScale(300), GUI.IntScale(50)))
56  { AbsoluteOffset = new Point(GUI.IntScale(20), GUI.IntScale(20) + (Rect.Bottom - GameMain.GraphicsHeight)) },
57  TextManager.Get("close"));
58  }
59 
60  private void Load()
61  {
62  scrollSpeed = configElement.GetAttributeFloat("scrollspeed", 100.0f);
63  int spacing = configElement.GetAttributeInt("spacing", 0);
64 
65  listBox = new GUIListBox(new RectTransform(Vector2.One, RectTransform), style: null)
66  {
67  Spacing = spacing
68  };
69 
70  foreach (var subElement in configElement.Elements())
71  {
72  FromXML(subElement, listBox.Content.RectTransform);
73  }
74  foreach (GUIComponent child in listBox.Content.Children)
75  {
76  child.CanBeFocused = false;
77  }
78 
79  listBox.RecalculateChildren();
80  listBox.UpdateScrollBarSize();
81  }
82 
83  public void Restart()
84  {
85  listBox.BarScroll = 0.0f;
86  }
87 
88  protected override void Update(float deltaTime)
89  {
90  if (!Visible) { return; }
91 
92  listBox.BarScroll += scrollSpeed / listBox.TotalSize * deltaTime;
93 
94  if (AutoRestart && listBox.BarScroll >= 1.0f)
95  {
96  listBox.BarScroll = 0.0f;
97  }
98  }
99  }
100 }
CreditsPlayer(RectTransform rectT, string configFile)
override void Update(float deltaTime)
readonly GUIButton CloseButton
static GUIComponent FromXML(ContentXElement element, RectTransform parent)
GUIComponent(string style, RectTransform rectT)
This is the new constructor.
virtual void ClearChildren()
RectTransform RectTransform
IEnumerable< GUIComponent > Children
Definition: GUIComponent.cs:29
bool ScrollBarEnabled
Disables the scroll bar without hiding it.
Definition: GUIListBox.cs:222
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.
Definition: GUIListBox.cs:42
Action ResolutionChanged
NOTE: Use very carefully. You need to ensure that you ALWAYS unsubscribe from this when you no longer...
Definition: GameMain.cs:133
static GameMain Instance
Definition: GameMain.cs:144