Пример #1
0
        private bool SelectServer(GUIComponent component, object obj)
        {
            if (obj == null || waitingForRefresh || (!(obj is ServerInfo)))
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(clientNameBox.Text))
            {
                joinButton.Enabled = true;
            }
            else
            {
                clientNameBox.Flash();
                joinButton.Enabled = false;
            }

            ServerInfo serverInfo;

            try
            {
                serverInfo     = (ServerInfo)obj;
                ipBox.UserData = serverInfo;
                ipBox.Text     = serverInfo.ServerName;
            }
            catch (InvalidCastException)
            {
                return(false);
            }

            return(true);
        }
Пример #2
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();
        }
Пример #3
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);
 }
Пример #4
0
 private bool EnterIDCardTags(GUITextBox textBox, string text)
 {
     IdCardTags   = text.Split(',');
     textBox.Text = string.Join(",", IdCardTags);
     textBox.Flash(Color.Green);
     textBox.Deselect();
     return(true);
 }
Пример #5
0
        private bool SaveSub(GUIButton button, object obj)
        {
            if (string.IsNullOrWhiteSpace(nameBox.Text))
            {
                GUI.AddMessage("Name your submarine before saving it", Color.Red, 3.0f);

                nameBox.Flash();
                return(false);
            }

            if (nameBox.Text.Contains("../"))
            {
                DebugConsole.ThrowError("Illegal symbols in filename (../)");
                nameBox.Flash();
                return(false);
            }

            string savePath = nameBox.Text + ".sub";

            if (Submarine.MainSub != null)
            {
                savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath);
            }
            else
            {
                savePath = Path.Combine(Submarine.SavePath, savePath);
            }

            Submarine.SaveCurrent(savePath);
            Submarine.MainSub.CheckForErrors();

            GUI.AddMessage("Submarine saved to " + Submarine.MainSub.FilePath, Color.Green, 3.0f);

            Submarine.RefreshSavedSubs();
            linkedSubBox.ClearChildren();
            foreach (Submarine sub in Submarine.SavedSubmarines)
            {
                linkedSubBox.AddItem(sub.Name, sub);
            }

            saveFrame = null;

            return(false);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
0
        private bool RefreshJoinButtonState(GUIComponent component, object obj)
        {
            if (obj == null || waitingForRefresh)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(clientNameBox.Text) && !string.IsNullOrWhiteSpace(ipBox.Text))
            {
                joinButton.Enabled = true;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(clientNameBox.Text))
                {
                    clientNameBox.Flash();
                }
                joinButton.Enabled = false;
            }

            return(true);
        }
Пример #9
0
        private bool JoinServer(string ip, string serverName)
        {
            if (string.IsNullOrWhiteSpace(clientNameBox.Text))
            {
                clientNameBox.Flash();
                return(false);
            }

            GameMain.Config.PlayerName = clientNameBox.Text;
            GameMain.Config.SaveNewPlayerConfig();

            CoroutineManager.StartCoroutine(ConnectToServer(ip, serverName));

            return(true);
        }
Пример #10
0
        private bool HostServerClicked(GUIButton button, object obj)
        {
            string name = serverNameBox.Text;

            if (string.IsNullOrEmpty(name))
            {
                serverNameBox.Flash();
                return(false);
            }

            if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535)
            {
                portBox.Text = NetConfig.DefaultPort.ToString();
                portBox.Flash();

                return(false);
            }

            int queryPort = 0;

            if (Steam.SteamManager.USE_STEAM)
            {
                if (!int.TryParse(queryPortBox.Text, out queryPort) || queryPort < 0 || queryPort > 65535)
                {
                    portBox.Text = NetConfig.DefaultQueryPort.ToString();
                    portBox.Flash();
                    return(false);
                }
            }

            GameMain.NetLobbyScreen = new NetLobbyScreen();
            try
            {
                GameMain.NetworkMember = new GameServer(name, port, queryPort, isPublicBox.Selected, passwordBox.Text, useUpnpBox.Selected, int.Parse(maxPlayersBox.Text));
            }

            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to start server", e);
            }

            GameMain.NetLobbyScreen.IsServer = true;
            return(true);
        }
Пример #11
0
        private bool JoinServer(GUIButton button, object obj)
        {
            if (string.IsNullOrWhiteSpace(clientNameBox.Text))
            {
                clientNameBox.Flash();
                return(false);
            }

            string ip = ipBox.Text;

            if (string.IsNullOrWhiteSpace(ip))
            {
                ipBox.Flash();
                return(false);
            }

            CoroutineManager.StartCoroutine(ConnectToServer(ip));


            return(true);
        }
Пример #12
0
        private bool JoinServer(GUIButton button, object obj, Boolean useNilmod = true)
        {
            if (string.IsNullOrWhiteSpace(clientNameBox.Text))
            {
                clientNameBox.Flash();
                return(false);
            }

            GameMain.Config.DefaultPlayerName = clientNameBox.Text;

            string ip = ipBox.Text;

            if (string.IsNullOrWhiteSpace(ip))
            {
                ipBox.Flash();
                return(false);
            }

            CoroutineManager.StartCoroutine(ConnectToServer(ip, useNilmod));


            return(true);
        }
Пример #13
0
        private void ShowCreateItemFrame()
        {
            createItemFrame.ClearChildren();

            if (itemEditor == null)
            {
                return;
            }

            var createItemContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), createItemFrame.RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.02f
            };

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 0.05f), createItemContent.RectTransform), "Title");
            var titleBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 0.05f), createItemContent.RectTransform), itemEditor.Title);

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 0.05f), createItemContent.RectTransform), "Description");
            var descriptionBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 0.1f), createItemContent.RectTransform), itemEditor.Description);

            descriptionBox.OnTextChanged += (textBox, text) => { itemEditor.Description = text; return(true); };

            new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), createItemContent.RectTransform, Anchor.TopRight), "Show folder")
            {
                IgnoreLayoutGroups = true,
                OnClicked          = (btn, userdata) => { System.Diagnostics.Process.Start(Path.GetFullPath(SteamManager.WorkshopItemStagingFolder)); return(true); }
            };

            new GUITextBlock(new RectTransform(new Vector2(0.2f, 0.05f), createItemContent.RectTransform), "Files included in the item");
            createItemFileList = new GUIListBox(new RectTransform(new Vector2(0.8f, 0.4f), createItemContent.RectTransform));
            RefreshCreateItemFileList();

            new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), createItemContent.RectTransform, Anchor.TopRight), "Refresh")
            {
                OnClicked = (btn, userdata) =>
                {
                    itemContentPackage = new ContentPackage(itemContentPackage.Path);
                    RefreshCreateItemFileList();
                    return(true);
                }
            };

            new GUIButton(new RectTransform(new Vector2(0.25f, 0.05f), createItemContent.RectTransform, Anchor.BottomRight),
                          "Publish item")
            {
                IgnoreLayoutGroups = true,
                OnClicked          = (btn, userData) =>
                {
                    itemEditor.Title       = titleBox.Text;
                    itemEditor.Description = descriptionBox.Text;
                    if (string.IsNullOrWhiteSpace(itemEditor.Title))
                    {
                        titleBox.Flash(Color.Red);
                        return(false);
                    }
                    if (string.IsNullOrWhiteSpace(itemEditor.Description))
                    {
                        descriptionBox.Flash(Color.Red);
                        return(false);
                    }
                    PublishWorkshopItem();
                    return(true);
                }
            };
        }
Пример #14
0
        public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable <Submarine> submarines, IEnumerable <string> saveFiles = null)
        {
            this.isMultiplayer     = isMultiplayer;
            this.newGameContainer  = newGameContainer;
            this.loadGameContainer = loadGameContainer;

            var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = isMultiplayer ? 0.0f : 0.05f
            };

            var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            var rightColumn = new GUILayoutGroup(new RectTransform(isMultiplayer ? Vector2.Zero : new Vector2(1.5f, 1.0f), columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            columnContainer.Recalculate();

            // New game left side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("SaveName") + ":");
            saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, string.Empty);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("MapSeed") + ":");
            seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, ToolBox.RandomSeed(8));

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("SelectedSub") + ":");
            var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), isHorizontal: true)
            {
                Stretch = true
            };

            subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform))
            {
                ScrollBarVisible = true
            };

            var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("FilterMapEntities"), textAlignment: Alignment.CenterLeft, font: GUI.Font);
            var searchBox   = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font);

            searchBox.OnSelected   += (sender, userdata) => { searchTitle.Visible = false; };
            searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; };

            searchBox.OnTextChanged += (textBox, text) => { FilterSubs(subList, text); return(true); };
            var clearButton = new GUIButton(new RectTransform(new Vector2(0.075f, 1.0f), filterContainer.RectTransform), "x")
            {
                OnClicked = (btn, userdata) => { searchBox.Text = ""; FilterSubs(subList, ""); searchBox.Flash(Color.White); return(true); }
            };

            if (!isMultiplayer)
            {
                subList.OnSelected = OnSubSelected;
            }

            // New game right side
            subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform))
            {
                Stretch = true
            };

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.13f),
                                                                       (isMultiplayer ? leftColumn : rightColumn).RectTransform)
            {
                MaxSize = new Point(int.MaxValue, 60)
            }, childAnchor: Anchor.TopRight);

            var startButton = new GUIButton(new RectTransform(isMultiplayer ? new Vector2(0.5f, 1.0f) : Vector2.One,
                                                              buttonContainer.RectTransform, Anchor.BottomRight)
            {
                MaxSize = new Point(350, 60)
            },
                                            TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge")
            {
                OnClicked = (GUIButton btn, object userData) =>
                {
                    if (string.IsNullOrWhiteSpace(saveNameBox.Text))
                    {
                        saveNameBox.Flash(Color.Red);
                        return(false);
                    }

                    if (!(subList.SelectedData is Submarine selectedSub))
                    {
                        return(false);
                    }

                    if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
                    {
                        ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
                        subList.SelectedComponent.CanBeFocused = false;
                        subList.Deselect();
                        return(false);
                    }

                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    bool   hasRequiredContentPackages = selectedSub.RequiredContentPackages.All(cp => GameMain.SelectedPackages.Any(cp2 => cp2.Name == cp));

                    if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
                    {
                        if (!hasRequiredContentPackages)
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                           TextManager.Get("ContentPackageMismatchWarning")
                                                           .Replace("[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked  = msgBox.Close;
                            msgBox.Buttons[0].OnClicked += (button, obj) =>
                            {
                                if (GUIMessageBox.MessageBoxes.Count == 0)
                                {
                                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                                    if (isMultiplayer)
                                    {
                                        CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                    }
                                }
                                return(true);
                            };

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                        }

                        if (selectedSub.HasTag(SubmarineTag.Shuttle))
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                           TextManager.Get("ShuttleWarning"),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked = (button, obj) =>
                            {
                                StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                                if (isMultiplayer)
                                {
                                    CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                }
                                return(true);
                            };
                            msgBox.Buttons[0].OnClicked += msgBox.Close;

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                            return(false);
                        }
                    }
                    else
                    {
                        StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                        if (isMultiplayer)
                        {
                            CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                        }
                    }

                    return(true);
                }
            };

            leftColumn.Recalculate();
            rightColumn.Recalculate();


            UpdateSubList(submarines);
            UpdateLoadMenu(saveFiles);
        }
Пример #15
0
        public CampaignUI(CampaignMode campaign, GUIFrame container)
        {
            this.Campaign = campaign;

            MapContainer = new GUICustomComponent(new RectTransform(Vector2.One, container.RectTransform), DrawMap, UpdateMap);
            new GUIFrame(new RectTransform(Vector2.One, MapContainer.RectTransform), style: "InnerGlow", color: Color.Black * 0.9f)
            {
                CanBeFocused = false
            };

            // top panel -------------------------------------------------------------------------

            topPanel = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.15f), container.RectTransform, Anchor.TopCenter), style: null)
            {
                CanBeFocused = false
            };
            var topPanelContent = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), topPanel.RectTransform, Anchor.BottomCenter), style: null)
            {
                CanBeFocused = false
            };

            var outpostBtn = new GUIButton(new RectTransform(new Vector2(0.15f, 0.55f), topPanelContent.RectTransform),
                                           TextManager.Get("Outpost"), textAlignment: Alignment.Center, style: "GUISlopedHeader")
            {
                OnClicked = (btn, userdata) => { SelectTab(Tab.Map); return(true); }
            };

            outpostBtn.TextBlock.Font      = GUI.LargeFont;
            outpostBtn.TextBlock.AutoScale = true;

            var tabButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 0.4f), topPanelContent.RectTransform, Anchor.BottomLeft), isHorizontal: true);

            int i         = 0;
            var tabValues = Enum.GetValues(typeof(Tab));

            foreach (Tab tab in tabValues)
            {
                var tabButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1.0f), tabButtonContainer.RectTransform),
                                              "",
                                              style: i == 0 ? "GUISlopedTabButtonLeft" : (i == tabValues.Length - 1 ? "GUISlopedTabButtonRight" : "GUISlopedTabButtonMid"))
                {
                    UserData  = tab,
                    OnClicked = (btn, userdata) => { SelectTab((Tab)userdata); return(true); },
                    Selected  = tab == Tab.Map
                };
                var buttonSprite = tabButton.Style.Sprites[GUIComponent.ComponentState.None][0];
                tabButton.RectTransform.MaxSize = new Point(
                    (int)(tabButton.Rect.Height * (buttonSprite.Sprite.size.X / buttonSprite.Sprite.size.Y)), int.MaxValue);

                //the text needs to be positioned differently in the buttons at the edges due to the "slopes" in the button
                if (i == 0 || i == tabValues.Length - 1)
                {
                    new GUITextBlock(new RectTransform(new Vector2(0.8f, 0.9f), tabButton.RectTransform, i == 0 ? Anchor.CenterLeft : Anchor.CenterRight)
                    {
                        RelativeOffset = new Vector2(0.05f, 0.0f)
                    },
                                     TextManager.Get(tab.ToString()), textColor: tabButton.TextColor, font: GUI.LargeFont, textAlignment: Alignment.Center, style: null)
                    {
                        UserData = "buttontext"
                    };
                }
                else
                {
                    new GUITextBlock(new RectTransform(new Vector2(0.7f, 0.9f), tabButton.RectTransform, Anchor.Center),
                                     TextManager.Get(tab.ToString()), textColor: tabButton.TextColor, font: GUI.LargeFont, textAlignment: Alignment.Center, style: null)
                    {
                        UserData = "buttontext"
                    };
                }

                tabButtons.Add(tabButton);
                i++;
            }
            GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(t => t.GetChildByUserData("buttontext") as GUITextBlock));
            tabButtons.FirstOrDefault().RectTransform.SizeChanged += () =>
            {
                GUITextBlock.AutoScaleAndNormalize(tabButtons.Select(t => t.GetChildByUserData("buttontext") as GUITextBlock));
            };

            // crew tab -------------------------------------------------------------------------

            tabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length];
            tabs[(int)Tab.Crew] = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.7f), container.RectTransform, Anchor.TopLeft)
            {
                RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y)
            }, color: Color.Black * 0.9f);
            new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f)
            {
                CanBeFocused = false
            };

            var crewContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), tabs[(int)Tab.Crew].RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), crewContent.RectTransform), "", font: GUI.LargeFont)
            {
                TextGetter = GetMoney
            };

            characterList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.9f), crewContent.RectTransform))
            {
                OnSelected = SelectCharacter
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform),
                             TextManager.Get("CampaignMenuCrew"), font: GUI.LargeFont)
            {
                UserData     = "mycrew",
                CanBeFocused = false,
                AutoScale    = true
            };
            if (campaign is SinglePlayerCampaign)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), characterList.Content.RectTransform),
                                 TextManager.Get("CampaignMenuHireable"), font: GUI.LargeFont)
                {
                    UserData     = "hire",
                    CanBeFocused = false,
                    AutoScale    = true
                };
            }

            // store tab -------------------------------------------------------------------------

            tabs[(int)Tab.Store] = new GUIFrame(new RectTransform(new Vector2(0.5f, 0.7f), container.RectTransform, Anchor.TopLeft)
            {
                RelativeOffset = new Vector2(0.1f, topPanel.RectTransform.RelativeSize.Y)
            }, color: Color.Black * 0.9f);
            new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Store].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f)
            {
                CanBeFocused = false
            };

            List <MapEntityCategory> itemCategories = Enum.GetValues(typeof(MapEntityCategory)).Cast <MapEntityCategory>().ToList();

            //don't show categories with no buyable items
            itemCategories.RemoveAll(c =>
                                     !MapEntityPrefab.List.Any(ep => ep.Category.HasFlag(c) && (ep is ItemPrefab) && ((ItemPrefab)ep).CanBeBought));

            var storeContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var storeContentTop = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), storeContent.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                Stretch = true
            };

            new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), storeContentTop.RectTransform), "", font: GUI.LargeFont)
            {
                TextGetter = GetMoney
            };
            var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.4f), storeContentTop.RectTransform), isHorizontal: true)
            {
                Stretch = true
            };
            var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font);

            searchBox               = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform), font: GUI.Font);
            searchBox.OnSelected   += (sender, userdata) => { searchTitle.Visible = false; };
            searchBox.OnDeselected += (sender, userdata) => { searchTitle.Visible = true; };

            searchBox.OnTextChanged += (textBox, text) => { FilterStoreItems(null, text); return(true); };
            var clearButton = new GUIButton(new RectTransform(new Vector2(0.1f, 1.0f), filterContainer.RectTransform), "x")
            {
                OnClicked = (btn, userdata) => { searchBox.Text = ""; FilterStoreItems(selectedItemCategory, ""); searchBox.Flash(Color.White); return(true); }
            };

            var storeItemLists = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), storeContent.RectTransform), isHorizontal: true)
            {
                Stretch = true
            };

            myItemList    = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform));
            storeItemList = new GUIListBox(new RectTransform(new Vector2(0.5f, 1.0f), storeItemLists.RectTransform))
            {
                OnSelected = BuyItem
            };

            var categoryButtonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.1f, 0.9f), tabs[(int)Tab.Store].RectTransform, Anchor.CenterLeft, Pivot.CenterRight))
            {
                RelativeSpacing = 0.02f
            };

            foreach (MapEntityCategory category in itemCategories)
            {
                var categoryButton = new GUIButton(new RectTransform(new Point(categoryButtonContainer.Rect.Width), categoryButtonContainer.RectTransform),
                                                   "", style: "ItemCategory" + category.ToString())
                {
                    UserData  = category,
                    OnClicked = (btn, userdata) =>
                    {
                        MapEntityCategory newCategory = (MapEntityCategory)userdata;
                        if (newCategory != selectedItemCategory)
                        {
                            searchBox.Text = "";
                        }
                        FilterStoreItems((MapEntityCategory)userdata, searchBox.Text);
                        return(true);
                    }
                };
                itemCategoryButtons.Add(categoryButton);

                new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.25f), categoryButton.RectTransform, Anchor.BottomCenter)
                {
                    RelativeOffset = new Vector2(0.0f, 0.02f)
                },
                                 TextManager.Get("MapEntityCategory." + category), textAlignment: Alignment.Center, textColor: categoryButton.TextColor)
                {
                    Padding       = Vector4.Zero,
                    AutoScale     = true,
                    Color         = Color.Transparent,
                    HoverColor    = Color.Transparent,
                    PressedColor  = Color.Transparent,
                    SelectedColor = Color.Transparent,
                    CanBeFocused  = false
                };
            }
            FillStoreItemList();
            FilterStoreItems(MapEntityCategory.Equipment, "");

            // repair tab -------------------------------------------------------------------------

            tabs[(int)Tab.Repair] = new GUIFrame(new RectTransform(new Vector2(0.35f, 0.5f), container.RectTransform, Anchor.TopLeft)
            {
                RelativeOffset = new Vector2(0.02f, topPanel.RectTransform.RelativeSize.Y)
            }, color: Color.Black * 0.9f);
            new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), tabs[(int)Tab.Repair].RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f)
            {
                CanBeFocused = false
            };

            var repairContent = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), tabs[(int)Tab.Repair].RectTransform, Anchor.Center))
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), repairContent.RectTransform), "", font: GUI.LargeFont)
            {
                TextGetter = GetMoney
            };

            var repairHullsHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), repairContent.RectTransform), childAnchor: Anchor.TopRight)
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            new GUIImage(new RectTransform(new Vector2(0.3f, 1.0f), repairHullsHolder.RectTransform, Anchor.CenterLeft), "RepairHullButton")
            {
                IgnoreLayoutGroups = true,
                CanBeFocused       = false
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairHullsHolder.RectTransform), TextManager.Get("RepairAllWalls"), textAlignment: Alignment.Right, font: GUI.LargeFont)
            {
                ForceUpperCase = true
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairHullsHolder.RectTransform), "500", textAlignment: Alignment.Right, font: GUI.LargeFont);
            repairHullsButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.3f), repairHullsHolder.RectTransform), TextManager.Get("Repair"), style: "GUIButtonLarge")
            {
                OnClicked = (btn, userdata) =>
                {
                    if (campaign.PurchasedHullRepairs)
                    {
                        campaign.Money += CampaignMode.HullRepairCost;
                        campaign.PurchasedHullRepairs = false;
                    }
                    else
                    {
                        if (campaign.Money >= CampaignMode.HullRepairCost)
                        {
                            campaign.Money -= CampaignMode.HullRepairCost;
                            campaign.PurchasedHullRepairs = true;
                        }
                    }
                    GameMain.Client?.SendCampaignState();
                    btn.GetChild <GUITickBox>().Selected = campaign.PurchasedHullRepairs;

                    return(true);
                }
            };
            new GUITickBox(new RectTransform(new Vector2(0.65f), repairHullsButton.RectTransform, Anchor.CenterLeft)
            {
                AbsoluteOffset = new Point(10, 0)
            }, "")
            {
                CanBeFocused = false
            };

            var repairItemsHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), repairContent.RectTransform), childAnchor: Anchor.TopRight)
            {
                RelativeSpacing = 0.05f,
                Stretch         = true
            };

            new GUIImage(new RectTransform(new Vector2(0.3f, 1.0f), repairItemsHolder.RectTransform, Anchor.CenterLeft), "RepairItemsButton")
            {
                IgnoreLayoutGroups = true,
                CanBeFocused       = false
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairItemsHolder.RectTransform), TextManager.Get("RepairAllItems"), textAlignment: Alignment.Right, font: GUI.LargeFont)
            {
                ForceUpperCase = true
            };
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.3f), repairItemsHolder.RectTransform), "500", textAlignment: Alignment.Right, font: GUI.LargeFont);
            repairItemsButton = new GUIButton(new RectTransform(new Vector2(0.4f, 0.3f), repairItemsHolder.RectTransform), TextManager.Get("Repair"), style: "GUIButtonLarge")
            {
                OnClicked = (btn, userdata) =>
                {
                    if (campaign.PurchasedItemRepairs)
                    {
                        campaign.Money += CampaignMode.ItemRepairCost;
                        campaign.PurchasedItemRepairs = false;
                    }
                    else
                    {
                        if (campaign.Money >= CampaignMode.ItemRepairCost)
                        {
                            campaign.Money -= CampaignMode.ItemRepairCost;
                            campaign.PurchasedItemRepairs = true;
                        }
                    }
                    GameMain.Client?.SendCampaignState();
                    btn.GetChild <GUITickBox>().Selected = campaign.PurchasedItemRepairs;

                    return(true);
                }
            };
            new GUITickBox(new RectTransform(new Vector2(0.65f), repairItemsButton.RectTransform, Anchor.CenterLeft)
            {
                AbsoluteOffset = new Point(10, 0)
            }, "")
            {
                CanBeFocused = false
            };

            // mission info -------------------------------------------------------------------------

            missionPanel = new GUIFrame(new RectTransform(new Vector2(0.3f, 0.5f), container.RectTransform, Anchor.TopRight)
            {
                RelativeOffset = new Vector2(0.0f, topPanel.RectTransform.RelativeSize.Y)
            }, color: Color.Black * 0.7f)
            {
                Visible = false
            };

            new GUIFrame(new RectTransform(new Vector2(1.25f, 1.25f), missionPanel.RectTransform, Anchor.Center), style: "OuterGlow", color: Color.Black * 0.7f)
            {
                CanBeFocused = false
            };

            new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.15f), missionPanel.RectTransform, Anchor.TopRight, Pivot.BottomRight)
            {
                RelativeOffset = new Vector2(0.1f, -0.05f)
            }, TextManager.Get("Mission"),
                             textAlignment: Alignment.Center, font: GUI.LargeFont, style: "GUISlopedHeader")
            {
                AutoScale = true
            };
            var missionPanelContent = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), missionPanel.RectTransform, Anchor.Center))
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            selectedLocationInfo = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.75f), missionPanelContent.RectTransform))
            {
                RelativeSpacing = 0.02f,
                Stretch         = true
            };
            selectedMissionInfo = new GUIListBox(new RectTransform(new Vector2(0.9f, 0.25f), missionPanel.RectTransform, Anchor.BottomRight, Pivot.TopRight))
            {
                Visible = false
            };

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

            topPanel.RectTransform.SetAsLastChild();

            SelectTab(Tab.Map);

            UpdateLocationView(campaign.Map.CurrentLocation);

            campaign.Map.OnLocationSelected += SelectLocation;
            campaign.Map.OnLocationChanged  += (prevLocation, newLocation) => UpdateLocationView(newLocation);
            campaign.Map.OnMissionSelected  += (connection, mission) =>
            {
                var selectedTickBox = missionTickBoxes.Find(tb => tb.UserData == mission);
                if (selectedTickBox != null)
                {
                    selectedTickBox.Selected = true;
                }
            };
            campaign.CargoManager.OnItemsChanged += RefreshMyItems;
        }
        private void CreateUI()
        {
            Frame.ClearChildren();

            leftPanel = new GUIFrame(new RectTransform(new Vector2(0.125f, 1.0f), Frame.RectTransform)
            {
                MinSize = new Point(150, 0)
            },
                                     style: "GUIFrameLeft");
            var paddedLeftPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), leftPanel.RectTransform, Anchor.CenterLeft)
            {
                RelativeOffset = new Vector2(0.02f, 0.0f)
            })
            {
                RelativeSpacing = 0.01f,
                Stretch         = true
            };

            rightPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), Frame.RectTransform, Anchor.TopRight)
            {
                MinSize = new Point(350, 0)
            },
                                      style: "GUIFrameRight");
            var paddedRightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), rightPanel.RectTransform, Anchor.Center)
            {
                RelativeOffset = new Vector2(0.02f, 0.0f)
            })
            {
                RelativeSpacing = 0.01f,
                Stretch         = true
            };

            var saveAllButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
                                              TextManager.Get("editor.saveall"))
            {
                OnClicked = (btn, obj) =>
                {
                    SerializeAll();
                    return(true);
                }
            };

            var serializeToClipBoardButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
                                                           TextManager.Get("editor.copytoclipboard"))
            {
                OnClicked = (btn, obj) =>
                {
                    SerializeToClipboard(selectedPrefab);
                    return(true);
                }
            };

            emitter = new Emitter();
            var emitterEditorContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), paddedRightPanel.RectTransform), style: null);
            var emitterEditor          = new SerializableEntityEditor(emitterEditorContainer.RectTransform, emitter, false, true, elementHeight: 20, titleFont: GUI.SubHeadingFont);

            emitterEditor.RectTransform.RelativeSize = Vector2.One;
            emitterEditorContainer.RectTransform.Resize(new Point(emitterEditorContainer.RectTransform.NonScaledSize.X, emitterEditor.ContentHeight), false);

            var listBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.6f), paddedRightPanel.RectTransform));

            var filterArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.03f), paddedLeftPanel.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, isHorizontal: true)
            {
                Stretch  = true,
                UserData = "filterarea"
            };

            filterLabel = new GUITextBlock(new RectTransform(Vector2.One, filterArea.RectTransform), TextManager.Get("serverlog.filter"), font: GUI.Font)
            {
                IgnoreLayoutGroups = true
            };
            filterBox = new GUITextBox(new RectTransform(new Vector2(0.8f, 1.0f), filterArea.RectTransform), font: GUI.Font);
            filterBox.OnTextChanged += (textBox, text) => { FilterEmitters(text); return(true); };
            new GUIButton(new RectTransform(new Vector2(0.05f, 1.0f), filterArea.RectTransform, scaleBasis: ScaleBasis.BothHeight), style: "GUICancelButton")
            {
                OnClicked = (btn, userdata) => { FilterEmitters(""); filterBox.Text = ""; filterBox.Flash(Color.White); return(true); }
            };

            prefabList             = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.8f), paddedLeftPanel.RectTransform));
            prefabList.OnSelected += (GUIComponent component, object obj) =>
            {
                selectedPrefab = obj as ParticlePrefab;
                listBox.ClearChildren();
                new SerializableEntityEditor(listBox.Content.RectTransform, selectedPrefab, false, true, elementHeight: 20, titleFont: GUI.SubHeadingFont);
                //listBox.Content.RectTransform.NonScaledSize = particlePrefabEditor.RectTransform.NonScaledSize;
                //listBox.UpdateScrollBarSize();
                return(true);
            };

            if (GameMain.ParticleManager != null)
            {
                RefreshPrefabList();
            }
        }
Пример #17
0
        public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable <SubmarineInfo> submarines, IEnumerable <string> saveFiles = null)
        {
            this.isMultiplayer     = isMultiplayer;
            this.newGameContainer  = newGameContainer;
            this.loadGameContainer = loadGameContainer;

            var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = isMultiplayer ? 0.0f : 0.02f
            };

            var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            var rightColumn = new GUILayoutGroup(new RectTransform(isMultiplayer ? Vector2.Zero : new Vector2(1.5f, 1.0f), columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            columnContainer.Recalculate();

            // New game left side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("SaveName"), font: GUI.SubHeadingFont);
            saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, string.Empty)
            {
                textFilterFunction = (string str) => { return(ToolBox.RemoveInvalidFileNameChars(str)); }
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("MapSeed"), font: GUI.SubHeadingFont);
            seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, ToolBox.RandomSeed(8));

            if (!isMultiplayer)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
                {
                    MinSize = new Point(0, 20)
                }, TextManager.Get("SelectedSub"), font: GUI.SubHeadingFont);

                var moddedDropdown = new GUIDropDown(new RectTransform(new Vector2(1f, 0.02f), leftColumn.RectTransform), "", 3);
                moddedDropdown.AddItem(TextManager.Get("clientpermission.all"), CategoryFilter.All);
                moddedDropdown.AddItem(TextManager.Get("servertag.modded.false"), CategoryFilter.Vanilla);
                moddedDropdown.AddItem(TextManager.Get("customrank"), CategoryFilter.Custom);
                moddedDropdown.Select(0);

                var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), isHorizontal: true)
                {
                    Stretch = true
                };

                subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform))
                {
                    ScrollBarVisible = true
                };

                var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font);
                var searchBox   = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true);
                filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize;
                searchBox.OnSelected    += (sender, userdata) => { searchTitle.Visible = false; };
                searchBox.OnDeselected  += (sender, userdata) => { searchTitle.Visible = true; };
                searchBox.OnTextChanged += (textBox, text) => { FilterSubs(subList, text); return(true); };

                moddedDropdown.OnSelected = (component, data) =>
                {
                    searchBox.Text = string.Empty;
                    subFilter      = (CategoryFilter)data;
                    UpdateSubList(SubmarineInfo.SavedSubmarines);
                    return(true);
                };

                subList.OnSelected = OnSubSelected;
            }
            else // Spacing to fix the multiplayer campaign setup layout
            {
                CreateMultiplayerCampaignSubList(leftColumn.RectTransform);

                //spacing
                //new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), leftColumn.RectTransform), style: null);
            }

            // New game right side
            subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform))
            {
                Stretch = true
            };

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.12f),
                                                                       (isMultiplayer ? leftColumn : rightColumn).RectTransform)
            {
                MaxSize = new Point(int.MaxValue, 60)
            }, childAnchor: Anchor.BottomRight, isHorizontal: true);

            if (!isMultiplayer)
            {
                buttonContainer.IgnoreLayoutGroups = true;
            }

            StartButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1f), buttonContainer.RectTransform, Anchor.BottomRight)
            {
                MaxSize = new Point(350, 60)
            }, TextManager.Get("StartCampaignButton"))
            {
                OnClicked = (GUIButton btn, object userData) =>
                {
                    if (string.IsNullOrWhiteSpace(saveNameBox.Text))
                    {
                        saveNameBox.Flash(GUI.Style.Red);
                        return(false);
                    }

                    SubmarineInfo selectedSub = null;

                    if (!isMultiplayer)
                    {
                        if (!(subList.SelectedData is SubmarineInfo))
                        {
                            return(false);
                        }
                        selectedSub = subList.SelectedData as SubmarineInfo;
                    }
                    else
                    {
                        if (GameMain.NetLobbyScreen.SelectedSub == null)
                        {
                            return(false);
                        }
                        selectedSub = GameMain.NetLobbyScreen.SelectedSub;
                    }

                    if (selectedSub.SubmarineClass == SubmarineClass.Undefined)
                    {
                        new GUIMessageBox(TextManager.Get("error"), TextManager.Get("undefinedsubmarineselected"));
                        return(false);
                    }

                    if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
                    {
                        ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
                        subList.SelectedComponent.CanBeFocused = false;
                        subList.Deselect();
                        return(false);
                    }

                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    bool   hasRequiredContentPackages = selectedSub.RequiredContentPackagesInstalled;

                    CampaignSettings settings = new CampaignSettings();
                    if (isMultiplayer)
                    {
                        settings.RadiationEnabled = GameMain.NetLobbyScreen.IsRadiationEnabled();
                        settings.MaxMissionCount  = GameMain.NetLobbyScreen.GetMaxMissionCount();
                    }
                    else
                    {
                        settings.RadiationEnabled = EnableRadiationToggle?.Selected ?? false;
                        if (MaxMissionCountText != null && Int32.TryParse(MaxMissionCountText.Text, out int missionCount))
                        {
                            settings.MaxMissionCount = missionCount;
                        }
                        else
                        {
                            settings.MaxMissionCount = CampaignSettings.DefaultMaxMissionCount;
                        }
                    }

                    if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
                    {
                        if (!hasRequiredContentPackages)
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                           TextManager.GetWithVariable("ContentPackageMismatchWarning", "[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked  = msgBox.Close;
                            msgBox.Buttons[0].OnClicked += (button, obj) =>
                            {
                                if (GUIMessageBox.MessageBoxes.Count == 0)
                                {
                                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                                    if (isMultiplayer)
                                    {
                                        CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                    }
                                }
                                return(true);
                            };

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                        }

                        if (selectedSub.HasTag(SubmarineTag.Shuttle))
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                           TextManager.Get("ShuttleWarning"),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked = (button, obj) =>
                            {
                                StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                                if (isMultiplayer)
                                {
                                    CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                }
                                return(true);
                            };
                            msgBox.Buttons[0].OnClicked += msgBox.Close;

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                            return(false);
                        }
                    }
                    else
                    {
                        StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                        if (isMultiplayer)
                        {
                            CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                        }
                    }

                    return(true);
                }
            };

            InitialMoneyText = new GUITextBlock(new RectTransform(new Vector2(isMultiplayer ? 0.6f : 0.3f, 1f), buttonContainer.RectTransform), "", font: isMultiplayer ? GUI.Style.SmallFont : GUI.Style.Font, textColor: GUI.Style.Green)
            {
                TextGetter = () =>
                {
                    int initialMoney = CampaignMode.InitialMoney;
                    if (isMultiplayer)
                    {
                        if (GameMain.NetLobbyScreen.SelectedSub != null)
                        {
                            initialMoney -= GameMain.NetLobbyScreen.SelectedSub.Price;
                        }
                    }
                    else if (subList.SelectedData is SubmarineInfo subInfo)
                    {
                        initialMoney -= subInfo.Price;
                    }
                    initialMoney = Math.Max(initialMoney, isMultiplayer ? MultiPlayerCampaign.MinimumInitialMoney : 0);
                    return(TextManager.GetWithVariable("campaignstartingmoney", "[money]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", initialMoney)));
                }
            };

            if (!isMultiplayer)
            {
                CampaignCustomizeButton = new GUIButton(new RectTransform(new Vector2(0.25f, 1f), buttonContainer.RectTransform, Anchor.CenterLeft), TextManager.Get("SettingsButton"))
                {
                    OnClicked = (tb, userdata) =>
                    {
                        CreateCustomizeWindow();
                        return(true);
                    }
                };

                var disclaimerBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform, Anchor.TopRight)
                {
                    AbsoluteOffset = new Point(5)
                }, style: "GUINotificationButton")
                {
                    IgnoreLayoutGroups = true,
                    OnClicked          = (btn, userdata) => { GameMain.Instance.ShowCampaignDisclaimer(); return(true); }
                };
                disclaimerBtn.RectTransform.MaxSize = new Point((int)(30 * GUI.Scale));
            }

            columnContainer.Recalculate();
            leftColumn.Recalculate();
            rightColumn.Recalculate();

            if (submarines != null)
            {
                UpdateSubList(submarines);
            }
            UpdateLoadMenu(saveFiles);
        }
Пример #18
0
        public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer)
        {
            this.isMultiplayer     = isMultiplayer;
            this.newGameContainer  = newGameContainer;
            this.loadGameContainer = loadGameContainer;

            var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.05f
            };

            var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.02f
            };

            var rightColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                RelativeSpacing = 0.02f
            };

            // New game left side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), leftColumn.RectTransform), TextManager.Get("SelectedSub") + ":", textAlignment: Alignment.BottomLeft);
            subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform));

            UpdateSubList();

            // New game right side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("SaveName") + ":", textAlignment: Alignment.BottomLeft);
            saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), string.Empty);

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("MapSeed") + ":", textAlignment: Alignment.BottomLeft);
            seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), ToolBox.RandomSeed(8));

            var startButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.13f), rightColumn.RectTransform, Anchor.BottomRight), TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge")
            {
                IgnoreLayoutGroups = true,
                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)
                    {
                        return(false);
                    }

                    if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
                    {
                        ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
                        subList.SelectedComponent.CanBeFocused = false;
                        subList.Deselect();
                        return(false);
                    }

                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    bool   hasRequiredContentPackages = selectedSub.RequiredContentPackages.All(cp => GameMain.SelectedPackages.Any(cp2 => cp2.Name == cp));

                    if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
                    {
                        if (!hasRequiredContentPackages)
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                           TextManager.Get("ContentPackageMismatchWarning")
                                                           .Replace("[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked  = msgBox.Close;
                            msgBox.Buttons[0].OnClicked += (button, obj) =>
                            {
                                if (GUIMessageBox.MessageBoxes.Count == 0)
                                {
                                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                                }
                                return(true);
                            };

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                        }

                        if (selectedSub.HasTag(SubmarineTag.Shuttle))
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                           TextManager.Get("ShuttleWarning"),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            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
                    {
                        StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                    }

                    return(true);
                }
            };

            UpdateLoadMenu();
        }
Пример #19
0
        public CampaignSetupUI(bool isMultiplayer, GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable <SubmarineInfo> submarines, IEnumerable <string> saveFiles = null)
        {
            this.isMultiplayer     = isMultiplayer;
            this.newGameContainer  = newGameContainer;
            this.loadGameContainer = loadGameContainer;

            var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = isMultiplayer ? 0.0f : 0.02f
            };

            var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            var rightColumn = new GUILayoutGroup(new RectTransform(isMultiplayer ? Vector2.Zero : new Vector2(1.5f, 1.0f), columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            columnContainer.Recalculate();

            // New game left side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("SaveName"), font: GUI.SubHeadingFont);
            saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, string.Empty)
            {
                textFilterFunction = (string str) => { return(ToolBox.RemoveInvalidFileNameChars(str)); }
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("MapSeed"), font: GUI.SubHeadingFont);
            seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, ToolBox.RandomSeed(8));

            if (!isMultiplayer)
            {
                new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
                {
                    MinSize = new Point(0, 20)
                }, TextManager.Get("SelectedSub"), font: GUI.SubHeadingFont);

                var filterContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), isHorizontal: true)
                {
                    Stretch = true
                };

                subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform))
                {
                    ScrollBarVisible = true
                };

                var searchTitle = new GUITextBlock(new RectTransform(new Vector2(0.001f, 1.0f), filterContainer.RectTransform), TextManager.Get("serverlog.filter"), textAlignment: Alignment.CenterLeft, font: GUI.Font);
                var searchBox   = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), filterContainer.RectTransform, Anchor.CenterRight), font: GUI.Font, createClearButton: true);
                filterContainer.RectTransform.MinSize = searchBox.RectTransform.MinSize;
                searchBox.OnSelected    += (sender, userdata) => { searchTitle.Visible = false; };
                searchBox.OnDeselected  += (sender, userdata) => { searchTitle.Visible = true; };
                searchBox.OnTextChanged += (textBox, text) => { FilterSubs(subList, text); return(true); };

                subList.OnSelected = OnSubSelected;
            }
            else // Spacing to fix the multiplayer campaign setup layout
            {
                //spacing
                new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), leftColumn.RectTransform), style: null);
            }

            // New game right side
            subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform))
            {
                Stretch = true
            };

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.13f),
                                                                       (isMultiplayer ? leftColumn : rightColumn).RectTransform)
            {
                MaxSize = new Point(int.MaxValue, 60)
            }, childAnchor: Anchor.TopRight);

            if (!isMultiplayer)
            {
                buttonContainer.IgnoreLayoutGroups = true;
            }

            StartButton = new GUIButton(new RectTransform(isMultiplayer ? new Vector2(0.5f, 1.0f) : Vector2.One,
                                                          buttonContainer.RectTransform, Anchor.BottomRight)
            {
                MaxSize = new Point(350, 60)
            },
                                        TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge")
            {
                OnClicked = (GUIButton btn, object userData) =>
                {
                    if (string.IsNullOrWhiteSpace(saveNameBox.Text))
                    {
                        saveNameBox.Flash(GUI.Style.Red);
                        return(false);
                    }

                    SubmarineInfo selectedSub = null;

                    if (!isMultiplayer)
                    {
                        if (!(subList.SelectedData is SubmarineInfo))
                        {
                            return(false);
                        }
                        selectedSub = subList.SelectedData as SubmarineInfo;
                    }
                    else
                    {
                        if (GameMain.NetLobbyScreen.SelectedSub == null)
                        {
                            return(false);
                        }
                        selectedSub = GameMain.NetLobbyScreen.SelectedSub;
                    }

                    if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
                    {
                        ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
                        subList.SelectedComponent.CanBeFocused = false;
                        subList.Deselect();
                        return(false);
                    }

                    string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                    bool   hasRequiredContentPackages = selectedSub.RequiredContentPackagesInstalled;

                    if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
                    {
                        if (!hasRequiredContentPackages)
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                           TextManager.GetWithVariable("ContentPackageMismatchWarning", "[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked  = msgBox.Close;
                            msgBox.Buttons[0].OnClicked += (button, obj) =>
                            {
                                if (GUIMessageBox.MessageBoxes.Count == 0)
                                {
                                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                                    if (isMultiplayer)
                                    {
                                        CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                    }
                                }
                                return(true);
                            };

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                        }

                        if (selectedSub.HasTag(SubmarineTag.Shuttle))
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                           TextManager.Get("ShuttleWarning"),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked = (button, obj) =>
                            {
                                StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                                if (isMultiplayer)
                                {
                                    CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                }
                                return(true);
                            };
                            msgBox.Buttons[0].OnClicked += msgBox.Close;

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                            return(false);
                        }
                    }
                    else
                    {
                        StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                        if (isMultiplayer)
                        {
                            CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                        }
                    }

                    return(true);
                }
            };


            if (!isMultiplayer)
            {
                var disclaimerBtn = new GUIButton(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform, Anchor.TopRight)
                {
                    AbsoluteOffset = new Point(5)
                }, style: "GUINotificationButton")
                {
                    IgnoreLayoutGroups = true,
                    OnClicked          = (btn, userdata) => { GameMain.Instance.ShowCampaignDisclaimer(); return(true); }
                };
                disclaimerBtn.RectTransform.MaxSize = new Point((int)(30 * GUI.Scale));
            }

            columnContainer.Recalculate();
            leftColumn.Recalculate();
            rightColumn.Recalculate();

            if (submarines != null)
            {
                UpdateSubList(submarines);
            }
            UpdateLoadMenu(saveFiles);
        }
Пример #20
0
            public GUIMessageBox Create()
            {
                var box = new GUIMessageBox(TextManager.Get("leveleditor.createlevelobj"), string.Empty,
                                            new string[] { TextManager.Get("cancel"), TextManager.Get("done") }, new Vector2(0.5f, 0.8f));

                box.Content.ChildAnchor     = Anchor.TopCenter;
                box.Content.AbsoluteSpacing = 20;
                int elementSize = 30;
                var listBox     = new GUIListBox(new RectTransform(new Vector2(1, 0.9f), box.Content.RectTransform));

                new GUITextBlock(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform),
                                 TextManager.Get("leveleditor.levelobjname"))
                {
                    CanBeFocused = false
                };
                var nameBox = new GUITextBox(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform));

                new GUITextBlock(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform),
                                 TextManager.Get("leveleditor.levelobjtexturepath"))
                {
                    CanBeFocused = false
                };
                var texturePathBox = new GUITextBox(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform));

                foreach (LevelObjectPrefab prefab in LevelObjectPrefab.List)
                {
                    if (prefab.Sprites.FirstOrDefault() == null)
                    {
                        continue;
                    }
                    texturePathBox.Text = Path.GetDirectoryName(prefab.Sprites.FirstOrDefault().FilePath);
                    break;
                }

                newPrefab = new LevelObjectPrefab(null);

                new SerializableEntityEditor(listBox.Content.RectTransform, newPrefab, false, false);

                box.Buttons[0].OnClicked += (b, d) =>
                {
                    box.Close();
                    return(true);
                };
                // Next
                box.Buttons[1].OnClicked += (b, d) =>
                {
                    if (string.IsNullOrEmpty(nameBox.Text))
                    {
                        nameBox.Flash(GUI.Style.Red);
                        GUI.AddMessage(TextManager.Get("leveleditor.levelobjnameempty"), GUI.Style.Red);
                        return(false);
                    }

                    if (LevelObjectPrefab.List.Any(obj => obj.Name.ToLower() == nameBox.Text.ToLower()))
                    {
                        nameBox.Flash(GUI.Style.Red);
                        GUI.AddMessage(TextManager.Get("leveleditor.levelobjnametaken"), GUI.Style.Red);
                        return(false);
                    }

                    if (!File.Exists(texturePathBox.Text))
                    {
                        texturePathBox.Flash(GUI.Style.Red);
                        GUI.AddMessage(TextManager.Get("leveleditor.levelobjtexturenotfound"), GUI.Style.Red);
                        return(false);
                    }

                    newPrefab.Name = nameBox.Text;

                    XmlWriterSettings settings = new XmlWriterSettings {
                        Indent = true
                    };
                    foreach (ContentFile configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelObjectPrefabs))
                    {
                        XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
                        if (doc == null)
                        {
                            continue;
                        }
                        var newElement = new XElement(newPrefab.Name);
                        newPrefab.Save(newElement);
                        newElement.Add(new XElement("Sprite",
                                                    new XAttribute("texture", texturePathBox.Text),
                                                    new XAttribute("sourcerect", "0,0,100,100"),
                                                    new XAttribute("origin", "0.5,0.5")));

                        doc.Root.Add(newElement);
                        using (var writer = XmlWriter.Create(configFile.Path, settings))
                        {
                            doc.WriteTo(writer);
                            writer.Flush();
                        }
                        // Recreate the prefab so that the sprite loads correctly: TODO: consider a better way to do this
                        newPrefab = new LevelObjectPrefab(newElement);
                        break;
                    }

                    LevelObjectPrefab.List.Add(newPrefab);
                    GameMain.LevelEditorScreen.UpdateLevelObjectsList();

                    box.Close();
                    return(true);
                };
                return(box);
            }
Пример #21
0
        private bool HostServerClicked(GUIButton button, object obj)
        {
            string name = serverNameBox.Text;

            if (string.IsNullOrEmpty(name))
            {
                serverNameBox.Flash();
                return(false);
            }

            if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535)
            {
                portBox.Text = NetConfig.DefaultPort.ToString();
                portBox.Flash();

                return(false);
            }

            int queryPort = 0;

            if (Steam.SteamManager.USE_STEAM)
            {
                if (!int.TryParse(queryPortBox.Text, out queryPort) || queryPort < 0 || queryPort > 65535)
                {
                    portBox.Text = NetConfig.DefaultQueryPort.ToString();
                    portBox.Flash();
                    return(false);
                }
            }

            GameMain.NetLobbyScreen = new NetLobbyScreen();
            try
            {
                string exeName = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.ServerExecutable)?.FirstOrDefault();
                if (string.IsNullOrEmpty(exeName))
                {
                    DebugConsole.ThrowError("No server executable defined in the selected content packages. Attempting to use the default executable...");
                    exeName = "DedicatedServer.exe";
                }

                int ownerKey = Math.Max(CryptoRandom.Instance.Next(), 1);

                string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
                                   " -port " + port.ToString() +
                                   " -queryport " + queryPort.ToString() +
                                   " -public " + isPublicBox.Selected.ToString() +
                                   " -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
                                   " -upnp " + useUpnpBox.Selected +
                                   " -maxplayers " + maxPlayersBox.Text +
                                   " -ownerkey " + ownerKey.ToString();

                string filename = exeName;
#if LINUX || OSX
                filename = "./" + Path.GetFileNameWithoutExtension(exeName);
#endif
                var processInfo = new ProcessStartInfo
                {
                    FileName  = filename,
                    Arguments = arguments,
#if !DEBUG
                    WindowStyle = ProcessWindowStyle.Hidden
#endif
                };
                GameMain.ServerChildProcess = Process.Start(processInfo);
                Thread.Sleep(1000); //wait until the server is ready before connecting

                GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(), name, ownerKey);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to start server", e);
            }

            return(true);
        }
Пример #22
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), TextManager.Get("SelectedSub") + ":", 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),
                             TextManager.Get("SaveName") + ": ", "", 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),
                             TextManager.Get("MapSeed") + ": ", "", 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), TextManager.Get("StartCampaignButton"), 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)
                {
                    return(false);
                }

                string savePath = SaveUtil.CreateSavePath(isMultiplayer ? SaveUtil.SaveType.Multiplayer : SaveUtil.SaveType.Singleplayer, saveNameBox.Text);
                if (selectedSub.HasTag(SubmarineTag.Shuttle) || !selectedSub.CompatibleContentPackages.Contains(GameMain.SelectedPackage.Name))
                {
                    if (!selectedSub.CompatibleContentPackages.Contains(GameMain.SelectedPackage.Name))
                    {
                        var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                       TextManager.Get("ContentPackageMismatchWarning")
                                                       .Replace("[selectedcontentpackage]", GameMain.SelectedPackage.Name),
                                                       new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                        msgBox.Buttons[0].OnClicked  = msgBox.Close;
                        msgBox.Buttons[0].OnClicked += (button, obj) =>
                        {
                            if (GUIMessageBox.MessageBoxes.Count == 0)
                            {
                                StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                            }
                            return(true);
                        };

                        msgBox.Buttons[1].OnClicked = msgBox.Close;
                    }

                    if (selectedSub.HasTag(SubmarineTag.Shuttle))
                    {
                        var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                       TextManager.Get("ShuttleWarning"),
                                                       new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                        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
                {
                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text);
                }

                return(true);
            };

            UpdateLoadMenu();
        }
Пример #23
0
        private bool HostServerClicked(GUIButton button, object obj)
        {
            string name = serverNameBox.Text;

            if (string.IsNullOrEmpty(name))
            {
                serverNameBox.Flash();
                return(false);
            }

            if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535)
            {
                portBox.Text = NetConfig.DefaultPort.ToString();
                portBox.Flash();

                return(false);
            }

            int queryPort = 0;

            if (Steam.SteamManager.USE_STEAM)
            {
                if (!int.TryParse(queryPortBox.Text, out queryPort) || queryPort < 0 || queryPort > 65535)
                {
                    portBox.Text = NetConfig.DefaultQueryPort.ToString();
                    portBox.Flash();
                    return(false);
                }
            }

            GameMain.NetLobbyScreen = new NetLobbyScreen();
            try
            {
                int ownerKey = Math.Max(CryptoRandom.Instance.Next(), 1);

                string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
                                   " -port " + port.ToString() +
                                   " -queryport " + queryPort.ToString() +
                                   " -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" +
                                   " -upnp " + useUpnpBox.Selected +
                                   " -playercount " + maxPlayersBox.Text +
                                   " -ownerkey " + ownerKey.ToString();

                string filename = "DedicatedServer.exe";
#if LINUX
                filename = "./DedicatedServer";
#elif OSX
                filename  = "mono";
                arguments = "./DedicatedServer.exe " + arguments;
#endif
                var processInfo = new ProcessStartInfo
                {
                    FileName  = filename,
                    Arguments = arguments
#if !DEBUG
                    ,
                    WindowStyle = ProcessWindowStyle.Hidden
#endif
                };
                GameMain.ServerChildProcess = Process.Start(processInfo);
                Thread.Sleep(1000); //wait until the server is ready before connecting

                GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(), ownerKey);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to start server", e);
            }

            return(true);
        }
        public MultiPlayerCampaignSetupUI(GUIComponent newGameContainer, GUIComponent loadGameContainer, IEnumerable <SubmarineInfo> submarines, IEnumerable <string> saveFiles = null)
            : base(newGameContainer, loadGameContainer)
        {
            var columnContainer = new GUILayoutGroup(new RectTransform(Vector2.One, newGameContainer.RectTransform), isHorizontal: true)
            {
                Stretch         = true,
                RelativeSpacing = 0.0f
            };

            var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            var rightColumn = new GUILayoutGroup(new RectTransform(Vector2.Zero, columnContainer.RectTransform))
            {
                Stretch         = true,
                RelativeSpacing = 0.015f
            };

            columnContainer.Recalculate();

            // New game left side
            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("SaveName"), font: GUI.SubHeadingFont);
            saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, string.Empty)
            {
                textFilterFunction = (string str) => { return(ToolBox.RemoveInvalidFileNameChars(str)); }
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, TextManager.Get("MapSeed"), font: GUI.SubHeadingFont);
            seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform)
            {
                MinSize = new Point(0, 20)
            }, ToolBox.RandomSeed(8));

            // Spacing to fix the multiplayer campaign setup layout
            CreateMultiplayerCampaignSubList(leftColumn.RectTransform);

            //spacing
            //new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), leftColumn.RectTransform), style: null);

            // New game right side
            subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), rightColumn.RectTransform))
            {
                Stretch = true
            };

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.12f),
                                                                       leftColumn.RectTransform)
            {
                MaxSize = new Point(int.MaxValue, 60)
            }, childAnchor: Anchor.BottomRight, isHorizontal: true);

            StartButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1f), buttonContainer.RectTransform, Anchor.BottomRight)
            {
                MaxSize = new Point(350, 60)
            }, TextManager.Get("StartCampaignButton"))
            {
                OnClicked = (GUIButton btn, object userData) =>
                {
                    if (string.IsNullOrWhiteSpace(saveNameBox.Text))
                    {
                        saveNameBox.Flash(GUI.Style.Red);
                        return(false);
                    }

                    SubmarineInfo selectedSub = null;

                    if (GameMain.NetLobbyScreen.SelectedSub == null)
                    {
                        return(false);
                    }
                    selectedSub = GameMain.NetLobbyScreen.SelectedSub;

                    if (selectedSub.SubmarineClass == SubmarineClass.Undefined)
                    {
                        new GUIMessageBox(TextManager.Get("error"), TextManager.Get("undefinedsubmarineselected"));
                        return(false);
                    }

                    if (string.IsNullOrEmpty(selectedSub.MD5Hash.Hash))
                    {
                        ((GUITextBlock)subList.SelectedComponent).TextColor = Color.DarkRed * 0.8f;
                        subList.SelectedComponent.CanBeFocused = false;
                        subList.Deselect();
                        return(false);
                    }

                    string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveNameBox.Text);
                    bool   hasRequiredContentPackages = selectedSub.RequiredContentPackagesInstalled;

                    CampaignSettings settings = new CampaignSettings();

                    settings.RadiationEnabled = GameMain.NetLobbyScreen.IsRadiationEnabled();
                    settings.MaxMissionCount  = GameMain.NetLobbyScreen.GetMaxMissionCount();

                    if (selectedSub.HasTag(SubmarineTag.Shuttle) || !hasRequiredContentPackages)
                    {
                        if (!hasRequiredContentPackages)
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ContentPackageMismatch"),
                                                           TextManager.GetWithVariable("ContentPackageMismatchWarning", "[requiredcontentpackages]", string.Join(", ", selectedSub.RequiredContentPackages)),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked  = msgBox.Close;
                            msgBox.Buttons[0].OnClicked += (button, obj) =>
                            {
                                if (GUIMessageBox.MessageBoxes.Count == 0)
                                {
                                    StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                                    CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                }
                                return(true);
                            };

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                        }

                        if (selectedSub.HasTag(SubmarineTag.Shuttle))
                        {
                            var msgBox = new GUIMessageBox(TextManager.Get("ShuttleSelected"),
                                                           TextManager.Get("ShuttleWarning"),
                                                           new string[] { TextManager.Get("Yes"), TextManager.Get("No") });

                            msgBox.Buttons[0].OnClicked = (button, obj) =>
                            {
                                StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                                CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                                return(true);
                            };
                            msgBox.Buttons[0].OnClicked += msgBox.Close;

                            msgBox.Buttons[1].OnClicked = msgBox.Close;
                            return(false);
                        }
                    }
                    else
                    {
                        StartNewGame?.Invoke(selectedSub, savePath, seedBox.Text, settings);
                        CoroutineManager.StartCoroutine(WaitForCampaignSetup(), "WaitForCampaignSetup");
                    }

                    return(true);
                }
            };

            InitialMoneyText = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1f), buttonContainer.RectTransform), "", font: GUI.Style.SmallFont, textColor: GUI.Style.Green)
            {
                TextGetter = () =>
                {
                    int initialMoney = CampaignMode.InitialMoney;
                    if (GameMain.NetLobbyScreen.SelectedSub != null)
                    {
                        initialMoney -= GameMain.NetLobbyScreen.SelectedSub.Price;
                    }
                    initialMoney = Math.Max(initialMoney, MultiPlayerCampaign.MinimumInitialMoney);
                    return(TextManager.GetWithVariable("campaignstartingmoney", "[money]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", initialMoney)));
                }
            };

            columnContainer.Recalculate();
            leftColumn.Recalculate();
            rightColumn.Recalculate();

            if (submarines != null)
            {
                UpdateSubList(submarines);
            }
            UpdateLoadMenu(saveFiles);
        }
Пример #25
0
            public GUIMessageBox Create()
            {
                var box = new GUIMessageBox(TextManager.Get("LevelEditorCreateLevelObj"), string.Empty, 
                    new string[] { TextManager.Get("Cancel"), TextManager.Get("Done") }, GameMain.GraphicsWidth / 2, (int)(GameMain.GraphicsHeight * 0.8f));

                box.Content.ChildAnchor = Anchor.TopCenter;
                box.Content.AbsoluteSpacing = 20;
                int elementSize = 30;
                var listBox = new GUIListBox(new RectTransform(new Vector2(1, 0.9f), box.Content.RectTransform));

                new GUITextBlock(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform), 
                    TextManager.Get("LevelEditorLevelObjName")) { CanBeFocused = false };
                var nameBox = new GUITextBox(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform));

                new GUITextBlock(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform), 
                    TextManager.Get("LevelEditorLevelObjTexturePath")) { CanBeFocused = false };
                var texturePathBox = new GUITextBox(new RectTransform(new Point(listBox.Content.Rect.Width, elementSize), listBox.Content.RectTransform));
                foreach (LevelObjectPrefab prefab in LevelObjectPrefab.List)
                {
                    if (prefab.Sprite == null) continue;
                    texturePathBox.Text = Path.GetDirectoryName(prefab.Sprite.FilePath);
                    break;
                }

                newPrefab = new LevelObjectPrefab(null);

                new SerializableEntityEditor(listBox.Content.RectTransform, newPrefab, false, false);
                
                box.Buttons[0].OnClicked += (b, d) =>
                {
                    box.Close();
                    return true;
                };
                // Next
                box.Buttons[1].OnClicked += (b, d) =>
                {
                    if (string.IsNullOrEmpty(nameBox.Text))
                    {
                        nameBox.Flash(Color.Red);
                        GUI.AddMessage(TextManager.Get("LevelEditorLevelObjNameEmpty"), Color.Red);
                        return false;
                    }
                    
                    if (LevelObjectPrefab.List.Any(obj => obj.Name.ToLower() == nameBox.Text.ToLower()))
                    {
                        nameBox.Flash(Color.Red);
                        GUI.AddMessage(TextManager.Get("LevelEditorLevelObjNameTaken"), Color.Red);
                        return false;
                    }

                    if (!File.Exists(texturePathBox.Text))
                    {
                        texturePathBox.Flash(Color.Red);
                        GUI.AddMessage(TextManager.Get("LevelEditorLevelObjTextureNotFound"), Color.Red);
                        return false;
                    }

                    newPrefab.Name = nameBox.Text;
                    
                    XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
                    foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.LevelObjectPrefabs))
                    {
                        XDocument doc = XMLExtensions.TryLoadXml(configFile);
                        if (doc?.Root == null) continue;
                        var newElement = new XElement(newPrefab.Name);
                        newPrefab.Save(newElement);
                        newElement.Add(new XElement("Sprite", 
                            new XAttribute("texture", texturePathBox.Text), 
                            new XAttribute("sourcerect", "0,0,100,100"),
                            new XAttribute("origin", "0.5,0.5")));

                        doc.Root.Add(newElement);
                        using (var writer = XmlWriter.Create(configFile, settings))
                        {
                            doc.WriteTo(writer);
                            writer.Flush();
                        }
                        break;
                    }

                    LevelObjectPrefab.List.Add(newPrefab);
                    GameMain.LevelEditorScreen.UpdateLevelObjectsList();

                    box.Close();
                    return true;
                };
                return box;
            }