コード例 #1
0
    //TODO: refactor
    private void clickedTile(PathBuildElement pathElement)
    {
        if (complete)
        {
            return;
        }

        // just holding over tile or clicked on same tile => do nothing
        if (selected != null && pathElement.index == selected.Value)
        {
            return;
        }

        GD.Print(String.Format("Level -> clicked on [{0}] from selected: '{1}'", pathElement, selected));

        // do we have anything selected?
        if (selected == null)
        {
            if (tiles[pathElement.index.Value].hasSelectableItem())
            {
                tiles[pathElement.index.Value].select(false);
                selected = pathElement.index;
                selectCandidates(selected.Value);
            }
        }
        else
        {
            var clickedIndex = clickedOnCandidate(pathElement.index.Value);

            if (clickedIndex.HasValue)
            {
                GD.Print("clicked on candidate");
                var originalColor = tiles[clickedIndex.Value].getItemColor();
                if (originalColor.HasValue)
                {
                    paths[originalColor.Value].cutPathIncluding(clickedIndex.Value);
                    makeLastBlockConstruction(originalColor.Value);
                }

                var color = tiles[selected.Value].getItemColor();
                if (color != null)
                {
                    GD.Print("build next block at ", clickedIndex);

                    // prepare new rails or go to depot
                    PlayObject newBlockItem;
                    if (tiles[clickedIndex.Value].hasDepot)
                    {
                        newBlockItem = tiles[clickedIndex.Value].depot;
                        updateLastRail(selected.Value, clickedIndex.Value, color.Value);
                    }
                    else
                    {
                        newBlockItem = buildNewConstructionRails(clickedIndex.Value, color.Value);
                    }

                    paths[color.Value].add(selected.Value, clickedIndex.Value, newBlockItem);

                    // clear selections
                    tiles[selected.Value].cancelSelect();
                    cancelSelectCandidates(selected.Value);

                    // select next candidates
                    selected = clickedIndex;
                    if (!(tiles[selected.Value].hasDepot && tiles[selected.Value].depot.depotType == DepotType.END))
                    {
                        tiles[selected.Value].select(false);
                        selectCandidates(selected.Value);
                    }
                }
                else
                {
                    throw new Exception(string.Format("this shoud not happen. We should be on block with item on it with color. We're on '{0}'", selected));
                }
            }
            else if (tiles[pathElement.index.Value].hasSelectableItem()) // clicked on new item
            {
                tiles[selected.Value].cancelSelect();
                cancelSelectCandidates(selected.Value);

                tiles[pathElement.index.Value].select(false);
                selected = pathElement.index;
                paths[pathElement.color.Value].cutPath(selected.Value);
                makeLastBlockConstruction(pathElement.color.Value);
                selectCandidates(selected.Value);
            }
        }
        // printPaths();
    }
コード例 #2
0
 private void clickedOnObject(PathBuildElement pathElement)
 {
     objectClicked?.Invoke(new PathBuildElement(pathElement.color, index));
     // highlight(!material.EmissionEnabled);
 }