Example #1
0
        public override void Update(float dt)
        {
            ComponentPlayer componentPlayer = base.GameWidget.PlayerData.ComponentPlayer;

            if (componentPlayer == null || base.GameWidget.Target == null)
            {
                return;
            }
            ComponentInput componentInput  = componentPlayer.ComponentInput;
            Vector3        cameraSneakMove = componentInput.PlayerInput.CameraSneakMove;
            Vector2        cameraLook      = componentInput.PlayerInput.CameraLook;

            m_angles.X = MathUtils.NormalizeAngle(m_angles.X + 4f * cameraLook.X * dt + 0.5f * cameraSneakMove.X * dt);
            m_angles.Y = MathUtils.Clamp(MathUtils.NormalizeAngle(m_angles.Y + 4f * cameraLook.Y * dt), MathUtils.DegToRad(-20f), MathUtils.DegToRad(70f));
            m_distance = MathUtils.Clamp(m_distance - 10f * cameraSneakMove.Z * dt, 2f, 16f);
            Vector3 v       = Vector3.Transform(new Vector3(m_distance, 0f, 0f), Matrix.CreateFromYawPitchRoll(m_angles.X, 0f, m_angles.Y));
            Vector3 vector  = base.GameWidget.Target.ComponentBody.BoundingBox.Center();
            Vector3 vector2 = vector + v;

            if (Vector3.Distance(vector2, m_position) < 10f)
            {
                Vector3 v2 = vector2 - m_position;
                float   s  = MathUtils.Saturate(10f * dt);
                m_position += s * v2;
            }
            else
            {
                m_position = vector2;
            }
            Vector3 vector3 = m_position - vector;
            float?  num     = null;
            Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
            Vector3 v3      = Vector3.Normalize(Vector3.Cross(vector3, vector4));

            for (int i = 0; i <= 0; i++)
            {
                for (int j = 0; j <= 0; j++)
                {
                    Vector3 v4      = 0.5f * (vector4 * i + v3 * j);
                    Vector3 vector5 = vector + v4;
                    Vector3 end     = vector5 + vector3 + Vector3.Normalize(vector3) * 0.5f;
                    TerrainRaycastResult?terrainRaycastResult = base.GameWidget.SubsystemGameWidgets.SubsystemTerrain.Raycast(vector5, end, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => !BlocksManager.Blocks[Terrain.ExtractContents(value)].IsTransparent);
                    if (terrainRaycastResult.HasValue)
                    {
                        num = (num.HasValue ? MathUtils.Min(num.Value, terrainRaycastResult.Value.Distance) : terrainRaycastResult.Value.Distance);
                    }
                }
            }
            Vector3 vector6 = (!num.HasValue) ? (vector + vector3) : (vector + Vector3.Normalize(vector3) * MathUtils.Max(num.Value - 0.5f, 0.2f));

            SetupPerspectiveCamera(vector6, vector - vector6, Vector3.UnitY);
        }
Example #2
0
        public override void Update(float dt)
        {
            Vector3        vector         = Vector3.Zero;
            Vector2        vector2        = Vector2.Zero;
            ComponentInput componentInput = base.GameWidget.PlayerData.ComponentPlayer?.ComponentInput;

            if (componentInput != null)
            {
                vector  = componentInput.PlayerInput.CameraMove * new Vector3(1f, 0f, 1f);
                vector2 = componentInput.PlayerInput.CameraLook;
            }
            bool    num       = Keyboard.IsKeyDown(Key.Shift);
            bool    flag      = Keyboard.IsKeyDown(Key.Control);
            Vector3 direction = m_direction;
            Vector3 unitY     = Vector3.UnitY;
            Vector3 vector3   = Vector3.Normalize(Vector3.Cross(direction, unitY));
            float   num2      = 10f;

            if (num)
            {
                num2 *= 5f;
            }
            if (flag)
            {
                num2 /= 5f;
            }
            Vector3 zero = Vector3.Zero;

            zero         += num2 * vector.X * vector3;
            zero         += num2 * vector.Y * unitY;
            zero         += num2 * vector.Z * direction;
            m_rollSpeed   = MathUtils.Lerp(m_rollSpeed, -1.5f * vector2.X, 3f * dt);
            m_rollAngle  += m_rollSpeed * dt;
            m_rollAngle  *= MathUtils.Pow(0.33f, dt);
            m_pitchSpeed  = MathUtils.Lerp(m_pitchSpeed, -0.2f * vector2.Y, 3f * dt);
            m_pitchSpeed *= MathUtils.Pow(0.33f, dt);
            m_velocity   += 1.5f * (zero - m_velocity) * dt;
            m_position   += m_velocity * dt;
            m_direction   = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(unitY, 0.05f * m_rollAngle));
            m_direction   = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(vector3, 0.2f * m_pitchSpeed));
            Vector3 up = Vector3.TransformNormal(Vector3.UnitY, Matrix.CreateFromAxisAngle(m_direction, 0f - m_rollAngle));

            SetupPerspectiveCamera(m_position, m_direction, up);
        }
Example #3
0
        public void UpdateWidgets()
        {
            ComponentRider componentRider = m_componentPlayer.ComponentRider;
            ComponentSleep componentSleep = m_componentPlayer.ComponentSleep;
            ComponentInput componentInput = m_componentPlayer.ComponentInput;
            WorldSettings  worldSettings  = m_subsystemGameInfo.WorldSettings;
            GameMode       gameMode       = worldSettings.GameMode;

            UpdateSidePanelsAnimation();
            if (m_modalPanelAnimationData != null)
            {
                UpdateModalPanelAnimation();
            }
            if (m_message != null)
            {
                double realTime = Time.RealTime;
                m_largeMessageWidget.IsVisible = true;
                LabelWidget labelWidget  = m_largeMessageWidget.Children.Find <LabelWidget>("LargeLabel");
                LabelWidget labelWidget2 = m_largeMessageWidget.Children.Find <LabelWidget>("SmallLabel");
                labelWidget.Text       = m_message.LargeText;
                labelWidget2.Text      = m_message.SmallText;
                labelWidget.IsVisible  = !string.IsNullOrEmpty(m_message.LargeText);
                labelWidget2.IsVisible = !string.IsNullOrEmpty(m_message.SmallText);
                float num = (float)MathUtils.Min(MathUtils.Saturate(2.0 * (realTime - m_message.StartTime)), MathUtils.Saturate(2.0 * (m_message.StartTime + (double)m_message.Duration - realTime)));
                labelWidget.Color  = new Color(num, num, num, num);
                labelWidget2.Color = new Color(num, num, num, num);
                if (Time.RealTime > m_message.StartTime + (double)m_message.Duration)
                {
                    m_message = null;
                }
            }
            else
            {
                m_largeMessageWidget.IsVisible = false;
            }
            ControlsContainerWidget.IsVisible        = (m_componentPlayer.PlayerData.IsReadyForPlaying && m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled && componentSleep.SleepFactor <= 0f);
            m_moveRectangleContainerWidget.IsVisible = (!SettingsManager.HideMoveLookPads && componentInput.IsControlledByTouch);
            m_lookRectangleContainerWidget.IsVisible = (!SettingsManager.HideMoveLookPads && componentInput.IsControlledByTouch && (SettingsManager.LookControlMode != LookControlMode.EntireScreen || SettingsManager.MoveControlMode != MoveControlMode.Buttons));
            m_lookPadContainerWidget.IsVisible       = (SettingsManager.LookControlMode != LookControlMode.SplitTouch);
            MoveRoseWidget.IsVisible               = componentInput.IsControlledByTouch;
            m_moreContentsWidget.IsVisible         = m_moreButtonWidget.IsChecked;
            HealthBarWidget.IsVisible              = (gameMode != GameMode.Creative);
            FoodBarWidget.IsVisible                = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            TemperatureBarWidget.IsVisible         = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            LevelLabelWidget.IsVisible             = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            m_creativeFlyButtonWidget.IsVisible    = (gameMode == GameMode.Creative);
            m_timeOfDayButtonWidget.IsVisible      = (gameMode == GameMode.Creative);
            m_lightningButtonWidget.IsVisible      = (gameMode == GameMode.Creative);
            m_moveButtonsContainerWidget.IsVisible = (SettingsManager.MoveControlMode == MoveControlMode.Buttons);
            m_movePadContainerWidget.IsVisible     = (SettingsManager.MoveControlMode == MoveControlMode.Pad);
            if (SettingsManager.LeftHandedLayout)
            {
                m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
                m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
                m_moveRectangleWidget.FlipHorizontal      = true;
                m_lookRectangleWidget.FlipHorizontal      = false;
            }
            else
            {
                m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
                m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
                m_moveRectangleWidget.FlipHorizontal      = false;
                m_lookRectangleWidget.FlipHorizontal      = true;
            }
            m_sneakButtonWidget.IsChecked       = m_componentPlayer.ComponentBody.IsSneaking;
            m_creativeFlyButtonWidget.IsChecked = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
            m_inventoryButtonWidget.IsChecked   = IsInventoryVisible();
            m_clothingButtonWidget.IsChecked    = IsClothingVisible();
            if (IsActiveSlotEditable() || m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue)
            {
                m_sneakButtonWidget.IsVisible = false;
                m_mountButtonWidget.IsVisible = false;
                m_editItemButton.IsVisible    = true;
            }
            else if (componentRider != null && componentRider.Mount != null)
            {
                m_sneakButtonWidget.IsVisible = false;
                m_mountButtonWidget.IsChecked = true;
                m_mountButtonWidget.IsVisible = true;
                m_editItemButton.IsVisible    = false;
            }
            else
            {
                m_mountButtonWidget.IsChecked = false;
                if (componentRider != null && Time.FrameStartTime - m_lastMountableCreatureSearchTime > 0.5)
                {
                    m_lastMountableCreatureSearchTime = Time.FrameStartTime;
                    if (componentRider.FindNearestMount() != null)
                    {
                        m_sneakButtonWidget.IsVisible = false;
                        m_mountButtonWidget.IsVisible = true;
                        m_editItemButton.IsVisible    = false;
                    }
                    else
                    {
                        m_sneakButtonWidget.IsVisible = true;
                        m_mountButtonWidget.IsVisible = false;
                        m_editItemButton.IsVisible    = false;
                    }
                }
            }
            if (!m_componentPlayer.IsAddedToProject || m_componentPlayer.ComponentHealth.Health == 0f || componentSleep.IsSleeping || m_componentPlayer.ComponentSickness.IsPuking)
            {
                ModalPanelWidget = null;
            }
            if (m_componentPlayer.ComponentSickness.IsSick)
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(166, 175, 103);
            }
            else if (m_componentPlayer.ComponentFlu.HasFlu)
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(0, 48, 255);
            }
            else
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(224, 24, 0);
            }
        }