This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom mainmenu button for content packs (campaigns)
- Loading branch information
Showing
6 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Distance.AdventureMaker/Harmony/Assembly-CSharp/MainMenuLogic/Start.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), "Start")] | ||
internal static class MainMenuLogic__Start | ||
{ | ||
[HarmonyPrefix] | ||
internal static void Prefix(MainMenuLogic __instance) | ||
{ | ||
__instance.gameObject.AddComponent<CampaignsMenuButton>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Distance.AdventureMaker/Scripts/MainMenu/CampaignsMenuButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Centrifuge.Distance.Game; | ||
|
||
namespace Distance.AdventureMaker.Scripts.MainMenu | ||
{ | ||
public class CampaignsMenuButton : 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); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
Distance.AdventureMaker/Scripts/MainMenu/MainMenuButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using UnityEngine; | ||
|
||
namespace Distance.AdventureMaker.Scripts.MainMenu | ||
{ | ||
public abstract class MainMenuButton : MonoBehaviour | ||
{ | ||
protected virtual string ButtonName => "MENU BUTTON"; | ||
|
||
protected virtual string ButtonText => "Text not set."; | ||
|
||
protected virtual int ItemPosition => 0; | ||
|
||
private MainMenuLogic menuLogic_; | ||
|
||
protected MainMenuLogic MenuLogic => menuLogic_; | ||
|
||
protected GameObject Button { get; private set; } | ||
|
||
protected UITable Table { get; private set; } | ||
|
||
public void Awake() | ||
{ | ||
MainMenuLogic menuLogic = gameObject.GetComponent<MainMenuLogic>(); | ||
if (menuLogic) | ||
{ | ||
Setup(menuLogic); | ||
} | ||
} | ||
|
||
public void Setup(MainMenuLogic menuLogic) | ||
{ | ||
// Do not create the button if it has already been created | ||
if (menuLogic_) return; | ||
|
||
menuLogic_ = menuLogic; | ||
|
||
Table = FindTable(); | ||
Button = CreateButtonItem(); | ||
|
||
// Rename/reposition the button | ||
Button.name = ButtonName; | ||
Button.transform.SetSiblingIndex(ItemPosition); | ||
|
||
// 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 | ||
// present on the object | ||
|
||
bool handlerSet = false; | ||
foreach (UIExButton button in Button.GetComponentsInChildren<UIExButton>()) | ||
{ | ||
button.onClick.Clear(); | ||
if (!handlerSet) | ||
{ | ||
button.onClick.Add(new EventDelegate(OnButtonClick)); | ||
handlerSet = true; | ||
} | ||
} | ||
} | ||
|
||
private UITable FindTable() | ||
{ | ||
return MenuLogic.mainButtons_.GetComponentInChildren<UITable>(); | ||
} | ||
|
||
private GameObject CreateButtonItem() | ||
{ | ||
// Get the table object (responsible for positioning the buttons vertically) | ||
Transform buttonTable = Table.transform; | ||
|
||
// Find one of the already existing buttons | ||
Transform buttonTemplate = buttonTable.Find("Arcade"); | ||
|
||
// Return a copy of the previously found button | ||
return Instantiate(buttonTemplate.gameObject, buttonTable); | ||
} | ||
|
||
public void SetVisible(bool value) | ||
{ | ||
Button.SetActive(value); | ||
Table.Reposition(); | ||
} | ||
|
||
protected abstract void OnButtonClick(); | ||
} | ||
} |