Пример #1
0
        public GUINumberInput(Rectangle rect, string style, Alignment alignment, int?minValue = null, int?maxValue = null, GUIComponent parent = null)
            : base(style)
        {
            this.rect = rect;

            this.alignment = alignment;

            if (parent != null)
            {
                parent.AddChild(this);
            }

            textBox = new GUITextBox(Rectangle.Empty, style, this);

            textBox.OnTextChanged += TextChanged;

            plusButton             = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", null, Alignment.TopRight, Alignment.Center, style, this);
            plusButton.OnClicked  += ChangeValue;
            minusButton            = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", null, Alignment.BottomRight, Alignment.Center, style, this);
            minusButton.OnClicked += ChangeValue;

            MinValue = minValue;
            MaxValue = maxValue;

            value = int.MaxValue;
            Value = minValue != null ? (int)minValue : 0;
        }
Пример #2
0
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            int width = 450;
            int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;

            editingHUD          = new GUIFrame(new Rectangle(x, y, width, 100), "");
            editingHUD.Padding  = new Vector4(10, 10, 0, 0);
            editingHUD.UserData = this;

            new GUITextBlock(new Rectangle(0, 0, 100, 20), "Linked submarine", "",
                             Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);

            var pathBox = new GUITextBox(new Rectangle(10, 30, 300, 20), "", editingHUD);

            pathBox.Font = GUI.SmallFont;
            pathBox.Text = filePath;

            var reloadButton = new GUIButton(new Rectangle(320, 30, 80, 20), "Refresh", "", editingHUD);

            reloadButton.OnClicked = Reload;
            reloadButton.UserData  = pathBox;

            reloadButton.ToolTip = "Reload the linked submarine from the specified file";

            y += 20;

            if (!inGame)
            {
                new GUITextBlock(new Rectangle(0, 0, 0, 20), "Hold space to link to a docking port",
                                 "", Alignment.TopRight, Alignment.TopRight, editingHUD, false, GUI.SmallFont);
                y += 25;
            }
            return(editingHUD);
        }
Пример #3
0
        public ChatBox(GUIComponent parent, bool isSinglePlayer)
        {
            this.isSinglePlayer = isSinglePlayer;
            if (radioIcon == null)
            {
                radioIcon        = new Sprite("Content/UI/inventoryAtlas.png", new Rectangle(527, 952, 38, 52), null);
                radioIcon.Origin = radioIcon.size / 2;
            }

            screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);

            int toggleButtonWidth = (int)(30 * GUI.Scale);

            guiFrame     = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.ChatBoxArea, parent.RectTransform), style: null);
            chatBox      = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.9f), guiFrame.RectTransform), style: "ChatBox");
            toggleButton = new GUIButton(new RectTransform(new Point(toggleButtonWidth, HUDLayoutSettings.ChatBoxArea.Height), parent.RectTransform),
                                         style: "UIToggleButton");

            toggleButton.OnClicked += (GUIButton btn, object userdata) =>
            {
                toggleOpen = !toggleOpen;
                foreach (GUIComponent child in btn.Children)
                {
                    child.SpriteEffects = toggleOpen == (HUDLayoutSettings.ChatBoxAlignment == Alignment.Right) ?
                                          SpriteEffects.FlipHorizontally : SpriteEffects.None;
                }
                return(true);
            };

            inputBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), guiFrame.RectTransform, Anchor.BottomCenter),
                                      style: "ChatTextBox")
            {
                Font          = GUI.SmallFont,
                MaxTextLength = ChatMessage.MaxLength
            };

            radioButton = new GUIButton(new RectTransform(new Vector2(0.1f, 2.0f), inputBox.RectTransform,
                                                          HUDLayoutSettings.ChatBoxAlignment == Alignment.Right ? Anchor.BottomRight : Anchor.BottomLeft,
                                                          HUDLayoutSettings.ChatBoxAlignment == Alignment.Right ? Pivot.TopRight : Pivot.TopLeft),
                                        style: null);
            new GUIImage(new RectTransform(Vector2.One, radioButton.RectTransform), radioIcon, scaleToFit: true);
            radioButton.OnClicked = (GUIButton btn, object userData) =>
            {
                if (inputBox.Selected)
                {
                    inputBox.Text = "";
                    inputBox.Deselect();
                }
                else
                {
                    inputBox.Select();
                    var radioItem = Character.Controlled?.Inventory?.Items.FirstOrDefault(i => i?.GetComponent <WifiComponent>() != null);
                    if (radioItem != null && Character.Controlled.HasEquippedItem(radioItem) && radioItem.GetComponent <WifiComponent>().CanTransmit())
                    {
                        inputBox.Text = "r; ";
                    }
                }
                return(true);
            };
        }
Пример #4
0
        public static void Init(GameWindow window)
        {
            int x = 20, y = 20;
            int width = 800, height = 500;

            frame         = new GUIFrame(new Rectangle(x, y, width, height), new Color(0.4f, 0.4f, 0.4f, 0.8f));
            frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);

            listBox = new GUIListBox(new Rectangle(0, 0, 0, frame.Rect.Height - 40), Color.Black, "", frame);
            //listBox.Color = Color.Black * 0.7f;

            textBox = new GUITextBox(new Rectangle(0, 0, 0, 20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, "", frame);
            //textBox.Color = Color.Black * 0.7f;

            //messages already added before initialization -> add them to the listbox
            List <ColoredText> unInitializedMessages = new List <ColoredText>(Messages);

            Messages.Clear();

            foreach (ColoredText msg in unInitializedMessages)
            {
                NewMessage(msg.Text, msg.Color);
            }

            NewMessage("Press F3 to open/close the debug console", Color.Cyan);
            NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
        }
Пример #5
0
        public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer)
        {
            this.isMultiplayer     = isMultiplayer;
            this.newGameContainer  = newGameContainer;
            this.loadGameContainer = loadGameContainer;

            new GUITextBlock(new Rectangle(0, 0, 0, 30), "Selected submarine:", null, null, Alignment.Left, "", newGameContainer);
            subList = new GUIListBox(new Rectangle(0, 30, 230, newGameContainer.Rect.Height - 100), "", newGameContainer);

            UpdateSubList();

            new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 0, 100, 20),
                             "Save name: ", "", Alignment.Left, Alignment.Left, newGameContainer);

            saveNameBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 30, 180, 20),
                                         Alignment.TopLeft, "", newGameContainer);

            new GUITextBlock(new Rectangle((int)(subList.Rect.Width + 20), 60, 100, 20),
                             "Map Seed: ", "", Alignment.Left, Alignment.Left, newGameContainer);

            seedBox = new GUITextBox(new Rectangle((int)(subList.Rect.Width + 30), 90, 180, 20),
                                     Alignment.TopLeft, "", newGameContainer);
            seedBox.Text = ToolBox.RandomSeed(8);

            var startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, "", newGameContainer);

            startButton.OnClicked = (GUIButton btn, object userData) =>
            {
                if (string.IsNullOrWhiteSpace(saveNameBox.Text))
                {
                    saveNameBox.Flash(Color.Red);
                    return(false);
                }

                Submarine selectedSub = subList.SelectedData as Submarine;
                if (selectedSub != null && selectedSub.HasTag(SubmarineTag.Shuttle))
                {
                    var msgBox = new GUIMessageBox("Shuttle selected",
                                                   "Most shuttles are not adequately equipped to deal with the dangers of the Europan depths. " +
                                                   "Are you sure you want to choose a shuttle as your vessel?",
                                                   new string[] { "Yes", "No" });

                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    msgBox.Buttons[0].OnClicked  = (button, obj) => { StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text); return(true); };
                    msgBox.Buttons[0].OnClicked += msgBox.Close;

                    msgBox.Buttons[1].OnClicked = msgBox.Close;
                    return(false);
                }
                else
                {
                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                }

                return(true);
            };

            UpdateLoadMenu();
        }
Пример #6
0
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            int width = 450;
            int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;

            editingHUD          = new GUIFrame(new Rectangle(x, y, width, 100), "");
            editingHUD.Padding  = new Vector4(10, 10, 0, 0);
            editingHUD.UserData = this;

            new GUITextBlock(new Rectangle(0, 0, 100, 20), TextManager.Get("LinkedSub"), "",
                             Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);

            var pathBox = new GUITextBox(new Rectangle(10, 30, 300, 20), "", editingHUD);

            pathBox.Font = GUI.SmallFont;
            pathBox.Text = filePath;

            var reloadButton = new GUIButton(new Rectangle(320, 30, 80, 20), TextManager.Get("ReloadLinkedSub"), "", editingHUD);

            reloadButton.OnClicked = Reload;
            reloadButton.UserData  = pathBox;
            reloadButton.ToolTip   = TextManager.Get("ReloadLinkedSubTooltip");

            y += 20;

            if (!inGame)
            {
                new GUITextBlock(new Rectangle(0, 0, 0, 20), TextManager.Get("LinkLinkedSub"),
                                 "", Alignment.TopRight, Alignment.TopRight, editingHUD, false, GUI.SmallFont);
                y += 25;
            }
            return(editingHUD);
        }
Пример #7
0
        private bool TextChanged(GUITextBox textBox, string text)
        {
            switch (InputType)
            {
            case NumberType.Int:
                int newIntValue = IntValue;
                if (string.IsNullOrWhiteSpace(text) || text == "-")
                {
                    intValue = 0;
                }
                else if (int.TryParse(text, out newIntValue))
                {
                    intValue = newIntValue;
                }
                ClampIntValue();
                break;

            case NumberType.Float:
                float newFloatValue = FloatValue;
                if (string.IsNullOrWhiteSpace(text) || text == "-")
                {
                    floatValue = 0;
                }
                else if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out newFloatValue))
                {
                    floatValue = newFloatValue;
                }
                ClampFloatValue();
                break;
            }
            OnValueChanged?.Invoke(this);
            return(true);
        }
Пример #8
0
        private GUIComponent CreateStringField(ISerializableEntity entity, SerializableProperty property, string value, int yPos, GUIComponent parent)
        {
            int boxHeight = 18;
            var editable  = property.GetAttribute <Editable>();

            boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * boxHeight);

            var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);

            label.ToolTip = property.GetAttribute <Editable>().ToolTip;
            GUITextBox propertyBox = new GUITextBox(new Rectangle(0, yPos, 250, boxHeight), Alignment.Right, "", parent);

            propertyBox.ToolTip = editable.ToolTip;
            propertyBox.Font    = GUI.SmallFont;

            propertyBox.Text           = value;
            propertyBox.OnEnterPressed = (textBox, text) =>
            {
                if (property.TrySetValue(text))
                {
                    TrySendNetworkUpdate(entity, property);
                    textBox.Text = (string)property.GetValue();
                    textBox.Deselect();
                }
                return(true);
            };

            return(propertyBox);
        }
Пример #9
0
        private bool FilterMessages(GUITextBox textBox, string text)
        {
            if (selectedTab == -1)
            {
                GUIComponent.KeyboardDispatcher.Subscriber = null;
                return(false);
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                GUItabs[selectedTab].GetChild <GUIListBox>().children.ForEach(c => c.Visible = true);
                return(true);
            }

            text = text.ToLower();

            foreach (GUIComponent child in GUItabs[selectedTab].GetChild <GUIListBox>().children)
            {
                var textBlock = child.GetChild <GUITextBlock>();
                child.Visible = textBlock.Text.ToLower().Contains(text);
            }

            GUItabs[selectedTab].GetChild <GUIListBox>().BarScroll = 0.0f;

            return(true);
        }
Пример #10
0
        public static void Init()
        {
            frame = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.45f), GUI.Canvas)
            {
                MinSize = new Point(400, 300), AbsoluteOffset = new Point(10, 10)
            },
                                 color: new Color(0.4f, 0.4f, 0.4f, 0.8f));
            var paddedFrame = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), frame.RectTransform, Anchor.Center), style: null);

            listBox = new GUIListBox(new RectTransform(new Point(paddedFrame.Rect.Width, paddedFrame.Rect.Height - 30), paddedFrame.RectTransform)
            {
                IsFixedSize = false
            }, color: Color.Black * 0.9f);

            textBox = new GUITextBox(new RectTransform(new Point(paddedFrame.Rect.Width, 20), paddedFrame.RectTransform, Anchor.BottomLeft)
            {
                IsFixedSize = false
            });
            textBox.OnKeyHit += (sender, key) =>
            {
                if (key != Keys.Tab)
                {
                    ResetAutoComplete();
                }
            };

            NewMessage("Press F3 to open/close the debug console", Color.Cyan);
            NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
        }
Пример #11
0
 private bool EnterIDCardTags(GUITextBox textBox, string text)
 {
     IdCardTags   = text.Split(',');
     textBox.Text = string.Join(",", IdCardTags);
     textBox.Flash(Color.Green);
     textBox.Deselect();
     return(true);
 }
Пример #12
0
 private bool EnterTags(GUITextBox textBox, string text)
 {
     tags         = text.Split(',').ToList();
     textBox.Text = string.Join(",", Tags);
     textBox.Flash(GUI.Style.Green);
     textBox.Deselect();
     return(true);
 }
Пример #13
0
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            int width = 500;
            int height = spawnType == SpawnType.Path ? 100 : 140;
            int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;

            editingHUD          = new GUIFrame(new Rectangle(x, y, width, height), Color.Black * 0.5f);
            editingHUD.Padding  = new Vector4(10, 10, 0, 0);
            editingHUD.UserData = this;

            if (spawnType == SpawnType.Path)
            {
                new GUITextBlock(new Rectangle(0, 0, 100, 20), "Editing waypoint", "", editingHUD);
                new GUITextBlock(new Rectangle(0, 20, 100, 20), "Hold space to link to another waypoint", "", editingHUD);
            }
            else
            {
                new GUITextBlock(new Rectangle(0, 0, 100, 20), "Editing spawnpoint", "", editingHUD);
                new GUITextBlock(new Rectangle(0, 25, 100, 20), "Spawn type: ", "", editingHUD);

                var spawnTypeText = new GUITextBlock(new Rectangle(0, 25, 200, 20), spawnType.ToString(), "", Alignment.Right, Alignment.TopLeft, editingHUD);

                var button = new GUIButton(new Rectangle(-30, 0, 20, 20), "-", Alignment.Right, "", spawnTypeText);
                button.UserData  = -1;
                button.OnClicked = ChangeSpawnType;

                button           = new GUIButton(new Rectangle(0, 0, 20, 20), "+", Alignment.Right, "", spawnTypeText);
                button.UserData  = 1;
                button.OnClicked = ChangeSpawnType;

                y = 40 + 20;

                new GUITextBlock(new Rectangle(0, y, 100, 20), "ID Card tags:", Color.Transparent, Color.White, Alignment.TopLeft, null, editingHUD);
                GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), "", editingHUD);
                propertyBox.Text           = string.Join(", ", idCardTags);
                propertyBox.OnEnterPressed = EnterIDCardTags;
                propertyBox.OnTextChanged  = TextBoxChanged;
                propertyBox.ToolTip        = "Characters spawning at this spawnpoint will have the specified tags added to their ID card. You can, for example, use these tags to limit access to some parts of the sub.";

                y = y + 30;

                new GUITextBlock(new Rectangle(0, y, 100, 20), "Assigned job:", Color.Transparent, Color.White, Alignment.TopLeft, null, editingHUD);
                propertyBox                = new GUITextBox(new Rectangle(100, y, 200, 20), "", editingHUD);
                propertyBox.Text           = (assignedJob == null) ? "None" : assignedJob.Name;
                propertyBox.OnEnterPressed = EnterAssignedJob;
                propertyBox.OnTextChanged  = TextBoxChanged;
                propertyBox.ToolTip        = "Only characters with the specified job will spawn at this spawnpoint.";
            }



            //GUI.Font.DrawString(spriteBatch, "Spawnpoint: " + spawnType.ToString() + " +/-", new Vector2(x, y + 40), Color.Black);


            y = y + 30;

            return(editingHUD);
        }
Пример #14
0
        private bool EnterIDCardTags(GUITextBox textBox, string text)
        {
            IdCardTags    = text.Split(',');
            textBox.Text  = text;
            textBox.Color = Color.Green;

            textBox.Deselect();

            return(true);
        }
Пример #15
0
        private bool EnterIDCardDesc(GUITextBox textBox, string text)
        {
            IdCardDesc    = text;
            textBox.Text  = text;
            textBox.Color = Color.Green;

            textBox.Deselect();

            return(true);
        }
Пример #16
0
        public ServerListScreen()
        {
            int width  = Math.Min(GameMain.GraphicsWidth - 160, 1000);
            int height = Math.Min(GameMain.GraphicsHeight - 160, 700);

            Rectangle panelRect = new Rectangle(0, 0, width, height);

            menu         = new GUIFrame(panelRect, null, Alignment.Center, "");
            menu.Padding = new Vector4(40.0f, 40.0f, 40.0f, 20.0f);

            new GUITextBlock(new Rectangle(0, -25, 0, 30), "Join Server", "", Alignment.CenterX, Alignment.CenterX, menu, false, GUI.LargeFont);

            new GUITextBlock(new Rectangle(0, 30, 0, 30), "Your Name:", "", menu);
            clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), "", menu);

            new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", "", menu);
            ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), "", menu);

            int middleX = (int)(width * 0.4f);

            serverList            = new GUIListBox(new Rectangle(middleX, 60, 0, height - 160), "", menu);
            serverList.OnSelected = SelectServer;

            float[] columnRelativeX = new float[] { 0.15f, 0.5f, 0.15f, 0.2f };
            columnX = new int[columnRelativeX.Length];
            for (int n = 0; n < columnX.Length; n++)
            {
                columnX[n] = (int)(columnRelativeX[n] * serverList.Rect.Width);
                if (n > 0)
                {
                    columnX[n] += columnX[n - 1];
                }
            }

            ScalableFont font = GUI.SmallFont; // serverList.Rect.Width < 400 ? GUI.SmallFont : GUI.Font;

            new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Password", "", menu).Font = font;

            new GUITextBlock(new Rectangle(middleX + columnX[0], 30, 0, 30), "Name", "", menu).Font          = font;
            new GUITextBlock(new Rectangle(middleX + columnX[1], 30, 0, 30), "Players", "", menu).Font       = font;
            new GUITextBlock(new Rectangle(middleX + columnX[2], 30, 0, 30), "Round started", "", menu).Font = font;

            joinButton           = new GUIButton(new Rectangle(-170, 0, 150, 30), "Refresh", Alignment.BottomRight, "", menu);
            joinButton.OnClicked = RefreshServers;

            joinButton           = new GUIButton(new Rectangle(0, 0, 150, 30), "Join", Alignment.BottomRight, "", menu);
            joinButton.OnClicked = JoinServer;

            GUIButton button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, "", menu);

            button.OnClicked     = GameMain.MainMenuScreen.SelectTab;
            button.SelectedColor = button.Color;

            refreshDisableTimer = DateTime.Now;
        }
Пример #17
0
        private IEnumerable <object> WaitForKeyPress(GUITextBox keyBox)
        {
            yield return(CoroutineStatus.Running);

            while (PlayerInput.LeftButtonHeld() || PlayerInput.LeftButtonClicked())
            {
                //wait for the mouse to be released, so that we don't interpret clicking on the textbox as the keybinding
                yield return(CoroutineStatus.Running);
            }
            while (keyBox.Selected && PlayerInput.GetKeyboardState.GetPressedKeys().Length == 0 &&
                   !PlayerInput.LeftButtonClicked() && !PlayerInput.RightButtonClicked() && !PlayerInput.MidButtonClicked())
            {
                if (Screen.Selected != GameMain.MainMenuScreen && !GUI.SettingsMenuOpen)
                {
                    yield return(CoroutineStatus.Success);
                }

                yield return(CoroutineStatus.Running);
            }

            UnsavedSettings = true;

            int keyIndex = (int)keyBox.UserData;

            if (PlayerInput.LeftButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(0);
                keyBox.Text          = "Mouse1";
            }
            else if (PlayerInput.RightButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(1);
                keyBox.Text          = "Mouse2";
            }
            else if (PlayerInput.MidButtonClicked())
            {
                keyMapping[keyIndex] = new KeyOrMouse(2);
                keyBox.Text          = "Mouse3";
            }
            else if (PlayerInput.GetKeyboardState.GetPressedKeys().Length > 0)
            {
                Keys key = PlayerInput.GetKeyboardState.GetPressedKeys()[0];
                keyMapping[keyIndex] = new KeyOrMouse(key);
                keyBox.Text          = key.ToString("G");
            }
            else
            {
                yield return(CoroutineStatus.Success);
            }

            keyBox.Deselect();

            yield return(CoroutineStatus.Success);
        }
Пример #18
0
        public GUINumberInput(Rectangle rect, string style, NumberType inputType, Alignment alignment, GUIComponent parent = null)
            : base(style)
        {
            this.rect = rect;

            this.alignment = alignment;

            if (parent != null)
            {
                parent.AddChild(this);
            }

            textBox = new GUITextBox(Rectangle.Empty, style, this);
            textBox.OnTextChanged += TextChanged;

            plusButton             = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "+", null, Alignment.TopRight, Alignment.Center, style, this);
            plusButton.OnClicked  += ChangeIntValue;
            plusButton.Visible     = inputType == NumberType.Int;
            minusButton            = new GUIButton(new Rectangle(0, 0, 15, rect.Height / 2), "-", null, Alignment.BottomRight, Alignment.Center, style, this);
            minusButton.OnClicked += ChangeIntValue;
            minusButton.Visible    = inputType == NumberType.Int;

            if (inputType == NumberType.Int)
            {
                textBox.Text            = "0";
                textBox.OnEnterPressed += (txtBox, txt) =>
                {
                    textBox.Text = IntValue.ToString();
                    textBox.Deselect();
                    return(true);
                };
                textBox.OnDeselected += (txtBox, key) =>
                {
                    textBox.Text = IntValue.ToString();
                };
            }
            else if (inputType == NumberType.Float)
            {
                textBox.Text          = "0.0";
                textBox.OnDeselected += (txtBox, key) =>
                {
                    textBox.Text = FloatValue.ToString("G", CultureInfo.InvariantCulture);
                };
                textBox.OnEnterPressed += (txtBox, txt) =>
                {
                    textBox.Text = FloatValue.ToString("G", CultureInfo.InvariantCulture);
                    textBox.Deselect();
                    return(true);
                };
            }

            InputType = inputType;
        }
Пример #19
0
        private bool CreateRenamingComponent(GUIButton button, object userData)
        {
            if (!HasPermission || !(userData is CharacterInfo characterInfo))
            {
                return(false);
            }
            var outerGlowFrame = new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), parentComponent.RectTransform, Anchor.Center),
                                              style: "OuterGlow", color: Color.Black * 0.7f);
            var frame = new GUIFrame(new RectTransform(new Vector2(0.33f, 0.4f), outerGlowFrame.RectTransform, anchor: Anchor.Center)
            {
                MaxSize = new Point(400, 300).Multiply(GUI.Scale)
            });
            var layoutGroup = new GUILayoutGroup(new RectTransform((frame.Rect.Size - GUIStyle.ItemFrameMargin).Multiply(new Vector2(0.75f, 1.0f)), frame.RectTransform, anchor: Anchor.Center), childAnchor: Anchor.TopCenter)
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), layoutGroup.RectTransform), TextManager.Get("campaigncrew.givenickname"), font: GUI.SubHeadingFont, textAlignment: Alignment.Center, wrap: true);
            var groupElementSize = new Vector2(1.0f, 0.25f);
            var nameBox          = new GUITextBox(new RectTransform(groupElementSize, layoutGroup.RectTransform))
            {
                MaxTextLength = Client.MaxNameLength
            };

            new GUIButton(new RectTransform(groupElementSize, layoutGroup.RectTransform), text: TextManager.Get("confirm"))
            {
                OnClicked = (button, userData) =>
                {
                    if (RenameCharacter(characterInfo, nameBox.Text?.Trim()))
                    {
                        parentComponent.RemoveChild(outerGlowFrame);
                        return(true);
                    }
                    else
                    {
                        nameBox.Flash(color: Color.Red);
                        return(false);
                    }
                }
            };
            new GUIButton(new RectTransform(groupElementSize, layoutGroup.RectTransform), text: TextManager.Get("cancel"))
            {
                OnClicked = (button, userData) =>
                {
                    parentComponent.RemoveChild(outerGlowFrame);
                    return(true);
                }
            };
            layoutGroup.Recalculate();
            return(true);
        }
Пример #20
0
        private bool SaveProjectToFile(GUIButton button, object o)
        {
            string directory = Path.GetFullPath("EventProjects");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var        msgBox    = new GUIMessageBox(TextManager.Get("EventEditor.NameFilePrompt"), "", new[] { TextManager.Get("Cancel"), TextManager.Get("Save") }, new Vector2(0.2f, 0.175f), minSize: new Point(300, 175));
            var        layout    = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.25f), msgBox.Content.RectTransform), isHorizontal: true);
            GUITextBox nameInput = new GUITextBox(new RectTransform(Vector2.One, layout.RectTransform))
            {
                Text = projectName
            };

            // Cancel button
            msgBox.Buttons[0].OnClicked = delegate
            {
                msgBox.Close();
                return(true);
            };

            // Ok button
            msgBox.Buttons[1].OnClicked = delegate
            {
                foreach (var illegalChar in Path.GetInvalidFileNameChars())
                {
                    if (!nameInput.Text.Contains(illegalChar))
                    {
                        continue;
                    }

                    GUI.AddMessage(TextManager.GetWithVariable("SubNameIllegalCharsWarning", "[illegalchar]", illegalChar.ToString()), GUI.Style.Red);
                    return(false);
                }

                msgBox.Close();
                projectName = nameInput.Text;
                XElement save     = SaveEvent(projectName);
                string   filePath = System.IO.Path.Combine(directory, $"{projectName}.sevproj");
                File.WriteAllText(Path.Combine(directory, $"{projectName}.sevproj"), save.ToString());
                GUI.AddMessage($"Project saved to {filePath}", GUI.Style.Green);

                AskForConfirmation(TextManager.Get("EventEditor.TestPromptHeader"), TextManager.Get("EventEditor.TestPromptBody"), CreateTestSetupMenu);
                return(true);
            };
            return(true);
        }
Пример #21
0
        private bool EnterAssignedJob(GUITextBox textBox, string text)
        {
            string trimmedName = text.ToLowerInvariant().Trim();

            assignedJob = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == trimmedName);

            if (assignedJob != null && trimmedName != TextManager.Get("None").ToLowerInvariant())
            {
                textBox.Color = Color.Green;
                textBox.Text  = (assignedJob == null) ? TextManager.Get("None") : assignedJob.Name;
            }

            textBox.Deselect();

            return(true);
        }
Пример #22
0
        private bool TextChanged(GUITextBox textBox, string text)
        {
            switch (InputType)
            {
            case NumberType.Int:
                int newIntValue = IntValue;
                if (text == "" || text == "-")
                {
                    IntValue     = 0;
                    textBox.Text = text;
                }
                else if (int.TryParse(text, out newIntValue))
                {
                    IntValue = newIntValue;
                }
                else
                {
                    textBox.Text = IntValue.ToString();
                }
                break;

            case NumberType.Float:
                float newFloatValue = FloatValue;

                text = new string(text.Where(c => char.IsDigit(c) || c == '.' || c == '-').ToArray());

                if (text == "" || text == "-")
                {
                    FloatValue   = 0;
                    textBox.Text = text;
                }
                else if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out newFloatValue))
                {
                    FloatValue   = newFloatValue;
                    textBox.Text = text;
                }

                /*else
                 * {
                 *  textBox.Text = FloatValue.ToString("G", CultureInfo.InvariantCulture);
                 * }*/
                break;
            }

            return(true);
        }
Пример #23
0
        public bool TypingChatMessage(GUITextBox textBox, string text)
        {
            string command = ChatMessage.GetChatMessageCommand(text, out _);

            if (IsSinglePlayer)
            {
                //radio is the only allowed special message type in single player
                if (command != "r" && command != "radio")
                {
                    command = "";
                }
            }

            switch (command)
            {
            case "r":
            case "radio":
                textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Radio];
                break;

            case "d":
            case "dead":
                textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Dead];
                break;

            default:
                if (Character.Controlled != null && (Character.Controlled.IsDead || Character.Controlled.SpeechImpediment >= 100.0f))
                {
                    textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Dead];
                }
                else if (command != "")     //PMing
                {
                    textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Private];
                }
                else
                {
                    textBox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Default];
                }
                break;
            }

            return(true);
        }
Пример #24
0
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            int width = 450, height = 120;
            int x = GameMain.GraphicsWidth / 2 - width / 2, y = 30;

            editingHUD = new GUIFrame(new RectTransform(new Point(width, height), GUI.Canvas)
            {
                ScreenSpaceOffset = new Point(x, y)
            })
            {
                UserData = this
            };

            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), editingHUD.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

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

            if (!inGame)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
                                 TextManager.Get("LinkLinkedSub"), textColor: Color.Yellow, font: GUI.SmallFont);
            }

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

            var pathBox      = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), pathContainer.RectTransform), filePath, font: GUI.SmallFont);
            var reloadButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), pathContainer.RectTransform), TextManager.Get("ReloadLinkedSub"))
            {
                OnClicked = Reload,
                UserData  = pathBox,
                ToolTip   = TextManager.Get("ReloadLinkedSubTooltip")
            };

            PositionEditingHUD();

            return(editingHUD);
        }
        private GUIComponent CreateEditingHUD(bool inGame = false)
        {
            editingHUD = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.25f), GUI.Canvas, Anchor.CenterRight)
            {
                MinSize = new Point(400, 0)
            })
            {
                UserData = this
            };
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.8f), editingHUD.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                AbsoluteSpacing = (int)(GUI.Scale * 5)
            };

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

            if (!inGame)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform),
                                 TextManager.Get("LinkLinkedSub"), textColor: GUI.Style.Orange, font: GUI.SmallFont);
            }

            var pathContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.2f), paddedFrame.RectTransform), isHorizontal: true);
            var pathBox       = new GUITextBox(new RectTransform(new Vector2(0.75f, 1.0f), pathContainer.RectTransform), filePath, font: GUI.SmallFont);
            var reloadButton  = new GUIButton(new RectTransform(new Vector2(0.25f / pathBox.RectTransform.RelativeSize.X, 1.0f), pathBox.RectTransform, Anchor.CenterRight, Pivot.CenterLeft),
                                              TextManager.Get("ReloadLinkedSub"), style: "GUIButtonSmall")
            {
                OnClicked = Reload,
                UserData  = pathBox,
                ToolTip   = TextManager.Get("ReloadLinkedSubTooltip")
            };

            editingHUD.RectTransform.Resize(new Point(
                                                editingHUD.Rect.Width,
                                                (int)(paddedFrame.Children.Sum(c => c.Rect.Height + paddedFrame.AbsoluteSpacing) / paddedFrame.RectTransform.RelativeSize.Y)));

            PositionEditingHUD();

            return(editingHUD);
        }
Пример #26
0
        private bool TextChanged(GUITextBox textBox, string text)
        {
            int newValue = Value;

            if (text == "" || text == "-")
            {
                Value        = 0;
                textBox.Text = text;
            }
            else if (int.TryParse(text, out newValue))
            {
                Value = newValue;
            }
            else
            {
                textBox.Text = Value.ToString();
            }

            return(true);
        }
Пример #27
0
        private bool ChangeSubName(GUITextBox textBox, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                textBox.Flash(Color.Red);
                return(false);
            }

            if (Submarine.MainSub != null)
            {
                Submarine.MainSub.Name = text;
            }
            textBox.Deselect();

            textBox.Text = text;

            textBox.Flash(Color.Green);

            return(true);
        }
Пример #28
0
        private bool ChangeSubDescription(GUITextBox textBox, string text)
        {
            if (Submarine.MainSub != null)
            {
                Submarine.MainSub.Description = text;
            }
            else
            {
                textBox.UserData = text;
            }

            // textBox.Rect = new Rectangle(textBox.Rect.Location, new Point(textBox.Rect.Width, 20));

            //textBox.Text = ToolBox.LimitString(text, 15);

            //textBox.Flash(Color.Green);
            //textBox.Deselect();

            return(true);
        }
Пример #29
0
        public static void Init(GameWindow window)
        {
            int x = 20, y = 20;
            int width = 800, height = 500;

            frame         = new GUIFrame(new Rectangle(x, y, width, height), new Color(0.4f, 0.4f, 0.4f, 0.8f));
            frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);

            listBox = new GUIListBox(new Rectangle(0, 0, 0, frame.Rect.Height - 40), Color.Black, "", frame);
            //listBox.Color = Color.Black * 0.7f;

            textBox = new GUITextBox(new Rectangle(0, 0, 0, 20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, "", frame);
            textBox.OnTextChanged += (textBox, text) =>
            {
                ResetAutoComplete();
                return(true);
            };


            NewMessage("Press F3 to open/close the debug console", Color.Cyan);
            NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
        }
Пример #30
0
        private bool EnterProperty(GUITextBox textBox, string text)
        {
            textBox.Color = Color.DarkGreen;

            var objectProperty = textBox.UserData as ObjectProperty;

            if (objectProperty == null)
            {
                return(false);
            }

            object prevValue = objectProperty.GetValue();

            textBox.Deselect();

            if (objectProperty.TrySetValue(text))
            {
                textBox.Text = text;

                if (GameMain.Server != null)
                {
                    GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
                }
                else if (GameMain.Client != null)
                {
                    GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
                }

                return(true);
            }
            else
            {
                if (prevValue != null)
                {
                    textBox.Text = prevValue.ToString();
                }
                return(false);
            }
        }