Пример #1
0
        partial void InitProjSpecific(XElement element)
        {
            uiElements.Clear();

            var visibleElements = customInterfaceElementList.Where(ciElement => !string.IsNullOrEmpty(ciElement.Label));

            GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center),
                                                            childAnchor: customInterfaceElementList.Count > 1 ? Anchor.TopCenter : Anchor.Center)
            {
                RelativeSpacing = 0.05f,
                Stretch         = visibleElements.Count() > 2
            };

            float elementSize = Math.Min(1.0f / visibleElements.Count(), 0.5f);

            foreach (CustomInterfaceElement ciElement in visibleElements)
            {
                if (ciElement.ContinuousSignal)
                {
                    var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementSize), paddedFrame.RectTransform),
                                                 TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label)
                    {
                        UserData = ciElement
                    };
                    tickBox.TextBlock.AutoScale = true;
                    tickBox.OnSelected         += (tBox) =>
                    {
                        if (GameMain.Client == null)
                        {
                            TickBoxToggled(tBox.UserData as CustomInterfaceElement, tBox.Selected);
                        }
                        else
                        {
                            item.CreateClientEvent(this);
                        }
                        return(true);
                    };
                    uiElements.Add(tickBox);
                }
                else
                {
                    var btn = new GUIButton(new RectTransform(new Vector2(1.0f, elementSize), paddedFrame.RectTransform),
                                            TextManager.Get(ciElement.Label, returnNull: true) ?? ciElement.Label, style: "GUIButtonLarge")
                    {
                        UserData = ciElement
                    };
                    btn.TextBlock.AutoScale = true;
                    btn.OnClicked          += (_, userdata) =>
                    {
                        if (GameMain.Client == null)
                        {
                            ButtonClicked(userdata as CustomInterfaceElement);
                        }
                        else
                        {
                            GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.GetComponentIndex(this), userdata as CustomInterfaceElement });
                        }
                        return(true);
                    };
                    uiElements.Add(btn);
                }
            }
        }
Пример #2
0
        partial void InitProjSpecific(XElement element)
        {
            powerIndicator = new GUITickBox(new RectTransform(new Point(30, 30), GuiFrame.RectTransform)
            {
                RelativeOffset = new Vector2(0.05f, 0.15f)
            },
                                            TextManager.Get("EnginePowered"), style: "IndicatorLightGreen")
            {
                CanBeFocused = false
            };

            string powerLabel = TextManager.Get("EngineForce");

            new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.3f), GuiFrame.RectTransform, Anchor.BottomCenter)
            {
                RelativeOffset = new Vector2(0.0f, 0.4f)
            }, "", textAlignment: Alignment.Center)
            {
                TextGetter = () => { return(powerLabel + ": " + (int)(targetForce) + " %"); }
            };

            var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.25f), GuiFrame.RectTransform, Anchor.BottomCenter)
            {
                RelativeOffset = new Vector2(0.0f, 0.2f)
            }, isHorizontal: true);

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), sliderArea.RectTransform), TextManager.Get("EngineBackwards"),
                             font: GUI.SmallFont, textAlignment: Alignment.Center);
            forceSlider = new GUIScrollBar(new RectTransform(new Vector2(0.6f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider")
            {
                Step    = 0.05f,
                OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
                {
                    float newTargetForce = barScroll * 200.0f - 100.0f;
                    if (Math.Abs(newTargetForce - targetForce) < 0.01)
                    {
                        return(false);
                    }

                    targetForce = newTargetForce;
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                        GameServer.Log(Character.Controlled.LogName + " set the force speed of " + item.Name + " to " + (int)(targetForce) + " %", ServerLog.MessageType.ItemInteraction);
                    }
                    else if (GameMain.Client != null)
                    {
                        correctionTimer = CorrectionDelay;
                        item.CreateClientEvent(this);
                    }
                    return(true);
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(0.2f, 1.0f), sliderArea.RectTransform), TextManager.Get("EngineForwards"),
                             font: GUI.SmallFont, textAlignment: Alignment.Center);

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "propellersprite":
                    propellerSprite = new SpriteSheet(subElement);
                    AnimSpeed       = subElement.GetAttributeFloat("animspeed", 1.0f);
                    break;
                }
            }
        }
Пример #3
0
        public void CreatePreviewWindow(GUIMessageBox messageBox)
        {
            var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), messageBox.Content.RectTransform), ServerName, textAlignment: Alignment.Center, font: GUI.LargeFont, wrap: true);

            var serverMsg = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), messageBox.Content.RectTransform));

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverMsg.Content.RectTransform), ServerMessage, wrap: true);

            var columnContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), messageBox.Content.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            var columnLeft = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), columnContainer.RectTransform))
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };
            var columnRight = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), columnContainer.RectTransform))
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };

            float elementHeight = 0.1f;

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

            //new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnLeft.RectTransform), IP + ":" + Port);
            new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnLeft.RectTransform),
                             TextManager.Get("ServerListVersion") + ": " + (string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion));
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), columnLeft.RectTransform),
                             TextManager.Get("ServerListContentPackages"));

            var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.7f), columnLeft.RectTransform));

            if (ContentPackageNames.Count == 0)
            {
                new GUITextBlock(new RectTransform(Vector2.One, contentPackageList.Content.RectTransform), TextManager.Get("Unknown"), textAlignment: Alignment.Center)
                {
                    CanBeFocused = false
                };
            }
            else
            {
                List <string> availableWorkshopUrls = new List <string>();
                for (int i = 0; i < ContentPackageNames.Count; i++)
                {
                    var packageText = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.15f), contentPackageList.Content.RectTransform)
                    {
                        MinSize = new Point(0, 15)
                    },
                                                     ContentPackageNames[i])
                    {
                        Enabled = false
                    };
                    if (i < ContentPackageHashes.Count)
                    {
                        if (GameMain.Config.SelectedContentPackages.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
                        {
                            packageText.Selected = true;
                            continue;
                        }

                        //matching content package found, but it hasn't been enabled
                        if (ContentPackage.List.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
                        {
                            packageText.TextColor = Color.Orange;
                            packageText.ToolTip   = TextManager.Get("ServerListContentPackageNotEnabled")
                                                    .Replace("[contentpackage]", ContentPackageNames[i]);
                        }
                        //workshop download link found
                        else if (i < ContentPackageWorkshopUrls.Count && !string.IsNullOrEmpty(ContentPackageWorkshopUrls[i]))
                        {
                            availableWorkshopUrls.Add(ContentPackageWorkshopUrls[i]);
                            packageText.TextColor = Color.Yellow;
                            packageText.ToolTip   = TextManager.Get("ServerListIncompatibleContentPackageWorkshopAvailable")
                                                    .Replace("[contentpackage]", ContentPackageNames[i]);
                        }
                        else //no package or workshop download link found, tough luck
                        {
                            packageText.TextColor = Color.Red;
                            packageText.ToolTip   = TextManager.Get("ServerListIncompatibleContentPackage")
                                                    .Replace("[contentpackage]", ContentPackageNames[i])
                                                    .Replace("[hash]", ContentPackageHashes[i]);
                        }
                    }
                }
                if (availableWorkshopUrls.Count > 0)
                {
                    var workshopBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.15f), columnLeft.RectTransform), TextManager.Get("ServerListSubscribeMissingPackages"))
                    {
                        ToolTip   = TextManager.Get(SteamManager.IsInitialized ? "ServerListSubscribeMissingPackagesTooltip" : "ServerListSubscribeMissingPackagesTooltipNoSteam"),
                        Enabled   = SteamManager.IsInitialized,
                        OnClicked = (btn, userdata) =>
                        {
                            GameMain.SteamWorkshopScreen.SubscribeToPackages(availableWorkshopUrls);
                            GameMain.SteamWorkshopScreen.Select();
                            return(true);
                        }
                    };
                    workshopBtn.TextBlock.AutoScale = true;
                }
            }

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

            var playerCount = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListPlayers"));

            new GUITextBlock(new RectTransform(Vector2.One, playerCount.RectTransform), PlayerCount + "/" + MaxPlayers, textAlignment: Alignment.Right);


            new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), "Round running")
            {
                Selected     = GameStarted,
                CanBeFocused = false
            };

            var gameMode = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("GameMode"));

            new GUITextBlock(new RectTransform(Vector2.One, gameMode.RectTransform), string.IsNullOrEmpty(GameMode) ? "Unknown" : GameMode, textAlignment: Alignment.Right);

            var traitors = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("Traitors"));

            new GUITextBlock(new RectTransform(Vector2.One, traitors.RectTransform), !TraitorsEnabled.HasValue ? "Unknown" : TraitorsEnabled.Value.ToString(), textAlignment: Alignment.Right);


            var subSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListSubSelection"));

            new GUITextBlock(new RectTransform(Vector2.One, subSelection.RectTransform), !SubSelectionMode.HasValue ? "Unknown" : SubSelectionMode.Value.ToString(), textAlignment: Alignment.Right);

            var modeSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListModeSelection"));

            new GUITextBlock(new RectTransform(Vector2.One, modeSelection.RectTransform), (!ModeSelectionMode.HasValue ? "Unknown" : ModeSelectionMode.Value.ToString()), textAlignment: Alignment.Right);

            var allowSpectating = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListAllowSpectating"))
            {
                CanBeFocused = false
            };

            if (!AllowSpectating.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowSpectating.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                allowSpectating.Selected = AllowSpectating.Value;
            }

            var allowRespawn = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), "Allow respawn")
            {
                CanBeFocused = false
            };

            if (!AllowRespawn.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowRespawn.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                allowRespawn.Selected = AllowRespawn.Value;
            }

            new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListHasPassword"))
            {
                Selected     = HasPassword,
                CanBeFocused = false
            };

            var usingWhiteList = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), columnRight.RectTransform), TextManager.Get("ServerListUsingWhitelist"))
            {
                CanBeFocused = false
            };

            if (!UsingWhiteList.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), usingWhiteList.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                usingWhiteList.Selected = UsingWhiteList.Value;
            }

            // -----------------------------------------------------------------------------

            foreach (GUIComponent c in columnLeft.Children)
            {
                if (c is GUITextBlock textBlock)
                {
                    textBlock.Padding = Vector4.Zero;
                }
            }
            foreach (GUIComponent c in columnRight.Children)
            {
                if (c is GUITextBlock textBlock)
                {
                    textBlock.Padding = Vector4.Zero;
                }
            }
        }
Пример #4
0
        public GUIComponent CreateBanFrame(GUIComponent parent)
        {
            banFrame = new GUIListBox(new RectTransform(Vector2.One, parent.RectTransform, Anchor.Center));

            foreach (BannedPlayer bannedPlayer in bannedPlayers)
            {
                if (localRemovedBans.Contains(bannedPlayer.UniqueIdentifier))
                {
                    continue;
                }

                var playerFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), ((GUIListBox)banFrame).Content.RectTransform)
                {
                    MinSize = new Point(0, 70)
                }, style: null)
                {
                    UserData = banFrame
                };

                var paddedPlayerFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.85f), playerFrame.RectTransform, Anchor.Center))
                {
                    Stretch         = true,
                    RelativeSpacing = 0.05f
                };

                string ip = bannedPlayer.IP;
                if (localRangeBans.Contains(bannedPlayer.UniqueIdentifier))
                {
                    ip = ToRange(ip);
                }
                GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), paddedPlayerFrame.RectTransform),
                                                          bannedPlayer.Name + " (" + ip + ")");

                var removeButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.4f), paddedPlayerFrame.RectTransform, Anchor.TopRight), TextManager.Get("BanListRemove"))
                {
                    UserData           = bannedPlayer,
                    IgnoreLayoutGroups = true,
                    OnClicked          = RemoveBan
                };
                if (bannedPlayer.IP.IndexOf(".x") <= -1)
                {
                    var rangeBanButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.4f), paddedPlayerFrame.RectTransform, Anchor.TopRight)
                    {
                        RelativeOffset = new Vector2(0.22f, 0.0f)
                    }, TextManager.Get("BanRange"))
                    {
                        UserData           = bannedPlayer,
                        IgnoreLayoutGroups = true,
                        OnClicked          = RangeBan
                    };
                }

                new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.0f), paddedPlayerFrame.RectTransform),
                                 bannedPlayer.ExpirationTime == null ?
                                 TextManager.Get("BanPermanent") :  TextManager.GetWithVariable("BanExpires", "[time]", bannedPlayer.ExpirationTime.Value.ToString()),
                                 font: GUI.SmallFont);

                var reasonText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.0f), paddedPlayerFrame.RectTransform),
                                                  TextManager.Get("BanReason") + " " +
                                                  (string.IsNullOrEmpty(bannedPlayer.Reason) ? TextManager.Get("None") : ToolBox.LimitString(bannedPlayer.Reason, GUI.SmallFont, 170)),
                                                  font: GUI.SmallFont, wrap: true)
                {
                    ToolTip = bannedPlayer.Reason
                };
            }

            return(banFrame);
        }
Пример #5
0
		internal static void LayoutFreeGroup(GUILayoutGroup toplevel){}
Пример #6
0
        public void CreateLogFrame()
        {
            LogFrame = new GUIButton(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker")
            {
                OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock)
                                                 {
                                                     LogFrame = null;
                                                 }
                                                 return(true); }
            };
            new GUIButton(new RectTransform(Vector2.One, LogFrame.RectTransform), "", style: null).OnClicked += (btn, userData) =>
            {
                LogFrame = null;
                return(true);
            };

            GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.5f), LogFrame.RectTransform, Anchor.Center)
            {
                MinSize = new Point(700, 500)
            });
            GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.85f), innerFrame.RectTransform, Anchor.Center)
            {
                RelativeOffset = new Vector2(0.0f, -0.03f)
            }, style: null);

            new GUITextBlock(new RectTransform(new Vector2(0.75f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), TextManager.Get("ServerLog.Filter"), font: GUI.SmallFont);
            GUITextBox searchBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), font: GUI.SmallFont);

            searchBox.OnTextChanged += (textBox, text) =>
            {
                msgFilter = text;
                FilterMessages();
                return(true);
            };
            GUI.KeyboardDispatcher.Subscriber = searchBox;

            var clearButton = new GUIButton(new RectTransform(new Vector2(0.05f, 0.05f), paddedFrame.RectTransform, Anchor.TopRight), "x")
            {
                OnClicked = ClearFilter,
                UserData  = searchBox
            };

            listBox = new GUIListBox(new RectTransform(new Vector2(0.75f, 0.95f), paddedFrame.RectTransform, Anchor.BottomRight));

            var tickBoxContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.25f, 0.95f), paddedFrame.RectTransform, Anchor.BottomLeft));
            int y = 30;
            List <GUITickBox> tickBoxes = new List <GUITickBox>();

            foreach (MessageType msgType in Enum.GetValues(typeof(MessageType)))
            {
                var tickBox = new GUITickBox(new RectTransform(new Point(tickBoxContainer.Rect.Width, 30), tickBoxContainer.RectTransform), TextManager.Get("ServerLog." + messageTypeName[(int)msgType]), font: GUI.SmallFont)
                {
                    Selected   = true,
                    TextColor  = messageColor[(int)msgType],
                    OnSelected = (GUITickBox tb) =>
                    {
                        msgTypeHidden[(int)msgType] = !tb.Selected;
                        FilterMessages();
                        return(true);
                    }
                };
                tickBox.Selected = !msgTypeHidden[(int)msgType];
                tickBoxes.Add(tickBox);

                y += 20;
            }

            tickBoxes.Last().TextBlock.RectTransform.SizeChanged += () =>
            {
                GUITextBlock.AutoScaleAndNormalize(tickBoxes.Select(t => t.TextBlock));
            };

            var currLines = lines.ToList();

            foreach (LogMessage line in currLines)
            {
                AddLine(line);
            }
            FilterMessages();

            listBox.UpdateScrollBarSize();

            if (listBox.BarScroll == 0.0f || listBox.BarScroll == 1.0f)
            {
                listBox.BarScroll = 1.0f;
            }

            GUIButton closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), innerFrame.RectTransform, Anchor.BottomRight)
            {
                RelativeOffset = new Vector2(0.02f, 0.03f)
            }, TextManager.Get("Close"))
            {
                OnClicked = (button, userData) =>
                {
                    LogFrame = null;
                    return(true);
                }
            };

            msgFilter = "";
        }
Пример #7
0
        partial void InitProjSpecific(XElement element)
        {
            // TODO: need to recreate the gui when the resolution changes

            fissionRateMeter   = new Sprite(element.GetChildElement("fissionratemeter")?.GetChildElement("sprite"));
            turbineOutputMeter = new Sprite(element.GetChildElement("turbineoutputmeter")?.GetChildElement("sprite"));
            meterPointer       = new Sprite(element.GetChildElement("meterpointer")?.GetChildElement("sprite"));
            sectorSprite       = new Sprite(element.GetChildElement("sectorsprite")?.GetChildElement("sprite"));
            tempMeterFrame     = new Sprite(element.GetChildElement("tempmeterframe")?.GetChildElement("sprite"));
            tempMeterBar       = new Sprite(element.GetChildElement("tempmeterbar")?.GetChildElement("sprite"));
            tempRangeIndicator = new Sprite(element.GetChildElement("temprangeindicator")?.GetChildElement("sprite"));
            graphLine          = new Sprite(element.GetChildElement("graphline")?.GetChildElement("sprite"));

            var paddedFrame = new GUILayoutGroup(new RectTransform(
                                                     GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center)
            {
                AbsoluteOffset = GUIStyle.ItemFrameOffset
            },
                                                 isHorizontal: true)
            {
                RelativeSpacing = 0.012f,
                Stretch         = true
            };

            GUILayoutGroup columnLeft = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), paddedFrame.RectTransform))
            {
                RelativeSpacing = 0.012f,
                Stretch         = true
            };
            GUILayoutGroup columnRight = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 1.0f), paddedFrame.RectTransform))
            {
                CanBeFocused    = true,
                RelativeSpacing = 0.012f,
                Stretch         = true
            };

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

            GUIFrame inventoryWindow = new GUIFrame(new RectTransform(new Vector2(0.1f, 0.75f), GuiFrame.RectTransform, Anchor.TopLeft, Pivot.TopRight)
            {
                MinSize        = new Point(85, 220),
                RelativeOffset = new Vector2(-0.02f, 0)
            }, style: "ItemUI");

            GUILayoutGroup inventoryContent = new GUILayoutGroup(new RectTransform(inventoryWindow.Rect.Size - GUIStyle.ItemFrameMargin, inventoryWindow.RectTransform, Anchor.Center)
            {
                AbsoluteOffset = GUIStyle.ItemFrameOffset
            },
                                                                 childAnchor: Anchor.TopCenter)
            {
                Stretch = true
            };

            /*new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), inventoryContent.RectTransform), "",
             *  textAlignment: Alignment.Center, font: GUI.SubHeadingFont, wrap: true);*/
            inventoryContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.9f), inventoryContent.RectTransform), style: null);

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

            var topLeftArea = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.2f), columnLeft.RectTransform),
                                                 isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                Stretch = true
            };


            Point maxIndicatorSize = new Point(int.MaxValue, (int)(40 * GUI.Scale));

            criticalHeatWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform)
            {
                MaxSize = maxIndicatorSize
            },
                                                 TextManager.Get("ReactorWarningCriticalTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightRed")
            {
                Selected = false,
                Enabled  = false,
                ToolTip  = TextManager.Get("ReactorHeatTip")
            };
            lowTemperatureWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform)
            {
                MaxSize = maxIndicatorSize
            },
                                                   TextManager.Get("ReactorWarningCriticalLowTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightRed")
            {
                Selected = false,
                Enabled  = false,
                ToolTip  = TextManager.Get("ReactorTempTip")
            };
            criticalOutputWarning = new GUITickBox(new RectTransform(new Vector2(0.33f, 1.0f), topLeftArea.RectTransform)
            {
                MaxSize = maxIndicatorSize
            },
                                                   TextManager.Get("ReactorWarningCriticalOutput"), font: GUI.SubHeadingFont, style: "IndicatorLightRed")
            {
                Selected = false,
                Enabled  = false,
                ToolTip  = TextManager.Get("ReactorOutputTip")
            };
            List <GUITickBox> indicatorLights = new List <GUITickBox>()
            {
                criticalHeatWarning, lowTemperatureWarning, criticalOutputWarning
            };

            indicatorLights.ForEach(l => l.TextBlock.OverrideTextColor(GUI.Style.TextColor));
            topLeftArea.Recalculate();

            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.01f), columnLeft.RectTransform), style: "HorizontalLine");

            float   relativeYMargin  = 0.02f;
            Vector2 relativeTextSize = new Vector2(0.9f, 0.2f);
            Vector2 sliderSize       = new Vector2(1.0f, 0.125f);
            Vector2 meterSize        = new Vector2(1, 1 - relativeTextSize.Y - relativeYMargin - sliderSize.Y - 0.1f);

            var meterArea = new GUIFrame(new RectTransform(new Vector2(1, 0.6f - relativeYMargin * 2), columnLeft.RectTransform), style: null);
            var leftArea  = new GUIFrame(new RectTransform(new Vector2(0.49f, 1), meterArea.RectTransform), style: null);
            var rightArea = new GUIFrame(new RectTransform(new Vector2(0.49f, 1), meterArea.RectTransform, Anchor.TopCenter, Pivot.TopLeft), style: null);

            var fissionRateTextBox = new GUITextBlock(new RectTransform(relativeTextSize, leftArea.RectTransform, Anchor.TopCenter),
                                                      TextManager.Get("ReactorFissionRate"), textColor: GUI.Style.TextColor, textAlignment: Alignment.Center, font: GUI.SubHeadingFont)
            {
                AutoScaleHorizontal = true
            };
            var fissionMeter = new GUICustomComponent(new RectTransform(meterSize, leftArea.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0.0f, relativeTextSize.Y + relativeYMargin)
            },
                                                      DrawFissionRateMeter, null)
            {
                ToolTip = TextManager.Get("ReactorTipFissionRate")
            };

            var turbineOutputTextBox = new GUITextBlock(new RectTransform(relativeTextSize, rightArea.RectTransform, Anchor.TopCenter),
                                                        TextManager.Get("ReactorTurbineOutput"), textColor: GUI.Style.TextColor, textAlignment: Alignment.Center, font: GUI.SubHeadingFont)
            {
                AutoScaleHorizontal = true
            };

            GUITextBlock.AutoScaleAndNormalize(turbineOutputTextBox, fissionRateTextBox);

            var turbineMeter = new GUICustomComponent(new RectTransform(meterSize, rightArea.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0.0f, relativeTextSize.Y + relativeYMargin)
            },
                                                      DrawTurbineOutputMeter, null)
            {
                ToolTip = TextManager.Get("ReactorTipTurbineOutput")
            };

            FissionRateScrollBar = new GUIScrollBar(new RectTransform(sliderSize, leftArea.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0, fissionMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
            },
                                                    style: "DeviceSlider", barSize: 0.15f)
            {
                Enabled = false,
                Step    = 1.0f / 255,
                OnMoved = (GUIScrollBar bar, float scrollAmount) =>
                {
                    LastUser          = Character.Controlled;
                    unsentChanges     = true;
                    targetFissionRate = scrollAmount * 100.0f;

                    return(false);
                }
            };

            TurbineOutputScrollBar = new GUIScrollBar(new RectTransform(sliderSize, rightArea.RectTransform, Anchor.TopCenter)
            {
                RelativeOffset = new Vector2(0, turbineMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
            },
                                                      style: "DeviceSlider", barSize: 0.15f, isHorizontal: true)
            {
                Enabled = false,
                Step    = 1.0f / 255,
                OnMoved = (GUIScrollBar bar, float scrollAmount) =>
                {
                    LastUser            = Character.Controlled;
                    unsentChanges       = true;
                    targetTurbineOutput = scrollAmount * 100.0f;

                    return(false);
                }
            };

            var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.2f), columnLeft.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };
            var upperButtons = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.5f), buttonArea.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.01f
            };
            var lowerButtons = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.5f), buttonArea.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.01f
            };
            int buttonCount = warningTexts.Length;

            for (int i = 0; i < buttonCount; i++)
            {
                string text = warningTexts[i];
                var    b    = new GUIButton(new RectTransform(Vector2.One, (i < 4) ? upperButtons.RectTransform : lowerButtons.RectTransform),
                                            TextManager.Get(text), style: "IndicatorButton")
                {
                    Font         = GUI.SubHeadingFont,
                    CanBeFocused = false
                };
                warningButtons.Add(text, b);
            }
            upperButtons.Recalculate();
            lowerButtons.Recalculate();
            //only wrap texts that consist of multiple words and are way too big to fit otherwise
            warningButtons.Values.ForEach(b => b.TextBlock.Wrap = b.Text.Contains(' ') && b.TextBlock.TextSize.X > b.TextBlock.Rect.Width * 1.5f);
            GUITextBlock.AutoScaleAndNormalize(warningButtons.Values.Select(b => b.TextBlock));

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

            // Auto temp
            var topRightArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.25f), columnRight.RectTransform),
                                                  isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            topRightArea.RectTransform.MinSize = new Point(0, topLeftArea.Rect.Height);
            topRightArea.RectTransform.MaxSize = new Point(int.MaxValue, topLeftArea.Rect.Height);

            new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), topRightArea.RectTransform), style: "VerticalLine");

            AutoTempSwitch = new GUIButton(new RectTransform(new Vector2(0.15f, 0.9f), topRightArea.RectTransform),
                                           style: "SwitchVertical")
            {
                Enabled   = false,
                Selected  = AutoTemp,
                OnClicked = (button, data) =>
                {
                    AutoTemp      = !AutoTemp;
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };
            AutoTempSwitch.RectTransform.MaxSize = new Point((int)(AutoTempSwitch.Rect.Height * 0.4f), int.MaxValue);

            autoTempLight = new GUITickBox(new RectTransform(new Vector2(0.4f, 1.0f), topRightArea.RectTransform),
                                           TextManager.Get("ReactorAutoTemp"), font: GUI.SubHeadingFont, style: "IndicatorLightYellow")
            {
                ToolTip      = TextManager.Get("ReactorTipAutoTemp"),
                CanBeFocused = false,
                Selected     = AutoTemp
            };
            autoTempLight.RectTransform.MaxSize = new Point(int.MaxValue, criticalHeatWarning.Rect.Height);
            autoTempLight.TextBlock.OverrideTextColor(GUI.Style.TextColor);

            new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), topRightArea.RectTransform), style: "VerticalLine");

            // Power button
            var powerArea       = new GUIFrame(new RectTransform(new Vector2(0.4f, 1.0f), topRightArea.RectTransform), style: null);
            var paddedPowerArea = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), powerArea.RectTransform, Anchor.Center, scaleBasis: ScaleBasis.BothHeight), style: "PowerButtonFrame");

            powerLight = new GUITickBox(new RectTransform(new Vector2(0.87f, 0.3f), paddedPowerArea.RectTransform, Anchor.TopCenter, Pivot.Center),
                                        TextManager.Get("PowerLabel"), font: GUI.SubHeadingFont, style: "IndicatorLightPower")
            {
                CanBeFocused = false,
                Selected     = _powerOn
            };
            powerLight.TextBlock.Padding             = new Vector4(5.0f, 0.0f, 0.0f, 0.0f);
            powerLight.TextBlock.AutoScaleHorizontal = true;
            powerLight.TextBlock.OverrideTextColor(GUI.Style.TextColor);
            PowerButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.75f), paddedPowerArea.RectTransform, Anchor.BottomCenter)
            {
                RelativeOffset = new Vector2(0, 0.1f)
            }, style: "PowerButton")
            {
                OnClicked = (button, data) =>
                {
                    PowerOn       = !PowerOn;
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };

            topRightArea.Recalculate();
            autoTempLight.TextBlock.Wrap = true;
            indicatorLights.Add(autoTempLight);
            GUITextBlock.AutoScaleAndNormalize(indicatorLights.Select(l => l.TextBlock));

            // right bottom (graph area) -----------------------

            new GUIFrame(new RectTransform(new Vector2(0.95f, 0.01f), columnRight.RectTransform), style: "HorizontalLine");

            var bottomRightArea = new GUILayoutGroup(new RectTransform(Vector2.One, columnRight.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                CanBeFocused    = true,
                RelativeSpacing = 0.02f
            };

            new GUIFrame(new RectTransform(new Vector2(0.01f, 1.0f), bottomRightArea.RectTransform), style: "VerticalLine");

            new GUICustomComponent(new RectTransform(new Vector2(0.1f, 1), bottomRightArea.RectTransform, Anchor.Center), DrawTempMeter, null);

            var graphArea = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), bottomRightArea.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            relativeTextSize = new Vector2(1.0f, 0.15f);
            var loadText = new GUITextBlock(new RectTransform(relativeTextSize, graphArea.RectTransform),
                                            "Load", textColor: loadColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft)
            {
                ToolTip = TextManager.Get("ReactorTipLoad")
            };
            string loadStr = TextManager.Get("ReactorLoad");
            string kW      = TextManager.Get("kilowatt");

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

            var graph = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.9f), graphArea.RectTransform), style: "InnerFrameRed");

            new GUICustomComponent(new RectTransform(new Vector2(0.9f, 0.98f), graph.RectTransform, Anchor.Center), DrawGraph, null);

            var outputText = new GUITextBlock(new RectTransform(relativeTextSize, graphArea.RectTransform),
                                              "Output", textColor: outputColor, font: GUI.SubHeadingFont, textAlignment: Alignment.CenterLeft)
            {
                ToolTip = TextManager.Get("ReactorTipPower")
            };
            string outputStr = TextManager.Get("ReactorOutput");

            outputText.TextGetter += () => $"{outputStr.Replace("[kw]", ((int)-currPowerConsumption).ToString())} {kW}";
        }
Пример #8
0
        private bool SelectItem(Character user, FabricationRecipe selectedItem)
        {
            selectedItemFrame.ClearChildren();
            selectedItemReqsFrame.ClearChildren();

            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.9f), selectedItemFrame.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f
            };
            var paddedReqFrame = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.9f), selectedItemReqsFrame.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f
            };

            /*var itemIcon = selectedItem.TargetItem.InventoryIcon ?? selectedItem.TargetItem.sprite;
             * if (itemIcon != null)
             * {
             *  GUIImage img = new GUIImage(new RectTransform(new Point(40, 40), paddedFrame.RectTransform),
             *      itemIcon, scaleToFit: true)
             *  {
             *      Color = selectedItem.TargetItem.InventoryIconColor
             *  };
             * }*/
            var nameBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                             selectedItem.TargetItem.Name, textAlignment: Alignment.CenterLeft, textColor: Color.Aqua, font: GUI.SubHeadingFont)
            {
                AutoScaleHorizontal = true
            };

            nameBlock.Padding = new Vector4(0, nameBlock.Padding.Y, nameBlock.Padding.Z, nameBlock.Padding.W);

            if (!string.IsNullOrWhiteSpace(selectedItem.TargetItem.Description))
            {
                var description = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                                   selectedItem.TargetItem.Description,
                                                   font: GUI.SmallFont, wrap: true);
                description.Padding = new Vector4(0, description.Padding.Y, description.Padding.Z, description.Padding.W);

                while (description.Rect.Height + nameBlock.Rect.Height > paddedFrame.Rect.Height)
                {
                    var lines     = description.WrappedText.Split('\n');
                    var newString = string.Join('\n', lines.Take(lines.Length - 1));
                    description.Text = newString.Substring(0, newString.Length - 4) + "...";
                    description.CalculateHeightFromText();
                    description.ToolTip = selectedItem.TargetItem.Description;
                }
            }

            List <Skill> inadequateSkills = new List <Skill>();

            if (user != null)
            {
                inadequateSkills = selectedItem.RequiredSkills.FindAll(skill => user.GetSkillLevel(skill.Identifier) < skill.Level);
            }

            if (selectedItem.RequiredSkills.Any())
            {
                string text = "";
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedReqFrame.RectTransform),
                                 TextManager.Get("FabricatorRequiredSkills"), textColor: inadequateSkills.Any() ? GUI.Style.Red : GUI.Style.Green, font: GUI.SubHeadingFont)
                {
                    AutoScaleHorizontal = true,
                };
                foreach (Skill skill in selectedItem.RequiredSkills)
                {
                    text += TextManager.Get("SkillName." + skill.Identifier) + " " + TextManager.Get("Lvl").ToLower() + " " + skill.Level;
                    if (skill != selectedItem.RequiredSkills.Last())
                    {
                        text += "\n";
                    }
                }
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedReqFrame.RectTransform), text, font: GUI.SmallFont);
            }

            float degreeOfSuccess = user == null ? 0.0f : DegreeOfSuccess(user, selectedItem.RequiredSkills);

            if (degreeOfSuccess > 0.5f)
            {
                degreeOfSuccess = 1.0f;
            }

            float requiredTime = user == null ? selectedItem.RequiredTime : GetRequiredTime(selectedItem, user);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedReqFrame.RectTransform),
                             TextManager.Get("FabricatorRequiredTime"), textColor: ToolBox.GradientLerp(degreeOfSuccess, GUI.Style.Red, Color.Yellow, GUI.Style.Green), font: GUI.SubHeadingFont)
            {
                AutoScaleHorizontal = true,
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedReqFrame.RectTransform), ToolBox.SecondsToReadableTime(requiredTime),
                             font: GUI.SmallFont);
            return(true);
        }
Пример #9
0
        private void CreateGUI()
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter);

            // === LABEL === //
            new GUITextBlock(new RectTransform(new Vector2(1f, 0.05f), paddedFrame.RectTransform), item.Name, font: GUI.SubHeadingFont)
            {
                TextAlignment     = Alignment.Center,
                AutoScaleVertical = true
            };

            var mainFrame = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1f), paddedFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
            {
                RelativeSpacing = 0.02f
            };

            // === TOP AREA ===
            var topFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.65f), mainFrame.RectTransform), style: "InnerFrameDark");

            // === ITEM LIST ===
            var itemListFrame   = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), topFrame.RectTransform), childAnchor: Anchor.Center);
            var paddedItemFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), itemListFrame.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.03f
            };
            var filterArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), paddedItemFrame.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.03f,
                UserData        = "filterarea"
            };

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 1f), filterArea.RectTransform), TextManager.Get("serverlog.filter"), font: GUI.SubHeadingFont)
            {
                Padding           = Vector4.Zero,
                AutoScaleVertical = true
            };
            itemFilterBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), filterArea.RectTransform), createClearButton: true);
            itemFilterBox.OnTextChanged += (textBox, text) =>
            {
                FilterEntities(text);
                return(true);
            };
            filterArea.RectTransform.MaxSize = new Point(int.MaxValue, itemFilterBox.Rect.Height);

            itemList = new GUIListBox(new RectTransform(new Vector2(1f, 0.9f), paddedItemFrame.RectTransform), style: null)
            {
                OnSelected = (component, userdata) =>
                {
                    selectedItem = userdata as FabricationRecipe;
                    if (selectedItem != null)
                    {
                        SelectItem(Character.Controlled, selectedItem);
                    }
                    return(true);
                }
            };

            // === SEPARATOR === //
            new GUIFrame(new RectTransform(new Vector2(0.01f, 0.9f), topFrame.RectTransform, Anchor.Center), style: "VerticalLine");

            // === OUTPUT AREA === //
            var outputArea       = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1f), topFrame.RectTransform, Anchor.TopRight), childAnchor: Anchor.Center);
            var paddedOutputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), outputArea.RectTransform));
            var outputTopArea    = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.5F), paddedOutputArea.RectTransform, Anchor.Center), isHorizontal: true);

            // === OUTPUT SLOT === //
            outputSlot            = new GUIFrame(new RectTransform(new Vector2(0.4f, 1f), outputTopArea.RectTransform), style: null);
            outputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(1f, 1.2f), outputSlot.RectTransform, Anchor.BottomCenter), style: null);
            new GUICustomComponent(new RectTransform(Vector2.One, outputInventoryHolder.RectTransform), DrawOutputOverLay)
            {
                CanBeFocused = false
            };
            // === DESCRIPTION === //
            selectedItemFrame = new GUIFrame(new RectTransform(new Vector2(0.6f, 1f), outputTopArea.RectTransform), style: null);
            // === REQUIREMENTS === //
            selectedItemReqsFrame = new GUIFrame(new RectTransform(new Vector2(1f, 0.5f), paddedOutputArea.RectTransform), style: null);

            // === BOTTOM AREA === //
            var bottomFrame = new GUIFrame(new RectTransform(new Vector2(1f, 0.3f), mainFrame.RectTransform), style: null);

            // === SEPARATOR === //
            var separatorArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.15f), bottomFrame.RectTransform, Anchor.TopCenter), childAnchor: Anchor.CenterLeft, isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.03f
            };
            var inputLabel = new GUITextBlock(new RectTransform(Vector2.One, separatorArea.RectTransform), TextManager.Get("uilabel.input"), font: GUI.SubHeadingFont)
            {
                Padding = Vector4.Zero
            };

            inputLabel.RectTransform.Resize(new Point((int)inputLabel.Font.MeasureString(inputLabel.Text).X, inputLabel.RectTransform.Rect.Height));
            new GUIFrame(new RectTransform(Vector2.One, separatorArea.RectTransform), style: "HorizontalLine");

            // === INPUT AREA === //
            var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 1f), bottomFrame.RectTransform, Anchor.BottomCenter), isHorizontal: true, childAnchor: Anchor.BottomLeft);

            // === INPUT SLOTS === //
            inputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(0.7f, 1f), inputArea.RectTransform), style: null);
            new GUICustomComponent(new RectTransform(Vector2.One, inputInventoryHolder.RectTransform), DrawInputOverLay)
            {
                CanBeFocused = false
            };

            // === ACTIVATE BUTTON === //
            var buttonFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.3f, 0.8f), inputArea.RectTransform), childAnchor: Anchor.CenterRight);

            activateButton = new GUIButton(new RectTransform(new Vector2(1f, 0.6f), buttonFrame.RectTransform),
                                           TextManager.Get("FabricatorCreate"), style: "DeviceButton")
            {
                OnClicked = StartButtonClicked,
                UserData  = selectedItem,
                Enabled   = false
            };
            // === POWER WARNING === //
            inSufficientPowerWarning = new GUITextBlock(new RectTransform(Vector2.One, activateButton.RectTransform),
                                                        TextManager.Get("FabricatorNoPower"), textColor: GUI.Style.Orange, textAlignment: Alignment.Center, color: Color.Black, style: "OuterGlow", wrap: true)
            {
                HoverColor         = Color.Black,
                IgnoreLayoutGroups = true,
                Visible            = false,
                CanBeFocused       = false
            };
            CreateRecipes();
        }
Пример #10
0
        partial void InitProjSpecific(XElement element)
        {
            int viewSize         = (int)Math.Min(GuiFrame.Rect.Width - 150, GuiFrame.Rect.Height * 0.9f);
            var controlContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.35f), GuiFrame.RectTransform, Anchor.CenterLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.99f), (int)(viewSize * 0.05f))
            }, "SonarFrame");
            var paddedControlContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), controlContainer.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            statusContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0)
            }, "SonarFrame");
            var paddedStatusContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), statusContainer.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            manualTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), paddedControlContainer.RectTransform),
                                           TextManager.Get("SteeringManual"), style: "GUIRadioButton")
            {
                Selected   = true,
                OnSelected = (GUITickBox box) =>
                {
                    AutoPilot     = !box.Selected;
                    unsentChanges = true;
                    user          = Character.Controlled;

                    return(true);
                }
            };
            autopilotTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), paddedControlContainer.RectTransform),
                                              TextManager.Get("SteeringAutoPilot"), style: "GUIRadioButton")
            {
                OnSelected = (GUITickBox box) =>
                {
                    AutoPilot = box.Selected;
                    if (AutoPilot && MaintainPos)
                    {
                        posToMaintain = controlledSub != null ?
                                        controlledSub.WorldPosition :
                                        item.Submarine == null ? item.WorldPosition : item.Submarine.WorldPosition;
                    }
                    unsentChanges = true;
                    user          = Character.Controlled;

                    return(true);
                }
            };

            GUIRadioButtonGroup modes = new GUIRadioButtonGroup();

            modes.AddRadioButton(Mode.AutoPilot, autopilotTickBox);
            modes.AddRadioButton(Mode.Manual, manualTickBox);
            modes.Selected = Mode.Manual;

            var autoPilotControls       = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.6f), paddedControlContainer.RectTransform), "InnerFrame");
            var paddedAutoPilotControls = new GUILayoutGroup(new RectTransform(new Vector2(0.8f), autoPilotControls.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.03f
            };

            maintainPosTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                                TextManager.Get("SteeringMaintainPos"), font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = maintainPos,
                OnSelected = tickBox =>
                {
                    if (maintainPos != tickBox.Selected)
                    {
                        unsentChanges = true;
                        user          = Character.Controlled;
                        maintainPos   = tickBox.Selected;
                        if (maintainPos)
                        {
                            if (controlledSub == null)
                            {
                                posToMaintain = null;
                            }
                            else
                            {
                                posToMaintain = controlledSub.WorldPosition;
                            }
                        }
                        else if (!LevelEndSelected && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                        if (!maintainPos)
                        {
                            posToMaintain = null;
                        }
                    }
                    return(true);
                }
            };

            levelStartTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                               GameMain.GameSession?.StartLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
                                               font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = levelStartSelected,
                OnSelected = tickBox =>
                {
                    if (levelStartSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelStartSelected = tickBox.Selected;
                        levelEndSelected   = !levelStartSelected;
                        if (levelStartSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelEndSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };

            levelEndTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                             GameMain.GameSession?.EndLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, 20),
                                             font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = levelEndSelected,
                OnSelected = tickBox =>
                {
                    if (levelEndSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelEndSelected   = tickBox.Selected;
                        levelStartSelected = !levelEndSelected;
                        if (levelEndSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };

            autoPilotControlsDisabler = new GUIFrame(new RectTransform(Vector2.One, autoPilotControls.RectTransform), "InnerFrame");

            GUIRadioButtonGroup destinations = new GUIRadioButtonGroup();

            destinations.AddRadioButton(Destination.MaintainPos, maintainPosTickBox);
            destinations.AddRadioButton(Destination.LevelStart, levelStartTickBox);
            destinations.AddRadioButton(Destination.LevelEnd, levelEndTickBox);
            destinations.Selected = maintainPos        ? Destination.MaintainPos :
                                    levelStartSelected ? Destination.LevelStart  : Destination.LevelEnd;

            string steeringVelX  = TextManager.Get("SteeringVelocityX");
            string steeringVelY  = TextManager.Get("SteeringVelocityY");
            string steeringDepth = TextManager.Get("SteeringDepth");

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                    var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.Y * Physics.DisplayToRealWorldRatio) * 3.6f;
                    return(steeringVelY.Replace("[kph]", ((int)-realWorldVel).ToString()));
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                    var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.X * Physics.DisplayToRealWorldRatio) * 3.6f;
                    return(steeringVelX.Replace("[kph]", ((int)realWorldVel).ToString()));
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 pos            = controlledSub == null ? Vector2.Zero : controlledSub.Position;
                    float   realWorldDepth = Level.Loaded == null ? 0.0f : Math.Abs(pos.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
                    return(steeringDepth.Replace("[m]", ((int)realWorldDepth).ToString()));
                }
            };

            pressureWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), TextManager.Get("SteeringDepthWarning"), Color.Red)
            {
                Visible = false
            };

            tipContainer = new GUITextBlock(new RectTransform(new Vector2(0.25f, 0.12f), GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                MinSize = new Point(150, 0), RelativeOffset = new Vector2(0.0f, -0.05f)
            }, "", wrap: true, style: "GUIToolTip")
            {
                AutoScale = true
            };

            noPowerTip = TextManager.Get("SteeringNoPowerTip");
            autoPilotMaintainPosTip = TextManager.Get("SteeringAutoPilotMaintainPosTip");
            autoPilotLevelStartTip  = TextManager.GetWithVariable("SteeringAutoPilotLocationTip", "[locationname]",
                                                                  GameMain.GameSession?.StartLocation == null ? "Start" : GameMain.GameSession.StartLocation.Name);
            autoPilotLevelEndTip = TextManager.GetWithVariable("SteeringAutoPilotLocationTip", "[locationname]",
                                                               GameMain.GameSession?.EndLocation == null ? "End" : GameMain.GameSession.EndLocation.Name);

            steerArea = new GUICustomComponent(new RectTransform(new Point(viewSize), GuiFrame.RectTransform, Anchor.CenterLeft),
                                               (spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);

            //docking interface ----------------------------------------------------
            dockingContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0)
            }, style: null);
            var paddedDockingContainer = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), dockingContainer.RectTransform, Anchor.Center), style: null);

            //TODO: add new texts for these ("Dock" & "Undock")
            dockText      = TextManager.Get("captain.dock");
            undockText    = TextManager.Get("captain.undock");
            dockingButton = new GUIButton(new RectTransform(new Vector2(0.5f, 0.5f), paddedDockingContainer.RectTransform, Anchor.Center), dockText, style: "GUIButtonLarge")
            {
                OnClicked = (btn, userdata) =>
                {
                    if (GameMain.Client == null)
                    {
                        item.SendSignal(0, "1", "toggle_docking", sender: Character.Controlled);
                    }
                    else
                    {
                        dockingNetworkMessagePending = true;
                        item.CreateClientEvent(this);
                    }
                    return(true);
                }
            };
            dockingButton.Font = GUI.SmallFont;

            var leftButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.5f), paddedDockingContainer.RectTransform, Anchor.CenterLeft), "")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = -Vector2.UnitX
            };

            new GUIImage(new RectTransform(new Vector2(0.7f), leftButton.RectTransform, Anchor.Center), "GUIButtonHorizontalArrow").SpriteEffects = SpriteEffects.FlipHorizontally;
            var rightButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.5f), paddedDockingContainer.RectTransform, Anchor.CenterRight), "")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = Vector2.UnitX
            };

            new GUIImage(new RectTransform(new Vector2(0.7f), rightButton.RectTransform, Anchor.Center), "GUIButtonHorizontalArrow");
            var upButton = new GUIButton(new RectTransform(new Vector2(0.5f, 0.2f), paddedDockingContainer.RectTransform, Anchor.TopCenter), "")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = Vector2.UnitY
            };

            new GUIImage(new RectTransform(new Vector2(0.7f), upButton.RectTransform, Anchor.Center), "GUIButtonVerticalArrow");
            var downButton = new GUIButton(new RectTransform(new Vector2(0.5f, 0.2f), paddedDockingContainer.RectTransform, Anchor.BottomCenter), "")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = -Vector2.UnitY
            };

            new GUIImage(new RectTransform(new Vector2(0.7f), downButton.RectTransform, Anchor.Center), "GUIButtonVerticalArrow").SpriteEffects = SpriteEffects.FlipVertically;

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "steeringindicator":
                    steeringIndicator = new Sprite(subElement);
                    break;

                case "maintainposindicator":
                    maintainPosIndicator = new Sprite(subElement);
                    break;

                case "maintainposoriginindicator":
                    maintainPosOriginIndicator = new Sprite(subElement);
                    break;
                }
            }
        }
Пример #11
0
        protected override void CreateGUI()
        {
            controlContainer = new GUIFrame(new RectTransform(new Vector2(Sonar.controlBoxSize.X, 1 - Sonar.controlBoxSize.Y * 2), GuiFrame.RectTransform, Anchor.CenterLeft), "ItemUI");
            var paddedControlContainer = new GUIFrame(new RectTransform(controlContainer.Rect.Size - GUIStyle.ItemFrameMargin, controlContainer.RectTransform, Anchor.Center)
            {
                AbsoluteOffset = GUIStyle.ItemFrameOffset
            }, style: null);

            var steeringModeArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f), paddedControlContainer.RectTransform, Anchor.TopLeft), style: null);

            steeringModeSwitch = new GUIButton(new RectTransform(new Vector2(0.2f, 1), steeringModeArea.RectTransform), string.Empty, style: "SwitchVertical")
            {
                Selected   = autoPilot,
                Enabled    = true,
                ClickSound = GUISoundType.UISwitch,
                OnClicked  = (button, data) =>
                {
                    button.Selected = !button.Selected;
                    AutoPilot       = button.Selected;
                    if (GameMain.Client != null)
                    {
                        unsentChanges = true;
                        user          = Character.Controlled;
                    }
                    return(true);
                }
            };
            var steeringModeRightSide = new GUIFrame(new RectTransform(new Vector2(1.0f - steeringModeSwitch.RectTransform.RelativeSize.X, 0.8f), steeringModeArea.RectTransform, Anchor.CenterLeft)
            {
                RelativeOffset = new Vector2(steeringModeSwitch.RectTransform.RelativeSize.X, 0)
            }, style: null);

            manualPilotIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.45f), steeringModeRightSide.RectTransform, Anchor.TopLeft),
                                                  TextManager.Get("SteeringManual"), font: GUI.SubHeadingFont, style: "IndicatorLightRedSmall")
            {
                Selected = !autoPilot,
                Enabled  = false
            };
            autopilotIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.45f), steeringModeRightSide.RectTransform, Anchor.BottomLeft),
                                                TextManager.Get("SteeringAutoPilot"), font: GUI.SubHeadingFont, style: "IndicatorLightRedSmall")
            {
                Selected = autoPilot,
                Enabled  = false
            };
            manualPilotIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor);
            autopilotIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor);
            GUITextBlock.AutoScaleAndNormalize(manualPilotIndicator.TextBlock, autopilotIndicator.TextBlock);

            var autoPilotControls       = new GUIFrame(new RectTransform(new Vector2(0.75f, 0.62f), paddedControlContainer.RectTransform, Anchor.BottomCenter), "OutlineFrame");
            var paddedAutoPilotControls = new GUIFrame(new RectTransform(new Vector2(0.92f, 0.88f), autoPilotControls.RectTransform, Anchor.Center), style: null);

            maintainPosTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.TopCenter),
                                                TextManager.Get("SteeringMaintainPos"), font: GUI.SmallFont, style: "GUIRadioButton")
            {
                Enabled    = autoPilot,
                Selected   = maintainPos,
                OnSelected = tickBox =>
                {
                    if (maintainPos != tickBox.Selected)
                    {
                        unsentChanges = true;
                        user          = Character.Controlled;
                        maintainPos   = tickBox.Selected;
                        if (maintainPos)
                        {
                            if (controlledSub == null)
                            {
                                posToMaintain = null;
                            }
                            else
                            {
                                posToMaintain = controlledSub.WorldPosition;
                            }
                        }
                        else if (!LevelEndSelected && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                        if (!maintainPos)
                        {
                            posToMaintain = null;
                        }
                    }
                    return(true);
                }
            };
            int textLimit = (int)(MathHelper.Clamp(25 * GUI.xScale, 15, 35));

            levelStartTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.Center),
                                               GameMain.GameSession?.StartLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, textLimit),
                                               font: GUI.SmallFont, style: "GUIRadioButton")
            {
                Enabled    = autoPilot,
                Selected   = levelStartSelected,
                OnSelected = tickBox =>
                {
                    if (levelStartSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelStartSelected = tickBox.Selected;
                        levelEndSelected   = !levelStartSelected;
                        if (levelStartSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelEndSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };

            levelEndTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.BottomCenter),
                                             (GameMain.GameSession?.EndLocation == null || Level.IsLoadedOutpost) ? "" : ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, textLimit),
                                             font: GUI.SmallFont, style: "GUIRadioButton")
            {
                Enabled    = autoPilot,
                Selected   = levelEndSelected,
                Visible    = GameMain.GameSession?.EndLocation != null,
                OnSelected = tickBox =>
                {
                    if (levelEndSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelEndSelected   = tickBox.Selected;
                        levelStartSelected = !levelEndSelected;
                        if (levelEndSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };
            maintainPosTickBox.RectTransform.IsFixedSize = levelStartTickBox.RectTransform.IsFixedSize = levelEndTickBox.RectTransform.IsFixedSize = false;
            maintainPosTickBox.RectTransform.MaxSize     = levelStartTickBox.RectTransform.MaxSize = levelEndTickBox.RectTransform.MaxSize =
                new Point(int.MaxValue, paddedAutoPilotControls.Rect.Height / 3);
            maintainPosTickBox.RectTransform.MinSize = levelStartTickBox.RectTransform.MinSize = levelEndTickBox.RectTransform.MinSize =
                Point.Zero;

            GUITextBlock.AutoScaleAndNormalize(scaleHorizontal: false, scaleVertical: true, maintainPosTickBox.TextBlock, levelStartTickBox.TextBlock, levelEndTickBox.TextBlock);

            GUIRadioButtonGroup destinations = new GUIRadioButtonGroup();

            destinations.AddRadioButton((int)Destination.MaintainPos, maintainPosTickBox);
            destinations.AddRadioButton((int)Destination.LevelStart, levelStartTickBox);
            destinations.AddRadioButton((int)Destination.LevelEnd, levelEndTickBox);
            destinations.Selected = (int)(maintainPos ? Destination.MaintainPos :
                                          levelStartSelected ? Destination.LevelStart : Destination.LevelEnd);

            // Status ->
            statusContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                RelativeOffset = Sonar.controlBoxOffset
            }, "ItemUI");
            var paddedStatusContainer = new GUIFrame(new RectTransform(statusContainer.Rect.Size - GUIStyle.ItemFrameMargin, statusContainer.RectTransform, Anchor.Center, isFixedSize: false)
            {
                AbsoluteOffset = GUIStyle.ItemFrameOffset
            }, style: null);

            var elements = GUI.CreateElements(3, new Vector2(1f, 0.333f), paddedStatusContainer.RectTransform, rt => new GUIFrame(rt, style: null), Anchor.TopCenter, relativeSpacing: 0.01f);
            List <GUIComponent> leftElements = new List <GUIComponent>(), centerElements = new List <GUIComponent>(), rightElements = new List <GUIComponent>();

            for (int i = 0; i < elements.Count; i++)
            {
                var e     = elements[i];
                var group = new GUILayoutGroup(new RectTransform(Vector2.One, e.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
                {
                    RelativeSpacing = 0.01f,
                    Stretch         = true
                };
                var left   = new GUIFrame(new RectTransform(new Vector2(0.45f, 1), group.RectTransform), style: null);
                var center = new GUIFrame(new RectTransform(new Vector2(0.15f, 1), group.RectTransform), style: null);
                var right  = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.8f), group.RectTransform), style: null);
                leftElements.Add(left);
                centerElements.Add(center);
                rightElements.Add(right);
                string leftText = string.Empty, centerText = string.Empty;
                GUITextBlock.TextGetterHandler rightTextGetter = null;
                switch (i)
                {
                case 0:
                    leftText        = TextManager.Get("DescentVelocity");
                    centerText      = $"({TextManager.Get("KilometersPerHour")})";
                    rightTextGetter = () =>
                    {
                        Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                        var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.Y * Physics.DisplayToRealWorldRatio) * 3.6f;
                        return(((int)(-realWorldVel)).ToString());
                    };
                    break;

                case 1:
                    leftText        = TextManager.Get("Velocity");
                    centerText      = $"({TextManager.Get("KilometersPerHour")})";
                    rightTextGetter = () =>
                    {
                        Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                        var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.X * Physics.DisplayToRealWorldRatio) * 3.6f;
                        return(((int)realWorldVel).ToString());
                    };
                    break;

                case 2:
                    leftText        = TextManager.Get("Depth");
                    centerText      = $"({TextManager.Get("Meter")})";
                    rightTextGetter = () =>
                    {
                        Vector2 pos            = controlledSub == null ? Vector2.Zero : controlledSub.Position;
                        float   realWorldDepth = Level.Loaded == null ? 0.0f : Math.Abs(pos.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
                        return(((int)realWorldDepth).ToString());
                    };
                    break;
                }
                new GUITextBlock(new RectTransform(Vector2.One, left.RectTransform), leftText, font: GUI.SubHeadingFont, wrap: leftText.Contains(' '), textAlignment: Alignment.CenterRight);
                new GUITextBlock(new RectTransform(Vector2.One, center.RectTransform), centerText, font: GUI.Font, textAlignment: Alignment.Center)
                {
                    Padding = Vector4.Zero
                };
                var digitalFrame = new GUIFrame(new RectTransform(Vector2.One, right.RectTransform), style: "DigitalFrameDark");
                new GUITextBlock(new RectTransform(Vector2.One * 0.85f, digitalFrame.RectTransform, Anchor.Center), "12345", GUI.Style.TextColorDark, GUI.DigitalFont, Alignment.CenterRight)
                {
                    TextGetter = rightTextGetter
                };
            }
            GUITextBlock.AutoScaleAndNormalize(leftElements.SelectMany(e => e.GetAllChildren <GUITextBlock>()));
            GUITextBlock.AutoScaleAndNormalize(centerElements.SelectMany(e => e.GetAllChildren <GUITextBlock>()));
            GUITextBlock.AutoScaleAndNormalize(rightElements.SelectMany(e => e.GetAllChildren <GUITextBlock>()));

            //docking interface ----------------------------------------------------
            float dockingButtonSize = 1.1f;
            float elementScale      = 0.6f;

            dockingContainer = new GUIFrame(new RectTransform(Sonar.controlBoxSize, GuiFrame.RectTransform, Anchor.BottomLeft, scaleBasis: ScaleBasis.Smallest)
            {
                RelativeOffset = new Vector2(Sonar.controlBoxOffset.X + 0.05f, Sonar.controlBoxOffset.Y)
            }, style: null);

            dockText      = TextManager.Get("label.navterminaldock", fallBackTag: "captain.dock");
            undockText    = TextManager.Get("label.navterminalundock", fallBackTag: "captain.undock");
            dockingButton = new GUIButton(new RectTransform(new Vector2(elementScale), dockingContainer.RectTransform, Anchor.Center), dockText, style: "PowerButton")
            {
                OnClicked = (btn, userdata) =>
                {
                    if (GameMain.GameSession?.Campaign is CampaignMode campaign)
                    {
                        if (Level.IsLoadedOutpost &&
                            DockingSources.Any(d => d.Docked && (d.DockingTarget?.Item.Submarine?.Info?.IsOutpost ?? false)))
                        {
                            // Undocking from an outpost
                            campaign.CampaignUI.SelectTab(CampaignMode.InteractionType.Map);
                            campaign.ShowCampaignUI = true;
                            return(false);
                        }
                        else if (!Level.IsLoadedOutpost && DockingModeEnabled && ActiveDockingSource != null &&
                                 !ActiveDockingSource.Docked && DockingTarget?.Item?.Submarine == Level.Loaded.StartOutpost && (DockingTarget?.Item?.Submarine?.Info.IsOutpost ?? false))
                        {
                            // Docking to an outpost
                            var subsToLeaveBehind = campaign.GetSubsToLeaveBehind(Item.Submarine);
                            if (subsToLeaveBehind.Any())
                            {
                                enterOutpostPrompt = new GUIMessageBox(
                                    TextManager.GetWithVariable("enterlocation", "[locationname]", DockingTarget.Item.Submarine.Info.Name),
                                    TextManager.Get(subsToLeaveBehind.Count == 1 ? "LeaveSubBehind" : "LeaveSubsBehind"),
                                    new string[] { TextManager.Get("yes"), TextManager.Get("no") });
                            }
                            else
                            {
                                enterOutpostPrompt = new GUIMessageBox("",
                                                                       TextManager.GetWithVariable("campaignenteroutpostprompt", "[locationname]", DockingTarget.Item.Submarine.Info.Name),
                                                                       new string[] { TextManager.Get("yes"), TextManager.Get("no") });
                            }
                            enterOutpostPrompt.Buttons[0].OnClicked += (btn, userdata) =>
                            {
                                SendDockingSignal();
                                enterOutpostPrompt.Close();
                                return(true);
                            };
                            enterOutpostPrompt.Buttons[1].OnClicked += enterOutpostPrompt.Close;
                            return(false);
                        }
                    }
                    SendDockingSignal();

                    return(true);
                }
            };
            void SendDockingSignal()
            {
                if (GameMain.Client == null)
                {
                    item.SendSignal(0, "1", "toggle_docking", sender: null);
                }
                else
                {
                    dockingNetworkMessagePending = true;
                    item.CreateClientEvent(this);
                }
            }

            dockingButton.Font = GUI.SubHeadingFont;
            dockingButton.TextBlock.RectTransform.MaxSize = new Point((int)(dockingButton.Rect.Width * 0.7f), int.MaxValue);
            dockingButton.TextBlock.AutoScaleHorizontal   = true;

            var    style        = GUI.Style.GetComponentStyle("DockingButtonUp");
            Sprite buttonSprite = style.Sprites.FirstOrDefault().Value.FirstOrDefault()?.Sprite;
            Point  buttonSize   = buttonSprite != null?buttonSprite.size.ToPoint() : new Point(149, 52);

            Point horizontalButtonSize = buttonSize.Multiply(elementScale * GUI.Scale * dockingButtonSize);
            Point verticalButtonSize   = horizontalButtonSize.Flip();
            var   leftButton           = new GUIButton(new RectTransform(verticalButtonSize, dockingContainer.RectTransform, Anchor.CenterLeft), "", style: "DockingButtonLeft")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = -Vector2.UnitX
            };
            var rightButton = new GUIButton(new RectTransform(verticalButtonSize, dockingContainer.RectTransform, Anchor.CenterRight), "", style: "DockingButtonRight")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = Vector2.UnitX
            };
            var upButton = new GUIButton(new RectTransform(horizontalButtonSize, dockingContainer.RectTransform, Anchor.TopCenter), "", style: "DockingButtonUp")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = Vector2.UnitY
            };
            var downButton = new GUIButton(new RectTransform(horizontalButtonSize, dockingContainer.RectTransform, Anchor.BottomCenter), "", style: "DockingButtonDown")
            {
                OnClicked = NudgeButtonClicked,
                UserData  = -Vector2.UnitY
            };

            // Sonar area
            steerArea = new GUICustomComponent(new RectTransform(Sonar.GUISizeCalculation, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
                                               (spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
            steerRadius = steerArea.Rect.Width / 2;

            pressureWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), steerArea.RectTransform, Anchor.Center, Pivot.TopCenter),
                                                   TextManager.Get("SteeringDepthWarning"), Color.Red, GUI.LargeFont, Alignment.Center)
            {
                Visible = false
            };
            // Tooltip/helper text
            tipContainer = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.1f), steerArea.RectTransform, Anchor.BottomCenter, Pivot.TopCenter)
                                            , "", font: GUI.Font, wrap: true, style: "GUIToolTip", textAlignment: Alignment.Center)
            {
                AutoScaleHorizontal = true
            };
            noPowerTip = TextManager.Get("SteeringNoPowerTip");
            autoPilotMaintainPosTip = TextManager.Get("SteeringAutoPilotMaintainPosTip");
            autoPilotLevelStartTip  = TextManager.GetWithVariable("SteeringAutoPilotLocationTip", "[locationname]",
                                                                  GameMain.GameSession?.StartLocation == null ? "Start" : GameMain.GameSession.StartLocation.Name);
            autoPilotLevelEndTip = TextManager.GetWithVariable("SteeringAutoPilotLocationTip", "[locationname]",
                                                               GameMain.GameSession?.EndLocation == null ? "End" : GameMain.GameSession.EndLocation.Name);
        }
Пример #12
0
        private bool SelectItem(Character user, FabricationRecipe selectedItem)
        {
            selectedItemFrame.ClearChildren();

            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), selectedItemFrame.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f, Stretch = true
            };

            /*var itemIcon = selectedItem.TargetItem.InventoryIcon ?? selectedItem.TargetItem.sprite;
             * if (itemIcon != null)
             * {
             *  GUIImage img = new GUIImage(new RectTransform(new Point(40, 40), paddedFrame.RectTransform),
             *      itemIcon, scaleToFit: true)
             *  {
             *      Color = selectedItem.TargetItem.InventoryIconColor
             *  };
             * }*/
            var nameBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                             selectedItem.TargetItem.Name, textAlignment: Alignment.CenterLeft);

            if (!string.IsNullOrWhiteSpace(selectedItem.TargetItem.Description))
            {
                var description = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                                                   selectedItem.TargetItem.Description,
                                                   font: GUI.SmallFont, wrap: true);
                if (description.Rect.Height > paddedFrame.Rect.Height * 0.4f)
                {
                    description.Wrap  = false;
                    description.Text  = description.WrappedText.Split('\n').First() + "...";
                    nameBlock.ToolTip = description.ToolTip = selectedItem.TargetItem.Description;
                    description.RectTransform.MaxSize = new Point(int.MaxValue, (int)description.Font.MeasureString(description.Text).Y);
                }
            }

            List <Skill> inadequateSkills = new List <Skill>();

            if (user != null)
            {
                inadequateSkills = selectedItem.RequiredSkills.FindAll(skill => user.GetSkillLevel(skill.Identifier) < skill.Level);
            }

            if (selectedItem.RequiredSkills.Any())
            {
                string text = TextManager.Get("FabricatorRequiredSkills") + ":\n";
                foreach (Skill skill in selectedItem.RequiredSkills)
                {
                    text += "   - " + TextManager.Get("SkillName." + skill.Identifier) + " " + TextManager.Get("Lvl").ToLower() + " " + skill.Level;
                    if (skill != selectedItem.RequiredSkills.Last())
                    {
                        text += "\n";
                    }
                }
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform), text,
                                 textColor: inadequateSkills.Any() ? Color.Red : Color.LightGreen, font: GUI.SmallFont);
            }

            float degreeOfSuccess = user == null ? 0.0f : DegreeOfSuccess(user, selectedItem.RequiredSkills);

            if (degreeOfSuccess > 0.5f)
            {
                degreeOfSuccess = 1.0f;
            }

            float  requiredTime     = user == null ? selectedItem.RequiredTime : GetRequiredTime(selectedItem, user);
            string requiredTimeText = TextManager.Get("FabricatorRequiredTime") + ": " + ToolBox.SecondsToReadableTime(requiredTime);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                             requiredTimeText, textColor: ToolBox.GradientLerp(degreeOfSuccess, Color.Red, Color.Yellow, Color.LightGreen), font: GUI.SmallFont);

            return(true);
        }
Пример #13
0
        partial void InitProjSpecific()
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var filterArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), paddedFrame.RectTransform), isHorizontal: true)
            {
                Stretch  = true,
                UserData = "filterarea"
            };

            new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), filterArea.RectTransform), TextManager.Get("FilterMapEntities"), font: GUI.Font);
            itemFilterBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), filterArea.RectTransform), font: GUI.Font);
            itemFilterBox.OnTextChanged += (textBox, text) => { FilterEntities(text); return(true); };
            var clearButton = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), filterArea.RectTransform), "x")
            {
                OnClicked = (btn, userdata) => { ClearFilter(); itemFilterBox.Flash(Color.White); return(true); }
            };

            itemList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.5f), paddedFrame.RectTransform))
            {
                OnSelected = (GUIComponent component, object userdata) =>
                {
                    selectedItem = userdata as FabricationRecipe;
                    if (selectedItem != null)
                    {
                        SelectItem(Character.Controlled, selectedItem);
                    }
                    return(true);
                }
            };

            inputInventoryHolder  = new GUIFrame(new RectTransform(new Vector2(0.7f, 0.15f), paddedFrame.RectTransform), style: null);
            inputInventoryOverlay = new GUICustomComponent(new RectTransform(Vector2.One, inputInventoryHolder.RectTransform), DrawInputOverLay, null)
            {
                CanBeFocused = false
            };

            var outputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.25f), paddedFrame.RectTransform), isHorizontal: true);

            selectedItemFrame      = new GUIFrame(new RectTransform(new Vector2(0.75f, 1.0f), outputArea.RectTransform), style: "InnerFrame");
            outputInventoryHolder  = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), outputArea.RectTransform), style: null);
            outputInventoryOverlay = new GUICustomComponent(new RectTransform(Vector2.One, outputArea.RectTransform), DrawOutputOverLay, null)
            {
                CanBeFocused = false
            };

            foreach (FabricationRecipe fi in fabricationRecipes)
            {
                GUIFrame frame = new GUIFrame(new RectTransform(new Point(itemList.Rect.Width, 30), itemList.Content.RectTransform), style: null)
                {
                    UserData      = fi,
                    HoverColor    = Color.Gold * 0.2f,
                    SelectedColor = Color.Gold * 0.5f,
                    ToolTip       = fi.TargetItem.Description
                };

                GUITextBlock textBlock = new GUITextBlock(new RectTransform(Vector2.Zero, frame.RectTransform, Anchor.CenterLeft)
                {
                    AbsoluteOffset = new Point(50, 0)
                },
                                                          fi.DisplayName)
                {
                    ToolTip = fi.TargetItem.Description
                };

                var itemIcon = fi.TargetItem.InventoryIcon ?? fi.TargetItem.sprite;
                if (itemIcon != null)
                {
                    GUIImage img = new GUIImage(new RectTransform(new Point(30, 30), frame.RectTransform, Anchor.CenterLeft)
                    {
                        AbsoluteOffset = new Point(3, 0)
                    },
                                                itemIcon, scaleToFit: true)
                    {
                        Color   = fi.TargetItem.InventoryIconColor,
                        ToolTip = fi.TargetItem.Description
                    };
                }
            }

            activateButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.07f), paddedFrame.RectTransform),
                                           TextManager.Get("FabricatorCreate"), style: "GUIButtonLarge")
            {
                OnClicked = StartButtonClicked,
                UserData  = selectedItem,
                Enabled   = false
            };

            inSufficientPowerWarning = new GUITextBlock(new RectTransform(Vector2.One, activateButton.RectTransform), TextManager.Get("FabricatorNoPower"),
                                                        textColor: Color.Orange, textAlignment: Alignment.Center, color: Color.Black, style: "OuterGlow")
            {
                HoverColor         = Color.Black,
                IgnoreLayoutGroups = true,
                Visible            = false,
                CanBeFocused       = false
            };
        }
Пример #14
0
        partial void InitProjSpecific()
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var filterArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), paddedFrame.RectTransform), isHorizontal: true)
            {
                Stretch  = true,
                UserData = "filterarea"
            };

            new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), filterArea.RectTransform), TextManager.Get("FilterMapEntities"), font: GUI.Font);
            itemFilterBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), filterArea.RectTransform), font: GUI.Font);
            itemFilterBox.OnTextChanged += (textBox, text) => { FilterEntities(text); return(true); };
            var clearButton = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), filterArea.RectTransform), "x")
            {
                OnClicked = (btn, userdata) => { ClearFilter(); itemFilterBox.Flash(Color.White); return(true); }
            };

            itemList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.5f), paddedFrame.RectTransform))
            {
                OnSelected = (GUIComponent component, object userdata) =>
                {
                    selectedItem = userdata as FabricationRecipe;
                    if (selectedItem != null)
                    {
                        SelectItem(Character.Controlled, selectedItem);
                    }
                    return(true);
                }
            };

            inputInventoryHolder  = new GUIFrame(new RectTransform(new Vector2(0.7f, 0.15f), paddedFrame.RectTransform), style: null);
            inputInventoryOverlay = new GUICustomComponent(new RectTransform(Vector2.One, inputInventoryHolder.RectTransform), DrawInputOverLay, null)
            {
                CanBeFocused = false
            };

            var outputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.25f), paddedFrame.RectTransform), isHorizontal: true);

            selectedItemFrame      = new GUIFrame(new RectTransform(new Vector2(0.75f, 1.0f), outputArea.RectTransform), style: "InnerFrame");
            outputInventoryHolder  = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), outputArea.RectTransform), style: null);
            outputInventoryOverlay = new GUICustomComponent(new RectTransform(Vector2.One, outputArea.RectTransform), DrawOutputOverLay, null)
            {
                CanBeFocused = false
            };

            CreateRecipes();

            activateButton = new GUIButton(new RectTransform(new Vector2(0.8f, 0.07f), paddedFrame.RectTransform),
                                           TextManager.Get("FabricatorCreate"), style: "GUIButtonLarge")
            {
                OnClicked = StartButtonClicked,
                UserData  = selectedItem,
                Enabled   = false
            };

            inSufficientPowerWarning = new GUITextBlock(new RectTransform(Vector2.One, activateButton.RectTransform), TextManager.Get("FabricatorNoPower"),
                                                        textColor: Color.Orange, textAlignment: Alignment.Center, color: Color.Black, style: "OuterGlow")
            {
                HoverColor         = Color.Black,
                IgnoreLayoutGroups = true,
                Visible            = false,
                CanBeFocused       = false
            };
        }
Пример #15
0
        partial void InitProjSpecific()
        {
            int viewSize         = (int)Math.Min(GuiFrame.Rect.Width - 150, GuiFrame.Rect.Height * 0.9f);
            var controlContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.35f), GuiFrame.RectTransform, Anchor.CenterLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.99f), (int)(viewSize * 0.05f))
            }, "SonarFrame");
            var paddedControlContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), controlContainer.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            var statusContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0)
            }, "SonarFrame");
            var paddedStatusContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), statusContainer.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            manualTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), paddedControlContainer.RectTransform),
                                           TextManager.Get("SteeringManual"), style: "GUIRadioButton")
            {
                Selected   = true,
                OnSelected = (GUITickBox box) =>
                {
                    AutoPilot     = !box.Selected;
                    unsentChanges = true;
                    user          = Character.Controlled;

                    return(true);
                }
            };
            autopilotTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), paddedControlContainer.RectTransform),
                                              TextManager.Get("SteeringAutoPilot"), style: "GUIRadioButton")
            {
                OnSelected = (GUITickBox box) =>
                {
                    AutoPilot = box.Selected;
                    if (AutoPilot && MaintainPos)
                    {
                        posToMaintain = controlledSub == null ? item.WorldPosition : controlledSub.WorldPosition;
                    }
                    unsentChanges = true;
                    user          = Character.Controlled;

                    return(true);
                }
            };

            GUITickBox.CreateRadioButtonGroup(new List <GUITickBox> {
                manualTickBox, autopilotTickBox
            });

            var autoPilotControls       = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.6f), paddedControlContainer.RectTransform), "InnerFrame");
            var paddedAutoPilotControls = new GUILayoutGroup(new RectTransform(new Vector2(0.8f), autoPilotControls.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.03f
            };

            maintainPosTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                                TextManager.Get("SteeringMaintainPos"), font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = maintainPos,
                OnSelected = tickBox =>
                {
                    if (maintainPos != tickBox.Selected)
                    {
                        unsentChanges = true;
                        user          = Character.Controlled;
                        maintainPos   = tickBox.Selected;
                        if (maintainPos)
                        {
                            if (controlledSub == null)
                            {
                                posToMaintain = null;
                            }
                            else
                            {
                                posToMaintain = controlledSub.WorldPosition;
                            }
                        }
                        else if (!LevelEndSelected && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                        if (!maintainPos)
                        {
                            posToMaintain = null;
                        }
                    }
                    return(true);
                }
            };

            levelStartTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                               GameMain.GameSession?.StartLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
                                               font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = levelStartSelected,
                OnSelected = tickBox =>
                {
                    if (levelStartSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelStartSelected = tickBox.Selected;
                        levelEndSelected   = !levelStartSelected;
                        if (levelStartSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelEndSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };

            levelEndTickBox = new GUITickBox(new RectTransform(new Vector2(0.2f, 0.2f), paddedAutoPilotControls.RectTransform),
                                             GameMain.GameSession?.EndLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, 20),
                                             font: GUI.SmallFont)
            {
                Enabled    = false,
                Selected   = levelEndSelected,
                OnSelected = tickBox =>
                {
                    if (levelEndSelected != tickBox.Selected)
                    {
                        unsentChanges      = true;
                        user               = Character.Controlled;
                        levelEndSelected   = tickBox.Selected;
                        levelStartSelected = !levelEndSelected;
                        if (levelEndSelected)
                        {
                            UpdatePath();
                        }
                        else if (!MaintainPos && !LevelStartSelected)
                        {
                            AutoPilot = false;
                        }
                    }
                    return(true);
                }
            };

            autoPilotControlsDisabler = new GUIFrame(new RectTransform(Vector2.One, autoPilotControls.RectTransform), "InnerFrame");

            GUITickBox.CreateRadioButtonGroup(new List <GUITickBox> {
                maintainPosTickBox, levelStartTickBox, levelEndTickBox
            });

            string steeringVelX  = TextManager.Get("SteeringVelocityX");
            string steeringVelY  = TextManager.Get("SteeringVelocityY");
            string steeringDepth = TextManager.Get("SteeringDepth");

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                    var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.Y * Physics.DisplayToRealWorldRatio) * 3.6f;
                    return(steeringVelY.Replace("[kph]", ((int)-realWorldVel).ToString()));
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 vel          = controlledSub == null ? Vector2.Zero : controlledSub.Velocity;
                    var     realWorldVel = ConvertUnits.ToDisplayUnits(vel.X * Physics.DisplayToRealWorldRatio) * 3.6f;
                    return(steeringVelX.Replace("[kph]", ((int)realWorldVel).ToString()));
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), "")
            {
                TextGetter = () =>
                {
                    Vector2 pos            = controlledSub == null ? Vector2.Zero : controlledSub.Position;
                    float   realWorldDepth = Level.Loaded == null ? 0.0f : Math.Abs(pos.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
                    return(steeringDepth.Replace("[m]", ((int)realWorldDepth).ToString()));
                }
            };

            pressureWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), TextManager.Get("SteeringDepthWarning"), Color.Red)
            {
                Visible = false
            };

            tipContainer = new GUITextBlock(new RectTransform(new Vector2(0.25f, 0.12f), GuiFrame.RectTransform, Anchor.BottomLeft)
            {
                MinSize = new Point(150, 0), RelativeOffset = new Vector2(0.0f, -0.05f)
            }, "", wrap: true, style: "GUIToolTip")
            {
                AutoScale = true
            };

            noPowerTip = TextManager.Get("SteeringNoPowerTip");
            autoPilotMaintainPosTip = TextManager.Get("SteeringAutoPilotMaintainPosTip");
            autoPilotLevelStartTip  = TextManager.Get("SteeringAutoPilotLocationTip").Replace("[locationname]",
                                                                                              GameMain.GameSession?.StartLocation == null ? "Start" : GameMain.GameSession.StartLocation.Name);
            autoPilotLevelEndTip = TextManager.Get("SteeringAutoPilotLocationTip").Replace("[locationname]",
                                                                                           GameMain.GameSession?.EndLocation == null ? "End" : GameMain.GameSession.EndLocation.Name);

            steerArea = new GUICustomComponent(new RectTransform(new Point(viewSize), GuiFrame.RectTransform, Anchor.CenterLeft),
                                               (spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
        }
Пример #16
0
        partial void InitProjSpecific(XElement element)
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform),
                             header, textAlignment: Alignment.TopCenter, font: GUI.LargeFont);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedFrame.RectTransform),
                             Description, font: GUI.SmallFont, wrap: true);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform),
                             TextManager.Get("RequiredRepairSkills"));
            for (int i = 0; i < requiredSkills.Count; i++)
            {
                var skillText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform),
                                                 "   - " + TextManager.AddPunctuation(':', TextManager.Get("SkillName." + requiredSkills[i].Identifier), ((int)requiredSkills[i].Level).ToString()),
                                                 font: GUI.SmallFont)
                {
                    UserData = requiredSkills[i]
                };
            }

            progressBar = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform),
                                             color: Color.Green, barSize: 0.0f);

            repairButtonText = TextManager.Get("RepairButton");
            repairingText    = TextManager.Get("Repairing");
            RepairButton     = new GUIButton(new RectTransform(new Vector2(0.8f, 0.15f), paddedFrame.RectTransform, Anchor.TopCenter), repairButtonText)
            {
                OnClicked = (btn, obj) =>
                {
                    requestStartFixAction = FixActions.Repair;
                    item.CreateClientEvent(this);
                    return(true);
                }
            };
            sabotageButtonText = TextManager.Get("SabotageButton");
            sabotagingText     = TextManager.Get("Sabotaging");
            SabotageButton     = new GUIButton(new RectTransform(new Vector2(0.8f, 0.15f), paddedFrame.RectTransform, Anchor.BottomCenter), sabotageButtonText)
            {
                OnClicked = (btn, obj) =>
                {
                    requestStartFixAction = FixActions.Sabotage;
                    item.CreateClientEvent(this);
                    return(true);
                }
            };

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "emitter":
                case "particleemitter":
                    particleEmitters.Add(new ParticleEmitter(subElement));
                    particleEmitterConditionRanges.Add(new Vector2(
                                                           subElement.GetAttributeFloat("mincondition", 0.0f),
                                                           subElement.GetAttributeFloat("maxcondition", 100.0f)));
                    break;
                }
            }
        }
Пример #17
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.015f,
                Stretch         = true
            };

            GUIFrame columnLeft = new GUIFrame(new RectTransform(new Vector2(0.2f, 1.0f), paddedFrame.RectTransform), style: null);

            leftHUDColumn = columnLeft;
            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.35f, 1.0f), paddedFrame.RectTransform), style: null);

            //----------------------------------------------------------
            //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.SmallFont;
                btnText.Wrap = true;
                btnText.SetTextPos();
                warningButtons.Add(warningTexts[i], warningBtn);
            }

            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(30, 30), columnMid.RectTransform),
                                                 TextManager.Get("ReactorWarningCriticalTemp"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };
            lowTemperatureWarning = new GUITickBox(new RectTransform(new Point(30, 30), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.3f, 0.0f)
            },
                                                   TextManager.Get("ReactorWarningCriticalLowTemp"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };
            criticalOutputWarning = new GUITickBox(new RectTransform(new Point(30, 30), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.75f, 0.0f)
            },
                                                   TextManager.Get("ReactorWarningCriticalOutput"), font: GUI.SmallFont, style: "IndicatorLightRed")
            {
                CanBeFocused = false
            };

            new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.05f), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.25f)
            },
                             TextManager.Get("ReactorFissionRate"));
            new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.3f)
            },
                                   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, 0.25f)
            },
                             TextManager.Get("ReactorTurbineOutput"));
            new GUICustomComponent(new RectTransform(new Vector2(0.5f, 0.5f), columnMid.RectTransform, Anchor.TopRight)
            {
                RelativeOffset = new Vector2(0.0f, 0.3f)
            },
                                   DrawTurbineOutputMeter, null)
            {
                ToolTip = TextManager.Get("ReactorTipTurbineOutput")
            };

            new GUITextBlock(new RectTransform(new Point(0, 20), columnMid.RectTransform, Anchor.BottomLeft)
            {
                AbsoluteOffset = new Point(0, 90)
            },
                             TextManager.Get("ReactorFissionRate"));
            fissionRateScrollBar = new GUIScrollBar(new RectTransform(new Point(columnMid.Rect.Width, 30), columnMid.RectTransform, Anchor.BottomCenter)
            {
                AbsoluteOffset = new Point(0, 60)
            },
                                                    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, 20), columnMid.RectTransform, Anchor.BottomLeft)
            {
                AbsoluteOffset = new Point(0, 30)
            },
                             TextManager.Get("ReactorTurbineOutput"));
            turbineOutputScrollBar = new GUIScrollBar(new RectTransform(new Point(columnMid.Rect.Width, 30), columnMid.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 Point(100, 20), columnRight.RectTransform), TextManager.Get("ReactorAutoTemp"))
            {
                ToolTip = TextManager.Get("ReactorTipAutoTemp")
            };
            autoTempSlider = new GUIScrollBar(new RectTransform(new Point(100, 30), columnRight.RectTransform)
            {
                AbsoluteOffset = new Point(0, 30)
            },
                                              barSize: 0.5f, style: "OnOffSlider")
            {
                ToolTip         = TextManager.Get("ReactorTipAutoTemp"),
                IsBooleanSwitch = true,
                BarScroll       = 1.0f,
                OnMoved         = (scrollBar, scrollAmount) =>
                {
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };

            onOffSwitch = new GUIScrollBar(new RectTransform(new Point(50, 80), columnRight.RectTransform, Anchor.TopRight),
                                           barSize: 0.2f, style: "OnOffLever")
            {
                IsBooleanSwitch = true,
                MinValue        = 0.25f,
                MaxValue        = 0.75f,
                OnMoved         = (scrollBar, scrollAmount) =>
                {
                    LastUser      = Character.Controlled;
                    unsentChanges = true;
                    return(true);
                }
            };

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

            lever.RectTransform.NonScaledSize = new Point(lever.Rect.Width + 30, 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);

            var loadText = new GUITextBlock(new RectTransform(new Point(100, 30), 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(new Point(100, 30), 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())); };
        }
Пример #18
0
        protected GUIComponent CreateInfoFrame(string title, string text, int width = 300, int height = 80, string anchorStr = "", bool hasButton = false, Action callback = null, Action showVideo = null)
        {
            if (hasButton)
            {
                height += 60;
            }

            Anchor anchor = Anchor.TopRight;

            if (anchorStr != string.Empty)
            {
                Enum.TryParse(anchorStr, out anchor);
            }

            width  = (int)(width * GUI.Scale);
            height = (int)(height * GUI.Scale);

            string wrappedText = ToolBox.WrapText(text, width, GUI.Font);

            height += (int)GUI.Font.MeasureString(wrappedText).Y;

            if (title.Length > 0)
            {
                height += (int)GUI.Font.MeasureString(title).Y + (int)(150 * GUI.Scale);
            }

            var background = new GUIFrame(new RectTransform(new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight), GUI.Canvas, Anchor.Center), style: "GUIBackgroundBlocker");

            var infoBlock = new GUIFrame(new RectTransform(new Point(width, height), background.RectTransform, anchor));

            infoBlock.Flash(GUI.Style.Green);

            var infoContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), infoBlock.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                AbsoluteSpacing = 5
            };

            if (title.Length > 0)
            {
                var titleBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform),
                                                  title, font: GUI.LargeFont, textAlignment: Alignment.Center, textColor: new Color(253, 174, 0));
                titleBlock.RectTransform.IsFixedSize = true;
            }

            List <RichTextData> richTextData = RichTextData.GetRichTextData(text, out text);
            GUITextBlock        textBlock;

            if (richTextData == null)
            {
                textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), " " + text, wrap: true);
            }
            else
            {
                textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), infoContent.RectTransform), richTextData, " " + text, wrap: true);
            }

            textBlock.RectTransform.IsFixedSize = true;
            infoBoxClosedCallback = callback;

            if (hasButton)
            {
                var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), infoContent.RectTransform), isHorizontal: true)
                {
                    RelativeSpacing = 0.1f
                };
                buttonContainer.RectTransform.IsFixedSize = true;

                if (showVideo != null)
                {
                    buttonContainer.Stretch = true;
                    var videoButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform),
                                                    TextManager.Get("Video"), style: "GUIButtonLarge")
                    {
                        OnClicked = (GUIButton button, object obj) =>
                        {
                            showVideo();
                            return(true);
                        }
                    };
                }
                else
                {
                    buttonContainer.Stretch     = false;
                    buttonContainer.ChildAnchor = Anchor.Center;
                }

                var okButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonContainer.RectTransform),
                                             TextManager.Get("OK"), style: "GUIButtonLarge")
                {
                    OnClicked = CloseInfoFrame
                };
            }

            infoBlock.RectTransform.NonScaledSize = new Point(infoBlock.Rect.Width, (int)(infoContent.Children.Sum(c => c.Rect.Height + infoContent.AbsoluteSpacing) / infoContent.RectTransform.RelativeSize.Y));

            GUI.PlayUISound(GUISoundType.UIMessage);

            return(background);
        }
Пример #19
0
        protected override void CreateGUI()
        {
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                Stretch         = true,
                RelativeSpacing = 0.08f
            };

            paddedFrame.OnAddedToGUIUpdateList += (component) =>
            {
                bool buttonsEnabled = AllowUsingButtons;
                foreach (var child in component.Children)
                {
                    if (!(child is GUIButton))
                    {
                        continue;
                    }
                    if (!(child.UserData is int))
                    {
                        continue;
                    }
                    child.Enabled = buttonsEnabled;
                    child.Children.ForEach(c => c.Enabled = buttonsEnabled);
                }
                bool itemsContained = Container.Inventory.AllItems.Any();
                if (itemsContained)
                {
                    var indicatorStyle = buttonsEnabled ? indicatorStyleGreen : indicatorStyleRed;
                    if (containerIndicator.Style != indicatorStyle)
                    {
                        containerIndicator.ApplyStyle(indicatorStyle);
                    }
                }
                containerIndicator.OverrideState = itemsContained ? GUIComponent.ComponentState.Selected : GUIComponent.ComponentState.None;
            };

            float   x            = 1.0f / (1 + RequiredSignalCount);
            float   y            = Math.Min((x * paddedFrame.Rect.Width) / paddedFrame.Rect.Height, 0.5f);
            Vector2 relativeSize = new Vector2(x, y);

            var containerSection = new GUIFrame(new RectTransform(new Vector2(x, 1.0f), paddedFrame.RectTransform), style: null);
            var containerSlot    = new GUIFrame(new RectTransform(new Vector2(1.0f, y), containerSection.RectTransform, anchor: Anchor.Center), style: null);

            containerHolder    = new GUIFrame(new RectTransform(new Vector2(1f, 1.2f), containerSlot.RectTransform, Anchor.BottomCenter), style: null);
            containerIndicator = new GUIImage(new RectTransform(new Vector2(0.5f, 0.5f * (1.0f - y)), containerSection.RectTransform, anchor: Anchor.BottomCenter),
                                              style: "IndicatorLightRed", scaleToFit: true);

            for (int i = 0; i < RequiredSignalCount; i++)
            {
                var button = new GUIButton(new RectTransform(relativeSize, paddedFrame.RectTransform), style: null)
                {
                    UserData  = i,
                    OnClicked = (button, userData) =>
                    {
                        if (GameMain.IsSingleplayer)
                        {
                            SendSignal((int)userData);
                        }
                        else
                        {
                            item.CreateClientEvent(this, new object[] { userData });
                        }
                        return(true);
                    }
                };
                var image = new GUIImage(new RectTransform(Vector2.One, button.RectTransform), terminalButtonStyles[i], scaleToFit: true);
            }
        }
Пример #20
0
        partial void InitProjSpecific()
        {
            if (GuiFrame == null)
            {
                return;
            }

            GUILayoutGroup paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.7f), GuiFrame.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.1f, Stretch = true
            };

            string rechargeStr = TextManager.Get("PowerContainerRechargeRate");

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform), "RechargeRate", textAlignment: Alignment.Center)
            {
                TextGetter = () =>
                {
                    return(rechargeStr.Replace("[rate]", ((int)((rechargeSpeed / maxRechargeSpeed) * 100.0f)).ToString()));
                }
            };

            var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform, Anchor.BottomCenter), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform),
                             "0 %", textAlignment: Alignment.Center);
            rechargeSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.8f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider")
            {
                Step    = 0.1f,
                OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
                {
                    float newRechargeSpeed = maxRechargeSpeed * barScroll;
                    if (Math.Abs(newRechargeSpeed - rechargeSpeed) < 0.1f)
                    {
                        return(false);
                    }

                    RechargeSpeed = newRechargeSpeed;
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                        GameServer.Log(Character.Controlled.LogName + " set the recharge speed of " + item.Name + " to " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
                    }
                    else if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
                    return(true);
                }
            };
            new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform),
                             "100 %", textAlignment: Alignment.Center);

            string chargeStr = TextManager.Get("PowerContainerCharge");

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedFrame.RectTransform), "Charge", textAlignment: Alignment.Center)
            {
                TextGetter = () =>
                {
                    return(chargeStr.Replace("[charge]", (int)charge + "/" + (int)capacity).Replace("[percentage]", ((int)((charge / capacity) * 100.0f)).ToString()));
                }
            };

            chargeIndicator = new GUIProgressBar(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), barSize: 0.0f)
            {
                ProgressGetter = () =>
                {
                    return(charge / capacity);
                }
            };
        }
Пример #21
0
        public GUIComponent CreateWhiteListFrame(GUIComponent parent)
        {
            if (whitelistFrame != null)
            {
                whitelistFrame.Parent.ClearChildren();
                whitelistFrame = null;
            }

            whitelistFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), parent.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var enabledTick = new GUITickBox(new RectTransform(new Vector2(0.1f, 0.1f), whitelistFrame.RectTransform), TextManager.Get("WhiteListEnabled"))
            {
                Selected    = Enabled,
                UpdateOrder = 1,
                OnSelected  = (GUITickBox box) =>
                {
                    Enabled = !Enabled;

                    nameBox.Text         = "";
                    nameBox.Enabled      = Enabled;
                    ipBox.Text           = "";
                    ipBox.Enabled        = Enabled;
                    addNewButton.Enabled = false;

                    if (Enabled)
                    {
                        foreach (Client c in GameMain.Server.ConnectedClients)
                        {
                            if (!IsWhiteListed(c.Name, c.Connection.RemoteEndPoint.Address.ToString()))
                            {
                                whitelistedPlayers.Add(new WhiteListedPlayer(c.Name, c.Connection.RemoteEndPoint.Address.ToString()));
                                if (whitelistFrame != null)
                                {
                                    CreateWhiteListFrame(whitelistFrame.Parent);
                                }
                            }
                        }
                    }

                    Save();
                    return(true);
                }
            };

            var listBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.7f), whitelistFrame.RectTransform));

            foreach (WhiteListedPlayer wlp in whitelistedPlayers)
            {
                string blockText = wlp.Name;
                if (!string.IsNullOrWhiteSpace(wlp.IP))
                {
                    blockText += " (" + wlp.IP + ")";
                }
                GUITextBlock textBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), listBox.Content.RectTransform),
                                                          blockText)
                {
                    UserData = wlp
                };

                var removeButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.8f), textBlock.RectTransform, Anchor.CenterRight), TextManager.Get("WhiteListRemove"))
                {
                    UserData  = wlp,
                    OnClicked = RemoveFromWhiteList
                };
            }

            var nameArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), whitelistFrame.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), nameArea.RectTransform), TextManager.Get("WhiteListName"));
            nameBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), nameArea.RectTransform), "");
            nameBox.OnTextChanged += (textBox, text) =>
            {
                addNewButton.Enabled = !string.IsNullOrEmpty(ipBox.Text) && !string.IsNullOrEmpty(nameBox.Text);
                return(true);
            };

            var ipArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), whitelistFrame.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), ipArea.RectTransform), TextManager.Get("WhiteListIP"));
            ipBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), ipArea.RectTransform), "");
            ipBox.OnTextChanged += (textBox, text) =>
            {
                addNewButton.Enabled = !string.IsNullOrEmpty(ipBox.Text) && !string.IsNullOrEmpty(nameBox.Text);
                return(true);
            };

            addNewButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.1f), whitelistFrame.RectTransform), TextManager.Get("WhiteListAdd"))
            {
                OnClicked = AddToWhiteList
            };

            nameBox.Enabled      = Enabled;
            ipBox.Enabled        = Enabled;
            addNewButton.Enabled = false;

            return(parent);
        }
Пример #22
0
        public void CreatePreviewWindow(GUIFrame frame)
        {
            frame.ClearChildren();

            if (frame == null)
            {
                return;
            }

            var previewContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.98f), frame.RectTransform, Anchor.Center))
            {
                Stretch = true
            };

            var title = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), previewContainer.RectTransform, Anchor.CenterLeft), ServerName, font: GUI.LargeFont)
            {
                ToolTip = ServerName
            };

            title.Text = ToolBox.LimitString(title.Text, title.Font, (int)(title.Rect.Width * 0.85f));

            GUITickBox favoriteTickBox = new GUITickBox(new RectTransform(new Vector2(0.15f, 0.8f), title.RectTransform, Anchor.CenterRight),
                                                        "", null, "GUIServerListFavoriteTickBox")
            {
                Selected   = Favorite,
                ToolTip    = TextManager.Get(Favorite ? "removefromfavorites" : "addtofavorites"),
                OnSelected = (tickbox) =>
                {
                    if (tickbox.Selected)
                    {
                        GameMain.ServerListScreen.AddToFavoriteServers(this);
                    }
                    else
                    {
                        GameMain.ServerListScreen.RemoveFromFavoriteServers(this);
                    }
                    tickbox.ToolTip = TextManager.Get(tickbox.Selected ? "removefromfavorites" : "addtofavorites");
                    return(true);
                }
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), previewContainer.RectTransform),
                             TextManager.AddPunctuation(':', TextManager.Get("ServerListVersion"), string.IsNullOrEmpty(GameVersion) ? TextManager.Get("Unknown") : GameVersion));

            PlayStyle playStyle = PlayStyle ?? Networking.PlayStyle.Serious;

            Sprite playStyleBannerSprite      = ServerListScreen.PlayStyleBanners[(int)playStyle];
            float  playStyleBannerAspectRatio = playStyleBannerSprite.SourceRect.Width / playStyleBannerSprite.SourceRect.Height;
            var    playStyleBanner            = new GUIImage(new RectTransform(new Point(previewContainer.Rect.Width, (int)(previewContainer.Rect.Width / playStyleBannerAspectRatio)), previewContainer.RectTransform),
                                                             playStyleBannerSprite, null, true);

            var playStyleName = new GUITextBlock(new RectTransform(new Vector2(0.15f, 0.0f), playStyleBanner.RectTransform)
            {
                RelativeOffset = new Vector2(0.01f, 0.06f)
            },
                                                 TextManager.AddPunctuation(':', TextManager.Get("serverplaystyle"), TextManager.Get("servertag." + playStyle)), textColor: Color.White,
                                                 font: GUI.SmallFont, textAlignment: Alignment.Center,
                                                 color: ServerListScreen.PlayStyleColors[(int)playStyle], style: "GUISlopedHeader");

            playStyleName.RectTransform.NonScaledSize = (playStyleName.Font.MeasureString(playStyleName.Text) + new Vector2(20, 5) * GUI.Scale).ToPoint();
            playStyleName.RectTransform.IsFixedSize   = true;

            var content = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.6f), previewContainer.RectTransform))
            {
                Stretch = true
            };
            // playstyle tags -----------------------------------------------------------------------------

            var playStyleContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), content.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.01f,
                CanBeFocused    = true
            };

            var playStyleTags = GetPlayStyleTags();

            foreach (string tag in playStyleTags)
            {
                if (!ServerListScreen.PlayStyleIcons.ContainsKey(tag))
                {
                    continue;
                }

                new GUIImage(new RectTransform(Vector2.One, playStyleContainer.RectTransform),
                             ServerListScreen.PlayStyleIcons[tag], scaleToFit: true)
                {
                    ToolTip = TextManager.Get("servertagdescription." + tag),
                    Color   = ServerListScreen.PlayStyleIconColors[tag]
                };
            }

            playStyleContainer.Recalculate();

            // -----------------------------------------------------------------------------

            float elementHeight = 0.075f;

            // Spacing
            new GUIFrame(new RectTransform(new Vector2(1.0f, 0.025f), content.RectTransform), style: null);

            var serverMsg = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform))
            {
                ScrollBarVisible = true
            };
            var msgText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), serverMsg.Content.RectTransform), ServerMessage, font: GUI.SmallFont, wrap: true)
            {
                CanBeFocused = false
            };

            serverMsg.Content.RectTransform.SizeChanged += () => { msgText.CalculateHeightFromText(); };
            msgText.RectTransform.SizeChanged           += () => { serverMsg.UpdateScrollBarSize(); };

            var gameMode = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), content.RectTransform), TextManager.Get("GameMode"));

            new GUITextBlock(new RectTransform(Vector2.One, gameMode.RectTransform),
                             TextManager.Get(string.IsNullOrEmpty(GameMode) ? "Unknown" : "GameMode." + GameMode, returnNull: true) ?? GameMode,
                             textAlignment: Alignment.Right);

            /*var traitors = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), bodyContainer.RectTransform), TextManager.Get("Traitors"));
             * new GUITextBlock(new RectTransform(Vector2.One, traitors.RectTransform), TextManager.Get(!TraitorsEnabled.HasValue ? "Unknown" : TraitorsEnabled.Value.ToString()), textAlignment: Alignment.Right);*/

            var subSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), content.RectTransform), TextManager.Get("ServerListSubSelection"));

            new GUITextBlock(new RectTransform(Vector2.One, subSelection.RectTransform), TextManager.Get(!SubSelectionMode.HasValue ? "Unknown" : SubSelectionMode.Value.ToString()), textAlignment: Alignment.Right);

            var modeSelection = new GUITextBlock(new RectTransform(new Vector2(1.0f, elementHeight), content.RectTransform), TextManager.Get("ServerListModeSelection"));

            new GUITextBlock(new RectTransform(Vector2.One, modeSelection.RectTransform), TextManager.Get(!ModeSelectionMode.HasValue ? "Unknown" : ModeSelectionMode.Value.ToString()), textAlignment: Alignment.Right);

            if (gameMode.TextSize.X + gameMode.GetChild <GUITextBlock>().TextSize.X > gameMode.Rect.Width ||
                subSelection.TextSize.X + subSelection.GetChild <GUITextBlock>().TextSize.X > subSelection.Rect.Width ||
                modeSelection.TextSize.X + modeSelection.GetChild <GUITextBlock>().TextSize.X > modeSelection.Rect.Width)
            {
                gameMode.Font = subSelection.Font = modeSelection.Font = GUI.SmallFont;
                gameMode.GetChild <GUITextBlock>().Font = subSelection.GetChild <GUITextBlock>().Font = modeSelection.GetChild <GUITextBlock>().Font = GUI.SmallFont;
            }

            var allowSpectating = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), content.RectTransform), TextManager.Get("ServerListAllowSpectating"))
            {
                CanBeFocused = false
            };

            if (!AllowSpectating.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowSpectating.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                allowSpectating.Selected = AllowSpectating.Value;
            }

            var allowRespawn = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), content.RectTransform), TextManager.Get("ServerSettingsAllowRespawning"))
            {
                CanBeFocused = false
            };

            if (!AllowRespawn.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), allowRespawn.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                allowRespawn.Selected = AllowRespawn.Value;
            }

            /*var voipEnabledTickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, elementHeight), bodyContainer.RectTransform), TextManager.Get("serversettingsvoicechatenabled"))
             * {
             *  CanBeFocused = false
             * };
             * if (!VoipEnabled.HasValue)
             *  new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), voipEnabledTickBox.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
             * else
             *  voipEnabledTickBox.Selected = VoipEnabled.Value;*/

            var usingWhiteList = new GUITickBox(new RectTransform(new Vector2(1, elementHeight), content.RectTransform), TextManager.Get("ServerListUsingWhitelist"))
            {
                CanBeFocused = false
            };

            if (!UsingWhiteList.HasValue)
            {
                new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.8f), usingWhiteList.Box.RectTransform, Anchor.Center), "?", textAlignment: Alignment.Center);
            }
            else
            {
                usingWhiteList.Selected = UsingWhiteList.Value;
            }


            content.RectTransform.SizeChanged += () =>
            {
                GUITextBlock.AutoScaleAndNormalize(allowSpectating.TextBlock, allowRespawn.TextBlock, usingWhiteList.TextBlock);
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), content.RectTransform),
                             TextManager.Get("ServerListContentPackages"), textAlignment: Alignment.Center, font: GUI.SubHeadingFont);

            var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), content.RectTransform))
            {
                ScrollBarVisible = true
            };

            if (ContentPackageNames.Count == 0)
            {
                new GUITextBlock(new RectTransform(Vector2.One, contentPackageList.Content.RectTransform), TextManager.Get("Unknown"), textAlignment: Alignment.Center)
                {
                    CanBeFocused = false
                };
            }
            else
            {
                List <string> availableWorkshopUrls = new List <string>();
                for (int i = 0; i < ContentPackageNames.Count; i++)
                {
                    var packageText = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.15f), contentPackageList.Content.RectTransform)
                    {
                        MinSize = new Point(0, 15)
                    },
                                                     ContentPackageNames[i])
                    {
                        Enabled = false
                    };
                    if (i < ContentPackageHashes.Count)
                    {
                        if (GameMain.Config.SelectedContentPackages.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
                        {
                            packageText.Selected = true;
                            continue;
                        }

                        //matching content package found, but it hasn't been enabled
                        if (ContentPackage.List.Any(cp => cp.MD5hash.Hash == ContentPackageHashes[i]))
                        {
                            packageText.TextColor = GUI.Style.Orange;
                            packageText.ToolTip   = TextManager.GetWithVariable("ServerListContentPackageNotEnabled", "[contentpackage]", ContentPackageNames[i]);
                        }
                        //workshop download link found
                        else if (i < ContentPackageWorkshopUrls.Count && !string.IsNullOrEmpty(ContentPackageWorkshopUrls[i]))
                        {
                            availableWorkshopUrls.Add(ContentPackageWorkshopUrls[i]);
                            packageText.TextColor = Color.Yellow;
                            packageText.ToolTip   = TextManager.GetWithVariable("ServerListIncompatibleContentPackageWorkshopAvailable", "[contentpackage]", ContentPackageNames[i]);
                        }
                        else //no package or workshop download link found, tough luck
                        {
                            packageText.TextColor = GUI.Style.Red;
                            packageText.ToolTip   = TextManager.GetWithVariables("ServerListIncompatibleContentPackage",
                                                                                 new string[2] {
                                "[contentpackage]", "[hash]"
                            }, new string[2] {
                                ContentPackageNames[i], ContentPackageHashes[i]
                            });
                        }
                    }
                }
                if (availableWorkshopUrls.Count > 0)
                {
                    var workshopBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), content.RectTransform), TextManager.Get("ServerListSubscribeMissingPackages"))
                    {
                        ToolTip   = TextManager.Get(SteamManager.IsInitialized ? "ServerListSubscribeMissingPackagesTooltip" : "ServerListSubscribeMissingPackagesTooltipNoSteam"),
                        Enabled   = SteamManager.IsInitialized,
                        OnClicked = (btn, userdata) =>
                        {
                            GameMain.SteamWorkshopScreen.SubscribeToPackages(availableWorkshopUrls);
                            GameMain.SteamWorkshopScreen.Select();
                            return(true);
                        }
                    };
                    workshopBtn.TextBlock.AutoScaleHorizontal = true;
                }
            }

            // -----------------------------------------------------------------------------

            foreach (GUIComponent c in content.Children)
            {
                if (c is GUITextBlock textBlock)
                {
                    textBlock.Padding = Vector4.Zero;
                }
            }
        }
Пример #23
0
        private void CreateSettingsFrame()
        {
            foreach (NetPropertyData prop in netProperties.Values)
            {
                prop.TempValue = prop.Value;
            }

            //background frame
            settingsFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null, color: Color.Black * 0.5f);
            new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null).OnClicked += (btn, userData) =>
            {
                if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock)
                {
                    ToggleSettingsFrame(btn, userData);
                }
                return(true);
            };

            new GUIButton(new RectTransform(Vector2.One, settingsFrame.RectTransform), "", style: null)
            {
                OnClicked = ToggleSettingsFrame
            };

            //center frames
            GUIFrame innerFrame = new GUIFrame(new RectTransform(new Vector2(0.4f, 0.75f), settingsFrame.RectTransform, Anchor.Center)
            {
                MinSize = new Point(400, 430)
            });
            GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center), style: null);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), paddedFrame.RectTransform), TextManager.Get("Settings"), font: GUI.LargeFont);

            var buttonArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.1f)
            }, isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.01f
            };

            //tabs
            var tabValues = Enum.GetValues(typeof(SettingsTab)).Cast <SettingsTab>().ToArray();

            string[] tabNames = new string[tabValues.Count()];
            for (int i = 0; i < tabNames.Length; i++)
            {
                tabNames[i] = TextManager.Get("ServerSettings" + tabValues[i] + "Tab");
            }
            settingsTabs = new GUIFrame[tabNames.Length];
            tabButtons   = new GUIButton[tabNames.Length];
            for (int i = 0; i < tabNames.Length; i++)
            {
                settingsTabs[i] = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.79f), paddedFrame.RectTransform, Anchor.Center)
                {
                    RelativeOffset = new Vector2(0.0f, 0.05f)
                },
                                               style: "InnerFrame");

                tabButtons[i] = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), tabNames[i], style: "GUITabButton")
                {
                    UserData  = i,
                    OnClicked = SelectSettingsTab
                };
            }
            GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(b => b.TextBlock));
            SelectSettingsTab(tabButtons[0], 0);

            //"Close"
            var closeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), paddedFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Close"))
            {
                OnClicked = ToggleSettingsFrame
            };


            //--------------------------------------------------------------------------------
            //                              server settings
            //--------------------------------------------------------------------------------

            var serverTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.General].RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            //***********************************************

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSubSelection"));
            var selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            GUIRadioButtonGroup selectionMode = new GUIRadioButtonGroup();

            for (int i = 0; i < 3; i++)
            {
                var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont);
                selectionMode.AddRadioButton((SelectionMode)i, selectionTick);
            }
            DebugConsole.NewMessage(SubSelectionMode.ToString(), Color.White);
            GetPropertyData("SubSelectionMode").AssignGUIComponent(selectionMode);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsModeSelection"));
            selectionFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            selectionMode = new GUIRadioButtonGroup();
            for (int i = 0; i < 3; i++)
            {
                var selectionTick = new GUITickBox(new RectTransform(new Vector2(0.3f, 1.0f), selectionFrame.RectTransform), TextManager.Get(((SelectionMode)i).ToString()), font: GUI.SmallFont);
                selectionMode.AddRadioButton((SelectionMode)i, selectionTick);
            }
            GetPropertyData("ModeSelectionMode").AssignGUIComponent(selectionMode);


            //***********************************************

            var voiceChatEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform),
                                                  TextManager.Get("ServerSettingsVoiceChatEnabled"));

            GetPropertyData("VoiceChatEnabled").AssignGUIComponent(voiceChatEnabled);

            //***********************************************

            string autoRestartDelayLabel = TextManager.Get("ServerSettingsAutoRestartDelay") + " ";
            var    startIntervalText     = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), autoRestartDelayLabel);
            var    startIntervalSlider   = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), barSize: 0.1f)
            {
                UserData = startIntervalText,
                Step     = 0.05f,
                OnMoved  = (GUIScrollBar scrollBar, float barScroll) =>
                {
                    GUITextBlock text = scrollBar.UserData as GUITextBlock;
                    text.Text = autoRestartDelayLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue);
                    return(true);
                }
            };

            startIntervalSlider.Range = new Vector2(10.0f, 300.0f);
            GetPropertyData("AutoRestartInterval").AssignGUIComponent(startIntervalSlider);
            startIntervalSlider.OnMoved(startIntervalSlider, startIntervalSlider.BarScroll);

            //***********************************************

            var startWhenClientsReady = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform),
                                                       TextManager.Get("ServerSettingsStartWhenClientsReady"));

            GetPropertyData("StartWhenClientsReady").AssignGUIComponent(startWhenClientsReady);

            CreateLabeledSlider(serverTab, "ServerSettingsStartWhenClientsReadyRatio", out GUIScrollBar slider, out GUITextBlock sliderLabel);
            string clientsReadyRequiredLabel = sliderLabel.Text;

            slider.Step    = 0.2f;
            slider.Range   = new Vector2(0.5f, 1.0f);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                ((GUITextBlock)scrollBar.UserData).Text = clientsReadyRequiredLabel.Replace("[percentage]", ((int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f)).ToString());
                return(true);
            };
            GetPropertyData("StartWhenClientsReadyRatio").AssignGUIComponent(slider);
            slider.OnMoved(slider, slider.BarScroll);

            //***********************************************

            var allowSpecBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsAllowSpectating"));

            GetPropertyData("AllowSpectating").AssignGUIComponent(allowSpecBox);


            var shareSubsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsShareSubFiles"));

            GetPropertyData("AllowFileTransfers").AssignGUIComponent(shareSubsBox);

            var randomizeLevelBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsRandomizeSeed"));

            GetPropertyData("RandomizeSeed").AssignGUIComponent(randomizeLevelBox);

            var saveLogsBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), serverTab.RectTransform), TextManager.Get("ServerSettingsSaveLogs"))
            {
                OnSelected = (GUITickBox) =>
                {
                    //TODO: fix?
                    //showLogButton.Visible = SaveServerLogs;
                    return(true);
                }
            };

            GetPropertyData("SaveServerLogs").AssignGUIComponent(saveLogsBox);

            //--------------------------------------------------------------------------------
            //                              game settings
            //--------------------------------------------------------------------------------

            var roundsTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };


            var endBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
                                        TextManager.Get("ServerSettingsEndRoundWhenDestReached"));

            GetPropertyData("EndRoundAtLevelEnd").AssignGUIComponent(endBox);

            var endVoteBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
                                            TextManager.Get("ServerSettingsEndRoundVoting"));

            GetPropertyData("AllowEndVoting").AssignGUIComponent(endVoteBox);

            CreateLabeledSlider(roundsTab, "ServerSettingsEndRoundVotesRequired", out slider, out sliderLabel);

            string endRoundLabel = sliderLabel.Text;

            slider.Step  = 0.2f;
            slider.Range = new Vector2(0.5f, 1.0f);
            GetPropertyData("EndVoteRequiredRatio").AssignGUIComponent(slider);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                ((GUITextBlock)scrollBar.UserData).Text = endRoundLabel + " " + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %";
                return(true);
            };
            slider.OnMoved(slider, slider.BarScroll);

            var respawnBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform),
                                            TextManager.Get("ServerSettingsAllowRespawning"));

            GetPropertyData("AllowRespawn").AssignGUIComponent(respawnBox);

            CreateLabeledSlider(roundsTab, "ServerSettingsRespawnInterval", out slider, out sliderLabel);
            string intervalLabel = sliderLabel.Text;

            slider.Step  = 0.05f;
            slider.Range = new Vector2(10.0f, 600.0f);
            GetPropertyData("RespawnInterval").AssignGUIComponent(slider);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                GUITextBlock text = scrollBar.UserData as GUITextBlock;
                text.Text = intervalLabel + " " + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue);
                return(true);
            };
            slider.OnMoved(slider, slider.BarScroll);

            var minRespawnText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "")
            {
                ToolTip = TextManager.Get("ServerSettingsMinRespawnToolTip")
            };

            string minRespawnLabel = TextManager.Get("ServerSettingsMinRespawn") + " ";

            CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel);
            slider.ToolTip  = minRespawnText.ToolTip;
            slider.UserData = minRespawnText;
            slider.Step     = 0.1f;
            slider.Range    = new Vector2(0.0f, 1.0f);
            GetPropertyData("MinRespawnRatio").AssignGUIComponent(slider);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                ((GUITextBlock)scrollBar.UserData).Text = minRespawnLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %";
                return(true);
            };
            slider.OnMoved(slider, MinRespawnRatio);

            var respawnDurationText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), "")
            {
                ToolTip = TextManager.Get("ServerSettingsRespawnDurationToolTip")
            };

            string respawnDurationLabel = TextManager.Get("ServerSettingsRespawnDuration") + " ";

            CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel);
            slider.ToolTip       = respawnDurationText.ToolTip;
            slider.UserData      = respawnDurationText;
            slider.Step          = 0.1f;
            slider.Range         = new Vector2(60.0f, 660.0f);
            slider.ScrollToValue = (GUIScrollBar scrollBar, float barScroll) =>
            {
                return(barScroll >= 1.0f ? 0.0f : barScroll *(scrollBar.Range.Y - scrollBar.Range.X) + scrollBar.Range.X);
            };
            slider.ValueToScroll = (GUIScrollBar scrollBar, float value) =>
            {
                return(value <= 0.0f ? 1.0f : (value - scrollBar.Range.X) / (scrollBar.Range.Y - scrollBar.Range.X));
            };
            GetPropertyData("MaxTransportTime").AssignGUIComponent(slider);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                if (barScroll == 1.0f)
                {
                    ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + TextManager.Get("Unlimited");
                }
                else
                {
                    ((GUITextBlock)scrollBar.UserData).Text = respawnDurationLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue);
                }

                return(true);
            };
            slider.OnMoved(slider, slider.BarScroll);


            var ragdollButtonBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsAllowRagdollButton"));

            GetPropertyData("AllowRagdollButton").AssignGUIComponent(ragdollButtonBox);

            /*var traitorRatioBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), roundsTab.RectTransform), TextManager.Get("ServerSettingsUseTraitorRatio"));
             *
             * CreateLabeledSlider(roundsTab, "", out slider, out sliderLabel);
             * var traitorRatioSlider = slider;
             * traitorRatioBox.OnSelected = (GUITickBox) =>
             * {
             *  traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll);
             *  return true;
             * };
             *
             * if (TraitorUseRatio)
             * {
             *  traitorRatioSlider.Range = new Vector2(0.1f, 1.0f);
             * }
             * else
             * {
             *  traitorRatioSlider.Range = new Vector2(1.0f, maxPlayers);
             * }
             *
             * string traitorRatioLabel = TextManager.Get("ServerSettingsTraitorRatio") + " ";
             * string traitorCountLabel = TextManager.Get("ServerSettingsTraitorCount") + " ";
             *
             * traitorRatioSlider.Range = new Vector2(0.1f, 1.0f);
             * traitorRatioSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
             * {
             *  GUITextBlock traitorText = scrollBar.UserData as GUITextBlock;
             *  if (traitorRatioBox.Selected)
             *  {
             *      scrollBar.Step = 0.01f;
             *      scrollBar.Range = new Vector2(0.1f, 1.0f);
             *      traitorText.Text = traitorRatioLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 1.0f) + " %";
             *  }
             *  else
             *  {
             *      scrollBar.Step = 1f / (maxPlayers - 1);
             *      scrollBar.Range = new Vector2(1.0f, maxPlayers);
             *      traitorText.Text = traitorCountLabel + scrollBar.BarScrollValue;
             *  }
             *  return true;
             * };
             *
             * GetPropertyData("TraitorUseRatio").AssignGUIComponent(traitorRatioBox);
             * GetPropertyData("TraitorRatio").AssignGUIComponent(traitorRatioSlider);
             *
             * traitorRatioSlider.OnMoved(traitorRatioSlider, traitorRatioSlider.BarScroll);
             * traitorRatioBox.OnSelected(traitorRatioBox);*/

            var buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), roundsTab.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            var monsterButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform),
                                              TextManager.Get("ServerSettingsMonsterSpawns"))
            {
                Enabled = !GameMain.NetworkMember.GameStarted
            };
            var monsterFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomLeft, Pivot.BottomRight))
            {
                Visible = false
            };

            monsterButton.UserData  = monsterFrame;
            monsterButton.OnClicked = (button, obj) =>
            {
                if (GameMain.NetworkMember.GameStarted)
                {
                    ((GUIComponent)obj).Visible = false;
                    button.Enabled = false;
                    return(true);
                }
                ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
                return(true);
            };

            InitMonstersEnabled();
            List <string> monsterNames = MonsterEnabled.Keys.ToList();

            tempMonsterEnabled = new Dictionary <string, bool>(MonsterEnabled);
            foreach (string s in monsterNames)
            {
                string translatedLabel   = TextManager.Get($"Character.{s}", true);
                var    monsterEnabledBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.1f), monsterFrame.Content.RectTransform)
                {
                    MinSize = new Point(0, 25)
                },
                                                          label: translatedLabel ?? s)
                {
                    Selected   = tempMonsterEnabled[s],
                    OnSelected = (GUITickBox tb) =>
                    {
                        tempMonsterEnabled[s] = tb.Selected;
                        return(true);
                    }
                };
            }

            var cargoButton = new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), buttonHolder.RectTransform),
                                            TextManager.Get("ServerSettingsAdditionalCargo"))
            {
                Enabled = !GameMain.NetworkMember.GameStarted
            };
            var cargoFrame = new GUIListBox(new RectTransform(new Vector2(0.6f, 0.7f), settingsTabs[(int)SettingsTab.Rounds].RectTransform, Anchor.BottomRight, Pivot.BottomLeft))
            {
                Visible = false
            };

            cargoButton.UserData  = cargoFrame;
            cargoButton.OnClicked = (button, obj) =>
            {
                if (GameMain.NetworkMember.GameStarted)
                {
                    ((GUIComponent)obj).Visible = false;
                    button.Enabled = false;
                    return(true);
                }
                ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible;
                return(true);
            };

            GUITextBlock.AutoScaleAndNormalize(buttonHolder.Children.Select(c => ((GUIButton)c).TextBlock));

            foreach (ItemPrefab ip in MapEntityPrefab.List.Where(p => p is ItemPrefab).Select(p => p as ItemPrefab))
            {
                if (!ip.CanBeBought && !ip.Tags.Contains("smallitem"))
                {
                    continue;
                }

                var itemFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.15f), cargoFrame.Content.RectTransform)
                {
                    MinSize = new Point(0, 30)
                }, isHorizontal: true)
                {
                    Stretch         = true,
                    UserData        = cargoFrame,
                    RelativeSpacing = 0.05f
                };


                if (ip.InventoryIcon != null || ip.sprite != null)
                {
                    GUIImage img = new GUIImage(new RectTransform(new Point(itemFrame.Rect.Height), itemFrame.RectTransform),
                                                ip.InventoryIcon ?? ip.sprite, scaleToFit: true)
                    {
                        CanBeFocused = false
                    };
                    img.Color = img.Sprite == ip.InventoryIcon ? ip.InventoryIconColor : ip.SpriteColor;
                }

                new GUITextBlock(new RectTransform(new Vector2(0.75f, 1.0f), itemFrame.RectTransform),
                                 ip.Name, font: GUI.SmallFont)
                {
                    Wrap         = true,
                    CanBeFocused = false
                };

                ExtraCargo.TryGetValue(ip, out int cargoVal);
                var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.35f, 1.0f), itemFrame.RectTransform),
                                                     GUINumberInput.NumberType.Int, textAlignment: Alignment.CenterLeft)
                {
                    MinValueInt = 0,
                    MaxValueInt = 100,
                    IntValue    = cargoVal
                };
                amountInput.OnValueChanged += (numberInput) =>
                {
                    if (ExtraCargo.ContainsKey(ip))
                    {
                        ExtraCargo[ip] = numberInput.IntValue;
                        if (numberInput.IntValue <= 0)
                        {
                            ExtraCargo.Remove(ip);
                        }
                    }
                    else
                    {
                        ExtraCargo.Add(ip, numberInput.IntValue);
                    }
                };
            }


            //--------------------------------------------------------------------------------
            //                              antigriefing
            //--------------------------------------------------------------------------------

            var antigriefingTab = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), settingsTabs[(int)SettingsTab.Antigriefing].RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var voteKickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsAllowVoteKick"));

            GetPropertyData("AllowVoteKick").AssignGUIComponent(voteKickBox);

            CreateLabeledSlider(antigriefingTab, "ServerSettingsKickVotesRequired", out slider, out sliderLabel);
            string votesRequiredLabel = sliderLabel.Text + " ";

            slider.Step    = 0.2f;
            slider.Range   = new Vector2(0.5f, 1.0f);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                ((GUITextBlock)scrollBar.UserData).Text = votesRequiredLabel + (int)MathUtils.Round(scrollBar.BarScrollValue * 100.0f, 10.0f) + " %";
                return(true);
            };
            GetPropertyData("KickVoteRequiredRatio").AssignGUIComponent(slider);
            slider.OnMoved(slider, slider.BarScroll);

            CreateLabeledSlider(antigriefingTab, "ServerSettingsAutobanTime", out slider, out sliderLabel);
            string autobanLabel = sliderLabel.Text + " ";

            slider.Step    = 0.01f;
            slider.Range   = new Vector2(0.0f, MaxAutoBanTime);
            slider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                ((GUITextBlock)scrollBar.UserData).Text = autobanLabel + ToolBox.SecondsToReadableTime(scrollBar.BarScrollValue);
                return(true);
            };
            GetPropertyData("AutoBanTime").AssignGUIComponent(slider);
            slider.OnMoved(slider, slider.BarScroll);

            // karma --------------------------------------------------------------------------

            var karmaBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform), TextManager.Get("ServerSettingsUseKarma"));

            GetPropertyData("KarmaEnabled").AssignGUIComponent(karmaBox);

            karmaPresetDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.05f), antigriefingTab.RectTransform));
            foreach (string karmaPreset in GameMain.NetworkMember.KarmaManager.Presets.Keys)
            {
                karmaPresetDD.AddItem(TextManager.Get("KarmaPreset." + karmaPreset), karmaPreset);
            }

            var karmaSettingsContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.5f), antigriefingTab.RectTransform), style: null);
            var karmaSettingsList      = new GUIListBox(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform));

            karmaSettingsBlocker = new GUIFrame(new RectTransform(Vector2.One, karmaSettingsContainer.RectTransform, Anchor.CenterLeft)
            {
                MaxSize = new Point(karmaSettingsList.Content.Rect.Width, int.MaxValue)
            },
                                                style: "InnerFrame");
            karmaPresetDD.SelectItem(KarmaPreset);
            karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom";
            GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content);
            karmaPresetDD.OnSelected = (selected, obj) =>
            {
                string newKarmaPreset = obj as string;
                if (newKarmaPreset == KarmaPreset)
                {
                    return(true);
                }

                List <NetPropertyData> properties = netProperties.Values.ToList();
                List <object>          prevValues = new List <object>();
                foreach (NetPropertyData prop in netProperties.Values)
                {
                    prevValues.Add(prop.TempValue);
                    if (prop.GUIComponent != null)
                    {
                        prop.Value = prop.GUIComponentValue;
                    }
                }
                if (KarmaPreset == "custom")
                {
                    GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset();
                    GameMain.NetworkMember?.KarmaManager?.Save();
                }
                KarmaPreset = newKarmaPreset;
                GameMain.NetworkMember.KarmaManager.SelectPreset(KarmaPreset);
                karmaSettingsList.Content.ClearChildren();
                karmaSettingsBlocker.Visible = !karmaBox.Selected || KarmaPreset != "custom";
                GameMain.NetworkMember.KarmaManager.CreateSettingsFrame(karmaSettingsList.Content);
                for (int i = 0; i < netProperties.Count; i++)
                {
                    properties[i].TempValue = prevValues[i];
                }
                return(true);
            };
            AssignGUIComponent("KarmaPreset", karmaPresetDD);
            karmaBox.OnSelected = (tb) =>
            {
                karmaSettingsBlocker.Visible = !tb.Selected || KarmaPreset != "custom";
                return(true);
            };

            //--------------------------------------------------------------------------------
            //                              banlist
            //--------------------------------------------------------------------------------

            BanList.CreateBanFrame(settingsTabs[(int)SettingsTab.Banlist]);

            //--------------------------------------------------------------------------------
            //                              whitelist
            //--------------------------------------------------------------------------------

            Whitelist.CreateWhiteListFrame(settingsTabs[(int)SettingsTab.Whitelist]);
        }
Пример #24
0
        partial void InitProjSpecific(XElement element)
        {
            sonarBlips = new List <SonarBlip>();

            int viewSize = (int)Math.Min(GuiFrame.Rect.Width - 150, GuiFrame.Rect.Height * 0.9f);

            sonarView = new GUICustomComponent(new RectTransform(new Point(viewSize), GuiFrame.RectTransform, Anchor.CenterLeft),
                                               (spriteBatch, guiCustomComponent) => { DrawSonar(spriteBatch, guiCustomComponent.Rect); }, null);

            var controlContainer = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.35f), GuiFrame.RectTransform, Anchor.TopLeft)
            {
                MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0)
            }, "SonarFrame");

            controlContainer.RectTransform.SetAsFirstChild();

            var paddedControlContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), controlContainer.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            passiveTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.2f), paddedControlContainer.RectTransform), TextManager.Get("SonarPassive"), style: "GUIRadioButton")
            {
                ToolTip  = TextManager.Get("SonarTipPassive"),
                Selected = true
            };

            activeTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.2f), paddedControlContainer.RectTransform), TextManager.Get("SonarActive"), style: "GUIRadioButton")
            {
                ToolTip    = TextManager.Get("SonarTipActive"),
                OnSelected = (GUITickBox box) =>
                {
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                    }
                    else if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
                    IsActive = box.Selected;

                    return(true);
                }
            };

            var zoomContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedControlContainer.RectTransform), isHorizontal: true);

            new GUITextBlock(new RectTransform(new Vector2(0.35f, 1.0f), zoomContainer.RectTransform), TextManager.Get("SonarZoom"), font: GUI.SmallFont)
            {
                Padding = Vector4.Zero
            };
            zoomSlider = new GUIScrollBar(new RectTransform(new Vector2(0.65f, 1.0f), zoomContainer.RectTransform), barSize: 0.1f, isHorizontal: true)
            {
                OnMoved = (scrollbar, scroll) =>
                {
                    zoom = MathHelper.Lerp(MinZoom, MaxZoom, scroll);
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                    }
                    else if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
                    return(true);
                }
            };

            var activeControls = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.6f), paddedControlContainer.RectTransform)
            {
                RelativeOffset = new Vector2(0.1f, 0.0f)
            }, "InnerFrame");

            activeControlsContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), activeControls.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.03f,
                Stretch         = true
            };

            directionalTickBox = new GUITickBox(new RectTransform(new Vector2(0.3f, 0.3f), activeControlsContainer.RectTransform), TextManager.Get("SonarDirectionalPing"))
            {
                OnSelected = (tickBox) =>
                {
                    useDirectionalPing = tickBox.Selected;
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                    }
                    else if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
                    return(true);
                }
            };
            directionalSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.3f), activeControlsContainer.RectTransform), barSize: 0.1f, isHorizontal: true)
            {
                OnMoved = (scrollbar, scroll) =>
                {
                    float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, scroll);
                    pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                    }
                    else if (GameMain.Client != null)
                    {
                        item.CreateClientEvent(this);
                        correctionTimer = CorrectionDelay;
                    }
                    return(true);
                }
            };

            signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedControlContainer.RectTransform), "", Color.Orange, textAlignment: Alignment.Center);

            GUITickBox.CreateRadioButtonGroup(new List <GUITickBox>()
            {
                activeTickBox, passiveTickBox
            });

            GuiFrame.CanBeFocused = false;
        }
Пример #25
0
		private static void LayoutSingleGroup(GUILayoutGroup i){}
Пример #26
0
        partial void InitProjSpecific(XElement element)
        {
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "pumpoutemitter":
                    pumpOutEmitters.Add(new Pair <Vector2, ParticleEmitter>(
                                            subElement.GetAttributeVector2("position", Vector2.Zero),
                                            new ParticleEmitter(subElement)));
                    break;

                case "pumpinemitter":
                    pumpInEmitters.Add(new Pair <Vector2, ParticleEmitter>(
                                           subElement.GetAttributeVector2("position", Vector2.Zero),
                                           new ParticleEmitter(subElement)));
                    break;
                }
            }

            GUIFrame paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.8f), GuiFrame.RectTransform, Anchor.Center), style: null);

            isActiveSlider = new GUIScrollBar(new RectTransform(new Point(50, 100), paddedFrame.RectTransform, Anchor.CenterLeft),
                                              barSize: 0.2f, style: "OnOffLever")
            {
                IsBooleanSwitch = true,
                MinValue        = 0.25f,
                MaxValue        = 0.75f
            };
            var sliderHandle = isActiveSlider.GetChild <GUIButton>();

            sliderHandle.RectTransform.NonScaledSize = new Point(84, sliderHandle.Rect.Height);

            isActiveSlider.OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
            {
                bool active = scrollBar.BarScroll < 0.5f;
                if (active == IsActive)
                {
                    return(false);
                }

                targetLevel = null;
                IsActive    = active;
                if (!IsActive)
                {
                    currPowerConsumption = 0.0f;
                }

                if (GameMain.Server != null)
                {
                    item.CreateServerEvent(this);
                    GameServer.Log(Character.Controlled.LogName + (IsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
                }
                else if (GameMain.Client != null)
                {
                    correctionTimer = CorrectionDelay;
                    item.CreateClientEvent(this);
                }

                return(true);
            };

            var rightArea = new GUILayoutGroup(new RectTransform(new Vector2(0.75f, 1.0f), paddedFrame.RectTransform, Anchor.CenterRight))
            {
                RelativeSpacing = 0.1f
            };

            powerIndicator = new GUITickBox(new RectTransform(new Point(30, 30), rightArea.RectTransform), TextManager.Get("PumpPowered"), style: "IndicatorLightGreen")
            {
                CanBeFocused = false
            };

            var pumpSpeedText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), rightArea.RectTransform)
            {
                RelativeOffset = new Vector2(0.25f, 0.0f)
            },
                                                 "", textAlignment: Alignment.BottomLeft);
            string pumpSpeedStr = TextManager.Get("PumpSpeed");

            pumpSpeedText.TextGetter = () => { return(pumpSpeedStr + ": " + (int)flowPercentage + " %"); };

            var sliderArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.3f), rightArea.RectTransform, Anchor.CenterLeft), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform),
                             TextManager.Get("PumpOut"), textAlignment: Alignment.Center);
            pumpSpeedSlider = new GUIScrollBar(new RectTransform(new Vector2(0.8f, 1.0f), sliderArea.RectTransform), barSize: 0.25f, style: "GUISlider")
            {
                Step    = 0.05f,
                OnMoved = (GUIScrollBar scrollBar, float barScroll) =>
                {
                    float newValue = barScroll * 200.0f - 100.0f;
                    if (Math.Abs(newValue - FlowPercentage) < 0.1f)
                    {
                        return(false);
                    }

                    FlowPercentage = newValue;
                    if (GameMain.Server != null)
                    {
                        item.CreateServerEvent(this);
                        GameServer.Log(Character.Controlled.LogName + " set the pumping speed of " + item.Name + " to " + (int)(flowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
                    }
                    else if (GameMain.Client != null)
                    {
                        correctionTimer = CorrectionDelay;
                        item.CreateClientEvent(this);
                    }
                    return(true);
                }
            };

            new GUITextBlock(new RectTransform(new Vector2(0.15f, 1.0f), sliderArea.RectTransform),
                             TextManager.Get("PumpIn"), textAlignment: Alignment.Center);
        }