Skip to content

Commit

Permalink
AVC dialog rework in UITK
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-bures committed Jul 19, 2023
1 parent da44864 commit dda6797
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 32 deletions.
35 changes: 16 additions & 19 deletions SpaceWarp/SpaceWarpPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using UnityEngine.Networking;
using UnityEngine.UIElements;
using SpaceWarp.Backend.Sound;
using SpaceWarp.UI.AvcDialog;

namespace SpaceWarp;

Expand All @@ -59,19 +60,18 @@ public sealed class SpaceWarpPlugin : BaseSpaceWarpPlugin
internal ConfigEntry<bool> ConfigShowMainMenuWarningForErroredMods;
internal ConfigEntry<Color> ConfigDebugColor;
internal ConfigEntry<int> ConfigDebugMessageLimit;

internal ConfigEntry<Color> ConfigErrorColor;
private ConfigEntry<bool> _configFirstLaunch;
internal ConfigEntry<bool> ConfigFirstLaunch;
internal ConfigEntry<Color> ConfigInfoColor;
internal ConfigEntry<Color> ConfigMessageColor;
internal ConfigEntry<bool> ConfigShowConsoleButton;
internal ConfigEntry<bool> ConfigShowTimeStamps;
internal ConfigEntry<string> ConfigTimeStampFormat;
internal ConfigEntry<Color> ConfigWarningColor;
internal ConfigEntry<Color> ConfigAutoScrollEnabledColor;

internal ScriptEnvironment GlobalLuaState;

private string _kspVersion;

internal new static ManualLogSource Logger;
Expand All @@ -87,7 +87,7 @@ public void Awake()
_kspVersion = typeof(VersionID).GetField("VERSION_TEXT", BindingFlags.Static | BindingFlags.Public)
?.GetValue(null) as string;
SetupSpaceWarpConfiguration();

BepInEx.Logging.Logger.Listeners.Add(new SpaceWarpConsoleLogListener(this));

Harmony.CreateAndPatchAll(typeof(SpaceWarpPlugin).Assembly, ModGuid);
Expand Down Expand Up @@ -121,7 +121,7 @@ private void SetupSpaceWarpConfiguration()
"The format for the timestamps in the debug console.");
ConfigDebugMessageLimit = Config.Bind("Debug Console", "Message Limit", 1000,
"The maximum number of messages to keep in the debug console.");
_configFirstLaunch = Config.Bind("Version Checking", "First Launch", true,
ConfigFirstLaunch = Config.Bind("Version Checking", "First Launch", true,
"Whether or not this is the first launch of space warp, used to show the version checking prompt to the user.");
ConfigCheckVersions = Config.Bind("Version Checking", "Check Versions", false,
"Whether or not Space Warp should check mod versions using their swinfo.json files");
Expand Down Expand Up @@ -169,13 +169,14 @@ public override void OnInitialized()
Game.Messages.Subscribe(typeof(TrackingStationUnloadedMessage), StateLoadings.TrackingStationUnloadedHandler, false, true);
Game.Messages.Subscribe(typeof(TrainingCenterLoadedMessage), StateLoadings.TrainingCenterLoadedHandler, false, true);

if (_configFirstLaunch.Value)
if (ConfigFirstLaunch.Value)
{
_configFirstLaunch.Value = false;
// Generate a prompt for whether or not space warp should check mod versions
var o = new GameObject();
var prompt = o.AddComponent<VersionCheckPrompt>();
prompt.spaceWarpPlugin = this;
var avcDialogUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/avcdialog/ui/avcdialog/avcdialog.uxml");
var avcDialog = Window.CreateFromUxml(avcDialogUxml, "Space Warp AVC Dialog", transform, true);

var avcDialogController = avcDialog.gameObject.AddComponent<AvcDialogController>();
avcDialogController.Plugin = this;
}

SpaceWarpManager.CheckKspVersions();
Expand Down Expand Up @@ -306,20 +307,16 @@ private void InitializeUI()
(ConfigurationManager.ConfigurationManager)Chainloader
.PluginInfos[ConfigurationManager.ConfigurationManager.GUID].Instance;

var modListUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/modlist/modlist.uxml");
var modListUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/modlist/ui/modlist/modlist.uxml");
var modList = Window.CreateFromUxml(modListUxml, "Space Warp Mod List", transform, true);

var swConsoleUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/uitkswconsole/spacewarp.console/ConsoleWindow.uxml");
var swConsole = Window.CreateFromUxml(swConsoleUxml, "Space Warp Console", transform, true);

SpaceWarpManager.ModListController = modList.gameObject.AddComponent<ModListController>();
modList.gameObject.Persist();

var swConsoleUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/swconsole/ui/console/console.uxml");
var swConsole = Window.CreateFromUxml(swConsoleUxml, "Space Warp Console", transform, true);
SpaceWarpManager.SpaceWarpConsole = swConsole.gameObject.AddComponent<SpaceWarpConsole>();
swConsole.gameObject.Persist();
}

private void InitializeSettingsUI()
private static void InitializeSettingsUI()
{
GameObject settingsController = new("Settings Controller");
settingsController.Persist();
Expand Down
34 changes: 34 additions & 0 deletions SpaceWarp/UI/AvcDialog/AvcDialogController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using UitkForKsp2.API;
using UnityEngine;
using UnityEngine.UIElements;

namespace SpaceWarp.UI.AvcDialog;

public class AvcDialogController : MonoBehaviour
{
internal SpaceWarpPlugin Plugin;

private void Awake()
{
var document = GetComponent<UIDocument>();
document.EnableLocalization();

var container = document.rootVisualElement;
container[0].CenterByDefault();

container.Q<Button>("yes-button").RegisterCallback<ClickEvent>(_ =>
{
Plugin.ConfigFirstLaunch.Value = false;
Plugin.ConfigCheckVersions.Value = true;
Plugin.CheckVersions();
gameObject.SetActive(false);
});

container.Q<Button>("no-button").RegisterCallback<ClickEvent>(_ =>
{
Plugin.ConfigFirstLaunch.Value = false;
Plugin.ConfigCheckVersions.Value = false;
gameObject.SetActive(false);
});
}
}
26 changes: 13 additions & 13 deletions SpaceWarp/UI/ModList/ModListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ internal class ModListController : MonoBehaviour

private void Awake()
{
_listEntryTemplate = AssetManager.GetAsset<VisualTreeAsset>($"{SpaceWarpPlugin.ModGuid}/modlist/modlistitem.uxml");
_dependencyTemplate = AssetManager.GetAsset<VisualTreeAsset>($"{SpaceWarpPlugin.ModGuid}/modlist/modlistdependency.uxml");
_listEntryTemplate = AssetManager.GetAsset<VisualTreeAsset>($"{SpaceWarpPlugin.ModGuid}/modlist/ui/modlist/modlistitem.uxml");
_dependencyTemplate = AssetManager.GetAsset<VisualTreeAsset>($"{SpaceWarpPlugin.ModGuid}/modlist/ui/modlist/modlistdependency.uxml");
}

internal void AddMainMenuItem()
Expand Down Expand Up @@ -165,7 +165,7 @@ private void InitializeElements()

_disabledModFoldout = _container.Q<Foldout>("disabled-mod-foldout");
_disabledModList = _container.Q<VisualElement>("disabled-mod-list");

_erroredModFoldout = _container.Q<Foldout>("errored-mod-foldout");
_erroredModList = _container.Q<VisualElement>("errored-mod-list");

Expand All @@ -190,7 +190,7 @@ private void InitializeElements()
_missingInfoWarning = _container.Q<VisualElement>("details-missing-info-error");
_mismatchedVersionWarning = _container.Q<VisualElement>("details-mismatched-error");
_badDirectoryWarning = _container.Q<VisualElement>("details-bad-directory-error");

_detailsDependenciesFoldout = _container.Q<Foldout>("details-dependencies-foldout");
_detailsDependenciesList = _container.Q<VisualElement>("details-dependencies-list");

Expand All @@ -204,7 +204,7 @@ private void InitializeElements()
{
_disabledModFoldout.style.display = DisplayStyle.Flex;
}

if (SpaceWarpManager.ErroredPlugins.Count > 0)
{
_erroredModFoldout.style.display = DisplayStyle.Flex;
Expand Down Expand Up @@ -239,7 +239,7 @@ private void FillModLists()

foreach (var erroredPlugin in SpaceWarpManager.ErroredPlugins)
{
MakeListItem(_erroredModList, data => {
MakeListItem(_erroredModList, data => {
data.Guid = erroredPlugin.Plugin.Guid;
erroredPlugin.Apply(data);
});
Expand Down Expand Up @@ -354,7 +354,7 @@ private void OnModSelected(EventBase evt)
modItem[0].RemoveFromClassList("selected");
}
}

if (data.Info != null)
{
SetSelectedModInfo(data,data.Info);
Expand All @@ -367,7 +367,7 @@ private void OnModSelected(EventBase evt)

private void SetSelectedModInfo(ModListItemController data, SpaceWarpPluginDescriptor descriptor)
{

//TODO: Add the ability to show errors at some point (Munix)
SetSelected(
descriptor.Name,
Expand All @@ -394,7 +394,7 @@ private void SetSelectedModInfo(ModListItemController data, SpaceWarpPluginDescr
data.DisabledDependencies
);
}


private void SetSelected(
string modName = "",
Expand Down Expand Up @@ -482,13 +482,13 @@ private void SetDependencies(
warning.style.display = DisplayStyle.Flex;
warning.text = $"({_erroredDependency})";
}

if (unsupportedDependencies.Contains(id))
{
warning.style.display = DisplayStyle.Flex;
warning.text = $"({_unsupportedDependency})";
}

if (unspecifiedDependencies.Contains(id))
{
warning.style.display = DisplayStyle.Flex;
Expand All @@ -500,8 +500,8 @@ private void SetDependencies(
warning.style.display = DisplayStyle.Flex;
warning.text = $"({_disabledDependency})";
}


_detailsDependenciesList.Add(dependencyElement);
}
}
Expand Down
Binary file not shown.
Binary file modified SpaceWarpBuildTemplate/assets/bundles/modlist.bundle
Binary file not shown.
Binary file modified SpaceWarpBuildTemplate/assets/bundles/swconsole.bundle
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ SpaceWarp/Console/Clear,Text,,Clear,Limpar
SpaceWarp/Console/AutoScroll,Text,,Auto Scroll,Scroll automatico
SpaceWarp/Console/On,Text,,On,On
SpaceWarp/Console/Off,Text,,Off,Off
SpaceWarp/AvcDialog/Title,Text,,spacewarp.avc,spacewarp.avc
SpaceWarp/AvcDialog/MainText,Text,,Allow SpaceWarp to automatically check for mod updates online?,Allow SpaceWarp to automatically check for mod updates online?
SpaceWarp/AvcDialog/MinorText,Text,,*You can change this later in the Configuration Manager.,*You can change this later in the Configuration Manager.

0 comments on commit dda6797

Please sign in to comment.