Skip to content

Commit

Permalink
V4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MeowServer committed Jul 4, 2024
1 parent e7012d4 commit 5eec0ab
Show file tree
Hide file tree
Showing 15 changed files with 963 additions and 651 deletions.
1 change: 1 addition & 0 deletions .vs/HintServiceMeow.csproj.dtbcache.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ public class PlayerDisplayConfig

[Description("The minimum time wait before each update, you can shorten it if you're confident with your server's performance, count in miliseconds")]
public float MinTimeDelayBeforeUpdate = 50f;

[Description("The interval between each hint content refresh, count in second.")]
public float HintUpdateInterval = 0.1f;

[Description("The time between each force update.")]
public float ForceUpdateInterval = 3f;
}
}
44 changes: 0 additions & 44 deletions Config/PlayerDisplayConfigs/HintConfigs.cs

This file was deleted.

127 changes: 127 additions & 0 deletions Config/PlayerUIConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HintServiceMeow.Config
{
public class PlayerUIConfig
{
[Description("The default time to show for each type of common hint.\r\n" +
"Short means that the hint has on title but not decription\r\n")]
public int ItemHintDisplayTime { get; set; } = 10;
public int ShortItemHintDisplayTime { get; set; } = 5;

public int MapHintDisplayTime { get; set; } = 10;
public int ShortMapHintDisplayTime { get; set; } = 7;

public int RoleHintDisplayTime { get; set; } = 15;
public int ShortRoleHintDisplayTime { get; set; } = 5;

public int OtherHintDisplayTime { get; set; } = 5;

[Description("The default config to show for each type of common hint.\r\n" +
"Only config for alignment, font size, hint fiel, and priority are valid.\r\n")]
public List<DynamicHintConfig> ItemHints { get; set; } = new List<DynamicHintConfig>()
{
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 25,
TopYCoordinate = 450,
BottomYCoordinate = 750
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 25,
TopYCoordinate = 475,
BottomYCoordinate = 775
}
};

public List<DynamicHintConfig> MapHints { get; set; } = new List<DynamicHintConfig>()
{
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Right,
FontSize = 25,
TopYCoordinate = 0,
BottomYCoordinate = 200
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Right,
FontSize = 25,
TopYCoordinate = 25,
BottomYCoordinate = 225
}
};

public List<DynamicHintConfig> RoleHints { get; set; } = new List<DynamicHintConfig>()
{
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Left,
FontSize = 30,
TopYCoordinate = 100,
BottomYCoordinate = 500
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Left,
FontSize = 25,
TopYCoordinate = 130,
BottomYCoordinate = 530
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Left,
FontSize = 25,
TopYCoordinate = 155,
BottomYCoordinate = 555
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Left,
FontSize = 25,
TopYCoordinate = 180,
BottomYCoordinate = 580
}
};

public List<DynamicHintConfig> OtherHints { get; set; } = new List<DynamicHintConfig>()
{
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 20,
TopYCoordinate = 520,
BottomYCoordinate = 700
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 20,
TopYCoordinate = 540,
BottomYCoordinate = 700
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 20,
TopYCoordinate = 560,
BottomYCoordinate = 700
},
new DynamicHintPositionConfig()
{
Alignment = HintAlignment.Center,
FontSize = 20,
TopYCoordinate = 580,
BottomYCoordinate = 700
}
};
}
}
12 changes: 5 additions & 7 deletions Config/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using Exiled.API.Enums;
using Exiled.API.Interfaces;
using PlayerRoles;
using Respawning;
using Exiled.API.Interfaces;

using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace HintServiceMeow.Config
{
public class PluginConfig:IConfig
{
internal static PluginConfig instance;
internal static PluginConfig Instance;

public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;

[Description("Configs for PlayerDisplay. Changing these configs might leads to errors")]
public PlayerDisplayConfig PlayerDisplayConfig { get; set; } = new PlayerDisplayConfig();

[Description("The for PlayerUI. PlayerUI contains commonly used hints")]
public PlayerUIConfig PlayerUIConfig { get; set; } = new PlayerUIConfig();
}
}
43 changes: 43 additions & 0 deletions EventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Exiled.Events.EventArgs.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HintServiceMeow
{
public static class EventHandler
{
public delegate void NewPlayerHandler(PlayerDisplay playerDisplay);
public static event NewPlayerHandler NewPlayer;

internal static void InvokeNewPlayerEvent(PlayerDisplay pd)
{
NewPlayer?.Invoke(pd);
}

// Create PlayerDisplay and PlayerUIConfig for the new player
internal static void OnVerified(VerifiedEventArgs ev)
{
if (ev.Player.IsNPC) return;

var pd = new PlayerDisplay(ev.Player);
new PlayerUI(ev.Player);

EventHandler.InvokeNewPlayerEvent(pd);
}

internal static void OnLeft(LeftEventArgs ev)
{
PlayerUI.RemovePlayerUI(ev.Player);
PlayerDisplay.RemovePlayerDisplay(ev.Player);
}

internal static void OnDisable()
{
PlayerUI.ClearPlayerUI();
PlayerDisplay.ClearPlayerDisplay();
}
}
}
22 changes: 3 additions & 19 deletions Patch.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
using HarmonyLib;
using Hints;
using Mirror;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Utf8Json;
using YamlDotNet.Core;
using Exiled.API.Features;

namespace HintServiceMeow
{
[HarmonyPatch(typeof(HintDisplay), nameof(HintDisplay.Show))]
static class HintPatch
internal static class HintPatch
{
static bool Prefix(Hints.Hint hint, ref HintDisplay __instance)
{
try
{
var playerDisplay = PlayerDisplay.Get(Player.Get(__instance.connectionToClient));

if (playerDisplay.UpdatedRecently())
{
return true;
}

return false;
return playerDisplay.AllowPatchUpdate;
}
catch(Exception e)
{
Expand All @@ -40,7 +24,7 @@ static bool Prefix(Hints.Hint hint, ref HintDisplay __instance)

[HarmonyPatch(typeof(Player))]
[HarmonyPatch("ShowHint", typeof(string), typeof(float))]
static class HintPatch2
internal static class HintPatch2
{
static bool Prefix(string message, float duration, ref Player __instance)
{
Expand Down
78 changes: 78 additions & 0 deletions PlayerDisplay/Hints/DynamicHintConfigs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HintServiceMeow
{
[Description("Please be aware that the plugin might not be using all of the config." +
"\r\nIn other words, not all of the following configs are valid")]
public class DynamicHintConfig
{
[Description("The ID of the hint")]
public string Id { get; set; } = null;

[Description("The priority of the hint. Higher priority means the hint is less likely to be covered by other hint." +
"\r\nnAvailable: Highest, High, Medium, Low, Lowest")]
public HintPriority Priority { get; set; } = HintPriority.Medium;

public DynamicHintPositionConfig Position { get; set; } = new DynamicHintPositionConfig();

public DynamicHintContentConfig Content { get; set; } = new DynamicHintContentConfig();

public DynamicHintConfig()
{
}
}

public class DynamicHintPositionConfig
{
[Description("The alignment of the hint. " +
"\r\nAvailable: Left, Right, Center ")]
public HintAlignment Alignment { get; set; } = HintAlignment.Center;

[Description("The size of the font, default is 20")]
public int FontSize { get; set; } = 20;

[Description("The Y-Coordiante of top boundary, default is 300")]
public int TopYCoordinate { get; set; } = 300;

[Description("The Y-Coordiante of bottom boundary, default is 700")]
public int BottomYCoordinate { get; set; } = 700;

public DynamicHintPositionConfig()
{
}

public static implicit operator DynamicHintConfig(DynamicHintPositionConfig v)
{
return new DynamicHintConfig()
{
Position = v,
};
}
}

public class DynamicHintContentConfig
{
[Description("The initial message displayed. The message migth be changed by the plugin")]
public string Message { get; set; } = "This is a default message";

[Description("To hide the hint or not.")]
public bool Hide { get; set; } = false;

public DynamicHintContentConfig()
{
}

public static implicit operator DynamicHintConfig(DynamicHintContentConfig v)
{
return new DynamicHintConfig()
{
Content = v,
};
}
}
}
Loading

0 comments on commit 5eec0ab

Please sign in to comment.