Client LuaCsForBarotrauma
TestScreen.cs
1 #nullable enable
2 using System.Linq;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
6 
7 /*
8  * This screen only exists because I'm going mental without access to EnC on Linux.
9  * This is fucking stupid and horrible.
10  * Remember to remove this crap eventually.
11  * - Markus
12  */
13 namespace Barotrauma
14 {
15  internal sealed class TestScreen : EditorScreen
16  {
17  public override Camera Cam { get; }
18 
19  private Item? miniMapItem;
20 
21  public static Character? dummyCharacter;
22  public static Effect? BlueprintEffect;
23  public TabMenu? TabMenu;
24 
25  public TestScreen()
26  {
27  Cam = new Camera();
28  BlueprintEffect = GameMain.GameScreen.BlueprintEffect;
29 
30  new GUIButton(new RectTransform(new Point(256, 256), Frame.RectTransform), "Reload shader")
31  {
32  OnClicked = (button, o) =>
33  {
34  BlueprintEffect.Dispose();
35  GameMain.Instance.Content.Unload();
36  BlueprintEffect = EffectLoader.Load("Effects/blueprintshader");
37  GameMain.GameScreen.BlueprintEffect = BlueprintEffect;
38  return true;
39  }
40  };
41  }
42 
43  public override void Select()
44  {
45  base.Select();
46  if (dummyCharacter is { Removed: false })
47  {
48  dummyCharacter.Remove();
49  }
50 
51  dummyCharacter = Character.Create(CharacterPrefab.HumanSpeciesName, Vector2.Zero, "", id: Entity.DummyID, hasAi: false);
52  dummyCharacter.Info.Job = new Job(JobPrefab.Prefabs.FirstOrDefault(static jp => jp.Identifier == "captain"), isPvP: false);
53  dummyCharacter.Info.Name = "Galldren";
54  dummyCharacter.Inventory.CreateSlots();
55  dummyCharacter.Info.GiveExperience(999999);
56 
57  miniMapItem = new Item(ItemPrefab.Find(null, "circuitbox".ToIdentifier()), Vector2.Zero, null, 1337, false);
58  miniMapItem.GetComponent<Holdable>().AttachToWall();
59 
60  Character.Controlled = dummyCharacter;
61  GameMain.World.ProcessChanges();
62 
63  dummyCharacter.Info.TalentRefundPoints = 2;
64  TabMenu = new TabMenu();
65  }
66 
67  public override void AddToGUIUpdateList()
68  {
70  CharacterHUD.AddToGUIUpdateList(dummyCharacter);
71  dummyCharacter?.SelectedItem?.AddToGUIUpdateList();
72  TabMenu?.AddToGUIUpdateList();
73  }
74 
75  public override void Update(double deltaTime)
76  {
77  base.Update(deltaTime);
78  TabMenu?.Update((float)deltaTime);
79 
80  if (dummyCharacter is { } dummy && miniMapItem is { } item)
81  {
82  if (dummy.SelectedItem != item)
83  {
84  dummy.SelectedItem = item;
85  }
86 
87  dummy.SelectedItem?.UpdateHUD(Cam, dummy, (float)deltaTime);
88  item.SendSignal("1", "signal_in1");
89  Vector2 pos = FarseerPhysics.ConvertUnits.ToSimUnits(item.Position);
90 
91  foreach (Limb limb in dummy.AnimController.Limbs)
92  {
93  limb.body.SetTransform(pos, 0.0f);
94  }
95 
96  if (dummy.AnimController?.Collider is { } collider)
97  {
98  collider.SetTransform(pos, 0);
99  }
100 
101  dummy.ControlLocalPlayer((float)deltaTime, Cam, false);
102  dummy.Control((float)deltaTime, Cam);
103  }
104  }
105 
106  public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
107  {
108  base.Draw(deltaTime, graphics, spriteBatch);
109  graphics.Clear(BackgroundColor);
110 
111  spriteBatch.Begin(SpriteSortMode.BackToFront, transformMatrix: Cam.Transform);
112  miniMapItem?.Draw(spriteBatch, false);
113  if (dummyCharacter is { } dummy)
114  {
115  dummyCharacter.DrawFront(spriteBatch, Cam);
116  dummyCharacter.Draw(spriteBatch, Cam);
117  }
118 
119  spriteBatch.End();
120 
121  spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState);
122 
123  GUI.Draw(Cam, spriteBatch);
124 
125  dummyCharacter?.DrawHUD(spriteBatch, Cam, false);
126 
127  spriteBatch.End();
128  }
129  }
130 }
virtual void AddToGUIUpdateList(bool ignoreChildren=false, int order=0)
RectTransform RectTransform
@ Character
Characters only