• Hi Guest!

    We have posted a new VaM2 dev log on Patreon, starting a monthly cadence of written progress updates between Beta releases. Highlights include the new Gizmos System, Selection Carousel, and Modes System with Context-Specific Editing. Beta1.2 is 7 of 21 items complete.

    Read the full post on Patreon, or follow progress on the public Trello roadmap.
CustomUI

Plugins + Scripts CustomUI

Download [<1 MB]

14mhz

Well-known member
Joined
Oct 23, 2024
Messages
287
Solutions
7
Reactions
2,027
14mhz submitted a new resource:

CustomUI - This is a plugin simple development tool.

※ Reporting bugs or issues will help me improve the plugin and help others.
CustomUI
● This .cs for plugin UI implementation library for developer.
● This library doesn't aim to offer something novel, but rather simplifies and standardizes components that are commonly implemented by developers.
● Of course...

Read more about this resource...
 
Hi 14MHz, I stumbled over a minor problem I cannot solve for now. I use a CustomUI.addSliderSimple Layout with an added Default button which itself is in a tab layout which will be reloaded on clicking on the tab. This will load the current value into the slider, which is great.
C#:
public static JSONStorableFloat erectionmorph1_min_JSON = new JSONStorableFloat("Penis Length Flaccid", 2.2f, -5.0f, 10.0f, false);

//Init value, min value, max value in the GUI
value = new float[][] {
             new float[] {erectionmorph1_min_JSON.val, erectionmorph1_min_JSON.min, erectionmorph1_min_JSON.max},
            ...

BaseLabelUI ui01 = CustomUI.addLabel(this, true, titleLabel).setTextFontSize(26).setBackgroundColor(Color.clear).setTextColor(Color.white);
ui01.setTextAlign(TextAnchor.MiddleLeft);

BaseSliderSimpleUI ui02 = CustomUI.addSliderSimple(this, true, name, _val[0], _val[1], _val[2]).setLabelTextWeight(0.0f).setSliderWeight(0.75f).setCallback(callbackEvent).register();
UIDynamicSlider u = ui02.uid as UIDynamicSlider;
if (u != null)
{
       u.defaultButtonEnabled = true;
       Transform btnTransform = u.transform.Find("DefaultValueButton");

       if (btnTransform != null)
       {
              RectTransform rt = btnTransform.GetComponent<RectTransform>();
              rt.anchoredPosition = new Vector2(-40f, 13f);
        }
}

In this situation, however, the default value is always overwritten with the current value as the slider is created. Do you have any idea how to make the default stick to the static default value of the JSONStorableFloat (2.2f in this case)? Thank you in advance for any help!!
 
Hi 14MHz, I stumbled over a minor problem I cannot solve for now. I use a CustomUI.addSliderSimple Layout with an added Default button which itself is in a tab layout which will be reloaded on clicking on the tab. This will load the current value into the slider, which is great.
C#:
public static JSONStorableFloat erectionmorph1_min_JSON = new JSONStorableFloat("Penis Length Flaccid", 2.2f, -5.0f, 10.0f, false);

//Init value, min value, max value in the GUI
value = new float[][] {
             new float[] {erectionmorph1_min_JSON.val, erectionmorph1_min_JSON.min, erectionmorph1_min_JSON.max},
            ...

BaseLabelUI ui01 = CustomUI.addLabel(this, true, titleLabel).setTextFontSize(26).setBackgroundColor(Color.clear).setTextColor(Color.white);
ui01.setTextAlign(TextAnchor.MiddleLeft);

BaseSliderSimpleUI ui02 = CustomUI.addSliderSimple(this, true, name, _val[0], _val[1], _val[2]).setLabelTextWeight(0.0f).setSliderWeight(0.75f).setCallback(callbackEvent).register();
UIDynamicSlider u = ui02.uid as UIDynamicSlider;
if (u != null)
{
       u.defaultButtonEnabled = true;
       Transform btnTransform = u.transform.Find("DefaultValueButton");

       if (btnTransform != null)
       {
              RectTransform rt = btnTransform.GetComponent<RectTransform>();
              rt.anchoredPosition = new Vector2(-40f, 13f);
        }
}

In this situation, however, the default value is always overwritten with the current value as the slider is created. Do you have any idea how to make the default stick to the static default value of the JSONStorableFloat (2.2f in this case)? Thank you in advance for any help!!
Hello, RunRudolf !
Has the issue you requested been resolved?
 
Hello, RunRudolf !
Has the issue you requested been resolved?
Hi 14mhz! No, I dont think anything changed in this regard (did you change anything?).
I think its a VaM specific behaviour that the default values are set each time a slider is created. Since this happens every time the sub UI is (re)created, the default values will be overwritten with the current active value. Maybe I have to prevent the slider from being created each time the UI is called?
 
I think its a VaM specific behaviour that the default values are set each time a slider is created.
<-- In my opinion, it seems to be an issue with the implementation method.

-----

I think that in various other button-based Tab implementations, it is often done like this.
The following implementation leads to many issues because it deletes the object when a tab is selected and recreates it every time.
C#:
if select tab
    foreach alltab
       close(tab elements)
    new(tab elements) <-- Actually, it is not advisable to implement it in this way (This is not the :) right way)
As an alternative, I suggest making only the elements within the selected Tab visible. By doing so, the problems you mentioned should not arise.
C#:
if select tab
    foreach alltab
       if (t is tab)
           visiable(tab elements)
       else
           invisiable(tab elements)
The CustomTabUI I implemented is designed in this way.

In addition, in your code,
C#:
public static JSONStorableFloat erectionmorph1_min_JSON = new JSONStorableFloat("Penis Length Flaccid", 2.2f, -5.0f, 10.0f, false);

//Init value, min value, max value in the GUI
value = new float[][] {
             new float[] {erectionmorph1_min_JSON.val, erectionmorph1_min_JSON.min, erectionmorph1_min_JSON.max},
            ...

BaseLabelUI ui01 = CustomUI.addLabel(this, true, titleLabel).setTextFontSize(26).setBackgroundColor(Color.clear).setTextColor(Color.white);
ui01.setTextAlign(TextAnchor.MiddleLeft);

BaseSliderSimpleUI ui02 = CustomUI.addSliderSimple(this, true, name, _val[0], _val[1], _val[2]).setLabelTextWeight(0.0f).setSliderWeight(0.75f).setCallback(callbackEvent).register();
UIDynamicSlider u = ui02.uid as UIDynamicSlider;
if (u != null)
{
       u.defaultButtonEnabled = true;
       Transform btnTransform = u.transform.Find("DefaultValueButton");

       if (btnTransform != null)
       {
              RectTransform rt = btnTransform.GetComponent<RectTransform>();
              rt.anchoredPosition = new Vector2(-40f, 13f);
        }
}
when register() is called with name as the key, a JSONStorableFloat is generated automatically.
Apart from sharing the initial value, it is not connected to "erectionmorph1_min_JSON"
 
Last edited:
<-- In my opinion, it seems to be an issue with the implementation method.

-----

I think that in various other button-based Tab implementations, it is often done like this.
The following implementation leads to many issues because it deletes the object when a tab is selected and recreates it every time.
C#:
if select tab
    foreach alltab
       close(tab elements)
    new(tab elements) <-- Actually, it is not advisable to implement it in this way (This is not the :) right way)
As an alternative, I suggest making only the elements within the selected Tab visible. By doing so, the problems you mentioned should not arise.
C#:
if select tab
    foreach alltab
       if (t is tab)
           visiable(tab elements)
       else
           invisiable(tab elements)
The CustomTabUI I implemented is designed in this way.

In addition, in your code,
C#:
public static JSONStorableFloat erectionmorph1_min_JSON = new JSONStorableFloat("Penis Length Flaccid", 2.2f, -5.0f, 10.0f, false);

//Init value, min value, max value in the GUI
value = new float[][] {
             new float[] {erectionmorph1_min_JSON.val, erectionmorph1_min_JSON.min, erectionmorph1_min_JSON.max},
            ...

BaseLabelUI ui01 = CustomUI.addLabel(this, true, titleLabel).setTextFontSize(26).setBackgroundColor(Color.clear).setTextColor(Color.white);
ui01.setTextAlign(TextAnchor.MiddleLeft);

BaseSliderSimpleUI ui02 = CustomUI.addSliderSimple(this, true, name, _val[0], _val[1], _val[2]).setLabelTextWeight(0.0f).setSliderWeight(0.75f).setCallback(callbackEvent).register();
UIDynamicSlider u = ui02.uid as UIDynamicSlider;
if (u != null)
{
       u.defaultButtonEnabled = true;
       Transform btnTransform = u.transform.Find("DefaultValueButton");

       if (btnTransform != null)
       {
              RectTransform rt = btnTransform.GetComponent<RectTransform>();
              rt.anchoredPosition = new Vector2(-40f, 13f);
        }
}
when register() is called with name as the key, a JSONStorableFloat is generated automatically.
Apart from sharing the initial value, it is not connected to "erectionmorph1_min_JSON"
Thanks for your help! I am aware that this method is not perfect, but I cannot restructure the entire UI. I also did not succeed putting the entire layout into a container and hiding it without leaving empty boxes. So I coutinue working with the create and destroy method, but now found a way to add consistent defaultValues for your SliderSimples.

I added the following function to your CustomUI.cs to reset the DefaultValue to the initial value of the JSONStorableFloat each time the UI is created:
C#:
        public BaseSliderSimpleUI setDefaultValue(float def) //Added by RunRudolf
        {
            UIDynamicSlider u = uid as UIDynamicSlider;
            if (u != null)
            {
                u.defaultValue = def;
                u.defaultButtonEnabled = true; //Optional, if button was deactivated
            }
            return this;
        }

I then call this in a for with the .setDefaultValue() included:
C#:
for (int r = 0; r < layout.row; r++)
{
      string name2 = variable[(r * 2) + 1];
      float[] _val = value[r * 2];
      float[] _val2 = value[(r * 2) + 1];
      float[] _defVal2 = defaultValue[r + 1];
      ...

      BaseSliderSimpleUI ui03 = CustomUI.addSliderSimple(this, true, name2, _val2[0], _val2[1],   _val2[2]).setLabelTextWeight(0.0f).setSliderWeight(0.75f).setCallback(callbackEvent).setDefaultValue(_defVal2[0]);
      UIDynamicSlider u2 = ui03.uid as UIDynamicSlider;
      if (u2 != null)
       {
                u2.defaultButtonEnabled = true;
                Transform btnTransform = u2.transform.Find("DefaultValueButton");
                if (btnTransform != null)
                {
                        RectTransform rt = btnTransform.GetComponent<RectTransform>();
                        rt.anchoredPosition = new Vector2(-40f, 13f);
                 }
       }
}

The defaultValues are simply created like this:
C#:
defaultValue = new float[][] {
      new float[] {erectionmorph1_min_JSON.defaultVal},
      new float[] {erectionmorph1_max_JSON.defaultVal},
      ...

It seems to solve the problem of changing default values for me. BTW, I also left the .register(), its not needed here apparently. Thanks again for your feedback!
 
How would I show/hide certain UI elements?
Trying .uid.gameObject.SetActive(false) but that isn't hiding them for me.
 
How would I show/hide certain UI elements?
Trying .uid.gameObject.SetActive(false) but that isn't hiding them for me.
Good to hear from you, bill_prime. I'm away from my computer at the moment, so I can't be exact. SetActive normally works fine, but when it fails, in my experience it's usually due to interference from another routine. (I turned it off, but another process is turning it back on). Rather than calling it in Init() or Start(), try testing it in Update().
 
Good to hear from you, bill_prime. I'm away from my computer at the moment, so I can't be exact. SetActive normally works fine, but when it fails, in my experience it's usually due to interference from another routine. (I turned it off, but another process is turning it back on). Rather than calling it in Init() or Start(), try testing it in Update().
Okay no worries, thank you for the reply. I will do some more testing in different cases.
 

Similar threads

Replies
23
Views
2K
Back
Top Bottom