Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Highlight selection, use menu select button to get route
Browse files Browse the repository at this point in the history
  • Loading branch information
syyePhenomenol committed Jan 21, 2022
1 parent 53a7781 commit 063d043
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 7 deletions.
1 change: 1 addition & 0 deletions MapModS/Map/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private static string GetActualSceneName(string objName)
public class ExtraMapData : MonoBehaviour
{
public Color origColor;
public Color origTransitionColor;
public string sceneName;
}

Expand Down
2 changes: 1 addition & 1 deletion MapModS/UI/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static void GameMap_Start(On.GameMap.orig_Start orig, GameMap self)
private static void GameMap_WorldMap (On.GameMap.orig_WorldMap orig, GameMap self)
{
orig(self);
TransitionText.ShowInstructions();
TransitionText.ShowWorldMap(self);
}

private static void SetupMapMarkers(On.GameMap.orig_SetupMapMarkers orig, GameMap self)
Expand Down
8 changes: 4 additions & 4 deletions MapModS/UI/InputListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ protected void Update()
PauseMenu.SizeClicked("Size");
}

if (Input.GetKeyDown(KeyCode.T) && MapModS.LS.mapMode == Settings.MapMode.TransitionRando)
{
TransitionText.GetRoute();
}
//if (Input.GetKeyDown(KeyCode.T) && MapModS.LS.mapMode == Settings.MapMode.TransitionRando)
//{
// TransitionText.GetRoute();
//}
}
}
}
Expand Down
87 changes: 85 additions & 2 deletions MapModS/UI/TransitionText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,43 @@ public static void Show()
SetTexts();
}

public static void ShowInstructions()
public static void ShowWorldMap(GameMap gameMap)
{
bool isActive = !LockToggleEnable && MapModS.LS.ModEnabled
&& RandomizerMod.RandomizerMod.RS.GenerationSettings.TransitionSettings.Mode != RandomizerMod.Settings.TransitionSettings.TransitionMode.None
&& MapModS.LS.mapMode == MapMode.TransitionRando;

_instructionPanel.SetActive(isActive, isActive);

// The following stores the colors of the rooms prior to selection
if (gameMap == null) return;

foreach (Transform areaObj in gameMap.transform)
{
foreach (Transform roomObj in areaObj.transform)
{
Transition.ExtraMapData extra = roomObj.GetComponent<Transition.ExtraMapData>();

if (extra == null) continue;

SpriteRenderer sr = roomObj.GetComponent<SpriteRenderer>();

// For AdditionalMaps room objects, the child has the SR
if (extra.sceneName.Contains("White_Palace"))
{
foreach (Transform roomObj2 in roomObj.transform)
{
if (!roomObj2.name.Contains("RWP")) continue;
sr = roomObj2.GetComponent<SpriteRenderer>();
break;
}
}

if (sr == null) continue;

extra.origTransitionColor = sr.color;
}
}
}

public static void Hide()
Expand Down Expand Up @@ -116,13 +146,20 @@ public static void Update()
return;
}

// Use menu selection button for control
if (InputHandler.Instance != null && InputHandler.Instance.inputActions.menuSubmit.WasPressed)
{
GetRoute();
}

frameCounter = (frameCounter + 1) % 24;

if (frameCounter == 0)
{
if (GetRoomClosestToMiddle(selectedScene, out selectedScene))
{
SetInstructionsText();
SetRoomColors();
}
}
}
Expand All @@ -132,6 +169,9 @@ private static double DistanceToMiddle(Transform transform)
return Math.Pow(transform.position.x, 2) + Math.Pow(transform.position.y, 2);
}

private static readonly Vector4 selectionColor = new(255, 255, 0, 0.5f);

// This method also handles highlighting the selected room
public static bool GetRoomClosestToMiddle(string previousScene, out string selectedScene)
{
selectedScene = null;
Expand Down Expand Up @@ -165,6 +205,49 @@ public static bool GetRoomClosestToMiddle(string previousScene, out string selec
return selectedScene != previousScene;
}

private static void SetRoomColors()
{
GameObject go_GameMap = GameManager.instance.gameMap;

if (go_GameMap == null) return;

foreach (Transform areaObj in go_GameMap.transform)
{
foreach (Transform roomObj in areaObj.transform)
{
if (!roomObj.gameObject.activeSelf) continue;

Transition.ExtraMapData extra = roomObj.GetComponent<Transition.ExtraMapData>();

if (extra == null) continue;

SpriteRenderer sr = roomObj.GetComponent<SpriteRenderer>();

// For AdditionalMaps room objects, the child has the SR
if (extra.sceneName.Contains("White_Palace"))
{
foreach (Transform roomObj2 in roomObj.transform)
{
if (!roomObj2.name.Contains("RWP")) continue;
sr = roomObj2.GetComponent<SpriteRenderer>();
break;
}
}

if (sr == null) continue;

if (extra.sceneName == selectedScene)
{
sr.color = selectionColor;
}
else
{
sr.color = extra.origTransitionColor;
}
}
}
}

public static void SetInstructionsText()
{
string instructionsText = $"Selected room: {selectedScene}.";
Expand All @@ -175,7 +258,7 @@ public static void SetInstructionsText()
}
else
{
instructionsText += " Press CTRL-T to find new route / switch starting transition for current route.";
instructionsText += $" Press [Menu Select] to find new route / switch starting transition for current route.";
}

_instructionPanel.GetText("Instructions").UpdateText(instructionsText);
Expand Down

0 comments on commit 063d043

Please sign in to comment.