Beispiel #1
0
        private bool OnSliderClicked(MyGuiControlSlider who)
        {
            if (MyInput.Static.IsAnyCtrlKeyPressed())
            {
                float min = 0;
                float max = 255;
                float val = who.Value;

                MyGuiScreenDialogAmount dialog = new MyGuiScreenDialogAmount(min, max, m_caption, parseAsInteger: true, defaultAmount: val);
                dialog.OnConfirmed += (v) => { who.Value = v; };
                MyScreenManager.AddScreen(dialog);
                return(true);
            }
            return(false);
        }
Beispiel #2
0
 private void EnableSoundsBasedOnWindowFocus()
 {
     if (MySandboxGame.Static.WindowHandle == GetForegroundWindow() && MyScreenManager.GetScreenWithFocus() != null)
     { // allow
         // this works bad (	0007128: BUG B - audio sliders are broken)
         //MyAudio.Static.SetAllVolume(MyConfig.GameVolume, MyConfig.MusicVolume);
         MyAudio.Static.Mute = false;
     }
     else // mute
     {
         // this works bad (	0007128: BUG B - audio sliders are broken)
         //MyAudio.Static.SetAllVolume(0,0);
         MyAudio.Static.Mute = true;
     }
 }
Beispiel #3
0
        //  Update all screens
        public void Update(int totalTimeInMS)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGuiSandbox::Update1");

            HandleRenderProfilerInput();
            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("MyGuiSandbox::Update2");

            TotalGamePlayTimeInMilliseconds = totalTimeInMS;

            MyScreenManager.Update(totalTimeInMS);

            MyGuiScreenBase screenWithFocus = MyScreenManager.GetScreenWithFocus();

#if !XB1
            bool gameFocused = (MySandboxGame.Static.IsActive == true
                                &&
                                ((Sandbox.AppCode.MyExternalAppBase.Static == null && MySandboxGame.Static.WindowHandle == GetForegroundWindow())
                                 ||
                                 (Sandbox.AppCode.MyExternalAppBase.Static != null && !Sandbox.AppCode.MyExternalAppBase.IsEditorActive))
                                );
#else // XB1
            bool gameFocused = (MySandboxGame.Static.IsActive == true
                                &&
                                ((Sandbox.AppCode.MyExternalAppBase.Static == null)
                                 ||
                                 (Sandbox.AppCode.MyExternalAppBase.Static != null && !Sandbox.AppCode.MyExternalAppBase.IsEditorActive))
                                );
#endif // XB1

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("MyGuiSandbox::Update3");
            //We have to know current focus screen because of centerize mouse
            MyInput.Static.Update(gameFocused);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("MyGuiSandbox::Update4");
            MyGuiManager.Update(totalTimeInMS);
            MyGuiManager.MouseCursorPosition = MouseCursorPosition;


            MyGuiManager.Camera     = MySector.MainCamera != null ? MySector.MainCamera.WorldMatrix : VRageMath.MatrixD.Identity;
            MyGuiManager.CameraView = MySector.MainCamera != null ? MySector.MainCamera.ViewMatrix : VRageMath.MatrixD.Identity;
            MyGuiManager.TotalTimeInMilliseconds = MySandboxGame.TotalTimeInMilliseconds;

            //We should not need this call
            //EnableSoundsBasedOnWindowFocus();

            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Beispiel #4
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        public void LoadData()
        {
            ProfilerShort.Begin("MyScreenManager.LoadData");
            MyScreenManager.LoadData();
            ProfilerShort.BeginNextBlock("MyGuiManager.LoadData");
            MyGuiManager.LoadData();
            ProfilerShort.End();

            ProfilerShort.Begin("MyLanguage.CurrentLanguage set");
            MyLanguage.CurrentLanguage = MySandboxGame.Config.Language;
            ProfilerShort.End();

            if (MyFakes.SHOW_AUDIO_DEV_SCREEN)
            {
                ProfilerShort.Begin("MyGuiScreenDebugAudio");
                MyGuiScreenDebugAudio audioDebug = new MyGuiScreenDebugAudio();
                AddScreen(audioDebug);
                ProfilerShort.End();
            }
        }
Beispiel #5
0
        private void DrawControls(float transitionAlpha)
        {
            //  Then draw all screen controls, except opened combobox and drag and drop - must be drawn as last
            // foreach (MyGuiControlBase control in Controls.GetVisibleControls())  //dont use this - allocations
            List <MyGuiControlBase> visibleControls = Controls.GetVisibleControls();

            for (int i = 0; i < visibleControls.Count; i++)
            {
                MyGuiControlBase control = visibleControls[i];
                if (control != m_comboboxHandlingNow && control != m_listboxDragAndDropHandlingNow)
                {
                    //if (MySandboxGame.IsPaused && !control.DrawWhilePaused) continue;
                    control.Draw(transitionAlpha);
                }
            }

            //  Finaly draw opened combobox and dragAndDrop, so it will overdraw all other controls

            if (m_comboboxHandlingNow != null)
            {
                m_comboboxHandlingNow.Draw(transitionAlpha);
            }

            if (m_listboxDragAndDropHandlingNow != null)
            {
                m_listboxDragAndDropHandlingNow.Draw(transitionAlpha);
            }

            // draw tooltips only when screen has focus
            if (this == MyScreenManager.GetScreenWithFocus())
            {
                //  Draw tooltips
                foreach (var control in Controls.GetVisibleControls())
                {
                    control.ShowToolTip();
                }
            }
        }
Beispiel #6
0
        public void Drop()
        {
            if (!IsActive())
            {
                return;
            }

            MyDragAndDropInfo dropTo = null;

            m_dropToControls.Clear();

            MyScreenManager.GetControlsUnderMouseCursor(m_dropToControls, true);

            foreach (var control in m_dropToControls)
            {
                var grid = control as MyGuiControlGrid;
                if (grid != null)
                {
                    if (grid.Enabled && grid.MouseOverIndex != MyGuiControlGrid.INVALID_INDEX)
                    {
                        dropTo           = new MyDragAndDropInfo();
                        dropTo.Grid      = grid;
                        dropTo.ItemIndex = grid.MouseOverIndex;
                        break;
                    }
                }
            }

            ItemDropped(this, new MyDragAndDropEventArgs()
            {
                DragFrom   = m_draggingFrom,
                DropTo     = dropTo,
                Item       = m_draggingGridItem,
                DragButton = m_dragButton.Value,
            });

            Stop();
        }
Beispiel #7
0
        public void BackToIntroLogos(Action afterLogosAction)
        {
            MyScreenManager.CloseAllScreensNowExcept(null);

            string[] logos = new string[]
            {
                //"Textures\\Logo\\keen_swh",
                //"Textures\\Logo\\game",
                //"Textures\\Logo\\vrage",
            };

            MyGuiScreenBase previousScreen = null;

            foreach (var logo in logos)
            {
                var logoScreen = new MyGuiScreenLogo(logo);
                if (previousScreen != null)
                {
                    AddCloseHandler(previousScreen, logoScreen, afterLogosAction);
                }
                else
                {
                    AddScreen(logoScreen);
                }

                previousScreen = logoScreen;
            }

            if (previousScreen != null)
            {
                previousScreen.Closed += (screen) => afterLogosAction();
            }
            else
            {
                afterLogosAction();
            }
        }
Beispiel #8
0
        //  Draw all screens
        public void Draw()
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGuiSandbox::Draw");

            ProfilerShort.Begin("ScreenManager.Draw");
            MyScreenManager.Draw();
            ProfilerShort.End();

            m_debugText.Clear();

            if (MyInput.Static.ENABLE_DEVELOPER_KEYS && MySandboxGame.Config.DebugComponentsInfo != MyDebugComponent.MyDebugComponentInfoState.NoInfo)
            {
                var  h = 0f;
                var  i = 0;
                bool drawBackground = false;

                MyDebugComponent.ResetFrame();

                foreach (var userInputComponent in UserDebugInputComponents)
                {
                    if (userInputComponent.Enabled)
                    {
                        if (h == 0)
                        {
                            m_debugText.AppendLine("Debug input:");
                            m_debugText.AppendLine();
                            h += 0.0630f;
                        }
                        m_debugText.ConcatFormat("{0} (Ctrl + numPad{1})", UserDebugInputComponents[i].GetName(), i);
                        m_debugText.AppendLine();
                        h += 0.0265f;
                        if (MySession.Static != null)
                        {
                            userInputComponent.DispatchUpdate();
                        }
                        userInputComponent.Draw();
                        drawBackground = true;
                    }
                    ++i;
                }

                if (drawBackground)
                {
                    MyGuiManager.DrawSpriteBatch(@"Textures\GUI\Controls\rectangle_dark_center.dds",
                                                 new Vector2(MyGuiManager.GetMaxMouseCoord().X, 0f),
                                                 new Vector2(MyGuiManager.MeasureString(MyFontEnum.White, m_debugText, 1f).X + 0.012f, h),
                                                 new Color(0, 0, 0, 130),
                                                 MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
                    MyGuiManager.DrawString(MyFontEnum.White, m_debugText, new Vector2(MyGuiManager.GetMaxMouseCoord().X - 0.01f, 0f), 1f, Color.White, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
                }
            }

            bool hwCursor = MyVideoSettingsManager.IsHardwareCursorUsed();

            var screenWithFocus = MyScreenManager.GetScreenWithFocus();

            if (((screenWithFocus != null) && (screenWithFocus.GetDrawMouseCursor() == true)) || (MyScreenManager.InputToNonFocusedScreens && MyScreenManager.GetScreensCount() > 1))
            {
#if XB1
                SetMouseCursorVisibility(false, false);
                DrawMouseCursor(GetMouseOverTexture(screenWithFocus));
#else
                SetMouseCursorVisibility(hwCursor, false);

                if (!hwCursor || MyFakes.FORCE_SOFTWARE_MOUSE_DRAW)
                {
                    DrawMouseCursor(GetMouseOverTexture(screenWithFocus));
                }
#endif
            }
            else
            {
                if (hwCursor)
                {
                    if (screenWithFocus != null)
                    {
                        SetMouseCursorVisibility(screenWithFocus.GetDrawMouseCursor());
                    }
                }
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Beispiel #9
0
        //  Sends input (keyboard/mouse) to screen which has focus (top-most)
        public void HandleInputAfterSimulation()
        {
            if (MySession.Static != null)
            {
                bool cameraControllerMovementAllowed = MyScreenManager.GetScreenWithFocus() == MyGuiScreenGamePlay.Static && MyGuiScreenGamePlay.Static != null && !MyScreenManager.InputToNonFocusedScreens;
                bool lookAroundEnabled = MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND) || (MySession.Static.ControlledEntity != null && MySession.Static.ControlledEntity.PrimaryLookaround);

                //After respawn, the controlled object might be null
                bool shouldStopControlledObject = MySession.Static.ControlledEntity != null && (!cameraControllerMovementAllowed && m_cameraControllerMovementAllowed != cameraControllerMovementAllowed);

                bool movementAllowedInPause = MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Spectator ||
                                              MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorDelta ||
                                              MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorFixed;
                bool rotationAllowedInPause = movementAllowedInPause;   //GK: consider removing if in the future is not different from movementAllowed
                bool devScreenFlag          = MyScreenManager.GetScreenWithFocus() is MyGuiScreenDebugBase && !MyInput.Static.IsAnyAltKeyPressed();
                MyCameraControllerEnum cce  = MySession.Static.GetCameraControllerEnum();

                float             rollIndicator     = MyInput.Static.GetRoll();
                Vector2           rotationIndicator = MyInput.Static.GetRotation();
                VRageMath.Vector3 moveIndicator     = MyInput.Static.GetPositionDelta();

                var focusScreen = MyScreenManager.GetScreenWithFocus();

                if (MySandboxGame.IsPaused && focusScreen is MyGuiScreenGamePlay)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!movementAllowedInPause)
                    {
                        moveIndicator = VRageMath.Vector3.Zero;
                    }
                    if (!rotationAllowedInPause || devScreenFlag)
                    {
                        rollIndicator     = 0.0f;
                        rotationIndicator = Vector2.Zero;
                    }

                    MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);
                }
                else if (lookAroundEnabled)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        //Then move camera (because it can be dependent on control object)
                        MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);

                        if (!m_lookAroundEnabled && shouldStopControlledObject)
                        {
                            MySession.Static.ControlledEntity.MoveAndRotateStopped();
                        }
                    }

                    if (shouldStopControlledObject)
                    {
                        MySession.Static.CameraController.RotateStopped();
                    }
                }
                //Hack to make spectators work until they are made entities
                else if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.ConstantDelta)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                }

                if (shouldStopControlledObject)
                {
                    MySession.Static.ControlledEntity.MoveAndRotateStopped();
                }

                m_cameraControllerMovementAllowed = cameraControllerMovementAllowed;
                m_lookAroundEnabled = lookAroundEnabled;
            }
        }
Beispiel #10
0
        //  Sends input (keyboard/mouse) to screen which has focus (top-most)
        public void HandleInput()
        {
            ProfilerShort.Begin("MyGuiManager.HandleInput");
            try
            {
                if (MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.F4))
                {
                    MyAnalyticsTracker.SendGameEnd("Alt+F4", MySandboxGame.TotalTimeInMilliseconds / 1000);

                    //  Exit application
                    MySandboxGame.ExitThreadSafe();
                    return;
                }

                //  Screenshot(s)
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SCREENSHOT))
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    TakeScreenshot();
                }

                bool newPressf12 = MyInput.Static.IsNewKeyPressed(MyKeys.F12);
                bool newPressf2  = MyInput.Static.IsNewKeyPressed(MyKeys.F2);
                if ((newPressf2 || newPressf12) && MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyAltKeyPressed())
                {
                    if (MySession.Static != null && MySession.Static.CreativeMode)
                    {
                        if (newPressf12)
                        {
                            MyDebugDrawSettings.DEBUG_DRAW_PHYSICS = !MyDebugDrawSettings.DEBUG_DRAW_PHYSICS;
                            if (!m_shapeRenderingMessageBoxShown)
                            {
                                m_shapeRenderingMessageBoxShown = true;
                                AddScreen(MyGuiSandbox.CreateMessageBox(
                                              messageCaption: new StringBuilder("PHYSICS SHAPES"),
                                              messageText: new StringBuilder("Enabled physics shapes rendering. This feature is for modders only and is not part of the gameplay.")));
                            }
                        }
                    }
                    else
                    {
                        AddScreen(MyGuiSandbox.CreateMessageBox(
                                      messageCaption: new StringBuilder("MODDING HELPER KEYS"),
                                      messageText: new StringBuilder("Use of helper key combinations for modders is only allowed in creative mode.")));
                    }
                    return;
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.H) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    if (MyFakes.ENABLE_NETGRAPH)
                    {
                        MyHud.IsNetgraphVisible = !MyHud.IsNetgraphVisible;
                    }
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.F11))
                {
                    if (MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        SwitchTimingScreen();
                    }
                }

                if (MyFakes.ENABLE_MISSION_SCREEN && MyInput.Static.IsNewKeyPressed(MyKeys.U))
                {
                    MyScreenManager.AddScreen(new MyGuiScreenMission());
                }

                if (!MyInput.Static.ENABLE_DEVELOPER_KEYS && Sync.MultiplayerActive && m_currentDebugScreen is MyGuiScreenDebugOfficial)
                {
                    RemoveScreen(m_currentDebugScreen);
                    m_currentDebugScreen = null;
                }

                bool inputHandled = false;

                if (MySession.Static != null && MySession.Static.CreativeMode ||
                    MyInput.Static.ENABLE_DEVELOPER_KEYS)
                {
                    F12Handling();
                }

                if (MyInput.Static.ENABLE_DEVELOPER_KEYS)
                {
                    //  Statistics screen
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.F11) && !MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        SwitchStatisticsScreen();
                    }

                    if (MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsAnyCtrlKeyPressed() &&
                        MyInput.Static.IsNewKeyPressed(MyKeys.Home))
                    {
                        throw new InvalidOperationException("Controlled crash");
                    }

                    // Forge GC to run
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Pause) && MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        GC.Collect(GC.MaxGeneration);
                    }

                    if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.F2))
                    {
                        //Reload textures
                        if (MyInput.Static.IsKeyPress(MyKeys.LeftShift))
                        {
                            MyDefinitionManager.Static.ReloadDecalMaterials();
                            VRageRender.MyRenderProxy.ReloadTextures();
                        }
                        else
                        if (MyInput.Static.IsKeyPress(MyKeys.LeftAlt))
                        {
                            VRageRender.MyRenderProxy.ReloadModels();
                        }
                        else
                        {
                            VRageRender.MyRenderProxy.ReloadEffects();
                        }
                    }

                    //WS size
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.F3) && MyInput.Static.IsKeyPress(MyKeys.LeftShift))
                    {
#if !XB1
                        WinApi.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
#endif // !XB1
                    }

                    inputHandled = HandleDebugInput();
                }

                if (!inputHandled)
                {
                    MyScreenManager.HandleInput();
                }
            }
            finally
            {
                ProfilerShort.End();
            }
        }
Beispiel #11
0
 public void RemoveScreen(MyGuiScreenBase screen)
 {
     MyScreenManager.RemoveScreen(screen);
 }
Beispiel #12
0
 public void AddScreen(MyGuiScreenBase screen)
 {
     MyScreenManager.AddScreen(screen);
 }
Beispiel #13
0
 public void UnloadContent()
 {
     MyScreenManager.UnloadContent();
 }