コード例 #1
0
        /// <summary>
        /// Called to close the menu.
        /// </summary>
        public void close()
        {
            if (!readyToClose())
            {
                return;
            }

            // no more tree selection
            selectedTree = null;
            // clean up before leaving the area
            Game1.currentLocation.cleanupBeforePlayerExit();
            // move to the farm
            Game1.currentLocation = savedLocation;
            // reset the location for our entry
            Game1.currentLocation.resetForPlayerEntry();
            // enable the HUD
            Game1.displayHUD = true;
            // unfreeze the viewport
            Game1.viewportFreeze = false;
            // render our character
            Game1.displayFarmer = true;
            // fade the screen in with no callback
            Game1.globalFadeToClear();

            // exit the menu
            exitThisMenu();
        }
コード例 #2
0
 /// <summary>
 /// Handles closing the menu.
 /// </summary>
 private void handleCancelAction()
 {
     if (readyToClose())
     {
         Game1.globalFadeToBlack(new Game1.afterFadeFunction(close));
     }
     else if (selectedTree != null)
     {
         selectedTree = null;
         Game1.playSound("shwip");
     }
 }
コード例 #3
0
        /// <summary>
        /// Called when left click is performed in our menu
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="playSound">If set to <c>true</c> play sound.</param>
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            // invoke base class method
            base.receiveLeftClick(x, y, playSound);

            // if we are fading then ignore
            if (Game1.globalFade)
            {
                return;
            }

            // get the mouse position (don't use the x and y from the function)
            var mouseX = Game1.getOldMouseX(ui_scale: false);
            var mouseY = Game1.getOldMouseY(ui_scale: false);

            // get cursor tile location
            var tileLocation = new Vector2(
                (Game1.viewport.X + mouseX) / Game1.tileSize,
                (Game1.viewport.Y + mouseY) / Game1.tileSize
                );

            if (cancelButton.containsPoint(x, y))
            {
                handleCancelAction();
                return;
            }

            if (flipButton.containsPoint(x, y))
            {
                flipTree();
                return;
            }

            if (!canPlace && selectedTree != null)
            {
                Notifier.Message(TreeTransplant.helper.Translation.Get("Menu_InvalidPlace"));
                Game1.playSound("cancel");
            }
            else if (selectedTree != null && tileLocation == selectedTreeLocation)
            {
                if (selectedTree.tree.flipped == selectedTree.flipped)
                {
                    Game1.playSound("shwip");
                }
                else
                {
                    Game1.playSound("dirtyHit");
                }
                selectedTree.propFlip();
                selectedTree = null;
            }
            else if (Game1.currentLocation.terrainFeatures.ContainsKey(tileLocation))
            {
                // get our terrain feature
                var terrainFeature = Game1.currentLocation.terrainFeatures[tileLocation];
                // make sure its the type we care about
                if (terrainFeature is FruitTree || terrainFeature is Tree)
                {
                    if (terrainFeature is Tree && (terrainFeature as Tree).tapped.Value)
                    {
                        Notifier.Message(TreeTransplant.helper.Translation.Get("Menu_InvalidCap"));
                        Game1.playSound("cancel");
                        return;
                    }
                    // set the selected tree
                    selectedTree         = new TreeRenderer(terrainFeature);
                    selectedTreeLocation = tileLocation;
                    Game1.playSound("hoeHit");
                }
            }
            else if (selectedTree != null)
            {
                // remove the original
                Game1.currentLocation.terrainFeatures.Remove(selectedTreeLocation);
                // perform the flip that's done in memory
                selectedTree.propFlip();
                // add a new one in the spot selected
                Game1.currentLocation.terrainFeatures.Add(tileLocation, selectedTree.tree.getTerrainFeature());
                // play sound of seed placement
                Game1.playSound("dirtyHit");
                // deselect the tree
                selectedTree         = null;
                selectedTreeLocation = Vector2.Zero;
            }
        }
コード例 #4
0
        /// <summary>
        /// Called when left click is performed in our menu
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="playSound">If set to <c>true</c> play sound.</param>
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            // invoke base class method
            base.receiveLeftClick(x, y, playSound);

            // if we are fading then ignore
            if (Game1.globalFade)
            {
                return;
            }

            // get cursor tile location
            var tileLocation = new Vector2(
                (Game1.viewport.X + x) / Game1.tileSize,
                (Game1.viewport.Y + y) / Game1.tileSize
                );

            if (cancelButton.containsPoint(x, y))
            {
                handleCancelAction();
                return;
            }

            if (flipButton.containsPoint(x, y))
            {
                flipTree();
                return;
            }

            if (!canPlace && selectedTree != null)
            {
                Notifier.Message("Can't place here!");
                Game1.playSound("cancel");
            }
            else if (selectedTree != null && tileLocation == selectedTreeLocation)
            {
                selectedTree.propFlip();
                selectedTree = null;
                Game1.playSound("shwip");
            }
            else if (Game1.currentLocation.terrainFeatures.ContainsKey(tileLocation))
            {
                // get our terrain feature
                TerrainFeature terrainFeature = Game1.currentLocation.terrainFeatures[tileLocation];
                // make sure its the type we care about
                if (terrainFeature is FruitTree || terrainFeature is Tree)
                {
                    if (terrainFeature is Tree && (terrainFeature as Tree).tapped)
                    {
                        Notifier.Message("Can't move tree with a tree tap!");
                        Game1.playSound("cancel");
                        return;
                    }
                    // set the selected tree
                    selectedTree         = new TreeRenderer(terrainFeature);
                    selectedTreeLocation = tileLocation;
                    Game1.playSound("bigSelect");
                }
            }
            else if (selectedTree != null)
            {
                // remove the original
                Game1.currentLocation.terrainFeatures.Remove(selectedTreeLocation);
                // perform the flip that's done in memory
                selectedTree.propFlip();
                // add a new one in the spot selected
                Game1.currentLocation.terrainFeatures.Add(tileLocation, selectedTree.tree.getTerrainFeature());
                // play sound of tree
                Game1.playSound("bigDeSelect");
                // deselect the tree
                selectedTree         = null;
                selectedTreeLocation = Vector2.Zero;
            }
        }