/// <summary> /// Constructor. /// </summary> public ViewModel(Dispatcher uiDispatcher, string baseContentDir, Isometry iso) { // Reference to the UIDispatcher for thread-safe collection manipulation _uiDispatcher = uiDispatcher; Factions = new ObservableCollection<FactionList> { new FactionList("AI"), new FactionList("Player 1"), new FactionList("Player 2") }; // Map setup Map = new MapDefinition(new ZTile(baseContentDir + "tiles\\Generic Tiles\\Generic Floors\\DirtSand\\Waste_Floor_Gravel_SandDirtCentre_F_1_NE.til"), iso, baseContentDir); MapCanvas = new MapCanvas(Map, uiDispatcher, baseContentDir + "tiles\\", iso, Factions); _useAltEditLayer = false; // Create the available TileSets and collection views TileSets = new Dictionary<string, ObservableCollection<ZTile>>(); TileSetViews = new Dictionary<string, ListCollectionView>(); foreach (var di in new DirectoryInfo(baseContentDir + "tiles\\").GetDirectories()) { TileSets.Add(di.Name, new ObservableCollection<ZTile>()); TileSetViews.Add(di.Name, new ListCollectionView(TileSets[di.Name])); } // Start a new thread to load in the tile images ThreadPool.QueueUserWorkItem(GetWholeTileSet, baseContentDir + "tiles\\"); }
/// <summary> /// Constructor. /// </summary> /// <param name="unit"></param> /// <param name="direction"></param> /// <param name="linkedAnimProcess"></param> /// <param name="delay"></param> public MovementProcess(Unit unit, CompassDirection direction, AnimProcess linkedAnimProcess, Isometry iso, float delay = .015f) : base() { _unit = unit; _direction = direction; _linkedAnimProcess = linkedAnimProcess; _speed = delay; _iso = iso; }
// Remember to update Clone() before adding any more instance variables! /// <summary> /// Constructor. /// </summary> public MapDefinition(ZTile defaultFloorTile, Isometry iso, string baseContentDir) { _baseContentDir = baseContentDir; Iso = iso; DefaultFloorTile = defaultFloorTile; TileHeight = 37; TileWidth = 73; UndoInfo = new HashSet<Point>(); Cells = new MapCell[0, 0]; ClearAllCells(26, 45); }
/// <summary> /// Constructor. /// </summary> public MainWindow() { // Window initialisation SourceInitialized += (s, a) => WindowState = WindowState.Maximized; // Isometry helper _iso = new Isometry(IsometricStyle.Staggered, BaseContentDirectory + "tiles\\mousemap.png"); // Start the ViewModel ViewModel = new ViewModel(Dispatcher, BaseContentDirectory, _iso); // Text filter function for tile picker _filterFX = (p) => p.ToString().Contains(tileFilterTextBox.Text); InitializeComponent(); // Pass an ImageControl reference to the MapCanvas (violating MVVM) ViewModel.MapCanvas.ImageControl = mapCanvasImage; cellOverlayImage.IsHitTestVisible = false; // Tabs for each tileset foreach (var s in ViewModel.TileSets.Keys) { var tab = new TabItem {Header = s}; // Listview of filtered tiles in this tileset var lv = new ListView(); // Style & template from XAML tab.Style = (Style)FindResource("TilePickerTabItemStyle"); lv.Style = (Style)FindResource("TilePickerListViewStyle"); lv.ItemTemplate = (DataTemplate)FindResource("TilePickerListData"); // Use a WrapPanel for content lv.ItemsPanel = new ItemsPanelTemplate( new FrameworkElementFactory( typeof(WrapPanel))); // Set the ListView content & filter function lv.ItemsSource = ViewModel.TileSetViews[s]; ViewModel.TileSetViews[s].Filter = _filterFX; // Action lv.SelectionChanged += TilePickerSelectionChanged; tab.Content = lv; // Add the tab to the TabControl tilePickerTabControl.Items.Add(tab); } _random = new Random(); _characterEditor = new CharacterEditor(ViewModel, Dispatcher); _characterEditor.Show(); _characterEditor.Topmost = true; }
/// <summary> /// Reads a Module from the give stream. /// </summary> /// <param name="stream"></param> /// <param name="iso"></param> /// <returns></returns> public static Module ReadModule(TextReader stream, Isometry iso) { Module mod = new Module(); stream.ReadLine(); // <Module> mod.Map = MapDefinition.ReadMap(stream, iso); stream.ReadLine(); // <Roster> int numUnits = int.Parse(stream.ReadLine()); for (int i = 0; i < numUnits; i++) { mod.Roster.Add(Unit.ReadUnit(stream)); // Mark the corresponding map cell as occupied mod.Map.Cells[mod.Roster[mod.Roster.Count - 1].X, mod.Roster[mod.Roster.Count - 1].Y].IsOccupied = true; } stream.ReadLine(); // </Roster> stream.ReadLine(); // </Module> return mod; }
/// <summary> /// Opens and returns a Module from stream. /// </summary> /// <param name="filePath"></param> /// <param name="asString"> </param> /// <returns></returns> public static Module OpenModule(string filePath, Isometry iso, bool asString) { TextReader stream; if (asString) { using (stream = new StringReader(filePath)) { return ReadModule(stream, iso); } } else { using (stream = new StreamReader(filePath)) { return ReadModule(stream, iso); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="game"></param> public MapScroller(ClientGame game, GameState state) { RegisterListeners(); characterAvailable = true; _game = game; _module = state.Module; _iso = _module.Map.Iso; _state = state; _spriteBatch = game.SpriteBatch; _gameFont = game.Content.Load<SpriteFont>("Fonts//gameFont"); _circle = _game.Content.Load<Texture2D>("Textures//circle"); _screenSpace = new Rectangle(0, 0, _game.GraphicsDevice.PresentationParameters.BackBufferWidth, _game.GraphicsDevice.PresentationParameters.BackBufferHeight); // World space var max = _iso.TilePlotter(new Point(_module.Map.Width - 1, _module.Map.Height - 1)); _worldSpace = new Rectangle(0, 0, max.X + _module.Map.TileWidth, max.Y + _module.Map.TileHeight); // Anchor space _anchorSpace = _worldSpace; var horizontal = _screenSpace.Right - _screenSpace.Left; _anchorSpace.Width -= horizontal; if (_anchorSpace.Right < _anchorSpace.Left) _anchorSpace.Width = 0; var vertical = _screenSpace.Bottom - _screenSpace.Top; _anchorSpace.Height -= vertical; if (_anchorSpace.Bottom < _anchorSpace.Top) _anchorSpace.Height = 0; // Adjust for staggered maps to eliminate jaggies when scrolling to map edge if (_iso.Style == IsometricStyle.Staggered) { _anchorSpace.Y += _module.Map.TileHeight / 2; _anchorSpace.Height -= _module.Map.TileHeight / 2; _anchorSpace.X += _module.Map.TileWidth / 2; _anchorSpace.Width -= _module.Map.TileWidth / 2; _screenAnchor = new Point(_anchorSpace.Left, _anchorSpace.Top); } else { // Screen anchor _screenAnchor = new Point(0, 0); } }
/// <summary> /// Constructor. /// </summary> public GameState(string mouseMapPath) { Players = new List<PlayerState>(); iso = new Isometry(IsometricStyle.Staggered, mouseMapPath); }
/// <summary> /// Opens and returns a map from file. /// </summary> /// <param name="filePath"></param> /// <param name="Iso"> </param> /// <param name="asString"> </param> /// <returns></returns> public static MapDefinition OpenMap(string filePath, Isometry Iso, bool asString) { if (filePath == null) return new MapDefinition(null, Iso, _baseContentDir) ; TextReader file; if (asString) { using (file = new StringReader(filePath)) { return ReadMap(file, Iso); } } else { using (file = new StreamReader(filePath)) { return ReadMap(file, Iso); } } }
/// <summary> /// Reads a map from the given stream. /// </summary> /// <param name="stream"></param> /// <param name="iso"></param> /// <returns></returns> public static MapDefinition ReadMap(TextReader stream, Isometry iso) { var newMap = new MapDefinition(null, iso, _baseContentDir); if (stream == null) return newMap; stream.ReadLine(); // <Map> newMap.Iso.Style = (IsometricStyle)Enum.Parse(typeof(IsometricStyle), stream.ReadLine()); newMap.ClearAllCells(int.Parse(stream.ReadLine()), int.Parse(stream.ReadLine())); newMap.TileWidth = int.Parse(stream.ReadLine()); newMap.TileHeight = int.Parse(stream.ReadLine()); stream.ReadLine(); // </Map> stream.ReadLine(); // <TileDictionary> var requiredTiles = new List<ZTile>(); var line = stream.ReadLine(); while (!line.Equals("</TileDictionary>")) { requiredTiles.Add(new ZTile("D:\\workspace\\BaseGame\\" + line)); line = stream.ReadLine(); } Console.WriteLine(requiredTiles[0].Bitmaps.Count()); stream.ReadLine(); // <Cells> for (var x = 0; x < newMap.Cells.GetLength(0); x++) for (var y = 0; y < newMap.Cells.GetLength(1); y++) { newMap.Cells[x, y] = MapCell.FromStream(stream, requiredTiles, newMap, new Point(x,y)); } stream.ReadLine(); // </Cells> // Remake Parent links for (var x = 0; x < newMap.Cells.GetLength(0); x++) for (var y = 0; y < newMap.Cells.GetLength(1); y++) { if (newMap.Cells[x, y].TempPoint.X != -1) { newMap.Cells[x, y].ParentCell = newMap.Cells[newMap.Cells[x, y].TempPoint.X, newMap.Cells[x, y].TempPoint.Y]; } } return newMap; }
/// <summary> /// Constructor. /// </summary> /// <param name="unit"></param> /// <param name="iso"></param> /// <param name="path"></param> public AnimatedMoveProcess(Unit unit, Isometry iso, params CompassDirection[] path) { this.unit = unit; this.iso = iso; this.path = path; }
/// <summary> /// Opens module from file. /// </summary> /// <param name="fileName"></param> /// <param name="iso"></param> internal List<Unit> OpenModule(string fileName, Isometry iso) { _currentUndoNode = null; var tempMod = Module.OpenModule(fileName, iso, false); Map = tempMod.Map; MapCanvas.Map = tempMod.Map; foreach (FactionList fl in Factions) fl.Units.Clear(); foreach (Unit u in tempMod.Roster) { Factions[u.OwnerID].Units.Add(u); } ThreadPool.QueueUserWorkItem(MapCanvas.RenderMap, null); return tempMod.Roster; }