Skip to content

Commit

Permalink
Merge pull request #44 from RuinedYourLife/master
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonixRIT authored Jun 22, 2022
2 parents 90c73a3 + 63f7429 commit fd3d154
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Menus/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ public override void Draw()
private static void UnloadMenu() => Loader.Unload();
private static void DoNothing() => Utility.StubbedFunction();
}
}
}
157 changes: 110 additions & 47 deletions Menus/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
using RoR2;
using System.Collections.Generic;
using System.Linq;
using UmbraMenu.monsoon;

namespace UmbraMenu.Menus
{
public class Render : Menu
{
private static readonly IMenu render = new NormalMenu(6, new Rect(10, 795, 20, 20), "RENDER MENU");

private static Camera camera;

public static List<PurchaseInteraction> purchaseInteractions = new List<PurchaseInteraction>();
public static List<BarrelInteraction> barrelInteractions = new List<BarrelInteraction>();
public static List<PressurePlateController> secretButtons = new List<PressurePlateController>();
Expand Down Expand Up @@ -116,22 +119,19 @@ public static void DumpInteractables(SceneDirector obj)
scrappers = MonoBehaviour.FindObjectsOfType<ScrapperController>().ToList();
}

public static void Interactables()
{
public static void DrawTeleporter() {
camera = Camera.main;

if (TeleporterInteraction.instance)
{
var teleporterInteraction = TeleporterInteraction.instance;
float distanceToObject = Vector3.Distance(Camera.main.transform.position, teleporterInteraction.transform.position);
Vector3 Position = Camera.main.WorldToScreenPoint(teleporterInteraction.transform.position);
float distanceToObject = Vector3.Distance(camera.transform.position, teleporterInteraction.transform.position);
Vector3 Position = camera.WorldToScreenPoint(teleporterInteraction.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);
if (BoundingVector.z > 0.01)
{
Styles.RenderTeleporterStyle.normal.textColor =
teleporterInteraction.isIdle ? Color.magenta :
teleporterInteraction.isIdleToCharging || teleporterInteraction.isCharging ? Color.yellow :
teleporterInteraction.isCharged ? Color.green : Color.yellow;
int distance = (int)distanceToObject;
String friendlyName = "Teleporter";
string friendlyName = "Teleporter";
string status = "" + (
teleporterInteraction.isIdle ? "Idle" :
teleporterInteraction.isCharging ? "Charging" :
Expand All @@ -141,88 +141,151 @@ public static void Interactables()
teleporterInteraction.isInFinalSequence ? "Final-Sequence" :
"???");
string boxText = $"{friendlyName}\n{status}\n{distance}m";
GUI.Label(new Rect(BoundingVector.x - 50f, (float)Screen.height - BoundingVector.y, 100f, 50f), boxText, Styles.RenderTeleporterStyle);
monsoon.Renderer.DrawString(new Vector2(BoundingVector.x, (float)Screen.height - BoundingVector.y),
boxText, Styles.TeleporterStyle);
}
}
}

public static void DrawInteractables()
{
for (int i = 0; i < purchaseInteractions.Count; i++)
{
PurchaseInteraction purchaseInteraction = purchaseInteractions[i];

if (purchaseInteraction.available)
{
string dropName = null;
var chest = purchaseInteraction?.gameObject.GetComponent<ChestBehavior>();
if (chest)
{
dropName = Util.GenerateColoredString(Language.GetString(chest.dropPickup.GetPickupNameToken()), chest.dropPickup.GetPickupColor());
}

float distanceToObject = Vector3.Distance(camera.transform.position, purchaseInteraction.transform.position);
Vector3 Position = camera.WorldToScreenPoint(purchaseInteraction.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);

if (BoundingVector.z > 0.01)
{
int distance = (int)distanceToObject;
string friendlyName = purchaseInteraction.GetDisplayName();
int cost = purchaseInteraction.cost;

string boxText;
if (friendlyName.Contains("Mountain") || friendlyName.Contains("Combat") || friendlyName.Contains("Printer"))
{
boxText = $"{friendlyName}\n{distance}m";
}
else
{
boxText = dropName != null
? $"{friendlyName}\n{BuyingUnit(friendlyName, cost)}\n{distance}m\n{dropName}"
: $"{friendlyName}\n{BuyingUnit(friendlyName, cost)}\n{distance}m";
}
monsoon.Renderer.DrawString(new Vector2(BoundingVector.x, (float)Screen.height - BoundingVector.y),
boxText, ChooseStyle(friendlyName));
}
}

}
}

public static void DrawBarrels()
{
for (int i = 0; i < barrelInteractions.Count; i++)
{
BarrelInteraction barrel = barrelInteractions[i];

if (!barrel.Networkopened)
{
string friendlyName = "Barrel";
Vector3 Position = Camera.main.WorldToScreenPoint(barrel.transform.position);
Vector3 Position = camera.WorldToScreenPoint(barrel.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);
if (BoundingVector.z > 0.01)
{
float distance = (int)Vector3.Distance(Camera.main.transform.position, barrel.transform.position);
float distance = (int)Vector3.Distance(camera.transform.position, barrel.transform.position);
string boxText = $"{friendlyName}\n{distance}m";
GUI.Label(new Rect(BoundingVector.x - 50f, (float)Screen.height - BoundingVector.y, 100f, 50f), boxText, Styles.RenderInteractablesStyle);
monsoon.Renderer.DrawString(new Vector2(BoundingVector.x, Screen.height - BoundingVector.y),
boxText, ChooseStyle(friendlyName));
}
}
}
}

public static void DrawPressurePlates()
{
for (int i = 0; i < secretButtons.Count; i++)
{
PressurePlateController secretButton = secretButtons[i];
if (secretButton)
{
string friendlyName = "Secret Button";
Vector3 Position = Camera.main.WorldToScreenPoint(secretButton.transform.position);
Vector3 Position = camera.WorldToScreenPoint(secretButton.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);
if (BoundingVector.z > 0.01)
{
float distance = (int)Vector3.Distance(Camera.main.transform.position, secretButton.transform.position);
float distance = (int)Vector3.Distance(camera.transform.position, secretButton.transform.position);
string boxText = $"{friendlyName}\n{distance}m";
GUI.Label(new Rect(BoundingVector.x - 50f, (float)Screen.height - BoundingVector.y, 100f, 50f), boxText, Styles.RenderSecretsStyle);
monsoon.Renderer.DrawString(new Vector2(BoundingVector.x, (float)Screen.height - BoundingVector.y),
boxText, ChooseStyle(friendlyName));
}
}
}
}

public static void DrawScrappers()
{
for (int i = 0; i < scrappers.Count; i++)
{
ScrapperController scrapper = scrappers[i];
if (scrapper)
{
string friendlyName = "Scrapper";
Vector3 Position = Camera.main.WorldToScreenPoint(scrapper.transform.position);
Vector3 Position = camera.WorldToScreenPoint(scrapper.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);
if (BoundingVector.z > 0.01)
{
float distance = (int)Vector3.Distance(Camera.main.transform.position, scrapper.transform.position);
float distance = (int)Vector3.Distance(camera.transform.position, scrapper.transform.position);
string boxText = $"{friendlyName}\n{distance}m";
GUI.Label(new Rect(BoundingVector.x - 50f, (float)Screen.height - BoundingVector.y, 100f, 50f), boxText, Styles.RenderInteractablesStyle);
monsoon.Renderer.DrawString(new Vector2(BoundingVector.x, (float)Screen.height - BoundingVector.y),
boxText, ChooseStyle(friendlyName));
}
}
}
}

for (int i = 0; i < purchaseInteractions.Count; i++)
{
PurchaseInteraction purchaseInteraction = purchaseInteractions[i];

if (purchaseInteraction.available)
{
string dropName = null;
var chest = purchaseInteraction?.gameObject.GetComponent<ChestBehavior>();
if (chest)
{
dropName = Util.GenerateColoredString(Language.GetString(chest.dropPickup.GetPickupNameToken()), chest.dropPickup.GetPickupColor());
}
float distanceToObject = Vector3.Distance(Camera.main.transform.position, purchaseInteraction.transform.position);
Vector3 Position = Camera.main.WorldToScreenPoint(purchaseInteraction.transform.position);
var BoundingVector = new Vector3(Position.x, Position.y, Position.z);
if (BoundingVector.z > 0.01)
{
int distance = (int)distanceToObject;
String friendlyName = purchaseInteraction.GetDisplayName();
int cost = purchaseInteraction.cost;
string boxText = dropName != null ? $"{friendlyName}\n${cost}\n{distance}m\n{dropName}" : $"{friendlyName}\n${cost}\n{distance}m";
GUI.Label(new Rect(BoundingVector.x - 50f, (float)Screen.height - BoundingVector.y, 100f, 50f), boxText, Styles.RenderInteractablesStyle);
}
}

}
private static string BuyingUnit(string name, int cost)
{
if (name.Contains("Newt") || name.Contains("Lunar") || name.Contains("Order") || name.Contains("Slab"))
return cost + "LC";
else if (name.Contains("Void") || name.Contains("Blood"))
return cost + "%HP";
return "$" + cost;
}
private static GUIStyle ChooseStyle(string name)
{
if (name.Contains("Newt"))
return Styles.NewtStyle;
else if (name.Contains("Chest") || name.Contains("Multishop") || name.Contains("Printer"))
return Styles.ChestStyle;
else if (name.Contains("Equipment"))
return Styles.EquipmentStyle;
else if (name.Contains("Lunar"))
return Styles.LunarStyle;
else if (name.Contains("Void"))
return Styles.VoidStyle;
else if (name.Contains("Gold") || name.Contains("Chance"))
return Styles.ChanceStyle;
else if (name.Contains("Blood"))
return Styles.BloodStyle;
else if (name.Contains("Combat") || name.Contains("Order"))
return Styles.CombatStyle;
else if (name.Contains("Mountain"))
return Styles.MountainStyle;
else if (name.Contains("Woods"))
return Styles.WoodsStyle;
return Styles.DefaultStyle;
}

public static void Mobs()
Expand All @@ -232,9 +295,9 @@ public static void Mobs()
var mob = HurtBox.FindEntityObject(hurtBoxes[i]);
if (mob)
{
Vector3 MobPosition = Camera.main.WorldToScreenPoint(mob.transform.position);
Vector3 MobPosition = camera.WorldToScreenPoint(mob.transform.position);
var MobBoundingVector = new Vector3(MobPosition.x, MobPosition.y, MobPosition.z);
float distanceToMob = Vector3.Distance(Camera.main.transform.position, mob.transform.position);
float distanceToMob = Vector3.Distance(camera.transform.position, mob.transform.position);
if (MobBoundingVector.z > 0.01)
{
float width = 100f * (distanceToMob / 100);
Expand Down
47 changes: 47 additions & 0 deletions Renderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using UnityEngine;

namespace UmbraMenu.monsoon
{
public class Renderer
{
public static GUIStyle StringStyle { get; set; } = new GUIStyle(GUI.skin.label);

public static Color Color
{
get { return GUI.color; }
set { GUI.color = value; }
}

public static void DrawLine(Vector2 from, Vector2 to, Color color)
{
Color = color;
DrawLine(from, to);
}
public static void DrawLine(Vector2 from, Vector2 to)
{
var angle = Vector2.SignedAngle(from, to);
GUIUtility.RotateAroundPivot(angle, from);
DrawBox(from, Vector2.right * (from - to).magnitude, false);
GUIUtility.RotateAroundPivot(-angle, from);
}

public static void DrawBox(Vector2 position, Vector2 size, Color color, bool centered = true)
{
Color = color;
DrawBox(position, size, centered);
}
public static void DrawBox(Vector2 position, Vector2 size, bool centered = true)
{
var upperLeft = centered ? position - size / 2f : position;
GUI.DrawTexture(new Rect(upperLeft, size), Texture2D.whiteTexture, ScaleMode.StretchToFill);
}

public static void DrawString(Vector2 position, string label, GUIStyle style, bool centered = true)
{
var content = new GUIContent(label);
var size = StringStyle.CalcSize(content);
var upperLeft = centered ? position - size / 2f : position;
GUI.Label(new Rect(upperLeft, size), content, style);
}
}
}
Loading

0 comments on commit fd3d154

Please sign in to comment.