-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support changing color in-game
- Loading branch information
Showing
5 changed files
with
661 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections; | ||
using Celeste.Mod.UI; | ||
using Microsoft.Xna.Framework; | ||
using Monocle; | ||
|
||
namespace Celeste.Mod.Trailine.UI { | ||
public class OuiTextInput : Oui, OuiModOptions.ISubmenu { | ||
|
||
private const float OnScreenX = 0f; | ||
private const float OffScreenX = 1920f; | ||
|
||
private TextInputMenu menu; | ||
private float alpha; | ||
|
||
public TextInputMenu Init(TextInputMenu menu) { | ||
this.menu = menu; | ||
return menu; | ||
} | ||
|
||
public override IEnumerator Enter(Oui from) { | ||
Overworld.ShowInputUI = false; | ||
Scene.Add(menu); | ||
|
||
Visible = true; | ||
menu.Visible = true; | ||
menu.Focused = false; | ||
|
||
for (float p = 0f; p < 1f; p += Engine.DeltaTime * 4f) { | ||
menu.X = OffScreenX + -1920f * Ease.CubeOut(p); | ||
alpha = Ease.CubeOut(p); | ||
yield return null; | ||
} | ||
alpha = 1f; | ||
|
||
menu.Focused = true; | ||
} | ||
|
||
public override IEnumerator Leave(Oui next) { | ||
Audio.Play(SFX.ui_main_whoosh_large_out); | ||
menu.Focused = false; | ||
Overworld.ShowInputUI = true; | ||
|
||
for (float p = 0f; p < 1f; p += Engine.DeltaTime * 4f) { | ||
menu.X = OnScreenX + 1920f * Ease.CubeIn(p); | ||
alpha = 1f - Ease.CubeIn(p); | ||
yield return null; | ||
} | ||
|
||
menu.Visible = Visible = false; | ||
menu.RemoveSelf(); | ||
menu = null; | ||
} | ||
|
||
public override void Render() { | ||
if (alpha > 0f) { | ||
Draw.Rect(-10f, -10f, 1940f, 1100f, Color.Black * alpha * 0.4f); | ||
} | ||
base.Render(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using Celeste.Mod.Trailine.Utils; | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace Celeste.Mod.Trailine.UI { | ||
public class TextInputButton : TextMenu.Item { | ||
|
||
public bool AlwaysCenter; | ||
public string Label; | ||
public int MinValueLength; | ||
public int MaxValueLength; | ||
public string Value; | ||
public string LetterChars; | ||
|
||
public Action<string> OnValueChange; | ||
public Action<bool> OnMenuExit; | ||
|
||
public string ButtonLabel => $"{Label}: {Value}"; | ||
|
||
public TextInputButton(string label, string value, int minValueLength = 1, int maxValueLength = 12) { | ||
Label = label; | ||
Value = value; | ||
MinValueLength = Math.Max(minValueLength, 1); | ||
MaxValueLength = Math.Max(maxValueLength, 1); | ||
Selectable = true; | ||
LetterChars = string.Join("\n", | ||
"ABCDEFGHI abcdefghi", | ||
"JKLMNOPQR jklmnopqr", | ||
"STUVWXYZ stuvwxyz", | ||
"1234567890+=:~!@$%", | ||
"^&*_-#\"'()<>/\\.,|`" | ||
); | ||
} | ||
|
||
public TextInputButton Change(Action<string> action) { | ||
OnValueChange = action; | ||
return this; | ||
} | ||
|
||
public TextInputButton MenuExit(Action<bool> action) { | ||
OnMenuExit = action; | ||
return this; | ||
} | ||
|
||
public override void ConfirmPressed() { | ||
Audio.Play(SFX.ui_main_button_select); | ||
|
||
TextInputMenu textInputMenu = new TextInputMenu(Value, OnValueChange, MinValueLength, MaxValueLength) { | ||
LetterChars = LetterChars | ||
}; | ||
switch (Container.Scene) { | ||
case Overworld overworld: { | ||
textInputMenu.OnExit += confirm => { | ||
overworld.Goto(overworld.Last.GetType()); | ||
}; | ||
overworld.Goto<OuiTextInput>().Init(textInputMenu); | ||
break; | ||
} | ||
case Level level: { | ||
Container.RemoveSelf(); | ||
|
||
// notify the pause menu that we aren't in the main menu anymore (hides the strawberry tracker) | ||
bool comesFromPauseMainMenu = level.PauseMainMenuOpen; | ||
level.PauseMainMenuOpen = false; | ||
|
||
textInputMenu.OnExit += confirm => { | ||
textInputMenu.RemoveSelf(); | ||
level.Add(Container); | ||
level.PauseMainMenuOpen = comesFromPauseMainMenu; | ||
}; | ||
|
||
// add the menu to the scene | ||
level.Add(textInputMenu); | ||
break; | ||
} | ||
} | ||
textInputMenu.OnExit += OnMenuExit; | ||
} | ||
|
||
public override float LeftWidth() { | ||
return ActiveFont.Measure(ButtonLabel).X; | ||
} | ||
|
||
public override float Height() { | ||
return ActiveFont.LineHeight; | ||
} | ||
|
||
public override void Render(Vector2 position, bool highlighted) { | ||
float alpha = Container.Alpha; | ||
Color color = Disabled ? Color.DarkSlateGray : (highlighted ? Container.HighlightColor : Color.White) * alpha; | ||
Color strokeColor = Color.Black * (alpha * alpha * alpha); | ||
bool center = Container.InnerContent == TextMenu.InnerContentMode.TwoColumn && !AlwaysCenter; | ||
Vector2 position2 = position + (center ? Vector2.Zero : new Vector2(Container.Width * 0.5f, 0f)); | ||
Vector2 justify = center && !AlwaysCenter ? new Vector2(0f, 0.5f) : new Vector2(0.5f, 0.5f); | ||
ActiveFont.DrawOutline(ButtonLabel, position2, justify, Vector2.One, color, 2f, strokeColor); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.