1- using Centrifuge . Distance . Game ;
2- using Centrifuge . Distance . GUI . Controls ;
3- using Centrifuge . Distance . GUI . Data ;
1+ using BepInEx ;
2+ using BepInEx . Configuration ;
3+ using BepInEx . Logging ;
44using Distance . Overheatmeter . Enums ;
5- using Reactor . API . Attributes ;
6- using Reactor . API . Input ;
7- using Reactor . API . Interfaces . Systems ;
8- using Reactor . API . Logging ;
9- using Reactor . API . Runtime . Patching ;
5+ using HarmonyLib ;
106using System ;
117using System . Collections . Generic ;
128using System . Text . RegularExpressions ;
139using UnityEngine ;
1410
1511namespace Distance . Overheatmeter
1612{
17- [ ModEntryPoint ( "com.github.Seeker14491/Heat" ) ]
18- public class Mod : MonoBehaviour
13+ //"com.github.Seeker14491/Heat"
14+ //Authors: vddCore + Seekr + pigpenguin
15+ [ BepInPlugin ( modGUID , modName , modVersion ) ]
16+ public sealed class Mod : BaseUnityPlugin
1917 {
20- public static Mod Instance ;
18+ //Mod Details
19+ private const string modGUID = "Distance.OverheatMeter" ;
20+ private const string modName = "Overheat Meter" ;
21+ private const string modVersion = "1.0.0" ;
2122
22- public IManager Manager { get ; set ; }
23+ //Config Entries
24+ public static ConfigEntry < KeyboardShortcut > ToggleHotkey { get ; set ; }
25+ public static ConfigEntry < ActivationMode > ActivationModeConfig { get ; set ; }
26+ public static ConfigEntry < DisplayMode > DisplayModeConfig { get ; set ; }
27+ public static ConfigEntry < float > WarningThreshold { get ; set ; }
2328
24- public Log Logger { get ; set ; }
29+ //Public Variables
2530
26- public ConfigurationLogic Config { get ; private set ; }
31+ //Private Variables
2732
28- public void Initialize ( IManager manager )
33+ //Other
34+ private static readonly Harmony harmony = new Harmony ( modGUID ) ;
35+ public static ManualLogSource Log = new ManualLogSource ( modName ) ;
36+ public static Mod Instance ;
37+
38+ void Awake ( )
2939 {
3040 DontDestroyOnLoad ( this ) ;
31- Instance = this ;
32- Manager = manager ;
33-
3441 Flags . SubscribeEvents ( ) ;
3542
36- Logger = LogManager . GetForCurrentAssembly ( ) ;
37- Config = gameObject . AddComponent < ConfigurationLogic > ( ) ;
43+ if ( Instance == null )
44+ {
45+ Instance = this ;
46+ }
3847
39- Config . OnChanged += OnConfigChanged ;
48+ Log = BepInEx . Logging . Logger . CreateLogSource ( modGUID ) ;
49+ Logger . LogInfo ( "Initializing Overheat Meter..." ) ;
4050
41- OnConfigChanged ( Config ) ;
51+ //Config Setup
52+ ToggleHotkey = Config . Bind ( "General" , "SET TOGGLE HOTKEY" , new KeyboardShortcut ( KeyCode . H , new KeyCode [ ] { KeyCode . LeftControl } ) ,
53+ new ConfigDescription ( "Set the shortcut to toggle the Overheat Meter UI" ) ) ;
4254
43- CreateSettingsMenu ( ) ;
55+ ActivationModeConfig = Config . Bind ( "General" , "ACTIVATION MODE" , ActivationMode . Always , new ConfigDescription ( "Control how the UI activates" ) ) ;
4456
45- RuntimePatcher . AutoPatch ( ) ;
46- }
57+ DisplayModeConfig = Config . Bind ( "General" , "DISPLAY MODE" , DisplayMode . Hud , new ConfigDescription ( "Control how the UI displays" ) ) ;
4758
48- private void CreateSettingsMenu ( )
49- {
50- var settingsMenu = new MenuTree ( "menu.mod.heat" , "Heat Display Settings" )
51- {
52- new InputPrompt ( MenuDisplayMode . Both , "setting:toggle_hotkey" , "SET TOGGLE HOTKEY" )
53- . WithTitle ( "SET TOGGLE HOTKEY" )
54- . WithDefaultValue ( ( ) => Config . ToggleHotkey )
55- . WithSubmitAction ( x => Config . ToggleHotkey = x ) ,
56-
57- new ListBox < DisplayMode > ( MenuDisplayMode . Both , "setting:display_mode" , "DISPLAY MODE" )
58- . WithEntries ( MapEnumToListBox < DisplayMode > ( ) )
59- . WithGetter ( ( ) => Config . DisplayMode )
60- . WithSetter ( ( x ) => Config . DisplayMode = x ) ,
61-
62- new ListBox < ActivationMode > ( MenuDisplayMode . Both , "setting:activation_mode" , "ACTIVATION MODE" )
63- . WithEntries ( MapEnumToListBox < ActivationMode > ( ) )
64- . WithGetter ( ( ) => Config . ActivationMode )
65- . WithSetter ( ( x ) => Config . ActivationMode = x ) ,
66-
67- new FloatSlider ( MenuDisplayMode . Both , "setting:warning_threshold" , "WARNING THRESHOLD" )
68- . LimitedByRange ( 0.0f , 1.0f )
69- . WithGetter ( ( ) => Config . WarningTreshold )
70- . WithSetter ( ( x ) => Config . WarningTreshold = x )
71- } ;
72-
73- Menus . AddNew ( MenuDisplayMode . Both , settingsMenu , "HEAT DISPLAY" , "Configure the Heat mod." ) ;
59+ WarningThreshold = Config . Bind ( "General" , "WARNING THRESHOLD" , 0.8f , new ConfigDescription ( "Adjust the warning threshold" , new AcceptableValueRange < float > ( 0.0f , 1.0f ) ) ) ;
60+
61+ //Apply Patches
62+ Logger . LogInfo ( "Loading..." ) ;
63+ harmony . PatchAll ( ) ;
64+ Logger . LogInfo ( "Loaded!" ) ;
7465 }
7566
7667 #region Utilities
@@ -105,33 +96,40 @@ private string SplitCamelCase(string str)
10596 #endregion
10697
10798 #region Data
108- public bool DisplayCondition => Config . ActivationMode == ActivationMode . Always ||
109- ( Config . ActivationMode == ActivationMode . Warning && Vehicle . HeatLevel >= Config . WarningTreshold ) ||
110- ( Config . ActivationMode == ActivationMode . Toggle && Toggled ) ;
99+ public bool DisplayCondition => ActivationModeConfig . Value == ActivationMode . Always ||
100+ ( ActivationModeConfig . Value == ActivationMode . Warning && Vehicle . HeatLevel >= WarningThreshold . Value ) ||
101+ ( ActivationModeConfig . Value == ActivationMode . Toggle && Toggled ) ;
111102
112103 public bool Toggled { get ; set ; }
113104
114105 public string Text => $ "{ GetHeatLevel ( ) } \n { GetSpeed ( ) } ";
115106
116107 public string GetHeatLevel ( )
117108 {
118- string percent = Mathf . RoundToInt ( 100 * Mathf . Clamp ( Vehicle . HeatLevel , 0 , 1 ) ) . ToString ( ) ;
119- while ( percent . Length < 3 )
109+ if ( G . Sys . GameManager_ . IsModeStarted_ )
120110 {
121- percent = $ "0{ percent } ";
122- }
111+ string percent = Mathf . RoundToInt ( 100 * Mathf . Clamp ( Vehicle . HeatLevel , 0 , 1 ) ) . ToString ( ) ;
112+ while ( percent . Length < 3 )
113+ {
114+ percent = $ "0{ percent } ";
115+ }
123116
124- return $ "{ percent } %";
117+ return $ "{ percent } %";
118+ }
119+ else
120+ {
121+ return "0%" ;
122+ }
125123 }
126124
127125 private string GetSpeed ( )
128126 {
129127 if ( G . Sys . GameManager_ . IsModeStarted_ )
130128 {
131- switch ( Centrifuge . Distance . Game . Options . General . Units )
129+ switch ( Options . General . Units )
132130 {
133131 case Units . Metric :
134- return $ "{ Mathf . RoundToInt ( Vehicle . VelocityKPH ) } KM/H";
132+ return $ "{ Mathf . RoundToInt ( Vehicle . VelocityKPH ) } KM/H";
135133 case Units . Imperial :
136134 return $ "{ Mathf . RoundToInt ( Vehicle . VelocityMPH ) } MPH";
137135 default :
@@ -146,9 +144,13 @@ private string GetSpeed()
146144 #endregion
147145
148146 #region Settings Changed
149- public void OnConfigChanged ( ConfigurationLogic config )
147+ public void OnConfigChanged ( object sender , EventArgs e )
150148 {
151- BindAction ( ref _keybindToggle , config . ToggleHotkey , ( ) =>
149+ SettingChangedEventArgs settingChangedEventArgs = e as SettingChangedEventArgs ;
150+
151+ if ( settingChangedEventArgs == null ) return ;
152+
153+ if ( sender == ToggleHotkey )
152154 {
153155 Toggled = ! Toggled ;
154156
@@ -159,22 +161,7 @@ public void OnConfigChanged(ConfigurationLogic config)
159161 trickText . Clear ( ) ;
160162 }
161163 }
162- } ) ;
163- }
164- #endregion
165-
166- #region Key Bindings
167-
168- private Hotkey _keybindToggle = null ;
169-
170- public void BindAction ( ref Hotkey unbind , string rebind , Action callback )
171- {
172- if ( unbind != null )
173- {
174- Manager . Hotkeys . UnbindHotkey ( unbind ) ;
175164 }
176-
177- unbind = Manager . Hotkeys . BindHotkey ( rebind , callback , true ) ;
178165 }
179166 #endregion
180167 }
0 commit comments