Example #1
0
        private void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView   = EditorUtil.CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            var vimTextBuffer = Vim.CreateVimTextBuffer(_textBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);

            _selection = _textView.Selection;
            _factory   = new MockRepository(MockBehavior.Strict);
            _tracker   = _factory.Create <ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.ResetCaret());
            _tracker.Setup(x => x.UpdateSelection());
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _commandUtil = _factory.Create <ICommandUtil>();
            var motionUtil = new MotionUtil(vimBufferData);
            var capture    = new MotionCapture(vimBufferData, new IncrementalSearch(vimBufferData, _operations.Object));
            var runner     = new CommandRunner(
                _textView,
                Vim.RegisterMap,
                capture,
                _commandUtil.Object,
                (new Mock <IStatusUtil>()).Object,
                VisualKind.Character);

            _modeRaw = new VisualMode(vimBufferData, _operations.Object, motionUtil, kind, runner, capture, _tracker.Object);
            _mode    = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Example #2
0
        public void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView   = EditorUtil.CreateView(lines);
            _textBuffer = _textView.TextBuffer;
            _selection  = _textView.Selection;
            _factory    = new MockRepository(MockBehavior.Strict);
            _map        = VimUtil.CreateRegisterMap(MockObjectFactory.CreateClipboardDevice(_factory).Object);
            _markMap    = new MarkMap(new TrackingLineColumnService());
            _tracker    = _factory.Create <ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.ResetCaret());
            _tracker.Setup(x => x.UpdateSelection());
            _jumpList           = _factory.Create <IJumpList>(MockBehavior.Loose);
            _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
            _foldManager        = _factory.Create <IFoldManager>();
            _editorOperations   = _factory.Create <IEditorOperations>();
            _operations         = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.FoldManager).Returns(_foldManager.Object);
            _operations.SetupGet(x => x.UndoRedoOperations).Returns(_undoRedoOperations.Object);
            _operations.SetupGet(x => x.EditorOperations).Returns(_editorOperations.Object);
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _host        = _factory.Create <IVimHost>(MockBehavior.Loose);
            _commandUtil = _factory.Create <ICommandUtil>();
            _commandUtil
            .Setup(x => x.RunCommand(It.Is <Command>(y => y.IsLegacyCommand)))
            .Returns <Command>(c => c.AsLegacyCommand().Item.Function.Invoke(null));
            _incrementalSearch = MockObjectFactory.CreateIncrementalSearch(factory: _factory);
            var globalSettings = new GlobalSettings();
            var localSettings  = new LocalSettings(globalSettings, _textView);
            var motionUtil     = VimUtil.CreateTextViewMotionUtil(
                _textView,
                _markMap,
                localSettings);

            _bufferData = MockObjectFactory.CreateVimBuffer(
                _textView,
                "test",
                MockObjectFactory.CreateVim(_map, host: _host.Object, settings: globalSettings).Object,
                incrementalSearch: _incrementalSearch.Object,
                jumpList: _jumpList.Object,
                motionUtil: motionUtil);
            var capture = new MotionCapture(
                _host.Object,
                _textView,
                _incrementalSearch.Object,
                localSettings);
            var runner = new CommandRunner(
                _textView,
                _map,
                capture,
                _commandUtil.Object,
                (new Mock <IStatusUtil>()).Object,
                VisualKind.Character);

            _modeRaw = new VisualMode(_bufferData.Object, _operations.Object, kind, runner, capture, _tracker.Object);
            _mode    = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Example #3
0
 public Render(string filename, string skinName, VisualMode mode = VisualMode.DARK_ROOM)
     : this(filename,
            Directory.GetDirectories(FileUtils.GetCarSkinsDirectory(Path.GetDirectoryName(filename)))
            .Select(Path.GetFileName).ToList().IndexOf(skinName),
            mode)
 {
 }
Example #4
0
        private static IEnumerable <Thing> GetIntersectingThings(VisualMode mode, Thing thing)
        {
            // Get nearby things
            List <Thing> neighbours = new List <Thing>();
            RectangleF   bbox       = new RectangleF(thing.Position.x - thing.Size, thing.Position.y - thing.Size, thing.Size * 2, thing.Size * 2);
            Point        p1         = mode.BlockMap.GetBlockCoordinates(new Vector2D(bbox.Left, bbox.Top));
            Point        p2         = mode.BlockMap.GetBlockCoordinates(new Vector2D(bbox.Right, bbox.Bottom));

            for (int x = p1.X; x <= p2.X; x++)
            {
                for (int y = p1.Y; y <= p2.Y; y++)
                {
                    neighbours.AddRange(mode.BlockMap.GetBlock(new Point(x, y)).Things);
                }
            }

            // Collect things intersecting with target thing
            List <Thing> intersectingthings = new List <Thing>();

            foreach (Thing t in neighbours)
            {
                if (t != thing && t.Sector != null && bbox.IntersectsWith(new RectangleF(t.Position.x - t.Size, t.Position.y - t.Size, t.Size * 2, t.Size * 2)))
                {
                    intersectingthings.Add(t);
                }
            }

            return(intersectingthings);
        }
Example #5
0
        private void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView   = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            var vimTextBuffer = Vim.CreateVimTextBuffer(_textBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            var visualKind    = VisualKind.OfModeKind(kind).Value;

            _selection = _textView.Selection;
            _factory   = new MockRepository(MockBehavior.Strict);
            _tracker   = _factory.Create <ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.UpdateSelection());
            _tracker.Setup(x => x.RecordCaretTrackingPoint(It.IsAny <ModeArgument>()));
            _tracker.SetupGet(x => x.IsRunning).Returns(true);
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _operations.Setup(x => x.MoveCaretToPoint(It.IsAny <SnapshotPoint>(), ViewFlags.Standard));
            _commandUtil = _factory.Create <ICommandUtil>();
            var motionUtil = new MotionUtil(vimBufferData, _operations.Object);
            var capture    = new MotionCapture(vimBufferData, new IncrementalSearch(vimBufferData, _operations.Object, motionUtil));
            var runner     = new CommandRunner(
                vimBufferData,
                capture,
                _commandUtil.Object,
                VisualKind.Character,
                KeyRemapMode.Visual);

            _modeRaw = new VisualMode(vimBufferData, _operations.Object, motionUtil, visualKind, runner, capture, _tracker.Object);
            _mode    = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Example #6
0
        public static FlatArray <ITile> GenerateRandomMap(int x, int y, VisualMode mode)
        {
            FlatArray <ITile> resultTiles = new FlatArray <ITile>(x, y);

            switch (mode)
            {
            case VisualMode.ASCII:
            {
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        int val = rng.Next(0, 100);
                        if (val > 70)
                        {
                            Terrain wall = new Terrain("wall", "#", Tile.MaxVolume);
                            resultTiles[i, j] = new Tile(new Point(i, j), wall);
                        }
                        else
                        {
                            Terrain grass = new Terrain("grass", ",", 5, Flags.IsTransparent);
                            resultTiles[i, j] = new Tile(new Point(i, j), grass);
                        }
                    }
                }

                break;
            }

            case VisualMode.Sprites:
                break;
            }

            return(resultTiles);
        }
Example #7
0
 public PaintBotConfig(string name, GameMode gameMode, int gameLengthInSeconds, VisualMode visualMode)
 {
     Name                = name;
     GameMode            = gameMode;
     GameLengthInSeconds = gameLengthInSeconds;
     VisualMode          = visualMode;
 }
Example #8
0
 protected void SetVisualMode(VisualMode mode)
 {
     visualMode = mode;
     EnableInClassList(k_InsertMode, mode == VisualMode.Insert);
     EnableInClassList(k_AddEndMode, mode == VisualMode.AddToEnd);
     EnableInClassList(k_AddStartMode, mode == VisualMode.AddToStart);
     EnableInClassList(k_DisabledMode, mode == VisualMode.Disabled);
 }
Example #9
0
 protected PaintBot(PaintBotConfig paintBotConfig, IPaintBotClient paintBotClient, IHearBeatSender heartBeatSender, ILogger logger)
 {
     _paintBotClient      = paintBotClient;
     _heartBeatSender     = heartBeatSender;
     _logger              = logger;
     visualMode           = paintBotConfig.VisualMode;
     _gameLengthInSeconds = paintBotConfig.GameLengthInSeconds;
 }
        void SetVisualMode(VisualMode mode)
        {
            int intMode = (int)mode;
            var euler   = RT.localEulerAngles;

            euler.x             = 10f * intMode;
            euler.z             = 4f * intMode;
            RT.localEulerAngles = euler;
        }
Example #11
0
        public VisualEngine(
            VisualMode mode,
            int tileSize,
            Point mapDrawboxTileSize,
            IMap map,
            ContentManager content = null,
            SpriteFont spriteFont  = null)
        {
            this.mode               = mode;
            this.tileSize           = tileSize;
            this.MapDrawboxTileSize = mapDrawboxTileSize;
            this.Map         = map;
            this.FOVSettings = new FOVSettings();

            // Set defaults
            this.TopMargin  = 10;
            this.LeftMargin = 10;
            this.spriteDict = new Dictionary <string, Texture2D>();
            this.DeltaTileDrawCoordinates = new Point(0, 0);
            this.highlighterIsOn          = false;
            this.tilesToHighlight         = new List <Point>();

            this.ASCIIColor    = Color.White;
            this.ASCIIRotation = 0f;
            this.ASCIIScale    = 1f;
            this.ASCIIOrigin   = new Vector2(0, 0);
            this.ASCIIEffects  = SpriteEffects.None;
            this.LayerDepth    = 0f;

            switch (mode)
            {
            case VisualMode.ASCII:
                if (spriteFont == null)
                {
                    throw new ArgumentNullException(
                              "spriteFont",
                              "SpriteFont should be supplied to the constructor if ASCII mode is to be used.");
                }

                this.SpriteFont = spriteFont;
                break;

            case VisualMode.Sprites:
                if (content == null)
                {
                    throw new ArgumentNullException(
                              "content",
                              "ContentManager should be supplied to the constructor if Tiles mode is to be used.");
                }

                this.content = content;
                break;
            }
        }
Example #12
0
 public VisualEngine(
     VisualMode mode,
     int tileSize,
     int x,
     int y,
     IMap map,
     ContentManager content,
     SpriteFont spriteFont)
     : this(mode, tileSize, new Point(x, y), map, content, spriteFont)
 {
 }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            VisualMode mode = (VisualMode)value;

            if (mode == VisualMode.LinearMode)
            {
                return("LinearMode");
            }
            else
            {
                return("Default");
            }
        }
Example #14
0
        public VimHandler(TextArea ta, String FileName) : base(ta)
        {
            this.FileName  = FileName;
            CommandMode    = new CommandMode(this);
            InsertMode     = new InsertMode(this);
            ArgumentMode   = new ArgumentMode(this);
            VisualMode     = new VisualMode(this);
            VisualLineMode = new VisualLineMode(this);

            ViSDGlobalState.StateChanged += delegate(object sender, State s) {
                ActualMode = GetModeByState(s);
            };

            ActualMode = GetModeByState(ViSDGlobalState.State);
        }
Example #15
0
        private void UpdateGeometry()
        {
            // Update what must be updated
            if (editingModeName == "BaseVisualMode")
            {
                VisualMode vm = ((VisualMode)General.Editing.Mode);

                for (int i = 0; i < selection.Count; i++)
                {
                    visualSelection[i].SetPosition(new Vector3D(selection[i].Position.x, selection[i].Position.y, selection[i].Sector.FloorHeight + selection[i].Position.z));
                    visualSelection[i].Update();

                    if (vm.VisualSectorExists(visualSelection[i].Thing.Sector))
                    {
                        vm.GetVisualSector(visualSelection[i].Thing.Sector).UpdateSectorGeometry(true);
                    }
                }
            }
            else
            {
                //update view
                General.Interface.RedrawDisplay();
            }
        }
Example #16
0
        private static IEnumerable <Thing> GetIntersectingThings(VisualMode mode, Thing thing)
        {
            // Get nearby things
            List <Thing> neighbours = new List <Thing>();
            RectangleF   bbox       = new RectangleF(thing.Position.x - thing.Size, thing.Position.y - thing.Size, thing.Size * 2, thing.Size * 2);

            foreach (var block in mode.BlockMap.GetBlocks(bbox))
            {
                neighbours.AddRange(block.Things);
            }

            // Collect things intersecting with target thing
            List <Thing> intersectingthings = new List <Thing>();

            foreach (Thing t in neighbours)
            {
                if (t != thing && t.Sector != null && bbox.IntersectsWith(new RectangleF(t.Position.x - t.Size, t.Position.y - t.Size, t.Size * 2, t.Size * 2)))
                {
                    intersectingthings.Add(t);
                }
            }

            return(intersectingthings);
        }
Example #17
0
        private void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            var vimTextBuffer = Vim.CreateVimTextBuffer(_textBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            var visualKind = VisualKind.OfModeKind(kind).Value;

            _selection = _textView.Selection;
            _factory = new MockRepository(MockBehavior.Strict);
            _tracker = _factory.Create<ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.UpdateSelection());
            _tracker.Setup(x => x.RecordCaretTrackingPoint(It.IsAny<ModeArgument>()));
            _tracker.SetupGet(x => x.IsRunning).Returns(true);
            _operations = _factory.Create<ICommonOperations>();
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _operations.Setup(x => x.MoveCaretToPoint(It.IsAny<SnapshotPoint>(), ViewFlags.Standard));
            _commandUtil = _factory.Create<ICommandUtil>();
            var motionUtil = new MotionUtil(vimBufferData, _operations.Object);
            var capture = new MotionCapture(vimBufferData, new IncrementalSearch(vimBufferData, _operations.Object));
            var runner = new CommandRunner(
                _textView,
                Vim.RegisterMap,
                capture,
                vimBufferData.LocalSettings,
                _commandUtil.Object,
                (new Mock<IStatusUtil>()).Object,
                VisualKind.Character,
                KeyRemapMode.Visual);
            _modeRaw = new VisualMode(vimBufferData, _operations.Object, motionUtil, visualKind, runner, capture, _tracker.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Example #18
0
        void LoadScene(string filename, int skinNumber, VisualMode mode)
        {
            _mode     = mode;
            _filename = filename;

            _kn5 = Kn5.FromFile(filename, mode == VisualMode.BODY_SHADOW || mode == VisualMode.TRACK_MAP);
            if (_kn5.IsWithoutTextures())
            {
                var mainFile = FileUtils.GetMainCarFilename(Path.GetDirectoryName(filename));
                if (mainFile != null)
                {
                    _kn5.LoadTexturesFrom(mainFile);
                }
            }

            _textures = new Dictionary <string, ShaderResourceView>(_kn5.Textures.Count);

            LoadMaterials();
            GetObjects();

            _wireframeBackgroundColor = new Color4(0x292826);

            switch (_mode)
            {
            case VisualMode.SIMPLE_PREVIEW_GT5: {
                _camera = new CameraOrbit(0.08f * MathF.PI)
                {
                    Alpha = 1.1f, Beta = -0.04f, Radius = 8.0f, Target = new Vector3(0, 0.78f, 0)
                };

                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(0.65f, 0.66f, 0.64f),
                    Diffuse   = new Color4(1.84f, 1.87f, 1.88f),
                    Specular  = new Color4(0.95f, 0.96f, 1.13f),
                    Direction = new Vector3(-1.57735f, -2.57735f, 0.57735f)
                };

                _backgroundColor   = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
                _reflectionCubemap = ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomReflection);
            }
            break;

            case VisualMode.SIMPLE_PREVIEW_GT6: {
                _camera = new CameraOrbit(0.011f * MathF.PI)
                {
                    Alpha = 0.0f, Beta = 0.0f, NearZ = 1.0f, Radius = 90.0f, Target = new Vector3(0, 0.78f, 0)
                };

                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(0.65f, 0.66f, 0.64f),
                    Diffuse   = new Color4(1.84f, 1.87f, 1.88f),
                    Specular  = new Color4(0.95f, 0.96f, 1.13f),
                    Direction = new Vector3(-1.57735f, -2.57735f, 0.57735f)
                };

                _backgroundColor   = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
                _reflectionCubemap = ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomReflection);
            }
            break;

            case VisualMode.LIVERY_VIEW: {
                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(2.5f, 2.5f, 2.5f),
                    Diffuse   = new Color4(0.0f, 0.0f, 0.0f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(0.0f, -1.0f, 0.0f)
                };

                var pos = -_objectPos;
                pos.Y = CarSize.Y + 1.0f;

                _camera = new CameraOrtho()
                {
                    Position = pos,
                    FarZ     = CarSize.Y + 10.0f,
                    Target   = pos - Vector3.UnitY,
                    Width    = CarSize.X,
                    Height   = CarSize.Z
                };

                foreach (var obj in _objs)
                {
                    if (obj.Blen != null)
                    {
                        obj.Blen.Dispose();

                        var transDesc = new BlendStateDescription {
                            AlphaToCoverageEnable  = false,
                            IndependentBlendEnable = false
                        };

                        transDesc.RenderTargets[0].BlendEnable           = true;
                        transDesc.RenderTargets[0].SourceBlend           = BlendOption.Zero;
                        transDesc.RenderTargets[0].DestinationBlend      = BlendOption.Zero;
                        transDesc.RenderTargets[0].BlendOperation        = BlendOperation.Add;
                        transDesc.RenderTargets[0].SourceBlendAlpha      = BlendOption.Zero;
                        transDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
                        transDesc.RenderTargets[0].BlendOperationAlpha   = BlendOperation.Add;
                        transDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

                        obj.Blen = BlendState.FromDescription(CurrentDevice, transDesc);
                    }
                }

                _backgroundColor = new Color4(0.0f, 0.0f, 0.0f, 0.0f);
            }
            break;

            case VisualMode.SIMPLE_PREVIEW_SEAT_LEON_EUROCUP: {
                _camera = new CameraOrbit(0.011f * MathF.PI)
                {
                    Alpha = 0.0f, Beta = 0.0f, NearZ = 1.0f, Radius = 90.0f, Target = new Vector3(0, 0.78f, 0)
                };

                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(0.65f, 0.66f, 0.64f),
                    Diffuse   = new Color4(1.89f, 1.89f, 1.84f),
                    Specular  = new Color4(2.95f, 2.96f, 2.13f),
                    Direction = new Vector3(-1.57735f, -0.57735f, 0.57735f)
                };

                _backgroundColor   = new Color4(0.68f, 0.68f, 0.68f);
                _reflectionCubemap = ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomReflection);
            }
            break;

            case VisualMode.DARK_ROOM: {
                _camera = new CameraOrbit(0.15f * MathF.PI)
                {
                    Alpha = 1.1f, Beta = 0.021f, Radius = 5.4f, Target = new Vector3(0, 0.78f, 0)
                };

                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(1.45f, 1.46f, 1.44f),
                    Diffuse   = new Color4(2.24f, 2.23f, 2.20f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(-1.57735f, -2.57735f, 0.57735f)
                };

                _backgroundColor   = new Color4(0.0f, 0.0f, 0.0f);
                _reflectionCubemap = ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomReflection);

                var size    = CarSize;
                var maxSize = System.Math.Max(size.X, size.Z) * 0.8f;
                var pos     = _objectPos;
                pos.Y = 0;
                CreateTexturedPlace(Matrix.Scaling(maxSize, 1.0f, maxSize) * Matrix.Translation(pos),
                                    ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomFloor));
                LoadShadows();
            }
            break;

            case VisualMode.BRIGHT_ROOM: {
                _camera = new CameraOrbit(0.15f * MathF.PI)
                {
                    Alpha = 1.1f, Beta = 0.021f, Radius = 5.4f, Target = new Vector3(0, 0.78f, 0)
                };

                _dirLight = new DirectionalLight {
                    Ambient   = new Color4(2.36f, 2.36f, 2.36f),
                    Diffuse   = new Color4(1.08f, 1.08f, 1.08f),
                    Specular  = new Color4(0.0f, 0.0f, 0.0f),
                    Direction = new Vector3(1.57735f, -2.57735f, 0.57735f)
                };

                _backgroundColor   = new Color4(0.9f, 0.92f, 0.97f);
                _reflectionCubemap = ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomReflection);

                var size    = CarSize;
                var maxSize = System.Math.Max(size.X, size.Z) * 0.8f;
                var pos     = _objectPos;
                pos.Y = 0;
                CreateTexturedPlace(Matrix.Scaling(maxSize, 1.0f, maxSize) * Matrix.Translation(pos),
                                    ShaderResourceView.FromMemory(CurrentDevice, Properties.Resources.TextureDarkRoomFloor)).Visible = false;
                LoadShadows();
            }
            break;

            case VisualMode.BODY_SHADOW: {
                LoadShadowsSize();
            }
                return;

            case VisualMode.TRACK_MAP:
                return;
            }

            LoadSkins();
            if (skinNumber >= 0 && skinNumber < Skins.Count)
            {
                LoadSkin(skinNumber);
            }

            LoadTextures();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupBarGettingStartedViewModel" /> class.
 /// </summary>
 public GroupBarGettingStartedViewModel()
 {
     visualMode           = new DelegateCommand <object>(HideAllowCollapse);
     selectedModeproperty = VisualMode.StackMode;
 }
Example #20
0
        public bool Setup(string editingModeName)
        {
            mode = editingModeName;

            if (mode == "SectorsMode")
            {
                selection = (List <Sector>)(General.Map.Map.GetSelectedSectors(true));
            }
            else             //should be Visual mode
            {
                selection = new List <Sector>();
                VisualMode vm = (VisualMode)General.Editing.Mode;
                visualSelection = vm.GetSelectedVisualSectors(false);

                if (visualSelection.Count > 0)
                {
                    foreach (VisualSector vs in visualSelection)
                    {
                        selection.Add(vs.Sector);
                    }
                }
                else                 //should be some sectors selected in 2d-mode...
                {
                    visualSelection = new List <VisualSector>();
                    selection       = (List <Sector>)(General.Map.Map.GetSelectedSectors(true));

                    foreach (Sector s in selection)
                    {
                        if (vm.VisualSectorExists(s))
                        {
                            visualSelection.Add(vm.GetVisualSector(s));
                        }
                    }
                }
            }

            //create undo
            string rest = selection.Count + " sector" + (selection.Count > 1 ? "s" : "");

            General.Map.UndoRedo.CreateUndo("Edit color of " + rest);

            foreach (Sector s in selection)
            {
                s.Fields.BeforeFieldsChange();
            }

            //set colors
            curSectorColor = selection[0].Fields.GetValue("lightcolor", DEFAULT_LIGHT_COLOR);
            curFadeColor   = selection[0].Fields.GetValue("fadecolor", DEFAULT_FADE_COLOR);

            //check that all sectors in selection have "lightcolor" and "fadecolor" fields
            for (int i = 0; i < selection.Count; i++)
            {
                if (!selection[i].Fields.ContainsKey("lightcolor"))
                {
                    selection[i].Fields.Add("lightcolor", new UniValue(UniversalType.Color, curSectorColor));
                }

                if (!selection[i].Fields.ContainsKey("fadecolor"))
                {
                    selection[i].Fields.Add("fadecolor", new UniValue(UniversalType.Color, curFadeColor));
                }
            }

            initialSectorColor = curSectorColor;
            initialFadeColor   = curFadeColor;

            InitializeComponent();

            colorPickerControl1.Initialize(Color.FromArgb(currentColorTag == "lightcolor" ? curSectorColor : curFadeColor));
            colorPickerControl1.OnColorChanged  += OnColorPickerControl1OnColorChanged;
            colorPickerControl1.OnOkPressed     += colorPickerControl1_OnOkPressed;
            colorPickerControl1.OnCancelPressed += colorPickerControl1_OnCancelPressed;

            if (currentColorTag == "lightcolor")
            {
                rbSectorColor.Checked = true;
            }
            else
            {
                rbFadeColor.Checked = true;
            }

            rbSectorColor.CheckedChanged += rbColor_CheckedChanged;
            rbFadeColor.CheckedChanged   += rbColor_CheckedChanged;

            Text = "Editing " + rest;

            //cannot fail here :)
            return(true);
        }
Example #21
0
 public void Create2(
     ModeKind kind = ModeKind.VisualCharacter,
     params string[] lines)
 {
     _textView = EditorUtil.CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _selection = _textView.Selection;
     _factory = new MockRepository(MockBehavior.Strict);
     _map = VimUtil.CreateRegisterMap(MockObjectFactory.CreateClipboardDevice(_factory).Object);
     _markMap = new MarkMap(new TrackingLineColumnService());
     _tracker = _factory.Create<ISelectionTracker>();
     _tracker.Setup(x => x.Start());
     _tracker.Setup(x => x.ResetCaret());
     _tracker.Setup(x => x.UpdateSelection());
     _jumpList = _factory.Create<IJumpList>(MockBehavior.Loose);
     _undoRedoOperations = _factory.Create<IUndoRedoOperations>();
     _foldManager = _factory.Create<IFoldManager>();
     _editorOperations = _factory.Create<IEditorOperations>();
     _operations = _factory.Create<ICommonOperations>();
     _operations.SetupGet(x => x.UndoRedoOperations).Returns(_undoRedoOperations.Object);
     _operations.SetupGet(x => x.EditorOperations).Returns(_editorOperations.Object);
     _operations.SetupGet(x => x.TextView).Returns(_textView);
     _host = _factory.Create<IVimHost>(MockBehavior.Loose);
     _commandUtil = _factory.Create<ICommandUtil>();
     _incrementalSearch = MockObjectFactory.CreateIncrementalSearch(factory: _factory);
     var globalSettings = new GlobalSettings();
     var localSettings = new LocalSettings(globalSettings, EditorUtil.GetEditorOptions(_textView), _textView);
     var motionUtil = VimUtil.CreateTextViewMotionUtil(
         _textView,
         _markMap,
         localSettings);
     _bufferData = MockObjectFactory.CreateVimBuffer(
         _textView,
         "test",
         MockObjectFactory.CreateVim(_map, host: _host.Object, settings: globalSettings).Object,
         incrementalSearch: _incrementalSearch.Object,
         jumpList: _jumpList.Object,
         motionUtil: motionUtil);
     var capture = new MotionCapture(
         _host.Object,
         _textView,
         _incrementalSearch.Object,
         localSettings);
     var runner = new CommandRunner(
         _textView,
         _map,
         capture,
         _commandUtil.Object,
         (new Mock<IStatusUtil>()).Object,
         VisualKind.Character);
     _modeRaw = new VisualMode(_bufferData.Object, _operations.Object, kind, runner, capture, _tracker.Object);
     _mode = _modeRaw;
     _mode.OnEnter(ModeArgument.None);
 }
        public JitterVerticesForm(string editingModeName)
        {
            this.editingModeName = editingModeName;
            this.HelpRequested  += JitterVerticesForm_HelpRequested;

            InitializeComponent();

            //get selection
            selection = new List <Vertex>();

            if (editingModeName == "BaseVisualMode")
            {
                VisualMode            vm = (VisualMode)General.Editing.Mode;
                List <VisualGeometry> visualSelection = vm.GetSelectedSurfaces();
                visualSectors = new List <VisualSector>();
                int linesCount = 0;

                foreach (VisualGeometry vg in visualSelection)
                {
                    if (vg.Sidedef != null && vm.VisualSectorExists(vg.Sidedef.Sector))
                    {
                        if (!selection.Contains(vg.Sidedef.Line.Start))
                        {
                            selection.Add(vg.Sidedef.Line.Start);
                        }
                        if (!selection.Contains(vg.Sidedef.Line.End))
                        {
                            selection.Add(vg.Sidedef.Line.End);
                        }
                        linesCount++;

                        visualSectors.Add(vm.GetVisualSector(vg.Sidedef.Sector));

                        if (vg.Sidedef.Other != null && vg.Sidedef.Other.Sector != null && vm.VisualSectorExists(vg.Sidedef.Other.Sector))
                        {
                            visualSectors.Add(vm.GetVisualSector(vg.Sidedef.Other.Sector));
                        }
                    }
                }

                visualVerts = new List <VisualVertexPair>();
                foreach (Vertex vert in selection)
                {
                    if (vm.VisualVertices.ContainsKey(vert))
                    {
                        visualVerts.Add(vm.VisualVertices[vert]);
                    }
                }

                //update window header
                this.Text = "Randomize " + linesCount + (linesCount > 1 ? " linedefs" : " linedef");
            }
            else if (editingModeName == "LinedefsMode")
            {
                ICollection <Linedef> list = General.Map.Map.GetSelectedLinedefs(true);
                int linesCount             = 0;

                foreach (Linedef l in list)
                {
                    if (!selection.Contains(l.Start))
                    {
                        selection.Add(l.Start);
                    }
                    if (!selection.Contains(l.End))
                    {
                        selection.Add(l.End);
                    }
                    linesCount++;
                }

                //update window header
                this.Text = "Randomize " + linesCount + (linesCount > 1 ? " linedefs" : " linedef");
            }
            else
            {
                ICollection <Vertex> list = General.Map.Map.GetSelectedVertices(true);
                foreach (Vertex v in list)
                {
                    selection.Add(v);
                }

                //update window header
                this.Text = "Randomize " + selection.Count + (selection.Count > 1 ? " vertices" : " vertex");
            }

            if (selection.Count == 0)
            {
                General.Interface.DisplayStatus(StatusType.Warning, "Unable to get vertices from selection!");
                return;
            }

            //create undo
            General.Map.UndoRedo.ClearAllRedos();
            General.Map.UndoRedo.CreateUndo("Randomize " + selection.Count + (selection.Count > 1 ? " vertices" : " vertex"));

            Dictionary <Vertex, VertexData> data = new Dictionary <Vertex, VertexData>();

            foreach (Vertex v in selection)
            {
                VertexData vd = new VertexData {
                    Position = v.Position
                };
                data.Add(v, vd);
            }

            foreach (Vertex v in selection)
            {
                if (v.Linedefs == null)
                {
                    continue;
                }

                //get nearest linedef
                Linedef closestLine = null;
                float   distance    = float.MaxValue;

                // Go for all linedefs in selection
                foreach (Linedef l in General.Map.Map.Linedefs)
                {
                    if (v.Linedefs.Contains(l))
                    {
                        continue;
                    }

                    // Calculate distance and check if closer than previous find
                    float d = l.SafeDistanceToSq(v.Position, true);
                    if (d < distance)
                    {
                        // This one is closer
                        closestLine = l;
                        distance    = d;
                    }
                }

                if (closestLine == null)
                {
                    continue;
                }

                float closestLineDistance = Vector2D.Distance(v.Position, closestLine.NearestOnLine(v.Position));

                //check SafeDistance of closest line
                if (data.ContainsKey(closestLine.Start) &&
                    data[closestLine.Start].SafeDistance > closestLineDistance)
                {
                    VertexData vd = data[closestLine.Start];
                    vd.SafeDistance         = (int)Math.Floor(closestLineDistance);
                    data[closestLine.Start] = vd;
                }
                if (data.ContainsKey(closestLine.End) &&
                    data[closestLine.End].SafeDistance > closestLineDistance)
                {
                    VertexData vd = data[closestLine.End];
                    vd.SafeDistance       = (int)Math.Floor(closestLineDistance);
                    data[closestLine.End] = vd;
                }

                //save SafeDistance
                int dist = (int)Math.Floor(closestLineDistance);
                if (data[v].SafeDistance == 0 || data[v].SafeDistance > dist)
                {
                    VertexData vd = data[v];
                    vd.SafeDistance = dist;
                    data[v]         = vd;
                }
            }

            //store properties
            vertexData = new VertexData[data.Values.Count];
            data.Values.CopyTo(vertexData, 0);

            for (int i = 0; i < vertexData.Length; i++)
            {
                if (vertexData[i].SafeDistance > 0)
                {
                    vertexData[i].SafeDistance /= 2;
                }
                if (MaxSafeDistance < vertexData[i].SafeDistance)
                {
                    MaxSafeDistance = vertexData[i].SafeDistance;
                }
            }

            positionJitterAmmount.Maximum = MaxSafeDistance;

            UpdateAngles();
        }
Example #23
0
        private void Create2(
            ModeKind kind = ModeKind.VisualCharacter,
            params string[] lines)
        {
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            var vimTextBuffer = Vim.CreateVimTextBuffer(_textBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);

            _selection = _textView.Selection;
            _factory = new MockRepository(MockBehavior.Strict);
            _tracker = _factory.Create<ISelectionTracker>();
            _tracker.Setup(x => x.Start());
            _tracker.Setup(x => x.UpdateSelection());
            _tracker.SetupGet(x => x.IsRunning).Returns(true);
            _operations = _factory.Create<ICommonOperations>();
            _operations.SetupGet(x => x.TextView).Returns(_textView);
            _commandUtil = _factory.Create<ICommandUtil>();
            var motionUtil = new MotionUtil(vimBufferData);
            var capture = new MotionCapture(vimBufferData, new IncrementalSearch(vimBufferData, _operations.Object));
            var runner = new CommandRunner(
                _textView,
                Vim.RegisterMap,
                capture,
                _commandUtil.Object,
                (new Mock<IStatusUtil>()).Object,
                VisualKind.Character);
            _modeRaw = new VisualMode(vimBufferData, _operations.Object, motionUtil, kind, runner, capture, _tracker.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
        }
Example #24
0
 public void Create2(
     ModeKind kind=ModeKind.VisualCharacter,
     IVimHost host= null,
     params string[] lines)
 {
     _buffer = EditorUtil.CreateBuffer(lines);
     _caret = new Mock<ITextCaret>(MockBehavior.Strict);
     _view = new Mock<IWpfTextView>(MockBehavior.Strict);
     _selection = new Mock<ITextSelection>(MockBehavior.Strict);
     _view.SetupGet(x => x.Caret).Returns(_caret.Object);
     _view.SetupGet(x => x.Selection).Returns(_selection.Object);
     _view.SetupGet(x => x.TextBuffer).Returns(_buffer);
     _view.SetupGet(x => x.TextSnapshot).Returns(() => _buffer.CurrentSnapshot);
     _map = new RegisterMap();
     _editOpts = new Mock<IEditorOperations>(MockBehavior.Strict);
     _tracker = new Mock<ISelectionTracker>(MockBehavior.Strict);
     _tracker.Setup(x => x.Start());
     _operations = new Mock<IOperations>(MockBehavior.Strict);
     _operations.SetupGet(x => x.SelectionTracker).Returns(_tracker.Object);
     host = host ?? new FakeVimHost();
     _bufferData = MockObjectFactory.CreateVimBuffer(
         _view.Object,
         "test",
         MockObjectFactory.CreateVim(_map,host:host).Object,
         _editOpts.Object);
     _modeRaw = new Vim.Modes.Visual.VisualMode(Tuple.Create<IVimBuffer, IOperations, ModeKind>(_bufferData.Object, _operations.Object, kind));
     _mode = _modeRaw;
     _mode.OnEnter();
 }
Example #25
0
 public void Create2(
     ModeKind kind = ModeKind.VisualCharacter,
     params string[] lines)
 {
     _buffer = EditorUtil.CreateBuffer(lines);
     _factory = new MockRepository(MockBehavior.Strict);
     _caret = _factory.Create<ITextCaret>();
     _view = _factory.Create<IWpfTextView>();
     _selection = _factory.Create<ITextSelection>();
     _selection.Setup(x => x.Clear());
     _selection.SetupSet(x => x.Mode = TextSelectionMode.Stream);
     _view.SetupGet(x => x.Caret).Returns(_caret.Object);
     _view.SetupGet(x => x.Selection).Returns(_selection.Object);
     _view.SetupGet(x => x.TextBuffer).Returns(_buffer);
     _view.SetupGet(x => x.TextSnapshot).Returns(() => _buffer.CurrentSnapshot);
     _view.SetupGet(x => x.IsClosed).Returns(false);
     _map = new RegisterMap(MockObjectFactory.CreateClipboardDevice(_factory).Object);
     _tracker = _factory.Create<ISelectionTracker>();
     _tracker.Setup(x => x.Start());
     _tracker.Setup(x => x.ResetCaret());
     _undoRedoOperations = _factory.Create<IUndoRedoOperations>();
     _foldManager = _factory.Create<IFoldManager>();
     _editorOperations = _factory.Create<IEditorOperations>();
     _operations = _factory.Create<ICommonOperations>();
     _operations.SetupGet(x => x.FoldManager).Returns(_foldManager.Object);
     _operations.SetupGet(x => x.UndoRedoOperations).Returns(_undoRedoOperations.Object);
     _operations.SetupGet(x => x.EditorOperations).Returns(_editorOperations.Object);
     _host = _factory.Create<IVimHost>(MockBehavior.Loose);
     _bufferData = MockObjectFactory.CreateVimBuffer(
         _view.Object,
         "test",
         MockObjectFactory.CreateVim(_map, host: _host.Object).Object,
         factory: _factory);
     var capture = new MotionCapture(
         _host.Object,
         _view.Object,
         new TextViewMotionUtil(_view.Object, new Vim.LocalSettings(_bufferData.Object.Settings.GlobalSettings, _view.Object)),
         new MotionCaptureGlobalData());
     var runner = new CommandRunner(_view.Object, _map, (IMotionCapture)capture, (new Mock<IStatusUtil>()).Object);
     _modeRaw = new Vim.Modes.Visual.VisualMode(_bufferData.Object, _operations.Object, kind, runner, capture, _tracker.Object);
     _mode = _modeRaw;
     _mode.OnEnter(ModeArgument.None);
 }
Example #26
0
 public void Create2(
     ModeKind kind=ModeKind.VisualCharacter,
     params string[] lines)
 {
     _buffer = EditorUtil.CreateBuffer(lines);
     _caret = new Mock<ITextCaret>(MockBehavior.Strict);
     _view = new Mock<IWpfTextView>(MockBehavior.Strict);
     _selection = new Mock<ITextSelection>(MockBehavior.Strict);
     _view.SetupGet(x => x.Caret).Returns(_caret.Object);
     _view.SetupGet(x => x.Selection).Returns(_selection.Object);
     _view.SetupGet(x => x.TextBuffer).Returns(_buffer);
     _view.SetupGet(x => x.TextSnapshot).Returns(() => _buffer.CurrentSnapshot);
     _map = new RegisterMap();
     _tracker = new Mock<ISelectionTracker>(MockBehavior.Strict);
     _tracker.Setup(x => x.Start());
     _operations = new Mock<IOperations>(MockBehavior.Strict);
     _operations.SetupGet(x => x.SelectionTracker).Returns(_tracker.Object);
     _bufferData = MockObjectFactory.CreateVimBuffer(
         _view.Object,
         "test",
         MockObjectFactory.CreateVim(_map).Object);
     var capture = new MotionCapture(_view.Object, new MotionUtil(_view.Object, _bufferData.Object.Settings.GlobalSettings));
     var runner = new CommandRunner(Tuple.Create((ITextView)_view.Object, _map, (IMotionCapture)capture, (new Mock<IStatusUtil>()).Object));
     _modeRaw = new Vim.Modes.Visual.VisualMode(_bufferData.Object, _operations.Object, kind, runner, capture);
     _mode = _modeRaw;
     _mode.OnEnter();
 }
Example #27
0
        private void ApplyDirectionalShading()
        {
            // Boilerplate
            if (General.Editing.Mode == null)
            {
                return;
            }
            if (!General.Map.UDMF)
            {
                General.Interface.DisplayStatus(StatusType.Warning, "This action is available only in UDMF map format!");
                return;
            }

            DirectionalShadingForm form;
            string currentmodename = General.Editing.Mode.GetType().Name;

            // Create the form or tell the user why we can't do that
            if (currentmodename == "SectorsMode")
            {
                if (General.Map.Map.SelectedSectorsCount == 0)
                {
                    General.Interface.DisplayStatus(StatusType.Warning, "Select some sectors first!");
                    return;
                }

                // Collect sectors
                ICollection <Sector> sectors = General.Map.Map.GetSelectedSectors(true);

                // Collect sidedefs
                HashSet <Sidedef> sides = new HashSet <Sidedef>();
                foreach (Sector s in sectors)
                {
                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        sides.Add(sd);
                        if (sd.Other != null)
                        {
                            sides.Add(sd.Other);
                        }
                    }
                }

                // Create the form
                form = new DirectionalShadingForm(sectors, sides, null);
            }
            else if (currentmodename == "LinedefsMode")
            {
                if (General.Map.Map.SelectedLinedefsCount == 0)
                {
                    General.Interface.DisplayStatus(StatusType.Warning, "Select some linedefs first!");
                    return;
                }

                // Collect linedefs
                ICollection <Linedef> linedefs = General.Map.Map.GetSelectedLinedefs(true);

                // Collect sectors
                ICollection <Sector> sectors = General.Map.Map.GetSectorsFromLinedefs(linedefs);

                // Collect sidedefs from linedefs
                HashSet <Sidedef> sides = new HashSet <Sidedef>();
                foreach (Linedef l in linedefs)
                {
                    if (l.Front != null)
                    {
                        sides.Add(l.Front);
                    }
                    if (l.Back != null)
                    {
                        sides.Add(l.Back);
                    }
                }

                // Collect sidedefs from sectors
                foreach (Sector s in sectors)
                {
                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        sides.Add(sd);
                        if (sd.Other != null)
                        {
                            sides.Add(sd.Other);
                        }
                    }
                }

                // Create the form
                form = new DirectionalShadingForm(sectors, sides, null);
            }
            else if (currentmodename == "BaseVisualMode")
            {
                // Check selected geometry
                VisualMode             mode        = (VisualMode)General.Editing.Mode;
                List <VisualGeometry>  list        = mode.GetSelectedSurfaces();
                HashSet <VisualSector> selectedgeo = new HashSet <VisualSector>();
                List <Sector>          sectors     = new List <Sector>();
                HashSet <Sidedef>      sides       = new HashSet <Sidedef>();

                // Collect sectors and sides
                if (list.Count > 0)
                {
                    foreach (VisualGeometry vg in list)
                    {
                        switch (vg.GeometryType)
                        {
                        case VisualGeometryType.FLOOR:
                            selectedgeo.Add(vg.Sector);
                            sectors.Add(vg.Sector.Sector);
                            break;

                        case VisualGeometryType.WALL_UPPER:
                        case VisualGeometryType.WALL_MIDDLE:
                        case VisualGeometryType.WALL_LOWER:
                            sides.Add(vg.Sidedef);
                            selectedgeo.Add(mode.GetVisualSector(vg.Sidedef.Sector));
                            break;
                        }
                    }
                }

                // Add sides from selected sectors
                foreach (Sector s in sectors)
                {
                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        sides.Add(sd);
                        if (sd.Other != null)
                        {
                            sides.Add(sd.Other);
                        }
                    }
                }

                // Create the form?
                if (sectors.Count > 0 || sides.Count > 0)
                {
                    form = new DirectionalShadingForm(sectors, sides, selectedgeo);
                }
                else
                {
                    General.Interface.DisplayStatus(StatusType.Warning, "Select some floor or wall surfaces first!");
                    return;
                }
            }
            else             // Wrong mode
            {
                General.Interface.DisplayStatus(StatusType.Warning, "Switch to Sectors, Linedefs or Visual mode first!");
                return;
            }

            // Show the form
            form.ShowDialog(General.Interface);
        }
        public JitterSectorsForm(string editingModeName)
        {
            this.editingModeName = editingModeName;

            InitializeComponent();

            //get selection
            List <Vertex> verts   = new List <Vertex>();
            List <Sector> sectors = new List <Sector>();

            if (editingModeName == "BaseVisualMode")
            {
                VisualMode            vm             = (VisualMode)General.Editing.Mode;
                List <VisualGeometry> visualGeometry = vm.GetSelectedSurfaces();
                visualSectors = new List <VisualSector>();

                //get selected visual and regular sectors
                foreach (VisualGeometry vg in visualGeometry)
                {
                    if (vg.GeometryType != VisualGeometryType.CEILING && vg.GeometryType != VisualGeometryType.FLOOR)
                    {
                        continue;
                    }

                    if (vg.Sector != null && vg.Sector.Sector != null)
                    {
                        foreach (Sidedef sd in vg.Sector.Sector.Sidedefs)
                        {
                            if (!verts.Contains(sd.Line.Start))
                            {
                                verts.Add(sd.Line.Start);
                            }
                            if (!verts.Contains(sd.Line.End))
                            {
                                verts.Add(sd.Line.End);
                            }
                        }

                        sectors.Add(vg.Sector.Sector);
                        visualSectors.Add(vg.Sector);
                    }
                }

                //also get visual sectors around selected ones (because they also may be affected)
                List <Vertex> affectedVerts = new List <Vertex>();

                foreach (Sector s in sectors)
                {
                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        if (!affectedVerts.Contains(sd.Line.Start))
                        {
                            affectedVerts.Add(sd.Line.Start);
                        }
                        if (!affectedVerts.Contains(sd.Line.End))
                        {
                            affectedVerts.Add(sd.Line.End);
                        }
                    }
                }

                List <Sector> affectedSectors = new List <Sector>();
                foreach (Vertex v in affectedVerts)
                {
                    foreach (Linedef l in v.Linedefs)
                    {
                        if (l.Front != null && !sectors.Contains(l.Front.Sector) &&
                            !affectedSectors.Contains(l.Front.Sector) &&
                            vm.VisualSectorExists(l.Front.Sector))
                        {
                            visualSectors.Add(vm.GetVisualSector(l.Front.Sector));
                            affectedSectors.Add(l.Front.Sector);
                        }
                        if (l.Back != null && !sectors.Contains(l.Back.Sector) &&
                            !affectedSectors.Contains(l.Back.Sector) &&
                            vm.VisualSectorExists(l.Back.Sector))
                        {
                            visualSectors.Add(vm.GetVisualSector(l.Back.Sector));
                            affectedSectors.Add(l.Back.Sector);
                        }
                    }
                }

                visualVerts = new List <VisualVertexPair>();
                foreach (Vertex vert in affectedVerts)
                {
                    if (vm.VisualVertices.ContainsKey(vert))
                    {
                        visualVerts.Add(vm.VisualVertices[vert]);
                    }
                }
            }
            else if (editingModeName == "SectorsMode")
            {
                ICollection <Sector> list = General.Map.Map.GetSelectedSectors(true);

                foreach (Sector s in list)
                {
                    foreach (Sidedef sd in s.Sidedefs)
                    {
                        if (!verts.Contains(sd.Line.Start))
                        {
                            verts.Add(sd.Line.Start);
                        }
                        if (!verts.Contains(sd.Line.End))
                        {
                            verts.Add(sd.Line.End);
                        }
                    }
                    sectors.Add(s);
                }
            }

            if (verts.Count == 0 || sectors.Count == 0)
            {
                General.Interface.DisplayStatus(StatusType.Warning, "Unable to get sectors from selection!");
                return;
            }

            //create undo
            General.Map.UndoRedo.ClearAllRedos();
            General.Map.UndoRedo.CreateUndo("Randomize " + sectors.Count + (sectors.Count > 1 ? " sectors" : " sector"));

            //update window header
            this.Text = "Randomize " + sectors.Count + (sectors.Count > 1 ? " sectors" : " sector");

            //store intial properties
//process verts...
            Dictionary <Vertex, TranslationOffsetVertexData> data = new Dictionary <Vertex, TranslationOffsetVertexData>();

            foreach (Vertex v in verts)
            {
                TranslationOffsetVertexData vd = new TranslationOffsetVertexData();
                vd.Vertex          = v;
                vd.InitialPosition = v.Position;
                data.Add(v, vd);
            }

            foreach (Vertex v in verts)
            {
                if (v.Linedefs == null)
                {
                    continue;
                }

                //get nearest linedef
                Linedef closestLine = null;
                double  distance    = double.MaxValue;

                // Go for all linedefs in selection
                foreach (Linedef l in General.Map.Map.Linedefs)
                {
                    if (v.Linedefs.Contains(l))
                    {
                        continue;
                    }

                    // Calculate distance and check if closer than previous find
                    double d = l.SafeDistanceToSq(v.Position, true);
                    if (d < distance)
                    {
                        // This one is closer
                        closestLine = l;
                        distance    = d;
                    }
                }

                if (closestLine == null)
                {
                    continue;
                }

                double closestLineDistance = Vector2D.Distance(v.Position, closestLine.NearestOnLine(v.Position));

                //check SafeDistance of closest line
                if (data.ContainsKey(closestLine.Start) &&
                    data[closestLine.Start].SafeDistance > closestLineDistance)
                {
                    TranslationOffsetVertexData vd = data[closestLine.Start];
                    vd.SafeDistance         = (int)Math.Floor(closestLineDistance);
                    data[closestLine.Start] = vd;
                }
                if (data.ContainsKey(closestLine.End) &&
                    data[closestLine.End].SafeDistance > closestLineDistance)
                {
                    TranslationOffsetVertexData vd = data[closestLine.End];
                    vd.SafeDistance       = (int)Math.Floor(closestLineDistance);
                    data[closestLine.End] = vd;
                }

                //save SafeDistance
                int dist = (int)Math.Floor(closestLineDistance);
                if (data[v].SafeDistance == 0 || data[v].SafeDistance > dist)
                {
                    TranslationOffsetVertexData vd = data[v];
                    vd.SafeDistance = dist;
                    data[v]         = vd;
                }
            }

            //store properties
            vertexData = new TranslationOffsetVertexData[data.Values.Count];
            data.Values.CopyTo(vertexData, 0);

            for (int i = 0; i < data.Count; i++)
            {
                if (vertexData[i].SafeDistance > 0)
                {
                    vertexData[i].SafeDistance /= 2;
                }
                if (MaxSafeDistance < vertexData[i].SafeDistance)
                {
                    MaxSafeDistance = vertexData[i].SafeDistance;
                }
            }

//process sectors and linedes
            sectorData  = new List <SectorData>();
            sidedefData = new List <SidedefData>();

            foreach (Sector s in sectors)
            {
                SectorData sd = new SectorData();

                sd.Sector = s;
                sd.InitialCeilingHeight = s.CeilHeight;
                sd.InitialFloorHeight   = s.FloorHeight;
                sd.Triangular           = General.Map.UDMF && s.Sidedefs.Count == 3;
                if (sd.Triangular)
                {
                    Vertex[] sectorverts = GetSectorVerts(s);
                    sd.Verts = new HeightOffsetVertexData[sectorverts.Length];
                    for (int i = 0; i < sectorverts.Length; i++)
                    {
                        HeightOffsetVertexData vd = new HeightOffsetVertexData();
                        vd.Vertex               = sectorverts[i];
                        vd.ZFloor               = sectorverts[i].ZFloor;
                        vd.ZCeiling             = sectorverts[i].ZCeiling;
                        vd.InitialFloorHeight   = double.IsNaN(vd.ZFloor) ? GetHighestFloor(sectorverts[i]) : sectorverts[i].ZFloor;
                        vd.InitialCeilingHeight = double.IsNaN(vd.ZCeiling) ? GetLowestCeiling(sectorverts[i]) : sectorverts[i].ZCeiling;

                        sd.Verts[i] = vd;
                    }
                }
                sd.SafeDistance = (s.CeilHeight - s.FloorHeight) / 2;
                if (sd.SafeDistance > MaxSafeHeightDistance)
                {
                    MaxSafeHeightDistance = sd.SafeDistance;
                }
                sectorData.Add(sd);

                foreach (Sidedef side in s.Sidedefs)
                {
                    //store initial sidedef properties
                    SidedefData sdd = new SidedefData();

                    sdd.Side        = side;
                    sdd.LowTexture  = side.LowTexture;
                    sdd.HighTexture = side.HighTexture;
                    sdd.PegBottom   = side.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag);
                    sdd.PegTop      = side.Line.IsFlagSet(General.Map.Config.UpperUnpeggedFlag);

                    if (side.Other != null && !sectors.Contains(side.Other.Sector))
                    {
                        sdd.UpdateTextureOnOtherSide = true;
                        sdd.OtherHighTexture         = side.Other.HighTexture;
                        sdd.OtherLowTexture          = side.Other.LowTexture;
                    }

                    sidedefData.Add(sdd);
                }
            }

            positionJitterAmmount.Maximum = MaxSafeDistance;
            floorHeightAmmount.Maximum    = MaxSafeHeightDistance;
            ceilingHeightAmmount.Maximum  = MaxSafeHeightDistance;

            //set editing settings
            cbKeepExistingTextures.Checked = keepExistingSideTextures;
            ceiloffsetmode.SelectedIndex   = storedceiloffsetmode;
            flooroffsetmode.SelectedIndex  = storedflooroffsetmode;

            //vertex heights can not be set in non-UDMF maps
            if (General.Map.UDMF)
            {
                cbUseFloorVertexHeights.Checked   = useFloorVertexHeights;
                cbUseCeilingVertexHeights.Checked = useCeilingVertexHeights;
            }
            else
            {
                useFloorVertexHeights           = false;
                cbUseFloorVertexHeights.Checked = false;
                cbUseFloorVertexHeights.Enabled = false;

                useCeilingVertexHeights           = false;
                cbUseCeilingVertexHeights.Checked = false;
                cbUseCeilingVertexHeights.Enabled = false;
            }

            //texture pickers
            textureLower.Initialize();
            textureUpper.Initialize();

            //We can't use floor/ceiling textures when MixTexturesFlats is disabled
            if (General.Map.Config.MixTexturesFlats)
            {
                textureLower.TextureName = General.Settings.DefaultFloorTexture;
                textureUpper.TextureName = General.Settings.DefaultCeilingTexture;
            }
            else
            {
                textureLower.TextureName = General.Settings.DefaultTexture;
                textureUpper.TextureName = General.Settings.DefaultTexture;
                cbUpperTexStyle.Items[1] = "Use default texture";
                cbLowerTexStyle.Items[1] = "Use default texture";
            }

            cbUpperTexStyle.SelectedIndex = 0;
            cbLowerTexStyle.SelectedIndex = 0;
            UpdateTextureSelectors();             //update interface

            //create random values
            UpdateAngles();
            UpdateFloorHeights();
            UpdateCeilingHeights();
        }
Example #29
0
 public Render(string filename, int skinNumber, VisualMode mode = VisualMode.DARK_ROOM)
 {
     DxInitDevice();
     DxInitStuff();
     LoadScene(filename, skinNumber, mode);
 }