Пример #1
0
    public List <GameObject> HandleDragVisual(MouseController.DragParameters parameters, Transform parent)
    {
        List <GameObject> objects = new List <GameObject>();

        if (parameters.EndX != parameters.StartX)
        {
            // We should NEVER reach here, the disable dragging means that this should NEVER be true
            throw new ArgumentException("Parameters Start X/Y values should Equal End X/Y values, this is taken care by the DisableDragging = true property.");
        }

        Tile t = WorldController.Instance.World.GetTileAt(parameters.StartX, parameters.StartY, WorldController.Instance.CameraController.CurrentLayer);

        if (t != null)
        {
            // Show generic visuals
            GameObject go = new GameObject();
            go.transform.SetParent(parent);
            go.transform.position = new Vector3(parameters.StartX, parameters.StartY);

            if (t.Furniture == null && (t.Inventory == null || t.Inventory.Type == InventoryToBuild) && t.Type != TileType.Empty)
            {
                InventorySpriteController.SetSprite(go, CurrentInventory).color = Color.green; // = new Color(0.5f, 1f, 0.5f, 0.25f);
            }
            else
            {
                InventorySpriteController.SetSprite(go, CurrentInventory).color = Color.red; // new Color(1f, 0.5f, 0.5f, 0.25f);
            }

            objects.Add(go);
        }

        return(objects);
    }
Пример #2
0
    public void HandleDragFinished(MouseController.DragParameters dragParams)
    {
        for (int x = dragParams.StartX; x <= dragParams.EndX; x++)
        {
            // Variables for the for-loop over the y-coordinates.
            // These are used to determine whether the loop should run from highest to lowest values or vice-versa.
            // The tiles are thus added in a snake or zig-zag pattern, which makes building more efficient.
            int begin     = (x - dragParams.StartX) % 2 == 0 ? dragParams.StartY : dragParams.EndY;
            int stop      = (x - dragParams.StartX) % 2 == 0 ? dragParams.EndY + 1 : dragParams.StartY - 1;
            int increment = (x - dragParams.StartX) % 2 == 0 ? 1 : -1;

            for (int y = begin; y != stop; y += increment)
            {
                Tile tile = WorldController.Instance.World.GetTileAt(x, y, WorldController.Instance.CameraController.CurrentLayer);
                if (tile == null)
                {
                    // Trying to build off the map, bail out of this cycle.
                    continue;
                }

                if (BuildMode == BuildMode.FURNITURE)
                {
                    // Check for furniture dragType.
                    Furniture proto = PrototypeManager.Furniture.Get(BuildModeType);

                    if (IsTilePartOfDrag(tile, dragParams, proto.DragType))
                    {
                        // Call BuildModeController::DoBuild().
                        DoBuild(tile);
                    }
                }
                else if (BuildMode == BuildMode.UTILITY)
                {
                    // Check for furniture dragType.
                    Utility proto = PrototypeManager.Utility.Get(BuildModeType);

                    if (IsTilePartOfDrag(tile, dragParams, proto.DragType))
                    {
                        // Call BuildModeController::DoBuild().
                        DoBuild(tile);
                    }
                }
                else
                {
                    DoBuild(tile);
                }
            }
        }

        // In devmode, utilities don't build their network, and one of the utilities built needs UpdateGrid called explicitly after all are built.
        if (BuildMode == BuildMode.UTILITY && SettingsKeyHolder.DeveloperMode)
        {
            Tile    firstTile = World.Current.GetTileAt(dragParams.RawStartX, dragParams.RawStartY, WorldController.Instance.CameraController.CurrentLayer);
            Utility utility   = firstTile.Utilities[PrototypeManager.Utility.Get(BuildModeType).Type];
            utility.UpdateGrid(utility);
        }
    }
Пример #3
0
    /// <summary>
    /// Checks whether a tile is valid for the drag type, given the drag parameters
    /// Returns true if tile should be included, false otherwise.
    /// </summary>
    private bool IsTilePartOfDrag(Tile tile, MouseController.DragParameters dragParams, string dragType)
    {
        switch (dragType)
        {
        case "border":
            return(tile.X == dragParams.StartX || tile.X == dragParams.EndX || tile.Y == dragParams.StartY || tile.Y == dragParams.EndY);

        case "path":
            bool withinXBounds = dragParams.StartX <= tile.X && tile.X <= dragParams.EndX;
            bool onPath        = tile.Y == dragParams.RawStartY || tile.X == dragParams.RawEndX;
            return(withinXBounds && onPath);

        default:
            return(true);
        }
    }
Пример #4
0
    public List <GameObject> HandleDragVisual(MouseController.DragParameters dragParams, Transform parent)
    {
        List <GameObject> objects = new List <GameObject>();

        for (int x = dragParams.StartX; x <= dragParams.EndX; x++)
        {
            for (int y = dragParams.StartY; y <= dragParams.EndY; y++)
            {
                Tile t = WorldController.Instance.World.GetTileAt(x, y, WorldController.Instance.CameraController.CurrentLayer);
                if (t != null)
                {
                    // Display the building hint on top of this tile position.
                    if (BuildMode == BuildMode.FURNITURE)
                    {
                        Furniture proto = PrototypeManager.Furniture.Get(BuildModeType);
                        if (IsTilePartOfDrag(t, dragParams, proto.DragType))
                        {
                            objects.Add(ShowFurnitureSpriteAtTile(BuildModeType, t));
                            GameObject go = ShowWorkSpotSpriteAtTile(BuildModeType, t);
                            if (go != null)
                            {
                                objects.Add(go);
                            }
                        }
                    }
                    else if (BuildMode == BuildMode.UTILITY)
                    {
                        Utility proto = PrototypeManager.Utility.Get(BuildModeType);
                        if (IsTilePartOfDrag(t, dragParams, proto.DragType))
                        {
                            objects.Add(ShowUtilitySpriteAtTile(BuildModeType, t));
                        }
                    }
                    else
                    {
                        // Show generic visuals
                        GameObject go = SimplePool.Spawn(WorldController.Instance.CircleCursorPrefab, new Vector3(x, y, WorldController.Instance.CameraController.CurrentLayer), Quaternion.identity);
                        go.transform.SetParent(parent, true);
                        go.GetComponent <SpriteRenderer>().sprite = SpriteManager.GetSprite("UI", "CursorCircle");
                        objects.Add(go);
                    }
                }
            }
        }

        return(objects);
    }
Пример #5
0
 /// <summary>
 /// NOT IMPLEMENTED BY SPAWN INVENTORY CONTROLLER.  Will throw on call.
 /// NOT MEANT TO BE CALLED.
 /// </summary>
 public void HandleDragFinished(MouseController.DragParameters parameters)
 {
     throw new InvalidOperationException("Not supported by this class");
 }