diff --git a/Changelogs/Github/v0.1.3.MD b/Changelogs/Github/v0.1.3.MD new file mode 100644 index 0000000..4203d47 --- /dev/null +++ b/Changelogs/Github/v0.1.3.MD @@ -0,0 +1,4 @@ +# Release Notes v0.1.3 + +- Added method to disable deselect pets +- Added preference to toggle pet collision \ No newline at end of file diff --git a/Changelogs/Workshop/v0.1.3.MD b/Changelogs/Workshop/v0.1.3.MD new file mode 100644 index 0000000..1f643a0 --- /dev/null +++ b/Changelogs/Workshop/v0.1.3.MD @@ -0,0 +1,4 @@ +[h1]Release Notes v0.1.3[/h1] + +- Added method to disable deselect pets +- Added preference to toggle pet collision \ No newline at end of file diff --git a/Customs/Types/Pet.cs b/Customs/Types/Pet.cs index ae1696d..f656fce 100644 --- a/Customs/Types/Pet.cs +++ b/Customs/Types/Pet.cs @@ -37,6 +37,7 @@ namespace Pets.Customs.Types view.agent = Prefab.GetComponentInChildren(); view.animator = Prefab.GetComponentInChildren(); view.vfx = Prefab.GetComponentInChildren(); + view.Colliders = new List(Prefab.GetComponentsInChildren()); TextMeshPro tmp = Prefab.GetComponentInChildren(); if (tmp != null) { diff --git a/Menus/GridMenuPetConfig.cs b/Menus/GridMenuPetConfig.cs index 84f6597..c67a2b0 100644 --- a/Menus/GridMenuPetConfig.cs +++ b/Menus/GridMenuPetConfig.cs @@ -12,6 +12,7 @@ namespace Pets.Menus return new PetGridMenu(Pets, container, player, has_back); } - public List Pets = new List(); + public List _Pets = new List(); + public List Pets = new List(); } } \ No newline at end of file diff --git a/Menus/PetGridMenu.cs b/Menus/PetGridMenu.cs index 1d2cfe3..61bd9e0 100644 --- a/Menus/PetGridMenu.cs +++ b/Menus/PetGridMenu.cs @@ -1,31 +1,37 @@ using System.Collections.Generic; using Kitchen; using Kitchen.Modules; +using KitchenData; using Pets.Customs.Types; using Pets.Views; using UnityEngine; namespace Pets.Menus { - public class PetGridMenu : GridMenu + public class PetGridMenu : GridMenu { - public PetGridMenu(List items, Transform container, int player, bool has_back) : base(items, container, player, has_back) + public PetGridMenu(List items, Transform container, int player, bool has_back) : base(items, container, player, has_back) { } protected override int ColumnLength => 3; - protected override void SetupElement(Pet item, GridMenuElement element) + protected override void SetupElement(int item, GridMenuElement element) { - element.Set(PrefabSnapshot.GetSnapshot(item.IconPrefab)); + if (item == 0) + { + element.Set(Mod.Bundle.LoadAsset("None")); + return; + } + element.Set(PrefabSnapshot.GetSnapshot(GameData.Main.Get(item).IconPrefab)); } - protected override void OnSelect(Pet item) + protected override void OnSelect(int item) { if (Player != 0 && item != null) { PetRequestView.PlayerID = Player; - PetRequestView.PetID = item.ID; + PetRequestView.PetID = item; } } } diff --git a/Menus/PreferenceMenu.cs b/Menus/PreferenceMenu.cs new file mode 100644 index 0000000..625bc10 --- /dev/null +++ b/Menus/PreferenceMenu.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using Kitchen; +using Kitchen.Modules; +using KitchenLib; +using KitchenLib.Preferences; +using UnityEngine; + +namespace Pets.Menus +{ + public class PreferenceMenu: KLMenu + { + public PreferenceMenu(Transform container, ModuleList module_list) : base(container, module_list) + { + } + + private Option petsHaveColliders = new Option(new List { true, false }, Mod.manager.GetPreference("petsHaveColliders").Value, new List { "Enabled", "Disabled" }); + + public override void Setup(int player_id) + { + AddLabel("Pet Colliders"); + New(true); + AddSelect(petsHaveColliders); + petsHaveColliders.OnChanged += delegate (object _, bool result) + { + Mod.manager.GetPreference("petsHaveColliders").Set(result); + }; + New(true); + New(true); + AddButton(base.Localisation["MENU_BACK_SETTINGS"], delegate(int i) + { + Mod.manager.Save(); + RequestPreviousMenu(); + }); + } + } +} \ No newline at end of file diff --git a/Mod.cs b/Mod.cs index 593ff88..a7b6df6 100644 --- a/Mod.cs +++ b/Mod.cs @@ -4,12 +4,14 @@ using KitchenLib.Logging.Exceptions; using KitchenMods; using System.Linq; using System.Reflection; +using Kitchen; using Kitchen.Modules; +using KitchenLib.Event; using KitchenLib.Interfaces; +using KitchenLib.Preferences; using KitchenLib.Utils; using Pets.Components; using Pets.Customs; -using Pets.Customs.Types; using Pets.Menus; using Pets.Views; using UnityEngine; @@ -20,12 +22,13 @@ namespace Pets { public const string MOD_GUID = "com.starfluxgames.pets"; public const string MOD_NAME = "Pets"; - public const string MOD_VERSION = "0.1.2"; + public const string MOD_VERSION = "0.1.3"; public const string MOD_AUTHOR = "StarFluxGames"; public const string MOD_GAMEVERSION = ">=1.1.8"; public static AssetBundle Bundle; public static KitchenLogger Logger; + public static PreferenceManager manager; public static float MinimumSpeedThreshold = 0.1f; @@ -40,15 +43,16 @@ namespace Pets if (grid.name == "Root") { GridMenuPetConfig config = new GridMenuPetConfig(); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); - config.Pets.Add(GDOUtils.GetCustomGameDataObject().GameDataObject as Pet); + config.Pets.Add(0); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); + config.Pets.Add(GDOUtils.GetCustomGameDataObject().ID); config.Icon = Bundle.LoadAsset("PawPrint"); grid.Links.Add(config); } @@ -60,6 +64,24 @@ namespace Pets Bundle = mod.GetPacks().SelectMany(e => e.AssetBundles).FirstOrDefault() ?? throw new MissingAssetBundleException(MOD_GUID); Logger = InitLogger(); + manager = new PreferenceManager(MOD_GUID); + manager.RegisterPreference(new PreferenceBool("petsHaveColliders", true)); + manager.Load(); + manager.Save(); + + ModsPreferencesMenu.RegisterMenu(MOD_NAME, typeof(PreferenceMenu), typeof(MainMenuAction)); + ModsPreferencesMenu.RegisterMenu(MOD_NAME, typeof(PreferenceMenu), typeof(PauseMenuAction)); + + Events.MainMenuView_SetupMenusEvent += (s, args) => + { + args.addMenu.Invoke(args.instance, new object[] { typeof(PreferenceMenu), new PreferenceMenu(args.instance.ButtonContainer, args.module_list) }); + }; + + Events.PlayerPauseView_SetupMenusEvent += (s, args) => + { + args.addMenu.Invoke(args.instance, new object[] { typeof(PreferenceMenu), new PreferenceMenu(args.instance.ButtonContainer, args.module_list) }); + }; + ViewUtils.RegisterView("Pets.Views.PetRequestView", typeof(SPetRequestView), typeof(PetRequestView)); } } diff --git a/Systems/Activities/PetEatActivity.cs b/Systems/Activities/PetEatActivity.cs index 51118e2..7fb9931 100644 --- a/Systems/Activities/PetEatActivity.cs +++ b/Systems/Activities/PetEatActivity.cs @@ -53,7 +53,7 @@ namespace Pets.Systems.Activities if (!Require(foodEntity, out CPosition cFoodPosition)) continue; Vector3 targetPos = Vector3.zero; - + if (!CanGetTo(data.PetPosition, cFoodPosition, new Vector3(1 + offset, 0, 0), out targetPos)) if (!CanGetTo(data.PetPosition, cFoodPosition, new Vector3(-1 - offset, 0, 0), out targetPos)) if (!CanGetTo(data.PetPosition, cFoodPosition, new Vector3(0, 0, 1 + offset), out targetPos)) diff --git a/Systems/EditorMenu/SpawnDebugPets.cs b/Systems/EditorMenu/SpawnDebugPets.cs new file mode 100644 index 0000000..6263027 --- /dev/null +++ b/Systems/EditorMenu/SpawnDebugPets.cs @@ -0,0 +1,151 @@ +using System.Collections.Generic; +using Kitchen; +using KitchenData; +using KitchenMods; +using Pets.Components; +using Pets.Customs.Types; +using Pets.Enums; +using Unity.Collections; +using Unity.Entities; +using UnityEngine; + +namespace Pets.Systems.EditorMenu +{ + public class SpawnDebugPets : GameSystemBase + { + private EntityQuery _displayPets; + + protected override void Initialise() + { + return; + base.Initialise(); + _displayPets = GetEntityQuery(typeof(CDisplayPet)); + + foreach (Pet pet in GameData.Main.Get()) + { + _pets.Add(pet); + } + } + + private Vector3 _spawnPosition = new Vector3(0, 0, 0); + private Vector3 facing = new Vector3(0, 0, 0); + private List _pets = new List(); + private int _selectedPet = 0; + + protected override void OnUpdate() + { + return; + using NativeArray displayPets = _displayPets.ToEntityArray(Allocator.Temp); + if (Input.GetKeyDown(KeyCode.LeftArrow)) + { + _spawnPosition.x -= 1; + } + if (Input.GetKeyDown(KeyCode.RightArrow)) + { + _spawnPosition.x += 1; + } + if (Input.GetKeyDown(KeyCode.UpArrow)) + { + _spawnPosition.z += 1; + } + if (Input.GetKeyDown(KeyCode.DownArrow)) + { + _spawnPosition.z -= 1; + } + + if (Input.GetKeyDown(KeyCode.Keypad2)) + { + facing = _spawnPosition; + facing.z -= 1; + } + if (Input.GetKeyDown(KeyCode.Keypad4)) + { + facing = _spawnPosition; + facing.x -= 1; + } + if (Input.GetKeyDown(KeyCode.Keypad6)) + { + facing = _spawnPosition; + facing.x += 1; + } + if (Input.GetKeyDown(KeyCode.Keypad8)) + { + facing = _spawnPosition; + facing.z += 1; + } + if (Input.GetKeyDown(KeyCode.Keypad7)) + { + facing = _spawnPosition; + facing.x -= 1; + facing.z += 1; + } + if (Input.GetKeyDown(KeyCode.Keypad9)) + { + facing = _spawnPosition; + facing.x += 1; + facing.z += 1; + } + if (Input.GetKeyDown(KeyCode.Keypad1)) + { + facing = _spawnPosition; + facing.x -= 1; + facing.z -= 1; + } + if (Input.GetKeyDown(KeyCode.Keypad3)) + { + facing = _spawnPosition; + facing.x += 1; + facing.z -= 1; + } + + + for (int i = 0; i < displayPets.Length; i++) + { + Entity displayPet = displayPets[i]; + EntityManager.AddComponentData(displayPet, new CPosition(_spawnPosition)); + EntityManager.AddComponentData(displayPet, new CMoveToLocation + { + Location = _spawnPosition, + DesiredFacing = facing + }); + } + + if (Input.GetKeyDown(KeyCode.G)) + { + for (int i = 0; i < displayPets.Length; i++) + { + Entity displayPet = displayPets[i]; + EntityManager.DestroyEntity(displayPet); + } + + if (_selectedPet < _pets.Count - 1) + { + _selectedPet++; + } + else + { + _selectedPet = 0; + } + + Entity pet = EntityManager.CreateEntity(); + + EntityManager.AddComponentData(pet, new CPet + { + State = PetState.Idle, + PetType = _pets[_selectedPet].ID + }); + + EntityManager.AddComponentData(pet, new CPosition(_spawnPosition)); + + EntityManager.AddComponentData(pet, new CRequiresView + { + Type = _pets[_selectedPet].ViewType, + PhysicsDriven = true + }); + + EntityManager.AddComponentData(pet, new CDoNotPersist()); + EntityManager.AddComponentData(pet, new CDisplayPet()); + } + } + } +} \ No newline at end of file diff --git a/Systems/PetActivitySystem.cs b/Systems/PetActivitySystem.cs index a45d22a..5157be5 100644 --- a/Systems/PetActivitySystem.cs +++ b/Systems/PetActivitySystem.cs @@ -90,11 +90,7 @@ namespace Pets.Systems private GameObject point2; protected bool CanGetTo(Vector3 startingPosition, Vector3 targetPosition, Vector3 targetOffset, out Vector3 targetDestination, bool ShowDebugSpheres = false) - { - if (!ShowDebugSpheres) - Mod.Logger.LogInfo(""); - - + { if (ShowDebugSpheres) { if (point1 != null) @@ -154,8 +150,12 @@ namespace Pets.Systems return false; } - point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); - point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); + if (ShowDebugSpheres) + { + point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); + point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); + } + return true; } diff --git a/Views/PetView.cs b/Views/PetView.cs index d51bc3e..95a6bdf 100644 --- a/Views/PetView.cs +++ b/Views/PetView.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using Controllers; using Kitchen; using KitchenData; +using KitchenLib.Preferences; using KitchenMods; using MessagePack; using Pets.Components; @@ -22,6 +24,7 @@ namespace Pets.Views public VisualEffect vfx; public GameObject warningIcon; public TextMeshPro label; + public List Colliders; public override void SetPosition(UpdateViewPositionData pos) { @@ -81,7 +84,8 @@ namespace Pets.Views PreferedFacingDirection = PreferedFacingDirection, State = cPet.State, RequestingInputSource = RequestingInputSource, - PetName = cPet.PetName.Value + PetName = cPet.PetName.Value, + EnableColliders = Mod.manager.GetPreference("petsHaveColliders").Value }); if (ApplyUpdates(cLinkedView, (data) => { @@ -131,6 +135,7 @@ namespace Pets.Views [Key(4)] public PetState State; [Key(5)] public int RequestingInputSource; [Key(6)] public string PetName; + [Key(7)] public bool EnableColliders; } [MessagePackObject(false)] @@ -226,6 +231,14 @@ namespace Pets.Views label.font = GameData.Main.GlobalLocalisation.Fonts[KitchenData.Font.Default]; label.text = Data.PetName; } + + if (Colliders != null) + { + foreach (Collider collider in Colliders) + { + collider.enabled = Data.EnableColliders; + } + } } } } \ No newline at end of file