public void TurnOnJetpack(bool newState, bool fromInit = false, bool fromLoad = false) { bool originalNewState = newState; var controller = Character.ControllerInfo.Controller; newState = newState && MySession.Static.Settings.EnableJetpack; newState = newState && Character.Definition.Jetpack != null; newState = newState && (!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL || controller == null || MySession.Static.IsAdminModeEnabled(controller.Player.Id.SteamId)); bool valueChanged = TurnedOn != newState; TurnedOn = newState; ThrustComp.Enabled = newState; ThrustComp.ControlThrust = Vector3.Zero; ThrustComp.MarkDirty(); ThrustComp.UpdateBeforeSimulation(); if (!ThrustComp.Enabled) { ThrustComp.SetRequiredFuelInput(ref FuelDefinition.Id, 0f, null); } ThrustComp.ResourceSink(Character).Update(); if (!Character.ControllerInfo.IsLocallyControlled() && !fromInit && !Sync.IsServer) { return; } MyCharacterMovementEnum currentMovementState = Character.GetCurrentMovementState(); if (currentMovementState == MyCharacterMovementEnum.Sitting) { return; } Character.StopFalling(); bool noHydrogen = false; bool canUseJetpack = newState; if (!IsPowered && canUseJetpack && ((Character.ControllerInfo.Controller != null && MySession.Static.IsAdminModeEnabled(Character.ControllerInfo.Controller.Player.Id.SteamId) == false) || (MySession.Static.LocalCharacter != Character && Sync.IsServer == false))) { canUseJetpack = false; noHydrogen = true; } if (canUseJetpack) { Character.IsUsing = null; } if (MySession.Static.ControlledEntity == Character && valueChanged && !fromLoad) { m_jetpackToggleNotification.Text = (noHydrogen) ? MySpaceTexts.NotificationJetpackOffNoHydrogen : (canUseJetpack || (originalNewState)) ? MySpaceTexts.NotificationJetpackOn : MySpaceTexts.NotificationJetpackOff; MyHud.Notifications.Add(m_jetpackToggleNotification); if (canUseJetpack) { MyAnalyticsHelper.ReportActivityStart(Character, "jetpack", "character", string.Empty, string.Empty); } else { MyAnalyticsHelper.ReportActivityEnd(Character, "jetpack"); } //unable sound + turn off jetpack if (noHydrogen) { MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); TurnedOn = false; ThrustComp.Enabled = false; ThrustComp.ControlThrust = Vector3.Zero; ThrustComp.MarkDirty(); ThrustComp.UpdateBeforeSimulation(); ThrustComp.SetRequiredFuelInput(ref FuelDefinition.Id, 0f, null); ThrustComp.ResourceSink(Character).Update(); } } var characterProxy = Character.Physics.CharacterProxy; if (characterProxy != null) { characterProxy.Forward = Character.WorldMatrix.Forward; characterProxy.Up = Character.WorldMatrix.Up; characterProxy.EnableFlyingState(Running); if (currentMovementState != MyCharacterMovementEnum.Died) { if (!Running && (characterProxy.GetState() == HkCharacterStateType.HK_CHARACTER_IN_AIR || (int)characterProxy.GetState() == MyCharacter.HK_CHARACTER_FLYING)) { Character.StartFalling(); } //If we are in any state but not standing and new state is to be flying, dont change to standing. Else is probably ok? else if (currentMovementState != MyCharacterMovementEnum.Standing && !newState) { Character.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f); Character.SetCurrentMovementState(MyCharacterMovementEnum.Standing); currentMovementState = Character.GetCurrentMovementState(); } } if (Running && currentMovementState != MyCharacterMovementEnum.Died) { Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.0f); Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying); Character.SetLocalHeadAnimation(0, 0, 0.3f); // If the character is running when enabling the jetpack, these will keep making him fly in the same direction always if not zeroed characterProxy.PosX = 0; characterProxy.PosY = 0; } // When disabling the jetpack normally during the game in zero-G, disable jetpack autoenable if (!fromLoad && !newState && characterProxy.Gravity.LengthSquared() <= 0.1f) { CurrentAutoEnableDelay = -1; } } }
public void Shoot(MyShootActionEnum action, Vector3 direction, Vector3D?overrideWeaponPos, string gunAction) { MyAnalyticsHelper.ReportActivityStartIf(!IsShooting, this.Owner, "Drilling", "Character", "HandTools", "HandDrill", true); DoDrillAction(collectOre: action == MyShootActionEnum.PrimaryAction); }
public static void LoadSingleplayerSession(string sessionPath) { MyLog.Default.WriteLine("LoadSession() - Start"); MyLog.Default.WriteLine(sessionPath); ulong checkpointSizeInBytes; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out checkpointSizeInBytes); 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 (!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; } MyGuiScreenGamePlay.StartLoading(delegate { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Load); MySession.Load(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"); }); }
protected override void OnClosed() { base.OnClosed(); MyAnalyticsHelper.ReportActivityEnd(null, "show_workshop"); }
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(); MySessionLoader.UnloadAndExitToMenu(); }; 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 void TurnOnJetpack(bool newState, bool fromInit = false, bool fromLoad = false) { int num1; int num2; MyEntityController controller = base.Character.ControllerInfo.Controller; newState = newState && MySession.Static.Settings.EnableJetpack; newState = newState && (base.Character.Definition.Jetpack != null); if (!newState) { num1 = 0; } else if ((!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL) || (controller == null)) { num1 = 1; } else { num1 = (int)MySession.Static.CreativeToolsEnabled(controller.Player.Id.SteamId); } newState = (bool)num2; bool flag = this.TurnedOn != newState; this.TurnedOn = newState; this.ThrustComp.Enabled = newState; this.ThrustComp.ControlThrust = Vector3.Zero; this.ThrustComp.MarkDirty(false); this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity); if (!this.ThrustComp.Enabled) { this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null); } this.ThrustComp.ResourceSink(base.Character).Update(); if ((base.Character.ControllerInfo.IsLocallyControlled() || fromInit) || Sync.IsServer) { MyCharacterMovementEnum currentMovementState = base.Character.GetCurrentMovementState(); if (currentMovementState != MyCharacterMovementEnum.Sitting) { if (this.TurnedOn) { base.Character.StopFalling(); } bool flag2 = false; bool flag3 = newState; if ((!this.IsPowered & flag3) && (((base.Character.ControllerInfo.Controller != null) && !MySession.Static.CreativeToolsEnabled(base.Character.ControllerInfo.Controller.Player.Id.SteamId)) || (!ReferenceEquals(MySession.Static.LocalCharacter, base.Character) && !Sync.IsServer))) { flag3 = false; flag2 = true; } if (flag3) { if (base.Character.IsOnLadder) { base.Character.GetOffLadder(); } base.Character.IsUsing = null; } if (flag && !base.Character.IsDead) { base.Character.UpdateCharacterPhysics(false); } if ((ReferenceEquals(MySession.Static.ControlledEntity, base.Character) & flag) && !fromLoad) { if (flag3) { MyAnalyticsHelper.ReportActivityStart(base.Character, "jetpack", "character", string.Empty, string.Empty, true); } else { MyAnalyticsHelper.ReportActivityEnd(base.Character, "jetpack"); } if (flag2) { MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); this.TurnedOn = false; this.ThrustComp.Enabled = false; this.ThrustComp.ControlThrust = Vector3.Zero; this.ThrustComp.MarkDirty(false); this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity); this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null); this.ThrustComp.ResourceSink(base.Character).Update(); } } MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy; if (characterProxy == null) { if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died)) { base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false); base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f); } } else { MatrixD worldMatrix = base.Character.WorldMatrix; characterProxy.SetForwardAndUp((Vector3)worldMatrix.Forward, (Vector3)worldMatrix.Up); characterProxy.EnableFlyingState(this.Running); if ((currentMovementState != MyCharacterMovementEnum.Died) && !base.Character.IsOnLadder) { if (!this.Running && ((characterProxy.GetState() == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (characterProxy.GetState() == ((HkCharacterStateType)5)))) { base.Character.StartFalling(); } else if ((currentMovementState != MyCharacterMovementEnum.Standing) && !newState) { base.Character.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false); base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Standing); currentMovementState = base.Character.GetCurrentMovementState(); } } if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died)) { base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false); base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying); base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f); characterProxy.PosX = 0f; characterProxy.PosY = 0f; } if ((!fromLoad && !newState) && (base.Character.Physics.Gravity.LengthSquared() <= 0.1f)) { this.CurrentAutoEnableDelay = -1f; } } } } }
public override void EndShoot(MyShootActionEnum action) { MyAnalyticsHelper.ReportActivityEnd(this.Owner, "Grinding"); base.EndShoot(action); }
public void OnTutorialClick(MyGuiControlButton sender) { MyAnalyticsHelper.ReportTutorialScreen("TutorialsButtonClicked"); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.TutorialScreen)); }
// Because only main menu's controla depends on fullscreen pixel coordinates (not normalized), after we change // screen resolution we need to recreate controls too. Otherwise they will be still on old/bad positions, and // for example when changing from 1920x1200 to 800x600 they would be out of screen public override void RecreateControls(bool constructor) { base.RecreateControls(constructor); // Enable background fade when we're in game, but in main menu we disable it. var buttonSize = MyGuiControlButton.GetVisualStyle(MyGuiControlButtonStyleEnum.Default).NormalTexture.MinSizeGui; Vector2 leftButtonPositionOrigin = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM) + new Vector2(buttonSize.X / 2f, 0f); Vector2 rightButtonPositionOrigin = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM) + new Vector2(-buttonSize.X / 2f, 0f); // In main menu if (MyGuiScreenGamePlay.Static == null) { EnabledBackgroundFade = false; // Left main menu part var a = MyGuiManager.GetSafeFullscreenRectangle(); var fullScreenSize = new Vector2(a.Width / (a.Height * (4 / 3f)), 1f); // New Game // Load world // Join world // Workshop // // Options // Help // Credits // Exit to windows int buttonIndex = MyPerGameSettings.MultiplayerEnabled ? 8 : 7; if (MyFakes.XB1_PREVIEW) { buttonIndex = MyPerGameSettings.MultiplayerEnabled ? 7 : 6; } Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonNewWorld, OnClickNewWorld)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonLoadWorld, OnClickLoad)); if (MyPerGameSettings.MultiplayerEnabled) { Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonJoinWorld, OnJoinWorld)); } if (!MyFakes.XB1_PREVIEW) { #if !XB1 // XB1_NOWORKSHOP Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonSubscribedWorlds, OnClickSubscribedWorlds, MyCommonTexts.ToolTipMenuSubscribedWorlds)); #endif // !XB1 } --buttonIndex; Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonOptions, OnClickOptions)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonHelp, OnClickHelp)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonCredits, OnClickCredits)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonExitToWindows, OnClickExitToWindows)); Vector2 textRightTopPosition = MyGuiManager.GetScreenTextRightTopPosition(); Vector2 position = textRightTopPosition + 8f * MyGuiConstants.CONTROLS_DELTA + new Vector2(-.1f, .06f); } else // In-game { MyAnalyticsHelper.ReportActivityStart(null, "show_main_menu", string.Empty, "gui", string.Empty); EnabledBackgroundFade = true; int buttonRowIndex = Sync.MultiplayerActive ? 6 : 5; // Save // Load button (only on dev) // // Options // Help // Exit to main menu var saveButton = MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonSave, OnClickSaveWorld); var saveAsButton = MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.LoadScreenButtonSaveAs, OnClickSaveAs); if (!Sync.IsServer || (MySession.Static.Battle)) { saveButton.Enabled = false; saveButton.ShowTooltipWhenDisabled = true; saveButton.SetToolTip(MyCommonTexts.NotificationClientCannotSave); saveAsButton.Enabled = false; saveButton.ShowTooltipWhenDisabled = true; saveButton.SetToolTip(MyCommonTexts.NotificationClientCannotSave); } Controls.Add(saveButton); Controls.Add(saveAsButton); // --buttonRowIndex; // empty line if (Sync.MultiplayerActive) { Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonPlayers, OnClickPlayers)); } Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonOptions, OnClickOptions)); Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonHelp, OnClickHelp)); Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonExitToMainMenu, OnExitToMainMenuClick)); } var logoPanel = new MyGuiControlPanel( position: MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, 54, 84), size: MyGuiConstants.TEXTURE_KEEN_LOGO.MinSizeGui, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP ); logoPanel.BackgroundTexture = MyGuiConstants.TEXTURE_KEEN_LOGO; Controls.Add(logoPanel); // Recommend button Vector2 pos = rightButtonPositionOrigin - 8f * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA; Controls.Add(MakeButton(pos, MyCommonTexts.ScreenMenuButtonRecommend, OnClickRecommend)); m_newsControl = new MyGuiControlNews() { Position = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM) - 7f * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, Size = new Vector2(0.4f, 0.28f), OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, }; Controls.Add(m_newsControl); var webButton = MakeButton( MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, 70), MySpaceTexts.Blank, OnClickGameWeb); webButton.Text = MyPerGameSettings.GameWebUrl; webButton.VisualStyle = MyGuiControlButtonStyleEnum.UrlText; Controls.Add(webButton); var reportButton = MakeButton( new Vector2(m_newsControl.Position.X, m_newsControl.Position.Y + m_newsControl.Size.Y), //MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM, 140,80), MyCommonTexts.ReportBug, OnClickReportBug); reportButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP; reportButton.VisualStyle = MyGuiControlButtonStyleEnum.UrlText; Controls.Add(reportButton); m_newsControl.State = MyGuiControlNews.StateEnum.Loading; DownloadNews(); CheckLowMemSwitchToLow(); }
/// <summary> /// Starts new session and unloads outdated if theres any. /// </summary> /// <param name="sessionName">Created session name.</param> /// <param name="settings">Session settings OB.</param> /// <param name="mods">Mod selection.</param> /// <param name="scenarioDefinition">World generator argument.</param> /// <param name="asteroidAmount">Hostility settings.</param> /// <param name="description">Session description.</param> /// <param name="passwd">Session password.</param> public static void StartNewSession(string sessionName, MyObjectBuilder_SessionSettings settings, List <MyObjectBuilder_Checkpoint.ModItem> mods, MyScenarioDefinition scenarioDefinition = null, int asteroidAmount = 0, string description = "", string passwd = "") { MyLog.Default.WriteLine("StartNewSandbox - Start"); if (!MySteamWorkshop.CheckLocalModsAllowed(mods, settings.OnlineMode == MyOnlineModeEnum.OFFLINE)) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer), buttonType: MyMessageBoxButtonsType.OK)); MyLog.Default.WriteLine("LoadSession() - End"); return; } MySteamWorkshop.DownloadModsAsync(mods, delegate(bool success, string mismatchMods) { if (success || (settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(mods)) { CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val) { MyScreenManager.RemoveAllScreensExcept(null); if (asteroidAmount < 0) { MyWorldGenerator.SetProceduralSettings(asteroidAmount, settings); asteroidAmount = 0; } MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom); StartLoading(delegate { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom); MySession.Start( sessionName, description, passwd, settings, mods, new MyWorldGenerator.Args() { AsteroidAmount = asteroidAmount, Scenario = scenarioDefinition } ); }); }); } else { if (MySteam.IsOnline) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed), buttonType: MyMessageBoxButtonsType.OK)); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline), buttonType: MyMessageBoxButtonsType.OK)); } } MyLog.Default.WriteLine("StartNewSandbox - End"); }); }
public static void LoadSingleplayerSession(MyObjectBuilder_Checkpoint checkpoint, string sessionPath, ulong checkpointSizeInBytes, Action afterLoad = null) { if (!MySession.IsCompatibleVersion(checkpoint)) { MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion).ToString()); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion), buttonType: MyMessageBoxButtonsType.OK)); MyLog.Default.WriteLine("LoadSession() - End"); return; } if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE)) { MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer).ToString()); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer), buttonType: MyMessageBoxButtonsType.OK)); MyLog.Default.WriteLine("LoadSession() - End"); return; } var customLoadingScreenPath = GetCustomLoadingScreenImagePath(checkpoint.CustomLoadingScreenImage); MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success, string mismatchMods) { 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); CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val) { if (val == ResultEnum.OK) { // 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; } StartLoading(delegate { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Load); MySession.Load(sessionPath, checkpoint, checkpointSizeInBytes); if (afterLoad != null) { afterLoad(); } }, customLoadingScreenPath, checkpoint.CustomLoadingScreenText); } else { MySessionLoader.UnloadAndExitToMenu(); } }); } else { MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed).ToString()); if (MySteam.IsOnline) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText : MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed), buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result) { if (MyFakes.QUICK_LAUNCH != null) { MySessionLoader.UnloadAndExitToMenu(); } })); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline), buttonType: MyMessageBoxButtonsType.OK)); } } MyLog.Default.WriteLine("LoadSession() - End"); }); }
internal void UpdateAfterSimulation10() { this.UpdateRigidBodyShape(); if (this.m_voxelMap.Storage != null) { foreach (IMyEntity entity in this.m_nearbyEntities) { if (entity != null) { bool flag = false; MyPhysicsBody physics = entity.Physics as MyPhysicsBody; if (((physics != null) && (physics.RigidBody != null)) && ((physics.RigidBody.Layer == 0x17) || (physics.RigidBody.Layer == 10))) { flag = true; } if ((((entity is MyCubeGrid) || flag) && !entity.MarkedForClose) && (entity.Physics != null)) { BoundingBoxD xd; this.GetPrediction(entity, out xd); if (xd.Intersects(this.m_voxelMap.PositionComp.WorldAABB)) { Vector3I vectori; Vector3I vectori2; HkUniformGridShape shape; int num1; if (flag || !UseLod1VoxelPhysics) { num1 = 0; } else { num1 = 1; } int lod = num1; int num2 = 1 << (lod & 0x1f); BoundingBoxD xd2 = xd.TransformFast(this.m_voxelMap.PositionComp.WorldMatrixInvScaled); xd2.Translate(this.m_voxelMap.SizeInMetresHalf); Vector3 max = (Vector3)xd2.Max; Vector3 min = (Vector3)xd2.Min; this.ClampVoxelCoords(ref min, ref max, out vectori, out vectori2); vectori = vectori >> lod; vectori2 = vectori2 >> lod; int size = ((vectori2 - vectori) + 1).Size; if (size >= m_cellsToGenerateBuffer.Length) { m_cellsToGenerateBuffer = new Vector3I[MathHelper.GetNearestBiggerPowerOfTwo(size)]; } if (this.GetShape(lod, out shape)) { if (shape.Base.IsZero) { MyAnalyticsHelper.ReportBug("Null voxel shape", "SE-7366", true, @"E:\Repo1\Sources\Sandbox.Game\Engine\Voxels\MyVoxelPhysicsBody.cs", 680); } else { int requiredCellsCount = shape.GetMissingCellsInRange(ref vectori, ref vectori2, m_cellsToGenerateBuffer); if (requiredCellsCount != 0) { BoundingBoxI box = new BoundingBoxI((vectori * 8) * num2, (Vector3I)(((vectori2 + 1) * 8) * num2)); box.Translate(this.m_voxelMap.StorageMin); if ((requiredCellsCount > 0) && (this.m_voxelMap.Storage.Intersect(ref box, lod, true) != ContainmentType.Intersects)) { this.SetEmptyShapes(lod, ref shape, requiredCellsCount); } else { for (int i = 0; i < requiredCellsCount; i++) { this.StartPrecalcJobPhysicsIfNeeded(lod, i); } } } } } } } } } this.ScheduleBatchJobs(); if (this.m_bodiesInitialized) { this.CheckAndDiscardShapes(); } } }
// Because only main menu's controla depends on fullscreen pixel coordinates (not normalized), after we change // screen resolution we need to recreate controls too. Otherwise they will be still on old/bad positions, and // for example when changing from 1920x1200 to 800x600 they would be out of screen public override void RecreateControls(bool constructor) { base.RecreateControls(constructor); // Enable background fade when we're in game, but in main menu we disable it. var buttonSize = MyGuiControlButton.GetVisualStyle(MyGuiControlButtonStyleEnum.Default).NormalTexture.MinSizeGui; Vector2 leftButtonPositionOrigin = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM) + new Vector2(buttonSize.X / 2f, 0f); Vector2 rightButtonPositionOrigin = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM) + new Vector2(-buttonSize.X / 2f, 0f); // In main menu if (MyGuiScreenGamePlay.Static == null) { EnabledBackgroundFade = false; // Left main menu part var a = MyGuiManager.GetSafeFullscreenRectangle(); var fullScreenSize = new Vector2(a.Width / (a.Height * (4 / 3f)), 1f); // New Game // Load world // Join world // Workshop // // Options // Help // Credits // Exit to windows int buttonIndex = MyPerGameSettings.MultiplayerEnabled ? 7 : 6; Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA - MyGuiConstants.MENU_BUTTONS_POSITION_DELTA / 2, MyCommonTexts.ScreenMenuButtonContinueGame, OnContinueGameClicked)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonCampaign, OnClickNewGame)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonLoadGame, OnClickLoad)); if (MyPerGameSettings.MultiplayerEnabled) { Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonJoinGame, OnJoinWorld)); } //Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonCustomGame, OnCustomGameClicked)); --buttonIndex; //Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonSubscribedWorlds, OnClickSubscribedWorlds, MyCommonTexts.ToolTipMenuSubscribedWorlds)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonOptions, OnClickOptions)); //Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonHelp, OnClickHelp)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonCredits, OnClickCredits)); Controls.Add(MakeButton(leftButtonPositionOrigin - (buttonIndex--) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonExitToWindows, OnClickExitToWindows)); Vector2 textRightTopPosition = MyGuiManager.GetScreenTextRightTopPosition(); Vector2 position = textRightTopPosition + 8f * MyGuiConstants.CONTROLS_DELTA + new Vector2(-.1f, .06f); } else // In-game { MyAnalyticsHelper.ReportActivityStart(null, "show_main_menu", string.Empty, "gui", string.Empty); EnabledBackgroundFade = true; int buttonRowIndex = Sync.MultiplayerActive ? 6 : 5; // Save // Load button (only on dev) // // Options // Help // Exit to main menu var saveButton = MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonSave, OnClickSaveWorld); var saveAsButton = MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.LoadScreenButtonSaveAs, OnClickSaveAs); if (!Sync.IsServer || MyCampaignManager.Static.IsCampaignRunning) { saveButton.Enabled = false; saveButton.ShowTooltipWhenDisabled = true; saveButton.SetToolTip(MyCommonTexts.NotificationClientCannotSave); saveAsButton.Enabled = false; saveButton.ShowTooltipWhenDisabled = true; saveButton.SetToolTip(MyCommonTexts.NotificationClientCannotSave); } Controls.Add(saveButton); Controls.Add(saveAsButton); // --buttonRowIndex; // empty line if (Sync.MultiplayerActive) { Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonPlayers, OnClickPlayers)); } Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonOptions, OnClickOptions)); Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonHelp, OnClickHelp)); Controls.Add(MakeButton(leftButtonPositionOrigin - ((float)(--buttonRowIndex)) * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyCommonTexts.ScreenMenuButtonExitToMainMenu, OnExitToMainMenuClick)); } var logoPanel = new MyGuiControlPanel( position: MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, 54, 84), size: MyGuiConstants.TEXTURE_KEEN_LOGO.MinSizeGui, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP ); logoPanel.BackgroundTexture = MyGuiConstants.TEXTURE_KEEN_LOGO; Controls.Add(logoPanel); // News m_newsControl = new MyGuiControlNews() { Position = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM) - 7f * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, Size = new Vector2(0.4f, 0.28f), OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, }; Controls.Add(m_newsControl); // Bottom URL var webButton = MakeButton( MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, 70), MySpaceTexts.Blank, OnClickGameWeb); webButton.Text = MyPerGameSettings.GameWebUrl; webButton.VisualStyle = MyGuiControlButtonStyleEnum.UrlText; Controls.Add(webButton); var iconButtonOrigin = m_newsControl.Position; var iconButtonSize = new Vector2(50f) / MyGuiConstants.GUI_OPTIMAL_SIZE; iconButtonOrigin.Y += m_newsControl.Size.Y + MyGuiConstants.GENERIC_BUTTON_SPACING.Y; // Help button var helpButton = MakeButton( iconButtonOrigin, MyStringId.NullOrEmpty, OnClickHelp); helpButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP; helpButton.VisualStyle = MyGuiControlButtonStyleEnum.Help; helpButton.Size = iconButtonSize; Controls.Add(helpButton); iconButtonOrigin.X -= helpButton.Size.X + MyGuiConstants.GENERIC_BUTTON_SPACING.X * 2; // Report button var reportButton = MakeButton( iconButtonOrigin, MyStringId.NullOrEmpty, OnClickReportBug); reportButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP; reportButton.VisualStyle = MyGuiControlButtonStyleEnum.Bug; reportButton.Size = iconButtonSize; Controls.Add(reportButton); iconButtonOrigin.X -= reportButton.Size.X + MyGuiConstants.GENERIC_BUTTON_SPACING.X * 2; // Newsletter button var newsletterButton = MakeButton( iconButtonOrigin, MyStringId.NullOrEmpty, OnClickNewsletter); newsletterButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP; newsletterButton.VisualStyle = MyGuiControlButtonStyleEnum.Envelope; newsletterButton.Size = iconButtonSize; Controls.Add(newsletterButton); iconButtonOrigin.X -= newsletterButton.Size.X + MyGuiConstants.GENERIC_BUTTON_SPACING.X * 2; // Recommend button var button = MakeButton( iconButtonOrigin, MyStringId.NullOrEmpty, OnClickRecommend); button.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP; button.VisualStyle = MyGuiControlButtonStyleEnum.Like; button.Size = iconButtonSize; Controls.Add(button); CheckLowMemSwitchToLow(); }
private void StartNewSandbox() { MyLog.Default.WriteLine("StartNewSandbox - Start"); GetSettingsFromControls(); if (!MySteamWorkshop.CheckLocalModsAllowed(m_mods, m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE)) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer), buttonType: MyMessageBoxButtonsType.OK)); MyLog.Default.WriteLine("LoadSession() - End"); return; } MySteamWorkshop.DownloadModsAsync(m_mods, delegate(bool success) { if (success || (m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(m_mods)) { MyScreenManager.RemoveAllScreensExcept(null); if (AsteroidAmount < 0) { MyWorldGenerator.SetProceduralSettings(AsteroidAmount, m_settings); m_asteroidAmount = 0; } MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom); MyGuiScreenGamePlay.StartLoading(delegate { MySession.Start( m_nameTextbox.Text, GetDescription(), GetPassword(), m_settings, m_mods, new MyWorldGenerator.Args() { AsteroidAmount = this.AsteroidAmount, Scenario = (m_scenarioTypesGroup.SelectedButton as MyGuiControlScenarioButton).Scenario } ); }); } else { if (MySteam.IsOnline) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed), buttonType: MyMessageBoxButtonsType.OK)); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline), buttonType: MyMessageBoxButtonsType.OK)); } } MyLog.Default.WriteLine("StartNewSandbox - End"); }); }