Exemplo n.º 1
0
        /// <summary>
        /// Draw the body of the block.
        /// </summary>
        private static void DrawItems()
        {
            // exit early if there are no items
            if (items == null || items.Count == 0)
            {
                return;
            }

            // display items (move up, move down, int field,
            for (int i = 0; i < items.Count; i++)
            {
                //---------------------------------------------
                // get the box to draw around the foldout
                //---------------------------------------------
                GUIStyle style       = Box.StyleDefault;
                GUIStyle buttonStyle = Button.StyleFoldoutText;
                if (HeroObjectMenuBlock.stateFocus && HeroObjectMenuBlock.stateID == stateIndex && HeroObjectMenuBlock.eventID == eventIndex && HeroObjectMenuBlock.actionID == i)
                {
                    style       = Box.StyleMenuSelected;
                    buttonStyle = Button.StyleFoldoutTextB;
                }

                //---------------------------------------------
                // get the prefix to show before the name of the item
                //---------------------------------------------
                string prefix = (items[i].actionTemplate != null) ? items[i].actionTemplate.title : "";

                //---------------------------------------------
                // get the name to show for the action
                //---------------------------------------------
                string itemName = items[i].name;
                if (items[i].actionTemplate != null)
                {
                    itemName = (items[i].name != "") ? items[i].name : items[i].actionTemplate.name;
                }

                // dont show item name if prefix found and if item has no name
                itemName = (prefix != "" && items[i].name == "") ? "" : itemName;

                //---------------------------------------------
                // set indent level of this action
                //---------------------------------------------
                if (items[i].actionTemplate != null)
                {
                    // get new indent
                    indent = indent + items[i].actionTemplate.indentThis;

                    // if indent is negative, change it to zero (happens if too many end statements added)
                    if (indent < 0)
                    {
                        indent = 0;
                    }
                }
                items[i].indent = indent;
                string space = "".PadRight(indent * 5);

                //---------------------------------------------
                // set the color of the action title text
                //---------------------------------------------
                string hexColor = (SimpleGUICommon.isProSkin) ? "FFFFFF" : "000000";
                if (items[i].actionTemplate != null)
                {
                    hexColor = SimpleGUICommon.GetHexFromColor(items[i].actionTemplate.titleColor);

                    // lighten colors for dark skin
                    if (SimpleGUICommon.isProSkin)
                    {
                        hexColor = SimpleGUICommon.AlterHexBrightness(hexColor, 150);
                    }
                }

                //---------------------------------------------
                // if button is disabled, change the color of the text
                //---------------------------------------------
                if (!items[i].active)
                {
                    buttonStyle = Button.StyleFoldoutDisabledText;
                    hexColor    = SimpleGUICommon.GetHexFromColor(Button.StyleFoldoutDisabledText.normal.textColor);
                }

                //---------------------------------------------
                // show foldout
                //---------------------------------------------
                SimpleLayout.BeginHorizontal();
                SimpleLayout.Space(indentMenu);
                SimpleLayout.BeginHorizontal(style);
                string name = HeroObjectMenuBlock.textIcon + " " + blockName + " " + i + ": " + space + "<color=#" + hexColor + ">" + prefix + itemName + "</color>";
                SimpleLayout.Button(name, showBlockContent, showContextMenu, stateIndex, eventIndex, i, buttonStyle);
                SimpleLayout.EndHorizontal();
                SimpleLayout.EndHorizontal();

                //---------------------------------------------
                // set indent level of next action
                //---------------------------------------------

                // note if delete called, the last item in list won't exist. check to make sure it is still there.
                if (items.Count > i && items[i].actionTemplate != null)
                {
                    // get new indent
                    indent = indent + items[i].actionTemplate.indentNext;

                    // if indent is negative, change it to zero (happens if too many end statements added)
                    if (indent < 0)
                    {
                        indent = 0;
                    }
                }

                // if we are at the end of the action list, reset indent
                if (i == (items.Count - 1))
                {
                    indent = 0;
                }
            }
        }