Пример #1
0
        public static GuiEvent FromGuiElement(GuiElement sender)
        {
            GuiEvent returnEvent = new GuiEvent((int)sender.GetPosition().x, (int)sender.GetPosition().y);

            returnEvent.clickedElement = sender;
            returnEvent.clickedTiles = sender.GetParentLayer().GetTilesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            //presume no entities and tiles...?

            return returnEvent;
        }
Пример #2
0
        public void chargeLazer(GuiEvent evt)
        {
            //show the color we're going to create
            GuiLayer.GetLayerByName("CursorLayer").Show();

            //start with red
            newLightColor = new Color(1, 0, 0);

            //add an interval to the clock to advance the color to display
            chargeInterval = Clock.AddRender(colorTicker);
        }
Пример #3
0
        //public static GuiEvent FromClickData(GuiLayer gLayer, jQueryEvent jqClickData)
        public static GuiEvent FromClickData(GuiLayer gLayer, Point clickPos)
        {
            GuiEvent returnEvent = new GuiEvent(Helpah.d2i(clickPos.x), Helpah.d2i(clickPos.y));
            //Dimension TileSize = Stage.CurrentStage.GetTileSize();

            //returnEvent.eventPixelPos = new Point(clickPos.x, clickPos.y);
            //returnEvent.eventPos = new Point(returnEvent.eventPixelPos.x / TileSize.First, returnEvent.eventPixelPos.y / TileSize.Second);
            //Script.Eval("console.log('Pixelpos is " + returnEvent.eventPixelPos.x + ", " + returnEvent.eventPixelPos.y + ". Pos is " + returnEvent.eventPos.x + ", " + returnEvent.eventPos.y + "');");
            //returnEvent.eventAction = "Click";

            returnEvent.clickedElement = gLayer.GetElementAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            returnEvent.clickedEntities = gLayer.GetEntitiesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            returnEvent.clickedTiles = gLayer.GetTilesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);

            return returnEvent;
        }
Пример #4
0
        public void DoGUIFunction(GUIFunction func, InputDevice callingDevice, Point eventPos)
        {
            eventPos.x -= this.GetPosition().x;
            eventPos.y -= this.GetPosition().y;

            if(this.layerFunctions.ContainsKey(func))
            {
                GuiEvent eventToTrigger;
                if (callingDevice.IsCursor)
                {
                    eventToTrigger = GuiEvent.FromClickData(this, eventPos);
                }
                else
                {
                    eventToTrigger = new GuiEvent((int)eventPos.x, (int)eventPos.y);
                }

                this.layerFunctions[func].Invoke(eventToTrigger);
            }
            else
            {
                //Debug.log("I got " + this.layerFunctions.Count + " GUIFunctions but a " + func.GetName() + " aint one. (P.S. I am " + this.GetName() + ")");
                /*
                Script.Eval("console.log('No function " + func.GetName() + " on that element. It has these " + this.elementFunctions.Count + " functions:');");
                foreach (GUIFunction gf in this.elementFunctions.Keys)
                {
                    Script.Eval("console.log('" + gf.ToString() + "');");
                    //Script.Eval("console.log('" + gf.GetName() + "');");
                }
                */
            }
        }
Пример #5
0
        /// <summary>
        /// Each of the parameters is nullable. The most complete set of data possible will be built from any non-null parameters.
        /// </summary>
        /// <param name="sendingTile"></param>
        /// <param name="sendingGameEntity"></param>
        /// <param name="sendingElement"></param>
        /// <param name="triggeringPosition"></param>
        /// <param name="triggeringScreenPosition"></param>
        /// <returns></returns>
        public static GuiEvent FromPartialData(Tile sendingTile, GameEntity sendingGameEntity, GuiElement sendingElement, Point triggeringPosition, Point triggeringScreenPosition)
        {
            GuiEvent eventToReturn = new GuiEvent(0, 0);

            //check each of the parameters for non-null values and set them in the event to return
            if (sendingTile != null)
            {
                eventToReturn.clickedTiles.Add(sendingTile);
            }
            if (sendingGameEntity != null)
            {
                eventToReturn.clickedEntities.Add(sendingGameEntity);
            }
            if (sendingElement != null)
            {
                eventToReturn.clickedElement = sendingElement;
            }
            if (triggeringPosition != null)
            {
                eventToReturn.eventPos = triggeringPosition;
            }
            if (triggeringScreenPosition != null)
            {
                eventToReturn.eventPixelPos = triggeringScreenPosition;
            }

            //go through the values, and determine values for those that are null
            if (eventToReturn.eventPos == null)
            {
                //get the position from one of the properties that we have...
            }

            //gotta do this for the other stuff too
            //eventToReturn.clickedElement = gLayer.GetElementAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            //eventToReturn.clickedEntities = gLayer.GetEntitiesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);
            //eventToReturn.clickedTiles = gLayer.GetTilesAt(returnEvent.eventPos.x, returnEvent.eventPos.y);

            return eventToReturn;
        }
Пример #6
0
        //allows an action to be done on "manual" strokes of a clock
        //by default, the clock is 'advanced' by hitting the '+' key
        //if statefulness is ever implemented, it can be retreaded with the '-' key
        public static void DebugClock(GuiEvent buttonTrigger)
        {
            //if the 'clock' doesn't exist, create it...
            if (Debug.manualClockCreated == false)
            {
                CreateManualClock();
            }

            //advance the clock
            foreach (Action act in Debug.manualClockRenders)
            {
                act.Invoke();
            }
            foreach (Action act in Debug.manualClockCalculations)
            {
                act.Invoke();
            }
        }
Пример #7
0
        public void fireLazer(GuiEvent evt)
        {
            //stop the periodic color growth
            Clock.RemoveRender(chargeInterval);

            //remove (hide) the gui element created in chargeLazer
            GuiLayer.GetLayerByName("CursorLayer").Hide();

            int range = 10;

            //create the light
            LightSource plCol = new LightSource(evt.eventPos.x, evt.eventPos.y, 5, range);
            plCol.SetDiminishing(true);
            plCol.SetColor(newLightColor);

            //create a shadow creature, of the same color as the player dropped

            //chase away any nearby shadow creatures colored opposite to what the player dropped

            /*
            //show / affect any nearby lightstones
            List<LightSource> lightsInRange = Stage.CurrentStage.GetLightsNear(evt.eventPos, range);
            foreach (LightSource light in lightsInRange)
            {
                if (light is Lightstone)
                {
                    light.Show();
                    Clock.TimedExecute(light.Hide, 1);
                }
            }
            */
            int lightRange = Helpah.d2i(plCol.GetRange());
            List<LightSource> lightList = Stage.CurrentStage.GetLightsNear(plCol.GetPosition(), lightRange);
            //Debug.log("There are " + lightList.Count + " lights in within " + lightRange + " of click.");
            foreach (LightSource light in lightList)
            {
                if (!(light is Lightstone))
                {
                    continue;
                }
                light.Show();
                Clock.TimedExecute(light.Hide, 1);
            }
        }
Пример #8
0
        //test function to make a new tower...
        public void placeATower(GuiEvent gEvent)
        {
            //hide the collision map gui layer
            Stage.CurrentStage.HideCollisionMap();

            // Make sure we can place a tower there.
            if (checkTowerPlacement(gEvent) == false)
            {
                // Make a noise.
                return;
            }

            // Need to add a check for financial ability as well ...
            // But maybe on the tower menu instead.

            Tile clickedTile = gEvent.clickedTiles[0];

            // Decrement the player's currency
            changePlayerCurrency(-33);

            towerToPlace = LivingGameEntity.CloneByName(desiredTowerName);
            towerToPlace.SetParentStage(Stage.CurrentStage);
            towerToPlace.SetPosition(clickedTile.GetPosition().x, clickedTile.GetPosition().y);
            towerToPlace.Faction = playerFaction;

            Stage.CurrentStage.AddLivingGameEntity(towerToPlace);

            //deselect the selected tower in the gui menu
            GuiLayer towerLayer = GuiLayer.GetLayerByName("TowerMenu");
            //towerLayer.SelectItem("By putting this text here, everything will be deselected, but nothing will be selected.", -1);
            // Destroy the notification.
            placeTower.Destroy();

            // After the tower is placed, re-calculate pathing for the stage.
            // If there is only one path enemies can take, mark the crucial point(s) as walkable but unbuildable.
        }
Пример #9
0
        // Returns true if a tower can be placed at the tile located at the gui event. False if a tower cannot be placed.
        private bool checkTowerPlacement(GuiEvent gEvent)
        {
            if (gEvent.clickedTiles.Count == 0 || desiredTowerName == "")
            {
                Debug.log("Can't do click. No tile or no tower. Returning.");
                return false;
            }
            Tile clickedTile = gEvent.clickedTiles[0];

            if (clickedTile.GetBuildable() == false)
            {
                return false;
            }

            return true;
        }
Пример #10
0
        public void towerMenu_Click(GuiEvent gEvent)
        {
            //set up the tower that we intend to click based on the custom value set in the gui element
            desiredTowerName = gEvent.clickedElement.GetCustomValue();
            if (desiredTowerName == "" || desiredTowerName == null)
            {
                //Debug.log(gEvent.clickedElement.GetId() + " has no custom value :(");
                return;
            }

            //attach a function to the main view when the user clicks on it
            GUIFunction gfAction = GUIFunction.GetByName("Action");
            Stage.CurrentStage.GetCollisionMap().SetGUIFunction(gfAction, placeATower);

            //show the collision map on the main playable area
            Stage.CurrentStage.ShowCollisionMap();

            //set the gui element that led us here to be highlighted
            gEvent.clickedElement.Select(true);

            //set the tower menu as the default gui layer, so that if something tries to switch to default in the future, it switches to this
            //deactivate the tower menu gui layer

            //create a gui element and set it to following the mouse
            Debug.log("Attempting to set cursor to sprite " + desiredTowerName);
            SetCursor(Sprite.GetSpriteByName(desiredTowerName));

            //throw up a notification for the player
            Sprite ggg = Sprite.GetSpriteByName("GoodGuyGreg");
            placeTower = new Notification(ggg, "Good Guy Greg", "@ggg", "Click where you would like the tower to be placed.", 10);
        }