Exemplo n.º 1
0
    /*##################################
     *
     *      Public Functions
     *
     ###################################*/
    /// <summary>
    /// Links this Bend Input Screen to a Bend and Sets up Screen Appropriately
    /// </summary>
    public override void Link(IModel model)
    {
        if (!m_HasInitialized)
        {
            Debug.LogError("BendInputScreen: Link() Screen must first be Initialized.");
            return;
        }
        if (m_Bend != null)
        {
            // Unregister Listeners on Previous Bend
            m_Bend.onEvent.RemoveListener(ListenerBend);
        }
        Bend bend = (Bend)model;

        m_Bend = bend;
        m_Bend.onEvent.AddListener(ListenerBend);

        // Initialize Output View
        InitializeOutput();

        RectTransform   scrollerContent = bendParameterScroller.content;
        RectTransform   bendParamPrefab;
        UIBendParameter uiBendParam;
        BendParameter   bendParam;

        bendParameterScroller.ClearContent();

        // Set up Bend Input Parameter View
        for (int i = 0; i < bend.inputParameters.Count; ++i)
        {
            bendParam       = bend.inputParameters[i];
            bendParamPrefab = Instantiate(bendParameterPrefab);
            bendParamPrefab.SetParent(scrollerContent, false);

            uiBendParam = bendParamPrefab.GetComponent <UIBendParameter>();
            uiBendParam.Set(bendParam.type, BendParameter.GetStringValue(bendParam.name), i);
            uiBendParam.onClick = DisplayWidget;
            if (i == 0)
            {
                // Set 1st Parameter as Selected
                uiBendParam.button.Select();
            }
        }

        bendParameterScroller.Layout();

        // Set up Help Widget
        bendParamPrefab = Instantiate(bendParameterPrefab);
        bendParamPrefab.SetParent(scrollerContent, false);
        uiBendParam = bendParamPrefab.GetComponent <UIBendParameter>();
        uiBendParam.SetAsHelp();
        uiBendParam.onClick = DisplayHelpWidget;

        // Display 1st Parameter Widget
        m_ActiveParameter = -1;
        DisplayWidget(0);
    }
Exemplo n.º 2
0
    public void SetHighlightables(List <BendParameter> highlightables)
    {
        m_highlightables = highlightables;

        // Clear previous Parameters
        var content = parameterScroller.content;

        for (int i = 0; i < content.childCount; ++i)
        {
            Destroy(content.GetChild(i).gameObject);
        }

        if (highlightables.Count == 0)
        {
            message.text = k_UnAvailableMessage;
            return;
        }
        else
        {
            message.text = k_AvailableMessage;
        }

        // Populate Parameter view
        RectTransform scrollerContent = parameterScroller.content;
        RectTransform paramPrefab;
        Button        paramButton;
        Text          paramText;
        Vector2       nextPos = parameterPrefab.anchoredPosition;
        Vector2       size    = parameterPrefab.rect.size;

        for (var i = 0; i < m_highlightables.Count; ++i)
        {
            var param = m_highlightables[i];
            var index = i;
            // Instantiate next
            paramPrefab = Instantiate(parameterPrefab);

            // Position, Format and Listen
            paramButton = paramPrefab.GetComponent <Button>();
            paramButton.onClick.AddListener(() => { OnParameterClick(index); });

            paramText       = paramPrefab.GetComponent <Text>();
            paramText.text  = BendParameter.GetStringValue(param.name);
            paramText.color = Color.black;

            paramPrefab.SetParent(scrollerContent, false);
            paramPrefab.anchoredPosition = nextPos;
            paramPrefab.gameObject.SetActive(true);

            nextPos.y -= size.y;
        }
    }
Exemplo n.º 3
0
    private void InitializeOutput()
    {
        // Init Output View
        TextColumns.TextPair textPair;
        BendParameter        bendParam;
        int pinput = 0;

        m_EnabledParameterMask = 0;
        m_OutputText.Clear();

        // Input Parameters
        for (int p = 0; p < m_Bend.inputParameters.Count; ++p)
        {
            bendParam = m_Bend.inputParameters[p];

            textPair       = new TextColumns.TextPair();
            textPair.left  = "<b>" + BendParameter.GetStringValue(bendParam.name) + ":</b> ";
            textPair.right = "<color=#" + bendParam.colorHexString + ">" + BendParameter.GetFormattedValue(bendParam) + "</color>";

            m_OutputText.Write(textPair);
        }
        pinput = m_Bend.inputParameters.Count;

        // Output Parameters  (FF1800FF, EA75FF)
        for (int p = 0; p < m_Bend.outputParameters.Count; ++p)
        {
            bendParam = m_Bend.outputParameters[p];
            if (bendParam.enabled)
            {
                m_EnabledParameterMask |= 1 << (pinput + p);

                textPair       = new TextColumns.TextPair();
                textPair.left  = "<b>" + BendParameter.GetStringValue(bendParam.name) + ":</b> ";
                textPair.right = "<b><color=#" + bendParam.colorHexString + ">" + BendParameter.GetFormattedValue(bendParam) + "</color></b>";

                m_OutputText.Write(textPair);
            }
        }

        //Debug.Log( "BendInputScreen: InitializeOutput() m_EnabledParameterMask: " + m_EnabledParameterMask + " Lines: " + m_OutputText.lineCount );
    }
Exemplo n.º 4
0
    private void DisplayWidget(int id)
    {
        // Remove any active Highlighting
        m_Bend.SetHighlight(null);
        m_HelpWidget.GetComponentInChildren <BendHelp>().UnSelect();

        // Don't reselect the same Widget
        if (m_ActiveParameter == id)
        {
            return;
        }
        // Disable current Widget
        if (m_ActiveWidget != null)
        {
            m_ActiveWidget.gameObject.SetActive(false);
        }
        m_ActiveParameter = id;

        BendParameter      param = m_Bend.inputParameters[id];
        EBendParameterType type  = param.type;

        object[] range = BendParameter.GetRange(param.name);

        switch (type)
        {
        case EBendParameterType.FloatAngle:
            m_ActiveWidget = m_AngleWidget;
            m_ActiveWidget.gameObject.SetActive(true);
            AngleSlider ans = m_AngleWidget.GetComponentInChildren <AngleSlider>();
            ans.SetRange((float)range[0], (float)range[1]);
            ans.value = (float)param.value;
            break;

        case EBendParameterType.Float:
            m_ActiveWidget = m_RulerWidget;
            m_ActiveWidget.gameObject.SetActive(true);
            MultiRulerSlider mr = m_RulerWidget.GetComponentInChildren <MultiRulerSlider>();
            mr.SetRange((float)range[1]);
            mr.Set((float)param.value, false);
            break;

        case EBendParameterType.Integer:
            m_ActiveWidget = m_IntegerWidget;
            m_ActiveWidget.gameObject.SetActive(true);
            IntegerSlider ins = m_IntegerWidget.GetComponentInChildren <IntegerSlider>();
            ins.SetRange((int)range[0], (int)range[1]);
            ins.SetName(BendParameter.GetStringValue(param.name));
            ins.value = (int)param.value;
            break;

        case EBendParameterType.StringEnum:
            m_ActiveWidget = m_EnumWidget;
            m_ActiveWidget.gameObject.SetActive(true);

            EnumDropdown ed = m_EnumWidget.GetComponentInChildren <EnumDropdown>();
            List <Dropdown.OptionData> enumList = ed.options;
            StringEnum se        = (StringEnum)param.valueObject;
            int        enumStart = (int)range[0];
            int        enumEnd   = (int)range[1];
            enumList.Clear();
            for (int i = enumStart; i <= enumEnd; ++i)
            {
                enumList.Add(new EnumDropdown.EnumOptionData(se.ToStringValue(i), null, se.ToDescription(i)));
            }
            ed.value = (int)param.value;
            ed.Refresh();
            break;

        default:
            throw new ArgumentException("BendInputScreen: DisplayWidget() Invalid type.");
        }
    }