Пример #1
0
        public bool IsMirrorBlockValid(IMySlimBlock block, PaintMaterial paintMaterial)
        {
            if (block == null)
            {
                return(false);
            }

            if (Main.Palette.ColorPickMode)
            {
                return(false);
            }

            if (!paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                return(false);
            }

            if (!Utils.AllowedToPaintGrid(block.CubeGrid, MyAPIGateway.Session.Player.IdentityId))
            {
                return(false);
            }

            if (!Utils.SafeZoneCanPaint(block, MyAPIGateway.Multiplayer.MyId))
            {
                return(false);
            }

            BlockMaterial blockMaterial  = new BlockMaterial(block);
            bool          materialEquals = paintMaterial.PaintEquals(blockMaterial);

            if (Main.Palette.ReplaceMode)
            {
                return(!materialEquals);
            }

            if (!Main.InstantPaintAccess)
            {
                MyCubeBlockDefinition def = (MyCubeBlockDefinition)block.BlockDefinition;
                bool built = (block.BuildLevelRatio >= def.CriticalIntegrityRatio);

                if (!built || block.CurrentDamage > (block.MaxIntegrity / 10.0f))
                {
                    return(false);
                }
            }

            return(!materialEquals);
        }
Пример #2
0
        bool MirrorCheckSameColor(IMyCubeGrid grid, int axis, Vector3I originalPosition, PaintMaterial paintMaterial, out Vector3I?mirrorPosition)
        {
            mirrorPosition = null;

            switch (axis)
            {
            case 0:
                if (grid.XSymmetryPlane.HasValue)
                {
                    mirrorPosition = originalPosition + new Vector3I(((grid.XSymmetryPlane.Value.X - originalPosition.X) * 2) - (grid.XSymmetryOdd ? 1 : 0), 0, 0);
                }
                break;

            case 1:
                if (grid.YSymmetryPlane.HasValue)
                {
                    mirrorPosition = originalPosition + new Vector3I(0, ((grid.YSymmetryPlane.Value.Y - originalPosition.Y) * 2) - (grid.YSymmetryOdd ? 1 : 0), 0);
                }
                break;

            case 2:
                if (grid.ZSymmetryPlane.HasValue)
                {
                    mirrorPosition = originalPosition + new Vector3I(0, 0, ((grid.ZSymmetryPlane.Value.Z - originalPosition.Z) * 2) + (grid.ZSymmetryOdd ? 1 : 0));     // reversed on odd
                }
                break;
            }

            if (mirrorPosition.HasValue)
            {
                IMySlimBlock slim = grid.GetCubeBlock(mirrorPosition.Value);

                if (slim != null)
                {
                    return(paintMaterial.PaintEquals(slim));
                }
            }

            return(true);
        }
Пример #3
0
        bool ValidateMainBlock(IMySlimBlock block, PaintMaterial paintMaterial, BlockMaterial blockMaterial, bool trigger)
        {
            if (!paintMaterial.ColorMask.HasValue && !paintMaterial.Skin.HasValue)
            {
                string assigned = InputHandler.GetFriendlyStringForControl(MyAPIGateway.Input.GetGameControl(MyControlsSpace.CUBE_COLOR_CHANGE));

                Main.Notifications.Show(0, "No paint or skin enabled.", MyFontEnum.Red);
                Main.Notifications.Show(1, $"Press [{assigned}] to toggle color or combined with [Shift] to toggle skin.", MyFontEnum.Debug);

                Main.SelectionGUI.SetGUIStatus(0, "No paint or skin enabled.", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            if (!Utils.AllowedToPaintGrid(block.CubeGrid, MyAPIGateway.Session.Player.IdentityId))
            {
                if (trigger)
                {
                    Main.HUDSounds.PlayUnable();
                    Main.Notifications.Show(0, "Can't paint enemy ships.", MyFontEnum.Red, 2000);
                }

                Main.SelectionGUI.SetGUIStatus(0, "Not allied ship.", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            if (!Utils.SafeZoneCanPaint(block, MyAPIGateway.Multiplayer.MyId))
            {
                if (trigger)
                {
                    Main.HUDSounds.PlayUnable();
                    Main.Notifications.Show(0, "Can't paint in this safe zone.", MyFontEnum.Red, 2000);
                }

                Main.SelectionGUI.SetGUIStatus(0, "Protected by safe zone", "red");
                Main.SelectionGUI.SetGUIStatus(1, null);
                return(false);
            }

            bool materialEquals = paintMaterial.PaintEquals(blockMaterial);

            if (Main.Palette.ReplaceMode)
            {
                AimedState = (materialEquals ? SelectionState.Invalid : SelectionState.Valid);

                string assigned = InputHandler.GetFriendlyStringForControl(MyAPIGateway.Input.GetGameControl(MyControlsSpace.USE_SYMMETRY));

                if (AimedState == SelectionState.Invalid)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Already this material.", "red");
                }
                else
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to replace material.", "lime");
                }

                Main.SelectionGUI.SetGUIStatus(1, $"[{assigned}] {(Main.Palette.ReplaceShipWide ? "<color=yellow>" : "")}Replace mode: {(Main.Palette.ReplaceShipWide ? "Ship-wide" : "Grid")}");

                return(AimedState == SelectionState.Valid);
            }

            if (!Main.InstantPaintAccess)
            {
                MyCubeBlockDefinition def = (MyCubeBlockDefinition)block.BlockDefinition;
                bool built = (block.BuildLevelRatio >= def.CriticalIntegrityRatio);

                if (!built || block.CurrentDamage > (block.MaxIntegrity / 10.0f))
                {
                    AimedState = SelectionState.Invalid;

                    if (trigger)
                    {
                        Main.HUDSounds.PlayUnable();
                        Main.Notifications.Show(0, "Unfinished blocks can't be painted!", MyFontEnum.Red);
                    }

                    Main.SelectionGUI.SetGUIStatus(0, (!built ? "Block not built" : "Block damaged"), "red");
                    Main.SelectionGUI.SetGUIStatus(1, null);
                    return(false);
                }
            }

            MyCubeGrid grid              = (MyCubeGrid)block.CubeGrid;
            bool       symmetry          = Main.SymmetryAccess && MyCubeBuilder.Static.UseSymmetry && (grid.XSymmetryPlane.HasValue || grid.YSymmetryPlane.HasValue || grid.ZSymmetryPlane.HasValue);
            bool       symmetrySameColor = true;

            if (materialEquals)
            {
                AimedState = SelectionState.Invalid;

                if (symmetry)
                {
                    Vector3I?mirrorX  = null;
                    Vector3I?mirrorY  = null;
                    Vector3I?mirrorZ  = null;
                    Vector3I?mirrorYZ = null;

                    // NOTE: do not optimize, all methods must be called
                    if (!MirrorCheckSameColor(grid, 0, block.Position, paintMaterial, out mirrorX))
                    {
                        symmetrySameColor = false;
                    }

                    if (!MirrorCheckSameColor(grid, 1, block.Position, paintMaterial, out mirrorY))
                    {
                        symmetrySameColor = false;
                    }

                    if (!MirrorCheckSameColor(grid, 2, block.Position, paintMaterial, out mirrorZ))
                    {
                        symmetrySameColor = false;
                    }

                    if (mirrorX.HasValue && grid.YSymmetryPlane.HasValue) // XY
                    {
                        if (!MirrorCheckSameColor(grid, 1, mirrorX.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (mirrorX.HasValue && grid.ZSymmetryPlane.HasValue) // XZ
                    {
                        if (!MirrorCheckSameColor(grid, 2, mirrorX.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (mirrorY.HasValue && grid.ZSymmetryPlane.HasValue) // YZ
                    {
                        if (!MirrorCheckSameColor(grid, 2, mirrorY.Value, paintMaterial, out mirrorYZ))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (grid.XSymmetryPlane.HasValue && mirrorYZ.HasValue) // XYZ
                    {
                        if (!MirrorCheckSameColor(grid, 0, mirrorYZ.Value, paintMaterial, out mirrorX))
                        {
                            symmetrySameColor = false;
                        }
                    }

                    if (!symmetrySameColor)
                    {
                        AimedState = SelectionState.InvalidButMirrorValid;
                    }
                }

                if (!symmetry || symmetrySameColor)
                {
                    AimedState = SelectionState.Invalid;

                    if (symmetry)
                    {
                        Main.SelectionGUI.SetGUIStatus(0, "All materials match.", "lime");
                    }
                    else
                    {
                        Main.SelectionGUI.SetGUIStatus(0, "Materials match.", "lime");
                    }

                    Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
                    return(false);
                }
            }

            if (!trigger)
            {
                if (symmetry && !symmetrySameColor)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to update symmetry paint.");
                }
                else if (Main.InstantPaintAccess)
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Click to paint.");
                }
                else
                {
                    Main.SelectionGUI.SetGUIStatus(0, "Hold click to paint.");
                }

                Main.SelectionGUI.SetGUIStatus(1, Main.SelectionGUI.SymmetryStatusText);
            }

            return(true);
        }