-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinigameModeScreen.cs
152 lines (134 loc) · 5.1 KB
/
MinigameModeScreen.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using Celeste;
using Celeste.Mod.Entities;
using MadelineParty.Entities;
using MadelineParty.Multiplayer;
using MadelineParty.Multiplayer.General;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections;
namespace MadelineParty
{
[CustomEntity("madelineparty/minigameModeScreen")]
public class MinigameModeScreen : Entity {
public class ScreenTerminal : Entity {
private MinigameModeScreen parent;
public bool Interacting { get; private set; }
public ScreenTerminal(MinigameModeScreen parent, Vector2 position) : base(position) {
this.parent = parent;
Depth = -8500;
TalkComponent talk = new TalkComponent(new Rectangle(-24, -8, 48, 8), new Vector2(-0.5f, -20f), Interact);
talk.PlayerMustBeFacing = false;
Add(talk);
}
private void Interact(Player player) {
Coroutine routine = new Coroutine(InteractRoutine(player));
routine.RemoveOnComplete = true;
Add(routine);
}
private IEnumerator InteractRoutine(Player player) {
Level level = SceneAs<Level>();
SandwichLava sandwichLava = Scene.Entities.FindFirst<SandwichLava>();
if (sandwichLava != null) {
sandwichLava.Waiting = true;
}
if (player.Holding != null) {
player.Drop();
}
player.StateMachine.State = 11;
yield return player.DummyWalkToExact((int)X, walkBackwards: false, 1f, cancelOnFall: true);
if (Math.Abs(X - player.X) > 4f || player.Dead || !player.OnGround()) {
if (!player.Dead) {
player.StateMachine.State = 0;
}
yield break;
}
Audio.Play("event:/game/general/lookout_use", Position);
yield return 0.1f;
MultiplayerSingleton.Instance.Send(new MinigameMenu { selection = parent.menu.Selection });
parent.menu.Focused = true;
Interacting = true;
}
public void EndInteraction() {
if (Interacting) {
Scene.OnEndOfFrame += delegate {
parent.menu.Focused = false;
Interacting = false;
if (Scene.Tracker.GetEntity<Player>() is Player player) {
player.StateMachine.State = Player.StNormal;
}
Input.Dash.ConsumeBuffer();
};
}
}
}
private TextMenuPlus menu;
private int width, height;
private ScreenTerminal terminal;
private Level level;
public MinigameModeScreen(EntityData data, Vector2 offset) : base(data.Position * 6) {
width = data.Width;
height = data.Height;
terminal = new(this, data.NodesOffset(offset)[0]);
AddTag(TagsExt.SubHUD);
}
public override void Added(Scene scene) {
base.Added(scene);
level = SceneAs<Level>();
Scene.Add(terminal);
GameData.Instance.minigameStatus.Clear();
foreach(var kvp in GameData.Instance.minigameWins) {
GameData.Instance.minigameStatus[kvp.Key] = kvp.Value;
}
Scene.Add(new MinigameScoreDisplay(new MinigameFinishTrigger(new(), new())));
menu = new TextMenuPlus() {
DoCrop = true,
Crop = new Rectangle((int)Position.X, (int)Position.Y, width * 6, height * 6),
AlwaysHighlight = true
};
menu.Tag = TagsExt.SubHUD;
menu.AutoScroll = true;
menu.InnerContent = TextMenu.InnerContentMode.TwoColumn;
var header = new TextMenuPlus.BetterHeader(Dialog.Clean("MadelineParty_Minigame_List_Title")) {
Alignment = TextMenuPlus.TextAlignment.Left
};
menu.Add(header);
var minigameLevels = GameData.Instance.GetAllMinigames(level, new() {
PlayerCount = GameData.Instance.playerNumber
});
menu.Add(new TextMenu.Button(Dialog.Clean("MadelineParty_Minigame_List_Random")).Pressed(delegate {
if (terminal.Interacting) {
SelectLevel(minigameLevels[new Random().Next(minigameLevels.Count)].Name);
}
}));
minigameLevels.ForEach((lvl) => {
menu.Add(new TextMenu.Button(Dialog.Clean("MadelineParty_Minigame_Name_" + lvl.Name)).Pressed(delegate {
if (terminal.Interacting) {
SelectLevel(lvl.Name);
}
}));
});
menu.OnCancel = terminal.EndInteraction;
menu.Position = new Vector2(menu.Width / 2 + Position.X, Engine.Height / 2f);
menu.OnSelectionChanged += (oldSelect, newSelect) => {
if (terminal.Interacting) {
MultiplayerSingleton.Instance.Send(new MinigameMenu { selection = newSelect });
}
};
menu.Focused = false;
Add(new MultiplayerHandlerComponent<MinigameMenu>("minigameModeScreen", HandleMinigameMenu));
Scene.Add(menu);
}
private void SelectLevel(string levelName) {
MultiplayerSingleton.Instance.Send(new MinigameStart { choice = levelName, gameStart = DateTime.UtcNow.AddSeconds(3).ToFileTimeUtc() });
GameData.Instance.minigame = levelName;
ModeManager.Instance.AfterMinigameChosen(level);
}
private void HandleMinigameMenu(MPData data) {
if (data is not MinigameMenu mm) return;
if (GameData.Instance.celestenetIDs.Contains(mm.ID) && mm.ID != MultiplayerSingleton.Instance.CurrentPlayerID()) {
menu.Selection = mm.selection;
}
}
}
}