public Sprite TileSprite(TileReference<ushort, byte> r) { Sprite[] template; if (!templates.TryGetValue(r.Type, out template)) return missingTile; if (r.Index >= template.Length) return missingTile; return template[r.Index]; }
public BaseObject Create() { TileReference emptyInstance = new TileReference(CreatedWhenConstruct.CWC_NotToCreate); return(emptyInstance); }
void Start() { tr = GetComponent <TileReference>(); map = new int[width, height]; }
public static string FileName(this TileReference reference) { var fileName = $@"{reference.TileConfig.Naam}_{reference.Rij}_{reference.Kolom}"; return(ValidateFileNameRegEx.Replace(fileName, "_") + reference.TileConfig.Extensie); }
public TileReference<ushort, byte>[,] LoadMapTiles() { var tiles = new TileReference<ushort, byte>[MapSize.X, MapSize.Y]; using (var dataStream = Container.GetContent("map.bin")) { if (dataStream.ReadUInt8() != 1) throw new InvalidDataException("Unknown binary map format"); // Load header info var width = dataStream.ReadUInt16(); var height = dataStream.ReadUInt16(); if (width != MapSize.X || height != MapSize.Y) throw new InvalidDataException("Invalid tile data"); // Load tile data for (int i = 0; i < MapSize.X; i++) for (int j = 0; j < MapSize.Y; j++) { var tile = dataStream.ReadUInt16(); var index = dataStream.ReadUInt8(); if (index == byte.MaxValue) index = (byte)(i % 4 + (j % 4) * 4); tiles[i, j] = new TileReference<ushort, byte>(tile, index); } } return tiles; }
public TileReference<byte, byte>[,] LoadResourceTiles() { var resources = new TileReference<byte, byte>[MapSize.X, MapSize.Y]; using (var dataStream = Container.GetContent("map.bin")) { if (dataStream.ReadUInt8() != 1) throw new InvalidDataException("Unknown binary map format"); // Load header info var width = dataStream.ReadUInt16(); var height = dataStream.ReadUInt16(); if (width != MapSize.X || height != MapSize.Y) throw new InvalidDataException("Invalid tile data"); // Skip past tile data dataStream.Seek(3 * MapSize.X * MapSize.Y, SeekOrigin.Current); // Load resource data for (var i = 0; i < MapSize.X; i++) for (var j = 0; j < MapSize.Y; j++) { var type = dataStream.ReadUInt8(); var index = dataStream.ReadUInt8(); resources[i, j] = new TileReference<byte, byte>(type, index); } } return resources; }
public override void Construct() { AutoLayout = AutoLayout.DockFill; Background = new TileReference("basic", 1); BackgroundColor = new Vector4(1, 1, 1, 1); var imageSize = new Point(Root.RenderData.Texture.Width, Root.RenderData.Texture.Height); var availableArea = new Point(Root.RenderData.VirtualScreen.Width, Root.RenderData.VirtualScreen.Height - 32); if (imageSize.X > availableArea.X) { var ratio = (float)availableArea.X / (float)imageSize.X; imageSize.X = availableArea.X; imageSize.Y = (int)(imageSize.Y * ratio); } if (imageSize.Y > availableArea.Y) { var ratio = (float)availableArea.Y / (float)imageSize.Y; imageSize.Y = availableArea.Y; imageSize.X = (int)(imageSize.X * ratio); } ImagePosition = new Rectangle((Root.RenderData.VirtualScreen.Width / 2) - (imageSize.X / 2), ((Root.RenderData.VirtualScreen.Height - 32) / 2) - (imageSize.Y / 2), imageSize.X, imageSize.Y); var bottomBar = AddChild(new Widget { MinimumSize = new Point(0, 32), AutoLayout = Gui.AutoLayout.DockBottom, Padding = new Margin(2, 2, 2, 2) }); bottomBar.AddChild(new Widget { Text = "CLOSE", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, Border = "border-thin", Font = "font18-outline", OnClick = (sender, args) => this.Close(), AutoLayout = AutoLayout.DockRight }); bottomBar.AddChild(new Widget { Border = "border-thin", Font = "font18-outline", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, TextColor = new Vector4(1, 1, 1, 1), Text = "WHITE", AutoLayout = Gui.AutoLayout.DockLeft, OnClick = (sender, args) => { this.BackgroundColor = new Vector4(1, 1, 1, 1); this.Invalidate(); } }); bottomBar.AddChild(new Widget { Border = "border-thin", Font = "font18-outline", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, TextColor = new Vector4(0, 0, 0, 1), Text = "BLACK", AutoLayout = Gui.AutoLayout.DockLeft, OnClick = (sender, args) => { this.BackgroundColor = new Vector4(0, 0, 0, 1); this.Invalidate(); } }); bottomBar.AddChild(new Widget { Font = "font18-outline", TextHorizontalAlign = HorizontalAlign.Center, TextVerticalAlign = VerticalAlign.Center, TextColor = new Vector4(1, 1, 1, 1), Text = String.Format("{0} x {1}", Root.RenderData.Texture.Width, Root.RenderData.Texture.Height), AutoLayout = Gui.AutoLayout.DockLeft, }); }
public static Map FromTileset(TileSet tileset) { var tile = tileset.Templates.First(); var tileRef = new TileReference<ushort, byte> { Type = tile.Key, Index = (byte)0 }; Map map = new Map() { Title = "Name your map here", Description = "Describe your map here", Author = "Your name here", MapSize = new int2(1, 1), Tileset = tileset.Id, Options = new MapOptions(), MapResources = Exts.Lazy(() => new TileReference<byte, byte>[1, 1]), MapTiles = Exts.Lazy(() => new TileReference<ushort, byte>[1, 1] { { tileRef } }), Actors = Exts.Lazy(() => new Dictionary<string, ActorReference>()), Smudges = Exts.Lazy(() => new List<SmudgeReference>()) }; map.PostInit(); return map; }
public override void Construct() { ItemSize = new Point(32, 64); Root.RegisterForUpdate(this); Background = new TileReference("basic", 0); BackgroundColor = new Vector4(0, 0, 0, 0.5f); OnUpdate = (sender, time) => { var existingResourceEntries = new List <Widget>(Children); Children.Clear(); var aggregated = AggregateResources( Master.Faction.ListResourcesInStockpilesPlusMinions().Where(p => p.Value.First.NumResources > 0 || p.Value.Second.NumResources > 0)); foreach (var resource in aggregated) { var resourceTemplate = ResourceLibrary.GetResourceByName(resource.Amount.First.ResourceType); // Don't display resources with no value (a hack, yes!). This is to prevent "special" resources from getting traded. if (resourceTemplate.MoneyValue == 0.0m) { continue; } var icon = existingResourceEntries.FirstOrDefault(w => w is ResourceIcon && (w as ResourceIcon).EqualsLayers(resourceTemplate.GuiLayers)); StringBuilder label = new StringBuilder(); foreach (var aggregates in resource.Members) { label.Append(aggregates); label.Append("\n"); } label.Append(resourceTemplate.Description); if (icon == null) { icon = AddChild(new ResourceIcon() { Layers = resourceTemplate.GuiLayers, Tooltip = label.ToString(), }); } else { icon.Tooltip = label.ToString(); if (!Children.Contains(icon)) { AddChild(icon); } } string text = "S" + resource.Amount.First.NumResources.ToString(); text += "\n"; if (resource.Amount.Second.NumResources > 0) { text += "I" + resource.Amount.Second.NumResources.ToString(); } icon.Text = text; icon.Invalidate(); } var width = Root.RenderData.VirtualScreen.Width - ItemSpacing.X; var itemsThatFit = width / (ItemSize.X + ItemSpacing.X); var sensibleWidth = (Math.Min(Children.Count, itemsThatFit) * (ItemSize.X + ItemSpacing.X)) + ItemSpacing.X; Rect = new Rectangle((Root.RenderData.VirtualScreen.Width - sensibleWidth) / 2, 0, sensibleWidth, 0); Layout(); }; }
public override void Construct() { EnableScrolling = false; OverflowBottom = true; Transparent = true; base.Construct(); ItemSize = new Point(32, 64); Root.RegisterForUpdate(this); Background = new TileReference("basic", 0); BackgroundColor = new Vector4(0, 0, 0, 0.5f); OnUpdate = (sender, time) => { var existingResourceEntries = new List <Widget>(Children); Children.Clear(); var aggregated = AggregateResources(); foreach (var resource in aggregated) { var label = String.Join("\n", resource.StockpileMembers.Select(r => MakeDescriptionString(r))); var icon = existingResourceEntries.FirstOrDefault(w => w is Play.ResourceIcon && w.Tag.ToString() == resource.Category); if (icon == null) { icon = AddChild(new Play.ResourceIcon() { Resource = resource.Sample.Sample, Tooltip = label, Tag = resource.Category, OverrideTooltip = false }); } else { icon.Tooltip = label; if (!Children.Contains(icon)) { AddChild(icon); } existingResourceEntries.Remove(icon); } var text = "S" + resource.InStockpile + "\n"; if (resource.InBackpacks > 0) { text += "I" + resource.InBackpacks; } icon.Text = text; icon.Invalidate(); } var width = Root.RenderData.VirtualScreen.Width - ItemSpacing.X; var itemsThatFit = width / (ItemSize.X + ItemSpacing.X); var sensibleWidth = (Math.Min(Children.Count, itemsThatFit) * (ItemSize.X + ItemSpacing.X)) + ItemSpacing.X; Rect = new Rectangle((Root.RenderData.VirtualScreen.Width / 2 - sensibleWidth / 2), 0, sensibleWidth, 0); Layout(); }; }
public string GetTerrainType(TileReference<ushort, byte> r) { var tt = Templates[r.Type].Tiles; string ret; if (!tt.TryGetValue(r.Index, out ret)) return "Clear"; // Default walkable return ret; }
void ClearSelection() { SelectionStart = CPos.Zero; SelectionEnd = CPos.Zero; TileSelection = null; ResourceSelection = null; }
public void CopySelection() { // Grab tiles and resources within selection (doesn't do actors) var start = SelectionStart; var end = SelectionEnd; if (start == end) return; int width = Math.Abs((start - end).X); int height = Math.Abs((start - end).Y); TileSelection = new TileReference<ushort, byte>[width, height]; ResourceSelection = new TileReference<byte, byte>[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // TODO: crash prevention TileSelection[x, y] = Map.MapTiles.Value[start.X + x, start.Y + y]; ResourceSelection[x, y] = Map.MapResources.Value[start.X + x, start.Y + y]; } } }