private void load(JsonStore jsonStore, TileStore textureStore)
        {
            TileAtlas tileAtlas = new TileAtlas(textureStore, jsonStore, "Json/tiles.json");

            Add(new TileAtlasWindow
            {
                State     = Visibility.Visible,
                TileAtlas = tileAtlas,
            });
        }
Example #2
0
 // draws the hexgrid over the board
 private void DrawHexGrid(SpriteBatch sb)
 {
     for (int y = 0; y < client.Board.Tiles.Length; y++)
     {
         for (int x = 0; x < client.Board.Tiles[y].Length; x++)
         {
             Color     color = Color.White;
             Rectangle rect  = GetTileRenderRect(x, y);
             TileAtlas.Draw(sb, "TILEUTIL_OUTLINE", rect, null, color);
         }
     }
 }
Example #3
0
 // draws an outline around the hex currently under the mouse cursor
 private void DrawHexUnderMouse(SpriteBatch sb)
 {
     for (int y = 0; y < client.Board.Tiles.Length; y++)
     {
         for (int x = 0; x < client.Board.Tiles[y].Length; x++)
         {
             // check if the mouse is inside the tile
             if (GraphicsHelper.InsidePolygon(GetTileCorners(x, y), InputManager.Instance.MouseWorldPos(camera)))
             {
                 // the the tile border
                 Rectangle rect = GetTileRenderRect(x, y);
                 TileAtlas.Draw(sb, "TILEUTIL_OUTLINE", rect, null, Color.CornflowerBlue);
             }
         }
     }
 }
Example #4
0
        public void LoadMap(string mapName)
        {
            MapViewport mapObject = FindObjectOfType <MapViewport>();

            Debug.Log(campaignPath + mapName);
            JsonData loadedFile = JsonMapper.ToObject(File.ReadAllText(campaignPath + mapName + "/" + mapName + mapExtention));

            World.worldName = loadedFile["mapName"].ToString();
            Debug.Log(loadedFile["author"].ToString());
            World.width              = (int)loadedFile["mapWidth"];
            World.height             = (int)loadedFile["mapHeight"];
            mapObject.centerPosOnMap = new Vector2Int((int)loadedFile["playerStartPosX"], (int)loadedFile["playerStartPosY"]);
            List <string> chunkPaths = new List <string>();

            for (int i = 0; i < loadedFile["chnkPaths"].Count; i++)
            {
                chunkPaths.Add(loadedFile["chnkPaths"][i].ToString());
            }

            List <Chunk>   toLoad        = new List <Chunk>();
            List <int[, ]> loadedIntData = chnkExporter.LoadChunks(chunkPaths, mapName);
            int            x             = 0;
            int            y             = 0;

            foreach (var loadedData in loadedIntData)
            {
                toLoad.Add(new Chunk(loadedData, x * Chunk.chunkSize, y * Chunk.chunkSize));
                x++;
                if (x >= World.width)
                {
                    x = 0; y++;
                }
            }

            List <TileObject> importedTiles = new List <TileObject>();

            for (int i = 0; i < loadedFile["tilePalette"].Count; i++)
            {
                importedTiles.Add(new TileObject((int)loadedFile["tilePalette"][i]["sprId"], loadedFile["tilePalette"][i]["sprName"].ToString(),
                                                 (bool)loadedFile["tilePalette"][i]["collider"], (bool)loadedFile["tilePalette"][i]["transparent"], (bool)loadedFile["tilePalette"][i]["lightSrc"]));
            }
            TileAtlas.SetTileObjectArrayToAtlas(importedTiles.ToArray());

            mapObject.loadedWorld.CreateWorldWithExistingData(toLoad, loadedFile["mapName"].ToString(), (int)loadedFile["mapWidth"], (int)loadedFile["mapHeight"]);
        }
Example #5
0
        private void load(TileStore textures, JsonStore jsonStore)
        {
            TileAtlas atlas = new TileAtlas(textures, jsonStore, world);

            Add(new FillFlowContainer
            {
                AutoSizeAxes = Axes.Both,
                Children     = new[]
                {
                    new DrawableTile(atlas[0])
                    {
                        Size = new Vector2(Chunk.TILE_SIZE)
                    },
                    new DrawableTile(atlas[1])
                    {
                        Size = new Vector2(Chunk.TILE_SIZE)
                    }
                }
            });
        }
Example #6
0
        // draws every city that the client can see
        private void DrawCities(SpriteBatch sb)
        {
            foreach (City city in client.Cities.ToArray())
            {
                Tile tile = client.GetCachedTile(city.Location);
                if (tile == null)
                {
                    continue;
                }
                Rectangle cityDest = GetTileRenderRect(tile);
                TileAtlas.Draw(sb, "TILEIMPROVMENT_CITY", cityDest);

                if (client.SelectedCity != null && client.SelectedCity.InstanceID == city.InstanceID && city.PlayerID == client.Player.InstanceID)
                {
                    foreach (Point loc in city.CitizenLocations)
                    {
                        Rectangle dest = GetTileRenderRect(loc);
                        TileAtlas.Draw(sb, "TILEUTIL_HIGHLIGHT", dest);
                    }
                }
            }
        }
Example #7
0
        //Translate the intData to tiles.
        private TileObject[,] ConvertToTiles(int[,] mapData)
        {
            TileObject[,] toReturn = new TileObject[viewPortRadius, viewPortRadius];

            cachedTiles = new List <TileObject>();

            for (int y = 0; y < viewPortRadius; y++)
            {
                for (int x = 0; x < viewPortRadius; x++)
                {
                    int  intData      = mapData[x, y];
                    bool foundInCache = false;
                    foreach (var cachedTile in cachedTiles)
                    {
                        if (cachedTile.id == intData)
                        {
                            if (cachedTile.tile == null)
                            {
                                Debug.Log("null cachedTileObject at: " + cachedTile.id); cachedTiles.Remove(cachedTile); break;
                            }                                                                                                                                    //Broken tile, fetch a new one
                            toReturn[x, y] = cachedTile.Copy();
                            foundInCache   = true;
                            break;
                        }
                    }
                    if (foundInCache)
                    {
                        continue;
                    }


                    TileObject fetched = TileAtlas.FetchTileObjectByID(intData);
                    toReturn[x, y] = fetched.Copy();
                    cachedTiles.Add(fetched);
                }
            }
            return(toReturn);
        }
Example #8
0
        // draws every tile
        // tiles the client hasn't explored are covered by clouds
        // tiles the client has explored but cannot currently see are tinted gray
        private void DrawTiles(SpriteBatch sb)
        {
            // get the tile under the mouse
            Tile       tileUnderMouse = GetTileAtPoint(InputManager.Instance.MouseWorldPos(camera));
            List <int> myCityIDs      = client.GetMyCityIDs();

            for (int y = 0; y < client.Board.Tiles.Length; y++)
            {
                for (int x = 0; x < client.Board.Tiles[y].Length; x++)
                {
                    // get data
                    Tile      cachedTile   = client.GetCachedTile(x, y);
                    Tile      boardTile    = client.Board.GetTile(x, y);
                    Vector2[] localCorners = GetTileCorners(boardTile);

                    // check for cull
                    bool camContainsTile = false;
                    foreach (Vector2 corner in localCorners)
                    {
                        if (new Rectangle(0, 0, 1920, 1080).Contains(camera.ConvertWorldToScreen(corner)))
                        {
                            camContainsTile = true;
                            break;
                        }
                    }
                    if (!camContainsTile)
                    {
                        continue; // cull
                    }
                    // calc data
                    Rectangle rect = new Rectangle((int)localCorners[2].X, (int)localCorners[4].Y, TileWidth, TileHeight);

                    // check if explored
                    if (cachedTile == null)
                    {
                        TileAtlas.Draw(sb, "TILEUTIL_CLOUD", rect); // draw a cloud over the unexplored tile
                        continue;                                   // dont draw the underlying tile
                    }

                    // check if a unit or a city can see the tile
                    bool visible = false;
                    foreach (UnitInstance unit in client.GetMyUnits())
                    {
                        if (unit == null || unit.BaseUnit == null || cachedTile == null)
                        {
                            continue;
                        }
                        if (Board.HexDistance(unit.Location, cachedTile.Location) <= unit.BaseUnit.Sight)
                        {
                            visible = true;
                            break;
                        }
                    }
                    if (!visible)
                    {
                        foreach (Point nLoc in cachedTile.GetNeighbourTileLocations())
                        {
                            Tile n = client.GetCachedTile(nLoc);
                            if (n == null || n.CityID == -1)
                            {
                                continue;
                            }
                            if (myCityIDs.Contains(n.CityID))
                            {
                                visible = true;
                                break;
                            }
                        }
                    }

                    // visible tiles are white
                    Color color = Color.White;
                    if (!visible) // while explored but not currently visible tiles are gray
                    {
                        color = Color.Gray;
                    }

                    // draw the tile
                    TileAtlas.Draw(sb, $"TILEBASE_{cachedTile.TerrainBase}", rect, null, color);
                    if (cachedTile.TerrainFeature != TileTerrainFeature.OPEN)
                    {
                        TileAtlas.Draw(sb, $"TILEFEATURE_{cachedTile.TerrainFeature}", rect, null, color);
                    }
                    // draw the improvment if the tile has one
                    if (cachedTile.Improvement != TileImprovment.Null)
                    {
                        TileAtlas.Draw(sb, $"TILEIMPROVMENT_{cachedTile.Improvement}", rect, null, color);
                    }
                    // draw a resource icon if the tile has a resource
                    //if (cachedTile.Resource != TileResource.Null)
                    //{
                    //    tileAtlas.Draw(sb, $"TILERESOURCE_{cachedTile.Resource}", rect, null, color);
                    //}
                    // draw the city border is the tile belongs to a city
                    if (cachedTile.CityID != -1)
                    {
                        City city = client.Cities.Find(c => c.InstanceID == cachedTile.CityID);
                        if (city != null)
                        {
                            Color empColorPri = client.DataManager.Empire.GetEmpire(city.EmpireID).PrimaryColor;
                            Color empColorSec = client.DataManager.Empire.GetEmpire(city.EmpireID).SecondaryColor;
                            if (city.PlayerID == client.Player.InstanceID && tileUnderMouse != null && tileUnderMouse.Location == city.Location)
                            {
                                empColorPri = Color.Lerp(empColorPri, Color.White, 0.1f);
                            }
                            empColorPri.A = 255;
                            TileAtlas.Draw(sb, $"TILEUTIL_HIGHLIGHT", rect, null, empColorPri);
                            TileAtlas.Draw(sb, $"TILEUTIL_OUTLINE", rect, null, empColorSec);
                        }
                    }
                    // draw yield icons if enabled
                    if (DrawResourceIcons)
                    {
                        lock (_lock_tileIconUpdate)
                        {
                            tileIcons[y][x]?.Draw(sb);
                        }
                    }
                }
            }
        }
Example #9
0
 public void Dispose()
 {
     TileAtlas.Dispose();
 }
Example #10
0
 private void ReplaceTileOnChunk(Chunk chunkData, Vector2Int tilePos, Vector3Int viewPortPos, int idOfNewTile)
 {
     chunkData.mapData[tilePos.x, tilePos.y] = idOfNewTile; //Please work it's like 2am
     viewport.SetTile(viewPortPos, TileAtlas.FetchTileObjectByID(idOfNewTile).tile);
 }