Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 66 additions & 64 deletions BetterUI/BetterUI.csproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions BetterUI/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
####v2.4.4
####v2.4.4
- Fix for game version 0.217.14 (JuniorAndria)
####v2.4.3
- Required updates for Valheim version 0.216.9
Expand Down
26 changes: 13 additions & 13 deletions BetterUI/GameClasses/EnemyHud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

using TMPro;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -46,13 +46,13 @@ static void ShowHudPostfix(ref EnemyHud __instance, ref Character c, ref bool __
return;
}

var hpRoot = (hudData.m_gui.transform.Find("Health") as RectTransform);
RectTransform hpRoot = (hudData.m_gui.transform.Find("Health") as RectTransform);

if (c.IsPlayer())
{
if (Main.showPlayerHPText.Value)
{
var hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
TextMeshProUGUI hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
hpText.name = PlayerHpPrefix;
hpText.rectTransform.anchoredPosition = new Vector2(hpText.rectTransform.anchoredPosition.x, 3.5f);
hpText.text = $"<size={Main.playerHPTextSize.Value}>{hudData.m_character.GetHealth():0}/{hudData.m_character.GetMaxHealth():0}</size>";
Expand All @@ -71,7 +71,7 @@ static void ShowHudPostfix(ref EnemyHud __instance, ref Character c, ref bool __
if (Main.showEnemyHPText.Value)
{
// Edits to Boss HP Bar
var hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
TextMeshProUGUI hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
hpText.name = BossHpPrefix;
hpText.rectTransform.anchoredPosition = new Vector2(hpText.rectTransform.anchoredPosition.x, 0.0f); // orig.y = 21f
hpText.text = $"<size={Main.bossHPTextSize.Value}>{hudData.m_character.GetHealth():0} / {hudData.m_character.GetMaxHealth():0}</size>";
Expand All @@ -86,13 +86,13 @@ static void ShowHudPostfix(ref EnemyHud __instance, ref Character c, ref bool __
hudData.m_name.fontSize = Main.enemyNameTextSize.Value;
if (Main.enemyLevelStyle.Value != 0)
{
hudData.m_name.text = hudData.m_name.text.Insert(0, $"<size={Main.enemyNameTextSize.Value}><color=white>Lv.{c.m_level} </color></size> ");
hudData.m_name.text = hudData.m_name.text.Insert(0, $"<size={Main.enemyNameTextSize.Value}><color=#ffffffff>Lv.{c.m_level} </color></size> ");
}
if (Main.showEnemyHPText.Value)
{

hpRoot.sizeDelta = new Vector2(hpRoot.sizeDelta.x, hpRoot.sizeDelta.y * 3f);
var hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
TextMeshProUGUI hpText = UnityEngine.Object.Instantiate(hudData.m_name, hudData.m_name.transform.parent);
hpText.name = EnemyHpPrefix;
hpText.rectTransform.anchoredPosition = new Vector2(hpText.rectTransform.anchoredPosition.x, 7.0f); // orig.y = 21f
hpText.text = $"<size={Main.enemyHPTextSize.Value}>{hudData.m_character.GetHealth():0}/{hudData.m_character.GetMaxHealth():0}</size>";
Expand Down Expand Up @@ -135,7 +135,7 @@ static void UpdateHudsPostfix(ref EnemyHud __instance)
Character character = null;
foreach (KeyValuePair<Character, EnemyHud.HudData> keyValuePair in __instance.m_huds)
{
var value = keyValuePair.Value;
EnemyHud.HudData value = keyValuePair.Value;

if (!value.m_character || !__instance.TestShow(value.m_character, true))
{
Expand All @@ -149,13 +149,13 @@ static void UpdateHudsPostfix(ref EnemyHud __instance)
{
if (value.m_character.IsPlayer())
{
if (Main.showPlayerHPText.Value && _hpTextCache.TryGetValue(value, out var hpText)) {
if (Main.showPlayerHPText.Value && _hpTextCache.TryGetValue(value, out TextMeshProUGUI hpText)) {
hpText.text = $"<size={Main.playerHPTextSize.Value}>{value.m_character.GetHealth():0}/{value.m_character.GetMaxHealth():0}</size>";
}
}
else if (value.m_character.IsBoss())
{
if (Main.showEnemyHPText.Value && _hpTextCache.TryGetValue(value, out var hpText)) {
if (Main.showEnemyHPText.Value && _hpTextCache.TryGetValue(value, out TextMeshProUGUI hpText)) {
hpText.text = $"<size={Main.bossHPTextSize.Value}>{value.m_character.GetHealth():0} / {value.m_character.GetMaxHealth():0}</size>";
}
}
Expand All @@ -171,13 +171,13 @@ static void UpdateHudsPostfix(ref EnemyHud __instance)
}


if (Main.showEnemyHPText.Value && _hpTextCache.TryGetValue(value, out var hpText)) {
if (Main.showEnemyHPText.Value && _hpTextCache.TryGetValue(value, out TextMeshProUGUI hpText)) {
hpText.text = $"<size={Main.enemyHPTextSize.Value}>{value.m_character.GetHealth():0}/{value.m_character.GetMaxHealth():0}</size>";
}

if (Main.enemyLevelStyle.Value != 0)
{
value.m_name.text = value.m_name.text.Insert(0, $"<size={Main.enemyNameTextSize.Value}><color=white>Lv.{value.m_character.m_level} </color></size> ");
value.m_name.text = value.m_name.text.Insert(0, $"<size={Main.enemyNameTextSize.Value}><color=#ffffffff>Lv.{value.m_character.m_level} </color></size> ");
}

if (Main.enemyLevelStyle.Value == Main.EnemyLevelStyle.PrefixLevelNumber)
Expand Down Expand Up @@ -224,8 +224,8 @@ public static void ShowLocalPlayerEnemyHudConfigChanged() {
if (Player.m_localPlayer
&& EnemyHud.m_instance
&& EnemyHud.m_instance.m_huds.TryGetValue(Player.m_localPlayer, out EnemyHud.HudData hudData)) {
UnityEngine.Object.Destroy(hudData.m_gui);
EnemyHud.m_instance.m_huds.Remove(Player.m_localPlayer);
UnityEngine.Object.Destroy(hudData.m_gui);
EnemyHud.m_instance.m_huds.Remove(Player.m_localPlayer);
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions BetterUI/GameClasses/FejdStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

namespace BetterUI.GameClasses
{
[HarmonyPatch]
public static class BetterFejdStartup
{
[HarmonyPostfix]
[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
private static void AddWaterMark(ref FejdStartup __instance)
[HarmonyPatch]
public static class BetterFejdStartup
{
Patches.CustomWatermark.Apply(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
private static void AddWaterMark(ref FejdStartup __instance)
{
Patches.CustomWatermark.Apply(__instance);
}

[HarmonyPostfix]
[HarmonyPatch(typeof(FejdStartup), "UpdateCharacterList")]
private static void ShowCharacterStats(ref FejdStartup __instance)
{
if (Main.showCustomCharInfo.Value)
{
Patches.CharacterStats.Show(__instance);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FejdStartup), "UpdateCharacterList")]
private static void ShowCharacterStats(ref FejdStartup __instance)
{
if (Main.showCustomCharInfo.Value)
{
Patches.CharacterStats.Show(__instance);
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion BetterUI/GameClasses/HotkeyBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void PatchHotkeyBar(ref HotkeyBar __instance, ref Player player)
// would be better if this could be done reliably in an Awake/ Start, but I'm not in the mood to look for one
if (element.m_icon.gameObject.GetComponent<ItemIconUpdater>() == null)
{
var origScaleComp = element.m_icon.gameObject.AddComponent<ItemIconUpdater>();
ItemIconUpdater origScaleComp = element.m_icon.gameObject.AddComponent<ItemIconUpdater>();
origScaleComp.Setup(element.m_icon);
}

Expand Down
8 changes: 4 additions & 4 deletions BetterUI/GameClasses/Hud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static void Update(Hud __instance)
Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Now editing: {(Groups)activeLayer}");
}

float gameScale = GameObject.Find("LoadingGUI").GetComponent<CanvasScaler>().scaleFactor;
float gameScale = GuiScaler.m_largeGuiScale;

Vector3 mousePos = Input.mousePosition; // Select element / move element
float scrollPos = Input.GetAxis("Mouse ScrollWheel"); // Change scale
Expand Down Expand Up @@ -132,15 +132,15 @@ private static void Update(Hud __instance)
}
}

var mousePositionChange = (mousePos - lastMousePos) / gameScale;
Vector3 mousePositionChange = (mousePos - lastMousePos) / gameScale;

if (Helpers.CheckHeldKey(Main.modKeyPrimary.Value) && rectList.Count > 0)
{
if (currentlyDragging != string.Empty)
{
if (Helpers.CheckHeldKey(Main.modKeySecondary.Value))
{
var scaledMousePositionChange = mousePositionChange / (new Vector2(Screen.currentResolution.width, Screen.currentResolution.height) / 10);
Vector2 scaledMousePositionChange = mousePositionChange / (new Vector2(Screen.currentResolution.width, Screen.currentResolution.height) / 10);

CustomHud.UpdateScaleAndDimensions(currentlyDragging, scaledMousePositionChange, scrollPos);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ private static void Update(Hud __instance)
}
else
{
foreach (var item in rectList)
foreach (KeyValuePair<string, RectTransform> item in rectList)
{
if (RectTransformUtility.RectangleContainsScreenPoint(item.Value, mousePos))
{
Expand Down
4 changes: 2 additions & 2 deletions BetterUI/GameClasses/InventoryGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class BetterInventoryGrid
[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
private static void PatchInventory(ref InventoryGrid __instance, ref Player player, ItemDrop.ItemData dragItem)
{
var width = __instance.m_inventory.GetWidth();
int width = __instance.m_inventory.GetWidth();
InventoryGrid.Element element;
int index;

Expand All @@ -32,7 +32,7 @@ private static void PatchInventory(ref InventoryGrid __instance, ref Player play
// would be better if this could be done reliably in an Awake/ Start, but I'm not in the mood to look for one
if (element.m_icon.gameObject.GetComponent<ItemIconUpdater>() == null)
{
var origScaleComp = element.m_icon.gameObject.AddComponent<ItemIconUpdater>();
ItemIconUpdater origScaleComp = element.m_icon.gameObject.AddComponent<ItemIconUpdater>();
origScaleComp.Setup(element.m_icon);
}

Expand Down
10 changes: 6 additions & 4 deletions BetterUI/GameClasses/ItemDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BepInEx.Bootstrap;
using HarmonyLib;

namespace BetterUI.GameClasses
Expand All @@ -20,7 +21,7 @@ private static bool PatchHoverText(ref ItemDrop __instance, ref string __result)
text = string.Concat(new object[]
{
text,
" (<color=yellow>",
" (<color=#ffff00ff>",
Patches.Stars.HoverText(__instance.m_itemData.m_quality),
"</color>) "
});
Expand All @@ -29,20 +30,21 @@ private static bool PatchHoverText(ref ItemDrop __instance, ref string __result)
{
text = text + " x" + __instance.m_itemData.m_stack.ToString();
}
__result = Localization.instance.Localize(text + "\n[<color=yellow><b>$KEY_Use</b></color>] $inventory_pickup");
__result = Localization.instance.Localize(text + "\n[<color=#ffff00ff><b>$KEY_Use</b></color>] $inventory_pickup");
return false;
}

[HarmonyPatch]
static class ItemData
{
[HarmonyPrefix]
[HarmonyPatch(typeof(ItemDrop.ItemData), "GetTooltip", new Type[] { typeof(ItemDrop.ItemData), typeof(int), typeof(bool), typeof(float) })]
[HarmonyPatch(typeof(ItemDrop.ItemData), nameof(ItemDrop.ItemData.GetTooltip), new Type[] { typeof(ItemDrop.ItemData), typeof(int), typeof(bool), typeof(float), typeof(int) })]
public static bool PatchTooltip(ref string __result, ItemDrop.ItemData item, int qualityLevel, bool crafting)
{
if (!Main.showCustomTooltips.Value) return true;
if (!Main.showCustomTooltips.Value || Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot")) return true;
__result = Patches.BetterTooltip.Create(item, qualityLevel, crafting);
return false; // https://harmony.pardeike.net/articles/patching-prefix.html#changing-the-result-and-skipping-the-original

}
}
}
Expand Down
43 changes: 33 additions & 10 deletions BetterUI/GameClasses/SkillsDialog.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
using HarmonyLib;
using TMPro;
using UnityEngine.UI;

namespace BetterUI.GameClasses
{
[HarmonyPatch]
public static class BetterSkillsDialog
[HarmonyPatch(typeof(SkillsDialog), nameof(SkillsDialog.Setup))]
static class SkillsDialogSetupPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(SkillsDialog), "Setup")]
private static void ChangeGUI(ref SkillsDialog __instance, ref Player player)
static void Postfix(SkillsDialog __instance, Player player)
{
__instance.gameObject.SetActive(true);
if (__instance == null || player == null)
{
BetterUI.Main.log.LogError("SkillsDialog or Player instance is null.");
return;
}

try
{
__instance.gameObject?.SetActive(true);
}
catch
{
BetterUI.Main.log.LogError("Failed to set SkillsDialog active.");
}

if (Main.showCharacterXP.Value)
{
Utils.FindChild(__instance.transform, "topic").GetComponent<Text>().text = $"Level: {Patches.XP.level:0} Progress: {string.Format("{0:0%}", Patches.XP.LevelProgressPercentage)}";
TMP_Text topicText = Utils.FindChild(__instance.transform, "topic")?.GetComponent<TMP_Text>();
if (topicText != null)
{
topicText.text = $"Level: {Patches.XP.level:0} Progress: {Patches.XP.LevelProgressPercentage:0%}";
}
else
{
BetterUI.Main.log.LogError("Topic text component is null.");
}
}
if (!Main.customSkillUI.Value) return;

Patches.SkillUI.UpdateDialog(__instance, player);
if (Main.customSkillUI.Value)
{
Patches.SkillUI.UpdateDialog(__instance, player);
}
}
}
}
}
Loading