示例#1
0
 /// <summary>
 /// Enable and position the appropriate text object for rendering.
 /// </summary>
 /// <param name="showPage">Are we showing the page (true) or hiding it (false)?</param>
 internal void RenderPage(bool showPage)
 {
     if (showPage)
     {
         if (enabled)
         {
             if (active)
             {
                 activeText.SetRenderEnabled(true);
                 // Since I alias activeText and passiveText, I have to update
                 // the colors here.  Maybe I should simple create active and
                 // passive instances from the activeText, but that can
                 // double the number of texts that need updated.
                 activeText.SetColor(activeColor);
             }
             else
             {
                 passiveText.SetRenderEnabled(true);
                 passiveText.SetColor(passiveColor);
             }
         }
         else
         {
             if (usesDisabled)
             {
                 disabledText.SetRenderEnabled(true);
             }
             else
             {
                 if (active)
                 {
                     activeText.SetRenderEnabled(true);
                     activeText.SetColor(activeColor);
                 }
                 else
                 {
                     passiveText.SetRenderEnabled(true);
                     passiveText.SetColor(passiveColor);
                 }
             }
         }
     }
     else
     {
         activeText.SetRenderEnabled(false);
         passiveText.SetRenderEnabled(false);
         if (usesDisabled)
         {
             disabledText.SetRenderEnabled(false);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Called with `true` prior to the page rendering.  Called with
 /// `false` after the page completes rendering.
 /// </summary>
 /// <param name="enable">true indicates that the page is about to
 /// be rendered.  false indicates that the page has completed rendering.</param>
 public override void RenderPage(bool enable)
 {
     textObj.SetRenderEnabled(enable);
 }
示例#3
0
            internal MenuItem(ConfigNode itemNode, GameObject rootObject, Font font, Vector2 fontSize, FontStyle style, Color32 defaultColor, MASFlightComputer comp, InternalProp prop, VariableRegistrar variableRegistrar, int itemId)
            {
                string itemIdStr = itemId.ToString();

                if (!itemNode.TryGetValue("name", ref name))
                {
                    name = "anonymous";
                }

                string selectEventStr = string.Empty;

                if (itemNode.TryGetValue("selectEvent", ref selectEventStr))
                {
                    selectEventStr = selectEventStr.Replace("%ITEMID%", itemIdStr);
                    selectEvent    = comp.GetAction(selectEventStr, prop);
                }

                enabled = true;

                string activeColorStr = string.Empty;

                if (!itemNode.TryGetValue("activeColor", ref activeColorStr) || string.IsNullOrEmpty(activeColorStr))
                {
                    activeColor = defaultColor;
                }
                else
                {
                    activeColor = Utility.ParseColor32(activeColorStr, comp);
                }

                string activeTextStr = string.Empty;

                if (!itemNode.TryGetValue("activeText", ref activeTextStr))
                {
                    throw new ArgumentException("Missing 'activeText' in ITEM " + name);
                }
                activeTextStr = activeTextStr.Replace("%ITEMID%", itemIdStr);

                activeObject                    = new GameObject();
                activeObject.name               = rootObject.name + "_activeitem_" + name;
                activeObject.layer              = rootObject.layer;
                activeObject.transform.parent   = rootObject.transform;
                activeObject.transform.position = rootObject.transform.position;

                activeText          = activeObject.AddComponent <MdVTextMesh>();
                activeText.material = new Material(MASLoader.shaders["MOARdV/TextMonitor"]);
                activeText.SetFont(font, fontSize);
                activeText.SetColor(activeColor);
                activeText.material.SetFloat(Shader.PropertyToID("_EmissiveFactor"), 1.0f);
                activeText.fontStyle = style;
                activeText.SetText(activeTextStr, false, true, comp, prop);
                activeText.SetRenderEnabled(false);

                string passiveColorStr = string.Empty;

                if (!itemNode.TryGetValue("passiveColor", ref passiveColorStr) || string.IsNullOrEmpty(passiveColorStr))
                {
                    passiveColor = activeColor;
                }
                else
                {
                    passiveColor = Utility.ParseColor32(passiveColorStr, comp);
                }

                string passiveTextStr = string.Empty;

                if (!itemNode.TryGetValue("passiveText", ref passiveTextStr))
                {
                    passiveObject = activeObject;
                    passiveText   = activeText;
                }
                else
                {
                    passiveTextStr = passiveTextStr.Replace("%ITEMID%", itemIdStr);

                    passiveObject                    = new GameObject();
                    passiveObject.name               = rootObject.name + "_passiveitem_" + name;
                    passiveObject.layer              = rootObject.layer;
                    passiveObject.transform.parent   = rootObject.transform;
                    passiveObject.transform.position = rootObject.transform.position;

                    passiveText          = passiveObject.AddComponent <MdVTextMesh>();
                    passiveText.material = new Material(MASLoader.shaders["MOARdV/TextMonitor"]);
                    passiveText.SetFont(font, fontSize);
                    passiveText.SetColor(passiveColor);
                    passiveText.material.SetFloat(Shader.PropertyToID("_EmissiveFactor"), 1.0f);
                    passiveText.fontStyle = style;
                    passiveText.SetText(passiveTextStr, false, true, comp, prop);
                    passiveText.SetRenderEnabled(false);
                }

                string activeVariableStr = string.Empty;

                if (itemNode.TryGetValue("activeVariable", ref activeVariableStr))
                {
                    active            = false;
                    activeVariableStr = activeVariableStr.Replace("%ITEMID%", itemIdStr);
                    variableRegistrar.RegisterVariableChangeCallback(activeVariableStr, (double newValue) => active = (newValue > 0.0));
                }
                else
                {
                    active = true;
                }

                string enabledVariableStr = string.Empty;

                if (itemNode.TryGetValue("enabledVariable", ref enabledVariableStr))
                {
                    usesDisabled       = true;
                    enabled            = false;
                    enabledVariableStr = enabledVariableStr.Replace("%ITEMID%", itemIdStr);
                    variableRegistrar.RegisterVariableChangeCallback(enabledVariableStr, (double newValue) => enabled = (newValue > 0.0));

                    string disabledTextStr = string.Empty;
                    if (!itemNode.TryGetValue("disabledText", ref disabledTextStr))
                    {
                        throw new ArgumentException("Missing 'disabledText' in ITEM " + name);
                    }
                    disabledTextStr = disabledTextStr.Replace("%ITEMID%", itemIdStr);

                    Color32 disabledColor;
                    string  disabledColorStr = string.Empty;
                    if (!itemNode.TryGetValue("disabledColor", ref disabledColorStr) || string.IsNullOrEmpty(disabledColorStr))
                    {
                        disabledColor = defaultColor;
                    }
                    else
                    {
                        disabledColor = Utility.ParseColor32(disabledColorStr, comp);
                    }

                    disabledObject                    = new GameObject();
                    disabledObject.name               = rootObject.name + "_disableditem_" + name;
                    disabledObject.layer              = rootObject.layer;
                    disabledObject.transform.parent   = rootObject.transform;
                    disabledObject.transform.position = rootObject.transform.position;

                    disabledText          = disabledObject.AddComponent <MdVTextMesh>();
                    disabledText.material = new Material(MASLoader.shaders["MOARdV/TextMonitor"]);
                    disabledText.SetFont(font, fontSize);
                    disabledText.SetColor(disabledColor);
                    disabledText.material.SetFloat(Shader.PropertyToID("_EmissiveFactor"), 1.0f);
                    disabledText.fontStyle = style;
                    disabledText.SetText(disabledTextStr, false, true, comp, prop);
                    disabledText.SetRenderEnabled(false);
                }
                else
                {
                    enabled      = true;
                    usesDisabled = false;
                }
            }