[DONE] Mod Idea: Equipment Sets

Talk about the mods you'd like to see in Daggerfall Unity. Give mod creators some ideas!
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Mod Idea: Equipment Sets

Post by Ralzar »

pango wrote: Thu Dec 05, 2019 7:16 am I do like the UI idea (even if I'd prefer to add cruft at the bottom of the paperdoll instead of the top, but that's mostly personal preference).
Agreed, but there is so litte room by the feet and so much by the shoulders.

pango wrote: Thu Dec 05, 2019 7:16 am I see one difficulty with just flipping thru equipments 'til you find the one you want though: you will equip/unequip more items than strictly required, and without extra logic that could wear "on held" magic items prematurely...
Have a "change" button to indicate swapping outfits.

Speaking of swapping outfits, man why doesn't that have equiptime while weapons have?

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

Heads up, I've begun working on this today. I needed a break from the animations stuff, while I try and sort out the last bug I am struggling with.

I have gone over UI, inventory stuff for the last few days for my combat overhaul. This feature hits my work well, so I have started the base for the script today and got it imported in using the modding system. Now comes the fun stuff, coding in the rect objects for the UI and setting up the coding for managing the outfit system.

This will be both a fun mod to develop, but it also will help me understand the modding system better before I try to move my combat overhaul to it.

As of now, this is my plan based on discussions.

Will have two buttons on bottom left of portrait. One for saving the players current outfit to the selected outfit slot, and one for loading the selected outfit slot on to the character.

Will have buttons top right and left of portrait to scroll through a set of predefined outfits.

Will have small number or something in paperdoll area to read out the currently selected outfit. Will try to see if I can use array keys, and player input strings to allow players to name outfit setups themselves too.

The outfit predefiniations will be stored in a resizing array to allow users to build as many outfits as they wish.

At some point, it could be possible to allow users to place the rect objects/buttons and readouts where they want, but that would be a final release thing, if that.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Mod Idea: Equipment Sets

Post by pango »

Thank you so much! :D
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by Hazelnut »

l3lessed wrote: Fri Dec 06, 2019 1:29 am
I have gone over UI, inventory stuff for the last few days for my combat overhaul. This feature hits my work well, so I have started the base for the script today and got it imported in using the modding system. Now comes the fun stuff, coding in the rect objects for the UI and setting up the coding for managing the outfit system.

This will be both a fun mod to develop, but it also will help me understand the modding system better before I try to move my combat overhaul to it.
Please use the UI window factory to override the standard inventory window. You may need to make changes to permissions or mark methods as overridable, that's fine just submit a core PR with any changes you need.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

Hazel,

Can I use the built in Unity onGui routine? I've started the mod, and to get the coding done as fast as possible, and not worry about getting the UI in right away, I used Unity's built in OnGui overlay to setup some basic buttons to run the script.

If I compile, will these buttons still work for normal players not using the editor version of daggerfall? Honestly, I feel using the OnGui is a faster and easier way to get a mod that needs a very limited UI setup. However, I imagine it defaults to the very top layer of the engine, and doesn't allow easy hiding behind DF's UI items? Even if so, it will work fine for this mod, as I can hide and show the buttons using switches, and I can also put it to the far left or right, where the inventory menu doesn't overlay.

Here's the code I have so far. It works to setup four buttons. Two being to go back and forth between outfits, one to display the current outfit name/number you have selected and allow you to load it by clicking on the name, and one to save any changes you made to your characters current outfit after loading it.

All buttons show up, are clickable, allow for current equipment to be saved to an outfit list, then loads the list, removes empty slots in the list, and reads out the saved list in the unity debug log. From here, it is setting up the list for storing the individual lists for each outfit, and setting up the routine to equip the new outfit using the store outfit list selected by the player.

As always, super sloppy right now. So many unused components and just threw in.

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Linq;
using DaggerfallConnect;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Items;
using System.Collections.Generic;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game.UserInterfaceWindows;
using DaggerfallWorkshop.Game.Formulas;
using DaggerfallWorkshop.Game.MagicAndEffects;
using DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects;
using DaggerfallWorkshop.Game.Utility;
using DaggerfallWorkshop.Utility;
using DaggerfallWorkshop.Game.Utility.ModSupport;   //required for modding features

namespace DaggerfallWorkshop.Game
{
    public class OutfitManager : MonoBehaviour
    {
        PlayerEntity playerEntity;

        #region UI Rects

        Rect nextrect = new Rect(0, 10, 120, 30);
        Rect previousButton = new Rect(0, 40, 120, 30);
        Rect count = new Rect(0, 70, 120, 60);
        Rect load = new Rect(0, 130, 130, 30);

        public DaggerfallUnityItem rightHeld;
        public DaggerfallUnityItem leftHeld;
        public DaggerfallUnityItem leftArmEquipped;
        public DaggerfallUnityItem legsEquipped;
        public DaggerfallUnityItem rightArmEquipped;
        public DaggerfallUnityItem chestEquipped;
        public static List<DaggerfallUnityItem> outfitList = new List<DaggerfallUnityItem>();
        public static List<DaggerfallUnityItem> currentEquip = new List<DaggerfallUnityItem>();

        #endregion

        #region Properties

        public PlayerEntity PlayerEntity
        {
            get { return (playerEntity != null) ? playerEntity : playerEntity = GameManager.Instance.PlayerEntity; }
        }

        #endregion

        //KeyCode toggleClosedBinding;

        IEnumerator Start()
        {
            yield return new WaitForSeconds(2);
            //delay for a few seconds` then display the Hello World message
            DaggerfallUI.Instance.PopupMessage("Outfits Initiated");
            //toggleClosedBinding = InputManager.Instance.GetBinding(InputManager.Actions.Inventory);
        }

        // Update is called once per frame
        void Update()
        {
        }

        [Invoke(StateManager.StateTypes.Game, 0)]
        public static void Init(InitParams initParams)
        {
            Debug.Log("main init");

            //just an example of how to add a mono-behavior to a scene.
            GameObject outfitGo = new GameObject("outfit");
            OutfitManager outfit = outfitGo.AddComponent<OutfitManager>();

            //after finishing, set the mod's IsReady flag to true.
            ModManager.Instance.GetMod(initParams.ModTitle).IsReady = true;
        }

        //You can have as many of these methods as you want to call by the ModManager
        //If you pass an integer to the Invoke constructor, you can control the order in which they load
        //lower loads sooner.  Note that this is per MOD not per-class.
        [Invoke(StateManager.StateTypes.Game, 1)]
        public static void Init2(InitParams initParams)
        {
            Debug.Log("init 2");

        }

        //the 2nd paramater allows you to control which state the ModManager will invoke this method - the Start state
        //-that's when the scene is first loaded, or the game state - when a game is started (either a new game, or a save is loaded)
        [Invoke(StateManager.StateTypes.Start)]
        public static void InitStart(InitParams initParams)
        {
            Debug.Log("init at Start");
            DaggerfallUI.Instance.PopupMessage("Outfits Initiated 2");
        }

        //pulls players currently equipped outfit by grabbing every equipment slot.
        //it doesn't matter if the player has something equipped or not. It will add
        //a null, which then gets removed from the list later.
        void currentEquipped ()
        {
            rightHeld = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightHand);
            leftHeld = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand);
            legsEquipped = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LegsArmor);
            leftArmEquipped = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.LeftArm);
            rightArmEquipped = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.RightArm);
            chestEquipped = PlayerEntity.ItemEquipTable.GetItem(EquipSlots.ChestArmor);
        }

        //saves the currently selected outfit. It grabs the stored equipped items through the stored
        //vars retrieved from above. Then runs through list and removes slots that had no items/null.
        //prints out items in debug.log for debugging. Null items in list will cause object reference
        //error.
        void saveCurrentOutfit()
        {
            outfitList.Add(rightHeld);
            outfitList.Add(leftHeld);
            outfitList.Add(legsEquipped);
            outfitList.Add(leftArmEquipped);
            outfitList.Add(rightArmEquipped);
            outfitList.Add(chestEquipped);

            outfitList = outfitList.Where(item => item != null).ToList();

            DaggerfallUI.Instance.PopupMessage("List Size:" + outfitList.Count);
            foreach (DaggerfallUnityItem outfitItem in outfitList)
            {
                Debug.Log(outfitItem.LongName);
            }
        }

        //beginning of outfit load routine. Will use saved outfit lists to equipped outfits to player.
        void loadCurrentOutfit()
        {
            if (outfitList != null)
            {
                foreach (DaggerfallUnityItem outfitItem in outfitList)
                {
                    DaggerfallUI.Instance.PopupMessage("Equipped:" + outfitItem.ItemName);
                }             
            }
        }

        //GUI overlay.
        void OnGUI()
        {
            //sets background color for GUI items.
            GUI.backgroundColor = Color.red;
            //counts the total windows. Use this to hide added gui items when
            //not in menu.
            int totalwindows = DaggerfallUI.UIManager.WindowCount;

            //if a menu is not open, hide gui buttons below.
            if(totalwindows != -1)
            {
                //sets up buttons and then if true trigger. Uses stored rects from above.
                if (GUI.Button(nextrect, "Next Outfit"))
                {
                    DaggerfallUI.Instance.PopupMessage("Next Outfit Equipped");
                }
                else if (GUI.Button(previousButton, "Previous Outfit"))
                {
                    DaggerfallUI.Instance.PopupMessage("Previous Outfit Equipped");
                }
                else if (GUI.Button(count, totalwindows.ToString()))
                {
                    DaggerfallUI.Instance.PopupMessage("Are you sure you want to save this outfit into slot" + totalwindows.ToString());
                    currentEquipped();
                    saveCurrentOutfit();
                }
                else if (GUI.Button(load, "Load Outfit"))
                {
                    DaggerfallUI.Instance.PopupMessage("Are you sure you want to load outfit " + totalwindows.ToString());
                    loadCurrentOutfit();
                }
            } 
        }
    }
}
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

Attempt #1 went decent. Some expected bugs. Apparently items can be loaded, even when not in inventory anymore. But they are like ghost versions. They will disappear on unequip. I guess you need to put a built in check to ensure the player has the item in their inventory, as the EquipItem routine doesn't do it for you.

My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

Got about an hour to myself, after work and the wife crashed early, and took another pass at this.

As of now, the outfit code is done. I can easily save an outfit and reload it without any bugs or issues. It will not load any items already equipped or not in the inventory for the outfit. But, as long as you have the item, and it isn't equipped, the oufit manager will equip it to complete your outfit.

I still need to add in multiple outfits. The list coding is setup for it; I now need methods to easily load or delete the saved outfit selected in the outfit list.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

First version of an outfit/equipment manager will be released soon. I need to figure out how to save and retrieve values from the save file, and then it will drop. Right now, all is working, but there is no outfit permanency between saves/play sessions. Once I finish discussing it and figuring out the coding, the mod will drop.

I do not have hotkeys setup yet, but that and custom outfit names are the two post release features I plan on putting in. Both should be easy compared to trying to sort out how save data is initialized, serialized, saved, and restored.

viewtopic.php?f=22&p=36952#p36952
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Mod Idea: Equipment Sets

Post by pango »

l3lessed wrote: Mon Dec 16, 2019 8:43 pm I do not have hotkeys setup yet, but that and custom outfit names are the two post release features I plan on putting in. Both should be easy compared to trying to sort out how save data is initialized, serialized, saved, and restored.
By the way there's a pending PR that will add hotkeys for many things: https://github.com/Interkarma/daggerfal ... /pull/1510
So maybe it'll help to integrate with that when it's ready...
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Mod Idea: Equipment Sets

Post by l3lessed »

We can consider this request/feature done. I will be releasing the first version of my mod manager in a little. Just need to setup the nexus page for it.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply