mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
feat(LiveStreamAssist): add automatic statistics tab cycling
This commit is contained in:
1 parent
f91ccfcffb
commit
0604308d8a
8 files changed
+174
No files matched your search
@@ -0,0 +1,120 @@
|
||||
using System.Reflection;
|
||||
using BepInEx;
|
||||
using CommonAPI.Systems;
|
||||
using UnityEngine;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.ModFeatures;
|
||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||
|
||||
namespace LiveStreamAssist;
|
||||
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
[BepInDependency(UXAssist.PluginInfo.PLUGIN_GUID)]
|
||||
public class LiveStreamAssist : BaseUnityPlugin
|
||||
{
|
||||
public new static readonly BepInEx.Logging.ManualLogSource Logger =
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
I18N.Init();
|
||||
I18N.Add("KEYToggleLiveStreamAssist", "[LSA] Toggle live-stream statistics assist", "[LSA] \u5207\u6362\u76f4\u64ad\u7edf\u8ba1\u8f85\u52a9");
|
||||
ModFeatureRegistry.Discover(Assembly.GetExecutingAssembly());
|
||||
I18N.Apply();
|
||||
}
|
||||
}
|
||||
|
||||
[ModFeature("LiveStreamAssist", Order = 50)]
|
||||
internal static class LiveStreamAssistFeature
|
||||
{
|
||||
private const float MinIntervalSeconds = 15f;
|
||||
private const float MaxIntervalSeconds = 30f;
|
||||
private static PressKeyBind _toggleKey;
|
||||
private static bool _enabled;
|
||||
private static float _nextSwitchAt;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_toggleKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
|
||||
{
|
||||
key = new CombineKey((int)KeyCode.F8, CombineKey.CTRL_COMB, ECombineKeyAction.OnceClick, false),
|
||||
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING |
|
||||
KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND,
|
||||
name = "ToggleLiveStreamAssist",
|
||||
canOverride = true
|
||||
});
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
GameLogicProc.OnGameEnd += Stop;
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
GameLogicProc.OnGameEnd -= Stop;
|
||||
Stop();
|
||||
}
|
||||
|
||||
public static void OnInputUpdate()
|
||||
{
|
||||
if (!_toggleKey.keyValue) return;
|
||||
|
||||
if (_enabled)
|
||||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
TryStart();
|
||||
}
|
||||
|
||||
public static void OnUpdate()
|
||||
{
|
||||
if (!_enabled) return;
|
||||
|
||||
var statWindow = GetStatWindow();
|
||||
if (statWindow == null || !statWindow.active)
|
||||
{
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.unscaledTime < _nextSwitchAt) return;
|
||||
|
||||
var nextTab = statWindow.tabIndex == 1 ? 4 : 1;
|
||||
statWindow.OnTabButtonClick(nextTab);
|
||||
ScheduleNextSwitch();
|
||||
}
|
||||
|
||||
private static void TryStart()
|
||||
{
|
||||
var statWindow = GetStatWindow();
|
||||
if (statWindow == null || !GameMain.isRunning) return;
|
||||
|
||||
UIRoot.instance.uiGame.OpenProductionWindow();
|
||||
statWindow = GetStatWindow();
|
||||
if (statWindow == null || !statWindow.active) return;
|
||||
|
||||
statWindow.OnTabButtonClick(1);
|
||||
_enabled = true;
|
||||
ScheduleNextSwitch();
|
||||
}
|
||||
|
||||
private static UIStatisticsWindow GetStatWindow()
|
||||
{
|
||||
if (UIRoot.instance == null || UIRoot.instance.uiGame == null) return null;
|
||||
return UIRoot.instance.uiGame.statWindow;
|
||||
}
|
||||
|
||||
private static void ScheduleNextSwitch()
|
||||
{
|
||||
_nextSwitchAt = Time.unscaledTime + Random.Range(MinIntervalSeconds, MaxIntervalSeconds);
|
||||
}
|
||||
|
||||
private static void Stop()
|
||||
{
|
||||
_enabled = false;
|
||||
_nextSwitchAt = 0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<BepInExPluginGuid>org.soardev.livestreamassist</BepInExPluginGuid>
|
||||
<Description>DSP MOD - LiveStreamAssist</Description>
|
||||
<Version>1.0.0</Version>
|
||||
<PackageId>LiveStreamAssist</PackageId>
|
||||
<RootNamespace>LiveStreamAssist</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UXAssist\UXAssist.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
# LiveStreamAssist
|
||||
|
||||
Keeps the Dyson Sphere Program statistics window active during a live stream by switching between the Production Statistics and Dyson Sphere tabs at a random interval.
|
||||
|
||||
## Usage
|
||||
|
||||
- Press Ctrl+F8 to start or stop the assist. The key can be changed in the game's keyboard settings.
|
||||
- Starting the assist opens the statistics window and selects Production Statistics.
|
||||
- The mod switches between Production Statistics and Dyson Sphere every 15 to 30 seconds.
|
||||
- Closing the statistics window stops the assist automatically.
|
||||
|
||||
The mod requires UXAssist.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "LiveStreamAssist",
|
||||
"version_number": "1.0.0",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/LiveStreamAssist",
|
||||
"description": "Keep the statistics window active for live streams",
|
||||
"dependencies": [
|
||||
"xiaoye97-BepInEx-5.4.17",
|
||||
"soarqin-UXAssist-1.5.9"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user