mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2026-02-04 14:12:18 +08:00
add XianTu
This commit is contained in:
@@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net472</TargetFramework>
|
|
||||||
<AssemblyName>AutoPilot</AssemblyName>
|
|
||||||
<BepInExPluginGuid>org.soardev.AutoPilot</BepInExPluginGuid>
|
|
||||||
<Description>DSP MOD - AutoPilot</Description>
|
|
||||||
<Version>0.1.0</Version>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
<LangVersion>latest</LangVersion>
|
|
||||||
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
|
||||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
|
||||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
|
||||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
|
||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\CruiseAssist\CruiseAssist.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
|
||||||
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip
zip -9 -j package/$(ProjectName)-$(Version).zip $(TargetPath) package/icon.png package/manifest.json README.md" />
|
|
||||||
</Target>
|
|
||||||
</Project>
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
using AutoPilot.Commons;
|
|
||||||
using AutoPilot.UI;
|
|
||||||
using BepInEx.Configuration;
|
|
||||||
|
|
||||||
namespace AutoPilot;
|
|
||||||
|
|
||||||
internal class AutoPilotConfigManager : ConfigManager
|
|
||||||
{
|
|
||||||
public static void Init(ConfigFile config)
|
|
||||||
{
|
|
||||||
ConfigManager.Init<AutoPilotConfigManager>(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void CheckConfigImplements(Step step)
|
|
||||||
{
|
|
||||||
var ok = false;
|
|
||||||
switch (step)
|
|
||||||
{
|
|
||||||
case Step.Awake:
|
|
||||||
{
|
|
||||||
var configEntry = Bind("Base", "ModVersion", "0.0.4", "Don't change.");
|
|
||||||
configEntry.Value = "0.0.4";
|
|
||||||
ok = true;
|
|
||||||
goto case Step.GameMainBegin;
|
|
||||||
}
|
|
||||||
case Step.GameMainBegin:
|
|
||||||
{
|
|
||||||
AutoPilotDebugUI.Show = Bind("Debug", "DebugWindowShow", false).Value;
|
|
||||||
AutoPilotPlugin.Conf.MinEnergyPer = Bind("Setting", "MinEnergyPer", 20).Value;
|
|
||||||
AutoPilotPlugin.Conf.MaxSpeed = Bind("Setting", "MaxSpeed", 2000).Value;
|
|
||||||
AutoPilotPlugin.Conf.WarpMinRangeAu = Bind("Setting", "WarpMinRangeAU", 2).Value;
|
|
||||||
AutoPilotPlugin.Conf.SpeedToWarp = Bind("Setting", "WarpSpeed", 1200).Value;
|
|
||||||
AutoPilotPlugin.Conf.LocalWarpFlag = Bind("Setting", "LocalWarp", false).Value;
|
|
||||||
AutoPilotPlugin.Conf.AutoStartFlag = Bind("Setting", "AutoStart", true).Value;
|
|
||||||
AutoPilotPlugin.Conf.MainWindowJoinFlag = Bind("Setting", "MainWindowJoin", true).Value;
|
|
||||||
for (var i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
AutoPilotMainUI.Rect[i].x = Bind("State", $"MainWindow{i}Left", 100).Value;
|
|
||||||
AutoPilotMainUI.Rect[i].y = Bind("State", $"MainWindow{i}Top", 100).Value;
|
|
||||||
AutoPilotConfigUI.Rect[i].x = Bind("State", $"ConfigWindow{i}Left", 100).Value;
|
|
||||||
AutoPilotConfigUI.Rect[i].y = Bind("State", $"ConfigWindow{i}Top", 100).Value;
|
|
||||||
}
|
|
||||||
AutoPilotDebugUI.Rect.x = Bind("State", "DebugWindowLeft", 100).Value;
|
|
||||||
AutoPilotDebugUI.Rect.y = Bind("State", "DebugWindowTop", 100).Value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Step.State:
|
|
||||||
{
|
|
||||||
LogManager.LogInfo("check state.");
|
|
||||||
ok |= UpdateEntry("Setting", "MinEnergyPer", AutoPilotPlugin.Conf.MinEnergyPer);
|
|
||||||
ok |= UpdateEntry("Setting", "MaxSpeed", AutoPilotPlugin.Conf.MaxSpeed);
|
|
||||||
ok |= UpdateEntry("Setting", "WarpMinRangeAU", AutoPilotPlugin.Conf.WarpMinRangeAu);
|
|
||||||
ok |= UpdateEntry("Setting", "WarpSpeed", AutoPilotPlugin.Conf.SpeedToWarp);
|
|
||||||
ok |= UpdateEntry("Setting", "LocalWarp", AutoPilotPlugin.Conf.LocalWarpFlag);
|
|
||||||
ok |= UpdateEntry("Setting", "AutoStart", AutoPilotPlugin.Conf.AutoStartFlag);
|
|
||||||
ok |= UpdateEntry("Setting", "MainWindowJoin", AutoPilotPlugin.Conf.MainWindowJoinFlag);
|
|
||||||
for (var j = 0; j < 2; j++)
|
|
||||||
{
|
|
||||||
ok |= UpdateEntry("State", $"MainWindow{j}Left", (int)AutoPilotMainUI.Rect[j].x);
|
|
||||||
ok |= UpdateEntry("State", $"MainWindow{j}Top", (int)AutoPilotMainUI.Rect[j].y);
|
|
||||||
ok |= UpdateEntry("State", $"ConfigWindow{j}Left", (int)AutoPilotConfigUI.Rect[j].x);
|
|
||||||
ok |= UpdateEntry("State", $"ConfigWindow{j}Top", (int)AutoPilotConfigUI.Rect[j].y);
|
|
||||||
}
|
|
||||||
ok |= UpdateEntry("State", "DebugWindowLeft", (int)AutoPilotDebugUI.Rect.x);
|
|
||||||
ok |= UpdateEntry("State", "DebugWindowTop", (int)AutoPilotDebugUI.Rect.y);
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = long.MaxValue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Step.UniverseGenCreateGalaxy:
|
|
||||||
case Step.ChangeSeed:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,243 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using AutoPilot.Commons;
|
|
||||||
using AutoPilot.Enums;
|
|
||||||
using AutoPilot.UI;
|
|
||||||
using CruiseAssist;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AutoPilot;
|
|
||||||
|
|
||||||
internal class AutoPilotExtension : ICruiseAssistExtensionAPI
|
|
||||||
{
|
|
||||||
public void CheckConfig(string step)
|
|
||||||
{
|
|
||||||
EnumUtils.TryParse(step, out ConfigManager.Step step2);
|
|
||||||
ConfigManager.CheckConfig(step2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetTargetAstroId(int astroId)
|
|
||||||
{
|
|
||||||
AutoPilotPlugin.State = AutoPilotPlugin.Conf.AutoStartFlag ? AutoPilotState.Active : AutoPilotState.Inactive;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OperateWalk(PlayerMove_Walk __instance)
|
|
||||||
{
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var player = __instance.player;
|
|
||||||
var mecha = player.mecha;
|
|
||||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
|
||||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
|
||||||
AutoPilotPlugin.LeavePlanet = true;
|
|
||||||
AutoPilotPlugin.SpeedUp = false;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
|
|
||||||
{
|
|
||||||
player.controller.universalGravity = VectorLF3.zero;
|
|
||||||
player.controller.localGravity = VectorLF3.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
__instance.controller.input0.z = 1f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OperateDrift(PlayerMove_Drift __instance)
|
|
||||||
{
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var player = __instance.player;
|
|
||||||
var mecha = player.mecha;
|
|
||||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
|
||||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
|
||||||
AutoPilotPlugin.LeavePlanet = true;
|
|
||||||
AutoPilotPlugin.SpeedUp = false;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
|
|
||||||
{
|
|
||||||
player.controller.universalGravity = VectorLF3.zero;
|
|
||||||
player.controller.localGravity = VectorLF3.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
__instance.controller.input0.z = 1f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OperateFly(PlayerMove_Fly __instance)
|
|
||||||
{
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var player = __instance.player;
|
|
||||||
var mecha = player.mecha;
|
|
||||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
|
||||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
|
||||||
AutoPilotPlugin.LeavePlanet = true;
|
|
||||||
AutoPilotPlugin.SpeedUp = false;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
|
|
||||||
{
|
|
||||||
player.controller.universalGravity = VectorLF3.zero;
|
|
||||||
player.controller.localGravity = VectorLF3.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
var controller = __instance.controller;
|
|
||||||
controller.input0.y += 1f;
|
|
||||||
controller.input1.y += 1f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OperateSail(PlayerMove_Sail __instance)
|
|
||||||
{
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var player = __instance.player;
|
|
||||||
var mecha = player.mecha;
|
|
||||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
|
||||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
|
||||||
AutoPilotPlugin.LeavePlanet = false;
|
|
||||||
AutoPilotPlugin.SpeedUp = false;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
if (player.warping)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoPilotPlugin.EnergyPer < AutoPilotPlugin.Conf.MinEnergyPer)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
|
|
||||||
{
|
|
||||||
player.controller.universalGravity = VectorLF3.zero;
|
|
||||||
player.controller.localGravity = VectorLF3.zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
var speed = player.controller.actionSail.visual_uvel.magnitude;
|
|
||||||
if (speed < AutoPilotPlugin.Conf.MaxSpeed)
|
|
||||||
{
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = true;
|
|
||||||
AutoPilotPlugin.SpeedUp = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GameMain.localPlanet == null)
|
|
||||||
{
|
|
||||||
if (!AutoPilotPlugin.Conf.LocalWarpFlag && GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id == GameMain.localStar.id) return false;
|
|
||||||
if (!(AutoPilotPlugin.Conf.WarpMinRangeAu * 40000.0 <= CruiseAssistPlugin.TargetRange) || !(AutoPilotPlugin.Conf.SpeedToWarp <= speed) ||
|
|
||||||
1 > AutoPilotPlugin.WarperCount) return false;
|
|
||||||
if (!(mecha.coreEnergy > mecha.warpStartPowerPerSpeed * mecha.maxWarpSpeed)) return false;
|
|
||||||
if (!mecha.UseWarper()) return false;
|
|
||||||
player.warpCommand = true;
|
|
||||||
VFAudio.Create("warp-begin", player.transform, Vector3.zero, true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
speed = player.uVelocity.magnitude;
|
|
||||||
var vec = player.uPosition - GameMain.localPlanet.uPosition;
|
|
||||||
if (340.0 < speed && Math.Max(GameMain.localPlanet.realRadius, 900f) < vec.magnitude - GameMain.localPlanet.realRadius)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorLF3 result;
|
|
||||||
if (Vector3.Angle(player.uPosition - GameMain.localPlanet.uPosition, CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition) > 90f)
|
|
||||||
{
|
|
||||||
AutoPilotPlugin.LeavePlanet = true;
|
|
||||||
result = vec;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = CruiseAssistPlugin.TargetUPos - player.uPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
var angle = Vector3.Angle(result, player.uVelocity);
|
|
||||||
if (angle > 1.6f)
|
|
||||||
{
|
|
||||||
player.uVelocity = Vector3.Slerp(player.uVelocity, result.normalized * Math.Min(speed, 320.0), 1.6f / Mathf.Max(10f, angle));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.uVelocity = result.normalized * Math.Min(speed, 320.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetInactive()
|
|
||||||
{
|
|
||||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CancelOperate()
|
|
||||||
{
|
|
||||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
|
||||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnGUI()
|
|
||||||
{
|
|
||||||
if (!_initialized)
|
|
||||||
{
|
|
||||||
_initialized = true;
|
|
||||||
AutoPilotMainUI.OnInit();
|
|
||||||
AutoPilotConfigUI.OnInit();
|
|
||||||
AutoPilotDebugUI.OnInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
|
|
||||||
AutoPilotMainUI.OnGUI();
|
|
||||||
if (AutoPilotConfigUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
AutoPilotConfigUI.OnGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoPilotDebugUI.Show)
|
|
||||||
{
|
|
||||||
AutoPilotDebugUI.OnGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
var resetInput = ResetInput(AutoPilotMainUI.Rect[CruiseAssistMainUI.WIdx], scale);
|
|
||||||
if (!resetInput && AutoPilotConfigUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
resetInput = ResetInput(AutoPilotConfigUI.Rect[CruiseAssistMainUI.WIdx], scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resetInput && AutoPilotDebugUI.Show)
|
|
||||||
{
|
|
||||||
ResetInput(AutoPilotDebugUI.Rect, scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ResetInput(Rect rect, float scale)
|
|
||||||
{
|
|
||||||
var xMin = rect.xMin * scale;
|
|
||||||
var xMax = rect.xMax * scale;
|
|
||||||
var yMin = rect.yMin * scale;
|
|
||||||
var yMax = rect.yMax * scale;
|
|
||||||
var x = Input.mousePosition.x;
|
|
||||||
var num5 = Screen.height - Input.mousePosition.y;
|
|
||||||
if (!(xMin <= x) || !(x <= xMax) || !(yMin <= num5) || !(num5 <= yMax)) return false;
|
|
||||||
if (!MouseButtonArray.Any(Input.GetMouseButton) && Input.mouseScrollDelta.y == 0f) return false;
|
|
||||||
Input.ResetInputAxes();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _initialized;
|
|
||||||
private static readonly int[] MouseButtonArray = [0, 1, 2];
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using AutoPilot.Commons;
|
|
||||||
using AutoPilot.Enums;
|
|
||||||
using AutoPilot.Patches;
|
|
||||||
using BepInEx;
|
|
||||||
using BepInEx.Configuration;
|
|
||||||
using CruiseAssist;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace AutoPilot;
|
|
||||||
|
|
||||||
[BepInDependency("org.soardev.CruiseAssist")]
|
|
||||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
|
||||||
public class AutoPilotPlugin : BaseUnityPlugin
|
|
||||||
{
|
|
||||||
public void Awake()
|
|
||||||
{
|
|
||||||
LogManager.Logger = Logger;
|
|
||||||
AutoPilotConfigManager.Init(new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, "tanu.AutoPilot.cfg"), false, Info.Metadata));
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.Awake);
|
|
||||||
_harmony = new Harmony("org.soardev.AutoPilot.Patch");
|
|
||||||
_harmony.PatchAll(typeof(Patch_VFInput));
|
|
||||||
_harmony.PatchAll(typeof(UI.Strings));
|
|
||||||
CruiseAssistPlugin.RegistExtension(new AutoPilotExtension());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnDestroy()
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.UnregistExtension(typeof(AutoPilotExtension));
|
|
||||||
_harmony.UnpatchSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EnergyPer = 0.0;
|
|
||||||
|
|
||||||
public static int WarperCount = 0;
|
|
||||||
|
|
||||||
public static bool LeavePlanet = false;
|
|
||||||
|
|
||||||
public static bool SpeedUp = false;
|
|
||||||
|
|
||||||
public static AutoPilotState State = AutoPilotState.Inactive;
|
|
||||||
|
|
||||||
public static bool InputSailSpeedUp = false;
|
|
||||||
|
|
||||||
private Harmony _harmony;
|
|
||||||
|
|
||||||
public static class Conf
|
|
||||||
{
|
|
||||||
public static int MinEnergyPer = 20;
|
|
||||||
|
|
||||||
public static int MaxSpeed = 2000;
|
|
||||||
|
|
||||||
public static int WarpMinRangeAu = 2;
|
|
||||||
|
|
||||||
public static int SpeedToWarp = 1200;
|
|
||||||
|
|
||||||
public static bool LocalWarpFlag = false;
|
|
||||||
|
|
||||||
public static bool AutoStartFlag = true;
|
|
||||||
|
|
||||||
public static bool IgnoreGravityFlag = true;
|
|
||||||
|
|
||||||
public static bool MainWindowJoinFlag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BepInEx.Configuration;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace AutoPilot.Commons;
|
|
||||||
|
|
||||||
internal abstract class ConfigManager
|
|
||||||
{
|
|
||||||
private static ConfigFile Config { get; set; }
|
|
||||||
|
|
||||||
protected static void Init<T>(ConfigFile config) where T: ConfigManager, new()
|
|
||||||
{
|
|
||||||
_instance = new T();
|
|
||||||
Config = config;
|
|
||||||
Config.SaveOnConfigSet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CheckConfig(Step step)
|
|
||||||
{
|
|
||||||
_instance.CheckConfigImplements(step);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void CheckConfigImplements(Step step);
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
|
|
||||||
{
|
|
||||||
return Config.Bind(configDefinition, defaultValue, configDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
|
|
||||||
{
|
|
||||||
return Config.Bind(section, key, defaultValue, configDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
|
|
||||||
{
|
|
||||||
return Config.Bind(section, key, defaultValue, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> GetEntry<T>(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
ConfigEntry<T> configEntry;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
configEntry = (ConfigEntry<T>)Config[configDefinition];
|
|
||||||
}
|
|
||||||
catch (KeyNotFoundException ex)
|
|
||||||
{
|
|
||||||
LogManager.LogError($"{ex.GetType()}: configDefinition={configDefinition}");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return configEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> GetEntry<T>(string section, string key)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(new ConfigDefinition(section, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T GetValue<T>(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(configDefinition).Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T GetValue<T>(string section, string key)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(section, key).Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ContainsKey(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
return Config.ContainsKey(configDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ContainsKey(string section, string key)
|
|
||||||
{
|
|
||||||
return Config.ContainsKey(new ConfigDefinition(section, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool UpdateEntry<T>(string section, string key, T value) where T : IComparable
|
|
||||||
{
|
|
||||||
var entry = GetEntry<T>(section, key);
|
|
||||||
var value2 = entry.Value;
|
|
||||||
var flag = value2.CompareTo(value) == 0;
|
|
||||||
bool flag2;
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
flag2 = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry.Value = value;
|
|
||||||
flag2 = true;
|
|
||||||
}
|
|
||||||
return flag2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool RemoveEntry(ConfigDefinition key)
|
|
||||||
{
|
|
||||||
return Config.Remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dictionary<ConfigDefinition, string> GetOrphanedEntries()
|
|
||||||
{
|
|
||||||
var flag = _orphanedEntries == null;
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
_orphanedEntries = Traverse.Create(Config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries").Value;
|
|
||||||
}
|
|
||||||
return _orphanedEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Migration<T>(string newSection, string newKey, T defaultValue, string oldSection, string oldKey)
|
|
||||||
{
|
|
||||||
GetOrphanedEntries();
|
|
||||||
var configDefinition = new ConfigDefinition(oldSection, oldKey);
|
|
||||||
var flag = _orphanedEntries.TryGetValue(configDefinition, out var text);
|
|
||||||
if (!flag) return;
|
|
||||||
Bind(newSection, newKey, defaultValue).SetSerializedValue(text);
|
|
||||||
_orphanedEntries.Remove(configDefinition);
|
|
||||||
LogManager.LogInfo(string.Concat("migration ", oldSection, ".", oldKey, "(", text, ") => ", newSection, ".", newKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Save(bool clearOrphanedEntries = false)
|
|
||||||
{
|
|
||||||
if (clearOrphanedEntries)
|
|
||||||
{
|
|
||||||
GetOrphanedEntries().Clear();
|
|
||||||
}
|
|
||||||
Config.Save();
|
|
||||||
LogManager.LogInfo("save config.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Clear()
|
|
||||||
{
|
|
||||||
Config.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Reload()
|
|
||||||
{
|
|
||||||
Config.Reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ConfigManager _instance;
|
|
||||||
|
|
||||||
private static Dictionary<ConfigDefinition, string> _orphanedEntries;
|
|
||||||
|
|
||||||
public enum Step
|
|
||||||
{
|
|
||||||
Awake,
|
|
||||||
GameMainBegin,
|
|
||||||
UniverseGenCreateGalaxy,
|
|
||||||
State,
|
|
||||||
ChangeSeed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace AutoPilot.Commons;
|
|
||||||
|
|
||||||
internal static class EnumUtils
|
|
||||||
{
|
|
||||||
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct
|
|
||||||
{
|
|
||||||
if (value == null || !Enum.IsDefined(typeof(TEnum), value))
|
|
||||||
{
|
|
||||||
result = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
result = (TEnum)Enum.Parse(typeof(TEnum), value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using BepInEx.Logging;
|
|
||||||
|
|
||||||
namespace AutoPilot.Commons;
|
|
||||||
|
|
||||||
internal static class LogManager
|
|
||||||
{
|
|
||||||
public static ManualLogSource Logger { private get; set; }
|
|
||||||
|
|
||||||
public static void LogInfo(object data)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogInfo(MethodBase method)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(method.DeclaringType.Name + "." + method.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogInfo(MethodBase method, object data)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError(object data)
|
|
||||||
{
|
|
||||||
Logger.LogError(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError(MethodBase method, object data)
|
|
||||||
{
|
|
||||||
Logger.LogError(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace AutoPilot.Enums;
|
|
||||||
|
|
||||||
public enum AutoPilotState
|
|
||||||
{
|
|
||||||
Active,
|
|
||||||
Inactive
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using AutoPilot.Enums;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace AutoPilot.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(VFInput))]
|
|
||||||
internal class Patch_VFInput
|
|
||||||
{
|
|
||||||
[HarmonyPatch("_sailSpeedUp", MethodType.Getter)]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
public static void SailSpeedUp_Postfix(ref bool __result)
|
|
||||||
{
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive) return;
|
|
||||||
if (AutoPilotPlugin.InputSailSpeedUp)
|
|
||||||
__result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# AutoPilot
|
|
||||||
|
|
||||||
## What's this?
|
|
||||||
|
|
||||||
Auto pilot to a planet or star system.
|
|
||||||
|
|
||||||
This mod is a CruiseAssist extension.
|
|
||||||
|
|
||||||
Original mod: [AutoPilot](https://thunderstore.io/package/tanu/AutoPilot/)
|
|
||||||
It was discontinued, so I made a fork of it.
|
|
||||||
|
|
||||||
## CHANGE LOG
|
|
||||||
|
|
||||||
### 0.1.0
|
|
||||||
* Cleanup from disassmbly codes of AutoPilot 0.0.4.
|
|
||||||
* Optimization to codes.
|
|
||||||
* Add a simple localization implementation.
|
|
||||||
|
|
||||||
### Origianal AutoPilot Changelogs
|
|
||||||
Check [original mod](https://thunderstore.io/c/dyson-sphere-program/p/tanu/AutoPilot/) for details
|
|
||||||
@@ -1,184 +0,0 @@
|
|||||||
using CruiseAssist.UI;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AutoPilot.UI;
|
|
||||||
|
|
||||||
internal static class AutoPilotConfigUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
_labelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fontSize = 12,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_textFieldStyle = new GUIStyle(CruiseAssistMainUI.BaseTextFieldStyle)
|
|
||||||
{
|
|
||||||
fontSize = 12,
|
|
||||||
fixedWidth = 60f
|
|
||||||
};
|
|
||||||
_toggleStyle = new GUIStyle(CruiseAssistMainUI.BaseToggleStyle)
|
|
||||||
{
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.LowerLeft
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
_wIdx = CruiseAssistMainUI.WIdx;
|
|
||||||
Rect[_wIdx] = GUILayout.Window(99031292, Rect[_wIdx], WindowFunction, "AutoPilot - " + Strings.Get(0), CruiseAssistMainUI.WindowStyle);
|
|
||||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
if (Screen.width / scale < Rect[_wIdx].xMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = Screen.width / scale - Rect[_wIdx].width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].x < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.height / scale < Rect[_wIdx].yMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = Screen.height / scale - Rect[_wIdx].height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].y < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LastCheckWindowLeft[_wIdx] != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect[_wIdx].x != LastCheckWindowLeft[_wIdx] || Rect[_wIdx].y != LastCheckWindowTop[_wIdx])
|
|
||||||
{
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
_labelStyle.fixedHeight = 20f;
|
|
||||||
_textFieldStyle.alignment = TextAnchor.MiddleRight;
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
_labelStyle.fixedWidth = 240f;
|
|
||||||
GUILayout.Label(Strings.Get(15), _labelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
SetValue(ref TempMinEnergyPer, GUILayout.TextField(TempMinEnergyPer, _textFieldStyle), 0, 100, ref AutoPilotPlugin.Conf.MinEnergyPer);
|
|
||||||
_labelStyle.fixedWidth = 20f;
|
|
||||||
GUILayout.Label("%", _labelStyle);
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
_labelStyle.fixedWidth = 240f;
|
|
||||||
GUILayout.Label(Strings.Get(16), _labelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
SetValue(ref TempMaxSpeed, GUILayout.TextField(TempMaxSpeed, _textFieldStyle), 0, 2000, ref AutoPilotPlugin.Conf.MaxSpeed);
|
|
||||||
_labelStyle.fixedWidth = 20f;
|
|
||||||
GUILayout.Label("m/s", _labelStyle);
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
_labelStyle.fixedWidth = 240f;
|
|
||||||
GUILayout.Label(Strings.Get(17), _labelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
SetValue(ref TempWarpMinRangeAu, GUILayout.TextField(TempWarpMinRangeAu, _textFieldStyle), 1, 60, ref AutoPilotPlugin.Conf.WarpMinRangeAu);
|
|
||||||
_labelStyle.fixedWidth = 20f;
|
|
||||||
GUILayout.Label("AU", _labelStyle);
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
_labelStyle.fixedWidth = 240f;
|
|
||||||
GUILayout.Label(Strings.Get(18), _labelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
SetValue(ref TempSpeedToWarp, GUILayout.TextField(TempSpeedToWarp, _textFieldStyle), 0, 2000, ref AutoPilotPlugin.Conf.SpeedToWarp);
|
|
||||||
_labelStyle.fixedWidth = 20f;
|
|
||||||
GUILayout.Label("m/s", _labelStyle);
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUI.changed = false;
|
|
||||||
AutoPilotPlugin.Conf.LocalWarpFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.LocalWarpFlag, Strings.Get(19), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
AutoPilotPlugin.Conf.AutoStartFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.AutoStartFlag, Strings.Get(20), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
AutoPilotPlugin.Conf.MainWindowJoinFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.MainWindowJoinFlag, Strings.Get(21), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
if (GUI.Button(new Rect(Rect[_wIdx].width - 16f, 1f, 16f, 16f), "", CruiseAssistMainUI.CloseButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool SetValue(ref string temp, string instr, int min, int max, ref int value)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(instr))
|
|
||||||
{
|
|
||||||
temp = string.Empty;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!int.TryParse(instr, out var num)) return false;
|
|
||||||
if (num < min)
|
|
||||||
{
|
|
||||||
num = min;
|
|
||||||
}
|
|
||||||
else if (max < num)
|
|
||||||
{
|
|
||||||
num = max;
|
|
||||||
}
|
|
||||||
value = num;
|
|
||||||
temp = value.ToString();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GUIStyle _labelStyle;
|
|
||||||
private static GUIStyle _textFieldStyle;
|
|
||||||
private static GUIStyle _toggleStyle;
|
|
||||||
|
|
||||||
private static int _wIdx;
|
|
||||||
|
|
||||||
public const float WindowWidth = 400f;
|
|
||||||
|
|
||||||
public const float WindowHeight = 400f;
|
|
||||||
|
|
||||||
public static readonly bool[] Show = new bool[2];
|
|
||||||
|
|
||||||
public static readonly Rect[] Rect =
|
|
||||||
[
|
|
||||||
new(0f, 0f, 400f, 400f),
|
|
||||||
new(0f, 0f, 400f, 400f)
|
|
||||||
];
|
|
||||||
|
|
||||||
private static readonly float[] LastCheckWindowLeft = [float.MinValue, float.MinValue];
|
|
||||||
|
|
||||||
private static readonly float[] LastCheckWindowTop = [float.MinValue, float.MinValue];
|
|
||||||
|
|
||||||
public static string TempMinEnergyPer;
|
|
||||||
|
|
||||||
public static string TempMaxSpeed;
|
|
||||||
|
|
||||||
public static string TempWarpMinRangeAu;
|
|
||||||
|
|
||||||
public static string TempSpeedToWarp;
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
using AutoPilot.Commons;
|
|
||||||
using CruiseAssist;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AutoPilot.UI;
|
|
||||||
|
|
||||||
internal static class AutoPilotDebugUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
_windowStyle = new GUIStyle(GUI.skin.window)
|
|
||||||
{
|
|
||||||
fontSize = 11
|
|
||||||
};
|
|
||||||
_labelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_toggleStyle = new GUIStyle(GUI.skin.toggle)
|
|
||||||
{
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.LowerLeft
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
Rect = GUILayout.Window(99031293, Rect, WindowFunction, "AutoPilot - Debug", _windowStyle);
|
|
||||||
|
|
||||||
if (Screen.width < Rect.xMax)
|
|
||||||
{
|
|
||||||
Rect.x = Screen.width - Rect.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect.x < 0f)
|
|
||||||
{
|
|
||||||
Rect.x = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.height < Rect.yMax)
|
|
||||||
{
|
|
||||||
Rect.y = Screen.height - Rect.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect.y < 0f)
|
|
||||||
{
|
|
||||||
Rect.y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_lastCheckWindowLeft != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect.x != _lastCheckWindowLeft || Rect.y != _lastCheckWindowTop)
|
|
||||||
{
|
|
||||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_lastCheckWindowLeft = Rect.x;
|
|
||||||
_lastCheckWindowTop = Rect.y;
|
|
||||||
if (AutoPilotMainUI.NextCheckGameTick <= GameMain.gameTick)
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
_scrollPos = GUILayout.BeginScrollView(_scrollPos);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.uPosition={GameMain.mainPlayer.uPosition}", _labelStyle);
|
|
||||||
if (GameMain.localPlanet != null && CruiseAssistPlugin.TargetUPos != VectorLF3.zero)
|
|
||||||
{
|
|
||||||
var mainPlayer = GameMain.mainPlayer;
|
|
||||||
var targetUPos = CruiseAssistPlugin.TargetUPos;
|
|
||||||
var magnitude = (targetUPos - mainPlayer.uPosition).magnitude;
|
|
||||||
var magnitude2 = (targetUPos - GameMain.localPlanet.uPosition).magnitude;
|
|
||||||
var vectorLF = mainPlayer.uPosition - GameMain.localPlanet.uPosition;
|
|
||||||
var vectorLF2 = CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition;
|
|
||||||
GUILayout.Label("range1=" + RangeToString(magnitude), _labelStyle);
|
|
||||||
GUILayout.Label("range2=" + RangeToString(magnitude2), _labelStyle);
|
|
||||||
GUILayout.Label($"range1>range2={magnitude > magnitude2}", _labelStyle);
|
|
||||||
GUILayout.Label($"angle={Vector3.Angle(vectorLF, vectorLF2)}", _labelStyle);
|
|
||||||
}
|
|
||||||
var mecha = GameMain.mainPlayer.mecha;
|
|
||||||
GUILayout.Label($"mecha.coreEnergy={mecha.coreEnergy}", _labelStyle);
|
|
||||||
GUILayout.Label($"mecha.coreEnergyCap={mecha.coreEnergyCap}", _labelStyle);
|
|
||||||
var energyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
|
||||||
GUILayout.Label($"energyPer={energyPer}", _labelStyle);
|
|
||||||
var speed = GameMain.mainPlayer.controller.actionSail.visual_uvel.magnitude;
|
|
||||||
GUILayout.Label("spped=" + RangeToString(speed), _labelStyle);
|
|
||||||
var movementStateInFrame = GameMain.mainPlayer.controller.movementStateInFrame;
|
|
||||||
GUILayout.Label($"movementStateInFrame={movementStateInFrame}", _labelStyle);
|
|
||||||
GUI.changed = false;
|
|
||||||
AutoPilotPlugin.Conf.IgnoreGravityFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.IgnoreGravityFlag, "Ignore gravity.", _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
}
|
|
||||||
GUILayout.EndScrollView();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string RangeToString(double range)
|
|
||||||
{
|
|
||||||
if (range < 10000.0)
|
|
||||||
{
|
|
||||||
return (int)(range + 0.5) + "m ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (range < 600000.0)
|
|
||||||
{
|
|
||||||
return (range / 40000.0).ToString("0.00") + "AU";
|
|
||||||
}
|
|
||||||
|
|
||||||
return (range / 2400000.0).ToString("0.00") + "Ly";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GUIStyle _windowStyle;
|
|
||||||
private static GUIStyle _labelStyle;
|
|
||||||
private static GUIStyle _toggleStyle;
|
|
||||||
|
|
||||||
public static bool Show = false;
|
|
||||||
|
|
||||||
public static Rect Rect = new(0f, 0f, 400f, 400f);
|
|
||||||
|
|
||||||
private static float _lastCheckWindowLeft = float.MinValue;
|
|
||||||
|
|
||||||
private static float _lastCheckWindowTop = float.MinValue;
|
|
||||||
|
|
||||||
private static Vector2 _scrollPos = Vector2.zero;
|
|
||||||
}
|
|
||||||
@@ -1,280 +0,0 @@
|
|||||||
using AutoPilot.Commons;
|
|
||||||
using AutoPilot.Enums;
|
|
||||||
using CruiseAssist;
|
|
||||||
using CruiseAssist.Enums;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AutoPilot.UI;
|
|
||||||
|
|
||||||
internal static class AutoPilotMainUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
_windowStyle = new GUIStyle(CruiseAssistMainUI.WindowStyle)
|
|
||||||
{
|
|
||||||
fontSize = 11
|
|
||||||
};
|
|
||||||
|
|
||||||
_baseLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
|
|
||||||
_highlightedLabelStyle = new GUIStyle(_baseLabelStyle)
|
|
||||||
{
|
|
||||||
normal = { textColor = Color.cyan }
|
|
||||||
};
|
|
||||||
|
|
||||||
_ngLabelStyle = new GUIStyle(_baseLabelStyle)
|
|
||||||
{
|
|
||||||
normal = { textColor = Color.red }
|
|
||||||
};
|
|
||||||
|
|
||||||
_labelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 160f,
|
|
||||||
fixedHeight = 32f,
|
|
||||||
fontSize = 14,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
|
|
||||||
_buttonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 55f,
|
|
||||||
fixedHeight = 18f,
|
|
||||||
fontSize = 11,
|
|
||||||
alignment = TextAnchor.MiddleCenter
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
_wIdx = CruiseAssistMainUI.WIdx;
|
|
||||||
var viewMode = CruiseAssistMainUI.ViewMode;
|
|
||||||
if (viewMode != CruiseAssistMainUIViewMode.Full)
|
|
||||||
{
|
|
||||||
if (viewMode == CruiseAssistMainUIViewMode.Mini)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].width = CruiseAssistMainUI.Rect[_wIdx].width;
|
|
||||||
Rect[_wIdx].height = 70f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Rect[_wIdx].width = CruiseAssistMainUI.Rect[_wIdx].width;
|
|
||||||
Rect[_wIdx].height = 150f;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect[_wIdx] = GUILayout.Window(99031291, Rect[_wIdx], WindowFunction, "AutoPilot", _windowStyle);
|
|
||||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
if (AutoPilotPlugin.Conf.MainWindowJoinFlag)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = CruiseAssistMainUI.Rect[CruiseAssistMainUI.WIdx].x;
|
|
||||||
Rect[_wIdx].y = CruiseAssistMainUI.Rect[CruiseAssistMainUI.WIdx].yMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.width / scale < Rect[_wIdx].xMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = Screen.width / scale - Rect[_wIdx].width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].x < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.height / scale < Rect[_wIdx].yMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = Screen.height / scale - Rect[_wIdx].height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].y < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LastCheckWindowLeft[_wIdx] != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect[_wIdx].x != LastCheckWindowLeft[_wIdx] || Rect[_wIdx].y != LastCheckWindowTop[_wIdx])
|
|
||||||
{
|
|
||||||
NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
if (NextCheckGameTick <= GameMain.gameTick)
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (CruiseAssistMainUI.ViewMode == CruiseAssistMainUIViewMode.Full)
|
|
||||||
{
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
int status;
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
status = 0;
|
|
||||||
else if (AutoPilotPlugin.EnergyPer <= AutoPilotPlugin.Conf.MinEnergyPer)
|
|
||||||
status = 1;
|
|
||||||
else
|
|
||||||
status = 2;
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
GUILayout.Label(Strings.Get(3) + " : " + Strings.Get(7), _ngLabelStyle);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
GUILayout.Label(Strings.Get(3) + " : " + Strings.Get(8), _highlightedLabelStyle);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GUILayout.Label(Strings.Get(3) + " : ---", _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive || CruiseAssistPlugin.TargetStar == null || GameMain.mainPlayer.warping ||
|
|
||||||
(!AutoPilotPlugin.Conf.LocalWarpFlag && GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id == GameMain.localStar.id) ||
|
|
||||||
CruiseAssistPlugin.TargetRange < AutoPilotPlugin.Conf.WarpMinRangeAu * 40000)
|
|
||||||
status = 0;
|
|
||||||
else if (AutoPilotPlugin.WarperCount < 1)
|
|
||||||
status = 1;
|
|
||||||
else
|
|
||||||
status = 2;
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
GUILayout.Label(Strings.Get(4) + " : " + Strings.Get(7), _ngLabelStyle);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
GUILayout.Label(Strings.Get(4) + " : " + Strings.Get(8), _highlightedLabelStyle);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GUILayout.Label(Strings.Get(4) + " : ---", _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
status = 0;
|
|
||||||
else if (AutoPilotPlugin.LeavePlanet)
|
|
||||||
status = 2;
|
|
||||||
else
|
|
||||||
status = 1;
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
GUILayout.Label(Strings.Get(5) + " : " + Strings.Get(10), _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
GUILayout.Label(Strings.Get(5) + " : " + Strings.Get(9), _highlightedLabelStyle);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GUILayout.Label(Strings.Get(5) + " : ---", _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
status = 0;
|
|
||||||
else if (AutoPilotPlugin.SpeedUp)
|
|
||||||
status = 2;
|
|
||||||
else
|
|
||||||
status = 1;
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
GUILayout.Label(Strings.Get(6) + " : " + Strings.Get(12), _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
GUILayout.Label(Strings.Get(6) + " : " + Strings.Get(11), _highlightedLabelStyle);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GUILayout.Label(Strings.Get(6) + " : ---", _baseLabelStyle);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
|
||||||
{
|
|
||||||
GUILayout.Label(Strings.Get(13), _labelStyle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_labelStyle.normal.textColor = Color.cyan;
|
|
||||||
GUILayout.Label(Strings.Get(14), _labelStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (GUILayout.Button(Strings.Get(0), _buttonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
var show = AutoPilotConfigUI.Show;
|
|
||||||
var num = _wIdx;
|
|
||||||
show[num] = !show[num];
|
|
||||||
if (AutoPilotConfigUI.Show[_wIdx])
|
|
||||||
{
|
|
||||||
AutoPilotConfigUI.TempMinEnergyPer = AutoPilotPlugin.Conf.MinEnergyPer.ToString();
|
|
||||||
AutoPilotConfigUI.TempMaxSpeed = AutoPilotPlugin.Conf.MaxSpeed.ToString();
|
|
||||||
AutoPilotConfigUI.TempWarpMinRangeAu = AutoPilotPlugin.Conf.WarpMinRangeAu.ToString();
|
|
||||||
AutoPilotConfigUI.TempSpeedToWarp = AutoPilotPlugin.Conf.SpeedToWarp.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button(Strings.Get(1), _buttonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
AutoPilotPlugin.State = AutoPilotState.Active;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
GUILayout.Button("-", _buttonStyle);
|
|
||||||
if (GUILayout.Button(Strings.Get(2), _buttonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int _wIdx;
|
|
||||||
|
|
||||||
public const float WindowWidthFull = 408f;
|
|
||||||
|
|
||||||
public const float WindowHeightFull = 150f;
|
|
||||||
|
|
||||||
public const float WindowWidthMini = 298f;
|
|
||||||
|
|
||||||
public const float WindowHeightMini = 70f;
|
|
||||||
|
|
||||||
public static readonly Rect[] Rect =
|
|
||||||
[
|
|
||||||
new Rect(0f, 0f, 398f, 150f),
|
|
||||||
new Rect(0f, 0f, 398f, 150f)
|
|
||||||
];
|
|
||||||
|
|
||||||
private static GUIStyle _windowStyle;
|
|
||||||
private static GUIStyle _baseLabelStyle;
|
|
||||||
private static GUIStyle _highlightedLabelStyle;
|
|
||||||
private static GUIStyle _ngLabelStyle;
|
|
||||||
private static GUIStyle _labelStyle;
|
|
||||||
private static GUIStyle _buttonStyle;
|
|
||||||
|
|
||||||
private static readonly float[] LastCheckWindowLeft = [float.MinValue, float.MinValue];
|
|
||||||
|
|
||||||
private static readonly float[] LastCheckWindowTop = [float.MinValue, float.MinValue];
|
|
||||||
|
|
||||||
public static long NextCheckGameTick = long.MaxValue;
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
using System;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace AutoPilot.UI;
|
|
||||||
|
|
||||||
public static class Strings
|
|
||||||
{
|
|
||||||
private static readonly string[] EngUs = [
|
|
||||||
// 0
|
|
||||||
"Config",
|
|
||||||
"Start",
|
|
||||||
"Stop",
|
|
||||||
"Energy",
|
|
||||||
"Warper",
|
|
||||||
// 5
|
|
||||||
"Leaving Planet",
|
|
||||||
"Speed UP",
|
|
||||||
"NG",
|
|
||||||
"OK",
|
|
||||||
"YES",
|
|
||||||
// 10
|
|
||||||
"NO",
|
|
||||||
"ON",
|
|
||||||
"OFF",
|
|
||||||
"Auto Pilot Inactive.",
|
|
||||||
"Auto Pilot Active.",
|
|
||||||
// 15
|
|
||||||
"Min Energy Percent (0-100 default:20)",
|
|
||||||
"Max Speed (0-2000 default:2000)",
|
|
||||||
"Warp Min Range (1-60 default:2)",
|
|
||||||
"Speed to warp (0-2000 default:1200)",
|
|
||||||
"Warp to planet in local system.",
|
|
||||||
// 20
|
|
||||||
"Start AutoPilot when set target planet.",
|
|
||||||
"Join AutoPilot window to CruiseAssist window.",
|
|
||||||
];
|
|
||||||
|
|
||||||
private static readonly string[] ZhoCn =
|
|
||||||
[
|
|
||||||
// 0
|
|
||||||
"设置",
|
|
||||||
"开始",
|
|
||||||
"停止",
|
|
||||||
"能量",
|
|
||||||
"翘曲",
|
|
||||||
// 5
|
|
||||||
"离开行星",
|
|
||||||
"加速",
|
|
||||||
"不足",
|
|
||||||
"OK",
|
|
||||||
"是",
|
|
||||||
// 10
|
|
||||||
"否",
|
|
||||||
"开",
|
|
||||||
"关",
|
|
||||||
"Auto Pilot 未在工作",
|
|
||||||
"Auto Pilot 正在工作",
|
|
||||||
// 15
|
|
||||||
"最小能量百分比 (0-100 默认:20)",
|
|
||||||
"最大速度 (0-2000 默认:2000)",
|
|
||||||
"启用曲速最小距离 (1-60 默认:2)",
|
|
||||||
"启动曲速的航行速度 (0-2000 默认:1200)",
|
|
||||||
"即使本星系的行星也允许曲速",
|
|
||||||
// 20
|
|
||||||
"设置目标行星后立即开始导航",
|
|
||||||
"合并 AutoPilot 和 CruiseAssist 窗口",
|
|
||||||
];
|
|
||||||
|
|
||||||
public static Action OnLanguageChanged;
|
|
||||||
|
|
||||||
private static string[] _langStr = EngUs;
|
|
||||||
|
|
||||||
public static string Get(int index) => _langStr[index];
|
|
||||||
|
|
||||||
[HarmonyPostfix]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.LoadSettings))]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.LoadLanguage))]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.NotifyLanguageChange))]
|
|
||||||
private static void Localization_LanguageChanged_Postfix()
|
|
||||||
{
|
|
||||||
var newstr = Localization.Languages[Localization.currentLanguageIndex].lcId switch
|
|
||||||
{
|
|
||||||
2052 => ZhoCn,
|
|
||||||
_ => EngUs
|
|
||||||
};
|
|
||||||
if (newstr == _langStr) return;
|
|
||||||
_langStr = newstr;
|
|
||||||
OnLanguageChanged?.Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "AutoPilot",
|
|
||||||
"version_number": "0.1.0",
|
|
||||||
"website_url": "https://github.com/soarqin/DSP_Mods_TO/tree/master/AutoPilot",
|
|
||||||
"description": "Auto pilot to a planet or star system.",
|
|
||||||
"dependencies": [
|
|
||||||
"xiaoye97-BepInEx-5.4.17",
|
|
||||||
"soarqin-CruiseAssist-0.1.0"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using BepInEx.Configuration;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Commons;
|
|
||||||
|
|
||||||
internal abstract class ConfigManager
|
|
||||||
{
|
|
||||||
private static ConfigFile Config { get; set; }
|
|
||||||
|
|
||||||
protected static void Init<T>(ConfigFile config) where T: ConfigManager, new()
|
|
||||||
{
|
|
||||||
_instance = new T();
|
|
||||||
Config = config;
|
|
||||||
Config.SaveOnConfigSet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CheckConfig(Step step)
|
|
||||||
{
|
|
||||||
_instance.CheckConfigImplements(step);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void CheckConfigImplements(Step step);
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
|
|
||||||
{
|
|
||||||
return Config.Bind(configDefinition, defaultValue, configDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
|
|
||||||
{
|
|
||||||
return Config.Bind(section, key, defaultValue, configDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
|
|
||||||
{
|
|
||||||
return Config.Bind(section, key, defaultValue, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> GetEntry<T>(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
ConfigEntry<T> configEntry;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
configEntry = (ConfigEntry<T>)Config[configDefinition];
|
|
||||||
}
|
|
||||||
catch (KeyNotFoundException ex)
|
|
||||||
{
|
|
||||||
LogManager.LogError($"{ex.GetType()}: configDefinition={configDefinition}");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return configEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigEntry<T> GetEntry<T>(string section, string key)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(new ConfigDefinition(section, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T GetValue<T>(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(configDefinition).Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T GetValue<T>(string section, string key)
|
|
||||||
{
|
|
||||||
return GetEntry<T>(section, key).Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ContainsKey(ConfigDefinition configDefinition)
|
|
||||||
{
|
|
||||||
return Config.ContainsKey(configDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ContainsKey(string section, string key)
|
|
||||||
{
|
|
||||||
return Config.ContainsKey(new ConfigDefinition(section, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool UpdateEntry<T>(string section, string key, T value) where T : IComparable
|
|
||||||
{
|
|
||||||
var entry = GetEntry<T>(section, key);
|
|
||||||
var value2 = entry.Value;
|
|
||||||
var flag = value2.CompareTo(value) == 0;
|
|
||||||
bool flag2;
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
flag2 = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry.Value = value;
|
|
||||||
flag2 = true;
|
|
||||||
}
|
|
||||||
return flag2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool RemoveEntry(ConfigDefinition key)
|
|
||||||
{
|
|
||||||
return Config.Remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dictionary<ConfigDefinition, string> GetOrphanedEntries()
|
|
||||||
{
|
|
||||||
var flag = _orphanedEntries == null;
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
_orphanedEntries = Traverse.Create(Config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries").Value;
|
|
||||||
}
|
|
||||||
return _orphanedEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Migration<T>(string newSection, string newKey, T defaultValue, string oldSection, string oldKey)
|
|
||||||
{
|
|
||||||
GetOrphanedEntries();
|
|
||||||
var configDefinition = new ConfigDefinition(oldSection, oldKey);
|
|
||||||
var flag = _orphanedEntries.TryGetValue(configDefinition, out var text);
|
|
||||||
if (!flag) return;
|
|
||||||
Bind(newSection, newKey, defaultValue).SetSerializedValue(text);
|
|
||||||
_orphanedEntries.Remove(configDefinition);
|
|
||||||
LogManager.LogInfo(string.Concat("migration ", oldSection, ".", oldKey, "(", text, ") => ", newSection, ".", newKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Save(bool clearOrphanedEntries = false)
|
|
||||||
{
|
|
||||||
if (clearOrphanedEntries)
|
|
||||||
{
|
|
||||||
GetOrphanedEntries().Clear();
|
|
||||||
}
|
|
||||||
Config.Save();
|
|
||||||
LogManager.LogInfo("save config.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Clear()
|
|
||||||
{
|
|
||||||
Config.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Reload()
|
|
||||||
{
|
|
||||||
Config.Reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ConfigManager _instance;
|
|
||||||
|
|
||||||
private static Dictionary<ConfigDefinition, string> _orphanedEntries;
|
|
||||||
|
|
||||||
public enum Step
|
|
||||||
{
|
|
||||||
Awake,
|
|
||||||
GameMainBegin,
|
|
||||||
UniverseGenCreateGalaxy,
|
|
||||||
State,
|
|
||||||
ChangeSeed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Commons;
|
|
||||||
|
|
||||||
internal static class EnumUtils
|
|
||||||
{
|
|
||||||
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct
|
|
||||||
{
|
|
||||||
if (value == null || !Enum.IsDefined(typeof(TEnum), value))
|
|
||||||
{
|
|
||||||
result = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
result = (TEnum)Enum.Parse(typeof(TEnum), value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Commons;
|
|
||||||
|
|
||||||
internal static class ListUtils
|
|
||||||
{
|
|
||||||
public static string ToString(List<int> list)
|
|
||||||
{
|
|
||||||
return list == null || list.Count == 0 ? "" : list.Select(id => id.ToString()).Aggregate((a, b) => a + "," + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToString(List<string> list)
|
|
||||||
{
|
|
||||||
return list == null || list.Count == 0 ? "" : list.Aggregate((a, b) => a + "," + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<int> ParseToIntList(string str)
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(str)
|
|
||||||
? []
|
|
||||||
: str.Split(',').Where(s => int.TryParse(s, out _)).Select(int.Parse).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<string> ParseToStringList(string str)
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(str) ? [] : str.Split(',').ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using BepInEx.Logging;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Commons;
|
|
||||||
|
|
||||||
internal static class LogManager
|
|
||||||
{
|
|
||||||
public static ManualLogSource Logger { private get; set; }
|
|
||||||
|
|
||||||
public static void LogInfo(object data)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogInfo(MethodBase method)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(method.DeclaringType.Name + "." + method.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogInfo(MethodBase method, object data)
|
|
||||||
{
|
|
||||||
Logger.LogInfo(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError(object data)
|
|
||||||
{
|
|
||||||
Logger.LogError(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError(MethodBase method, object data)
|
|
||||||
{
|
|
||||||
Logger.LogError(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace CruiseAssist.Commons;
|
|
||||||
|
|
||||||
internal struct Tuple<T1, T2>(T1 v1, T2 v2)
|
|
||||||
{
|
|
||||||
public T1 Item1 { get; set; } = v1;
|
|
||||||
|
|
||||||
public T2 Item2 { get; set; } = v2;
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
using BepInEx.Configuration;
|
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using CruiseAssist.Enums;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
|
|
||||||
namespace CruiseAssist;
|
|
||||||
|
|
||||||
internal class CruiseAssistConfigManager : ConfigManager
|
|
||||||
{
|
|
||||||
public static void Init(ConfigFile config)
|
|
||||||
{
|
|
||||||
ConfigManager.Init<CruiseAssistConfigManager>(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void CheckConfigImplements(Step step)
|
|
||||||
{
|
|
||||||
var saveFlag = false;
|
|
||||||
switch (step)
|
|
||||||
{
|
|
||||||
case Step.Awake:
|
|
||||||
saveFlag = OnAwake();
|
|
||||||
OnAwakeOrGameMainBegin();
|
|
||||||
OnAwakeOrGameMainBeginOrStateOrChangeSeed();
|
|
||||||
break;
|
|
||||||
case Step.GameMainBegin:
|
|
||||||
OnAwakeOrGameMainBegin();
|
|
||||||
OnAwakeOrGameMainBeginOrStateOrChangeSeed();
|
|
||||||
break;
|
|
||||||
case Step.ChangeSeed:
|
|
||||||
OnAwakeOrGameMainBeginOrStateOrChangeSeed();
|
|
||||||
break;
|
|
||||||
case Step.State:
|
|
||||||
OnAwakeOrGameMainBeginOrStateOrChangeSeed();
|
|
||||||
saveFlag = OnState();
|
|
||||||
break;
|
|
||||||
case Step.UniverseGenCreateGalaxy:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (saveFlag)
|
|
||||||
{
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool OnState()
|
|
||||||
{
|
|
||||||
var saveFlag = false;
|
|
||||||
LogManager.LogInfo("check state.");
|
|
||||||
saveFlag |= UpdateEntry("Setting", "Enable", CruiseAssistPlugin.Enable);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "MarkVisited", CruiseAssistPlugin.Conf.MarkVisitedFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "SelectFocus", CruiseAssistPlugin.Conf.SelectFocusFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "HideDuplicateHistory", CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "AutoDisableLockCursor", CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "ShowMainWindowWhenTargetSelectedEvenNotSailMode", CruiseAssistPlugin.Conf.ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "CloseStarListWhenSetTargetPlanet", CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "HideBottomCloseButton", CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "UIScale", (int)CruiseAssistMainUI.Scale);
|
|
||||||
saveFlag |= UpdateEntry("Setting", "MainWindowViewMode", CruiseAssistMainUI.ViewMode.ToString());
|
|
||||||
for (var j = 0; j < 2; j++)
|
|
||||||
{
|
|
||||||
saveFlag |= UpdateEntry("State", $"MainWindow{j}Left", (int)CruiseAssistMainUI.Rect[j].x);
|
|
||||||
saveFlag |= UpdateEntry("State", $"MainWindow{j}Top", (int)CruiseAssistMainUI.Rect[j].y);
|
|
||||||
saveFlag |= UpdateEntry("State", $"StarListWindow{j}Left", (int)CruiseAssistStarListUI.Rect[j].x);
|
|
||||||
saveFlag |= UpdateEntry("State", $"StarListWindow{j}Top", (int)CruiseAssistStarListUI.Rect[j].y);
|
|
||||||
saveFlag |= UpdateEntry("State", $"ConfigWindow{j}Left", (int)CruiseAssistConfigUI.Rect[j].x);
|
|
||||||
saveFlag |= UpdateEntry("State", $"ConfigWindow{j}Top", (int)CruiseAssistConfigUI.Rect[j].y);
|
|
||||||
}
|
|
||||||
saveFlag |= UpdateEntry("State", "StarListWindowListSelected", CruiseAssistStarListUI.ListSelected);
|
|
||||||
saveFlag |= UpdateEntry("State", "DebugWindowLeft", (int)CruiseAssistDebugUI.Rect.x);
|
|
||||||
saveFlag |= UpdateEntry("State", "DebugWindowTop", (int)CruiseAssistDebugUI.Rect.y);
|
|
||||||
if (CruiseAssistPlugin.Seed != -1)
|
|
||||||
{
|
|
||||||
saveFlag |= UpdateEntry("Save", $"History_{CruiseAssistPlugin.Seed}", CruiseAssistStarListUI.HistoryToString());
|
|
||||||
saveFlag |= UpdateEntry("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", CruiseAssistStarListUI.BookmarkToString());
|
|
||||||
}
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = long.MaxValue;
|
|
||||||
return saveFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnAwakeOrGameMainBeginOrStateOrChangeSeed()
|
|
||||||
{
|
|
||||||
if (DSPGame.IsMenuDemo || GameMain.galaxy == null)
|
|
||||||
{
|
|
||||||
var reset = CruiseAssistPlugin.Seed != -1;
|
|
||||||
if (!reset) return;
|
|
||||||
CruiseAssistPlugin.Seed = -1;
|
|
||||||
CruiseAssistStarListUI.ClearHistory();
|
|
||||||
CruiseAssistStarListUI.ClearBookmark();
|
|
||||||
LogManager.LogInfo("clear seed.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.Seed == GameMain.galaxy.seed) return;
|
|
||||||
CruiseAssistPlugin.Seed = GameMain.galaxy.seed;
|
|
||||||
CruiseAssistStarListUI.HistoryFromString(Bind("Save", $"History_{CruiseAssistPlugin.Seed}", "").Value);
|
|
||||||
CruiseAssistStarListUI.BookmarkFromString(Bind("Save", $"Bookmark_{CruiseAssistPlugin.Seed}", "").Value);
|
|
||||||
LogManager.LogInfo($"change seed {CruiseAssistPlugin.Seed}.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnAwakeOrGameMainBegin()
|
|
||||||
{
|
|
||||||
CruiseAssistDebugUI.Show = Bind("Debug", "DebugWindowShow", false).Value;
|
|
||||||
CruiseAssistPlugin.Enable = Bind("Setting", "Enable", true).Value;
|
|
||||||
CruiseAssistPlugin.Conf.MarkVisitedFlag = Bind("Setting", "MarkVisited", true).Value;
|
|
||||||
CruiseAssistPlugin.Conf.SelectFocusFlag = Bind("Setting", "SelectFocus", true).Value;
|
|
||||||
CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag = Bind("Setting", "HideDuplicateHistory", true).Value;
|
|
||||||
CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag = Bind("Setting", "AutoDisableLockCursor", false).Value;
|
|
||||||
CruiseAssistPlugin.Conf.ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag = Bind("Setting", "ShowMainWindowWhenTargetSelectedEvenNotSailMode", true).Value;
|
|
||||||
CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag = Bind("Setting", "CloseStarListWhenSetTargetPlanet", false).Value;
|
|
||||||
CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag = Bind("Setting", "HideBottomCloseButton", true).Value;
|
|
||||||
CruiseAssistMainUI.Scale = Bind("Setting", "UIScale", 150).Value;
|
|
||||||
var viewModeStr = Bind("Setting", "MainWindowViewMode", CruiseAssistMainUIViewMode.Full.ToString()).Value;
|
|
||||||
EnumUtils.TryParse(viewModeStr, out CruiseAssistMainUI.ViewMode);
|
|
||||||
for (var i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
CruiseAssistMainUI.Rect[i].x = Bind("State", $"MainWindow{i}Left", 100).Value;
|
|
||||||
CruiseAssistMainUI.Rect[i].y = Bind("State", $"MainWindow{i}Top", 100).Value;
|
|
||||||
CruiseAssistStarListUI.Rect[i].x = Bind("State", $"StarListWindow{i}Left", 100).Value;
|
|
||||||
CruiseAssistStarListUI.Rect[i].y = Bind("State", $"StarListWindow{i}Top", 100).Value;
|
|
||||||
CruiseAssistConfigUI.Rect[i].x = Bind("State", $"ConfigWindow{i}Left", 100).Value;
|
|
||||||
CruiseAssistConfigUI.Rect[i].y = Bind("State", $"ConfigWindow{i}Top", 100).Value;
|
|
||||||
}
|
|
||||||
CruiseAssistStarListUI.ListSelected = Bind("State", "StarListWindowListSelected", 0).Value;
|
|
||||||
CruiseAssistDebugUI.Rect.x = Bind("State", "DebugWindowLeft", 100).Value;
|
|
||||||
CruiseAssistDebugUI.Rect.y = Bind("State", "DebugWindowTop", 100).Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool OnAwake()
|
|
||||||
{
|
|
||||||
var configEntry = Bind("Base", "ModVersion", "0.0.37", "Don't change.");
|
|
||||||
configEntry.Value = "0.0.37";
|
|
||||||
Migration("State", "MainWindow0Left", 100, "State", "InfoWindowLeft");
|
|
||||||
Migration("State", "MainWindow0Top", 100, "State", "InfoWindowTop");
|
|
||||||
Migration("State", "MainWindow0Left", 100, "State", "MainWindowLeft");
|
|
||||||
Migration("State", "MainWindow0Top", 100, "State", "MainWindowTop");
|
|
||||||
Migration("State", "StarListWindow0Left", 100, "State", "StarListWindowLeft");
|
|
||||||
Migration("State", "StarListWindow0Top", 100, "State", "StarListWindowTop");
|
|
||||||
Migration("Setting", "CloseStarListWhenSetTargetPlanet", false, "Setting", "HideStarListWhenSetTargetPlanet");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
namespace CruiseAssist;
|
|
||||||
|
|
||||||
public interface ICruiseAssistExtensionAPI
|
|
||||||
{
|
|
||||||
void CheckConfig(string step);
|
|
||||||
|
|
||||||
void SetTargetAstroId(int astroId);
|
|
||||||
|
|
||||||
bool OperateWalk(PlayerMove_Walk __instance);
|
|
||||||
|
|
||||||
bool OperateDrift(PlayerMove_Drift __instance);
|
|
||||||
|
|
||||||
bool OperateFly(PlayerMove_Fly __instance);
|
|
||||||
|
|
||||||
bool OperateSail(PlayerMove_Sail __instance);
|
|
||||||
|
|
||||||
void SetInactive();
|
|
||||||
|
|
||||||
void CancelOperate();
|
|
||||||
|
|
||||||
void OnGUI();
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using BepInEx;
|
|
||||||
using BepInEx.Configuration;
|
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using CruiseAssist.Enums;
|
|
||||||
using CruiseAssist.Patches;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
using HarmonyLib;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist;
|
|
||||||
|
|
||||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
|
||||||
public class CruiseAssistPlugin : BaseUnityPlugin
|
|
||||||
{
|
|
||||||
public void Awake()
|
|
||||||
{
|
|
||||||
LogManager.Logger = Logger;
|
|
||||||
CruiseAssistConfigManager.Init(new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, "tanu.CruiseAssist.cfg"), false, Info.Metadata));
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.Awake);
|
|
||||||
_harmony = new Harmony("org.soardev.CruiseAssist.Patch");
|
|
||||||
_harmony.PatchAll(typeof(Patch_GameMain));
|
|
||||||
_harmony.PatchAll(typeof(Patch_UISailPanel));
|
|
||||||
_harmony.PatchAll(typeof(Patch_UIStarmap));
|
|
||||||
_harmony.PatchAll(typeof(Patch_UITechTree));
|
|
||||||
_harmony.PatchAll(typeof(Patch_PlayerMoveWalk));
|
|
||||||
_harmony.PatchAll(typeof(Patch_PlayerMoveDrift));
|
|
||||||
_harmony.PatchAll(typeof(Patch_PlayerMoveFly));
|
|
||||||
_harmony.PatchAll(typeof(Patch_PlayerMoveSail));
|
|
||||||
_harmony.PatchAll(typeof(Strings));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnDestroy()
|
|
||||||
{
|
|
||||||
_harmony.UnpatchSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RegistExtension(ICruiseAssistExtensionAPI extension)
|
|
||||||
{
|
|
||||||
Extensions.Add(extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UnregistExtension(Type type)
|
|
||||||
{
|
|
||||||
Extensions.RemoveAll(extension => extension.GetType().FullName == type.FullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnGUI()
|
|
||||||
{
|
|
||||||
if (DSPGame.IsMenuDemo) return;
|
|
||||||
var mainPlayer = GameMain.mainPlayer;
|
|
||||||
if (mainPlayer == null) return;
|
|
||||||
if (UIMechaEditor.isOpened) return;
|
|
||||||
if (!_initialized)
|
|
||||||
{
|
|
||||||
_initialized = true;
|
|
||||||
CruiseAssistMainUI.OnInit();
|
|
||||||
CruiseAssistConfigUI.OnInit();
|
|
||||||
CruiseAssistStarListUI.OnInit();
|
|
||||||
CruiseAssistDebugUI.OnInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
var uiRoot = UIRoot.instance;
|
|
||||||
var uiGame = uiRoot.uiGame;
|
|
||||||
if (!uiGame.guideComplete || uiGame.techTree.active || uiGame.escMenu.active || uiGame.dysonEditor.active || uiGame.hideAllUI0 || uiGame.hideAllUI1) return;
|
|
||||||
var uiMilkyWayLoadingSplash = UIMilkyWayLoadingSplash.instance;
|
|
||||||
if (uiMilkyWayLoadingSplash != null && uiMilkyWayLoadingSplash.active) return;
|
|
||||||
var uiRootUIMilkyWay = uiRoot.uiMilkyWay;
|
|
||||||
if (uiRootUIMilkyWay != null && uiRootUIMilkyWay.active) return;
|
|
||||||
var starmapActive = uiGame.starmap.active;
|
|
||||||
if (!(mainPlayer.sailing || starmapActive || (Conf.ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag && TargetSelected))) return;
|
|
||||||
if (Seed != GameMain.galaxy.seed)
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.ChangeSeed);
|
|
||||||
CruiseAssistMainUI.WIdx = starmapActive ? 1 : 0;
|
|
||||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
GUIUtility.ScaleAroundPivot(new Vector2(scale, scale), Vector2.zero);
|
|
||||||
CruiseAssistMainUI.OnGUI();
|
|
||||||
if (CruiseAssistStarListUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
CruiseAssistStarListUI.OnGUI();
|
|
||||||
}
|
|
||||||
if (CruiseAssistConfigUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
CruiseAssistConfigUI.OnGUI();
|
|
||||||
}
|
|
||||||
if (CruiseAssistDebugUI.Show)
|
|
||||||
{
|
|
||||||
CruiseAssistDebugUI.OnGUI();
|
|
||||||
}
|
|
||||||
var ok = ResetInput(CruiseAssistMainUI.Rect[CruiseAssistMainUI.WIdx], scale);
|
|
||||||
if (!ok && CruiseAssistStarListUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
ok = ResetInput(CruiseAssistStarListUI.Rect[CruiseAssistMainUI.WIdx], scale);
|
|
||||||
}
|
|
||||||
if (!ok && CruiseAssistConfigUI.Show[CruiseAssistMainUI.WIdx])
|
|
||||||
{
|
|
||||||
ok = ResetInput(CruiseAssistConfigUI.Rect[CruiseAssistMainUI.WIdx], scale);
|
|
||||||
}
|
|
||||||
if (!ok && CruiseAssistDebugUI.Show)
|
|
||||||
{
|
|
||||||
ResetInput(CruiseAssistDebugUI.Rect, scale);
|
|
||||||
}
|
|
||||||
Extensions.ForEach(extension => extension.OnGUI());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ResetInput(Rect rect, float scale)
|
|
||||||
{
|
|
||||||
var num = rect.xMin * scale;
|
|
||||||
var num2 = rect.xMax * scale;
|
|
||||||
var num3 = rect.yMin * scale;
|
|
||||||
var num4 = rect.yMax * scale;
|
|
||||||
var x = Input.mousePosition.x;
|
|
||||||
var num5 = Screen.height - Input.mousePosition.y;
|
|
||||||
var flag = num <= x && x <= num2 && num3 <= num5 && num5 <= num4;
|
|
||||||
if (!flag) return false;
|
|
||||||
var array = new[] { 0, 1, 2 };
|
|
||||||
var flag2 = array.Any(Input.GetMouseButton) || Input.mouseScrollDelta.y != 0f;
|
|
||||||
if (!flag2) return false;
|
|
||||||
Input.ResetInputAxes();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Enable = true;
|
|
||||||
public static bool TargetSelected = false;
|
|
||||||
public static StarData ReticuleTargetStar = null;
|
|
||||||
public static PlanetData ReticuleTargetPlanet = null;
|
|
||||||
public static StarData SelectTargetStar = null;
|
|
||||||
public static PlanetData SelectTargetPlanet = null;
|
|
||||||
public static int SelectTargetAstroId = 0;
|
|
||||||
public static StarData TargetStar = null;
|
|
||||||
public static PlanetData TargetPlanet = null;
|
|
||||||
public static VectorLF3 TargetUPos = VectorLF3.zero;
|
|
||||||
public static double TargetRange = 0.0;
|
|
||||||
public static CruiseAssistState State = CruiseAssistState.Inactive;
|
|
||||||
public static bool Interrupt = false;
|
|
||||||
public static int Seed = -1;
|
|
||||||
public static readonly Func<StarData, string> GetStarName = star => star.displayName;
|
|
||||||
public static readonly Func<PlanetData, string> GetPlanetName = planet => planet.displayName;
|
|
||||||
internal static readonly List<ICruiseAssistExtensionAPI> Extensions = [];
|
|
||||||
private Harmony _harmony;
|
|
||||||
private static bool _initialized;
|
|
||||||
|
|
||||||
public static class Conf
|
|
||||||
{
|
|
||||||
public static bool MarkVisitedFlag = true;
|
|
||||||
public static bool SelectFocusFlag = true;
|
|
||||||
public static bool HideDuplicateHistoryFlag = true;
|
|
||||||
public static bool AutoDisableLockCursorFlag = false;
|
|
||||||
public static bool ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag = true;
|
|
||||||
public static bool CloseStarListWhenSetTargetPlanetFlag = false;
|
|
||||||
public static bool HideBottomCloseButtonFlag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace CruiseAssist.Enums;
|
|
||||||
|
|
||||||
public enum CruiseAssistMainUIViewMode
|
|
||||||
{
|
|
||||||
Full,
|
|
||||||
Mini
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace CruiseAssist.Enums;
|
|
||||||
|
|
||||||
public enum CruiseAssistState
|
|
||||||
{
|
|
||||||
ToStar,
|
|
||||||
ToPlanet,
|
|
||||||
Inactive
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using CruiseAssist.Commons;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(GameMain))]
|
|
||||||
internal class Patch_GameMain
|
|
||||||
{
|
|
||||||
[HarmonyPatch("Begin")]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
public static void Begin_Postfix()
|
|
||||||
{
|
|
||||||
CruiseAssistStarListUI.OnReset();
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.GameMainBegin);
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CheckConfig(ConfigManager.Step.GameMainBegin.ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch("Pause")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Pause_Prefix()
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CheckConfig(ConfigManager.Step.State.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(PlayerMove_Drift))]
|
|
||||||
internal class Patch_PlayerMoveDrift
|
|
||||||
{
|
|
||||||
[HarmonyPatch("GameTick")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void GameTick_Prefix(PlayerMove_Drift __instance)
|
|
||||||
{
|
|
||||||
if (!CruiseAssistPlugin.Enable) return;
|
|
||||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
|
||||||
if (__instance.controller.movementStateInFrame != EMovementState.Drift) return;
|
|
||||||
if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Interrupt = true;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CancelOperate());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.OperateDrift(__instance));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(PlayerMove_Fly))]
|
|
||||||
internal class Patch_PlayerMoveFly
|
|
||||||
{
|
|
||||||
[HarmonyPatch("GameTick")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void GameTick_Prefix(PlayerMove_Fly __instance)
|
|
||||||
{
|
|
||||||
if (!CruiseAssistPlugin.Enable) return;
|
|
||||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
|
||||||
if (__instance.controller.movementStateInFrame != EMovementState.Fly) return;
|
|
||||||
if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Interrupt = true;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CancelOperate());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.OperateFly(__instance));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
using HarmonyLib;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(PlayerMove_Sail))]
|
|
||||||
internal class Patch_PlayerMoveSail
|
|
||||||
{
|
|
||||||
[HarmonyPatch("GameTick")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void GameTick_Prefix(PlayerMove_Sail __instance)
|
|
||||||
{
|
|
||||||
if (!CruiseAssistPlugin.Enable) return;
|
|
||||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
|
||||||
var player = __instance.player;
|
|
||||||
if (!player.sailing) return;
|
|
||||||
var controller = player.controller;
|
|
||||||
if (controller.input0 != Vector4.zero || controller.input1 != Vector4.zero)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Interrupt = true;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CancelOperate());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.TargetUPos = CruiseAssistPlugin.TargetPlanet.uPosition;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.TargetStar == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CruiseAssistPlugin.TargetUPos = CruiseAssistPlugin.TargetStar.uPosition;
|
|
||||||
}
|
|
||||||
var operate = false;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => operate |= extension.OperateSail(__instance));
|
|
||||||
if (operate) return;
|
|
||||||
var vec = CruiseAssistPlugin.TargetUPos - player.uPosition;
|
|
||||||
var magnitude = controller.actionSail.visual_uvel.magnitude;
|
|
||||||
var angle = Vector3.Angle(vec, player.uVelocity);
|
|
||||||
if (angle > 1.6f)
|
|
||||||
{
|
|
||||||
player.uVelocity = Vector3.Slerp(player.uVelocity, vec.normalized * magnitude, 1.6f / Mathf.Max(10f, angle));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player.uVelocity = vec.normalized * magnitude;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
using CruiseAssist.Commons;
|
|
||||||
using CruiseAssist.Enums;
|
|
||||||
using CruiseAssist.UI;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(PlayerMove_Walk))]
|
|
||||||
internal class Patch_PlayerMoveWalk
|
|
||||||
{
|
|
||||||
[HarmonyPatch("GameTick")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void GameTick_Prefix(PlayerMove_Walk __instance)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.State = CruiseAssistState.Inactive;
|
|
||||||
CruiseAssistPlugin.Interrupt = false;
|
|
||||||
CruiseAssistPlugin.TargetStar = null;
|
|
||||||
CruiseAssistPlugin.TargetPlanet = null;
|
|
||||||
CruiseAssistPlugin.TargetUPos = VectorLF3.zero;
|
|
||||||
CruiseAssistPlugin.TargetRange = 0.0;
|
|
||||||
CruiseAssistPlugin.TargetSelected = false;
|
|
||||||
if (GameMain.localPlanet != null)
|
|
||||||
{
|
|
||||||
if (CruiseAssistStarListUI.LastHistoryId() != GameMain.localPlanet.id)
|
|
||||||
{
|
|
||||||
CruiseAssistStarListUI.AddHistory(GameMain.localPlanet);
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CruiseAssistPlugin.Enable) return;
|
|
||||||
|
|
||||||
var indicatorAstroId = GameMain.mainPlayer.navigation.indicatorAstroId;
|
|
||||||
if (indicatorAstroId != 0 && CruiseAssistPlugin.SelectTargetAstroId != indicatorAstroId)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.SelectTargetAstroId = indicatorAstroId;
|
|
||||||
if (indicatorAstroId % 100 != 0)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.SelectTargetPlanet = GameMain.galaxy.PlanetById(indicatorAstroId);
|
|
||||||
CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetPlanet.star;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.SelectTargetPlanet = null;
|
|
||||||
CruiseAssistPlugin.SelectTargetStar = GameMain.galaxy.StarById(indicatorAstroId / 100);
|
|
||||||
}
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetTargetAstroId(indicatorAstroId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CruiseAssistPlugin.SelectTargetStar != null)
|
|
||||||
{
|
|
||||||
if (GameMain.localStar != null && CruiseAssistPlugin.SelectTargetStar.id == GameMain.localStar.id)
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.SelectTargetPlanet != null)
|
|
||||||
{
|
|
||||||
if (GameMain.localPlanet != null && CruiseAssistPlugin.SelectTargetPlanet.id == GameMain.localPlanet.id)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.SelectTargetStar = null;
|
|
||||||
CruiseAssistPlugin.SelectTargetPlanet = null;
|
|
||||||
CruiseAssistPlugin.SelectTargetAstroId = 0;
|
|
||||||
GameMain.mainPlayer.navigation.indicatorAstroId = 0;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetInactive());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (GameMain.localPlanet != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.SelectTargetStar = null;
|
|
||||||
CruiseAssistPlugin.SelectTargetAstroId = 0;
|
|
||||||
GameMain.mainPlayer.navigation.indicatorAstroId = 0;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetInactive());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.SelectTargetStar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
|
|
||||||
}
|
|
||||||
else if (CruiseAssistPlugin.ReticuleTargetStar != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.ReticuleTargetStar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.State = CruiseAssistState.ToPlanet;
|
|
||||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetPlanet.star;
|
|
||||||
CruiseAssistPlugin.TargetRange = (CruiseAssistPlugin.TargetPlanet.uPosition - GameMain.mainPlayer.uPosition).magnitude - CruiseAssistPlugin.TargetPlanet.realRadius;
|
|
||||||
CruiseAssistPlugin.TargetSelected = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.TargetStar == null)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetInactive());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CruiseAssistPlugin.State = CruiseAssistState.ToStar;
|
|
||||||
CruiseAssistPlugin.TargetRange = (CruiseAssistPlugin.TargetStar.uPosition - GameMain.mainPlayer.uPosition).magnitude - (CruiseAssistPlugin.TargetStar.viewRadius - 120f);
|
|
||||||
CruiseAssistPlugin.TargetSelected = true;
|
|
||||||
}
|
|
||||||
if (__instance.controller.movementStateInFrame > EMovementState.Walk) return;
|
|
||||||
if (VFInput._jump.pressing)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Interrupt = true;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CancelOperate());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.OperateWalk(__instance));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection.Emit;
|
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(UISailPanel))]
|
|
||||||
internal class Patch_UISailPanel
|
|
||||||
{
|
|
||||||
[HarmonyPatch("_OnUpdate")]
|
|
||||||
[HarmonyTranspiler]
|
|
||||||
public static IEnumerable<CodeInstruction> OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions)
|
|
||||||
{
|
|
||||||
var codeMatcher = new CodeMatcher(instructions);
|
|
||||||
codeMatcher.MatchForward(true,
|
|
||||||
new CodeMatch(OpCodes.Ldarg_0)
|
|
||||||
).InsertAndAdvance(
|
|
||||||
Transpilers.EmitDelegate(delegate()
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.ReticuleTargetPlanet = null;
|
|
||||||
CruiseAssistPlugin.ReticuleTargetStar = null;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
codeMatcher.MatchForward(true,
|
|
||||||
new CodeMatch(OpCodes.Bge_Un),
|
|
||||||
new CodeMatch(OpCodes.Ldloc_S),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S),
|
|
||||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S),
|
|
||||||
new CodeMatch(OpCodes.Ldloc_S),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S)
|
|
||||||
).Advance(1).InsertAndAdvance(
|
|
||||||
new CodeInstruction(OpCodes.Ldloc_0),
|
|
||||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StarData), "planets")),
|
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 21),
|
|
||||||
Transpilers.EmitDelegate(delegate(PlanetData[] planets, int planetIndex)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.ReticuleTargetPlanet = planets[planetIndex];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
codeMatcher.MatchForward(true,
|
|
||||||
new CodeMatch(OpCodes.Bge_Un),
|
|
||||||
new CodeMatch(OpCodes.Ldloc_S),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S),
|
|
||||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S),
|
|
||||||
new CodeMatch(OpCodes.Ldloc_S),
|
|
||||||
new CodeMatch(OpCodes.Stloc_S)
|
|
||||||
).Advance(1).InsertAndAdvance(
|
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 20),
|
|
||||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(GalaxyData), "stars")),
|
|
||||||
new CodeInstruction(OpCodes.Ldloc_S, 24),
|
|
||||||
Transpilers.EmitDelegate(delegate(StarData[] stars, int starIndex)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.ReticuleTargetStar = stars[starIndex];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return codeMatcher.InstructionEnumeration();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch("_OnOpen")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void OnOpen_Prefix()
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag)
|
|
||||||
{
|
|
||||||
UIRoot.instance.uiGame.disableLockCursor = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch("_OnClose")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void OnClose_Prefix()
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using CruiseAssist.Commons;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(UIStarmap))]
|
|
||||||
internal class Patch_UIStarmap
|
|
||||||
{
|
|
||||||
[HarmonyPatch("_OnClose")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void OnClose_Prefix()
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CheckConfig(ConfigManager.Step.State.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using CruiseAssist.Commons;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.Patches;
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(UITechTree))]
|
|
||||||
internal class Patch_UITechTree
|
|
||||||
{
|
|
||||||
[HarmonyPatch("_OnOpen")]
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void OnOpen_Prefix()
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.CheckConfig(ConfigManager.Step.State.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# CruiseAssist
|
|
||||||
|
|
||||||
## What's this?
|
|
||||||
|
|
||||||
Adjust the orientation to the target planet or star when moving between planets or star systems.
|
|
||||||
|
|
||||||
You can set the target by selecting it in the indicator, by selecting it in the star list, or by facing the star.
|
|
||||||
|
|
||||||
Original mod: [CruiseAssist](https://thunderstore.io/package/tanu/CruiseAssist/)
|
|
||||||
It was discontinued, so I made a fork of it.
|
|
||||||
|
|
||||||
## CHANGE LOG
|
|
||||||
|
|
||||||
### 0.1.0
|
|
||||||
* Cleanup from disassmbly codes of CruiseAssist 0.0.37.
|
|
||||||
* Heavily optimization to codes, with CPU usage reduced a lot.
|
|
||||||
* Add search text box to star list.
|
|
||||||
* Add a simple localization implementation.
|
|
||||||
|
|
||||||
### Origianal CruiseAssit Changelogs
|
|
||||||
* Check [original mod](https://thunderstore.io/c/dyson-sphere-program/p/tanu/CruiseAssit/) for details
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
using CruiseAssist.Enums;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist.UI;
|
|
||||||
|
|
||||||
public static class CruiseAssistConfigUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
Strings.OnLanguageChanged += LangChanged;
|
|
||||||
LangChanged();
|
|
||||||
_labelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 120f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_toolbarButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseToolbarButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 80f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_uiScaleStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 60f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_horizontalSliderStyle = new GUIStyle(CruiseAssistMainUI.BaseHorizontalSliderStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 180f,
|
|
||||||
margin =
|
|
||||||
{
|
|
||||||
top = 10
|
|
||||||
},
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_horizontalSliderThunbStyle = new GUIStyle(CruiseAssistMainUI.BaseHorizontalSliderThumbStyle)
|
|
||||||
{
|
|
||||||
border = new RectOffset(1, 1, 8, 8)
|
|
||||||
};
|
|
||||||
_percentStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 40f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_toggleStyle = new GUIStyle(CruiseAssistMainUI.BaseToggleStyle)
|
|
||||||
{
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.LowerLeft
|
|
||||||
};
|
|
||||||
_setButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 60f,
|
|
||||||
fixedHeight = 18f,
|
|
||||||
margin =
|
|
||||||
{
|
|
||||||
top = 6
|
|
||||||
},
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_closeButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 80f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
|
|
||||||
void LangChanged()
|
|
||||||
{
|
|
||||||
_viewModeTexts = [Strings.Get(30), Strings.Get(31)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
_wIdx = CruiseAssistMainUI.WIdx;
|
|
||||||
Rect[_wIdx] = GUILayout.Window(99030293, Rect[_wIdx], WindowFunction, "CruiseAssist - " + Strings.Get(5), CruiseAssistMainUI.WindowStyle);
|
|
||||||
var num = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
if (Screen.width / num < Rect[_wIdx].xMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = Screen.width / num - Rect[_wIdx].width;
|
|
||||||
}
|
|
||||||
if (Rect[_wIdx].x < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = 0f;
|
|
||||||
}
|
|
||||||
if (Screen.height / num < Rect[_wIdx].yMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = Screen.height / num - Rect[_wIdx].height;
|
|
||||||
}
|
|
||||||
if (Rect[_wIdx].y < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = 0f;
|
|
||||||
}
|
|
||||||
if (LastCheckWindowLeft[_wIdx] != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect[_wIdx].x != LastCheckWindowLeft[_wIdx] || Rect[_wIdx].y != LastCheckWindowTop[_wIdx])
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.Label(Strings.Get(21), _labelStyle);
|
|
||||||
var viewMode = CruiseAssistMainUI.ViewMode == CruiseAssistMainUIViewMode.Full ? 0 : 1;
|
|
||||||
GUI.changed = false;
|
|
||||||
var value = GUILayout.Toolbar(viewMode, _viewModeTexts, _toolbarButtonStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
}
|
|
||||||
if (value != viewMode)
|
|
||||||
{
|
|
||||||
if (value != 0)
|
|
||||||
{
|
|
||||||
if (value == 1)
|
|
||||||
{
|
|
||||||
CruiseAssistMainUI.ViewMode = CruiseAssistMainUIViewMode.Mini;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CruiseAssistMainUI.ViewMode = CruiseAssistMainUIViewMode.Full;
|
|
||||||
}
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.Label(Strings.Get(22), _uiScaleStyle);
|
|
||||||
TempScale = GUILayout.HorizontalSlider(TempScale, 80f, 240f, _horizontalSliderStyle, _horizontalSliderThunbStyle);
|
|
||||||
TempScale = (int)TempScale / 5 * 5;
|
|
||||||
GUILayout.Label(TempScale.ToString("0") + "%", _percentStyle);
|
|
||||||
if (GUILayout.Button(Strings.Get(14), _setButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.Scale = TempScale;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.MarkVisitedFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.MarkVisitedFlag, Strings.Get(23), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.SelectFocusFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.SelectFocusFlag, Strings.Get(24), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag, Strings.Get(25), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag, Strings.Get(26), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.ShowMainWindowWhenTargetSelectedEvenNotSailModeFlag, Strings.Get(27), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag, Strings.Get(28), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUI.changed = false;
|
|
||||||
CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag = GUILayout.Toggle(CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag, Strings.Get(29), _toggleStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
if (!CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag && GUILayout.Button(Strings.Get(20), _closeButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
if (GUI.Button(new Rect(Rect[_wIdx].width - 16f, 1f, 16f, 16f), "", CruiseAssistMainUI.CloseButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int _wIdx;
|
|
||||||
public const float WindowWidth = 400f;
|
|
||||||
public const float WindowHeight = 400f;
|
|
||||||
public static readonly bool[] Show = new bool[2];
|
|
||||||
public static readonly Rect[] Rect =
|
|
||||||
[
|
|
||||||
new Rect(0f, 0f, 400f, 400f),
|
|
||||||
new Rect(0f, 0f, 400f, 400f)
|
|
||||||
];
|
|
||||||
private static readonly float[] LastCheckWindowLeft = [float.MinValue, float.MinValue];
|
|
||||||
private static readonly float[] LastCheckWindowTop = [float.MinValue, float.MinValue];
|
|
||||||
public static float TempScale;
|
|
||||||
private static GUIStyle _labelStyle;
|
|
||||||
private static GUIStyle _toolbarButtonStyle;
|
|
||||||
private static GUIStyle _uiScaleStyle;
|
|
||||||
private static GUIStyle _horizontalSliderStyle;
|
|
||||||
private static GUIStyle _horizontalSliderThunbStyle;
|
|
||||||
private static GUIStyle _percentStyle;
|
|
||||||
private static GUIStyle _toggleStyle;
|
|
||||||
private static GUIStyle _setButtonStyle;
|
|
||||||
private static GUIStyle _closeButtonStyle;
|
|
||||||
private static string[] _viewModeTexts = [Strings.Get(30), Strings.Get(31)];
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist.UI;
|
|
||||||
|
|
||||||
public static class CruiseAssistDebugUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
_windowStyle = new GUIStyle(GUI.skin.window)
|
|
||||||
{
|
|
||||||
fontSize = 11
|
|
||||||
};
|
|
||||||
_debugStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
Rect = GUILayout.Window(99030294, Rect, WindowFunction, "CruiseAssist - Debug", _windowStyle);
|
|
||||||
if (Screen.width < Rect.xMax)
|
|
||||||
{
|
|
||||||
Rect.x = Screen.width - Rect.width;
|
|
||||||
}
|
|
||||||
if (Rect.x < 0f)
|
|
||||||
{
|
|
||||||
Rect.x = 0f;
|
|
||||||
}
|
|
||||||
if (Screen.height < Rect.yMax)
|
|
||||||
{
|
|
||||||
Rect.y = Screen.height - Rect.height;
|
|
||||||
}
|
|
||||||
if (Rect.y < 0f)
|
|
||||||
{
|
|
||||||
Rect.y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_lastCheckWindowLeft != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect.x != _lastCheckWindowLeft || Rect.y != _lastCheckWindowTop)
|
|
||||||
{
|
|
||||||
_lastCheckWindowLeft = Rect.x;
|
|
||||||
_lastCheckWindowTop = Rect.y;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_lastCheckWindowLeft = Rect.x;
|
|
||||||
_lastCheckWindowTop = Rect.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
_scrollPos = GUILayout.BeginScrollView(_scrollPos);
|
|
||||||
var reticuleTargetStar = CruiseAssistPlugin.ReticuleTargetStar;
|
|
||||||
GUILayout.Label($"CruiseAssistPlugin.ReticuleTargetStar.id={(reticuleTargetStar != null ? new int?(reticuleTargetStar.id) : null)}", _debugStyle);
|
|
||||||
var reticuleTargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
|
|
||||||
GUILayout.Label($"CruiseAssistPlugin.ReticuleTargetPlanet.id={(reticuleTargetPlanet != null ? new int?(reticuleTargetPlanet.id) : null)}", _debugStyle);
|
|
||||||
var selectTargetStar = CruiseAssistPlugin.SelectTargetStar;
|
|
||||||
GUILayout.Label($"CruiseAssistPlugin.SelectTargetStar.id={(selectTargetStar != null ? new int?(selectTargetStar.id) : null)}", _debugStyle);
|
|
||||||
var selectTargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
|
|
||||||
GUILayout.Label($"CruiseAssistPlugin.SelectTargetPlanet.id={(selectTargetPlanet != null ? new int?(selectTargetPlanet.id) : null)}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.navigation.indicatorAstroId={GameMain.mainPlayer.navigation.indicatorAstroId}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input0.w={GameMain.mainPlayer.controller.input0.w}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input0.x={GameMain.mainPlayer.controller.input0.x}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input0.y={GameMain.mainPlayer.controller.input0.y}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input0.z={GameMain.mainPlayer.controller.input0.z}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input1.w={GameMain.mainPlayer.controller.input1.w}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input1.x={GameMain.mainPlayer.controller.input1.x}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input1.y={GameMain.mainPlayer.controller.input1.y}", _debugStyle);
|
|
||||||
GUILayout.Label($"GameMain.mainPlayer.controller.input1.z={GameMain.mainPlayer.controller.input1.z}", _debugStyle);
|
|
||||||
GUILayout.Label($"VFInput._sailSpeedUp={VFInput._sailSpeedUp}", _debugStyle);
|
|
||||||
GUILayout.Label($"CruiseAssistPlugin.Enable={CruiseAssistPlugin.Enable}", _debugStyle);
|
|
||||||
GUILayout.Label($"GUI.skin.window.margin.top={GUI.skin.window.margin.top}", _debugStyle);
|
|
||||||
GUILayout.Label($"GUI.skin.window.border.top={GUI.skin.window.border.top}", _debugStyle);
|
|
||||||
GUILayout.Label($"GUI.skin.window.padding.top={GUI.skin.window.padding.top}", _debugStyle);
|
|
||||||
GUILayout.Label($"GUI.skin.window.overflow.top={GUI.skin.window.overflow.top}", _debugStyle);
|
|
||||||
GUILayout.EndScrollView();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Show = false;
|
|
||||||
public static Rect Rect = new(0f, 0f, 400f, 400f);
|
|
||||||
private static float _lastCheckWindowLeft = float.MinValue;
|
|
||||||
private static float _lastCheckWindowTop = float.MinValue;
|
|
||||||
private static Vector2 _scrollPos = Vector2.zero;
|
|
||||||
private static GUIStyle _windowStyle;
|
|
||||||
private static GUIStyle _debugStyle;
|
|
||||||
}
|
|
||||||
@@ -1,921 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using CruiseAssist.Enums;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist.UI;
|
|
||||||
|
|
||||||
public static class CruiseAssistMainUI
|
|
||||||
{
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
if (_whiteBorderBackgroundTexture == null)
|
|
||||||
{
|
|
||||||
_whiteBorderBackgroundTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color2 = new Color32(0, 0, 0, 224);
|
|
||||||
for (var i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 64; j++)
|
|
||||||
{
|
|
||||||
var color3 = i <= 0 || j <= 0 || i >= 63 || j >= 63 ? color : color2;
|
|
||||||
_whiteBorderBackgroundTexture.SetPixel(j, i, color3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_whiteBorderBackgroundTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_grayBorderBackgroundTexture == null)
|
|
||||||
{
|
|
||||||
_grayBorderBackgroundTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color4 = new Color32(64, 64, 64, byte.MaxValue);
|
|
||||||
var color5 = new Color32(0, 0, 0, 224);
|
|
||||||
for (var k = 0; k < 64; k++)
|
|
||||||
{
|
|
||||||
for (var l = 0; l < 64; l++)
|
|
||||||
{
|
|
||||||
var color6 = k <= 0 || l <= 0 || k >= 63 || l >= 63 ? color4 : color5;
|
|
||||||
_grayBorderBackgroundTexture.SetPixel(l, k, color6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_grayBorderBackgroundTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_whiteBorderTexture == null)
|
|
||||||
{
|
|
||||||
_whiteBorderTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color7 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color8 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
for (var m = 0; m < 64; m++)
|
|
||||||
{
|
|
||||||
for (var n = 0; n < 64; n++)
|
|
||||||
{
|
|
||||||
var color9 = m <= 0 || n <= 0 || m >= 63 || n >= 63 ? color7 : color8;
|
|
||||||
_whiteBorderTexture.SetPixel(n, m, color9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_whiteBorderTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_grayBorderTexture == null)
|
|
||||||
{
|
|
||||||
_grayBorderTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color10 = new Color32(64, 64, 64, byte.MaxValue);
|
|
||||||
var color11 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
for (var i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 64; j++)
|
|
||||||
{
|
|
||||||
var color12 = i <= 0 || j <= 0 || i >= 63 || j >= 63 ? color10 : color11;
|
|
||||||
_grayBorderTexture.SetPixel(j, i, color12);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_grayBorderTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_blackTexture == null)
|
|
||||||
{
|
|
||||||
_blackTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color13 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
for (var i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 64; j++)
|
|
||||||
{
|
|
||||||
_blackTexture.SetPixel(j, i, color13);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_blackTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_whiteTexture == null)
|
|
||||||
{
|
|
||||||
_whiteTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false);
|
|
||||||
var color14 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
for (var i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 64; j++)
|
|
||||||
{
|
|
||||||
_whiteTexture.SetPixel(j, i, color14);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_whiteTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_toggleOnTexture == null)
|
|
||||||
{
|
|
||||||
_toggleOnTexture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
|
|
||||||
var color15 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color16 = new Color32(0, 0, 0, 0);
|
|
||||||
for (var i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 16; j++)
|
|
||||||
{
|
|
||||||
var color17 = j is >= 1 and <= 12 && i is >= 2 and <= 13 ? color15 : color16;
|
|
||||||
_toggleOnTexture.SetPixel(j, i, color17);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_toggleOnTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_toggleOffTexture == null)
|
|
||||||
{
|
|
||||||
_toggleOffTexture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
|
|
||||||
var color18 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color19 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
var color20 = new Color32(0, 0, 0, 0);
|
|
||||||
for (var i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 16; j++)
|
|
||||||
{
|
|
||||||
var color21 = j < 1 || j > 12 || i < 2 || i > 13 ? color20 : j is > 1 and < 12 && i is > 2 and < 13 ? color19 : color18;
|
|
||||||
_toggleOffTexture.SetPixel(j, i, color21);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_toggleOffTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_closeButtonGrayBorderTexture != null)
|
|
||||||
{
|
|
||||||
_closeButtonGrayBorderTexture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
|
|
||||||
var color22 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color23 = new Color32(64, 64, 64, byte.MaxValue);
|
|
||||||
var color24 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
var color25 = new Color32(0, 0, 0, 0);
|
|
||||||
for (var i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 16; j++)
|
|
||||||
{
|
|
||||||
var color26 = j < 1 || j > 12 || i < 2 || i > 13 ? color25 : j is > 1 and < 12 && i is > 2 and < 13 ? color24 : color23;
|
|
||||||
_closeButtonGrayBorderTexture.SetPixel(j, i, color26);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 4; i <= 9; i++)
|
|
||||||
{
|
|
||||||
_closeButtonGrayBorderTexture.SetPixel(i, i + 1, color22);
|
|
||||||
_closeButtonGrayBorderTexture.SetPixel(i, 14 - i, color22);
|
|
||||||
}
|
|
||||||
|
|
||||||
_closeButtonGrayBorderTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_closeButtonWhiteBorderTexture == null)
|
|
||||||
{
|
|
||||||
_closeButtonWhiteBorderTexture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
|
|
||||||
var color27 = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
|
||||||
var color28 = new Color32(0, 0, 0, byte.MaxValue);
|
|
||||||
var color29 = new Color32(0, 0, 0, 0);
|
|
||||||
for (var i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
for (var j = 0; j < 16; j++)
|
|
||||||
{
|
|
||||||
var color30 = j < 1 || j > 12 || i < 2 || i > 13 ? color29 : j is > 1 and < 12 && i is > 2 and < 13 ? color28 : color27;
|
|
||||||
_closeButtonWhiteBorderTexture.SetPixel(j, i, color30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 4; i <= 9; i++)
|
|
||||||
{
|
|
||||||
_closeButtonWhiteBorderTexture.SetPixel(i, i + 1, color27);
|
|
||||||
_closeButtonWhiteBorderTexture.SetPixel(i, 14 - i, color27);
|
|
||||||
}
|
|
||||||
|
|
||||||
_closeButtonWhiteBorderTexture.Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowStyle ??= new GUIStyle(GUI.skin.window)
|
|
||||||
{
|
|
||||||
fontSize = 11,
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderBackgroundTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderBackgroundTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseButtonStyle ??= new GUIStyle(GUI.skin.button)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
textColor = Color.white,
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseToolbarButtonStyle ??= new GUIStyle(BaseButtonStyle)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
textColor = Color.gray
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
textColor = Color.gray
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
textColor = Color.gray
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
textColor = Color.gray
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderBackgroundTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseVerticalScrollBarStyle ??= new GUIStyle(GUI.skin.verticalScrollbar)
|
|
||||||
{
|
|
||||||
name = "cruiseassist.verticalscrollbar",
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseHorizontalSliderStyle ??= new GUIStyle(GUI.skin.horizontalSlider)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _grayBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseHorizontalSliderThumbStyle ??= new GUIStyle(GUI.skin.horizontalSliderThumb)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseToggleStyle ??= new GUIStyle(GUI.skin.toggle)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _toggleOffTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _toggleOffTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _toggleOffTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _toggleOffTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _toggleOnTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _toggleOnTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _toggleOnTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _toggleOnTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseTextFieldStyle ??= new GUIStyle(GUI.skin.textField)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CloseButtonStyle ??= new GUIStyle(GUI.skin.button)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _closeButtonGrayBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _closeButtonGrayBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _closeButtonWhiteBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (_verticalScrollBarSkins == null)
|
|
||||||
{
|
|
||||||
_verticalScrollBarSkins = [];
|
|
||||||
var guistyle = new GUIStyle(GUI.skin.verticalScrollbarThumb)
|
|
||||||
{
|
|
||||||
name = "cruiseassist.verticalscrollbarthumb",
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _whiteBorderTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_verticalScrollBarSkins.Add(guistyle);
|
|
||||||
var guistyle2 = new GUIStyle(GUI.skin.verticalScrollbarUpButton)
|
|
||||||
{
|
|
||||||
name = "cruiseassist.verticalscrollbarupbutton",
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_verticalScrollBarSkins.Add(guistyle2);
|
|
||||||
var guistyle3 = new GUIStyle(GUI.skin.verticalScrollbarDownButton)
|
|
||||||
{
|
|
||||||
name = "cruiseassist.verticalscrollbardownbutton",
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
hover =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
active =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
focused =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onNormal =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onHover =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onActive =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
},
|
|
||||||
onFocused =
|
|
||||||
{
|
|
||||||
background = _blackTexture
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_verticalScrollBarSkins.Add(guistyle3);
|
|
||||||
GUI.skin.customStyles = GUI.skin.customStyles.Concat(_verticalScrollBarSkins).ToArray();
|
|
||||||
}
|
|
||||||
_starLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 50f,
|
|
||||||
fixedHeight = 36f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.UpperLeft
|
|
||||||
};
|
|
||||||
_planetLabelStyle = new GUIStyle(_starLabelStyle);
|
|
||||||
_starLabelStyle2 = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 240f,
|
|
||||||
fixedHeight = 36f,
|
|
||||||
fontSize = 14,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_planetLabelStyle2 = new GUIStyle(_starLabelStyle2);
|
|
||||||
_starLabelStyle3 = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 80f,
|
|
||||||
fixedHeight = 36f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.MiddleRight
|
|
||||||
};
|
|
||||||
_planetLabelStyle3 = new GUIStyle(_starLabelStyle3);
|
|
||||||
_stateLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 160f,
|
|
||||||
fixedHeight = 32f,
|
|
||||||
fontSize = 14,
|
|
||||||
alignment = TextAnchor.MiddleLeft
|
|
||||||
};
|
|
||||||
_configButtonStyle = new GUIStyle(BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 55f,
|
|
||||||
fixedHeight = 18f,
|
|
||||||
fontSize = 11,
|
|
||||||
alignment = TextAnchor.MiddleCenter
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
switch (ViewMode)
|
|
||||||
{
|
|
||||||
case CruiseAssistMainUIViewMode.Full:
|
|
||||||
Rect[WIdx].width = 408f;
|
|
||||||
Rect[WIdx].height = 150f;
|
|
||||||
break;
|
|
||||||
case CruiseAssistMainUIViewMode.Mini:
|
|
||||||
Rect[WIdx].width = 298f;
|
|
||||||
Rect[WIdx].height = 70f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Rect[WIdx] = GUILayout.Window(99030291, Rect[WIdx], WindowFunction, "CruiseAssist", WindowStyle);
|
|
||||||
var scale = Scale / 100f;
|
|
||||||
if (Screen.width / scale < Rect[WIdx].xMax)
|
|
||||||
{
|
|
||||||
Rect[WIdx].x = Screen.width / scale - Rect[WIdx].width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[WIdx].x < 0f)
|
|
||||||
{
|
|
||||||
Rect[WIdx].x = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.height / scale < Rect[WIdx].yMax)
|
|
||||||
{
|
|
||||||
Rect[WIdx].y = Screen.height / scale - Rect[WIdx].height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[WIdx].y < 0f)
|
|
||||||
{
|
|
||||||
Rect[WIdx].y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LastCheckWindowLeft[WIdx] != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect[WIdx].x != LastCheckWindowLeft[WIdx] || Rect[WIdx].y != LastCheckWindowTop[WIdx])
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[WIdx] = Rect[WIdx].x;
|
|
||||||
LastCheckWindowTop[WIdx] = Rect[WIdx].y;
|
|
||||||
NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[WIdx] = Rect[WIdx].x;
|
|
||||||
LastCheckWindowTop[WIdx] = Rect[WIdx].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NextCheckGameTick <= GameMain.gameTick)
|
|
||||||
{
|
|
||||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (ViewMode == CruiseAssistMainUIViewMode.Full)
|
|
||||||
{
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
var starColor = CruiseAssistPlugin.State == CruiseAssistState.ToStar ? Color.cyan : Color.white;
|
|
||||||
var planetColor = CruiseAssistPlugin.State == CruiseAssistState.ToPlanet ? Color.cyan : Color.white;
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
_starLabelStyle.normal.textColor = starColor;
|
|
||||||
GUILayout.Label(Strings.Get(0), _starLabelStyle);
|
|
||||||
_planetLabelStyle.normal.textColor = planetColor;
|
|
||||||
GUILayout.Label(Strings.Get(1), _planetLabelStyle);
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (CruiseAssistPlugin.TargetStar != null && ((GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id != GameMain.localStar.id) || CruiseAssistPlugin.TargetPlanet == null))
|
|
||||||
{
|
|
||||||
_starLabelStyle2.normal.textColor = starColor;
|
|
||||||
GUILayout.Label(CruiseAssistPlugin.GetStarName(CruiseAssistPlugin.TargetStar), _starLabelStyle2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GUILayout.Label(" ", _starLabelStyle2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
|
||||||
{
|
|
||||||
_planetLabelStyle2.normal.textColor = planetColor;
|
|
||||||
GUILayout.Label(CruiseAssistPlugin.GetPlanetName(CruiseAssistPlugin.TargetPlanet), _planetLabelStyle2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GUILayout.Label(" ", _planetLabelStyle2);
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
var actionSail = GameMain.mainPlayer.controller.actionSail;
|
|
||||||
var visualUvel = actionSail.visual_uvel;
|
|
||||||
var warping = GameMain.mainPlayer.warping;
|
|
||||||
var magnitude = warping ? (visualUvel + actionSail.currentWarpVelocity).magnitude : visualUvel.magnitude;
|
|
||||||
if (CruiseAssistPlugin.TargetStar != null && ((GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id != GameMain.localStar.id) || CruiseAssistPlugin.TargetPlanet == null))
|
|
||||||
{
|
|
||||||
_starLabelStyle3.normal.textColor = starColor;
|
|
||||||
var text = GameMain.mainPlayer.sailing ? TimeToString(CruiseAssistPlugin.TargetRange / magnitude) : "-- -- --";
|
|
||||||
GUILayout.Label(RangeToString(CruiseAssistPlugin.TargetRange) + "\n" + text, _starLabelStyle3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GUILayout.Label(" \n ", _starLabelStyle3);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
|
||||||
{
|
|
||||||
_planetLabelStyle3.normal.textColor = planetColor;
|
|
||||||
var text2 = GameMain.mainPlayer.sailing ? TimeToString(CruiseAssistPlugin.TargetRange / magnitude) : "-- -- --";
|
|
||||||
GUILayout.Label(RangeToString(CruiseAssistPlugin.TargetRange) + "\n" + text2, _planetLabelStyle3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GUILayout.Label(" \n ", _planetLabelStyle3);
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
}
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
if (!CruiseAssistPlugin.Enable)
|
|
||||||
{
|
|
||||||
GUILayout.Label(Strings.Get(2), _stateLabelStyle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.State == CruiseAssistState.Inactive || CruiseAssistPlugin.Interrupt)
|
|
||||||
{
|
|
||||||
GUILayout.Label(Strings.Get(3), _stateLabelStyle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_stateLabelStyle.normal.textColor = Color.cyan;
|
|
||||||
GUILayout.Label(Strings.Get(4), _stateLabelStyle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (GUILayout.Button(Strings.Get(5), _configButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistConfigUI.Show[WIdx] = !CruiseAssistConfigUI.Show[WIdx];
|
|
||||||
if (CruiseAssistConfigUI.Show[WIdx])
|
|
||||||
{
|
|
||||||
CruiseAssistConfigUI.TempScale = Scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button(CruiseAssistPlugin.Enable ? Strings.Get(6) : Strings.Get(7), _configButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistPlugin.Enable = !CruiseAssistPlugin.Enable;
|
|
||||||
if (!CruiseAssistPlugin.Enable)
|
|
||||||
{
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetInactive());
|
|
||||||
}
|
|
||||||
NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
if (GUILayout.Button(Strings.Get(8), _configButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistStarListUI.Show[WIdx] = !CruiseAssistStarListUI.Show[WIdx];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button(Strings.Get(9), _configButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
CruiseAssistStarListUI.SelectStar(null, null);
|
|
||||||
}
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RangeToString(double range)
|
|
||||||
{
|
|
||||||
return range switch
|
|
||||||
{
|
|
||||||
< 10000.0 => $"{(int)(range + 0.5)}m",
|
|
||||||
< 600000.0 => $"{range / 40000.0:0.00}AU",
|
|
||||||
_ => $"{range / 2400000.0:0.00}Ly"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string TimeToString(double time)
|
|
||||||
{
|
|
||||||
var sec = (int)(time + 0.5);
|
|
||||||
var min = sec / 60;
|
|
||||||
var hour = min / 60;
|
|
||||||
return $"{hour:00} {min % 60:00} {sec % 60:00}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float Scale = 150f;
|
|
||||||
public static int WIdx = 0;
|
|
||||||
public static CruiseAssistMainUIViewMode ViewMode = CruiseAssistMainUIViewMode.Full;
|
|
||||||
public const float WindowWidthFull = 398f;
|
|
||||||
public const float WindowHeightFull = 150f;
|
|
||||||
public const float WindowWidthMini = 288f;
|
|
||||||
public const float WindowHeightMini = 70f;
|
|
||||||
public static readonly Rect[] Rect =
|
|
||||||
[
|
|
||||||
new Rect(0f, 0f, 398f, 150f),
|
|
||||||
new Rect(0f, 0f, 398f, 150f)
|
|
||||||
];
|
|
||||||
private static readonly float[] LastCheckWindowLeft = [float.MinValue, float.MinValue];
|
|
||||||
private static readonly float[] LastCheckWindowTop = [float.MinValue, float.MinValue];
|
|
||||||
public static long NextCheckGameTick = long.MaxValue;
|
|
||||||
private static Texture2D _whiteBorderBackgroundTexture;
|
|
||||||
private static Texture2D _grayBorderBackgroundTexture;
|
|
||||||
private static Texture2D _whiteBorderTexture;
|
|
||||||
private static Texture2D _grayBorderTexture;
|
|
||||||
private static Texture2D _blackTexture;
|
|
||||||
private static Texture2D _whiteTexture;
|
|
||||||
private static Texture2D _toggleOnTexture;
|
|
||||||
private static Texture2D _toggleOffTexture;
|
|
||||||
private static Texture2D _closeButtonGrayBorderTexture;
|
|
||||||
private static Texture2D _closeButtonWhiteBorderTexture;
|
|
||||||
public static GUIStyle WindowStyle;
|
|
||||||
public static GUIStyle BaseButtonStyle;
|
|
||||||
public static GUIStyle BaseToolbarButtonStyle;
|
|
||||||
public static GUIStyle BaseVerticalScrollBarStyle;
|
|
||||||
public static GUIStyle BaseHorizontalSliderStyle;
|
|
||||||
public static GUIStyle BaseHorizontalSliderThumbStyle;
|
|
||||||
public static GUIStyle BaseToggleStyle;
|
|
||||||
public static GUIStyle BaseTextFieldStyle;
|
|
||||||
public static GUIStyle CloseButtonStyle;
|
|
||||||
private static List<GUIStyle> _verticalScrollBarSkins;
|
|
||||||
private static GUIStyle _starLabelStyle;
|
|
||||||
private static GUIStyle _planetLabelStyle;
|
|
||||||
private static GUIStyle _starLabelStyle2;
|
|
||||||
private static GUIStyle _planetLabelStyle2;
|
|
||||||
private static GUIStyle _starLabelStyle3;
|
|
||||||
private static GUIStyle _planetLabelStyle3;
|
|
||||||
private static GUIStyle _stateLabelStyle;
|
|
||||||
private static GUIStyle _configButtonStyle;
|
|
||||||
}
|
|
||||||
@@ -1,839 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using CruiseAssist.Commons;
|
|
||||||
using HarmonyLib;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace CruiseAssist.UI;
|
|
||||||
|
|
||||||
public static class CruiseAssistStarListUI
|
|
||||||
{
|
|
||||||
private static GUIStyle _toolbarStyle;
|
|
||||||
private static GUIStyle _nameLabelStyle;
|
|
||||||
private static GUIStyle _nameLabelHighlightStyle;
|
|
||||||
private static GUIStyle _nRangeLabelStyle;
|
|
||||||
private static GUIStyle _nRangeLabelHighlightStyle;
|
|
||||||
private static GUIStyle _nActionButtonStyle;
|
|
||||||
private static GUIStyle _nSortButtonStyle;
|
|
||||||
private static GUIStyle _verticalScrollbarStyle;
|
|
||||||
private static GUIStyle _commonButtonStyle;
|
|
||||||
private static GUIStyle _searchLabelStyle;
|
|
||||||
private static string[] _tabs = [
|
|
||||||
Strings.Get(10),
|
|
||||||
Strings.Get(11),
|
|
||||||
Strings.Get(12)
|
|
||||||
];
|
|
||||||
|
|
||||||
private static string[][] _buttonTexts =
|
|
||||||
[
|
|
||||||
[Strings.Get(13), Strings.Get(12)],
|
|
||||||
[Strings.Get(13), Strings.Get(12), Strings.Get(15)],
|
|
||||||
[Strings.Get(13), Strings.Get(16), Strings.Get(15)]
|
|
||||||
];
|
|
||||||
|
|
||||||
public static void OnInit()
|
|
||||||
{
|
|
||||||
Strings.OnLanguageChanged += LangChanged;
|
|
||||||
LangChanged();
|
|
||||||
_toolbarStyle = new GUIStyle(CruiseAssistMainUI.BaseToolbarButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 80f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_nameLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 240f,
|
|
||||||
stretchHeight = true,
|
|
||||||
fontSize = 14,
|
|
||||||
alignment = TextAnchor.MiddleLeft,
|
|
||||||
};
|
|
||||||
_nameLabelHighlightStyle = new GUIStyle(_nameLabelStyle)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
textColor = Color.cyan
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_nRangeLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 60f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 14,
|
|
||||||
alignment = TextAnchor.MiddleRight,
|
|
||||||
normal = {textColor = Color.white}
|
|
||||||
};
|
|
||||||
_nRangeLabelHighlightStyle = new GUIStyle(_nRangeLabelStyle)
|
|
||||||
{
|
|
||||||
normal =
|
|
||||||
{
|
|
||||||
textColor = Color.cyan
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_nActionButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 40f,
|
|
||||||
fixedHeight = 18f,
|
|
||||||
margin =
|
|
||||||
{
|
|
||||||
top = 6
|
|
||||||
},
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_nSortButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 20f,
|
|
||||||
fixedHeight = 18f,
|
|
||||||
margin =
|
|
||||||
{
|
|
||||||
top = 6
|
|
||||||
},
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_verticalScrollbarStyle = CruiseAssistMainUI.BaseVerticalScrollBarStyle;
|
|
||||||
_commonButtonStyle = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
|
||||||
{
|
|
||||||
fixedWidth = 80f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12
|
|
||||||
};
|
|
||||||
_searchLabelStyle = new GUIStyle(GUI.skin.label)
|
|
||||||
{
|
|
||||||
fixedWidth = 50f,
|
|
||||||
fixedHeight = 20f,
|
|
||||||
fontSize = 12,
|
|
||||||
alignment = TextAnchor.MiddleRight
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
|
|
||||||
void LangChanged()
|
|
||||||
{
|
|
||||||
_tabs = [Strings.Get(10), Strings.Get(11), Strings.Get(12)];
|
|
||||||
_buttonTexts = [[Strings.Get(13), Strings.Get(14)], [Strings.Get(13), Strings.Get(14), Strings.Get(15)], [Strings.Get(13), Strings.Get(16), Strings.Get(15)]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnGUI()
|
|
||||||
{
|
|
||||||
_wIdx = CruiseAssistMainUI.WIdx;
|
|
||||||
Rect[_wIdx] = GUILayout.Window(99030292, Rect[_wIdx], WindowFunction, "CruiseAssist - " + Strings.Get(8), CruiseAssistMainUI.WindowStyle);
|
|
||||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
|
||||||
if (Screen.width / scale < Rect[_wIdx].xMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = Screen.width / scale - Rect[_wIdx].width;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].x < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].x = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Screen.height / scale < Rect[_wIdx].yMax)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = Screen.height / scale - Rect[_wIdx].height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Rect[_wIdx].y < 0f)
|
|
||||||
{
|
|
||||||
Rect[_wIdx].y = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LastCheckWindowLeft[_wIdx] != float.MinValue)
|
|
||||||
{
|
|
||||||
if (Rect[_wIdx].x != LastCheckWindowLeft[_wIdx] || Rect[_wIdx].y != LastCheckWindowTop[_wIdx])
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
|
||||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WindowFunction(int windowId)
|
|
||||||
{
|
|
||||||
GUILayout.BeginVertical();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUI.changed = false;
|
|
||||||
var selectedIndex = GUILayout.Toolbar(ListSelected, _tabs, _toolbarStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedIndex != ListSelected)
|
|
||||||
{
|
|
||||||
ListSelected = selectedIndex;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
ScrollPos[ListSelected] = GUILayout.BeginScrollView(ScrollPos[ListSelected], GUIStyle.none, _verticalScrollbarStyle);
|
|
||||||
var selectTargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
|
|
||||||
switch (ListSelected)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
UpdateStarPlanetList();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.Label(Strings.Get(32), _searchLabelStyle);
|
|
||||||
GUI.changed = false;
|
|
||||||
_searchString = GUILayout.TextField(_searchString, CruiseAssistMainUI.BaseTextFieldStyle);
|
|
||||||
if (GUI.changed)
|
|
||||||
{
|
|
||||||
_searchResults = string.IsNullOrEmpty(_searchString)
|
|
||||||
? null
|
|
||||||
: _celestialBodies.Where(celestialBody => (celestialBody.IsPlanet ? celestialBody.PlanetData.name : celestialBody.StarData.name).Contains(_searchString)).ToList();
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
foreach (var celestialBody in _searchResults ?? _celestialBodies)
|
|
||||||
{
|
|
||||||
var selected = celestialBody.Selected;
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
GUILayout.Label(celestialBody.Name, selected ? _nameLabelHighlightStyle : _nameLabelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.Label(CruiseAssistMainUI.RangeToString(celestialBody.Range), selected ? _nRangeLabelHighlightStyle : _nRangeLabelStyle);
|
|
||||||
if (GUILayout.Button(ActionSelected[ListSelected] == 0 ? Strings.Get(17) :
|
|
||||||
celestialBody.IsPlanet ? celestialBody.InBookmark ? Strings.Get(19) : Strings.Get(18) : "-",
|
|
||||||
_nActionButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
var planetData = celestialBody.PlanetData;
|
|
||||||
if (ActionSelected[ListSelected] == 0)
|
|
||||||
{
|
|
||||||
SelectStar(celestialBody.StarData, planetData);
|
|
||||||
if (CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag)
|
|
||||||
{
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (planetData != null)
|
|
||||||
{
|
|
||||||
if (RemoveBookmark(planetData))
|
|
||||||
{
|
|
||||||
celestialBody.InBookmark = false;
|
|
||||||
var bb = History.Find(b => b.PlanetData == planetData);
|
|
||||||
if (bb != null) bb.InBookmark = false;
|
|
||||||
}
|
|
||||||
else if (Bookmark.Count <= 128 && AddBookmark(planetData))
|
|
||||||
{
|
|
||||||
celestialBody.InBookmark = true;
|
|
||||||
var bb = History.Find(b => b.PlanetData == planetData);
|
|
||||||
if (bb != null) bb.InBookmark = true;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1 or 2:
|
|
||||||
{
|
|
||||||
UpdateHistoryOrBookmarkList();
|
|
||||||
var highlighted = false;
|
|
||||||
var enumBookmark = ListSelected != 1 ? Bookmark : Enumerable.Reverse(History);
|
|
||||||
if (ListSelected == 1 && ActionSelected[ListSelected] != 2 && CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag)
|
|
||||||
{
|
|
||||||
enumBookmark = _historyDistinct;
|
|
||||||
}
|
|
||||||
|
|
||||||
var listIndex = 0;
|
|
||||||
foreach (var body in enumBookmark)
|
|
||||||
{
|
|
||||||
var planetData = body.PlanetData;
|
|
||||||
var id = planetData.id;
|
|
||||||
var selected = !highlighted && selectTargetPlanet != null && planetData.id == selectTargetPlanet.id;
|
|
||||||
if (selected)
|
|
||||||
highlighted = true;
|
|
||||||
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
var name = CruiseAssistPlugin.GetStarName(planetData.star) + " - " + CruiseAssistPlugin.GetPlanetName(planetData);
|
|
||||||
if (CruiseAssistPlugin.Conf.MarkVisitedFlag)
|
|
||||||
{
|
|
||||||
name = (planetData.factory != null ? VisitedMark : NonVisitMark) + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Label(name, selected ? _nameLabelHighlightStyle : _nameLabelStyle);
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.Label(CruiseAssistMainUI.RangeToString(body.Range), selected ? _nRangeLabelHighlightStyle : _nRangeLabelStyle);
|
|
||||||
if (ListSelected == 2 && ActionSelected[ListSelected] == 1)
|
|
||||||
{
|
|
||||||
var first = Bookmark[0] == body;
|
|
||||||
var last = Bookmark.Last() == body;
|
|
||||||
if (GUILayout.Button(last ? "-" : "↓", _nSortButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
if (!last)
|
|
||||||
{
|
|
||||||
var index = Bookmark.IndexOf(body);
|
|
||||||
Bookmark.RemoveAt(index);
|
|
||||||
Bookmark.Insert(index + 1, body);
|
|
||||||
goto outside;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button(first ? "-" : "↑", _nSortButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
if (!first)
|
|
||||||
{
|
|
||||||
var index = Bookmark.IndexOf(body);
|
|
||||||
Bookmark.RemoveAt(index);
|
|
||||||
Bookmark.Insert(index - 1, body);
|
|
||||||
goto outside;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (GUILayout.Button(
|
|
||||||
ActionSelected[ListSelected] == 0 ? Strings.Get(17) :
|
|
||||||
ActionSelected[ListSelected] == 2 ? ListSelected == 1 && listIndex == 0 ? "-" : Strings.Get(19) :
|
|
||||||
body.InBookmark ? Strings.Get(19) : Strings.Get(18), _nActionButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
switch (ActionSelected[ListSelected])
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
SelectStar(planetData.star, planetData);
|
|
||||||
if (CruiseAssistPlugin.Conf.CloseStarListWhenSetTargetPlanetFlag)
|
|
||||||
{
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if (ListSelected != 1) break;
|
|
||||||
if (HasBookmark(id))
|
|
||||||
{
|
|
||||||
RemoveBookmark(planetData);
|
|
||||||
var b = _celestialBodies.Find(b => b.IsPlanet && b.PlanetData == planetData);
|
|
||||||
if (b != null) b.InBookmark = false;
|
|
||||||
var bb = History.Find(bb => bb.PlanetData == planetData);
|
|
||||||
if (bb != null) bb.InBookmark = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bookmark.Count > 128 || !AddBookmark(planetData)) goto outside;
|
|
||||||
var b2 = _celestialBodies.Find(b => b.IsPlanet && b.PlanetData == planetData);
|
|
||||||
if (b2 != null) b2.InBookmark = true;
|
|
||||||
var bb2 = History.Find(b => b.PlanetData == planetData);
|
|
||||||
if (bb2 != null) bb2.InBookmark = true;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
goto outside;
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
switch (ListSelected)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
if (listIndex != 0)
|
|
||||||
{
|
|
||||||
if (CruiseAssistPlugin.Conf.HideDuplicateHistoryFlag)
|
|
||||||
RemoveHistoryDistinctAt(listIndex);
|
|
||||||
else
|
|
||||||
RemoveHistoryAt(History.Count - 1 - listIndex);
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
goto outside;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
RemoveBookmark(planetData);
|
|
||||||
var b = _celestialBodies.Find(b => b.IsPlanet && b.PlanetData == planetData);
|
|
||||||
if (b != null) b.InBookmark = true;
|
|
||||||
CruiseAssistMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
listIndex++;
|
|
||||||
}
|
|
||||||
outside:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndScrollView();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
GUILayout.BeginHorizontal();
|
|
||||||
if (GUILayout.Button(_buttonTexts[ListSelected][ActionSelected[ListSelected]], _commonButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
ActionSelected[ListSelected]++;
|
|
||||||
ActionSelected[ListSelected] %= _buttonTexts[ListSelected].Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
if (!CruiseAssistPlugin.Conf.HideBottomCloseButtonFlag && GUILayout.Button(Strings.Get(20), _commonButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
GUILayout.EndVertical();
|
|
||||||
if (GUI.Button(new Rect(Rect[_wIdx].width - 16f, 1f, 16f, 16f), "", CruiseAssistMainUI.CloseButtonStyle))
|
|
||||||
{
|
|
||||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
|
||||||
Show[_wIdx] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GUI.DragWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SelectStar(StarData star, PlanetData planet)
|
|
||||||
{
|
|
||||||
if (star == CruiseAssistPlugin.SelectTargetStar && planet == CruiseAssistPlugin.SelectTargetPlanet) return;
|
|
||||||
CruiseAssistPlugin.SelectTargetStar = star;
|
|
||||||
CruiseAssistPlugin.SelectTargetPlanet = planet;
|
|
||||||
var uiGame = UIRoot.instance.uiGame;
|
|
||||||
if (CruiseAssistPlugin.Conf.SelectFocusFlag && uiGame.starmap.active)
|
|
||||||
{
|
|
||||||
if (star != null)
|
|
||||||
{
|
|
||||||
var uistarmapStar = uiGame.starmap.starUIs.FirstOrDefault(s => s.star.id == star.id);
|
|
||||||
if (uistarmapStar != null)
|
|
||||||
{
|
|
||||||
UIStarmap_OnStarClick(uiGame.starmap, uistarmapStar);
|
|
||||||
uiGame.starmap.OnCursorFunction2Click(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (planet != null)
|
|
||||||
{
|
|
||||||
var uistarmapPlanet = uiGame.starmap.planetUIs.FirstOrDefault(p => p.planet.id == planet.id);
|
|
||||||
if (uistarmapPlanet != null)
|
|
||||||
{
|
|
||||||
UIStarmap_OnPlanetClick(uiGame.starmap, uistarmapPlanet);
|
|
||||||
uiGame.starmap.OnCursorFunction2Click(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (planet != null)
|
|
||||||
{
|
|
||||||
GameMain.mainPlayer.navigation.indicatorAstroId = planet.id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (star != null)
|
|
||||||
{
|
|
||||||
GameMain.mainPlayer.navigation.indicatorAstroId = star.id * 100;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GameMain.mainPlayer.navigation.indicatorAstroId = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CruiseAssistPlugin.SelectTargetAstroId = GameMain.mainPlayer.navigation.indicatorAstroId;
|
|
||||||
CruiseAssistPlugin.Extensions.ForEach(extension => extension.SetTargetAstroId(CruiseAssistPlugin.SelectTargetAstroId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UIStarmap_OnStarClick(UIStarmap starmap, UIStarmapStar star)
|
|
||||||
{
|
|
||||||
if (starmap.focusStar != star)
|
|
||||||
{
|
|
||||||
if (starmap.viewPlanet != null || (starmap.viewStar != null && star.star != starmap.viewStar))
|
|
||||||
{
|
|
||||||
starmap.screenCameraController.DisablePositionLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
starmap.focusPlanet = null;
|
|
||||||
starmap.focusStar = star;
|
|
||||||
starmap._lastClickTime = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
starmap.forceUpdateCursorView = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UIStarmap_OnPlanetClick(UIStarmap starmap, UIStarmapPlanet planet)
|
|
||||||
{
|
|
||||||
if (starmap.focusPlanet != planet)
|
|
||||||
{
|
|
||||||
if ((starmap.viewPlanet != null && planet.planet != starmap.viewPlanet) || starmap.viewStar != null)
|
|
||||||
{
|
|
||||||
starmap.screenCameraController.DisablePositionLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
starmap.focusPlanet = planet;
|
|
||||||
starmap.focusStar = null;
|
|
||||||
starmap._lastClickTime = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
starmap.forceUpdateCursorView = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void OnReset()
|
|
||||||
{
|
|
||||||
_celestialBodies = null;
|
|
||||||
_stars = null;
|
|
||||||
_localStarPlanets = null;
|
|
||||||
_selectedStarPlanets = null;
|
|
||||||
_nextCheckTick = 0;
|
|
||||||
_lastLocalStar = null;
|
|
||||||
_lastLocalPlanet = null;
|
|
||||||
_lastPlayerPos = VectorLF3.zero;
|
|
||||||
GameMain.history.onFunctionUnlocked += OnObserveUpgradeUnlocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnObserveUpgradeUnlocked(int func, double value, int _)
|
|
||||||
{
|
|
||||||
var num = (int)(value > 0.0 ? value + 0.5 : value - 0.5);
|
|
||||||
if (func == 23 && num > 2)
|
|
||||||
{
|
|
||||||
_stars = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UpdateStarPlanetList()
|
|
||||||
{
|
|
||||||
if (_stars == null)
|
|
||||||
{
|
|
||||||
LoadAllStars();
|
|
||||||
LoadLocalStarPlanets();
|
|
||||||
LoadSelectedStarPlanets();
|
|
||||||
SortCelestialBodies();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var reorder = LoadLocalStarPlanets();
|
|
||||||
if (LoadSelectedStarPlanets() || reorder) SortCelestialBodies();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UpdateHistoryOrBookmarkList()
|
|
||||||
{
|
|
||||||
if (_nextCheckTick2 > GameMain.instance.timei)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_nextCheckTick2 = GameMain.instance.timei + (GameMain.data.localPlanet == null ? 30 : 300);
|
|
||||||
foreach (var body in ListSelected == 1 ? _historyDistinct : Bookmark)
|
|
||||||
{
|
|
||||||
body.Range = (body.PlanetData.uPosition - GameMain.mainPlayer.uPosition).magnitude - body.PlanetData.realRadius;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadAllStars()
|
|
||||||
{
|
|
||||||
_stars = [];
|
|
||||||
var markVisitedFlag = CruiseAssistPlugin.Conf.MarkVisitedFlag;
|
|
||||||
foreach (var star in GameMain.galaxy.stars)
|
|
||||||
{
|
|
||||||
if (star == null) continue;
|
|
||||||
var visted = markVisitedFlag && star.planets.Any(p => p.factory != null);
|
|
||||||
_stars.Add(new CelestialBody
|
|
||||||
{
|
|
||||||
StarData = star,
|
|
||||||
Name = (visted ? VisitedMark : NonVisitMark) + CruiseAssistPlugin.GetStarName(star),
|
|
||||||
Pos = star.uPosition,
|
|
||||||
IsPlanet = false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool LoadLocalStarPlanets()
|
|
||||||
{
|
|
||||||
var localPlanet = GameMain.data.localPlanet;
|
|
||||||
if (localPlanet != null && localPlanet == _lastLocalPlanet)
|
|
||||||
{
|
|
||||||
if (GameMain.instance.timei < _nextCheckTick) return false;
|
|
||||||
_nextCheckTick = GameMain.instance.timei + 300;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_lastLocalPlanet = GameMain.data.localPlanet;
|
|
||||||
|
|
||||||
var localStar = GameMain.localStar;
|
|
||||||
var mainPlayer = GameMain.data.mainPlayer;
|
|
||||||
var currentPos = mainPlayer.uPosition;
|
|
||||||
if (localStar == _lastLocalStar)
|
|
||||||
{
|
|
||||||
if (GameMain.instance.timei < _nextCheckTick) return false;
|
|
||||||
if ((currentPos - _lastPlayerPos).sqrMagnitude < 2000.0 * 2000.0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastLocalStar = localStar;
|
|
||||||
_lastPlayerPos = currentPos;
|
|
||||||
_nextCheckTick = GameMain.instance.timei + 300;
|
|
||||||
|
|
||||||
if (localStar == null)
|
|
||||||
{
|
|
||||||
if (_localStarPlanets is { Count: 0 }) return false;
|
|
||||||
_localStarPlanets = [];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_localStarPlanets = [];
|
|
||||||
var markVisitedFlag = CruiseAssistPlugin.Conf.MarkVisitedFlag;
|
|
||||||
foreach (var planet in localStar.planets)
|
|
||||||
{
|
|
||||||
if (planet == null) continue;
|
|
||||||
var visted = markVisitedFlag && planet.factory != null;
|
|
||||||
_localStarPlanets.Add(new CelestialBody
|
|
||||||
{
|
|
||||||
PlanetData = planet,
|
|
||||||
Name = (visted ? VisitedMark : NonVisitMark) + CruiseAssistPlugin.GetPlanetName(planet),
|
|
||||||
Pos = planet.uPosition,
|
|
||||||
IsPlanet = true,
|
|
||||||
InBookmark = HasBookmark(planet.id)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool LoadSelectedStarPlanets()
|
|
||||||
{
|
|
||||||
var selectedStar = CruiseAssistPlugin.SelectTargetStar;
|
|
||||||
if (selectedStar == _lastSelectedStar)
|
|
||||||
{
|
|
||||||
if (_selectedStarPlanets != null) return false;
|
|
||||||
_selectedStarPlanets = [];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_lastSelectedStar = selectedStar;
|
|
||||||
if (selectedStar == null || selectedStar == GameMain.localStar)
|
|
||||||
{
|
|
||||||
if (_selectedStarPlanets is { Count: 0 }) return false;
|
|
||||||
_selectedStarPlanets = [];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = (selectedStar.uPosition - GameMain.mainPlayer.uPosition).magnitude;
|
|
||||||
if (GameMain.history.universeObserveLevel < (range >= 14400000.0 ? 4 : 3))
|
|
||||||
{
|
|
||||||
if (_selectedStarPlanets is { Count: 0 }) return false;
|
|
||||||
_selectedStarPlanets = [];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_selectedStarPlanets = [];
|
|
||||||
var markVisitedFlag = CruiseAssistPlugin.Conf.MarkVisitedFlag;
|
|
||||||
foreach (var planet in selectedStar.planets)
|
|
||||||
{
|
|
||||||
if (planet == null) continue;
|
|
||||||
var visted = markVisitedFlag && planet.factory != null;
|
|
||||||
_selectedStarPlanets.Add(new CelestialBody
|
|
||||||
{
|
|
||||||
PlanetData = planet,
|
|
||||||
Name = (visted ? VisitedMark : NonVisitMark) + CruiseAssistPlugin.GetPlanetName(planet),
|
|
||||||
Pos = planet.uPosition,
|
|
||||||
IsPlanet = true,
|
|
||||||
InBookmark = HasBookmark(planet.id)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SortCelestialBodies()
|
|
||||||
{
|
|
||||||
_celestialBodies = [.._stars, .._localStarPlanets, .._selectedStarPlanets];
|
|
||||||
var uPos = GameMain.mainPlayer.uPosition;
|
|
||||||
var selectedId = CruiseAssistPlugin.SelectTargetPlanet?.id ?? 0;
|
|
||||||
var selectedStarId = CruiseAssistPlugin.SelectTargetStar?.id ?? 0;
|
|
||||||
foreach (var body in _celestialBodies)
|
|
||||||
{
|
|
||||||
if (body.IsPlanet)
|
|
||||||
{
|
|
||||||
body.Pos = body.PlanetData.uPosition;
|
|
||||||
body.Range = (body.Pos - uPos).magnitude - body.PlanetData.realRadius;
|
|
||||||
body.Selected = body.PlanetData.id == selectedId || (body.PlanetData.star?.id ?? 0) == selectedStarId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
body.Pos = body.StarData.uPosition;
|
|
||||||
body.Range = (body.Pos - uPos).magnitude - (body.StarData.viewRadius - 120f);
|
|
||||||
body.Selected = body.StarData.id == selectedStarId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_celestialBodies.Sort((s1, s2) => s1.Range.CompareTo(s2.Range));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddHistory(PlanetData planet)
|
|
||||||
{
|
|
||||||
if (History.Count >= 128)
|
|
||||||
{
|
|
||||||
History.RemoveAt(0);
|
|
||||||
}
|
|
||||||
var b = History.Find(b => b.PlanetData == planet);
|
|
||||||
if (b != null)
|
|
||||||
History.Add(b);
|
|
||||||
else
|
|
||||||
History.Add(new BookmarkCelestialBody
|
|
||||||
{
|
|
||||||
PlanetData = planet,
|
|
||||||
Range = (planet.uPosition - GameMain.mainPlayer.uPosition).magnitude - planet.realRadius,
|
|
||||||
InBookmark = HasBookmark(planet.id)
|
|
||||||
});
|
|
||||||
_historyDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoveHistoryAt(int index)
|
|
||||||
{
|
|
||||||
History.RemoveAt(index);
|
|
||||||
_historyDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoveHistoryDistinctAt(int index)
|
|
||||||
{
|
|
||||||
if (index < 0 || index >= _historyDistinct.Count) return;
|
|
||||||
var body = _historyDistinct[index];
|
|
||||||
History.RemoveAll(b => b == body);
|
|
||||||
_historyDistinct.RemoveAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ClearHistory()
|
|
||||||
{
|
|
||||||
History.Clear();
|
|
||||||
_historyDistinct.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int LastHistoryId() => History.Count > 0 ? History.Last().PlanetData.id : 0;
|
|
||||||
|
|
||||||
public static string HistoryToString() => History.Join(body => body.PlanetData.id.ToString(), ",");
|
|
||||||
|
|
||||||
public static void HistoryFromString(string str)
|
|
||||||
{
|
|
||||||
Bookmark.Clear();
|
|
||||||
foreach (var s in str.Split(','))
|
|
||||||
{
|
|
||||||
if (!int.TryParse(s, out var id)) continue;
|
|
||||||
var planet = GameMain.galaxy.PlanetById(id);
|
|
||||||
if (planet == null) continue;
|
|
||||||
var b = History.Find(b => b.PlanetData == planet);
|
|
||||||
if (b != null)
|
|
||||||
{
|
|
||||||
History.Add(b);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
History.Add(new BookmarkCelestialBody
|
|
||||||
{
|
|
||||||
PlanetData = planet,
|
|
||||||
Range = (planet.uPosition - GameMain.mainPlayer.uPosition).magnitude - planet.realRadius,
|
|
||||||
InBookmark = HasBookmark(planet.id)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_historyDistinct = Enumerable.Reverse(History).Distinct().ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool HasBookmark(int id) => BookmarkSet.Contains(id);
|
|
||||||
|
|
||||||
private static bool AddBookmark(PlanetData planet)
|
|
||||||
{
|
|
||||||
if (!BookmarkSet.Add(planet.id)) return false;
|
|
||||||
Bookmark.Add(new BookmarkCelestialBody
|
|
||||||
{
|
|
||||||
PlanetData = planet,
|
|
||||||
Range = (planet.uPosition - GameMain.mainPlayer.uPosition).magnitude - planet.realRadius,
|
|
||||||
InBookmark = true
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool RemoveBookmark(PlanetData planet)
|
|
||||||
{
|
|
||||||
var id = planet.id;
|
|
||||||
if (!BookmarkSet.Remove(id)) return false;
|
|
||||||
Bookmark.RemoveAll(body => body.PlanetData.id == id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveBookmarkAt(int index)
|
|
||||||
{
|
|
||||||
var body = Bookmark[index];
|
|
||||||
BookmarkSet.Remove(body.PlanetData.id);
|
|
||||||
Bookmark.RemoveAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ClearBookmark()
|
|
||||||
{
|
|
||||||
Bookmark.Clear();
|
|
||||||
BookmarkSet.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string BookmarkToString() => Bookmark.Join(body => body.PlanetData.id.ToString(), ",");
|
|
||||||
|
|
||||||
public static void BookmarkFromString(string str)
|
|
||||||
{
|
|
||||||
Bookmark.Clear();
|
|
||||||
foreach (var s in str.Split(','))
|
|
||||||
{
|
|
||||||
if (!int.TryParse(s, out var id)) continue;
|
|
||||||
var planet = GameMain.galaxy.PlanetById(id);
|
|
||||||
if (planet == null) continue;
|
|
||||||
AddBookmark(planet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CelestialBody
|
|
||||||
{
|
|
||||||
public StarData StarData;
|
|
||||||
public PlanetData PlanetData;
|
|
||||||
public string Name;
|
|
||||||
public VectorLF3 Pos;
|
|
||||||
public double Range;
|
|
||||||
public bool IsPlanet;
|
|
||||||
public bool Selected;
|
|
||||||
public bool InBookmark;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BookmarkCelestialBody
|
|
||||||
{
|
|
||||||
public PlanetData PlanetData;
|
|
||||||
public double Range;
|
|
||||||
public bool InBookmark;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<CelestialBody> _celestialBodies;
|
|
||||||
private static List<CelestialBody> _stars;
|
|
||||||
private static List<CelestialBody> _localStarPlanets;
|
|
||||||
private static List<CelestialBody> _selectedStarPlanets;
|
|
||||||
private static List<CelestialBody> _searchResults;
|
|
||||||
private static string _searchString;
|
|
||||||
|
|
||||||
private static readonly List<BookmarkCelestialBody> History = [];
|
|
||||||
private static List<BookmarkCelestialBody> _historyDistinct = [];
|
|
||||||
private static readonly List<BookmarkCelestialBody> Bookmark = [];
|
|
||||||
private static readonly HashSet<int> BookmarkSet = [];
|
|
||||||
|
|
||||||
private static long _nextCheckTick;
|
|
||||||
private static long _nextCheckTick2;
|
|
||||||
private static StarData _lastLocalStar;
|
|
||||||
private static PlanetData _lastLocalPlanet;
|
|
||||||
private static StarData _lastSelectedStar;
|
|
||||||
private static VectorLF3 _lastPlayerPos = VectorLF3.zero;
|
|
||||||
private static int _wIdx;
|
|
||||||
public const float WindowWidth = 400f;
|
|
||||||
public const float WindowHeight = 480f;
|
|
||||||
public static readonly bool[] Show = new bool[2];
|
|
||||||
|
|
||||||
public static readonly Rect[] Rect =
|
|
||||||
[
|
|
||||||
new Rect(0f, 0f, 400f, 480f),
|
|
||||||
new Rect(0f, 0f, 400f, 480f)
|
|
||||||
];
|
|
||||||
|
|
||||||
public static int ListSelected;
|
|
||||||
private static readonly int[] ActionSelected = new int[3];
|
|
||||||
private static readonly float[] LastCheckWindowLeft = [float.MinValue, float.MinValue];
|
|
||||||
private static readonly float[] LastCheckWindowTop = [float.MinValue, float.MinValue];
|
|
||||||
|
|
||||||
private static readonly Vector2[] ScrollPos =
|
|
||||||
[
|
|
||||||
Vector2.zero,
|
|
||||||
Vector2.zero,
|
|
||||||
Vector2.zero
|
|
||||||
];
|
|
||||||
|
|
||||||
private const string VisitedMark = "● ";
|
|
||||||
private const string NonVisitMark = "";
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
using System;
|
|
||||||
using HarmonyLib;
|
|
||||||
|
|
||||||
namespace CruiseAssist.UI;
|
|
||||||
|
|
||||||
public static class Strings
|
|
||||||
{
|
|
||||||
private static readonly string[] EngUs = [
|
|
||||||
// 0
|
|
||||||
"Target\n System:",
|
|
||||||
"Target\n Planet:",
|
|
||||||
"Cruise Assist Disabled.",
|
|
||||||
"Cruise Assist Inactive.",
|
|
||||||
"Cruise Assist Active.",
|
|
||||||
// 5
|
|
||||||
"Config",
|
|
||||||
"Disable",
|
|
||||||
"Enable",
|
|
||||||
"StarList",
|
|
||||||
"Cancel",
|
|
||||||
// 10
|
|
||||||
"Normal",
|
|
||||||
"History",
|
|
||||||
"Bookmark",
|
|
||||||
"Target",
|
|
||||||
"SET",
|
|
||||||
// 15
|
|
||||||
"Delete",
|
|
||||||
"Sort",
|
|
||||||
"SET",
|
|
||||||
"ADD",
|
|
||||||
"DEL",
|
|
||||||
// 20
|
|
||||||
"Close",
|
|
||||||
"Main Window Style :",
|
|
||||||
"UI Scale :",
|
|
||||||
"Mark the visited system and planet.",
|
|
||||||
"Focus when select target.",
|
|
||||||
// 25
|
|
||||||
"Hide duplicate history.",
|
|
||||||
"Disable lock cursor when starting sail mode.",
|
|
||||||
"Show main window when target selected, even not sail mode.",
|
|
||||||
"Close StarList when set target planet.",
|
|
||||||
"Hide bottom close button.",
|
|
||||||
// 30
|
|
||||||
"FULL",
|
|
||||||
"MINI",
|
|
||||||
"Search: ",
|
|
||||||
];
|
|
||||||
|
|
||||||
private static readonly string[] ZhoCn =
|
|
||||||
[
|
|
||||||
// 0
|
|
||||||
"目标\n 星系:",
|
|
||||||
"目标\n 行星:",
|
|
||||||
"Cruise Assist 已禁用",
|
|
||||||
"Cruise Assist 未在工作",
|
|
||||||
"Cruise Assist 正在工作",
|
|
||||||
// 5
|
|
||||||
"设置",
|
|
||||||
"禁用",
|
|
||||||
"启用",
|
|
||||||
"天体列表",
|
|
||||||
"取消",
|
|
||||||
// 10
|
|
||||||
"常规",
|
|
||||||
"历史记录",
|
|
||||||
"书签",
|
|
||||||
"目标",
|
|
||||||
"设置",
|
|
||||||
// 15
|
|
||||||
"删除",
|
|
||||||
"排序",
|
|
||||||
"选择",
|
|
||||||
"添加",
|
|
||||||
"删除",
|
|
||||||
// 20
|
|
||||||
"关闭",
|
|
||||||
"主窗口样式 :",
|
|
||||||
"界面缩放 :",
|
|
||||||
"标记已访问的星系和行星",
|
|
||||||
"设置目标时聚焦该天体",
|
|
||||||
// 25
|
|
||||||
"隐藏重复历史记录",
|
|
||||||
"进入航行模式时不锁定鼠标光标",
|
|
||||||
"选定目标天体时即使不在航行模式也显示主窗口",
|
|
||||||
"设置目标后关闭天体列表窗口",
|
|
||||||
"隐藏底部关闭按钮",
|
|
||||||
// 30
|
|
||||||
"完整",
|
|
||||||
"迷你",
|
|
||||||
"搜索:",
|
|
||||||
];
|
|
||||||
|
|
||||||
public static Action OnLanguageChanged;
|
|
||||||
|
|
||||||
private static string[] _langStr = EngUs;
|
|
||||||
|
|
||||||
public static string Get(int index) => _langStr[index];
|
|
||||||
|
|
||||||
[HarmonyPostfix]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.LoadSettings))]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.LoadLanguage))]
|
|
||||||
[HarmonyPatch(typeof(Localization), nameof(Localization.NotifyLanguageChange))]
|
|
||||||
private static void Localization_LanguageChanged_Postfix()
|
|
||||||
{
|
|
||||||
var newstr = Localization.Languages[Localization.currentLanguageIndex].lcId switch
|
|
||||||
{
|
|
||||||
2052 => ZhoCn,
|
|
||||||
_ => EngUs
|
|
||||||
};
|
|
||||||
if (newstr == _langStr) return;
|
|
||||||
_langStr = newstr;
|
|
||||||
OnLanguageChanged?.Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "CruiseAssist",
|
|
||||||
"version_number": "0.1.0",
|
|
||||||
"website_url": "https://github.com/soarqin/DSP_Mods_TO/tree/master/CruiseAssist",
|
|
||||||
"description": "Adjust the orientation to the target planet or star when moving between planets or star systems.",
|
|
||||||
"dependencies": [
|
|
||||||
"xiaoye97-BepInEx-5.4.17"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,7 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompressSave", "CompressSave\CompressSave.csproj", "{A283A918-207F-4DD7-A098-F99EBE610558}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompressSave", "CompressSave\CompressSave.csproj", "{A283A918-207F-4DD7-A098-F99EBE610558}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CruiseAssist", "CruiseAssist\CruiseAssist.csproj", "{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XianTu", "XianTu\XianTu.csproj", "{AD871765-1FBB-4BAE-B839-C0F35DEF20C2}"
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoPilot", "AutoPilot\AutoPilot.csproj", "{8F1E9D98-009B-4618-8827-5BFE7E0E2DD0}"
|
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
|
||||||
{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB} = {DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -19,13 +14,9 @@ Global
|
|||||||
{A283A918-207F-4DD7-A098-F99EBE610558}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A283A918-207F-4DD7-A098-F99EBE610558}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A283A918-207F-4DD7-A098-F99EBE610558}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A283A918-207F-4DD7-A098-F99EBE610558}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A283A918-207F-4DD7-A098-F99EBE610558}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A283A918-207F-4DD7-A098-F99EBE610558}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{AD871765-1FBB-4BAE-B839-C0F35DEF20C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{AD871765-1FBB-4BAE-B839-C0F35DEF20C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{AD871765-1FBB-4BAE-B839-C0F35DEF20C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{DC0FFF11-FFD8-4600-9CDE-8DB6F00F38EB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{AD871765-1FBB-4BAE-B839-C0F35DEF20C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{8F1E9D98-009B-4618-8827-5BFE7E0E2DD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{8F1E9D98-009B-4618-8827-5BFE7E0E2DD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{8F1E9D98-009B-4618-8827-5BFE7E0E2DD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{8F1E9D98-009B-4618-8827-5BFE7E0E2DD0}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
internal class ABEmbeddedAssetsLoad : ABLoad
|
||||||
|
{
|
||||||
|
public ABEmbeddedAssetsLoad(string filename, string assetsNamespace = null)
|
||||||
|
{
|
||||||
|
var stackTrace = new StackTrace();
|
||||||
|
var frame = stackTrace.GetFrame(1);
|
||||||
|
var assembly = frame.GetMethod().DeclaringType.Assembly;
|
||||||
|
var flag = assetsNamespace == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
assetsNamespace = assembly.FullName.Split([','])[0];
|
||||||
|
}
|
||||||
|
LoadAssetsFromEmbedded(filename, assetsNamespace, assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadAssetsFromEmbedded(string filename, string assetsNamespace, Assembly assembly)
|
||||||
|
{
|
||||||
|
var text = assetsNamespace + "." + filename;
|
||||||
|
var manifestResourceStream = assembly.GetManifestResourceStream(text);
|
||||||
|
var flag = manifestResourceStream == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.Log(string.Concat(["在", assembly.FullName, "找不到内嵌的资源", text, ",请检查内嵌资源中是否有它:"]));
|
||||||
|
foreach (var text2 in assembly.GetManifestResourceNames())
|
||||||
|
{
|
||||||
|
Debug.Log(text2);
|
||||||
|
}
|
||||||
|
Debug.Log("------------------------");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Ab = AssetBundle.LoadFromStream(manifestResourceStream);
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ABEmbeddedAssetsLoad(string filename, string dllFilepath, string dllNamespace)
|
||||||
|
{
|
||||||
|
var assembly = Assembly.LoadFrom(dllFilepath);
|
||||||
|
LoadAssetsFromEmbedded(filename, dllNamespace, assembly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
internal class ABFileLoad : ABLoad
|
||||||
|
{
|
||||||
|
public ABFileLoad(string filepath)
|
||||||
|
{
|
||||||
|
Ab = AssetBundle.LoadFromFile(filepath);
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
public abstract class ABLoad : ILoad
|
||||||
|
{
|
||||||
|
protected void Init()
|
||||||
|
{
|
||||||
|
foreach (var text in Ab.GetAllAssetNames())
|
||||||
|
{
|
||||||
|
var flag = text.Contains("prefabs");
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
PrefabPath = text.Substring(0, text.IndexOf("prefabs", StringComparison.OrdinalIgnoreCase));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject LoadPrefab(string path)
|
||||||
|
{
|
||||||
|
var flag = Ab == null;
|
||||||
|
GameObject gameObject;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.Log("内嵌的AB包没有找到");
|
||||||
|
gameObject = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag2 = path.Contains("/");
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
path = Path.Combine(PrefabPath, path);
|
||||||
|
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
path += ".prefab";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gameObject = Ab.LoadAsset<GameObject>(path);
|
||||||
|
}
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LoadText(string path)
|
||||||
|
{
|
||||||
|
var flag = Ab == null;
|
||||||
|
string text;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.Log("内嵌的AB包没有找到");
|
||||||
|
text = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag2 = path.Contains("/");
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
path = Path.Combine(_txtPath, path);
|
||||||
|
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
path += ".prefab";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text = Ab.LoadAsset<TextAsset>(path).text;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string PrefabPath;
|
||||||
|
|
||||||
|
protected AssetBundle Ab;
|
||||||
|
|
||||||
|
private string _txtPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
public static class ABLoader
|
||||||
|
{
|
||||||
|
public static ABLoad LoadFromFile(string abFilename, string dir)
|
||||||
|
{
|
||||||
|
var text = Path.Combine(dir, abFilename);
|
||||||
|
return new ABFileLoad(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ABLoad LoadFromFile(string filepath)
|
||||||
|
{
|
||||||
|
return new ABFileLoad(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ABLoad LoadFromEmbeddedAssets(string abFilename, string defaultNamespace = null)
|
||||||
|
{
|
||||||
|
return new ABEmbeddedAssetsLoad(abFilename, defaultNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ABLoad LoadFromDll(string abFilename, string dllFilepath, string dllDefaultNameSpace)
|
||||||
|
{
|
||||||
|
return new ABEmbeddedAssetsLoad(abFilename, dllFilepath, dllDefaultNameSpace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
XianTu/AssetsLoader/ILoad.cs
Normal file
11
XianTu/AssetsLoader/ILoad.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
public interface ILoad
|
||||||
|
{
|
||||||
|
GameObject LoadPrefab(string path);
|
||||||
|
|
||||||
|
string LoadText(string path);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace AssetsLoader
|
||||||
|
{
|
||||||
|
public class ResourceLoad : ILoad
|
||||||
|
{
|
||||||
|
public GameObject LoadPrefab(string path)
|
||||||
|
{
|
||||||
|
return Resources.Load<GameObject>(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LoadText(string path)
|
||||||
|
{
|
||||||
|
return Resources.Load<TextAsset>(path).text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
156
XianTu/BlueTuUIData.cs
Normal file
156
XianTu/BlueTuUIData.cs
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu
|
||||||
|
{
|
||||||
|
public class BlueTuUIData
|
||||||
|
{
|
||||||
|
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||||
|
public event Action OnValueChange;
|
||||||
|
|
||||||
|
public static BlueTuUIData Instance { get; } = new();
|
||||||
|
|
||||||
|
public Vector3 Bias
|
||||||
|
{
|
||||||
|
get => _bias;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_bias = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 Scale
|
||||||
|
{
|
||||||
|
get => _scale;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scale = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 Pivot
|
||||||
|
{
|
||||||
|
get => _pivot;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_pivot = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float LayerHeight
|
||||||
|
{
|
||||||
|
get => _layerHeight;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_layerHeight = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Rotate
|
||||||
|
{
|
||||||
|
get => _rotate;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_rotate = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LayerNumber
|
||||||
|
{
|
||||||
|
get => _layerNumber;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var flag = LayerNumber < 1;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
_layerNumber = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enable
|
||||||
|
{
|
||||||
|
get => _enable;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_enable = value;
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlueTuUIData Clone()
|
||||||
|
{
|
||||||
|
var blueTuUIData = (BlueTuUIData)MemberwiseClone();
|
||||||
|
blueTuUIData.OnValueChange = null;
|
||||||
|
return blueTuUIData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
var blueTuUIData = new BlueTuUIData();
|
||||||
|
_bias = blueTuUIData._bias;
|
||||||
|
_scale = blueTuUIData._scale;
|
||||||
|
_pivot = blueTuUIData._pivot;
|
||||||
|
_layerHeight = blueTuUIData._layerHeight;
|
||||||
|
_layerNumber = blueTuUIData._layerNumber;
|
||||||
|
_rotate = blueTuUIData._rotate;
|
||||||
|
_enable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Vector3 _bias = new(0f, 0f, 0f);
|
||||||
|
|
||||||
|
private Vector3 _scale = new(1f, 1f, 1f);
|
||||||
|
|
||||||
|
private Vector3 _pivot = new(0f, 0f, 0f);
|
||||||
|
|
||||||
|
private float _layerHeight = 5f;
|
||||||
|
|
||||||
|
private int _layerNumber = 1;
|
||||||
|
|
||||||
|
private float _rotate;
|
||||||
|
|
||||||
|
private bool _enable = true;
|
||||||
|
|
||||||
|
public Action OnBuildBtn;
|
||||||
|
|
||||||
|
public Action OnResetBtn;
|
||||||
|
|
||||||
|
public Action OnCopyBtn;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
XianTu/EmbeddedFileLoad.cs
Normal file
41
XianTu/EmbeddedFileLoad.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using AssetsLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu
|
||||||
|
{
|
||||||
|
internal class EmbeddedFileLoad : ILoad
|
||||||
|
{
|
||||||
|
public EmbeddedFileLoad(string assetsNamespace = null)
|
||||||
|
{
|
||||||
|
var stackTrace = new StackTrace();
|
||||||
|
var frame = stackTrace.GetFrame(1);
|
||||||
|
var assembly = frame.GetMethod().DeclaringType.Assembly;
|
||||||
|
var flag = assetsNamespace == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
assetsNamespace = assembly.FullName.Split([','])[0];
|
||||||
|
}
|
||||||
|
this._assetsNamespace = assetsNamespace;
|
||||||
|
this._assembly = assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject LoadPrefab(string path)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LoadText(string path)
|
||||||
|
{
|
||||||
|
using var manifestResourceStream = _assembly.GetManifestResourceStream(_assetsNamespace + "." + path.Replace('/', '.'));
|
||||||
|
using var streamReader = new StreamReader(manifestResourceStream);
|
||||||
|
return streamReader.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _assetsNamespace;
|
||||||
|
|
||||||
|
private readonly Assembly _assembly;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
XianTu/FileLoad.cs
Normal file
22
XianTu/FileLoad.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.IO;
|
||||||
|
using AssetsLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu
|
||||||
|
{
|
||||||
|
internal class FileLoad(string dirPath) : ILoad
|
||||||
|
{
|
||||||
|
|
||||||
|
public GameObject LoadPrefab(string path)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LoadText(string path)
|
||||||
|
{
|
||||||
|
return File.ReadAllText(Path.Combine(_dirPath, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _dirPath = dirPath ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
1
XianTu/FoundationBlueTu.txt
Normal file
1
XianTu/FoundationBlueTu.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
BLUEPRINT:0,10,0,0,0,0,0,0,637975354775775693,0.9.26.13034,OnBelt,"H4sIAAAAAAAAC2NkQAWMUAxh/2dgWABlMsKFEWoPSG5DZZs4g/BFdmWG/1CAZBwDAHYxJApsAAAA"DEB2D60B60B70FA664332C993B2453B2
|
||||||
64
XianTu/LoadManager.cs
Normal file
64
XianTu/LoadManager.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AssetsLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace XianTu;
|
||||||
|
|
||||||
|
public class LoadManager : Singleton<LoadManager>
|
||||||
|
{
|
||||||
|
public void SetLoader(ILoad loader)
|
||||||
|
{
|
||||||
|
_loaders = [loader];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddLoader(ILoad loader)
|
||||||
|
{
|
||||||
|
_loaders.Insert(0, loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GameObject LoadPrefab(string path)
|
||||||
|
{
|
||||||
|
foreach (var load in _loaders)
|
||||||
|
{
|
||||||
|
var gameObject = load.LoadPrefab(path);
|
||||||
|
var flag = gameObject != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject LoadPrefab(string path, Transform parent)
|
||||||
|
{
|
||||||
|
foreach (var load in _loaders)
|
||||||
|
{
|
||||||
|
var gameObject = load.LoadPrefab(path);
|
||||||
|
var flag = gameObject != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
return Object.Instantiate(gameObject, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LoadText(string path)
|
||||||
|
{
|
||||||
|
foreach (var load in _loaders)
|
||||||
|
{
|
||||||
|
var text = load.LoadText(path);
|
||||||
|
var flag = text != "";
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ILoad> _loaders = [new ResourceLoad()];
|
||||||
|
}
|
||||||
6
XianTu/Properties/AssemblyInfo.cs
Normal file
6
XianTu/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
413
XianTu/Scripts/DataController/BlueTuController.cs
Normal file
413
XianTu/Scripts/DataController/BlueTuController.cs
Normal file
@@ -0,0 +1,413 @@
|
|||||||
|
using System;
|
||||||
|
using ToolScripts;
|
||||||
|
using UnityEngine;
|
||||||
|
using XianTu.UI;
|
||||||
|
|
||||||
|
namespace XianTu.Scripts.DataController
|
||||||
|
{
|
||||||
|
internal class BlueTuController
|
||||||
|
{
|
||||||
|
public BlueTuController()
|
||||||
|
{
|
||||||
|
_oldData = BlueTuUIData.Instance.Clone();
|
||||||
|
_data = BlueTuUIData.Instance;
|
||||||
|
Init_OnUIOpen();
|
||||||
|
_data.OnValueChange += OnUserChangeData;
|
||||||
|
var blueTuUIData = _data;
|
||||||
|
blueTuUIData.OnBuildBtn = (Action)Delegate.Combine(blueTuUIData.OnBuildBtn, new Action(OnUserBuildDetermine));
|
||||||
|
var blueTuUIData2 = _data;
|
||||||
|
blueTuUIData2.OnCopyBtn = (Action)Delegate.Combine(blueTuUIData2.OnCopyBtn, new Action(OnUserCopy));
|
||||||
|
var blueTuUIData3 = _data;
|
||||||
|
blueTuUIData3.OnResetBtn = (Action)Delegate.Combine(blueTuUIData3.OnResetBtn, new Action(OnReset));
|
||||||
|
var blueprintData = BlueTuDatabase.Load("FoundationBlueTu");
|
||||||
|
_foundation = blueprintData.buildings[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUserCopy()
|
||||||
|
{
|
||||||
|
_actionBuild.blueprintClipboard = _bPaste.blueprint;
|
||||||
|
ResetBuildDuiDie();
|
||||||
|
_bPaste.RefreshBlueprintUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init_OnUIOpen()
|
||||||
|
{
|
||||||
|
UIManager.Instance.CanvasMonoEvent.onEnableEvent.AddListener(OnReset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReset()
|
||||||
|
{
|
||||||
|
Player = GameMain.mainPlayer;
|
||||||
|
var flag = Player == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
_data.Enable = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_playerController = Player.controller;
|
||||||
|
_actionBuild = PlayerController.actionBuild;
|
||||||
|
var flag2 = _actionBuild != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
_activeTool = _actionBuild.activeTool;
|
||||||
|
var buildToolBlueprintPaste = _activeTool as BuildTool_BlueprintPaste;
|
||||||
|
var flag3 = buildToolBlueprintPaste != null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
_bPaste = buildToolBlueprintPaste;
|
||||||
|
var mouseRay = _actionBuild.activeTool.mouseRay;
|
||||||
|
_defaultMouseRay = new Ray(mouseRay.origin, mouseRay.direction);
|
||||||
|
var flag4 = buildToolBlueprintPaste.blueprint != _blueprint;
|
||||||
|
if (flag4)
|
||||||
|
{
|
||||||
|
_templateBlueTu = buildToolBlueprintPaste.blueprint.Clone();
|
||||||
|
_blueprint = buildToolBlueprintPaste.blueprint;
|
||||||
|
}
|
||||||
|
_oldData = new BlueTuUIData();
|
||||||
|
_data.Reset();
|
||||||
|
_data.Enable = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_data.Enable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Player Player { get; set; }
|
||||||
|
|
||||||
|
private void OnUserBuildDetermine()
|
||||||
|
{
|
||||||
|
var flag = _actionBuild.activeTool != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var buildToolBlueprintPaste = _actionBuild.activeTool as BuildTool_BlueprintPaste;
|
||||||
|
var flag2 = buildToolBlueprintPaste != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
var flag3 = buildToolBlueprintPaste.CheckBuildConditionsPrestage();
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
ResetBuildDuiDie();
|
||||||
|
Build(buildToolBlueprintPaste);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetBuildDuiDie()
|
||||||
|
{
|
||||||
|
var buildToolBlueprintPaste = _bPaste;
|
||||||
|
BlueprintBuilding blueprintBuilding = null;
|
||||||
|
foreach (var blueprintBuilding2 in buildToolBlueprintPaste.blueprint.buildings)
|
||||||
|
{
|
||||||
|
var flag = Math.Abs(blueprintBuilding2.localOffset_z) < 1.5f;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var itemProto = LDB.items.Select(blueprintBuilding2.itemId);
|
||||||
|
Debug.Log($"基底查验:{itemProto.name}.{itemProto.ID}:{blueprintBuilding2.localOffset_x:2f}, {blueprintBuilding2.localOffset_y:2f}, {blueprintBuilding2.localOffset_z:2f}");
|
||||||
|
blueprintBuilding = blueprintBuilding2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var flag2 = blueprintBuilding == null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
Debug.Log("没有基底");
|
||||||
|
}
|
||||||
|
var flag3 = blueprintBuilding == null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
var buildings2 = _bPaste.blueprint.buildings;
|
||||||
|
var array = new BlueprintBuilding[_bPaste.blueprint.buildings.Length + 1];
|
||||||
|
_bPaste.blueprint.buildings = array;
|
||||||
|
buildings2.CopyTo(array, 0);
|
||||||
|
blueprintBuilding = _foundation;
|
||||||
|
blueprintBuilding.index = buildings2.Length;
|
||||||
|
blueprintBuilding.localOffset_z = -0.5f;
|
||||||
|
array[buildings2.Length] = blueprintBuilding;
|
||||||
|
}
|
||||||
|
foreach (var blueprintBuilding3 in _bPaste.blueprint.buildings)
|
||||||
|
{
|
||||||
|
var flag4 = blueprintBuilding3.IsBelt();
|
||||||
|
if (!flag4)
|
||||||
|
{
|
||||||
|
var flag5 = blueprintBuilding3.IsSlot();
|
||||||
|
if (!flag5)
|
||||||
|
{
|
||||||
|
var flag6 = blueprintBuilding3 == blueprintBuilding;
|
||||||
|
if (!flag6)
|
||||||
|
{
|
||||||
|
blueprintBuilding3.inputToSlot = 14;
|
||||||
|
blueprintBuilding3.outputFromSlot = 15;
|
||||||
|
blueprintBuilding3.inputFromSlot = 15;
|
||||||
|
blueprintBuilding3.outputToSlot = 14;
|
||||||
|
blueprintBuilding3.inputObj = blueprintBuilding;
|
||||||
|
blueprintBuilding3.inputFromSlot = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_bPaste.bpCursor = _bPaste.blueprint.buildings.Length;
|
||||||
|
_bPaste.buildPreviews.Clear();
|
||||||
|
_bPaste.ResetStates();
|
||||||
|
_BuildTool_BluePrint_OnTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Build(BuildTool_BlueprintPaste bp)
|
||||||
|
{
|
||||||
|
PlayerController.cmd.stage = 1;
|
||||||
|
bp.GenerateBlueprintGratBoxes();
|
||||||
|
bp.DeterminePreviewsPrestage(true);
|
||||||
|
bp.ActiveColliders(_actionBuild.model);
|
||||||
|
bp.buildCondition = bp.CheckBuildConditions();
|
||||||
|
bp.DeterminePreviews();
|
||||||
|
bp.DeactiveColliders(_actionBuild.model);
|
||||||
|
var buildCondition = bp.buildCondition;
|
||||||
|
if (buildCondition)
|
||||||
|
{
|
||||||
|
bp.CreatePrebuilds();
|
||||||
|
bp.ResetStates();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bp.isDragging = false;
|
||||||
|
bp.startGroundPosSnapped = bp.castGroundPosSnapped;
|
||||||
|
_BuildTool_BluePrint_OnTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUserChangeData()
|
||||||
|
{
|
||||||
|
var flag = !_data.Enable;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var flag2 = PlayerController == null;
|
||||||
|
if (!flag2)
|
||||||
|
{
|
||||||
|
var flag3 = _actionBuild == null;
|
||||||
|
if (!flag3)
|
||||||
|
{
|
||||||
|
var flag4 = _bPaste == null;
|
||||||
|
if (!flag4)
|
||||||
|
{
|
||||||
|
var vector = _data.Bias - _oldData.Bias;
|
||||||
|
var num = _data.LayerHeight - _oldData.LayerHeight;
|
||||||
|
var num2 = _data.LayerNumber - _oldData.LayerNumber;
|
||||||
|
var num3 = _data.Rotate - _oldData.Rotate;
|
||||||
|
var flag5 = _actionBuild != null;
|
||||||
|
if (flag5)
|
||||||
|
{
|
||||||
|
CtrlLayerNumber(num2);
|
||||||
|
CtrlLayerHeight(num);
|
||||||
|
CtrlRotate(num3);
|
||||||
|
CtrlBiasData(vector);
|
||||||
|
CtrlScale();
|
||||||
|
_BuildTool_BluePrint_OnTick();
|
||||||
|
}
|
||||||
|
_oldData.Scale = _data.Scale;
|
||||||
|
_oldData.Pivot = _data.Pivot;
|
||||||
|
_oldData.LayerHeight = _data.LayerHeight;
|
||||||
|
_oldData.LayerNumber = _data.LayerNumber;
|
||||||
|
_oldData.Rotate = _data.Rotate;
|
||||||
|
_oldData.Bias = _data.Bias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CtrlLayerNumber(int bLayerNumber)
|
||||||
|
{
|
||||||
|
var flag = bLayerNumber == 0;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var num = _data.LayerNumber * _templateBlueTu.buildings.Length;
|
||||||
|
var buildings = _bPaste.blueprint.buildings;
|
||||||
|
var array = new BlueprintBuilding[num];
|
||||||
|
var flag2 = buildings.Length > num;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
Array.Copy(buildings, array, num);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildings.CopyTo(array, 0);
|
||||||
|
var num2 = _templateBlueTu.buildings.Length;
|
||||||
|
for (var i = _bPaste.bpCursor; i < array.Length; i += num2)
|
||||||
|
{
|
||||||
|
_templateBlueTu.Clone().buildings.CopyTo(array, i);
|
||||||
|
}
|
||||||
|
for (var j = _bPaste.bpCursor; j < array.Length; j++)
|
||||||
|
{
|
||||||
|
array[j].localOffset_z = array[j - num2].localOffset_z + _data.LayerHeight;
|
||||||
|
array[j].localOffset_z2 = array[j - num2].localOffset_z2 + _data.LayerHeight;
|
||||||
|
}
|
||||||
|
for (var k = _bPaste.bpCursor; k < array.Length; k++)
|
||||||
|
{
|
||||||
|
array[k].index = k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_bPaste.blueprint.buildings = array;
|
||||||
|
_bPaste.bpCursor = _bPaste.blueprint.buildings.Length;
|
||||||
|
_bPaste.buildPreviews.Clear();
|
||||||
|
_bPaste.ResetStates();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CtrlLayerHeight(float bLayerHeight)
|
||||||
|
{
|
||||||
|
var flag = bLayerHeight == 0f;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var num = _templateBlueTu.buildings.Length;
|
||||||
|
var num2 = 0;
|
||||||
|
var buildings = _bPaste.blueprint.buildings;
|
||||||
|
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||||
|
{
|
||||||
|
var flag2 = i == num * (num2 + 1);
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
num2++;
|
||||||
|
}
|
||||||
|
buildings[i].localOffset_z += bLayerHeight * num2;
|
||||||
|
buildings[i].localOffset_z2 += bLayerHeight * num2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CtrlScale()
|
||||||
|
{
|
||||||
|
var flag = _oldData.Scale == _data.Scale;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var buildings = _templateBlueTu.buildings;
|
||||||
|
var vector = _data.Scale - _oldData.Scale;
|
||||||
|
var pivot = _data.Pivot;
|
||||||
|
var num = 0;
|
||||||
|
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||||
|
{
|
||||||
|
var flag2 = num == buildings.Length;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
var blueprintBuilding = buildings[num];
|
||||||
|
var blueprintBuilding2 = _bPaste.blueprint.buildings[i];
|
||||||
|
blueprintBuilding2.localOffset_x += (blueprintBuilding.localOffset_x - pivot.x) * vector.x + pivot.x;
|
||||||
|
blueprintBuilding2.localOffset_y += (blueprintBuilding.localOffset_y - pivot.y) * vector.y + pivot.y;
|
||||||
|
blueprintBuilding2.localOffset_z += blueprintBuilding.localOffset_z * vector.z;
|
||||||
|
blueprintBuilding2.localOffset_x2 += (blueprintBuilding.localOffset_x2 - pivot.x) * vector.x + pivot.x;
|
||||||
|
blueprintBuilding2.localOffset_y2 += (blueprintBuilding.localOffset_y2 - pivot.y) * vector.y + pivot.y;
|
||||||
|
blueprintBuilding2.localOffset_z2 += blueprintBuilding.localOffset_z2 * vector.z;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CtrlRotate(float bRotate)
|
||||||
|
{
|
||||||
|
var flag = Math.Abs(bRotate) < 0.001f;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var buildToolBlueprintPaste = _actionBuild.activeTool as BuildTool_BlueprintPaste;
|
||||||
|
var flag2 = buildToolBlueprintPaste != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
var pivot = _data.Pivot;
|
||||||
|
var buildings = buildToolBlueprintPaste.blueprint.buildings;
|
||||||
|
var quaternion = Quaternion.AngleAxis(bRotate, Vector3.forward);
|
||||||
|
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||||
|
{
|
||||||
|
var blueprintBuilding = buildings[i];
|
||||||
|
var vector = new Vector3(blueprintBuilding.localOffset_x - pivot.x, blueprintBuilding.localOffset_y - pivot.y, 0f);
|
||||||
|
vector = quaternion * vector;
|
||||||
|
blueprintBuilding.localOffset_x = vector.x + pivot.x;
|
||||||
|
blueprintBuilding.localOffset_y = vector.y + pivot.y;
|
||||||
|
blueprintBuilding.yaw -= bRotate;
|
||||||
|
vector = new Vector3(blueprintBuilding.localOffset_x2 - pivot.x, blueprintBuilding.localOffset_y2 - pivot.y, 0f);
|
||||||
|
vector = quaternion * vector;
|
||||||
|
blueprintBuilding.localOffset_x2 = vector.x + pivot.x;
|
||||||
|
blueprintBuilding.localOffset_y2 = vector.y + pivot.y;
|
||||||
|
blueprintBuilding.yaw2 -= bRotate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlayerController PlayerController => _playerController;
|
||||||
|
|
||||||
|
private void CtrlBiasData(Vector3 bBias)
|
||||||
|
{
|
||||||
|
var flag = bBias == Vector3.zero;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
var playerActionBuild = _actionBuild;
|
||||||
|
var buildTool = playerActionBuild.activeTool;
|
||||||
|
var buildToolBlueprintPaste = buildTool as BuildTool_BlueprintPaste;
|
||||||
|
var flag2 = buildToolBlueprintPaste != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < buildToolBlueprintPaste.bpCursor; i++)
|
||||||
|
{
|
||||||
|
var blueprintBuilding = buildToolBlueprintPaste.blueprint.buildings[i];
|
||||||
|
blueprintBuilding.localOffset_x += bBias.x;
|
||||||
|
blueprintBuilding.localOffset_x2 += bBias.x;
|
||||||
|
blueprintBuilding.localOffset_y += bBias.y;
|
||||||
|
blueprintBuilding.localOffset_y2 += bBias.y;
|
||||||
|
blueprintBuilding.localOffset_z += bBias.z;
|
||||||
|
blueprintBuilding.localOffset_z2 += bBias.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _BuildTool_BluePrint_OnTick()
|
||||||
|
{
|
||||||
|
VFInput.onGUI = false;
|
||||||
|
_bPaste.mouseRay = _defaultMouseRay;
|
||||||
|
var buildToolBlueprintPaste = _activeTool as BuildTool_BlueprintPaste;
|
||||||
|
var flag = buildToolBlueprintPaste != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
buildToolBlueprintPaste.ClearErrorMessage();
|
||||||
|
buildToolBlueprintPaste.UpdateRaycast();
|
||||||
|
var flag2 = PlayerController.cmd.stage == 0;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
buildToolBlueprintPaste.OperatingPrestage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag3 = PlayerController.cmd.stage == 1;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
buildToolBlueprintPaste.Operating();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildToolBlueprintPaste.UpdatePreviewModels(_actionBuild.model);
|
||||||
|
buildToolBlueprintPaste.ShowCursorText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly BlueTuUIData _data;
|
||||||
|
|
||||||
|
private BlueTuUIData _oldData;
|
||||||
|
|
||||||
|
private PlayerController _playerController;
|
||||||
|
|
||||||
|
private Ray _defaultMouseRay;
|
||||||
|
|
||||||
|
private BlueprintData _templateBlueTu;
|
||||||
|
|
||||||
|
private PlayerAction_Build _actionBuild;
|
||||||
|
|
||||||
|
private BuildTool _activeTool;
|
||||||
|
|
||||||
|
private BuildTool_BlueprintPaste _bPaste;
|
||||||
|
|
||||||
|
private readonly BlueprintBuilding _foundation;
|
||||||
|
|
||||||
|
private BlueprintData _blueprint;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
XianTu/Scripts/DataController/BlueTuDatabase.cs
Normal file
35
XianTu/Scripts/DataController/BlueTuDatabase.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu.Scripts.DataController
|
||||||
|
{
|
||||||
|
internal static class BlueTuDatabase
|
||||||
|
{
|
||||||
|
public static BlueprintData Load(string path)
|
||||||
|
{
|
||||||
|
var flag = !path.EndsWith(".txt");
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
path += ".txt";
|
||||||
|
}
|
||||||
|
var text = Singleton<LoadManager>.Instance.LoadText(path);
|
||||||
|
var flag2 = text == "";
|
||||||
|
BlueprintData blueprintData;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
Debug.Log("没有找到蓝图文件");
|
||||||
|
blueprintData = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var blueprintData2 = BlueprintData.CreateNew(text);
|
||||||
|
var flag3 = blueprintData2 == null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
Debug.Log("蓝图文件加载失败");
|
||||||
|
}
|
||||||
|
blueprintData = blueprintData2;
|
||||||
|
}
|
||||||
|
return blueprintData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
XianTu/Singleton.cs
Normal file
21
XianTu/Singleton.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
namespace XianTu;
|
||||||
|
|
||||||
|
public class Singleton<T> where T : new()
|
||||||
|
{
|
||||||
|
public static T Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var flag = _msInstance == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
_msInstance = new T();
|
||||||
|
}
|
||||||
|
return _msInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static T _msInstance;
|
||||||
|
}
|
||||||
21
XianTu/ToolScripts/EventTriggerExpand.cs
Normal file
21
XianTu/ToolScripts/EventTriggerExpand.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
namespace ToolScripts
|
||||||
|
{
|
||||||
|
internal static class EventTriggerExpand
|
||||||
|
{
|
||||||
|
public static void Add(this EventTrigger trigger, EventTriggerType eventID, UnityAction<BaseEventData> callback)
|
||||||
|
{
|
||||||
|
var flag = trigger.triggers == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
trigger.triggers = [];
|
||||||
|
}
|
||||||
|
var entry = new EventTrigger.Entry();
|
||||||
|
entry.eventID = eventID;
|
||||||
|
entry.callback.AddListener(callback);
|
||||||
|
trigger.triggers.Add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
XianTu/ToolScripts/GameObjectExpand.cs
Normal file
75
XianTu/ToolScripts/GameObjectExpand.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ToolScripts
|
||||||
|
{
|
||||||
|
public static class GameObjectExpand
|
||||||
|
{
|
||||||
|
public static T Find<T>(this GameObject obj, string name) where T : class
|
||||||
|
{
|
||||||
|
var gameObject = GameObject.Find(name);
|
||||||
|
bool flag = gameObject;
|
||||||
|
T t;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
t = gameObject.GetComponent<T>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = default(T);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T Find<T>(this Transform obj, string name) where T : class
|
||||||
|
{
|
||||||
|
var transform = obj.Find(name);
|
||||||
|
bool flag = transform;
|
||||||
|
T t;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
t = transform.GetComponent<T>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = default(T);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryFind<T>(this GameObject obj, string name, out T result) where T : class
|
||||||
|
{
|
||||||
|
var gameObject = GameObject.Find(name);
|
||||||
|
bool flag = gameObject;
|
||||||
|
bool flag2;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
result = gameObject.GetComponent<T>();
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = default(T);
|
||||||
|
flag2 = false;
|
||||||
|
}
|
||||||
|
return flag2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryFind<T>(this Transform obj, string name, out T result) where T : class
|
||||||
|
{
|
||||||
|
var transform = obj.Find(name);
|
||||||
|
bool flag = transform;
|
||||||
|
bool flag2;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
result = transform.GetComponent<T>();
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = default(T);
|
||||||
|
flag2 = false;
|
||||||
|
}
|
||||||
|
return flag2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
XianTu/ToolScripts/_BlueprintBuildingExpands.cs
Normal file
32
XianTu/ToolScripts/_BlueprintBuildingExpands.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ToolScripts
|
||||||
|
{
|
||||||
|
public static class _BlueprintBuildingExpands
|
||||||
|
{
|
||||||
|
static _BlueprintBuildingExpands()
|
||||||
|
{
|
||||||
|
BeltProtoDict.Add(2001, null);
|
||||||
|
BeltProtoDict.Add(2002, null);
|
||||||
|
BeltProtoDict.Add(2003, null);
|
||||||
|
SoltProtoDict.Add(2011, null);
|
||||||
|
SoltProtoDict.Add(2012, null);
|
||||||
|
SoltProtoDict.Add(2013, null);
|
||||||
|
SoltProtoDict.Add(2014, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsBelt(this BlueprintBuilding bb)
|
||||||
|
{
|
||||||
|
return BeltProtoDict.ContainsKey(bb.itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsSlot(this BlueprintBuilding bb)
|
||||||
|
{
|
||||||
|
return SoltProtoDict.ContainsKey(bb.itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Dictionary<int, ItemProto> BeltProtoDict = new();
|
||||||
|
|
||||||
|
private static readonly Dictionary<int, ItemProto> SoltProtoDict = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
40
XianTu/UI/BasePanel.cs
Normal file
40
XianTu/UI/BasePanel.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class BasePanel : MonoBehaviour
|
||||||
|
{
|
||||||
|
public virtual void OnEnter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPause()
|
||||||
|
{
|
||||||
|
UITool.GameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnResume()
|
||||||
|
{
|
||||||
|
UITool.GameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnExit()
|
||||||
|
{
|
||||||
|
Destroy(UITool.GameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(PanelManager panelManager)
|
||||||
|
{
|
||||||
|
PanelManager = panelManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PanelManager PanelManager { get; private set; }
|
||||||
|
|
||||||
|
public void Init(UITool uiTool)
|
||||||
|
{
|
||||||
|
UITool = uiTool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UITool UITool { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
344
XianTu/UI/BlueTuPatchUI.cs
Normal file
344
XianTu/UI/BlueTuPatchUI.cs
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class BlueTuPatchUI : XianTuBasePanel
|
||||||
|
{
|
||||||
|
public BlueTuUIData Data { get; private set; }
|
||||||
|
|
||||||
|
public static BlueTuPatchUI Instance { get; private set; }
|
||||||
|
|
||||||
|
public override void OnEnter()
|
||||||
|
{
|
||||||
|
base.OnEnter();
|
||||||
|
Data = BlueTuUIData.Instance;
|
||||||
|
enableToggle = UITool.GetComponentInChild<Toggle>("XianTuEnableTg");
|
||||||
|
enableToggle.isOn = Data.Enable;
|
||||||
|
enableToggle.onValueChanged.AddListener(delegate(bool value)
|
||||||
|
{
|
||||||
|
Data.Enable = value;
|
||||||
|
});
|
||||||
|
_tipText = UITool.GetComponentInChild<Button>("Tx_Tip");
|
||||||
|
_buildButton = UITool.GetComponentInChild<Button>("Btn_Build");
|
||||||
|
_buildButton.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
var onBuildBtn = Data.OnBuildBtn;
|
||||||
|
if (onBuildBtn != null)
|
||||||
|
{
|
||||||
|
onBuildBtn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_resetButton = UITool.GetComponentInChild<Button>("Btn_Reset");
|
||||||
|
_resetButton.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
var onResetBtn = Data.OnResetBtn;
|
||||||
|
if (onResetBtn != null)
|
||||||
|
{
|
||||||
|
onResetBtn();
|
||||||
|
}
|
||||||
|
ResetValue();
|
||||||
|
});
|
||||||
|
_copyButton = UITool.GetComponentInChild<Button>("Btn_Copy");
|
||||||
|
_copyButton.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
var onCopyBtn = Data.OnCopyBtn;
|
||||||
|
if (onCopyBtn != null)
|
||||||
|
{
|
||||||
|
onCopyBtn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LayerNumber = CreateUIValue(Data.LayerNumber, "LayerNumber");
|
||||||
|
LayerHeight = CreateUIValue(Data.LayerHeight, "LayerHeight", 20f);
|
||||||
|
var text = "ScaleGroup/Group/ScaleX";
|
||||||
|
var text2 = "ScaleGroup/Group/ScaleY";
|
||||||
|
ScaleX = CreateUIValue(Data.Scale.x, text);
|
||||||
|
ScaleY = CreateUIValue(Data.Scale.y, text2);
|
||||||
|
var text3 = "ScaleGroup/Group/ScaleZ";
|
||||||
|
ScaleZ = CreateUIValue(Data.Scale.z, text3);
|
||||||
|
var text4 = "BiasGroup/Group/BiasX";
|
||||||
|
var text5 = "BiasGroup/Group/BiasY";
|
||||||
|
var text6 = "BiasGroup/Group/BiasZ";
|
||||||
|
_biasX = CreateUIValue(Data.Bias.x, text4, 20f);
|
||||||
|
_biasY = CreateUIValue(Data.Bias.y, text5, 20f);
|
||||||
|
BiasZ = CreateUIValue(Data.Bias.z, text6, 20f);
|
||||||
|
Rotate = CreateUIValue(Data.Rotate, "Rotate", 180f);
|
||||||
|
_pivotX = CreateUIValue(Data.Pivot.x, "PivotX");
|
||||||
|
_pivotY = CreateUIValue(Data.Pivot.y, "PivotY");
|
||||||
|
AddDragControl(Rotate, "Name");
|
||||||
|
AddDragControl(LayerNumber, "Name");
|
||||||
|
AddDragControl(LayerHeight, "Name");
|
||||||
|
AddDragControl(ScaleX, "Name");
|
||||||
|
AddDragControl(ScaleY, "Name");
|
||||||
|
AddDragControl(ScaleZ, "Name");
|
||||||
|
AddDragControl(_pivotX, _pivotY, "Name");
|
||||||
|
AddDragControl(_biasX, "Name");
|
||||||
|
AddDragControl(_biasY, "Name");
|
||||||
|
AddDragControl(BiasZ, "Name");
|
||||||
|
BindScaleData();
|
||||||
|
BindBiasData();
|
||||||
|
BindPivot();
|
||||||
|
BindLayerNumber();
|
||||||
|
BindLayerHeight();
|
||||||
|
BindRotate();
|
||||||
|
Instance = this;
|
||||||
|
var initFinish = InitFinish;
|
||||||
|
if (initFinish != null)
|
||||||
|
{
|
||||||
|
initFinish(this);
|
||||||
|
}
|
||||||
|
BindOnEnable_MoveCenter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetValue()
|
||||||
|
{
|
||||||
|
_biasX.Value = Data.Bias.x;
|
||||||
|
_biasY.Value = Data.Bias.y;
|
||||||
|
BiasZ.Value = Data.Bias.z;
|
||||||
|
ScaleX.Value = Data.Scale.x;
|
||||||
|
ScaleY.Value = Data.Scale.y;
|
||||||
|
ScaleZ.Value = Data.Scale.z;
|
||||||
|
_pivotX.Value = Data.Pivot.x;
|
||||||
|
_pivotY.Value = Data.Pivot.y;
|
||||||
|
Rotate.Value = Data.Rotate;
|
||||||
|
enableToggle.isOn = Data.Enable;
|
||||||
|
LayerHeight.Value = Data.LayerHeight;
|
||||||
|
LayerNumber.Value = Data.LayerNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindOnEnable_MoveCenter()
|
||||||
|
{
|
||||||
|
var canvasMonoEvent = UIManager.CanvasMonoEvent;
|
||||||
|
var rectTransform = (RectTransform)transform;
|
||||||
|
var centerBias = new Vector3(-rectTransform.rect.width / 2f, rectTransform.rect.height / 2f);
|
||||||
|
canvasMonoEvent.onEnableEvent.AddListener(delegate
|
||||||
|
{
|
||||||
|
var isOn = enableToggle.isOn;
|
||||||
|
if (isOn)
|
||||||
|
{
|
||||||
|
UITool.GameObject.transform.position = Input.mousePosition + centerBias;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindRotate()
|
||||||
|
{
|
||||||
|
Rotate.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
Data.Rotate = f;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindLayerHeight()
|
||||||
|
{
|
||||||
|
LayerHeight.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
Data.LayerHeight = f;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindLayerNumber()
|
||||||
|
{
|
||||||
|
LayerNumber.OnValueChange += delegate(int i)
|
||||||
|
{
|
||||||
|
Data.LayerNumber = i;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindPivot()
|
||||||
|
{
|
||||||
|
var tempPivot = Data.Pivot;
|
||||||
|
var cd = Time.time;
|
||||||
|
_pivotX.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
var flag = Time.time - cd < Time.fixedDeltaTime;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
cd = Time.time;
|
||||||
|
tempPivot.x = f;
|
||||||
|
Data.Pivot = tempPivot;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_pivotY.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
var flag2 = Time.time - cd < Time.fixedDeltaTime;
|
||||||
|
if (!flag2)
|
||||||
|
{
|
||||||
|
cd = Time.time;
|
||||||
|
tempPivot.y = f;
|
||||||
|
Data.Pivot = tempPivot;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindBiasData()
|
||||||
|
{
|
||||||
|
var tempBias = Data.Bias;
|
||||||
|
_biasX.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempBias.x = f;
|
||||||
|
Data.Bias = tempBias;
|
||||||
|
};
|
||||||
|
_biasY.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempBias.y = f;
|
||||||
|
Data.Bias = tempBias;
|
||||||
|
};
|
||||||
|
BiasZ.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempBias.z = f;
|
||||||
|
Data.Bias = tempBias;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindScaleData()
|
||||||
|
{
|
||||||
|
var tempScale = Data.Scale;
|
||||||
|
ScaleX.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempScale.x = f;
|
||||||
|
Data.Scale = tempScale;
|
||||||
|
};
|
||||||
|
ScaleY.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempScale.y = f;
|
||||||
|
Data.Scale = tempScale;
|
||||||
|
};
|
||||||
|
ScaleZ.OnValueChange += delegate(float f)
|
||||||
|
{
|
||||||
|
tempScale.z = f;
|
||||||
|
Data.Scale = tempScale;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||||
|
private static event Action<BlueTuPatchUI> InitFinish;
|
||||||
|
|
||||||
|
public static event Action<BlueTuPatchUI> OnInitFinish
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
InitFinish += value;
|
||||||
|
var flag = Instance != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
value(Instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remove => InitFinish -= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddDragControl<T>(UIValue<T> uiValue, string childrenName) where T : IComparable
|
||||||
|
{
|
||||||
|
var flag = uiValue.Components.Length != 0;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var parent = uiValue.Components[0].gameObject.transform.parent;
|
||||||
|
var transform = parent.Find(childrenName);
|
||||||
|
bool flag2 = transform;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
uiValue.BindDragControl(transform.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddDragControl<T>(UIValue<T> uiValueX, UIValue<T> uiValueY, string childrenName) where T : IComparable
|
||||||
|
{
|
||||||
|
var flag = uiValueX.Components.Length != 0;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var parent = uiValueX.Components[0].gameObject.transform.parent;
|
||||||
|
var transform = parent.Find(childrenName);
|
||||||
|
bool flag2 = transform;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
uiValueX.BindDragControl(transform.gameObject);
|
||||||
|
uiValueY.BindDragControl(transform.gameObject);
|
||||||
|
UIValue<T>.BindDragControl(transform.gameObject, uiValueX, uiValueY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var flag3 = uiValueY.Components.Length != 0;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
var parent2 = uiValueY.Components[0].gameObject.transform.parent;
|
||||||
|
var transform2 = parent2.Find(childrenName);
|
||||||
|
bool flag4 = transform2;
|
||||||
|
if (flag4)
|
||||||
|
{
|
||||||
|
uiValueX.BindDragControl(transform2.gameObject);
|
||||||
|
uiValueY.BindDragControl(transform2.gameObject);
|
||||||
|
UIValue<T>.BindDragControl(transform2.gameObject, uiValueX, uiValueY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UIValue<T> CreateUIValue<T>(T defaultValue, string groupPath, float maxValue = 10f) where T : IComparable
|
||||||
|
{
|
||||||
|
var uivalue = new UIValue<T>(defaultValue, Array.Empty<Component>());
|
||||||
|
var gameObject = UITool.FindChildGameObject(groupPath);
|
||||||
|
var flag = gameObject == null;
|
||||||
|
UIValue<T> uivalue2;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.LogError("没有找到" + groupPath);
|
||||||
|
uivalue2 = uivalue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uivalue.Bind(gameObject.GetComponentInChildren<Toggle>());
|
||||||
|
uivalue.Bind(gameObject.GetComponentInChildren<Slider>());
|
||||||
|
uivalue.Bind(gameObject.GetComponentInChildren<Scrollbar>());
|
||||||
|
var componentsInChildren = gameObject.GetComponentsInChildren<Text>();
|
||||||
|
for (var i = 0; i < componentsInChildren.Length; i++)
|
||||||
|
{
|
||||||
|
var flag2 = componentsInChildren[i].name == "ValueText";
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
uivalue.Bind(componentsInChildren[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uivalue.Bind(gameObject.GetComponentInChildren<InputField>());
|
||||||
|
uivalue.MaxValue = maxValue;
|
||||||
|
uivalue2 = uivalue;
|
||||||
|
}
|
||||||
|
return uivalue2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Toggle enableToggle;
|
||||||
|
|
||||||
|
private Button _tipText;
|
||||||
|
|
||||||
|
private Button _buildButton;
|
||||||
|
|
||||||
|
private Button _resetButton;
|
||||||
|
|
||||||
|
public UIValue<int> LayerNumber;
|
||||||
|
|
||||||
|
public UIValue<float> LayerHeight;
|
||||||
|
|
||||||
|
public UIValue<float> ScaleX;
|
||||||
|
|
||||||
|
public UIValue<float> ScaleY;
|
||||||
|
|
||||||
|
public UIValue<float> ScaleZ;
|
||||||
|
|
||||||
|
public UIValue<float> BiasZ;
|
||||||
|
|
||||||
|
public UIValue<float> Rotate;
|
||||||
|
|
||||||
|
private UIValue<float> _pivotX;
|
||||||
|
|
||||||
|
private UIValue<float> _pivotY;
|
||||||
|
|
||||||
|
private UIValue<float> _biasX;
|
||||||
|
|
||||||
|
private UIValue<float> _biasY;
|
||||||
|
|
||||||
|
private Button _copyButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
XianTu/UI/CanvasMonoEvent.cs
Normal file
25
XianTu/UI/CanvasMonoEvent.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
public class CanvasMonoEvent : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
onEnableEvent = new UnityEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
var onEnableEvent = this.onEnableEvent;
|
||||||
|
if (onEnableEvent != null)
|
||||||
|
{
|
||||||
|
onEnableEvent.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[FormerlySerializedAs("OnEnableEvent")] public UnityEvent onEnableEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
99
XianTu/UI/PanelManager.cs
Normal file
99
XianTu/UI/PanelManager.cs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
public class PanelManager
|
||||||
|
{
|
||||||
|
public LoadManager Loader { get; private set; }
|
||||||
|
|
||||||
|
public PanelManager(GameObject rootCanvas)
|
||||||
|
{
|
||||||
|
_panelStack = new Stack<BasePanel>();
|
||||||
|
_panelDict = new Dictionary<string, BasePanel>();
|
||||||
|
this._rootCanvas = rootCanvas;
|
||||||
|
Loader = Singleton<LoadManager>.Instance;
|
||||||
|
_uiAssembly = GetType().Assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Push(string nextPanelName)
|
||||||
|
{
|
||||||
|
var flag = _panelStack.Count > 0;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
_panelStack.Peek().OnPause();
|
||||||
|
}
|
||||||
|
var flag2 = _panelDict.ContainsKey(nextPanelName);
|
||||||
|
BasePanel basePanel;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
basePanel = _panelDict[nextPanelName];
|
||||||
|
basePanel.OnResume();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var text = Path.Combine(UIPrefabDir, nextPanelName);
|
||||||
|
var gameObject = Loader.LoadPrefab(text);
|
||||||
|
var flag3 = gameObject == null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
Debug.LogError("没有找到" + text);
|
||||||
|
var flag4 = _panelStack.Count > 0;
|
||||||
|
if (flag4)
|
||||||
|
{
|
||||||
|
_panelStack.Peek().OnResume();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gameObject = Object.Instantiate(gameObject, _rootCanvas.transform);
|
||||||
|
var type = _uiAssembly.GetType(_panelNameSapce + "." + nextPanelName);
|
||||||
|
basePanel = (BasePanel)gameObject.AddComponent(type);
|
||||||
|
var uitool = new UITool(gameObject);
|
||||||
|
basePanel.Init(this);
|
||||||
|
basePanel.Init(uitool);
|
||||||
|
_panelDict.Add(nextPanelName, basePanel);
|
||||||
|
basePanel.OnEnter();
|
||||||
|
}
|
||||||
|
_panelStack.Push(basePanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Pop()
|
||||||
|
{
|
||||||
|
var flag = _panelStack.Count > 0;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var basePanel = _panelStack.Pop();
|
||||||
|
basePanel.OnPause();
|
||||||
|
}
|
||||||
|
var flag2 = _panelStack.Count > 0;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
_panelStack.Peek().OnResume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Exit()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < _panelDict.Count; i++)
|
||||||
|
{
|
||||||
|
_panelDict.ElementAt(i).Value.OnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stack<BasePanel> _panelStack;
|
||||||
|
|
||||||
|
private Dictionary<string, BasePanel> _panelDict;
|
||||||
|
|
||||||
|
private GameObject _rootCanvas;
|
||||||
|
|
||||||
|
private Assembly _uiAssembly;
|
||||||
|
|
||||||
|
private string _panelNameSapce = "XianTu.UI";
|
||||||
|
|
||||||
|
public readonly string UIPrefabDir = "Prefabs/UI";
|
||||||
|
}
|
||||||
|
}
|
||||||
72
XianTu/UI/UIManager.cs
Normal file
72
XianTu/UI/UIManager.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
public class UIManager
|
||||||
|
{
|
||||||
|
public GameObject CanvasObj { get; private set; }
|
||||||
|
|
||||||
|
public bool ActiveSelf => CanvasObj.activeSelf;
|
||||||
|
|
||||||
|
public void SetActive(bool value)
|
||||||
|
{
|
||||||
|
CanvasObj.SetActive(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SwitchDisplay()
|
||||||
|
{
|
||||||
|
CanvasObj.SetActive(CanvasObj.activeSelf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIManager(Action<object> debugLog = null)
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
var flag = debugLog == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
DebugLog = new Action<object>(Debug.Log);
|
||||||
|
}
|
||||||
|
var flag2 = !LoadCanvas();
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
DebugLog("UI管理器加载失败");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PanelManager = new PanelManager(CanvasObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PanelManager PanelManager { get; private set; }
|
||||||
|
|
||||||
|
public static UIManager Instance { get; private set; }
|
||||||
|
|
||||||
|
public CanvasMonoEvent CanvasMonoEvent { get; private set; }
|
||||||
|
|
||||||
|
private bool LoadCanvas()
|
||||||
|
{
|
||||||
|
var gameObject = Singleton<LoadManager>.Instance.LoadPrefab("Prefabs/XianTuCanvas");
|
||||||
|
var flag = gameObject != null;
|
||||||
|
bool flag2;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var gameObject2 = Object.Instantiate(gameObject);
|
||||||
|
CanvasObj = gameObject2;
|
||||||
|
CanvasMonoEvent = gameObject2.AddComponent<CanvasMonoEvent>();
|
||||||
|
gameObject2.SetActive(false);
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flag2 = false;
|
||||||
|
}
|
||||||
|
return flag2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string CanvasPrefabPath = "Prefabs/XianTuCanvas";
|
||||||
|
|
||||||
|
public readonly Action<object> DebugLog;
|
||||||
|
}
|
||||||
|
}
|
||||||
148
XianTu/UI/UITool.cs
Normal file
148
XianTu/UI/UITool.cs
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class UITool
|
||||||
|
{
|
||||||
|
public UITool(GameObject uiGameObject)
|
||||||
|
{
|
||||||
|
GameObject = uiGameObject;
|
||||||
|
Transform = GameObject.transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetComponentInChild<T>(string path) where T : class
|
||||||
|
{
|
||||||
|
var gameObject = FindChildGameObject(path);
|
||||||
|
bool flag = gameObject;
|
||||||
|
T t;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
t = gameObject.GetComponent<T>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = default(T);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject FindChildGameObject(string path)
|
||||||
|
{
|
||||||
|
var array = path.Split(['/']);
|
||||||
|
var flag = array.Length == 0;
|
||||||
|
GameObject gameObject;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.LogError("空路径");
|
||||||
|
gameObject = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag2 = array[0] == "";
|
||||||
|
GameObject gameObject2;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
gameObject2 = StepByStepFindChild(Transform, array.Skip(1).ToArray());
|
||||||
|
var flag3 = gameObject2 != null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
return gameObject2.gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameObject2 = BreadthFindChild(Transform, array[0]);
|
||||||
|
var flag4 = gameObject2 != null && array.Length > 1;
|
||||||
|
if (flag4)
|
||||||
|
{
|
||||||
|
gameObject2 = StepByStepFindChild(gameObject2.transform, array.Skip(1).ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var flag5 = gameObject2 == null;
|
||||||
|
if (flag5)
|
||||||
|
{
|
||||||
|
Debug.LogError("找不到" + path);
|
||||||
|
}
|
||||||
|
gameObject = gameObject2;
|
||||||
|
}
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameObject BreadthFindChild(Transform parent, string name)
|
||||||
|
{
|
||||||
|
var flag = parent == null;
|
||||||
|
GameObject gameObject;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Debug.LogError("不要传个空的过来!");
|
||||||
|
gameObject = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var queue = new Queue<Transform>();
|
||||||
|
queue.Enqueue(parent);
|
||||||
|
while (queue.Count > 0)
|
||||||
|
{
|
||||||
|
var transform = queue.Dequeue();
|
||||||
|
var transform2 = transform.Find(name);
|
||||||
|
var flag2 = transform2 != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
return transform2.gameObject;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < transform.childCount; i++)
|
||||||
|
{
|
||||||
|
queue.Enqueue(transform.GetChild(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gameObject = null;
|
||||||
|
}
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetOrAddComponentInChildren<T>(string name) where T : Component
|
||||||
|
{
|
||||||
|
var gameObject = FindChildGameObject(name);
|
||||||
|
var flag = gameObject != null;
|
||||||
|
T t2;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var t = gameObject.GetComponent<T>();
|
||||||
|
var flag2 = t == null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
t = gameObject.AddComponent<T>();
|
||||||
|
}
|
||||||
|
t2 = t;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t2 = default(T);
|
||||||
|
}
|
||||||
|
return t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
[CompilerGenerated]
|
||||||
|
internal static GameObject StepByStepFindChild(Transform parent, string[] filepaths)
|
||||||
|
{
|
||||||
|
var transform = parent;
|
||||||
|
for (var i = 0; i < filepaths.Length; i++)
|
||||||
|
{
|
||||||
|
transform = transform.Find(filepaths[i]);
|
||||||
|
var flag = transform == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return transform.gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly GameObject GameObject;
|
||||||
|
|
||||||
|
public readonly Transform Transform;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
XianTu/UI/UIType.cs
Normal file
15
XianTu/UI/UIType.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class UIType
|
||||||
|
{
|
||||||
|
public UIType(string prefabPath)
|
||||||
|
{
|
||||||
|
this.PrefabPath = prefabPath;
|
||||||
|
Name = prefabPath.Substring(prefabPath.LastIndexOf('/') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PrefabPath;
|
||||||
|
|
||||||
|
public string Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
421
XianTu/UI/UIValue.cs
Normal file
421
XianTu/UI/UIValue.cs
Normal file
@@ -0,0 +1,421 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using ToolScripts;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class UIValue<T> where T : IComparable
|
||||||
|
{
|
||||||
|
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||||
|
private event Action<object> ValueUpdate;
|
||||||
|
|
||||||
|
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||||
|
public event Action<T> OnValueChange;
|
||||||
|
|
||||||
|
public T Value
|
||||||
|
{
|
||||||
|
get => _value;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var publicValueLock = _publicValueLock;
|
||||||
|
if (!publicValueLock)
|
||||||
|
{
|
||||||
|
_publicValueLock = true;
|
||||||
|
ValueUpdate(value);
|
||||||
|
_publicValueLock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float MaxValue
|
||||||
|
{
|
||||||
|
get => _maxValue;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_maxValue = value;
|
||||||
|
for (var i = 0; i < Components.Length; i++)
|
||||||
|
{
|
||||||
|
var component = Components[i];
|
||||||
|
var component2 = component;
|
||||||
|
var slider = component2 as Slider;
|
||||||
|
if (slider != null)
|
||||||
|
{
|
||||||
|
slider.maxValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIValue(T defaultValue, params Component[] components)
|
||||||
|
{
|
||||||
|
var flag = typeof(T) == typeof(bool);
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
_valueType = EValueType.Bool;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag2 = typeof(T) == typeof(int);
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
_valueType = EValueType.Int;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag3 = typeof(T) == typeof(float);
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
_valueType = EValueType.Float;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag4 = typeof(T) == typeof(string);
|
||||||
|
if (flag4)
|
||||||
|
{
|
||||||
|
_valueType = EValueType.String;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag5 = typeof(T) == typeof(double);
|
||||||
|
if (flag5)
|
||||||
|
{
|
||||||
|
_valueType = EValueType.Double;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ValueUpdate = delegate(object v)
|
||||||
|
{
|
||||||
|
switch (_valueType)
|
||||||
|
{
|
||||||
|
case EValueType.Bool:
|
||||||
|
_value = (T)((object)Convert.ToBoolean(v));
|
||||||
|
break;
|
||||||
|
case EValueType.Int:
|
||||||
|
_value = (T)((object)Convert.ToInt32(v));
|
||||||
|
break;
|
||||||
|
case EValueType.Float:
|
||||||
|
_value = (T)((object)Convert.ToSingle(v));
|
||||||
|
break;
|
||||||
|
case EValueType.Double:
|
||||||
|
_value = (T)((object)Convert.ToDouble(v));
|
||||||
|
break;
|
||||||
|
case EValueType.String:
|
||||||
|
_value = (T)((object)_valueType.ToString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
var onValueChange = OnValueChange;
|
||||||
|
if (onValueChange != null)
|
||||||
|
{
|
||||||
|
onValueChange(_value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
foreach (var component in components)
|
||||||
|
{
|
||||||
|
var component2 = component;
|
||||||
|
var component3 = component2;
|
||||||
|
var inputField = component3 as InputField;
|
||||||
|
if (inputField == null)
|
||||||
|
{
|
||||||
|
var toggle = component3 as Toggle;
|
||||||
|
if (toggle == null)
|
||||||
|
{
|
||||||
|
var slider = component3 as Slider;
|
||||||
|
if (slider == null)
|
||||||
|
{
|
||||||
|
var text = component3 as Text;
|
||||||
|
if (text == null)
|
||||||
|
{
|
||||||
|
var scrollbar = component3 as Scrollbar;
|
||||||
|
if (scrollbar != null)
|
||||||
|
{
|
||||||
|
Bind(scrollbar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bind(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bind(slider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bind(toggle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bind(inputField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Bind(Scrollbar scrollBar)
|
||||||
|
{
|
||||||
|
var flag = scrollBar == null;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
Components = Components.Append(scrollBar).ToArray();
|
||||||
|
var hasSet = false;
|
||||||
|
var justUpdate = false;
|
||||||
|
ValueUpdate += delegate(object value)
|
||||||
|
{
|
||||||
|
var hasSet2 = hasSet;
|
||||||
|
if (!hasSet2)
|
||||||
|
{
|
||||||
|
justUpdate = true;
|
||||||
|
scrollBar.value = Convert.ToSingle(value);
|
||||||
|
justUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scrollBar.onValueChanged.AddListener(delegate(float value)
|
||||||
|
{
|
||||||
|
var justUpdate2 = justUpdate;
|
||||||
|
if (!justUpdate2)
|
||||||
|
{
|
||||||
|
hasSet = true;
|
||||||
|
ValueUpdate(value);
|
||||||
|
hasSet = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Bind(Text text)
|
||||||
|
{
|
||||||
|
var flag = text == null;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
Components = Components.Append(text).ToArray();
|
||||||
|
var justUpdate = false;
|
||||||
|
ValueUpdate += delegate(object value)
|
||||||
|
{
|
||||||
|
var justUpdate2 = justUpdate;
|
||||||
|
if (!justUpdate2)
|
||||||
|
{
|
||||||
|
justUpdate = true;
|
||||||
|
text.text = string.Format("{0:f2}", value);
|
||||||
|
justUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Bind(Slider slider)
|
||||||
|
{
|
||||||
|
var flag = slider == null;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
Components = Components.Append(slider).ToArray();
|
||||||
|
var hasSet = false;
|
||||||
|
var justUpdate = false;
|
||||||
|
ValueUpdate += delegate(object value)
|
||||||
|
{
|
||||||
|
var hasSet2 = hasSet;
|
||||||
|
if (!hasSet2)
|
||||||
|
{
|
||||||
|
justUpdate = true;
|
||||||
|
slider.value = Convert.ToSingle(value);
|
||||||
|
justUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
slider.onValueChanged.AddListener(delegate(float value)
|
||||||
|
{
|
||||||
|
var justUpdate2 = justUpdate;
|
||||||
|
if (!justUpdate2)
|
||||||
|
{
|
||||||
|
hasSet = true;
|
||||||
|
ValueUpdate(value);
|
||||||
|
hasSet = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Bind(Toggle toggle)
|
||||||
|
{
|
||||||
|
var flag = toggle == null;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
Components = Components.Append(toggle).ToArray();
|
||||||
|
var hasSet = false;
|
||||||
|
var justUpdate = false;
|
||||||
|
ValueUpdate += delegate(object value)
|
||||||
|
{
|
||||||
|
var hasSet2 = hasSet;
|
||||||
|
if (!hasSet2)
|
||||||
|
{
|
||||||
|
justUpdate = true;
|
||||||
|
toggle.isOn = Convert.ToBoolean(value);
|
||||||
|
justUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
toggle.onValueChanged.AddListener(delegate(bool value)
|
||||||
|
{
|
||||||
|
var justUpdate2 = justUpdate;
|
||||||
|
if (!justUpdate2)
|
||||||
|
{
|
||||||
|
hasSet = true;
|
||||||
|
ValueUpdate(value);
|
||||||
|
hasSet = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Bind(InputField inputField)
|
||||||
|
{
|
||||||
|
var flag = inputField == null;
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
Components = Components.Append(inputField).ToArray();
|
||||||
|
var hasSet = false;
|
||||||
|
var justUpdate = false;
|
||||||
|
ValueUpdate += delegate(object value)
|
||||||
|
{
|
||||||
|
var hasSet2 = hasSet;
|
||||||
|
if (!hasSet2)
|
||||||
|
{
|
||||||
|
justUpdate = true;
|
||||||
|
inputField.text = string.Format("{0:f2}", value);
|
||||||
|
justUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
inputField.onValueChanged.AddListener(delegate(string value)
|
||||||
|
{
|
||||||
|
var justUpdate2 = justUpdate;
|
||||||
|
if (!justUpdate2)
|
||||||
|
{
|
||||||
|
var flag2 = value == "-" || value == "";
|
||||||
|
if (!flag2)
|
||||||
|
{
|
||||||
|
hasSet = true;
|
||||||
|
switch (_valueType)
|
||||||
|
{
|
||||||
|
case EValueType.Bool:
|
||||||
|
ValueUpdate(Convert.ToBoolean(value));
|
||||||
|
break;
|
||||||
|
case EValueType.Int:
|
||||||
|
ValueUpdate(Convert.ToInt32(value));
|
||||||
|
break;
|
||||||
|
case EValueType.Float:
|
||||||
|
ValueUpdate(Convert.ToSingle(value));
|
||||||
|
break;
|
||||||
|
case EValueType.Double:
|
||||||
|
ValueUpdate(Convert.ToDouble(value));
|
||||||
|
break;
|
||||||
|
case EValueType.String:
|
||||||
|
ValueUpdate(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
hasSet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BindDragControl(GameObject gameObject)
|
||||||
|
{
|
||||||
|
var startPosition = default(Vector2);
|
||||||
|
var defaultValue = 0f;
|
||||||
|
var eventTrigger = gameObject.GetComponent<EventTrigger>();
|
||||||
|
var flag = eventTrigger == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
eventTrigger = gameObject.AddComponent<EventTrigger>();
|
||||||
|
}
|
||||||
|
var speed = 0f;
|
||||||
|
eventTrigger.Add(EventTriggerType.BeginDrag, delegate(BaseEventData edata)
|
||||||
|
{
|
||||||
|
var pointerEventData = edata as PointerEventData;
|
||||||
|
var flag2 = pointerEventData != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
startPosition = pointerEventData.position;
|
||||||
|
defaultValue = Convert.ToSingle(Value);
|
||||||
|
speed = _maxValue / Screen.width * 4f;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
eventTrigger.Add(EventTriggerType.Drag, delegate(BaseEventData edata)
|
||||||
|
{
|
||||||
|
var pointerEventData2 = edata as PointerEventData;
|
||||||
|
var flag3 = pointerEventData2 != null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
var num = (pointerEventData2.position.x - startPosition.x) * speed;
|
||||||
|
ValueUpdate(defaultValue + num);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BindDragControl(GameObject controller, UIValue<T> uiValueX, UIValue<T> uiValueY)
|
||||||
|
{
|
||||||
|
var startPosition = default(Vector2);
|
||||||
|
var defaultValue1 = 0f;
|
||||||
|
var defaultValue2 = 0f;
|
||||||
|
var eventTrigger = controller.GetComponent<EventTrigger>();
|
||||||
|
var flag = eventTrigger == null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
eventTrigger = controller.AddComponent<EventTrigger>();
|
||||||
|
}
|
||||||
|
var speed = 0f;
|
||||||
|
eventTrigger.Add(EventTriggerType.BeginDrag, delegate(BaseEventData edata)
|
||||||
|
{
|
||||||
|
var pointerEventData = edata as PointerEventData;
|
||||||
|
var flag2 = pointerEventData != null;
|
||||||
|
if (flag2)
|
||||||
|
{
|
||||||
|
startPosition = pointerEventData.position;
|
||||||
|
defaultValue1 = Convert.ToSingle(uiValueX.Value);
|
||||||
|
defaultValue2 = Convert.ToSingle(uiValueY.Value);
|
||||||
|
speed = uiValueX._maxValue / Screen.width * 4f;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
eventTrigger.Add(EventTriggerType.Drag, delegate(BaseEventData edata)
|
||||||
|
{
|
||||||
|
var pointerEventData2 = edata as PointerEventData;
|
||||||
|
var flag3 = pointerEventData2 != null;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
var vector = (pointerEventData2.position - startPosition) * speed;
|
||||||
|
uiValueX.ValueUpdate(defaultValue1 + vector.x);
|
||||||
|
uiValueY.ValueUpdate(defaultValue2 + vector.y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private T _value;
|
||||||
|
|
||||||
|
private float _maxValue = 1f;
|
||||||
|
|
||||||
|
private readonly EValueType _valueType;
|
||||||
|
|
||||||
|
public Component[] Components = new Component[0];
|
||||||
|
|
||||||
|
private bool _publicValueLock = false;
|
||||||
|
|
||||||
|
private enum EValueType
|
||||||
|
{
|
||||||
|
Bool,
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
Double,
|
||||||
|
String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
149
XianTu/UI/XianTuBasePanel.cs
Normal file
149
XianTu/UI/XianTuBasePanel.cs
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace XianTu.UI
|
||||||
|
{
|
||||||
|
internal class XianTuBasePanel : BasePanel
|
||||||
|
{
|
||||||
|
public override void OnEnter()
|
||||||
|
{
|
||||||
|
base.OnEnter();
|
||||||
|
UIManager = UIManager.Instance;
|
||||||
|
BindBaseEvent();
|
||||||
|
_uRect = UITool.GameObject.GetComponent<RectTransform>();
|
||||||
|
_defaultRect = _uRect.rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIManager UIManager { get; set; }
|
||||||
|
|
||||||
|
private void BindBaseEvent()
|
||||||
|
{
|
||||||
|
BindCloseWindowBtn();
|
||||||
|
var eventTrigger = UITool.GameObject.AddComponent<EventTrigger>();
|
||||||
|
eventTrigger.triggers = [];
|
||||||
|
var transform = UITool.Transform;
|
||||||
|
TriggerAdd(eventTrigger, EventTriggerType.Drag, delegate(BaseEventData x)
|
||||||
|
{
|
||||||
|
var pointerEventData = x as PointerEventData;
|
||||||
|
var flag = pointerEventData != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var vector = pointerEventData.position - _dragBias;
|
||||||
|
var width = _defaultRect.width;
|
||||||
|
var height = _defaultRect.height;
|
||||||
|
switch (_dragMode)
|
||||||
|
{
|
||||||
|
case EDragMode.Drag:
|
||||||
|
transform.position = _sourceDragPoint + vector;
|
||||||
|
break;
|
||||||
|
case EDragMode.ScaleX:
|
||||||
|
_uRect.sizeDelta = new Vector2(width + vector.x, height);
|
||||||
|
break;
|
||||||
|
case EDragMode.ScaleY:
|
||||||
|
_uRect.sizeDelta = new Vector2(width, height - vector.y);
|
||||||
|
break;
|
||||||
|
case EDragMode.ScaleXY:
|
||||||
|
_uRect.sizeDelta = new Vector2(width + vector.x, height - vector.y);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TriggerAdd(eventTrigger, EventTriggerType.PointerDown, delegate(BaseEventData x)
|
||||||
|
{
|
||||||
|
var pointerEventData2 = x as PointerEventData;
|
||||||
|
_sourceDragPoint = transform.position;
|
||||||
|
_dragBias = pointerEventData2.position;
|
||||||
|
var position = pointerEventData2.position;
|
||||||
|
var position2 = transform.position;
|
||||||
|
var num = position.x - position2.x;
|
||||||
|
var num2 = position.y - position2.y;
|
||||||
|
var rect = _uRect.rect;
|
||||||
|
var flag2 = rect.height - 20f < num2;
|
||||||
|
var flag3 = flag2;
|
||||||
|
if (flag3)
|
||||||
|
{
|
||||||
|
_dragMode = EDragMode.Drag;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag4 = num > rect.width - 20f;
|
||||||
|
var flag5 = -num2 > rect.height - 20f;
|
||||||
|
var flag6 = flag4 && flag5;
|
||||||
|
if (flag6)
|
||||||
|
{
|
||||||
|
_dragMode = EDragMode.ScaleXY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag7 = flag4;
|
||||||
|
if (flag7)
|
||||||
|
{
|
||||||
|
_dragMode = EDragMode.ScaleX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var flag8 = flag5;
|
||||||
|
if (flag8)
|
||||||
|
{
|
||||||
|
_dragMode = EDragMode.ScaleY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dragMode = EDragMode.Drag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindCloseWindowBtn()
|
||||||
|
{
|
||||||
|
var orAddComponentInChildren = UITool.GetOrAddComponentInChildren<Button>("Btn_Close");
|
||||||
|
var flag = orAddComponentInChildren != null;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var component = orAddComponentInChildren.gameObject.GetComponent<Button>();
|
||||||
|
component.onClick.AddListener(delegate
|
||||||
|
{
|
||||||
|
UIManager.SetActive(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("没有找到关闭按钮");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TriggerAdd(EventTrigger trigger, EventTriggerType eventID, UnityAction<BaseEventData> callback)
|
||||||
|
{
|
||||||
|
var entry = new EventTrigger.Entry();
|
||||||
|
entry.eventID = eventID;
|
||||||
|
entry.callback.AddListener(callback);
|
||||||
|
trigger.triggers.Add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector2 _dragBias;
|
||||||
|
|
||||||
|
private Vector2 _sourceDragPoint;
|
||||||
|
|
||||||
|
private RectTransform _uRect;
|
||||||
|
|
||||||
|
private EDragMode _dragMode = EDragMode.Drag;
|
||||||
|
|
||||||
|
private Rect _defaultRect;
|
||||||
|
|
||||||
|
private enum EDragMode
|
||||||
|
{
|
||||||
|
Drag,
|
||||||
|
ScaleX,
|
||||||
|
ScaleY,
|
||||||
|
ScaleXY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net472</TargetFramework>
|
<AssemblyName>XianTu</AssemblyName>
|
||||||
<AssemblyName>CruiseAssist</AssemblyName>
|
<BepInExPluginGuid>me.GammaChineYov.plugin.Dyson.XianTu</BepInExPluginGuid>
|
||||||
<BepInExPluginGuid>org.soardev.CruiseAssist</BepInExPluginGuid>
|
<Description>DSP MOD - CompressSave</Description>
|
||||||
<Description>DSP MOD - CruiseAssist</Description>
|
<Version>1.0.5</Version>
|
||||||
<Version>0.1.0</Version>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
|
<TargetFramework>net472</TargetFramework>
|
||||||
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>
|
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -16,14 +16,15 @@
|
|||||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
||||||
|
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.*" />
|
||||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<EmbeddedResource Include="FoundationBlueTu.txt" />
|
||||||
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip
zip -9 -j package/$(ProjectName)-$(Version).zip $(TargetPath) package/icon.png package/manifest.json README.md" />
|
<EmbeddedResource Include="xiantu" />
|
||||||
</Target>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
47
XianTu/XianTuPlugin.cs
Normal file
47
XianTu/XianTuPlugin.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using AssetsLoader;
|
||||||
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using BepInEx.Logging;
|
||||||
|
using UnityEngine;
|
||||||
|
using XianTu.Scripts.DataController;
|
||||||
|
using XianTu.UI;
|
||||||
|
|
||||||
|
namespace XianTu
|
||||||
|
{
|
||||||
|
[BepInPlugin("me.GammaChineYov.plugin.Dyson.XianTu", "XianTu", "1.0.5")]
|
||||||
|
internal class XianTuPlugin : BaseUnityPlugin
|
||||||
|
{
|
||||||
|
private static KeyCode HotKey => _hotKey.Value;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
_logger = Logger;
|
||||||
|
_hotKey = Config.Bind("config", "HotKey", KeyCode.F2, "显示UI的快捷键");
|
||||||
|
var abload = ABLoader.LoadFromEmbeddedAssets("xiantu");
|
||||||
|
Singleton<LoadManager>.Instance.SetLoader(abload);
|
||||||
|
Singleton<LoadManager>.Instance.AddLoader(new EmbeddedFileLoad());
|
||||||
|
UIManager = new UIManager();
|
||||||
|
UIManager.SetActive(false);
|
||||||
|
UIManager.PanelManager.Push("BlueTuPatchUI");
|
||||||
|
new BlueTuController();
|
||||||
|
_logger.LogInfo("仙图加载完毕");
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIManager UIManager { get; set; }
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
var keyDown = Input.GetKeyDown(HotKey);
|
||||||
|
if (keyDown)
|
||||||
|
{
|
||||||
|
UIManager.SetActive(!UIManager.ActiveSelf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static ManualLogSource _logger;
|
||||||
|
|
||||||
|
private static ConfigEntry<KeyCode> _hotKey;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
68
XianTu/XianTuTest.cs
Normal file
68
XianTu/XianTuTest.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using System.IO;
|
||||||
|
using AssetsLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
using XianTu.UI;
|
||||||
|
|
||||||
|
namespace XianTu
|
||||||
|
{
|
||||||
|
internal class XianTuTest : MonoBehaviour
|
||||||
|
{
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
var abload = ABLoader.LoadFromFile("xiantu", "Assets/AB");
|
||||||
|
Singleton<LoadManager>.Instance.SetLoader(abload);
|
||||||
|
_canvas = new UIManager();
|
||||||
|
cube = GameObject.Find("Cube");
|
||||||
|
_canvas.PanelManager.Push("BlueTuPatchUI");
|
||||||
|
var data = BlueTuUIData.Instance;
|
||||||
|
var trans = cube.transform;
|
||||||
|
BlueTuUIData.Instance.OnValueChange += delegate
|
||||||
|
{
|
||||||
|
trans.localScale = data.Scale;
|
||||||
|
trans.position = data.Bias;
|
||||||
|
trans.eulerAngles = new Vector3(0f, data.Rotate, 0f);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LoadTest()
|
||||||
|
{
|
||||||
|
var text = Path.Combine("Assets/XianTu/AB", "xiantu");
|
||||||
|
var assetBundle = AssetBundle.LoadFromFile(text);
|
||||||
|
var allAssetNames = assetBundle.GetAllAssetNames();
|
||||||
|
foreach (var text2 in allAssetNames)
|
||||||
|
{
|
||||||
|
Debug.Log("全路径: " + text2);
|
||||||
|
var text3 = text2.Substring(0, text2.IndexOf("prefabs"));
|
||||||
|
Debug.Log("测试切割" + text3);
|
||||||
|
var text4 = text2.Substring(text2.LastIndexOf('/') + 1);
|
||||||
|
text4 = text4.Split(['.'])[0];
|
||||||
|
Debug.Log("名字: " + text4);
|
||||||
|
var gameObject = assetBundle.LoadAsset<GameObject>(text4);
|
||||||
|
bool flag = gameObject;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
var gameObject2 = Instantiate(gameObject);
|
||||||
|
gameObject2.name = "路径: " + text4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.Log("路径streamingAssetsPath:" + Application.streamingAssetsPath);
|
||||||
|
Debug.Log("dataPath:" + Application.dataPath);
|
||||||
|
Debug.Log("persistentDataPath:" + Application.persistentDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
var keyDown = Input.GetKeyDown(hotKey);
|
||||||
|
if (keyDown)
|
||||||
|
{
|
||||||
|
_canvas.SetActive(!_canvas.ActiveSelf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UIManager _canvas;
|
||||||
|
|
||||||
|
public KeyCode hotKey = KeyCode.F2;
|
||||||
|
|
||||||
|
public GameObject cube;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
XianTu/xiantu
Normal file
BIN
XianTu/xiantu
Normal file
Binary file not shown.
Reference in New Issue
Block a user