public override void Deserialize(BinaryReader reader) { Commands = new List <VMArchitectureCommand>(); int length = reader.ReadInt32(); for (int i = 0; i < length; i++) { var cmd = new VMArchitectureCommand(); cmd.Deserialize(reader); Commands.Add(cmd); } }
public override void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(new Vector2(MousePosition.X, MousePosition.Y)); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); if (Drawing) { var diff = cursor - StartPosition; DrawLength = (int)Math.Round(Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y)); DrawDir = (int)DirectionUtils.PosMod(Math.Round(Math.Atan2(diff.Y, diff.X) / (Math.PI / 4)), 8); if (Modifiers.HasFlag(UILotControlModifiers.SHIFT)) { EndPosition = cursor; int smallX = Math.Min(StartPosition.X, EndPosition.X); int smallY = Math.Min(StartPosition.Y, EndPosition.Y); int bigX = Math.Max(StartPosition.X, EndPosition.X); int bigY = Math.Max(StartPosition.Y, EndPosition.Y); cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.WALL_RECT, level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY }); } else { cursor = StartPosition + new Point(DirUnits[DrawDir].X * DrawLength, DirUnits[DrawDir].Y * DrawLength); cmds.Add(new VMArchitectureCommand { Type = (Modifiers.HasFlag(UILotControlModifiers.CTRL)) ? VMArchitectureCommandType.WALL_DELETE : VMArchitectureCommandType.WALL_LINE, level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir }); } } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.Budget; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed?Color.DarkRed:Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(MousePosition.X, MousePosition.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); if (Modifiers.HasFlag(UILotControlModifiers.SHIFT)) { SetCursorGraphic(3); } else if (Modifiers.HasFlag(UILotControlModifiers.CTRL)) { SetCursorGraphic(1); } else { SetCursorGraphic(0); } }
public void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); bool redraw = false; if (Drawing && cursor != LastPosition) { redraw = true; VMArchitectureCommand cmd; if (!Commands.TryGetValue(cursor, out cmd)) { cmd = new VMArchitectureCommand() { Type = VMArchitectureCommandType.GRASS_DOT, x = cursor.X - 1, y = cursor.Y - 1, pattern = 0 }; } var mod = (!state.ShiftDown) ? 128 : 32; if (!state.CtrlDown) { mod *= -1; } cmd.pattern = (ushort)(Math.Min(255, Math.Max(-255, ((short)cmd.pattern) + mod))); LastPosition = cursor; Commands[cursor] = cmd; } var cmds = vm.Context.Architecture.Commands; cmds.Clear(); cmds.AddRange(Commands.Values); if (cmds.Count > 0) { if (!WasDown) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } if (redraw) { vm.Context.Architecture.SignalRedraw(); } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.Commands.Clear(); vm.Context.Architecture.SignalTerrainRedraw(); vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); SetCursorGraphic(3); }
public void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); if (Drawing) { EndPosition = cursor; var smallX = Math.Min(StartPosition.X, cursor.X); var smallY = Math.Min(StartPosition.Y, cursor.Y); var bigX = Math.Max(StartPosition.X, cursor.X); var bigY = Math.Max(StartPosition.Y, cursor.Y); cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.TERRAIN_FLATTEN, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY, style = (ushort)StartTerrainHeight, pattern = (ushort)((state.CtrlDown) ? 1 : 0) }); WallCursor2.SetVisualPosition(new Vector3(StartPosition.X, StartPosition.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); } else { WallCursor2.SetVisualPosition(new Vector3(-2048, -2048, 0), Direction.NORTH, vm.Context); } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { var failed = vm.Context.Architecture.LastFailReason; if (failed > 0) { if (failed == 1) { ShowErrorAtMouse(state, VMPlacementError.CantPlaceOnSlope, state.MouseState.Position); } else if (failed == 2) { ShowErrorAtMouse(state, VMPlacementError.LocationOutOfBounds, state.MouseState.Position); } else { ShowErrorAtMouse(state, VMPlacementError.LocationOutOfBounds, state.MouseState.Position); } vm.Context.Architecture.SignalTerrainRedraw(); } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.Commands.Clear(); vm.Context.Architecture.SignalTerrainRedraw(); vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); SetCursorGraphic(3, WallCursor); SetCursorGraphic(3, WallCursor2); }
public void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2()); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); int mod = 0; if (Drawing) { cursor = StartPosition; var mpos = (int)(state.MouseState.Y - World.State.WorldSpace.GetScreenOffset().Y); mod = ((StartMousePosition - mpos) * 10) / (15 / (1 << (3 - (int)World.State.Zoom))); if (!state.ShiftDown) { mod = (int)Math.Round(mod / 10f) * 10; } var newHeight = StartTerrainHeight + mod; cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.TERRAIN_RAISE, x = StartPosition.X, y = StartPosition.Y, style = (ushort)newHeight, pattern = (ushort)((state.CtrlDown) ? 1 : 0) }); } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { var failed = vm.Context.Architecture.LastFailReason; if (failed > 0) { if (failed == 1) { ShowErrorAtMouse(state, VMPlacementError.CantPlaceOnSlope, state.MouseState.Position); } else if (failed == 2) { ShowErrorAtMouse(state, VMPlacementError.LocationOutOfBounds, state.MouseState.Position); } else { ShowErrorAtMouse(state, VMPlacementError.LocationOutOfBounds, state.MouseState.Position); } vm.Context.Architecture.SignalTerrainRedraw(); } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.Commands.Clear(); vm.Context.Architecture.SignalTerrainRedraw(); vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f + mod * vm.Context.Blueprint.TerrainFactor), Direction.NORTH, vm.Context); if (state.CtrlDown) { SetCursorGraphic(1); } else { SetCursorGraphic(0); } }
public void Update(UpdateState state, bool scrolled) { ushort pattern = (state.CtrlDown) ? (ushort)0 : Pattern; var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor); Point cursor = new Point((int)tilePos.X, (int)tilePos.Y); if (!Drawing && Commands.Count > 0) { vm.Context.Architecture.SignalRedraw(); Commands.Clear(); } if (state.ShiftDown) { if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.PATTERN_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); Commands.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.PATTERN_FILL, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y }); } } else { if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.PATTERN_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } int dir = 0; int altdir = 0; Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y); switch (World.State.CutRotation) { case WorldRotation.BottomRight: if (fract.X - fract.Y > 0) { dir = 2; altdir = 3; } else { dir = 3; altdir = 2; } break; case WorldRotation.TopRight: if (fract.X + fract.Y > 1) { dir = 3; altdir = 0; } else { dir = 0; altdir = 3; } break; case WorldRotation.TopLeft: //+x is right down. +y is left down if (fract.X - fract.Y > 0) { dir = 1; altdir = 0; } else { dir = 0; altdir = 1; } break; case WorldRotation.BottomLeft: if (fract.X + fract.Y > 1) { dir = 2; altdir = 1; } else { dir = 1; altdir = 2; } break; } var finalDir = VMArchitectureTools.GetPatternDirection(vm.Context.Architecture, cursor, pattern, dir, altdir, World.State.Level); if (finalDir != -1) { CursorDir = finalDir; var cmd = new VMArchitectureCommand { Type = VMArchitectureCommandType.PATTERN_DOT, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y, x2 = dir, y2 = altdir }; if (!Commands.Contains(cmd)) { vm.Context.Architecture.SignalRedraw(); Commands.Add(cmd); } } } var cmds = vm.Context.Architecture.Commands; cmds.Clear(); foreach (var cmd in Commands) { cmds.Add(cmd); } if (cmds.Count > 0) { var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } } WallCursor.SetVisualPosition(new Vector3(cursor.X + 0.5f, cursor.Y + 0.5f, (World.State.Level - 1) * 2.95f), (Direction)(1 << ((3 - CursorDir) * 2)), vm.Context); }
public override void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(new Vector2(MousePosition.X, MousePosition.Y)); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); if (Drawing) { EndPosition = cursor; var smallX = Math.Min(StartPosition.X, cursor.X); var smallY = Math.Min(StartPosition.Y, cursor.Y); var bigX = Math.Max(StartPosition.X, cursor.X); var bigY = Math.Max(StartPosition.Y, cursor.Y); cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.TERRAIN_FLATTEN, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY, style = (ushort)StartTerrainHeight, pattern = (ushort)((Modifiers.HasFlag(UILotControlModifiers.CTRL)) ? 1 : 0) }); WallCursor2.SetVisualPosition(new Vector3(StartPosition.X, StartPosition.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); } else { WallCursor2.SetVisualPosition(new Vector3(-2048, -2048, 0), Direction.NORTH, vm.Context); } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.Budget; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(MousePosition.X, MousePosition.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.Commands.Clear(); vm.Context.Architecture.SignalTerrainRedraw(); vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); SetCursorGraphic(3, WallCursor); SetCursorGraphic(3, WallCursor2); }
public void Update(UpdateState state, bool scrolled) { ushort pattern = (state.CtrlDown) ? (ushort)0 : Pattern; var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor); Point cursor = new Point((int)tilePos.X, (int)tilePos.Y); /*if (!Drawing && Commands.Count > 0) * { * vm.Context.Architecture.SignalRedraw(); * Commands.Clear(); * }*/ if (state.ShiftDown && pattern < 65534) { if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.FLOOR_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); Commands.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.FLOOR_FILL, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y, }); } } else { if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.FLOOR_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } if (!Drawing || Commands.Count == 0) { StartX = cursor.X; StartY = cursor.Y; } int dir = 0; Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y); if (fract.X - fract.Y > 0) { dir = (fract.X + fract.Y > 1) ? 2 : 1; } else { dir = (fract.X + fract.Y > 1) ? 3 : 0; } int smallX = Math.Min(StartX, cursor.X); int smallY = Math.Min(StartY, cursor.Y); int bigX = Math.Max(StartX, cursor.X); int bigY = Math.Max(StartY, cursor.Y); var cmd = new VMArchitectureCommand { Type = VMArchitectureCommandType.FLOOR_RECT, level = World.State.Level, pattern = pattern, style = (ushort)dir, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY }; if (!Commands.Contains(cmd)) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); Commands.Add(cmd); } } var cmds = vm.Context.Architecture.Commands; cmds.Clear(); foreach (var cmd in Commands) { cmds.Add(cmd); } if (cmds.Count > 0) { var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } } }
public override void Update(UpdateState state, bool scrolled) { var tilePos = World.EstTileAtPosWithScroll(new Vector2(MousePosition.X, MousePosition.Y) / FSOEnvironment.DPIScaleFactor); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); int mod = 0; if (Drawing) { cursor = StartPosition; var mpos = (int)(MousePosition.Y - World.State.WorldSpace.GetScreenOffset().Y); mod = ((StartMousePosition - mpos) * 10) / (15 / (1 << (3 - (int)World.State.Zoom))); if (!Modifiers.HasFlag(UILotControlModifiers.SHIFT)) { mod = (int)Math.Round(mod / 10f) * 10; } var newHeight = StartTerrainHeight + mod; cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.TERRAIN_RAISE, x = StartPosition.X, y = StartPosition.Y, style = (ushort)newHeight, pattern = (ushort)((Modifiers.HasFlag(UILotControlModifiers.CTRL)) ? 1 : 0) }); } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); WasDown = true; } var cost = vm.Context.Architecture.LastTestCost; if (cost != 0) { var disallowed = Parent.ActiveEntity != null && cost > Parent.Budget; state.UIState.TooltipProperties.Show = true; state.UIState.TooltipProperties.Color = disallowed ? Color.DarkRed : Color.Black; state.UIState.TooltipProperties.Opacity = 1; state.UIState.TooltipProperties.Position = new Vector2(MousePosition.X, MousePosition.Y); state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost); state.UIState.TooltipProperties.UpdateDead = false; if (!cmds[0].Equals(LastCmd) && disallowed) { HITVM.Get().PlaySoundEvent(UISounds.Error); } } else { state.UIState.TooltipProperties.Show = false; state.UIState.TooltipProperties.Opacity = 0; } LastCmd = cmds[0]; } else { if (WasDown) { vm.Context.Architecture.Commands.Clear(); vm.Context.Architecture.SignalTerrainRedraw(); vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f + mod * vm.Context.Blueprint.TerrainFactor), Direction.NORTH, vm.Context); if (Modifiers.HasFlag(UILotControlModifiers.CTRL)) { SetCursorGraphic(1); } else { SetCursorGraphic(0); } }
public void Update(UpdateState state, bool scrolled) { ushort pattern = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? (ushort)0 : Pattern; var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y)); Point cursor = new Point((int)tilePos.X, (int)tilePos.Y); if (!Drawing && Commands.Count > 0) { vm.Context.Architecture.SignalRedraw(); Commands.Clear(); } if (state.KeyboardState.IsKeyDown(Keys.LeftShift) && pattern < 65534) { if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.FLOOR_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } Commands.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.FLOOR_FILL, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y, }); } else { if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.FLOOR_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } if (!Drawing || Commands.Count == 0) { StartX = cursor.X; StartY = cursor.Y; } int dir = 0; Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y); if (fract.X - fract.Y > 0) { dir = (fract.X + fract.Y > 1) ? 2 : 1; } else { dir = (fract.X + fract.Y > 1) ? 3 : 0; } int smallX = Math.Min(StartX, cursor.X); int smallY = Math.Min(StartY, cursor.Y); int bigX = Math.Max(StartX, cursor.X); int bigY = Math.Max(StartY, cursor.Y); var cmd = new VMArchitectureCommand { Type = VMArchitectureCommandType.FLOOR_RECT, level = World.State.Level, pattern = pattern, style = (ushort)dir, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY }; if (!Commands.Contains(cmd)) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); Commands.Add(cmd); } } var cmds = vm.Context.Architecture.Commands; cmds.Clear(); foreach (var cmd in Commands) { cmds.Add(cmd); } }
public void Update(UpdateState state, bool scrolled) { var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y)); Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y)); var cmds = vm.Context.Architecture.Commands; cmds.Clear(); if (Drawing) { var diff = cursor - StartPosition; DrawLength = (int)Math.Round(Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y)); DrawDir = (int)DirectionUtils.PosMod(Math.Round(Math.Atan2(diff.Y, diff.X) / (Math.PI / 4)), 8); if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) { EndPosition = cursor; int smallX = Math.Min(StartPosition.X, EndPosition.X); int smallY = Math.Min(StartPosition.Y, EndPosition.Y); int bigX = Math.Max(StartPosition.X, EndPosition.X); int bigY = Math.Max(StartPosition.Y, EndPosition.Y); cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.WALL_RECT, level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = smallX, y = smallY, x2 = bigX - smallX, y2 = bigY - smallY }); } else { cursor = StartPosition + new Point(DirUnits[DrawDir].X * DrawLength, DirUnits[DrawDir].Y * DrawLength); cmds.Add(new VMArchitectureCommand { Type = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? VMArchitectureCommandType.WALL_DELETE : VMArchitectureCommandType.WALL_LINE, level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir }); } } if (cmds.Count > 0) { if (!WasDown || !cmds[0].Equals(LastCmd)) { vm.Context.Architecture.SignalRedraw(); LastCmd = cmds[0]; WasDown = true; } } else { if (WasDown) { vm.Context.Architecture.SignalRedraw(); WasDown = false; } } WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level - 1) * 2.95f), Direction.NORTH, vm.Context); if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) { SetCursorGraphic(3); } else if (state.KeyboardState.IsKeyDown(Keys.LeftControl)) { SetCursorGraphic(1); } else { SetCursorGraphic(0); } }
public void Update(UpdateState state, bool scrolled) { ushort pattern = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? (ushort)0 : Pattern; var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y)); Point cursor = new Point((int)tilePos.X, (int)tilePos.Y); if (!Drawing && Commands.Count > 0) { vm.Context.Architecture.SignalRedraw(); Commands.Clear(); } if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) { if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.PATTERN_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } Commands.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.PATTERN_FILL, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y }); } else { if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.PATTERN_FILL) { Commands.Clear(); vm.Context.Architecture.SignalRedraw(); } int dir = 0; int altdir = 0; Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y); switch (World.State.Rotation) { case WorldRotation.BottomRight: if (fract.X - fract.Y > 0) { dir = 2; altdir = 3; } else { dir = 3; altdir = 2; } break; case WorldRotation.TopRight: if (fract.X + fract.Y > 1) { dir = 3; altdir = 0; } else { dir = 0; altdir = 3; } break; case WorldRotation.TopLeft: //+x is right down. +y is left down if (fract.X - fract.Y > 0) { dir = 1; altdir = 0; } else { dir = 0; altdir = 1; } break; case WorldRotation.BottomLeft: if (fract.X + fract.Y > 1) { dir = 2; altdir = 1; } else { dir = 1; altdir = 2; } break; } var finalDir = VMArchitectureTools.GetPatternDirection(vm.Context.Architecture, cursor, pattern, dir, altdir, World.State.Level); if (finalDir != -1) { CursorDir = finalDir; var cmd = new VMArchitectureCommand { Type = VMArchitectureCommandType.PATTERN_DOT, level = World.State.Level, pattern = pattern, style = 0, x = cursor.X, y = cursor.Y, x2 = dir, y2 = altdir }; if (!Commands.Contains(cmd)) { vm.Context.Architecture.SignalRedraw(); Commands.Add(cmd); } } } var cmds = vm.Context.Architecture.Commands; cmds.Clear(); foreach (var cmd in Commands) { cmds.Add(cmd); } WallCursor.SetVisualPosition(new Vector3(cursor.X + 0.5f, cursor.Y + 0.5f, (World.State.Level - 1) * 2.95f), (Direction)(1 << ((3 - CursorDir) * 2)), vm.Context); }