Ejemplo n.º 1
0
        private static void OnDownloadProgressChanged(MyGuiScreenProgress progress, MyDownloadWorldResult result, MyMultiplayerBase multiplayer)
        {
            switch (result.State)
            {
            case MyDownloadWorldStateEnum.Success:
                progress.CloseScreen();
                var world = multiplayer.ProcessWorldDownloadResult(result);

                CheckDx11AndJoin(world, multiplayer);
                break;

            case MyDownloadWorldStateEnum.InProgress:
                if (result.ReceivedBlockCount == 1)
                {
                    MyLog.Default.WriteLine("First world part received");
                }
                string percent   = (result.Progress * 100).ToString("0.");
                float  size      = result.ReceivedDatalength;
                string prefix    = MyUtils.FormatByteSizePrefix(ref size);
                string worldSize = size.ToString("0.") + " " + prefix + "B";
                if (progress.Text != null)
                {
                    progress.Text.Clear();
                }
                if (float.IsNaN(result.Progress))
                {
                    MyLog.Default.WriteLine("World requested - preemble received");
                    if (progress.Text != null)
                    {
                        progress.Text.Append(MyTexts.Get(MyCommonTexts.DialogWaitingForWorldData));
                    }
                }
                else
                {
                    if (progress.Text != null)
                    {
                        progress.Text.AppendFormat(MyTexts.GetString(MyCommonTexts.DialogTextDownloadingWorld), percent, worldSize);
                    }
                }
                break;

            case MyDownloadWorldStateEnum.WorldNotAvailable:
                MyLog.Default.WriteLine("World requested - world not available");
                progress.Cancel();
                MyGuiSandbox.Show(MyCommonTexts.DialogDownloadWorld_WorldDoesNotExists);
                multiplayer.Dispose();
                break;

            case MyDownloadWorldStateEnum.ConnectionFailed:
                MyLog.Default.WriteLine("World requested - connection failed");
                progress.Cancel();
                MyGuiSandbox.Show(MyTexts.AppendFormat(new StringBuilder(), MyCommonTexts.MultiplayerErrorConnectionFailed, result.ConnectionError));
                multiplayer.Dispose();
                break;

            case MyDownloadWorldStateEnum.DeserializationFailed:
            case MyDownloadWorldStateEnum.InvalidMessage:
                MyLog.Default.WriteLine("World requested - message invalid (wrong version?)");
                progress.Cancel();
                MyGuiSandbox.Show(MyCommonTexts.DialogTextDownloadWorldFailed);
                multiplayer.Dispose();
                break;

            default:
                throw new InvalidBranchException();
            }
        }
Ejemplo n.º 2
0
        private void CheckDx11AndStart()
        {
            bool needsDx11 = (m_scenarioTypesGroup.SelectedButton as MyGuiControlScenarioButton).Scenario.HasPlanets;

            if (!needsDx11)
            {
                StartNewSandbox();
            }
            else if (MySandboxGame.IsDirectX11)
            {
                StartNewSandbox();
            }
            else if (MyDirectXHelper.IsDx11Supported())
            {
                // Has DX11, ask for switch or selecting different scenario
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           callback: OnSwitchAnswer,
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.QuickstartDX11SwitchQuestion),
                                           buttonType: MyMessageBoxButtonsType.YES_NO));
            }
            else
            {
                // No DX11, ask for selecting another scenario
                var text = MyTexts.Get(MySpaceTexts.QuickstartNoDx9SelectDifferent);
                MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
                MyGuiSandbox.AddScreen(mb);
            }
        }
Ejemplo n.º 3
0
        static MyConveyorSorter()
        {
            drainAll        = new MyTerminalControlOnOffSwitch <MyConveyorSorter>("DrainAll", MySpaceTexts.Terminal_DrainAll);
            drainAll.Getter = (block) => block.DrainAll;
            drainAll.Setter = (block, val) => block.ChangeDrainAll(val);
            drainAll.EnableToggleAction();
            MyTerminalControlFactory.AddControl(drainAll);

            MyTerminalControlFactory.AddControl(new MyTerminalControlSeparator <MyConveyorSorter>());

            blacklistWhitelist = new MyTerminalControlCombobox <MyConveyorSorter>("blacklistWhitelist", MySpaceTexts.BlockPropertyTitle_ConveyorSorterFilterMode, MySpaceTexts.Blank);
            blacklistWhitelist.ComboBoxContent = (block) => FillBlWlCombo(block);
            blacklistWhitelist.Getter          = (block) => (long)(block.IsWhitelist ? 1 : 0);
            blacklistWhitelist.Setter          = (block, val) => block.ChangeBlWl(val == 1);
            MyTerminalControlFactory.AddControl(blacklistWhitelist);

            currentList              = new MyTerminalControlListbox <MyConveyorSorter>("CurrentList", MySpaceTexts.BlockPropertyTitle_ConveyorSorterFilterItemsList, MySpaceTexts.Blank, true);
            currentList.ListContent  = (block, list1, list2) => block.FillCurrentList(list1, list2);
            currentList.ItemSelected = (block, val) => block.SelectFromCurrentList(val);
            MyTerminalControlFactory.AddControl(currentList);

            removeFromSelectionButton = new MyTerminalControlButton <MyConveyorSorter>("removeFromSelectionButton",
                                                                                       MySpaceTexts.BlockPropertyTitle_ConveyorSorterRemove,
                                                                                       MySpaceTexts.Blank,
                                                                                       (block) => block.RemoveFromCurrentList());
            removeFromSelectionButton.Enabled = (x) => x.m_selectedForDelete != null && x.m_selectedForDelete.Count > 0;;
            MyTerminalControlFactory.AddControl(removeFromSelectionButton);

            candidates              = new MyTerminalControlListbox <MyConveyorSorter>("candidatesList", MySpaceTexts.BlockPropertyTitle_ConveyorSorterCandidatesList, MySpaceTexts.Blank, true);
            candidates.ListContent  = (block, list1, list2) => block.FillCandidatesList(list1, list2);
            candidates.ItemSelected = (block, val) => block.SelectCandidate(val);
            MyTerminalControlFactory.AddControl(candidates);

            addToSelectionButton = new MyTerminalControlButton <MyConveyorSorter>("addToSelectionButton",
                                                                                  MySpaceTexts.BlockPropertyTitle_ConveyorSorterAdd,
                                                                                  MySpaceTexts.Blank,
                                                                                  (x) => x.AddToCurrentList());
            addToSelectionButton.Enabled = (x) => x.m_selectedForAdd != null && x.m_selectedForAdd.Count > 0;
            MyTerminalControlFactory.AddControl(addToSelectionButton);

            byte index = 0;//warning: if you shuffle indexes, you will shuffle data in saved games

            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_AmmoMagazine), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ammo)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Component), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Component)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_PhysicalGunObject), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_HandTool)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ingot), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ingot)));
            CandidateTypes.Add(++index, new Tuple <MyObjectBuilderType, StringBuilder>(typeof(MyObjectBuilder_Ore), MyTexts.Get(MySpaceTexts.DisplayName_ConvSorterTypes_Ore)));
            foreach (var val in CandidateTypes)
            {
                CandidateTypesToId.Add(val.Value.Item1, val.Key);
            }
        }
Ejemplo n.º 4
0
        void OnUserJoined(ref JoinResultMsg msg, ulong sender)
        {
            if (msg.JoinResult == JoinResult.OK)
            {
                if (OnJoin != null)
                {
                    OnJoin();
                    OnJoin         = null;
                    m_clientJoined = true;
                }
            }
            else if (msg.JoinResult == JoinResult.NotInGroup)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong  groupId   = Server.GetGameTagByPrefixUlong("groupId");
                string groupName = MySteam.API.Friends.GetClanName(groupId);

                var messageBox = MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: new StringBuilder(string.Format(
                                                       MyTexts.GetString(MyCommonTexts.MultiplayerErrorNotInGroup), groupName)),
                    buttonType: MyMessageBoxButtonsType.YES_NO);
                messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                {
                    if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        MySteam.API.OpenOverlayUser(groupId);
                    }
                    ;
                };
                MyGuiSandbox.AddScreen(messageBox);
            }
            else if (msg.JoinResult == JoinResult.BannedByAdmins)
            {
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                Dispose();

                ulong admin = msg.Admin;

                if (admin != 0)
                {
                    var messageBox = MyGuiSandbox.CreateMessageBox(
                        messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                        messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdminsWithDialog),
                        buttonType: MyMessageBoxButtonsType.YES_NO);
                    messageBox.ResultCallback = delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (result == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteam.API.OpenOverlayUser(admin);
                        }
                        ;
                    };
                    MyGuiSandbox.AddScreen(messageBox);
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                               messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorBannedByAdmins)));
                }
            }
            else
            {
                MyStringId resultText = MyCommonTexts.MultiplayerErrorConnectionFailed;

                switch (msg.JoinResult)
                {
                case JoinResult.AlreadyJoined:
                    resultText = MyCommonTexts.MultiplayerErrorAlreadyJoined;
                    break;

                case JoinResult.ServerFull:
                    resultText = MyCommonTexts.MultiplayerErrorServerFull;
                    break;

                case JoinResult.SteamServersOffline:
                    resultText = MyCommonTexts.MultiplayerErrorSteamServersOffline;
                    break;

                case JoinResult.TicketInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorTicketInvalid;
                    break;

                case JoinResult.GroupIdInvalid:
                    resultText = MyCommonTexts.MultiplayerErrorGroupIdInvalid;
                    break;

                case JoinResult.TicketCanceled:
                    resultText = MyCommonTexts.MultiplayerErrorTicketCanceled;
                    break;

                case JoinResult.TicketAlreadyUsed:
                    resultText = MyCommonTexts.MultiplayerErrorTicketAlreadyUsed;
                    break;

                case JoinResult.LoggedInElseWhere:
                    resultText = MyCommonTexts.MultiplayerErrorLoggedInElseWhere;
                    break;

                case JoinResult.NoLicenseOrExpired:
                    resultText = MyCommonTexts.MultiplayerErrorNoLicenseOrExpired;
                    break;

                case JoinResult.UserNotConnected:
                    resultText = MyCommonTexts.MultiplayerErrorUserNotConnected;
                    break;

                case JoinResult.VACBanned:
                    resultText = MyCommonTexts.MultiplayerErrorVACBanned;
                    break;

                case JoinResult.VACCheckTimedOut:
                    resultText = MyCommonTexts.MultiplayerErrorVACCheckTimedOut;
                    break;

                default:
                    System.Diagnostics.Debug.Fail("Unknown JoinResult");
                    break;
                }

                Dispose();
                MyGuiScreenMainMenu.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(resultText)));
                return;
            }
        }
Ejemplo n.º 5
0
        private void PopulateOwnedCubeGrids(HashSet <CubeGridInfo> gridInfoList)
        {
            float scrollBarValue = m_shipsData.ScrollBar.Value;

            m_shipsData.Clear();
            foreach (var gridInfo in gridInfoList)
            {
                UserData data;
                MyGuiControlTable.Row  row;
                MyGuiControlTable.Cell nameCell, distanceCell, statusCell;

                data.GridEntityId = gridInfo.EntityId;
                if (gridInfo.Status == MyCubeGridConnectionStatus.Connected || gridInfo.Status == MyCubeGridConnectionStatus.PhysicallyConnected || gridInfo.Status == MyCubeGridConnectionStatus.Me)
                {
                    StringBuilder minDistance = new StringBuilder();
                    if (gridInfo.Status == MyCubeGridConnectionStatus.Connected)
                    {
                        minDistance = gridInfo.AppendedDistance.Append(" m");
                    }

                    data.IsSelectable = true;
                    nameCell          = new MyGuiControlTable.Cell(new StringBuilder(gridInfo.Name), textColor: Color.White);
                    distanceCell      = new MyGuiControlTable.Cell(minDistance, userData: gridInfo.Distance, textColor: Color.White);
                    switch (gridInfo.Status)
                    {
                    case MyCubeGridConnectionStatus.PhysicallyConnected:
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_PhysicallyConnected), userData: gridInfo.Status, textColor: Color.White);
                        break;

                    case MyCubeGridConnectionStatus.Me:
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_Me), userData: gridInfo.Status, textColor: Color.White);
                        break;

                    case MyCubeGridConnectionStatus.Connected:
                    default:
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_Connected), userData: gridInfo.Status, textColor: Color.White);
                        break;
                    }
                }

                else
                {
                    data.IsSelectable = false;
                    nameCell          = new MyGuiControlTable.Cell(new StringBuilder(gridInfo.Name), textColor: Color.Gray);
                    distanceCell      = new MyGuiControlTable.Cell(new StringBuilder(""), userData: float.MaxValue, textColor: Color.Gray);
                    if (gridInfo.Status == MyCubeGridConnectionStatus.OutOfReceivingRange)
                    {
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_OutOfReceivingRange), userData: gridInfo.Status, textColor: Color.Gray);
                    }
                    else if (gridInfo.Status == MyCubeGridConnectionStatus.OutOfBroadcastingRange)
                    {
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_OutOfBroadcastingRange), userData: gridInfo.Status, textColor: Color.Gray);
                    }
                    else
                    {
                        statusCell = new MyGuiControlTable.Cell(MyTexts.Get(MySpaceTexts.BroadcastStatus_IsPreviewGrid), userData: gridInfo.Status, textColor: Color.Gray);
                    }
                }

                row = new MyGuiControlTable.Row(data);
                row.AddCell(nameCell);
                row.AddCell(distanceCell);
                row.AddCell(statusCell);
                m_shipsData.Add(row);
                m_shipsData.SortByColumn(m_columnToSort, MyGuiControlTable.SortStateEnum.Ascending, false);
            }
            m_shipsData.ScrollBar.ChangeValue(scrollBarValue);
        }
Ejemplo n.º 6
0
    protected MyGuiControlButton MakeButton(Vector2 position, MyStringId text, Action <MyGuiControlButton> onClick, MyStringId?tooltip = null, MyStringId?gamepadHelpTextId = null)
    {
        MyGuiControlButton myGuiControlButton = new MyGuiControlButton(position, MyGuiControlButtonStyleEnum.StripeLeft, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, null, MyTexts.Get(text), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_CURSOR_OVER, onClick);

        if (tooltip.HasValue)
        {
            myGuiControlButton.SetToolTip(MyTexts.GetString(tooltip.Value));
        }
        myGuiControlButton.BorderEnabled          = false;
        myGuiControlButton.BorderSize             = 0;
        myGuiControlButton.BorderHighlightEnabled = false;
        myGuiControlButton.BorderColor            = Vector4.Zero;
        if (gamepadHelpTextId.HasValue)
        {
            myGuiControlButton.GamepadHelpTextId = gamepadHelpTextId.Value;
        }
        return(myGuiControlButton);
    }
Ejemplo n.º 7
0
        public static void Publish(MyObjectBuilder_Definitions prefab, string blueprintName, Action <ulong> publishCallback = null)
        {
            string file        = Path.Combine(m_localBlueprintFolder, blueprintName);
            string title       = prefab.ShipBlueprints[0].CubeGrids[0].DisplayName;
            string description = prefab.ShipBlueprints[0].Description;
            ulong  publishId   = prefab.ShipBlueprints[0].WorkshopId;

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       styleEnum : MyMessageBoxStyleEnum.Info,
                                       buttonType : MyMessageBoxButtonsType.YES_NO,
                                       messageCaption : new StringBuilder("Publish"),
                                       messageText : new StringBuilder("Do you want to publish this blueprint?"),
                                       callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
            {
                if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                {
                    Action <MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags)
                    {
                        if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MySteamWorkshop.PublishBlueprintAsync(file, title, description, publishId, outTags, SteamSDK.PublishedFileVisibility.Public,
                                                                  callbackOnFinished : delegate(bool success, Result result, ulong publishedFileId)
                            {
                                if (success)
                                {
                                    if (publishCallback != null)
                                    {
                                        publishCallback(publishedFileId);
                                    }

                                    prefab.ShipBlueprints[0].WorkshopId = publishedFileId;
                                    SavePrefabToFile(prefab, blueprintName, true);
                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               styleEnum: MyMessageBoxStyleEnum.Info,
                                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextWorldPublished),
                                                               messageCaption: new StringBuilder("BLUEPRINT PUBLISHED"),
                                                               callback: (a) =>
                                    {
                                        MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId));
                                    }));
                                }
                                else
                                {
                                    MyStringId error;
                                    switch (result)
                                    {
                                    case Result.AccessDenied:
                                        error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied;
                                        break;

                                    default:
                                        error = MyCommonTexts.MessageBoxTextWorldPublishFailed;
                                        break;
                                    }

                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               messageText: MyTexts.Get(error),
                                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublishFailed)));
                                }
                            });
                        }
                    };

                    if (MySteamWorkshop.BlueprintCategories.Length > 0)
                    {
                        MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_BLUEPRINT_TAG, MySteamWorkshop.BlueprintCategories, null, onTagsChosen));
                    }
                    else
                    {
                        onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_BLUEPRINT_TAG });
                    }
                }
            }));
        }
        void Reposition()
        {
            this.Size = new Vector2(this.Size.X, 0.12f * baseScale + itemHeight * BlockInfo.Components.Count);

            //BackgroundTexture =  @"Textures\GUI\Screens\aa";
            var topleft     = -this.Size / 2;
            var topRight    = new Vector2(this.Size.X / 2, -this.Size.Y / 2);
            var rightColumn = topleft + (m_progressMode ? new Vector2(0.0815f, 0) : new Vector2(0.036f, 0));

            var titleHeight = 0.072f * baseScale;

            Vector2 borderGap = new Vector2(0.0055f) * new Vector2(0.75f, 1) * baseScale;

            if (!m_progressMode)
            {
                borderGap.Y *= 0.5f;
            }

            m_installedRequiredLabel.TextToDraw = MyTexts.Get(BlockInfo.BlockIntegrity > 0 ? m_style.InstalledRequiredLabelText : m_style.RequiredLabelText);

            m_leftColumnBackground.ColorMask         = m_style.LeftColumnBackgroundColor;
            m_leftColumnBackground.Position          = topleft + borderGap;
            m_leftColumnBackground.Size              = new Vector2(rightColumn.X - topleft.X, this.Size.Y) - new Vector2(borderGap.X, 0.0088f);
            m_leftColumnBackground.BackgroundTexture = MyGuiConstants.TEXTURE_GUI_BLANK;

            m_titleBackground.ColorMask = m_style.TitleBackgroundColor;
            if (m_progressMode)
            {
                m_titleBackground.Position = rightColumn + new Vector2(-0.0015f, borderGap.Y);
            }
            else
            {
                m_titleBackground.Position = topleft + borderGap;
            }
            m_titleBackground.Size = new Vector2(topRight.X - m_titleBackground.Position.X - (m_progressMode ? borderGap.X : 0), 0.101f * baseScale);
            m_titleBackground.BackgroundTexture = MyGuiConstants.TEXTURE_GUI_BLANK;

            Vector2 separatorPos;

            if (m_progressMode)
            {
                separatorPos = rightColumn + new Vector2(0, titleHeight);
            }
            else
            {
                separatorPos = topleft + new Vector2(borderGap.X, titleHeight);
            }
            m_separator.Clear();
            m_separator.AddHorizontal(separatorPos, this.Size.X + topleft.X - separatorPos.X - 0.002f, 0.003f); // Title separator

            if (m_progressMode)
            {
                if (BlockInfo.BlockIntegrity > 0)
                {
                    float integrityHeight = itemHeight * BlockInfo.Components.Count - 0.002f;
                    float integrityWidth  = 0.032f;
                    var   integrityPos    = topleft + new Vector2(0.01f, 0.11f + integrityHeight);

                    m_integrityBackground.ColorMask         = m_style.IntegrityBackgroundColor;
                    m_integrityBackground.Position          = integrityPos;
                    m_integrityBackground.Size              = new Vector2(integrityWidth, integrityHeight);
                    m_integrityBackground.BackgroundTexture = MyGuiConstants.TEXTURE_GUI_BLANK;

                    var color = (BlockInfo.BlockIntegrity > BlockInfo.CriticalIntegrity)
                        ? m_style.IntegrityForegroundColorOverCritical
                        : m_style.IntegrityForegroundColor;

                    m_integrityForeground.ColorMask         = color;
                    m_integrityForeground.Position          = integrityPos;
                    m_integrityForeground.Size              = new Vector2(integrityWidth, integrityHeight * BlockInfo.BlockIntegrity);
                    m_integrityForeground.BackgroundTexture = MyGuiConstants.TEXTURE_GUI_BLANK;

                    if (ShowCriticalIntegrity)
                    {
                        float lineWidth = 0;
                        if (Math.Abs(BlockInfo.CriticalIntegrity - BlockInfo.OwnershipIntegrity) < 0.005f)
                        {
                            lineWidth = 0.004f; //if lines are overdrawing
                        }
                        m_separator.AddHorizontal(integrityPos - new Vector2(0, integrityHeight * BlockInfo.CriticalIntegrity), integrityWidth, width: lineWidth, color: CriticalIntegrityColor);
                    }

                    if (ShowOwnershipIntegrity && BlockInfo.OwnershipIntegrity > 0)
                    {
                        m_separator.AddHorizontal(integrityPos - new Vector2(0, integrityHeight * BlockInfo.OwnershipIntegrity), integrityWidth, color: OwnershipIntegrityColor);
                    }

                    m_integrityLabel.Position = integrityPos + new Vector2(integrityWidth / 2, -0.005f);
                    m_integrityLabel.Font     = MyFontEnum.White;
                    m_integrityLabel.TextToDraw.Clear();
                    m_integrityLabel.TextToDraw.AppendInt32((int)Math.Floor(BlockInfo.BlockIntegrity * 100)).Append("%");

                    m_integrityBackground.Visible = true;
                    m_integrityForeground.Visible = true;
                    m_integrityLabel.Visible      = true;
                }
                else
                {
                    m_integrityBackground.Visible = false;
                    m_integrityForeground.Visible = false;
                    m_integrityLabel.Visible      = false;
                }
            }

            if (m_progressMode)
            {
                m_blockNameLabel.Position = rightColumn + new Vector2(0.006f, 0.026f * baseScale);

                if (m_style.ShowAvailableComponents)
                {
                    Vector2 offset = new Vector2(0, -0.006f);
                    m_componentsLabel.Position = m_blockNameLabel.Position + new Vector2(0, m_blockNameLabel.Size.Y) + offset;
                    m_blockNameLabel.Position  = m_blockNameLabel.Position + offset;
                }
                else
                {
                    m_componentsLabel.Position = rightColumn + new Vector2(0.006f, 0.076f * baseScale);
                }

                m_blockNameLabel.Size              = new Vector2(Size.X / 2 - m_blockNameLabel.Position.X, m_blockNameLabel.Size.Y);
                m_blockTypeLabel.Visible           = false;
                m_blockTypePanel.Visible           = false;
                m_blockTypePanelBackground.Visible = false;
            }
            else
            {
                m_blockTypePanel.Position           = topRight + new Vector2(-0.0085f, 0.012f);
                m_blockTypePanelBackground.Position = topRight + new Vector2(-0.0085f, 0.012f);
                if (m_style.EnableBlockTypePanel)
                {
                    m_blockTypePanel.Visible           = true;
                    m_blockTypePanelBackground.Visible = true;

                    m_blockNameLabel.Size = new Vector2(m_blockTypePanel.Position.X - m_blockTypePanel.Size.X - m_blockNameLabel.Position.X, m_blockNameLabel.Size.Y);
                }
                else
                {
                    m_blockTypePanel.Visible           = false;
                    m_blockTypePanelBackground.Visible = false;

                    m_blockNameLabel.Size = new Vector2(m_blockTypePanel.Position.X - m_blockNameLabel.Position.X, m_blockNameLabel.Size.Y);
                }

                m_blockNameLabel.TextScale   = 0.95f * baseScale;
                m_blockNameLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                m_blockNameLabel.Position    = m_blockIconPanel.Position + m_blockIconPanel.Size + new Vector2(0.004f, 0);


                m_blockTypeLabel.Visible     = true;
                m_blockTypeLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
                m_blockTypeLabel.TextScale   = m_smallerFontSize * baseScale;
                m_blockTypeLabel.Position    = m_blockIconPanel.Position + new Vector2(m_blockIconPanel.Size.X, 0) + new Vector2(0.004f, -0.0025f);

                m_componentsLabel.Position = rightColumn + new Vector2(0.006f, 0.076f * baseScale);
            }

            m_installedRequiredLabel.Position = topRight + new Vector2(-0.011f, 0.076f * baseScale);

            m_blockIconPanel.Position           = topleft + new Vector2(0.0085f, 0.012f);
            m_blockIconPanelBackground.Position = topleft + new Vector2(0.0085f, 0.012f);

            Vector2 listPos;

            if (m_progressMode)
            {
                listPos = topleft + new Vector2(0.0485f, 0.102f);
            }
            else
            {
                listPos = topleft + new Vector2(0.008f, 0.102f * baseScale);
            }

            for (int i = 0; i < BlockInfo.Components.Count; i++)
            {
                m_componentLines[i].Position = listPos + new Vector2(0, (BlockInfo.Components.Count - i - 1) * itemHeight);
                m_componentLines[i].IconPanelProgress.Visible = ShowComponentProgress;
                m_componentLines[i].IconPanel.BorderColor     = CriticalComponentColor;
                m_componentLines[i].NameLabel.TextScale       = m_smallerFontSize * baseScale;
                m_componentLines[i].NumbersLabel.TextScale    = m_smallerFontSize * baseScale;
            }
        }
Ejemplo n.º 9
0
 protected virtual void StartQuickstart()
 {
     // TODO: Move to derived screen in SpaceEngineers.Game
     if (MySandboxGame.IsDirectX11) // Running DirectX11, start planet quickstart
     {
         QuickstartSandbox(GetQuickstartSettings(), CreatePlanetQuickstartArgs());
     }
     else if (MyDirectXHelper.IsDx11Supported()) // DirectX11 not enabled, messagebox
     {
         MyScreenManager.RemoveAllScreensExcept(null);
         var text = MyTexts.Get(MySpaceTexts.QuickstartDX11SwitchQuestion);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), buttonType: MyMessageBoxButtonsType.YES_NO, callback: MessageBoxSwitchCallback);
         MyGuiSandbox.AddScreen(mb);
     }
     else // DirectX11 not supported, show message, start easy start 1
     {
         MyScreenManager.RemoveAllScreensExcept(null);
         var text = MyTexts.Get(MySpaceTexts.QuickstartDX11NotAvailable);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), callback: StartNoPlanetsOK);
         MyGuiSandbox.AddScreen(mb);
     }
 }
Ejemplo n.º 10
0
        private void Refresh()
        {
            m_needsRefresh = false;
            var items = Data;

            StringBuilder stateText = null;

            switch (State)
            {
            case MyHudCharacterStateEnum.Crouching: stateText = MyTexts.Get(MySpaceTexts.HudInfoCrouching); break;

            case MyHudCharacterStateEnum.Standing: stateText = MyTexts.Get(MySpaceTexts.HudInfoStanding); break;

            case MyHudCharacterStateEnum.Falling: stateText = MyTexts.Get(MySpaceTexts.HudInfoFalling); break;

            case MyHudCharacterStateEnum.Flying: stateText = MyTexts.Get(MySpaceTexts.HudInfoFlying); break;

            case MyHudCharacterStateEnum.PilotingLargeShip: stateText = MyTexts.Get(MySpaceTexts.HudInfoPilotingLargeShip); break;

            case MyHudCharacterStateEnum.PilotingSmallShip: stateText = MyTexts.Get(MySpaceTexts.HudInfoPilotingSmallShip); break;

            case MyHudCharacterStateEnum.ControllingStation: stateText = MyTexts.Get(MySpaceTexts.HudInfoControllingStation); break;

            default:
                Debug.Fail("Missing character state.");
                break;
            }

            if (MySession.Static.Settings.EnableOxygen)
            {
                items[(int)LineEnum.CharacterState].Value.Clear().AppendStringBuilder(MyTexts.Get(MySpaceTexts.HudInfoHelmet)).Append(" ").AppendStringBuilder(GetOnOffText(IsHelmetOn));
            }

            items[(int)LineEnum.CharacterState].Name.Clear().AppendStringBuilder(stateText);
            items[(int)LineEnum.Lights].Value.Clear().AppendStringBuilder(GetOnOffText(LightEnabled));
            items[(int)LineEnum.Mass].Value.Clear().AppendInt32(Mass).Append(" kg");
            items[(int)LineEnum.Speed].Value.Clear().AppendDecimal(Speed, 1).Append(" m/s");
            items[(int)LineEnum.Jetpack].Value.Clear().AppendStringBuilder(GetOnOffText(JetpackEnabled));
            items[(int)LineEnum.Dampeners].Value.Clear().AppendStringBuilder(GetOnOffText(DampenersEnabled));
            items[(int)LineEnum.BroadcastOn].Value.Clear().AppendStringBuilder(GetOnOffText(BroadcastEnabled));
            items[(int)LineEnum.Oxygen].Value.Clear().AppendDecimal(OxygenLevel * 100f, 1).Append(" %");

            items[(int)LineEnum.Lights].Visible    = true;
            items[(int)LineEnum.Mass].Visible      = true;
            items[(int)LineEnum.Speed].Visible     = true;
            items[(int)LineEnum.Dampeners].Visible = true;


            var energyItem    = items[(int)LineEnum.Energy];
            var healthItem    = items[(int)LineEnum.Health];
            var inventoryItem = items[(int)LineEnum.Inventory];
            var oxygenItem    = items[(int)LineEnum.Oxygen];

            energyItem.Value.Clear().AppendDecimal((float)Math.Round(BatteryEnergy, 1), 1).Append(" %");
            healthItem.Value.Clear().AppendDecimal(HealthRatio * 100f, 0).Append(" %");
            inventoryItem.Value.Clear().AppendDecimal((double)InventoryVolume * 1000, 0).Append(" l");
            energyItem.NameFont = energyItem.ValueFont = IsBatteryEnergyLow ? (MyFontEnum?)MyFontEnum.Red : null;
            healthItem.NameFont = healthItem.ValueFont = IsHealthLow ? (MyFontEnum?)MyFontEnum.Red : null;
            if (!MySession.Static.CreativeMode)
            {
                inventoryItem.NameFont = inventoryItem.ValueFont = IsInventoryFull ? (MyFontEnum?)MyFontEnum.Red : null;
            }

            items[(int)LineEnum.BroadcastRange].Value.Clear().AppendDecimal(BroadcastRange, 0).Append(" m");

            oxygenItem.NameFont = oxygenItem.ValueFont = IsOxygenLevelLow ? (MyFontEnum?)MyFontEnum.Red : null;
            oxygenItem.Visible  = MySession.Static.Settings.EnableOxygen;
        }
Ejemplo n.º 11
0
 private StringBuilder GetOnOffText(bool value)
 {
     return((value) ? MyTexts.Get(MySpaceTexts.HudInfoOn)
                    : MyTexts.Get(MySpaceTexts.HudInfoOff));
 }
Ejemplo n.º 12
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            string filepath = MakeScreenFilepath("MedicalsScreen");
            MyObjectBuilder_GuiScreen objectBuilder;

            var fsPath = Path.Combine(MyFileSystem.ContentPath, filepath);

            MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_GuiScreen>(fsPath, out objectBuilder);
            Init(objectBuilder);

            m_multilineRespawnWhenShipReady = new MyGuiControlMultilineText()
            {
                Position     = new Vector2(0, -0.5f * Size.Value.Y + 80f / MyGuiConstants.GUI_OPTIMAL_SIZE.Y),
                Size         = new Vector2(Size.Value.X * 0.85f, 75f / MyGuiConstants.GUI_OPTIMAL_SIZE.Y),
                Font         = MyFontEnum.Red,
                OriginAlign  = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP,
                TextAlign    = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
                TextBoxAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
            };

            Controls.Add(m_multilineRespawnWhenShipReady);

            UpdateRespawnShipLabel();

            m_respawnsTable                  = new MyGuiControlTable();
            m_respawnsTable.Position         = new Vector2(0, -0.01f);
            m_respawnsTable.Size             = new Vector2(550f / MyGuiConstants.GUI_OPTIMAL_SIZE.X, 1.3f);
            m_respawnsTable.OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_respawnsTable.VisibleRowsCount = 17;
            Controls.Add(m_respawnsTable);

            m_respawnsTable.ColumnsCount       = 2;
            m_respawnsTable.ItemSelected      += OnTableItemSelected;
            m_respawnsTable.ItemDoubleClicked += OnTableItemDoubleClick;
            m_respawnsTable.SetCustomColumnWidths(new float[] { 0.50f, 0.50f });

            m_respawnsTable.SetColumnName(0, MyTexts.Get(MySpaceTexts.Name));
            m_respawnsTable.SetColumnName(1, MyTexts.Get(MySpaceTexts.ScreenMedicals_OwnerTimeoutColumn));

            m_labelNoRespawn = new MyGuiControlLabel()
            {
                Position    = new Vector2(0, -0.35f),
                ColorMask   = Color.Red,
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP
            };
            Controls.Add(m_labelNoRespawn);

            m_respawnButton = new MyGuiControlButton(
                position: new Vector2(-0.1f, 0.35f),
                text: MyTexts.Get(MySpaceTexts.Respawn),
                onButtonClick: onRespawnClick
                );
            Controls.Add(m_respawnButton);

            m_refreshButton = new MyGuiControlButton(
                position: new Vector2(0.1f, 0.35f),
                text: MyTexts.Get(MySpaceTexts.Refresh),
                onButtonClick: onRefreshClick
                );
            Controls.Add(m_refreshButton);

            m_noRespawnText = new MyGuiControlMultilineText(
                position: new Vector2(-0.02f, -0.19f),
                size: new Vector2(0.32f, 0.5f),
                contents: MyTexts.Get(MySpaceTexts.ScreenMedicals_NoRespawnPossible),
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                font: MyFontEnum.Red
                );
            Controls.Add(m_noRespawnText);

            RefreshRespawnPoints();
        }
Ejemplo n.º 13
0
        private void RefreshGameList()
        {
            m_gamesTable.Clear();
            AddHeaders();

            m_textCache.Clear();
            m_gameTypeText.Clear();
            m_gameTypeToolTip.Clear();

            m_lobbyPage.Text = MyTexts.Get(MySpaceTexts.JoinGame_TabTitle_Lobbies);

            if (m_lobbies != null)
            {
                int shownGames = 0;
                for (int i = 0; i < m_lobbies.Count; ++i)
                {
                    var lobby = m_lobbies[i];
                    var row   = new MyGuiControlTable.Row(lobby);

                    string sessionName = MyMultiplayerLobby.GetLobbyWorldName(lobby);
                    ulong  sessionSize = MyMultiplayerLobby.GetLobbyWorldSize(lobby);
                    int    appVersion  = MyMultiplayerLobby.GetLobbyAppVersion(lobby);
                    int    modCount    = MyMultiplayerLobby.GetLobbyModCount(lobby);

                    var searchName = m_blockSearch.Text.Trim();
                    if (!string.IsNullOrWhiteSpace(searchName) && !sessionName.ToLower().Contains(searchName.ToLower()))
                    {
                        continue;
                    }

                    m_gameTypeText.Clear();
                    m_gameTypeToolTip.Clear();
                    if (appVersion > 01022000)
                    {
                        var inventory = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.InventoryMultiplierTag, lobby, 1);
                        var refinery  = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.RefineryMultiplierTag, lobby, 1);
                        var assembler = MyMultiplayerLobby.GetLobbyFloat(MyMultiplayer.AssemblerMultiplierTag, lobby, 1);

                        MyGameModeEnum gameMode = MyMultiplayerLobby.GetLobbyGameMode(lobby);
                        bool           isBattle = MyMultiplayerLobby.GetLobbyBattle(lobby);
                        switch (gameMode)
                        {
                        case MyGameModeEnum.Creative:
                            m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeCreative));
                            break;

                        case MyGameModeEnum.Survival:
                            if (MyFakes.ENABLE_BATTLE_SYSTEM && isBattle)
                            {
                                m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_Battle));
                            }
                            else
                            {
                                m_gameTypeText.AppendStringBuilder(MyTexts.Get(MySpaceTexts.WorldSettings_GameModeSurvival));
                                m_gameTypeText.Append(String.Format(" {0}-{1}-{2}", inventory, assembler, refinery));
                            }
                            break;

                        default:
                            Debug.Fail("Unknown game type");
                            break;
                        }

                        m_gameTypeToolTip.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_MultipliersFormat).ToString(), inventory, assembler, refinery);

                        var viewDistance = MyMultiplayerLobby.GetLobbyViewDistance(lobby);
                        m_gameTypeToolTip.AppendLine();
                        m_gameTypeToolTip.AppendFormat(MyTexts.Get(MySpaceTexts.JoinGame_GameTypeToolTip_ViewDistance).ToString(), viewDistance);
                    }

                    // Skip world without name (not fully initialized)
                    if (string.IsNullOrEmpty(sessionName))
                    {
                        continue;
                    }

                    // Show only same app versions
                    if (m_showOnlyCompatibleGames.IsChecked && appVersion != MyFinalBuildConstants.APP_VERSION)
                    {
                        continue;
                    }

                    // Show only if the game data match
                    if (m_showOnlyWithSameMods.IsChecked && MyFakes.ENABLE_MP_DATA_HASHES && !MyMultiplayerLobby.HasSameData(lobby))
                    {
                        continue;
                    }

                    float  sessionFormattedSize = (float)sessionSize;
                    string owner     = MyMultiplayerLobby.GetLobbyHostName(lobby);
                    string limit     = lobby.MemberLimit.ToString();
                    string userCount = lobby.MemberCount + "/" + limit;

                    var prefixSize = MyUtils.FormatByteSizePrefix(ref sessionFormattedSize);

                    var modListToolTip = new StringBuilder();

                    int displayedModsMax = 15;
                    int lastMod          = Math.Min(displayedModsMax, modCount - 1);
                    foreach (var mod in MyMultiplayerLobby.GetLobbyMods(lobby))
                    {
                        if (displayedModsMax-- <= 0)
                        {
                            modListToolTip.Append("...");
                            break;
                        }

                        if (lastMod-- <= 0)
                        {
                            modListToolTip.Append(mod.FriendlyName);
                        }
                        else
                        {
                            modListToolTip.AppendLine(mod.FriendlyName);
                        }
                    }

                    //row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(MyMultiplayerLobby.HasSameData(lobby) ? "" : "*")));
                    row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(sessionName), userData: lobby.LobbyId, toolTip: m_textCache.ToString()));
                    row.AddCell(new MyGuiControlTable.Cell(text: m_gameTypeText, toolTip: (m_gameTypeToolTip.Length > 0) ? m_gameTypeToolTip.ToString() : null));
                    row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(sessionFormattedSize.ToString("0.") + prefixSize + "B    ")));
                    row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(owner), toolTip: m_textCache.ToString()));
                    row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(userCount)));
                    row.AddCell(new MyGuiControlTable.Cell(text: m_textCache.Clear().Append(modCount == 0 ? "---" : modCount.ToString()), toolTip: modListToolTip.ToString()));
                    m_gamesTable.Add(row);
                    shownGames++;
                }

                m_lobbyPage.Text = new StringBuilder().Append(MyTexts.Get(MySpaceTexts.JoinGame_TabTitle_Lobbies).ToString()).Append(" (").Append(shownGames).Append(")");
            }

            //m_gameDataLabel.Visible = m_incompatibleGameData;

            m_gamesTable.SelectedRowIndex = null;
        }
Ejemplo n.º 14
0
        public static void JoinGame(GameServerItem server)
        {
            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join);
            if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION)
            {
                var sb = new StringBuilder();
                sb.AppendFormat(MyTexts.GetString(MyCommonTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion);
                MyGuiSandbox.Show(sb, MyCommonTexts.MessageBoxCaptionError);
                return;
            }
            if (MyFakes.ENABLE_MP_DATA_HASHES)
            {
                var serverHash = server.GetGameTagByPrefix("datahash");
                if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64())
                {
                    MyGuiSandbox.Show(MyCommonTexts.MultiplayerError_DifferentData);
                    MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash);
                    return;
                }
            }

            UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp);

            MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel)));

            MyMultiplayer.Static = multiplayer;
            MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false;
            MyMultiplayer.Static.SyncLayer.RegisterGameEvents();

            multiplayer.SendPlayerData(MySteam.UserName);

            string gamemode = server.GetGameTagByPrefix("gamemode");

            if (MyFakes.ENABLE_BATTLE_SYSTEM && gamemode == "B")
            {
                StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningBattle);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    MyGuiScreenMainMenu.ReturnToMainMenu();
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoinBattle(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                    {
                        EnterState = LobbyEnterResponseEnum.Success
                    }, multiplayer);
                };
            }
            else
            {
                StringBuilder text = MyTexts.Get(MyCommonTexts.DialogTextJoiningWorld);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MyCommonTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    if (MyMultiplayer.Static != null)
                    {
                        MyMultiplayer.Static.Dispose();
                    }
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                    {
                        EnterState = LobbyEnterResponseEnum.Success
                    }, multiplayer);
                };
            }
        }
        public MyGuiScreenOptionsAudio()
            : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, size: new Vector2(1030f, 572f) / MyGuiConstants.GUI_OPTIMAL_SIZE)
        {
            EnabledBackgroundFade = true;

            AddCaption(MyCommonTexts.ScreenCaptionAudioOptions);

            var   topLeft      = m_size.Value * -0.5f;
            var   topCenter    = m_size.Value * new Vector2(0f, -0.5f);
            var   bottomCenter = m_size.Value * (MyPerGameSettings.VoiceChatEnabled ? new Vector2(0f, 0.7f) : new Vector2(0f, 0.6f));
            float startHeight  = MyPerGameSettings.VoiceChatEnabled? 150f : 170f;

            Vector2 controlsOriginLeft  = topLeft + new Vector2(110f, startHeight) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            Vector2 controlsOriginRight = topCenter + new Vector2(-25f, startHeight) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            Vector2 controlsDelta       = new Vector2(0f, 60f) / MyGuiConstants.GUI_OPTIMAL_SIZE;

            //  Game Volume
            Controls.Add(new MyGuiControlLabel(
                             position: controlsOriginLeft + 0 * controlsDelta,
                             text: MyTexts.GetString(MyCommonTexts.GameVolume),
                             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
            m_gameVolumeSlider = new MyGuiControlSlider(
                position: controlsOriginRight + 0 * controlsDelta,
                minValue: MyAudioConstants.GAME_MASTER_VOLUME_MIN,
                maxValue: MyAudioConstants.GAME_MASTER_VOLUME_MAX,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_gameVolumeSlider.ValueChanged = OnGameVolumeChange;
            Controls.Add(m_gameVolumeSlider);

            //  Music Volume
            Controls.Add(new MyGuiControlLabel(
                             position: controlsOriginLeft + 1 * controlsDelta,
                             text: MyTexts.GetString(MyCommonTexts.MusicVolume),
                             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
            m_musicVolumeSlider = new MyGuiControlSlider(
                position: controlsOriginRight + 1 * controlsDelta,
                minValue: MyAudioConstants.MUSIC_MASTER_VOLUME_MIN,
                maxValue: MyAudioConstants.MUSIC_MASTER_VOLUME_MAX,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_musicVolumeSlider.ValueChanged = OnMusicVolumeChange;
            Controls.Add(m_musicVolumeSlider);

            Controls.Add(new MyGuiControlLabel(
                             position: controlsOriginLeft + 2 * controlsDelta,
                             text: MyTexts.GetString(MyCommonTexts.HudWarnings),
                             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
            m_hudWarnings = new MyGuiControlCheckbox(
                position: controlsOriginRight + 2 * controlsDelta,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_hudWarnings.IsCheckedChanged = HudWarningsChecked;
            Controls.Add(m_hudWarnings);

            Controls.Add(new MyGuiControlLabel(
                             position: controlsOriginLeft + 3 * controlsDelta,
                             text: MyTexts.GetString(MyCommonTexts.MuteWhenNotInFocus),
                             originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
            m_enableMuteWhenNotInFocus = new MyGuiControlCheckbox(
                position: controlsOriginRight + 3 * controlsDelta,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_enableMuteWhenNotInFocus.IsCheckedChanged = EnableMuteWhenNotInFocusChecked;
            Controls.Add(m_enableMuteWhenNotInFocus);

            // Voice chat
            if (MyPerGameSettings.VoiceChatEnabled)
            {
                Controls.Add(new MyGuiControlLabel(
                                 position: controlsOriginLeft + 4 * controlsDelta,
                                 text: MyTexts.GetString(MyCommonTexts.EnableVoiceChat),
                                 originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));
            }
            m_enableVoiceChat = new MyGuiControlCheckbox(
                position: controlsOriginRight + 4 * controlsDelta,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_enableVoiceChat.IsCheckedChanged = VoiceChatChecked;

            m_voiceChatVolumeSlider = new MyGuiControlSlider(
                position: controlsOriginRight + 5 * controlsDelta,
                minValue: MyAudioConstants.VOICE_CHAT_VOLUME_MIN,
                maxValue: MyAudioConstants.VOICE_CHAT_VOLUME_MAX,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_voiceChatVolumeSlider.ValueChanged = OnVoiceChatVolumeChange;

            if (MyPerGameSettings.VoiceChatEnabled)
            {
                // voice char checkbox
                Controls.Add(m_enableVoiceChat);

                // label for voice chat
                Controls.Add(new MyGuiControlLabel(
                                 position: controlsOriginLeft + 5 * controlsDelta,
                                 text: MyTexts.GetString(MyCommonTexts.VoiceChatVolume),
                                 originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER));

                // adding of slider for volume of voice chat
                Controls.Add(m_voiceChatVolumeSlider);
            }

            //  Buttons OK and CANCEL

            var m_okButton = new MyGuiControlButton(
                position: bottomCenter + new Vector2(-75f, -130f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                size: MyGuiConstants.OK_BUTTON_SIZE,
                text: MyTexts.Get(MyCommonTexts.Ok),
                onButtonClick: OnOkClick,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);

            Controls.Add(m_okButton);

            var m_cancelButton = new MyGuiControlButton(
                position: bottomCenter + new Vector2(75f, -130f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                size: MyGuiConstants.OK_BUTTON_SIZE,
                text: MyTexts.Get(MyCommonTexts.Cancel),
                onButtonClick: OnCancelClick,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);

            Controls.Add(m_cancelButton);


            //  Update controls with values from config file
            UpdateFromConfig(m_settingsOld);
            UpdateFromConfig(m_settingsNew);
            UpdateControls(m_settingsOld);

            CloseButtonEnabled = true;
            CloseButtonOffset  = MakeXAndYEqual(new Vector2(-0.006f, 0.006f));

            m_gameAudioPausedWhenOpen = MyAudio.Static.GameSoundIsPaused;
            if (m_gameAudioPausedWhenOpen)
            {
                MyAudio.Static.ResumeGameSounds();
            }
        }
Ejemplo n.º 16
0
 void MessageBoxSwitchCallback(MyGuiScreenMessageBox.ResultEnum result)
 {
     if (result == MyGuiScreenMessageBox.ResultEnum.YES)
     {
         MySandboxGame.Config.GraphicsRenderer = MySandboxGame.DirectX11RendererKey;
         MySandboxGame.Config.Save();
         var text = MyTexts.Get(MySpaceTexts.QuickstartDX11PleaseRestartGame);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), callback: OnPleaseRestart);
         MyGuiSandbox.AddScreen(mb);
     }
     else
     {
         var text = MyTexts.Get(MySpaceTexts.QuickstartNoPlanets);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), callback: StartNoPlanetsOK);
         MyGuiSandbox.AddScreen(mb);
     }
 }
Ejemplo n.º 17
0
 private void RefreshQuote()
 {
     m_quoteTextControl.TextEnum = m_currentQuote.Text;
     m_authorWithDash.Clear().Append("- ").AppendStringBuilder(MyTexts.Get(m_currentQuote.Author)).Append(" -");
 }
Ejemplo n.º 18
0
        public void OnBattleClick(MyGuiControlButton sender)
        {
            if (MySteam.IsOnline)
            {
                if (MyFakes.ENABLE_TUTORIAL_PROMPT && MySandboxGame.Config.NeedShowBattleTutorialQuestion)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(buttonType : MyMessageBoxButtonsType.YES_NO,
                                                                         messageText : MyTexts.Get(MySpaceTexts.MessageBoxTextTutorialQuestion),
                                                                         messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionVideoTutorial),
                                                                         callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
                    {
                        if (val == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            MyGuiSandbox.OpenUrlWithFallback(MySteamConstants.URL_GUIDE_BATTLE, "Steam Guide");
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleScreen));
                        }
                    }));

                    MySandboxGame.Config.NeedShowBattleTutorialQuestion = false;
                    MySandboxGame.Config.Save();
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleScreen));
                }
            }
            else
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           buttonType: MyMessageBoxButtonsType.OK,
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.SteamIsOfflinePleaseRestart)
                                           ));
            }
        }
Ejemplo n.º 19
0
 protected void CheckLowMemSwitchToLow()
 {
     if (MySandboxGame.Config.LowMemSwitchToLow != MyConfig.LowMemSwitch.TRIGGERED)
     {
         return;
     }
     MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO, messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText : MyTexts.Get(MySpaceTexts.LowMemSwitchToLowQuestion), okButtonText : null, cancelButtonText : null, yesButtonText : null, noButtonText : null, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
     {
         if (result == MyGuiScreenMessageBox.ResultEnum.YES)
         {
             MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.ARMED;
             MySandboxGame.Config.SetToLowQuality();
             MySandboxGame.Config.Save();
             if (MySpaceAnalytics.Instance != null)
             {
                 MySpaceAnalytics.Instance.ReportSessionEnd("Exit to Windows");
             }
             MyScreenManager.CloseAllScreensNowExcept(null, isUnloading: true);
             MySandboxGame.ExitThreadSafe();
         }
         else
         {
             MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.USER_SAID_NO;
             MySandboxGame.Config.Save();
         }
     }));
 }
Ejemplo n.º 20
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            AddCaption(MyCommonTexts.ScreenCaptionNewWorld);

            Vector2 menuPositionOrigin = new Vector2(0.0f, -m_size.Value.Y / 2.0f + (0.147f - m_additionalButtons * 0.013f));
            Vector2 buttonDelta        = new Vector2(0.15f, 0);

            //MyStringId? otherButtonsForbidden = null;
            //MyStringId newGameText = MySpaceTexts.StartDemo;
            int buttonPositionCounter = 0;

            if (MyPerGameSettings.EnableTutorials)
            {
                // tutorials
                var tutorialButton = new MyGuiControlButton(
                    position: menuPositionOrigin + buttonPositionCounter++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
                    text: MyTexts.Get(MySpaceTexts.ScreenCaptionTutorials),
                    //toolTip: MyTexts.GetString(MySpaceTexts.ToolTipNewWorldCustomWorld),
                    onButtonClick: OnTutorialClick);

                Controls.Add(tutorialButton);
            }

            //  Quickstart
            var quickstartButton = new MyGuiControlButton(
                position: menuPositionOrigin + buttonPositionCounter++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
                text: MyTexts.Get(MyCommonTexts.ScreenNewWorldButtonQuickstart),
                toolTip: MyTexts.GetString(MySpaceTexts.ToolTipNewWorldQuickstart),
                onButtonClick: OnQuickstartClick);

            //  Custom Game
            var customGameButton = new MyGuiControlButton(
                position: menuPositionOrigin + buttonPositionCounter++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
                text: MyTexts.Get(MyCommonTexts.ScreenNewWorldButtonCustomWorld),
                toolTip: MyTexts.GetString(MyCommonTexts.ToolTipNewWorldCustomWorld),
                onButtonClick: OnCustomGameClick);

            Controls.Add(quickstartButton);
            Controls.Add(customGameButton);

            if (MyPerGameSettings.EnableScenarios)
            {
                //  scenarios
                var scenarioButton = new MyGuiControlButton(
                    position: menuPositionOrigin + buttonPositionCounter++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
                    text: MyTexts.Get(MySpaceTexts.ScreenCaptionScenario),
                    //toolTip: MyTexts.GetString(MySpaceTexts.ToolTipNewWorldCustomWorld),
                    onButtonClick: OnScenarioGameClick);

                Controls.Add(scenarioButton);
            }

            if (MyFakes.ENABLE_BATTLE_SYSTEM)
            {
                var battleButton = new MyGuiControlButton(
                    position: menuPositionOrigin + buttonPositionCounter++ *MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
                    text: MyTexts.Get(MySpaceTexts.ScreenButtonBattle),
                    //toolTip: MyTexts.GetString(MySpaceTexts.ToolTipNewWorldCustomWorld),
                    onButtonClick: OnBattleClick);

                Controls.Add(battleButton);
            }

            CloseButtonEnabled = true;
        }
Ejemplo n.º 21
0
        public static void LoadMission(string sessionPath, bool multiplayer, MyOnlineModeEnum onlineMode, short maxPlayers)
        {
            MyLog.Default.WriteLine("LoadSession() - Start");
            MyLog.Default.WriteLine(sessionPath);

            ulong checkpointSizeInBytes;
            var   checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes);

            checkpoint.Settings.OnlineMode       = onlineMode;
            checkpoint.Settings.MaxPlayers       = maxPlayers;
            checkpoint.Settings.Scenario         = true;
            checkpoint.Settings.GameMode         = MyGameModeEnum.Survival;
            checkpoint.Settings.ScenarioEditMode = false;

            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (checkpoint.BriefingVideo != null && checkpoint.BriefingVideo.Length > 0)
            {
                MyGuiSandbox.OpenUrlWithFallback(checkpoint.BriefingVideo, "Scenario briefing video");
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }


            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                    // May be called from gameplay, so we must make sure we unload the current game
                    if (MySession.Static != null)
                    {
                        MySession.Static.Unload();
                        MySession.Static = null;
                    }

                    //seed 0 has special meaning - please randomize at mission start. New seed will be saved and game will run with it ever since.
                    //  if you use this, YOU CANNOT HAVE ANY PROCEDURAL ASTEROIDS ALREADY SAVED
                    if (checkpoint.Settings.ProceduralSeed == 0)
                    {
                        checkpoint.Settings.ProceduralSeed = MyRandom.Instance.Next();
                    }

                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        checkpoint.Settings.Scenario = true;
                        MySession.LoadMission(sessionPath, checkpoint, checkpointSizeInBytes);
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed).ToString());
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText : MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                    {
                        if (MyFakes.QUICK_LAUNCH != null)
                        {
                            MyGuiScreenMainMenu.ReturnToMainMenu();
                        }
                    }));
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Ejemplo n.º 22
0
        protected override void CreateTerminalControls()
        {
            if (MyTerminalControlFactory.AreControlsCreated <MyProgrammableBlock>())
            {
                return;
            }
            base.CreateTerminalControls();
            var console = new MyTerminalControlButton <MyProgrammableBlock>("Edit", MySpaceTexts.TerminalControlPanel_EditCode, MySpaceTexts.TerminalControlPanel_EditCode_Tooltip, (b) => b.SendOpenEditorRequest());

            console.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts;
            MyTerminalControlFactory.AddControl(console);

            var arg = new MyTerminalControlTextbox <MyProgrammableBlock>("ConsoleCommand", MySpaceTexts.TerminalControlPanel_RunArgument, MySpaceTexts.TerminalControlPanel_RunArgument_ToolTip);

            arg.Visible = (e) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts;
            arg.Getter  = (e) => new StringBuilder(e.TerminalRunArgument);
            arg.Setter  = (e, v) => e.TerminalRunArgument = v.ToString();
            MyTerminalControlFactory.AddControl(arg);

            var terminalRun = new MyTerminalControlButton <MyProgrammableBlock>("TerminalRun", MySpaceTexts.TerminalControlPanel_RunCode, MySpaceTexts.TerminalControlPanel_RunCode_Tooltip, (b) => b.Run());

            terminalRun.Visible = (b) => MyFakes.ENABLE_PROGRAMMABLE_BLOCK && MySession.Static.EnableIngameScripts;
            terminalRun.Enabled = (b) => b.IsWorking == true && b.IsFunctional == true;
            MyTerminalControlFactory.AddControl(terminalRun);

            var runAction = new MyTerminalAction <MyProgrammableBlock>("Run", MyTexts.Get(MySpaceTexts.TerminalControlPanel_RunCode), OnRunApplied, null, MyTerminalActionIcons.START);

            runAction.Enabled = (b) => b.IsFunctional == true;
            runAction.DoUserParameterRequest = RequestRunArgument;
            runAction.ParameterDefinitions.Add(TerminalActionParameter.Get(string.Empty));
            MyTerminalControlFactory.AddAction(runAction);

            var runwithDefault = new MyTerminalAction <MyProgrammableBlock>("RunWithDefaultArgument", MyTexts.Get(MySpaceTexts.TerminalControlPanel_RunCodeDefault), OnRunDefaultApplied, MyTerminalActionIcons.START);

            runwithDefault.Enabled = (b) => b.IsFunctional == true;
            MyTerminalControlFactory.AddAction(runwithDefault);
        }
Ejemplo n.º 23
0
        private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo)
        {
            if (indicator.Entity == null)
            {
                return;
            }

            Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position);
            //gravity += MyPhysics.HavokWorld.Gravity;
            bool anyGravity = !MyUtils.IsZero(gravity.Length());

            // Background and text drawing
            MyFontEnum    font;
            StringBuilder text;

            m_hudIndicatorText.Clear();
            m_hudIndicatorText.AppendFormatedDecimal("", gravity.Length() / 9.81f, 1, " g");
            MyGuiPaddedTexture bg;

            if (anyGravity)
            {
                font = MyFontEnum.Blue;
                text = MyTexts.Get(MySpaceTexts.HudInfoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            }
            else
            {
                font = MyFontEnum.Red;
                text = MyTexts.Get(MySpaceTexts.HudInfoNoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED;
            }

            bool    drawOxygen  = MySession.Static.Settings.EnableOxygen;
            Vector2 bgSizeDelta = new Vector2(0.015f, 0f);
            float   oxygenLevel = 0f;

            Vector2 bgSize = bg.SizeGui + bgSizeDelta;

            Vector2            bgPos, textPos, gTextPos, position;
            MyGuiDrawAlignEnum align;

            if (indicator.Entity is MyCharacter)
            {
                bgPos    = new Vector2(0.99f, 0.99f);
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos - bgSize * new Vector2(0.94f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos - bgSize * new Vector2(0.56f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                oxygenLevel = (indicator.Entity as MyCharacter).EnvironmentOxygenLevel;
            }
            else
            {
                bgPos    = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f));
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos + bgSize * new Vector2(1 - 0.94f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos + bgSize * new Vector2(1 - 0.56f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(-0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                var cockpit = indicator.Entity as MyCockpit;
                if (cockpit != null && cockpit.Pilot != null)
                {
                    oxygenLevel = cockpit.Pilot.EnvironmentOxygenLevel;
                }
                else
                {
                    drawOxygen = false;
                }
            }

            if (drawOxygen)
            {
                bgSizeDelta += new Vector2(0f, 0.025f);
            }

            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui + bgSizeDelta, Color.White, align);

            MyGuiManager.DrawString(font, text, textPos, m_textScale);

            if (drawOxygen)
            {
                var oxygenFont = MyFontEnum.Blue;
                var oxygenText = new StringBuilder("Oxygen: ");
                if (oxygenLevel == 0f)
                {
                    oxygenText.Append("None");
                    oxygenFont = MyFontEnum.Red;
                }
                else if (oxygenLevel < 0.5f)
                {
                    oxygenText.Append("Low");
                    oxygenFont = MyFontEnum.Red;
                }
                else
                {
                    oxygenText.Append("High");
                }

                MyGuiManager.DrawString(oxygenFont, oxygenText, textPos - new Vector2(0f, 0.025f), m_textScale);
            }

            if (anyGravity)
            {
                MyGuiManager.DrawString(MyFontEnum.White, m_hudIndicatorText, gTextPos, m_textScale);
            }

            position = MyGuiManager.GetHudSize() * ConvertNormalizedGuiToHud(ref position);
            if (MyVideoSettingsManager.IsTripleHead())
            {
                position.X += 1.0f;
            }

            // Draw each of gravity indicators.
            foreach (var generatorGravity in MyGravityProviderSystem.GravityVectors)
            {
                DrawGravityVectorIndicator(position, generatorGravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);
            }

            //if (MyPhysics.HavokWorld.Gravity != Vector3.Zero)
            //    DrawGravityVectorIndicator(position, MyPhysics.HavokWorld.Gravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);

            if (anyGravity)
            {
                DrawGravityVectorIndicator(position, gravity, MyHudTexturesEnum.gravity_arrow, Color.White);
            }

            // Draw center
            MyAtlasTextureCoordinate centerTextCoord;

            if (anyGravity)
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_white);
            }
            else
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_red);
            }

            float   hudSizeX    = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float   hudSizeY    = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            Vector2 rightVector = Vector2.UnitX;

            MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                position,
                centerTextCoord.Offset,
                centerTextCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                MyHudConstants.HUD_COLOR_LIGHT,
                Vector2.One * 0.005f);
        }
 private void OnClickNewWorld(MyGuiControlButton sender)
 {
     if (MyFakes.ENABLE_TUTORIAL_PROMPT && MySandboxGame.Config.NeedShowTutorialQuestion)
     {
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(buttonType : MyMessageBoxButtonsType.YES_NO,
                                                              messageText : MyTexts.Get(MyPerGameSettings.EnableTutorials ? MySpaceTexts.MessageBoxTextTutorialQuestion : MyCommonTexts.MessageBoxTextGuideQuestion),
                                                              messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionTutorial),
                                                              callback : delegate(MyGuiScreenMessageBox.ResultEnum val)
         {
             if (val == MyGuiScreenMessageBox.ResultEnum.YES)
             {
                 MyAnalyticsHelper.ReportTutorialScreen("FirstTime");
                 MyGuiSandbox.OpenUrlWithFallback(MySteamConstants.URL_GUIDE_DEFAULT, "Steam Guide");
             }
             else
             {
                 MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenStartSandbox>());
             }
         }));
         MySandboxGame.Config.NeedShowTutorialQuestion = false;
         MySandboxGame.Config.Save();
     }
     else
     {
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen <MyGuiScreenStartSandbox>());
     }
 }
Ejemplo n.º 25
0
        protected virtual void BuildControls()
        {
            Vector2 buttonSize    = MyGuiConstants.BACK_BUTTON_SIZE;
            Vector2 buttonsOrigin = m_size.Value / 2 - new Vector2(0.23f, 0.03f);

            if (m_isNewGame)
            {
                AddCaption(MyCommonTexts.ScreenCaptionCustomWorld);
            }
            else
            {
                AddCaption(MyCommonTexts.ScreenCaptionEditSettings);
            }

            int numControls = 0;

            var nameLabel        = MakeLabel(MyCommonTexts.Name);
            var descriptionLabel = MakeLabel(MyCommonTexts.Description);
            var gameModeLabel    = MakeLabel(MyCommonTexts.WorldSettings_GameMode);
            var onlineModeLabel  = MakeLabel(MyCommonTexts.WorldSettings_OnlineMode);

            m_maxPlayersLabel = MakeLabel(MyCommonTexts.MaxPlayers);
            var environmentLabel = MakeLabel(MySpaceTexts.WorldSettings_EnvironmentHostility);
            var scenarioLabel    = MakeLabel(MySpaceTexts.WorldSettings_Scenario);
            var soundModeLabel   = MakeLabel(MySpaceTexts.WorldSettings_SoundMode);

            float width = 0.284375f + 0.025f;

            m_nameTextbox        = new MyGuiControlTextbox(maxLength: MySession.MAX_NAME_LENGTH);
            m_descriptionTextbox = new MyGuiControlTextbox(maxLength: MySession.MAX_DESCRIPTION_LENGTH);
            m_onlineMode         = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_environment        = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_maxPlayersSlider   = new MyGuiControlSlider(
                position: Vector2.Zero,
                width: m_onlineMode.Size.X,
                minValue: 2,
                maxValue: 16,
                labelText: new StringBuilder("{0}").ToString(),
                labelDecimalPlaces: 0,
                labelSpaceWidth: 0.05f,
                intValue: true
                );



            m_asteroidAmountLabel = MakeLabel(MySpaceTexts.Asteroid_Amount);
            m_asteroidAmountCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));

            m_asteroidAmountCombo.ItemSelected += m_asteroidAmountCombo_ItemSelected;
            m_soundModeCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));

            m_scenarioTypesList = new MyGuiControlList();

            // Ok/Cancel
            m_okButton     = new MyGuiControlButton(position: buttonsOrigin - new Vector2(0.01f, 0f), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Ok), onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_cancelButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(0.01f, 0f), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Cancel), onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);

            m_creativeModeButton = new MyGuiControlButton(visualStyle: MyGuiControlButtonStyleEnum.Small, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_GameModeCreative), onButtonClick: OnCreativeClick);
            m_creativeModeButton.SetToolTip(MySpaceTexts.ToolTipWorldSettingsModeCreative);
            m_survivalModeButton = new MyGuiControlButton(visualStyle: MyGuiControlButtonStyleEnum.Small, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_GameModeSurvival), onButtonClick: OnSurvivalClick);
            m_survivalModeButton.SetToolTip(MySpaceTexts.ToolTipWorldSettingsModeSurvival);

            m_onlineMode.ItemSelected += OnOnlineModeSelect;
            m_onlineMode.AddItem((int)MyOnlineModeEnum.OFFLINE, MyCommonTexts.WorldSettings_OnlineModeOffline);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PRIVATE, MyCommonTexts.WorldSettings_OnlineModePrivate);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.FRIENDS, MyCommonTexts.WorldSettings_OnlineModeFriends);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PUBLIC, MyCommonTexts.WorldSettings_OnlineModePublic);

            m_environment.AddItem((int)MyEnvironmentHostilityEnum.SAFE, MySpaceTexts.WorldSettings_EnvironmentHostilitySafe);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.NORMAL, MySpaceTexts.WorldSettings_EnvironmentHostilityNormal);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.CATACLYSM, MySpaceTexts.WorldSettings_EnvironmentHostilityCataclysm);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.CATACLYSM_UNREAL, MySpaceTexts.WorldSettings_EnvironmentHostilityCataclysmUnreal);
            m_environment.ItemSelected += HostilityChanged;

            m_soundModeCombo.AddItem((int)MySoundModeEnum.Arcade, MySpaceTexts.WorldSettings_ArcadeSound);
            m_soundModeCombo.AddItem((int)MySoundModeEnum.Realistic, MySpaceTexts.WorldSettings_RealisticSound);

            if (m_isNewGame)
            {
                if (MyDefinitionManager.Static.GetScenarioDefinitions().Count == 0)
                {
                    MyDefinitionManager.Static.LoadScenarios();
                }

                m_scenarioTypesGroup = new MyGuiControlRadioButtonGroup();
                m_scenarioTypesGroup.SelectedChanged += scenario_SelectedChanged;
                foreach (var scenario in MyDefinitionManager.Static.GetScenarioDefinitions())
                {
                    if (!scenario.Public && !MyFakes.ENABLE_NON_PUBLIC_SCENARIOS)
                    {
                        continue;
                    }

                    var button = new MyGuiControlScenarioButton(scenario);
                    m_scenarioTypesGroup.Add(button);
                    m_scenarioTypesList.Controls.Add(button);
                }
            }

            m_nameTextbox.SetToolTip(string.Format(MyTexts.GetString(MyCommonTexts.ToolTipWorldSettingsName), MySession.MIN_NAME_LENGTH, MySession.MAX_NAME_LENGTH));
            m_descriptionTextbox.SetToolTip(MyTexts.GetString(MyCommonTexts.ToolTipWorldSettingsDescription));
            m_environment.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsEnvironment));
            m_onlineMode.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsOnlineMode));
            m_maxPlayersSlider.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsMaxPlayer));
            m_asteroidAmountCombo.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsAsteroidAmount));
            m_soundModeCombo.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsSoundMode));

            m_nameTextbox.TextChanged     += m_nameTextbox_TextChanged;
            m_soundModeCombo.ItemSelected += m_soundModeCombo_ItemSelected;

            var advanced = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MySpaceTexts.WorldSettings_Advanced), onButtonClick: OnAdvancedClick);

#if !XB1 // XB1_NOWORKSHOP
            var mods = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_Mods), onButtonClick: OnModsClick);
#endif // !XB1

            m_worldGeneratorButton = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MySpaceTexts.WorldSettings_WorldGenerator), onButtonClick: OnWorldGeneratorClick);

            // Add controls in pairs; label first, control second. They will be laid out automatically this way.
            Controls.Add(nameLabel);
            Controls.Add(m_nameTextbox);
            Controls.Add(descriptionLabel);
            Controls.Add(m_descriptionTextbox);

            Controls.Add(gameModeLabel);
            Controls.Add(m_creativeModeButton);

            if (MyFakes.ENABLE_NEW_SOUNDS)
            {
                Controls.Add(soundModeLabel);
                Controls.Add(m_soundModeCombo);
            }

            Controls.Add(onlineModeLabel);
            Controls.Add(m_onlineMode);
            Controls.Add(m_maxPlayersLabel);
            Controls.Add(m_maxPlayersSlider);

            if (MyFakes.ENABLE_METEOR_SHOWERS)
            {
                Controls.Add(environmentLabel);
                Controls.Add(m_environment);
            }

            if (m_isNewGame && MyFakes.ENABLE_PLANETS == false)
            {
                Controls.Add(m_asteroidAmountLabel);
                Controls.Add(m_asteroidAmountCombo);
            }

            var blockLimitsLabel = MakeLabel(MyCommonTexts.WorldSettings_BlockLimits);
            m_blockLimits = new MyGuiControlCheckbox();
            m_blockLimits.IsCheckedChanged = blockLimits_CheckedChanged;
            m_blockLimits.SetToolTip(MyTexts.GetString(MyCommonTexts.ToolTipWorldSettingsBlockLimits));
            Controls.Add(blockLimitsLabel);
            Controls.Add(m_blockLimits);

            var autoSaveLabel = MakeLabel(MyCommonTexts.WorldSettings_AutoSave);
            m_autoSave = new MyGuiControlCheckbox();
            m_autoSave.SetToolTip(new StringBuilder().AppendFormat(MyCommonTexts.ToolTipWorldSettingsAutoSave, MyObjectBuilder_SessionSettings.DEFAULT_AUTOSAVE_IN_MINUTES).ToString());
            Controls.Add(autoSaveLabel);
            Controls.Add(m_autoSave);

#if !XB1 // XB1_NOWORKSHOP
            if (!MyFakes.XB1_PREVIEW)
            {
                if (MyFakes.ENABLE_WORKSHOP_MODS)
                {
                    Controls.Add(mods);
                }
            }
#endif // !XB1

            Controls.Add(advanced);

            if (m_isNewGame && MyFakes.ENABLE_PLANETS == true)
            {
                Controls.Add(m_worldGeneratorButton);
            }

            float labelSize = 0.20f;

            float MARGIN_TOP    = 0.12f;
            float MARGIN_BOTTOM = 0.12f;
            float MARGIN_LEFT   = m_isNewGame ? 0.315f : 0.08f;
            float MARGIN_RIGHT  = m_isNewGame ? 0.075f : 0.045f;

            // Automatic layout.
            Vector2 originL, originC;
            Vector2 controlsDelta = new Vector2(0f, 0.052f);
            float   rightColumnOffset;
            originL           = -m_size.Value / 2 + new Vector2(MARGIN_LEFT, MARGIN_TOP);
            originC           = originL + new Vector2(labelSize, 0f);
            rightColumnOffset = originC.X + m_onlineMode.Size.X - labelSize - 0.017f;

            foreach (var control in Controls)
            {
                control.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
                if (control is MyGuiControlLabel)
                {
                    control.Position = originL + controlsDelta * numControls;
                }
                else
                {
                    control.Position = originC + controlsDelta * numControls++;
                }
            }

            Controls.Add(m_survivalModeButton);
            m_survivalModeButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            m_survivalModeButton.Position    = m_creativeModeButton.Position + new Vector2(m_onlineMode.Size.X, 0);

            if (m_isNewGame)
            {
                Vector2 scenarioPosition = new Vector2(-0.375f, nameLabel.Position.Y);

                m_nameTextbox.Size        = m_onlineMode.Size;
                m_descriptionTextbox.Size = m_nameTextbox.Size;

                scenarioLabel.Position = scenarioPosition;

                m_scenarioTypesList.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
                m_scenarioTypesList.Position    = scenarioLabel.Position + new Vector2(0, 0.02f);
                m_scenarioTypesList.Size        = new Vector2(0.19f, m_size.Value.Y - MARGIN_BOTTOM - MARGIN_TOP);
                Controls.Add(scenarioLabel);
                Controls.Add(m_scenarioTypesList);

                MyGuiControlSeparatorList m_verticalLine = new MyGuiControlSeparatorList();
                Vector2 position = nameLabel.Position + new Vector2(-0.025f, -0.02f);
                m_verticalLine.AddVertical(position, m_size.Value.Y - MARGIN_BOTTOM - MARGIN_TOP + 0.04f);
                Controls.Add(m_verticalLine);
            }

            var pos2 = advanced.Position;
            //pos2.X = m_isNewGame ? 0.160f : 0.0f;
            pos2.X = Size.HasValue ? Size.Value.X / 2.0f - advanced.Size.X - MARGIN_RIGHT : 0.0f;
            advanced.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            advanced.Position    = pos2;

#if !XB1 // XB1_NOWORKSHOP
            mods.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            mods.Position    = advanced.Position - new Vector2(advanced.Size.X + 0.017f, 0);
#endif // !XB1

            m_worldGeneratorButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            m_worldGeneratorButton.Position    = advanced.Position - new Vector2(advanced.Size.X + 0.017f, -0.06f);

            if (MyFakes.XB1_PREVIEW)
            {
                var pos2p = m_worldGeneratorButton.Position;
                pos2p.X = Size.HasValue ? Size.Value.X / 2.0f - m_worldGeneratorButton.Size.X - MARGIN_RIGHT : 0.0f;
                m_worldGeneratorButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                m_worldGeneratorButton.Position    = pos2p;

                advanced.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                if (m_isNewGame)
                {
                    advanced.Position = m_worldGeneratorButton.Position - new Vector2(m_worldGeneratorButton.Size.X + 0.017f, 0);
                }
                else
                {
                    advanced.Position = m_worldGeneratorButton.Position - new Vector2(m_worldGeneratorButton.Size.X + 0.017f, 0.008f);
                }
            }

            Controls.Add(m_okButton);
            Controls.Add(m_cancelButton);

            CloseButtonEnabled = true;
        }
Ejemplo n.º 26
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);
            var layout = new MyLayoutTable(this);

            layout.SetColumnWidthsNormalized(50, 300, 300, 300, 300, 300, 50);
            layout.SetRowHeightsNormalized(50, 450, 70, 70, 70, 400, 70, 70, 50);

            //BRIEFING:
            MyGuiControlParent briefing = new MyGuiControlParent();
            var briefingScrollableArea  = new MyGuiControlScrollablePanel(
                scrolledControl: briefing)
            {
                Name = "BriefingScrollableArea",
                ScrollbarVEnabled   = true,
                OriginAlign         = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                BackgroundTexture   = MyGuiConstants.TEXTURE_SCROLLABLE_LIST,
                ScrolledAreaPadding = new MyGuiBorderThickness(0.005f),
            };

            layout.AddWithSize(briefingScrollableArea, MyAlignH.Left, MyAlignV.Top, 1, 1, rowSpan: 4, colSpan: 3);
            //inside scrollable area:
            m_descriptionBox = new MyGuiControlMultilineText(
                position: new Vector2(0.0f, 0.0f),
                size: new Vector2(1f, 1f),
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                selectable: false);
            briefing.Controls.Add(m_descriptionBox);

            m_connectedPlayers                  = new MyGuiControlTable();
            m_connectedPlayers.Size             = new Vector2(490f, 150f) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            m_connectedPlayers.VisibleRowsCount = 8;
            m_connectedPlayers.ColumnsCount     = 2;
            m_connectedPlayers.SetCustomColumnWidths(new float[] { 0.7f, 0.3f });
            m_connectedPlayers.SetColumnName(0, MyTexts.Get(MySpaceTexts.GuiScenarioPlayerName));
            m_connectedPlayers.SetColumnName(1, MyTexts.Get(MySpaceTexts.GuiScenarioPlayerStatus));

            m_kickPlayerButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.Kick), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                        size: new Vector2(190f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnKick2Clicked);
            m_kickPlayerButton.Enabled = CanKick();

            m_timeoutLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.GuiScenarioTimeout), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

            TimeoutCombo = new MyGuiControlCombobox();
            TimeoutCombo.ItemSelected += OnTimeoutSelected;
            TimeoutCombo.AddItem(3, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout3min));
            TimeoutCombo.AddItem(5, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout5min));
            TimeoutCombo.AddItem(10, MyTexts.Get(MySpaceTexts.GuiScenarioTimeout10min));
            TimeoutCombo.AddItem(-1, MyTexts.Get(MySpaceTexts.GuiScenarioTimeoutUnlimited));
            TimeoutCombo.SelectItemByIndex(0);
            TimeoutCombo.Enabled = Sync.IsServer;

            m_canJoinRunningLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.ScenarioSettings_CanJoinRunningShort), originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
            m_canJoinRunning      = new MyGuiControlCheckbox();

            m_canJoinRunningLabel.Enabled = false;
            m_canJoinRunning.Enabled      = false;

            m_startButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.GuiScenarioStart), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                   size: new Vector2(200, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnStartClicked);
            m_startButton.Enabled = Sync.IsServer;

            m_chatControl = new MyHudControlChat(
                MyHud.Chat,
                size: new Vector2(1400f, 300f) / MyGuiConstants.GUI_OPTIMAL_SIZE,
                font: MyFontEnum.DarkBlue,
                textScale: 0.7f,
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM,
                backgroundColor: MyGuiConstants.THEMED_GUI_BACKGROUND_COLOR,
                contents: null,
                drawScrollbar: true,
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);
            m_chatControl.BorderEnabled = true;
            m_chatControl.BorderColor   = Color.CornflowerBlue;

            m_chatTextbox               = new MyGuiControlTextbox(maxLength: ChatMessageBuffer.MAX_MESSAGE_SIZE);
            m_chatTextbox.Size          = new Vector2(1400f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE;
            m_chatTextbox.TextScale     = 0.8f;
            m_chatTextbox.VisualStyle   = MyGuiControlTextboxStyleEnum.Default;
            m_chatTextbox.EnterPressed += ChatTextbox_EnterPressed;

            m_sendChatButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.GuiScenarioSend), visualStyle: MyGuiControlButtonStyleEnum.Rectangular, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE,
                                                      size: new Vector2(190f, 48f) / MyGuiConstants.GUI_OPTIMAL_SIZE, onButtonClick: OnSendChatClicked);


            layout.AddWithSize(m_connectedPlayers, MyAlignH.Left, MyAlignV.Top, 1, 4, rowSpan: 2, colSpan: 2);

            layout.AddWithSize(m_kickPlayerButton, MyAlignH.Left, MyAlignV.Center, 2, 5);
            layout.AddWithSize(m_timeoutLabel, MyAlignH.Left, MyAlignV.Center, 3, 4);
            layout.AddWithSize(TimeoutCombo, MyAlignH.Left, MyAlignV.Center, 3, 5);

            layout.AddWithSize(m_canJoinRunningLabel, MyAlignH.Left, MyAlignV.Center, 4, 4);
            layout.AddWithSize(m_canJoinRunning, MyAlignH.Right, MyAlignV.Center, 4, 5);

            layout.AddWithSize(m_chatControl, MyAlignH.Left, MyAlignV.Top, 5, 1, rowSpan: 1, colSpan: 5);

            layout.AddWithSize(m_chatTextbox, MyAlignH.Left, MyAlignV.Top, 6, 1, rowSpan: 1, colSpan: 4);
            layout.AddWithSize(m_sendChatButton, MyAlignH.Right, MyAlignV.Top, 6, 5);

            layout.AddWithSize(m_startButton, MyAlignH.Left, MyAlignV.Top, 7, 2);
        }
Ejemplo n.º 27
0
 void OnSwitchAnswer(MyGuiScreenMessageBox.ResultEnum result)
 {
     if (result == MyGuiScreenMessageBox.ResultEnum.YES)
     {
         MySandboxGame.Config.GraphicsRenderer = MySandboxGame.DirectX11RendererKey;
         MySandboxGame.Config.Save();
         MyGuiSandbox.BackToMainMenu();
         var text = MyTexts.Get(MySpaceTexts.QuickstartDX11PleaseRestartGame);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
         MyGuiSandbox.AddScreen(mb);
     }
     else
     {
         var text = MyTexts.Get(MySpaceTexts.QuickstartSelectDifferent);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
         MyGuiSandbox.AddScreen(mb);
     }
 }
Ejemplo n.º 28
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            CloseButtonEnabled = true;

            var caption             = AddCaption(MyCommonTexts.ScreenCaptionPlayers);
            var captionCenter       = MyUtils.GetCoordCenterFromAligned(caption.Position, caption.Size, caption.OriginAlign);
            var captionBottomCenter = captionCenter + new Vector2(0f, 0.5f * caption.Size.Y);

            Vector2 sizeScale = Size.Value / MyGuiConstants.TEXTURE_SCREEN_BACKGROUND.SizeGui;
            Vector2 topLeft   = -0.5f * Size.Value + sizeScale * MyGuiConstants.TEXTURE_SCREEN_BACKGROUND.PaddingSizeGui * 1.1f;

            float verticalSpacing = 0.0045f;

            m_lobbyTypeCombo = new MyGuiControlCombobox(
                position: new Vector2(-topLeft.X, captionBottomCenter.Y + verticalSpacing),
                openAreaItemsCount: 3);
            m_lobbyTypeCombo.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP;
            m_lobbyTypeCombo.AddItem((int)LobbyTypeEnum.Private, MyCommonTexts.ScreenPlayersLobby_Private);
            m_lobbyTypeCombo.AddItem((int)LobbyTypeEnum.FriendsOnly, MyCommonTexts.ScreenPlayersLobby_Friends);
            m_lobbyTypeCombo.AddItem((int)LobbyTypeEnum.Public, MyCommonTexts.ScreenPlayersLobby_Public);
            m_lobbyTypeCombo.SelectItemByKey((int)MyMultiplayer.Static.GetLobbyType());

            MyGuiControlBase aboveControl;

            m_inviteButton = new MyGuiControlButton(
                position: new Vector2(-m_lobbyTypeCombo.Position.X, m_lobbyTypeCombo.Position.Y + m_lobbyTypeCombo.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.Get(MyCommonTexts.ScreenPlayers_Invite));
            aboveControl = m_inviteButton;

            m_promoteButton = new MyGuiControlButton(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.Get(MyCommonTexts.ScreenPlayers_Promote));
            aboveControl = m_promoteButton;

            m_demoteButton = new MyGuiControlButton(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.Get(MyCommonTexts.ScreenPlayers_Demote));
            aboveControl = m_demoteButton;

            m_kickButton = new MyGuiControlButton(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.Get(MyCommonTexts.ScreenPlayers_Kick));
            aboveControl = m_kickButton;

            m_banButton = new MyGuiControlButton(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.Get(MyCommonTexts.ScreenPlayers_Ban));
            aboveControl = m_banButton;

            var maxPlayersLabel = new MyGuiControlLabel(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y + verticalSpacing),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                text: MyTexts.GetString(MyCommonTexts.MaxPlayers));

            aboveControl = maxPlayersLabel;

            m_maxPlayersSlider = new MyGuiControlSlider(
                position: aboveControl.Position + new Vector2(0f, aboveControl.Size.Y),
                width: 0.15f,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                minValue: 2,
                maxValue: MyMultiplayer.Static != null ? MyMultiplayer.Static.MaxPlayers : 16,
                labelText: new StringBuilder("{0}").ToString(),
                labelDecimalPlaces: 0,
                labelSpaceWidth: 0.02f,
                defaultValue: Sync.IsServer ? MySession.Static.MaxPlayers : MyMultiplayer.Static.MemberLimit,
                intValue: true);
            m_maxPlayersSlider.ValueChanged = MaxPlayersSlider_Changed;
            aboveControl = m_maxPlayersSlider;

            m_playersTable = new MyGuiControlTable()
            {
                Position         = new Vector2(-m_inviteButton.Position.X, m_inviteButton.Position.Y),
                Size             = new Vector2(1200f / MyGuiConstants.GUI_OPTIMAL_SIZE.X, 1f) - m_inviteButton.Size * 1.05f,
                VisibleRowsCount = 21,
                OriginAlign      = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                ColumnsCount     = 5,
            };
            float PlayerNameWidth  = 0.3f;
            float FactionTagWidth  = 0.12f;
            float FactionNameWidth = MyPerGameSettings.EnableMutePlayer ? 0.3f : 0.34f;
            float MutedWidth       = MyPerGameSettings.EnableMutePlayer ? 0.13f : 0;

            m_playersTable.SetCustomColumnWidths(new float[] { PlayerNameWidth, FactionTagWidth, FactionNameWidth, MutedWidth, 1 - PlayerNameWidth - FactionTagWidth - FactionNameWidth - MutedWidth });
            m_playersTable.SetColumnName(PlayerNameColumn, MyTexts.Get(MyCommonTexts.ScreenPlayers_PlayerName));
            m_playersTable.SetColumnName(PlayerFactionTagColumn, MyTexts.Get(MyCommonTexts.ScreenPlayers_FactionTag));
            m_playersTable.SetColumnName(PlayerFactionNameColumn, MyTexts.Get(MyCommonTexts.ScreenPlayers_FactionName));
            m_playersTable.SetColumnName(PlayerMutedColumn, new StringBuilder(MyTexts.GetString(MyCommonTexts.ScreenPlayers_Muted)));
            m_playersTable.SetColumnName(GameAdminColumn, MyTexts.Get(MyCommonTexts.ScreenPlayers_GameAdmin));
            m_playersTable.SetColumnComparison(0, (a, b) => (a.Text.CompareToIgnoreCase(b.Text)));
            m_playersTable.ItemSelected += playersTable_ItemSelected;

            // CH: To show the clients correctly, we would need to know, whether the game is a dedicated-server-hosted game.
            // We don't know that, so I just show all clients with players
            foreach (var player in Sync.Players.GetOnlinePlayers())
            {
                if (player.Id.SerialId != 0)
                {
                    continue;
                }

                for (int i = 0; i < m_playersTable.RowsCount; ++i)
                {
                    var row = m_playersTable.GetRow(i);
                    if (row.UserData is ulong && (ulong)row.UserData == player.Id.SteamId)
                    {
                        continue;
                    }
                }

                AddPlayer(player.Id.SteamId);
            }

            m_inviteButton.ButtonClicked  += inviteButton_ButtonClicked;
            m_promoteButton.ButtonClicked += promoteButton_ButtonClicked;
            m_demoteButton.ButtonClicked  += demoteButton_ButtonClicked;
            m_kickButton.ButtonClicked    += kickButton_ButtonClicked;
            m_banButton.ButtonClicked     += banButton_ButtonClicked;
            m_lobbyTypeCombo.ItemSelected += lobbyTypeCombo_OnSelect;

            Controls.Add(m_inviteButton);
            Controls.Add(m_promoteButton);
            Controls.Add(m_demoteButton);
            Controls.Add(m_kickButton);
            Controls.Add(m_banButton);
            Controls.Add(m_playersTable);
            Controls.Add(m_lobbyTypeCombo);
            Controls.Add(m_maxPlayersSlider);
            Controls.Add(maxPlayersLabel);

            UpdateButtonsEnabledState();
        }
        void Matchmaking_LobbyChatUpdate(Lobby lobby, ulong changedUser, ulong makingChangeUser, ChatMemberStateChangeEnum stateChange)
        {
            //System.Diagnostics.Debug.Assert(MySession.Static != null);

            if (lobby.LobbyId == Lobby.LobbyId)
            {
                if (stateChange == ChatMemberStateChangeEnum.Entered)
                {
                    MySandboxGame.Log.WriteLineAndConsole("Player entered: " + MySteam.API.Friends.GetPersonaName(changedUser) + " (" + changedUser + ")");
                    MyTrace.Send(TraceWindow.Multiplayer, "Player entered");
                    Peer2Peer.AcceptSession(changedUser);

                    // When some clients connect at the same time then some of them can have already added clients
                    // (see function MySyncLayer.RegisterClientEvents which registers all Members in Lobby).
                    if (Sync.Clients == null || !Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientJoined(changedUser);
                    }

                    if (MySandboxGame.IsGameReady && changedUser != ServerId)
                    {
                        // Player is able to connect to the battle which already started - player is then kicked and we do not want to show connected message in HUD.
                        bool showMsg = true;
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static != null && MySession.Static.Battle && !BattleCanBeJoined)
                        {
                            showMsg = false;
                        }

                        if (showMsg)
                        {
                            var playerJoined = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                            playerJoined.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                            MyHud.Notifications.Add(playerJoined);
                        }
                    }
                }
                else
                {
                    // Kicked client can be already removed from Clients
                    if (Sync.Clients == null || Sync.Clients.HasClient(changedUser))
                    {
                        RaiseClientLeft(changedUser, stateChange);
                    }

                    if (changedUser == ServerId)
                    {
                        MyTrace.Send(TraceWindow.Multiplayer, "Host left: " + stateChange.ToString());
                        RaiseHostLeft();

                        MyGuiScreenMainMenu.UnloadAndExitToMenu();
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorServerHasLeft)));

                        // Set new server
                        //ServerId = Lobby.GetOwner();

                        //if (ServerId == Sync.MyId)
                        //{
                        //    Lobby.SetLobbyData(HostNameTag, Sync.MyName);
                        //}
                    }
                    else if (MySandboxGame.IsGameReady)
                    {
                        var playerLeft = new MyHudNotification(MyCommonTexts.NotificationClientDisconnected, 5000, level: MyNotificationLevel.Important);
                        playerLeft.SetTextFormatArguments(MySteam.API.Friends.GetPersonaName(changedUser));
                        MyHud.Notifications.Add(playerLeft);
                    }
                }
            }
        }
Ejemplo n.º 30
0
 public static void HandleDx11Needed()
 {
     MyGuiScreenMainMenu.ReturnToMainMenu();
     if (MyDirectXHelper.IsDx11Supported())
     {
         // Has DX11, ask for switch or selecting different scenario
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    callback: OnDX11SwitchRequestAnswer,
                                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                    messageText: MyTexts.Get(MySpaceTexts.QuickstartDX11SwitchQuestion),
                                    buttonType: MyMessageBoxButtonsType.YES_NO));
     }
     else
     {
         // No DX11, ask for selecting another scenario
         var text = MyTexts.Get(MySpaceTexts.QuickstartNoDx9SelectDifferent);
         MyGuiScreenMessageBox mb = MyGuiSandbox.CreateMessageBox(messageText: text, messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError));
         MyGuiSandbox.AddScreen(mb);
     }
 }