protected override void OnShow() { base.OnShow(); MyAnalyticsHelper.ReportActivityStart(null, "show_workshop", string.Empty, "gui", string.Empty); if (m_listNeedsReload) { FillList(); } }
public override void RecreateControls(bool constructor) { base.RecreateControls(constructor); MyAnalyticsHelper.ReportActivityStart(null, "show_blueprints", string.Empty, "gui", string.Empty); Vector2 searchPosition = new Vector2(0f, SCREEN_SIZE.Y - 1.58f); float hiddenPartTop = (SCREEN_SIZE.Y - 1.0f) / 2.0f; var searchBoxLabel = MakeLabel("Search:", searchPosition + new Vector2(-0.175f, -0.015f), m_textScale); m_searchBox = new MyGuiControlTextbox(searchPosition); m_searchBox.Size = new Vector2(0.2f, 0.2f); m_searchClear = new MyGuiControlButton() { Position = searchPosition + new Vector2(0.077f, 0f), Size = new Vector2(0.045f, 0.05666667f), OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, VisualStyle = MyGuiControlButtonStyleEnum.Close, ActivateOnMouseRelease = true, }; m_searchClear.ButtonClicked += OnSearchClear; m_blueprintList.Position = new Vector2(0f, -0.03f); m_blueprintList.VisibleRowsCount = 17; m_blueprintList.MultiSelect = false; var caption = AddCaption("Blueprints screen", VRageMath.Color.White.ToVector4(), m_controlPadding + new Vector2(-HIDDEN_PART_RIGHT, hiddenPartTop)); Controls.Add(searchBoxLabel); Controls.Add(m_searchBox); Controls.Add(m_searchClear); Controls.Add(m_blueprintList); RefreshThumbnail(); Controls.Add(m_thumbnailImage); CreateButtons(); var texture = MyGuiConstants.LOADING_TEXTURE; m_wheel = new MyGuiControlRotatingWheel( searchPosition + new Vector2(0.127f, 0f), MyGuiConstants.ROTATING_WHEEL_COLOR, 0.28f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, texture, true, multipleSpinningWheels: MyPerGameSettings.GUI.MultipleSpinningWheels); Controls.Add(m_wheel); m_wheel.Visible = false; }
void GetWorkshopItemsLocal() { var filePath = Path.Combine(m_workshopBlueprintFolder, "temp"); if (Directory.Exists(filePath)) { var folders = Directory.GetDirectories(filePath); var blueprintNames = new List <string>(); var fileNames = new List <string>(); foreach (var f in folders) { var tokens = f.Split('\\'); blueprintNames.Add(tokens[tokens.Length - 1]); } for (int i = 0; i < blueprintNames.Count; i++) { var modInfoPath = Path.Combine(filePath, blueprintNames[i], "info.temp"); MyObjectBuilder_ModInfo modInfo = null; if (File.Exists(modInfoPath)) { MyAnalyticsHelper.ReportActivityStart(null, "show_blueprints", string.Empty, "gui", string.Empty); var success = MyObjectBuilderSerializer.DeserializeXML(modInfoPath, out modInfo); if (!ValidateModInfo(modInfo) || !success) { continue; } String name = modInfo.SubtypeName; var info = new MyBlueprintItemInfo(MyBlueprintTypeEnum.STEAM, modInfo.WorkshopId); var item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal); m_blueprintList.Add(item); } } } }
// 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 ? 9 : 8; 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 || (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); CheckLowMemSwitchToLow(); }
public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false) { System.Diagnostics.Debug.Assert(pilot != null); System.Diagnostics.Debug.Assert(m_pilot == null); MyAnalyticsHelper.ReportActivityStart(pilot, "cockpit", "cockpit", string.Empty, string.Empty); m_pilot = pilot; m_pilot.OnMarkForClose += m_pilotClosedHandler; m_pilot.IsUsing = this; StartLoopSound(); if (storeOriginalPilotWorld) { m_pilotRelativeWorld = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.GetWorldMatrixNormalizedInv()); if (Sync.IsServer) { var relativeEntry = new MyPositionAndOrientation(m_pilotRelativeWorld.Value); SyncObject.SendPilotRelativeEntryUpdate(ref relativeEntry); } } if (pilot.InScene) { MyEntities.Remove(pilot); } m_pilot.Physics.Enabled = false; m_pilot.PositionComp.SetWorldMatrix(WorldMatrix); m_pilot.Physics.Clear(); //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f); Hierarchy.AddChild(m_pilot, true, true); var gunEntity = m_pilot.CurrentWeapon as MyEntity; if (gunEntity != null) { var ob = gunEntity.GetObjectBuilder(); m_pilotGunDefinition = ob.GetId(); } else { m_pilotGunDefinition = null; } MyAnimationDefinition animationDefinition; MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_AnimationDefinition), BlockDefinition.CharacterAnimation); if (!MyDefinitionManager.Static.TryGetDefinition(id, out animationDefinition) && !MyFileSystem.FileExists(BlockDefinition.CharacterAnimation)) { BlockDefinition.CharacterAnimation = null; } PlacePilotInSeat(pilot); m_pilot.SuitBattery.ResourceSink.TemporaryConnectedEntity = this; m_rechargeSocket.PlugIn(m_pilot.SuitBattery.ResourceSink); // Control should be handled elsewhere if we initialize the grid in the Init(...) if (!calledFromInit) { GiveControlToPilot(); } m_pilot.SwitchToWeapon(null); }
public void TurnOnJetpack(bool newState, bool fromLoad = false, bool updateSync = true, bool fromInit = false) { bool originalNewState = newState; newState = newState && MySession.Static.Settings.EnableJetpack; newState = newState && Character.Definition.Jetpack != null; newState = newState && (!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL || MySession.Static.IsAdminModeEnabled); 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 && !MyFakes.CHARACTER_SERVER_SYNC) { return; } MyCharacterMovementEnum currentMovementState = Character.GetCurrentMovementState(); if (currentMovementState == MyCharacterMovementEnum.Sitting) { return; } Character.StopFalling(); bool noHydrogen = false; bool canUseJetpack = newState; if (!IsPowered && canUseJetpack && (MySession.Static.IsAdminModeEnabled == false || MySession.Static.LocalCharacter != Character)) { 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 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; } } } } }