Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Added menu button controller
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Jun 24, 2021
1 parent 8151082 commit 89f0daa
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 67 deletions.
18 changes: 10 additions & 8 deletions Distance.AdventureMaker/Distance.AdventureMaker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,19 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationArguments.cs" />
<Compile Include="Harmony\Assembly-CSharp\MainMenuLogic\Start.cs" />
<Compile Include="Harmony\Assembly-CSharp\MainMenuLogic\Awake.cs" />
<Compile Include="Harmony\Assembly-CSharp\SteamworksUGC\OnEnable.cs" />
<Compile Include="Loader\CampaignLoaderLogic.cs" />
<Compile Include="Scripts\Loader\CampaignLoaderLogic.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Loader\Steps\CampaignImporter.cs" />
<Compile Include="Loader\Steps\CampaignExtractor.cs" />
<Compile Include="Loader\Steps\CampaignListing.cs" />
<Compile Include="Loader\Steps\CampaignWorkspaceSetup.cs" />
<Compile Include="Scripts\Loader\Steps\CampaignImporter.cs" />
<Compile Include="Scripts\Loader\Steps\CampaignExtractor.cs" />
<Compile Include="Scripts\Loader\Steps\CampaignListing.cs" />
<Compile Include="Scripts\Loader\Steps\CampaignWorkspaceSetup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripts\MainMenu\MainMenuButton.cs" />
<Compile Include="Scripts\MainMenu\CampaignsMenuButton.cs" />
<Compile Include="Scripts\MainMenu\Buttons\DefaultMainMenuButton.cs" />
<Compile Include="Scripts\MainMenu\Buttons\MainMenuButton.cs" />
<Compile Include="Scripts\MainMenu\Buttons\ContentPacksButton.cs" />
<Compile Include="Scripts\MainMenu\MainMenuButtonController.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
4 changes: 1 addition & 3 deletions Distance.AdventureMaker/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Centrifuge.Distance.Game;
using Distance.AdventureMaker.Loader;
using Distance.AdventureMaker.Loader;
using Events.MainMenu;
using Reactor.API.Attributes;
using Reactor.API.Interfaces.Systems;
using Reactor.API.Logging;
using Reactor.API.Runtime.Patching;
using System;
using UnityEngine;

namespace Distance.AdventureMaker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Distance.AdventureMaker.Scripts.MainMenu;
using HarmonyLib;

namespace Distance.AdventureMaker.Harmony
{
[HarmonyPatch(typeof(MainMenuLogic), "Awake")]
internal static class MainMenuLogic__Awake
{
[HarmonyPostfix]
internal static void Postfix(MainMenuLogic __instance)
{
var controller = __instance.gameObject.AddComponent<MainMenuButtonController>();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public void Start()

public void Run()
{
// TODO: REMOVE
return;
foreach (LoaderTask task in loader)
{
Task.Run(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ string hash(string entry)
}
}
}

status.SetText("");
status.SetProgress(0, 1);

yield return Task.Wait(5.5f);
//status.SetText("");
//status.SetProgress(0, 1);

//yield return Task.Wait(5.5f);
yield break;
}

/*public IEnumerator<KeyValuePair<string, CampaignItem>> GetEnumerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public override IEnumerator Run(Task.Status status)
DocumentsCampaignsFolder = new DirectoryInfo(Path.Combine(Resource.personalDistanceDirPath_, "Campaigns"));
DocumentsCampaignsFolder.CreateIfDoesntExist();

Mod.Instance.Logger.Error("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

yield break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Centrifuge.Distance.Game;

namespace Distance.AdventureMaker.Scripts.MainMenu
{
public class ContentPacksButton : MainMenuButton
{
protected override string ButtonName => "Community Content Packs";

protected override string ButtonText => "CONTENT PACKS";

protected override int ItemPosition => 5;

protected override void OnButtonClick()
{
MessageBox.Create("This feature isn't currently implemented.", ButtonText).Show();
//SetVisible(false);

return;
/*
var controller = MenuLogic.gameObject.GetComponent<MainMenuButtonController>();
if (!controller) return;
controller.Campaign.Visible = false;
controller.Arcade.Visible = false;
controller.Multiplayer.Visible = false;
controller.LevelEditor.Visible = false;
controller.Workshop.Visible = false;
controller.ContentPacks.Visible = false;
controller.Garage.Visible = false;
controller.ReportBug.Visible = true;
controller.Options.Visible = false;
controller.Quit.Visible = true;
var title = MenuLogic.transform.Find("UI Root/Panel - Main/DistanceTitle").GetComponent<UILabel>();
title.text = "N O";
var version = MenuLogic.transform.Find("UI Root/Panel - Main/VersionNumber").GetComponent<UILabel>();
version.text = "";
*/
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Distance.AdventureMaker.Scripts.MainMenu
{
public class DefaultMainMenuButton : MainMenuButton
{
protected override string ButtonText => Button.GetComponentInChildren<UILabel>().text;

protected override string ButtonName => Button.name;

protected override int ItemPosition => Button.transform.GetSiblingIndex();

public override void Setup(MainMenuLogic menuLogic)
{
if (menuLogic_) return;

menuLogic_ = menuLogic;

Table = FindTable();
Button = gameObject;
}

protected override void OnButtonClick()
{
foreach (UIExButton button in Button.GetComponentsInChildren<UIExButton>())
{
button.OnClick();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,38 @@ public abstract class MainMenuButton : MonoBehaviour

protected virtual int ItemPosition => 0;

private MainMenuLogic menuLogic_;
protected MainMenuLogic menuLogic_;

protected MainMenuLogic MenuLogic => menuLogic_;

protected GameObject Button { get; private set; }
public GameObject Button { get; protected set; }

protected UITable Table { get; private set; }
public UITable Table { get; protected set; }

public bool Visible
{
get
{
return Button.activeInHierarchy;
}
set
{
SetButtonVisible(value);
}
}

public bool ShowIndicator
{
get
{
UnclickedMenuStatusIconLogic unclickedIcon = Button.GetComponentInChildren<UnclickedMenuStatusIconLogic>();
return unclickedIcon && unclickedIcon.image_.enabled;
}
set
{
SetIndicatorVisible(value);
}
}

public void Awake()
{
Expand All @@ -27,7 +52,7 @@ public void Awake()
}
}

protected void Setup(MainMenuLogic menuLogic)
public virtual void Setup(MainMenuLogic menuLogic)
{
// Do not create the button if it has already been created
if (menuLogic_) return;
Expand All @@ -44,14 +69,6 @@ protected void Setup(MainMenuLogic menuLogic)
// Set the button's label (text)
Button.GetComponentInChildren<UILabel>().text = ButtonText;


UnclickedMenuStatusIconLogic unclickedIcon = Button.GetComponentInChildren<UnclickedMenuStatusIconLogic>();
if (unclickedIcon)
{
unclickedIcon.isDisabled_ = true;
unclickedIcon.image_.enabled = true;
}

// There may be multiple UIExButton scripts, we only wanna set the
// event handler on one of them. Otherwise the click event will
// trigger as many times as there are UIExButton/UIButton scripts
Expand All @@ -69,7 +86,7 @@ protected void Setup(MainMenuLogic menuLogic)
}
}

private UITable FindTable()
protected UITable FindTable()
{
return MenuLogic.mainButtons_.GetComponentInChildren<UITable>();
}
Expand All @@ -86,12 +103,22 @@ private GameObject CreateButtonItem()
return Instantiate(buttonTemplate.gameObject, buttonTable);
}

public void SetVisible(bool value)
public void SetButtonVisible(bool value)
{
Button.SetActive(value);
Table.Reposition();
}

public void SetIndicatorVisible(bool value)
{
UnclickedMenuStatusIconLogic unclickedIcon = Button.GetComponentInChildren<UnclickedMenuStatusIconLogic>();
if (unclickedIcon)
{
unclickedIcon.isDisabled_ = true;
unclickedIcon.image_.enabled = value;
}
}

protected abstract void OnButtonClick();
}
}
19 changes: 0 additions & 19 deletions Distance.AdventureMaker/Scripts/MainMenu/CampaignsMenuButton.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using UnityEngine;

namespace Distance.AdventureMaker.Scripts.MainMenu
{
public class MainMenuButtonController : MonoBehaviour
{
private MainMenuLogic menuLogic_;

public MainMenuLogic MenuLogic => menuLogic_;

public MainMenuButton Campaign { get; protected set; }

public MainMenuButton Arcade { get; protected set; }

public MainMenuButton Multiplayer { get; protected set; }

public MainMenuButton LevelEditor { get; protected set; }

public MainMenuButton Workshop { get; protected set; }

public MainMenuButton ContentPacks { get; protected set; }

public MainMenuButton Garage { get; protected set; }

public MainMenuButton ReportBug { get; protected set; }

public MainMenuButton Options { get; protected set; }

public MainMenuButton Quit { get; protected set; }

public void Awake()
{
menuLogic_ = GetComponent<MainMenuLogic>();
if (!menuLogic_)
{
DestroyImmediate(this);
return;
}

Campaign = GetOrAddButtonScript("Campaign");
Arcade = GetOrAddButtonScript("Arcade");
Multiplayer = GetOrAddButtonScript("Multiplayer");
LevelEditor = GetOrAddButtonScript("Level Editor");
Workshop = GetOrAddButtonScript("Steam Workshop");

ContentPacks = GetOrAddButtonScript<ContentPacksButton>();

Garage = GetOrAddButtonScript("Garage");
ReportBug = GetOrAddButtonScript("Report Bug");
Options = GetOrAddButtonScript("Options");
Quit = GetOrAddButtonScript("Quit");
}

private MainMenuButton GetOrAddButtonScript(string buttonName)
{
GameObject button = menuLogic_.mainButtons_.transform.Find($"MainButtons/{buttonName}").gameObject;
var script = button.GetOrAddComponent<DefaultMainMenuButton>();
script.Setup(menuLogic_);
return script;
}

private MainMenuButton GetOrAddButtonScript<T>() where T : MainMenuButton
{
return menuLogic_.GetOrAddComponent<T>();
}
}
}

0 comments on commit 89f0daa

Please sign in to comment.