|
| 1 | +using Celeste.Mod.Entities; |
| 2 | +using Microsoft.Xna.Framework; |
| 3 | +using Monocle; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Reflection; |
| 6 | + |
| 7 | +namespace Celeste.Mod.SpringCollab2020.Entities { |
| 8 | + [CustomEntity("SpringCollab2020/CustomBirdTutorial")] |
| 9 | + [Tracked] |
| 10 | + class CustomBirdTutorial : BirdNPC { |
| 11 | + public string BirdId; |
| 12 | + private bool onlyOnce; |
| 13 | + private bool caw; |
| 14 | + |
| 15 | + private bool triggered = false; |
| 16 | + private bool flewAway = false; |
| 17 | + |
| 18 | + private BirdTutorialGui gui; |
| 19 | + |
| 20 | + private static Dictionary<string, Vector2> directions = new Dictionary<string, Vector2>() { |
| 21 | + { "Left", new Vector2(-1, 0) }, |
| 22 | + { "Right", new Vector2(1, 0) }, |
| 23 | + { "Up", new Vector2(0, -1) }, |
| 24 | + { "Down", new Vector2(0, 1) }, |
| 25 | + { "UpLeft", new Vector2(-1, -1) }, |
| 26 | + { "UpRight", new Vector2(1, -1) }, |
| 27 | + { "DownLeft", new Vector2(-1, 1) }, |
| 28 | + { "DownRight", new Vector2(1, 1) } |
| 29 | + }; |
| 30 | + |
| 31 | + public CustomBirdTutorial(EntityData data, Vector2 offset) : base(data, offset) { |
| 32 | + BirdId = data.Attr("birdId"); |
| 33 | + onlyOnce = data.Bool("onlyOnce"); |
| 34 | + caw = data.Bool("caw"); |
| 35 | + Facing = data.Bool("faceLeft") ? Facings.Left : Facings.Right; |
| 36 | + |
| 37 | + object info; |
| 38 | + object[] controls; |
| 39 | + |
| 40 | + // parse the info ("title") |
| 41 | + string infoString = data.Attr("info"); |
| 42 | + if (GFX.Gui.Has(infoString)) { |
| 43 | + info = GFX.Gui[infoString]; |
| 44 | + } else { |
| 45 | + info = Dialog.Clean(infoString); |
| 46 | + } |
| 47 | + |
| 48 | + // go ahead and parse the controls. Controls can be textures, VirtualButtons, directions or strings. |
| 49 | + string[] controlsStrings = data.Attr("controls").Split(','); |
| 50 | + controls = new object[controlsStrings.Length]; |
| 51 | + for (int i = 0; i < controls.Length; i++) { |
| 52 | + string controlString = controlsStrings[i]; |
| 53 | + |
| 54 | + if (GFX.Gui.Has(controlString)) { |
| 55 | + // this is a texture. |
| 56 | + controls[i] = GFX.Gui[controlString]; |
| 57 | + } else if (directions.ContainsKey(controlString)) { |
| 58 | + // this is a direction. |
| 59 | + controls[i] = directions[controlString]; |
| 60 | + } else { |
| 61 | + FieldInfo matchingInput = typeof(Input).GetField(controlString, BindingFlags.Static | BindingFlags.Public); |
| 62 | + if (matchingInput?.GetValue(null)?.GetType() == typeof(VirtualButton)) { |
| 63 | + // this is a button. |
| 64 | + controls[i] = matchingInput.GetValue(null); |
| 65 | + } else if (controlString.StartsWith("dialog:")) { |
| 66 | + // treat that as a dialog key. |
| 67 | + controls[i] = Dialog.Clean(controlString.Substring("dialog:".Length)); |
| 68 | + } else { |
| 69 | + // treat that as a plain string. |
| 70 | + controls[i] = controlString; |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + gui = new BirdTutorialGui(this, new Vector2(0f, -16f), info, controls); |
| 76 | + } |
| 77 | + |
| 78 | + public void TriggerShowTutorial() { |
| 79 | + if (!triggered) { |
| 80 | + triggered = true; |
| 81 | + Add(new Coroutine(ShowTutorial(gui, caw))); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public void TriggerHideTutorial() { |
| 86 | + if (triggered && !flewAway) { |
| 87 | + flewAway = true; |
| 88 | + |
| 89 | + Add(new Coroutine(HideTutorial())); |
| 90 | + Add(new Coroutine(StartleAndFlyAway())); |
| 91 | + |
| 92 | + if (onlyOnce) { |
| 93 | + SceneAs<Level>().Session.DoNotLoad.Add(EntityID); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments