Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Jun 3, 2021
1 parent ce42636 commit 4a0325a
Show file tree
Hide file tree
Showing 17 changed files with 654 additions and 79 deletions.
2 changes: 1 addition & 1 deletion ControllerButtonSwitch/BepInExPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ControllerButtonSwitch
{
[BepInPlugin("aedenthorn.ControllerButtonSwitch", "Controller Button Switch", "0.1.0")]
[BepInPlugin("aedenthorn.ControllerButtonSwitch", "Controller Button Switch", "0.1.1")]
public class BepInExPlugin : BaseUnityPlugin
{
private static readonly bool isDebug = true;
Expand Down
45 changes: 27 additions & 18 deletions ControllerButtonSwitch/ButtonInfo.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
using BepInEx.Configuration;
using System;
using System.Globalization;

namespace ControllerButtonSwitch
{
internal class ButtonInfo
public class ButtonInfo
{
internal string button;
internal string key;
internal float repeatDelay = 0;
internal float repeatInterval = 0;
internal bool inverted = false;
public string button;
public string key;
public float repeatDelay = 0;
public float repeatInterval = 0;
public bool inverted = false;

public ButtonInfo(string name, ConfigEntry<string> entry)
{
button = name;
string[] parts = entry.Value.Split(',');
key = parts[0];
if (parts.Length == 1)
return;
repeatDelay = float.Parse(parts[1]);
if (parts.Length == 2)
return;
repeatInterval = float.Parse(parts[2]);
if (parts.Length == 3)
return;
inverted = bool.Parse(parts[3]);
try
{
button = name;
string[] parts = entry.Value.Split(',');
key = parts[0];
if (parts.Length == 1)
return;
repeatDelay = float.Parse(parts[1], CultureInfo.InvariantCulture.NumberFormat);
if (parts.Length == 2)
return;
repeatInterval = float.Parse(parts[2], CultureInfo.InvariantCulture.NumberFormat);
if (parts.Length == 3)
return;
inverted = bool.Parse(parts[3]);
}
catch(Exception ex)
{
BepInExPlugin.Dbgl($"Exception parsing config entry {name} string {entry.Value}\n{ex}");
}
}
}
}
77 changes: 62 additions & 15 deletions ServerRewards/BepInExPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using BepInEx.Configuration;
using HarmonyLib;
using Steamworks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;

namespace ServerRewards
{
[BepInPlugin("aedenthorn.ServerRewards", "Server Rewards", "0.5.4")]
[BepInPlugin("aedenthorn.ServerRewards", "Server Rewards", "0.6.2")]
public partial class BepInExPlugin : BaseUnityPlugin
{

Expand All @@ -34,6 +35,7 @@ public partial class BepInExPlugin : BaseUnityPlugin
public static ConfigEntry<int> titleFontSize;
public static ConfigEntry<int> currencyFontSize;
public static ConfigEntry<int> labelFontSize;
public static ConfigEntry<int> tooltipFontSize;
public static ConfigEntry<int> packagesPerRow;

public static ConfigEntry<string> storeTitleString;
Expand All @@ -43,6 +45,10 @@ public partial class BepInExPlugin : BaseUnityPlugin
public static ConfigEntry<string> packageInfoString;
public static ConfigEntry<string> rewardString;

public static ConfigEntry<Color> windowBackgroundColor;
public static ConfigEntry<Color> tooltipBackgroundColor;
public static ConfigEntry<Color> tooltipTextColor;

private static BepInExPlugin context;
private static int myCurrency;
private static bool storeOpen;
Expand All @@ -52,7 +58,10 @@ public partial class BepInExPlugin : BaseUnityPlugin
private static GUIStyle titleStyle;
private static GUIStyle currencyStyle;
private static GUIStyle labelStyle;
private static GUIStyle tooltipStyle;
private static Texture2D tooltipBackground;
private static GUIStyle coinStyle;
private static GUIStyle tooltipWindowStyle;
private static Rect windowRect;
private static string windowTitleText;
private static List<PackageInfo> storePackages = new List<PackageInfo>();
Expand Down Expand Up @@ -90,8 +99,13 @@ private void Awake()
titleFontSize = Config.Bind<int>("UI", "TitleFontSize", 24, "Size of the store window title");
currencyFontSize = Config.Bind<int>("UI", "CurrencyFontSize", 20, "Size of the currency info");
labelFontSize = Config.Bind<int>("UI", "LabelFontSize", 20, "Size of the package labels");
tooltipFontSize = Config.Bind<int>("UI", "TooltipFontSize", 16, "Size of the tooltip text");
coinBeforeAmount = Config.Bind<bool>("UI", "CoinBeforeAmount", true, "Display the currency icon before the amount? Otherwise after");

windowBackgroundColor = Config.Bind<Color>("Colors", "WindowBackgroundColor", new Color(0,0,0,0.5f), "Store window background color");
tooltipBackgroundColor = Config.Bind<Color>("Colors", "TooltipBackgroundColor", Color.black, "Tooltip background color");
tooltipTextColor = Config.Bind<Color>("Colors", "TooltipTextColor", Color.white, "Tooltip background color");

storeTitleString = Config.Bind<string>("Text", "StoreTitle", "<b><color=#FFFFFFFF>Server Store</color></b>", "Store window title");
currencyString = Config.Bind<string>("Text", "CurrencyString", "<b><color=#FFFF00FF>{0}</color></b>", "Currency string");
myCurrencyString = Config.Bind<string>("Text", "MyCurrencyString", "<b><color=#FFFFFFFF>My Balance:</color></b>", "My currency string");
Expand Down Expand Up @@ -179,6 +193,17 @@ private static void ApplyConfig()
{
alignment = TextAnchor.MiddleCenter
};
tooltipStyle = new GUIStyle
{
richText = true,
fontSize = tooltipFontSize.Value,
wordWrap = true,
alignment = TextAnchor.MiddleLeft
};
tooltipBackground = new Texture2D(1, 1, TextureFormat.ARGB32, false);
tooltipBackground.SetPixel(0, 0, tooltipBackgroundColor.Value);
tooltipBackground.Apply();

}

private void Update()
Expand Down Expand Up @@ -224,43 +249,46 @@ private void Update()
}

}

private void OnGUI()
{


if (!modEnabled.Value)
return;

if (thisTooltip != null && thisTooltip.Length > 0)
{
tooltipWindowStyle = new GUIStyle(GUI.skin.window);
tooltipWindowStyle.normal.background = tooltipBackground;
GUI.Window(424244, new Rect(Input.mousePosition.x + 30, Screen.height - Input.mousePosition.y + 30, 400, 80), new GUI.WindowFunction(TooltipBuilder), thisTooltip.Split('^')[0], tooltipWindowStyle);
}

if (testing.Value)
{
if (storeOpen)
{
GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 200, 40), "test");
GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 100, 200, 40), thisTooltip);
if (GameCamera.instance)
{
Traverse.Create(GameCamera.instance).Field("m_mouseCapture").SetValue(false);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = ZInput.IsMouseActive();
}
GUI.backgroundColor = windowBackgroundColor.Value;
windowRect = GUI.Window(424243, windowRect, new GUI.WindowFunction(WindowBuilder), "");
if (!Input.GetKey(KeyCode.Mouse0) && (windowRect.x != windowPosition.Value.x || windowRect.y != windowPosition.Value.y))
{
windowPosition.Value = new Vector2(windowRect.x, windowRect.y);
}

}
return;
}
if (!ZNet.instance?.IsServer() == true && Player.m_localPlayer)
else if (!ZNet.instance?.IsServer() == true && Player.m_localPlayer)
{
if (storeOpen)
{
Traverse.Create(GameCamera.instance).Field("m_mouseCapture").SetValue(false);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = ZInput.IsMouseActive();
GUI.backgroundColor = windowBackgroundColor.Value;
windowRect = GUI.Window(424243, windowRect, new GUI.WindowFunction(WindowBuilder), "");
GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y + 50, 200, 40), GUI.tooltip);
}
if (!Input.GetKey(KeyCode.Mouse0) && (windowRect.x != windowPosition.Value.x || windowRect.y != windowPosition.Value.y))
{
Expand All @@ -269,6 +297,18 @@ private void OnGUI()
}
}

private void TooltipBuilder(int id)
{
if (thisTooltip == null || thisTooltip.Length == 0)
return;

tooltipStyle.normal.textColor = tooltipTextColor.Value;

GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(windowWidth.Value) });
GUILayout.Label(thisTooltip.Split('^')[1], tooltipStyle);
GUILayout.EndVertical();
}

private void WindowBuilder(int id)
{
GUI.DragWindow(new Rect(0,0,windowWidth.Value, 20));
Expand Down Expand Up @@ -309,8 +349,13 @@ private void WindowBuilder(int id)
}
PackageInfo pi = storePackages[i];
string texture = textureDict.ContainsKey(pi.type) ? pi.type : "Common";
if (!textureDict.ContainsKey(texture))
{
Dbgl($"Missing texture for {texture} type");
continue;
}
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(itemWidth) });
if (GUILayout.Button(new GUIContent(textureDict[texture], "This is a test"), new GUILayoutOption[] { GUILayout.Width(itemWidth), GUILayout.Height(itemWidth) }))
if (GUILayout.Button(new GUIContent(textureDict[texture], pi.name + "^" + pi.description), new GUILayoutOption[] { GUILayout.Width(itemWidth), GUILayout.Height(itemWidth) }))
{
if (myCurrency >= pi.price)
{
Expand Down Expand Up @@ -338,10 +383,6 @@ private void WindowBuilder(int id)
}
}
}
if(GUI.tooltip != null && GUI.tooltip.Length > 0)
{
thisTooltip = GUI.tooltip;
}

GUILayout.Label(string.Format(packageString.Value, pi.name), labelStyle, new GUILayoutOption[] { GUILayout.Width(itemWidth) });
GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Width(itemWidth) });
Expand All @@ -361,12 +402,18 @@ private void WindowBuilder(int id)
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
if (GUI.tooltip != null && GUI.tooltip.Length > 0)
{
thisTooltip = GUI.tooltip;
}
else
thisTooltip = null;

GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndVertical();
}

}
}
14 changes: 5 additions & 9 deletions ServerRewards/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static void RPC_SendJSON(ZRpc rpc, string json)
Dbgl($"Item {name} not found!");
continue;
}

int amount = int.Parse(nameAmount[1]);

if (useTombstone.Value)
Expand All @@ -300,19 +300,15 @@ private static void RPC_SendJSON(ZRpc rpc, string json)
{
int stack = Mathf.Min(item.m_shared.m_maxStackSize, amount);

ItemDrop.ItemData _newItem = item.Clone();
_newItem.m_stack = stack;
chest.GetComponent<Container>().GetInventory().AddItem(_newItem);
//chest.GetComponent<Container>().GetInventory().AddItem(item.m_shared.m_name, stack, item.m_quality, item.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
//chest.GetComponent<Container>().GetInventory().AddItem(_newItem);
chest.GetComponent<Container>().GetInventory().AddItem(name, stack, item.m_quality, item.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
amount = amount - stack;
}

if (amount > 0)
{
ItemDrop.ItemData _newItem2 = item.Clone();
_newItem2.m_stack = amount;
chest.GetComponent<Container>().GetInventory().AddItem(_newItem2);
//chest.GetComponent<Container>().GetInventory().AddItem(_newItem2.m_shared.m_name, amount, _newItem2.m_quality, _newItem2.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
//chest.GetComponent<Container>().GetInventory().AddItem(_newItem2);
chest.GetComponent<Container>().GetInventory().AddItem(name, amount, item.m_quality, item.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName());
}

itemStrings.Add($"{Localization.instance.Localize(item.m_shared.m_name)} {nameAmount[0]}");
Expand Down
1 change: 1 addition & 0 deletions ServerRewards/ServerRewards/StoreInfo/Common_Base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "Base_Common",
"name": "Common",
"description": "This is a common chest.",
"price": 50,
"type": "Common",
"items": [
Expand Down
17 changes: 9 additions & 8 deletions ServerRewards/ServerRewards/StoreInfo/Epic_Base.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"id": "Base_Epic",
"name": "Epic",
"price": 400,
"type": "Epic",
"items": [
"ArmorIronLegs,1,10,choice",
"ArmorIronChest,1,10,choice",
"id": "Base_Epic",
"name": "Epic",
"description": "This is an epic chest.",
"price": 400,
"type": "Epic",
"items": [
"ArmorIronLegs,1,10,choice",
"ArmorIronChest,1,10,choice",
"HelmetIron,1,10,choice",
"CapeWolf,1,10,choice",
"SledgeIron,1,5,choice",
Expand All @@ -26,5 +27,5 @@
"BowDraugrFang,1,2,choice",
"ArrowFire,20-100,10,chance",
"ArrowIron,20-100,10,chance"
]
]
}
17 changes: 9 additions & 8 deletions ServerRewards/ServerRewards/StoreInfo/Legendary_Base.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"id": "Base_Legendary",
"name": "Legendary",
"price": 1000,
"type": "Legendary",
"items": [
"ArmorWolfLegs,1,10,choice",
"ArmorWolfChest,1,10,choice",
"id": "Base_Legendary",
"name": "Legendary",
"description": "This is a legendary chest.",
"price": 1000,
"type": "Legendary",
"items": [
"ArmorWolfLegs,1,10,choice",
"ArmorWolfChest,1,10,choice",
"HelmetDrake,1,10,choice",
"CapeWolf,1,15,choice",
"SpearChitin,1,5,choice",
Expand All @@ -28,5 +29,5 @@
"ArrowFrost,20-100,10,chance",
"ArrowObsidian,20-100,10,chance",
"ArrowNeedle,20-100,10,chance"
]
]
}
17 changes: 9 additions & 8 deletions ServerRewards/ServerRewards/StoreInfo/Rare_Base.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"id": "Base_Rare",
"name": "Rare",
"price": 150,
"type": "Rare",
"items": [
"ArmorBronzeLegs,1,10,choice",
"ArmorBronzeChest,1,10,choice",
"id": "Base_Rare",
"name": "Rare",
"description": "This is a rare chest.",
"price": 150,
"type": "Rare",
"items": [
"ArmorBronzeLegs,1,10,choice",
"ArmorBronzeChest,1,10,choice",
"HelmetBronze,1,10,choice",
"CapeTrollHide,1,10,choice",
"SledgeStagbreaker,1,5,choice",
Expand All @@ -20,5 +21,5 @@
"ArrowFire,100,10,chance",
"ArrowBronze,100,10,chance",
"ShieldWood,1,10,choice"
]
]
}
Loading

0 comments on commit 4a0325a

Please sign in to comment.