Giter VIP home page Giter VIP logo

uielementsunturned's Introduction

UIElementsUnturned Discord

This lib will help you easy communicate with UI in Unturned!

About this library

This library makes easy listening player UI button clicks and text input in inputfields and more.

Getting Started

First of all, download UIElementsLib.

Then, select mod what you are using for.

If you cant see your mod here dont worry you can use RocketMod version, this is not depends on RocketMod, but it 100% is made for it, or you can write about it in issues or you can implement this by yourself!

Contributing!

For more info click here.


ย 

uielementsunturned's People

Contributors

0x59r11 avatar sunnamed434 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

0x59r11 gmh5225

uielementsunturned's Issues

Hard example -> possible Null reference Exception

So, UIElementsLibPluginExample Instance is not assigned anywhere in code

Problem

Possible exception

public sealed class UIElementsLibPluginExample : RocketPlugin<UIElementsLibPluginExampleConfiguration>
{
    private InputFieldUIHolder inputFieldUIHolder;

    private ButtonUIHolder buttonUIHolder;



    public static UIElementsLibPluginExample Instance { get; private set; }



    protected override void Load()
    {
        // Creating Input Fields holder
        inputFieldUIHolder = new InputFieldUIHolder(items: new List<IInputField>
        {
            new SearchInputField(),
        });

        // Creating Buttons holder
        buttonUIHolder = new ButtonUIHolder(items: new List<IButton>
        {
            new CloseUIButton(configurationAsset: Instance.Configuration),
        });

        // Adding new Button, for special tests or fast work you can use ActionButton
        buttonUIHolder.AddNew(new ActionableButton(childObjectName: "MyUIObjectName", callback: (data, uPlayer) =>
        {

        }));

        // Or like that same with input field
        inputFieldUIHolder.AddNew(new ActionableInputField(childObjectName: "MyInputField", callback: onEnterInputInMyInputFieldCallback));

        // Removing input field
        inputFieldUIHolder.Remove(inputFieldUIHolder.FindItem("MyInputField"));

        EffectManager.onEffectTextCommitted += onInputFieldTextCommitted;
        EffectManager.onEffectButtonClicked += onButtonClicked;
    }

ActionableButton add classes with generics

add with this #6

public sealed class ActionableButton<TCallbackArgument1, TCallbackArgument2..> : IActionableUIElement<TCallbackArgument1, TCallbackArgument2..>, IButton
{
    public string ChildObjectName { get; }

    public Action<TCallbackArgument1, TCallbackArgument2..> Callback { get; }



    public ActionableButton(string childObjectName, Action<..> callback)
    {
    }



    void IButton.OnClick(UPlayer executor)
    {
        Callback?.Invoke(..);
    }
}

Upload fix of OpenMod version

OpenMod + UIElementsLib won`t work at the moment, at the moment I already have an working example + real usage plugin with it

IUIHolder add method for safely finding UI Elements

Examples:

bool TryFindItem(string childObjectName, out TUIHolder result);

to avoid this usage:

inputFieldUIHolder.FindItem(inputField)?.OnEnterInput(new UPlayer(player), text);

in result:

if (inputFieldUIHolder.TryFindItem(string childObjectName, out IInputField result))
     result.OnEnterInput(childObjectName);

UIElementsLib: UIHolderBase problems

1.
Problem_1

  1. private IList holders;
    Should looks like:
private readonly IList<TUIHolder> holders;

2.
Problem_2

  1. method FindItem and returning holders
    Should looks like:
public TUIHolder FindItem(string childObjectName)
{
    if (string.IsNullOrEmpty(childObjectName))
        throw new ArgumentNullException(nameof(childObjectName));

    return Holders.FirstOrDefault(h => h.ChildObjectName.Equals(childObjectName));
}

IActionableUIElement add new generics

Add 16 generics arguments

public interface IActionableUIElement<in TCallbackArgument1, in TCallbackArgument2, in TCallbackArgument3, in TCallbackArgument4, in TCallbackArgument5, in TCallbackArgument6, in TCallbackArgument7, in TCallbackArgument8, in TCallbackArgument9, in TCallbackArgument10> : IUIElement
{
    Action<TCallbackArgument1, TCallbackArgument2, TCallbackArgument3, TCallbackArgument4, TCallbackArgument5, TCallbackArgument6, TCallbackArgument7, TCallbackArgument8, TCallbackArgument9, TCallbackArgument10... - TCallbackArgument16> Callback { get; }
}

IUIHolder not right describes documentation

/// <summary>
/// Trying to find item safely by calling <see cref="TryFindItem(IChildObjectNameString, out TUIHolder)"/>.
/// </summary>
/// <param name="childObjectName">Child object name for searching.</param>
/// <param name="holder">Found UI Holder.</param>
/// <returns>Found UI Holder.</returns>
/// <exception cref="System.ArgumentException"></exception>
bool TryFindItem(string childObjectName, out TUIHolder holder);

here is returns not a Found UI Holder -> it returns success result

all methods with this documentation mistake:

TryFindItem(IChildObjectNameString childObjectNameString, out TUIHolder holder);
TryFindItem(string childObjectName, out TUIHolder holder);

Scatter classes and do it visible in folder, avoid contain it under interface

now interface IEffectArguments.cs looks like that:

/// <summary>
/// Model of Effect Arguments.
/// </summary>
public interface IEffectArguments
{
    /// <summary>
    /// Effect id.
    /// </summary>
    ushort Id { get; }

    /// <summary>
    /// Effect key.
    /// </summary>
    short Key { get; }
}

public class EffectArguments : IEffectArguments
{
    public ushort Id { get; }

    public short Key { get; }



    public EffectArguments(ushort id, short key)
    {
        Id = id;
        Key = key;
    }
}

[Serializable]
public class SerializableEffectArguments : IEffectArguments
{
    public ushort Id { get; set; }

    public short Key { get; set; }



    public SerializableEffectArguments(ushort id, short key)
    {
        Id = id;
        Key = key;
    }

    public SerializableEffectArguments()
    {
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.