Esempio n. 1
0
        partial void InitProjSpecific(XElement element)
        {
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "fissionratemeter":
                    fissionRateMeter = new Sprite(subElement);
                    break;

                case "turbineoutputmeter":
                    turbineOutputMeter = new Sprite(subElement);
                    break;

                case "meterpointer":
                    meterPointer = new Sprite(subElement);
                    break;

                case "sectorsprite":
                    sectorSprite = new Sprite(subElement);
                    break;

                case "tempmeterframe":
                    tempMeterFrame = new Sprite(subElement);
                    break;

                case "tempmeterbar":
                    tempMeterBar = new Sprite(subElement);
                    break;

                case "temprangeindicator":
                    tempRangeIndicator = new Sprite(subElement);
                    break;

                case "graphline":
                    graphLine = new Sprite(subElement);
                    break;
                }
            }

            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), GuiFrame.RectTransform, Anchor.Center), isHorizontal: true)
            {
                RelativeSpacing = 0.012f,
                Stretch         = true
            };

            GUIFrame columnLeft  = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), paddedFrame.RectTransform), style: null);
            GUIFrame columnMid   = new GUIFrame(new RectTransform(new Vector2(0.45f, 1.0f), paddedFrame.RectTransform), style: null);
            GUIFrame columnRight = new GUIFrame(new RectTransform(new Vector2(0.3f, 1.0f), paddedFrame.RectTransform), style: null);

            leftHUDColumn  = columnLeft;
            midHUDColumn   = columnMid;
            rightHUDColumn = columnRight;

            //----------------------------------------------------------
            //left column
            //----------------------------------------------------------

            int buttonsPerRow = 2;
            int spacing       = 5;
            int buttonWidth   = columnLeft.Rect.Width / buttonsPerRow - (spacing * (buttonsPerRow - 1));
            int buttonHeight  = (int)(columnLeft.Rect.Height * 0.5f) / 4;

            for (int i = 0; i < warningTexts.Length; i++)
            {
                var warningBtn = new GUIButton(new RectTransform(new Point(buttonWidth, buttonHeight), columnLeft.RectTransform)
                {
                    AbsoluteOffset = new Point((i % buttonsPerRow) * (buttonWidth + spacing), (int)Math.Floor(i / (float)buttonsPerRow) * (buttonHeight + spacing))
                },
                                               TextManager.Get(warningTexts[i]), style: "IndicatorButton")
                {
                    CanBeFocused = false
                };

                var btnText = warningBtn.GetChild <GUITextBlock>();
                btnText.Font = GUI.Font;
                btnText.Wrap = false;
                btnText.SetTextPos();
                warningButtons.Add(warningTexts[i], warningBtn);
            }
            GUITextBlock.AutoScaleAndNormalize(warningButtons.Values.Select(b => b.TextBlock));

            inventoryContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.45f), columnLeft.RectTransform, Anchor.BottomLeft), style: null);

            //----------------------------------------------------------
            //mid column
            //----------------------------------------------------------

            criticalHeatWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform),
                                                 TextManager.Get("ReactorWarningCriticalTemp"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };
            lowTemperatureWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.27f, 0.0f)
            },
                                                   TextManager.Get("ReactorWarningCriticalLowTemp"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };
            criticalOutputWarning = new GUITickBox(new RectTransform(new Point(columnMid.Rect.Width / 3, (int)(30 * GUI.Scale)), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.66f, 0.0f)
            },
                                                   TextManager.Get("ReactorWarningCriticalOutput"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };

            GUITextBlock.AutoScaleAndNormalize(criticalHeatWarning.TextBlock, lowTemperatureWarning.TextBlock, criticalOutputWarning.TextBlock);

            float gaugeOffset = criticalHeatWarning.Rect.Height / (float)columnMid.Rect.Height + 0.05f * GUI.Scale;

            new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.05f), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, gaugeOffset)
            },
                             TextManager.Get("ReactorFissionRate"));
            new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, gaugeOffset + 0.05f)
            },
                                   DrawFissionRateMeter, null)
            {
                ToolTip = TextManager.Get("ReactorTipFissionRate")
            };

            new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.05f), columnMid.RectTransform, Anchor.TopRight)
            {
                RelativeOffset = new Vector2(0.0f, gaugeOffset)
            },
                             TextManager.Get("ReactorTurbineOutput"));
            new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform, Anchor.TopRight)
            {
                RelativeOffset = new Vector2(0.0f, gaugeOffset + 0.05f)
            },
                                   DrawTurbineOutputMeter, null)
            {
                ToolTip = TextManager.Get("ReactorTipTurbineOutput")
            };

            GUILayoutGroup sliderControls = new GUILayoutGroup(new RectTransform(new Point(columnMid.Rect.Width, (int)(114 * GUI.Scale)), columnMid.RectTransform, Anchor.BottomCenter))
            {
                Stretch         = true,
                AbsoluteSpacing = (int)(5 * GUI.Scale)
            };

            sliderControlsContainer = sliderControls;

            new GUITextBlock(new RectTransform(new Point(0, (int)(20 * GUI.Scale)), sliderControls.RectTransform, Anchor.TopLeft),
                             TextManager.Get("ReactorFissionRate"));
            fissionRateScrollBar = new GUIScrollBar(new RectTransform(new Point(sliderControls.Rect.Width, (int)(30 * GUI.Scale)), sliderControls.RectTransform, Anchor.TopCenter),
                                                    style: "GUISlider", barSize: 0.1f)
            {
                OnMoved = (GUIScrollBar bar, float scrollAmount) =>
                {
                    LastUser          = Character.Controlled;
                    unsentChanges     = true;
                    targetFissionRate = scrollAmount * 100.0f;

                    return(false);
                }
            };

            new GUITextBlock(new RectTransform(new Point(0, (int)(20 * GUI.Scale)), sliderControls.RectTransform, Anchor.BottomLeft),
                             TextManager.Get("ReactorTurbineOutput"));
            turbineOutputScrollBar = new GUIScrollBar(new RectTransform(new Point(sliderControls.Rect.Width, (int)(30 * GUI.Scale)), sliderControls.RectTransform, Anchor.BottomCenter),
                                                      style: "GUISlider", barSize: 0.1f, isHorizontal: true)
            {
                OnMoved = (GUIScrollBar bar, float scrollAmount) =>
                {
                    LastUser            = Character.Controlled;
                    unsentChanges       = true;
                    targetTurbineOutput = scrollAmount * 100.0f;

                    return(false);
                }
            };

            //----------------------------------------------------------
            //right column
            //----------------------------------------------------------

            new GUITextBlock(new RectTransform(new Vector2(0.7f, 0.1f), columnRight.RectTransform), TextManager.Get("ReactorAutoTemp"))
            {
                ToolTip   = TextManager.Get("ReactorTipAutoTemp"),
                AutoScale = true
            };
            autoTempSlider = new GUIScrollBar(new RectTransform(new Vector2(0.6f, 0.15f), columnRight.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.1f)
            },
                                              barSize: 0.55f, style: "OnOffSlider", isHorizontal: true)
            {
                ToolTip         = TextManager.Get("ReactorTipAutoTemp"),
                IsBooleanSwitch = true,
                BarScroll       = 1.0f,
                OnMoved         = (scrollBar, scrollAmount) =>
                {
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };
            var sliderSprite = autoTempSlider.Frame.Style.Sprites[GUIComponent.ComponentState.None].First();

            autoTempSlider.RectTransform.MaxSize = new Point((int)(sliderSprite.Sprite.SourceRect.Size.X * GUI.Scale), (int)(sliderSprite.Sprite.SourceRect.Size.Y * GUI.Scale));

            onOffSwitch = new GUIScrollBar(new RectTransform(new Vector2(0.4f, 0.3f), columnRight.RectTransform, Anchor.TopRight),
                                           barSize: 0.2f, style: "OnOffLever", isHorizontal: false)
            {
                IsBooleanSwitch = true,
                MinValue        = 0.25f,
                MaxValue        = 0.75f,
                OnMoved         = (scrollBar, scrollAmount) =>
                {
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };
            var switchSprite = onOffSwitch.Frame.Style.Sprites[GUIComponent.ComponentState.None].First();

            onOffSwitch.RectTransform.MaxSize = new Point((int)(switchSprite.Sprite.SourceRect.Size.X * GUI.Scale), (int)(switchSprite.Sprite.SourceRect.Size.Y * GUI.Scale));

            var lever = onOffSwitch.GetChild <GUIButton>();

            lever.RectTransform.NonScaledSize = new Point(lever.Rect.Width + (int)(30 * GUI.Scale), lever.Rect.Height);

            var graphArea = new GUICustomComponent(new RectTransform(new Vector2(1.0f, 0.5f), columnRight.RectTransform, Anchor.BottomCenter)
            {
                AbsoluteOffset = new Point(0, 30)
            },
                                                   DrawGraph, null);

            Point textSize = new Point((int)(100 * GUI.Scale), (int)(30 * GUI.Scale));

            var loadText = new GUITextBlock(new RectTransform(textSize, graphArea.RectTransform, Anchor.TopLeft, Pivot.BottomLeft),
                                            "Load", textColor: Color.LightBlue, textAlignment: Alignment.CenterLeft)
            {
                ToolTip = TextManager.Get("ReactorTipLoad")
            };
            string loadStr = TextManager.Get("ReactorLoad");

            loadText.TextGetter += () => { return(loadStr.Replace("[kw]", ((int)load).ToString())); };

            var outputText = new GUITextBlock(new RectTransform(textSize, graphArea.RectTransform, Anchor.BottomLeft, Pivot.TopLeft),
                                              "Output", textColor: Color.LightGreen, textAlignment: Alignment.CenterLeft)
            {
                ToolTip = TextManager.Get("ReactorTipPower")
            };
            string outputStr = TextManager.Get("ReactorOutput");

            outputText.TextGetter += () => { return(outputStr.Replace("[kw]", ((int)-currPowerConsumption).ToString())); };
        }