Ejemplo n.º 1
0
        public void DoGUIFunction(GUIFunction func)
        {
            if(this.elementFunctions.ContainsKey(func))
            {
                //GuiEvent eventToTrigger = GuiEvent.FromClickData(this.parentLayer, this.GetPosition());
                /*
                Point thisPixelPos = new Point(
                    this.GetPosition().x * Stage.CurrentStage.GetTileSize().Item1,
                    this.GetPosition().y * Stage.CurrentStage.GetTileSize().Item2);
                */
                //GuiEvent eventToTrigger = GuiEvent.FromClickData(this.parentLayer, thisPixelPos, this);
                GuiEvent eventToTrigger = GuiEvent.FromGuiElement(this);

                this.elementFunctions[func].Invoke(eventToTrigger);
            }
            else
            {
                //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() + "');");
                }
            }
        }
Ejemplo n.º 2
0
        public GUIFunction(string name, InputDevice bindingDevice, string defaultButtonName)
        {
            this.eventName = name;
            bindingDevice.Bind(defaultButtonName, 0, ButtonCommand.Down, this);

            //if there is no default function, it's this now
            if (GUIFunction.defaultFunction == null)
            {
                GUIFunction.defaultFunction = this;
            }

            GUIFunction.guiFunctions.Add(this);
        }
Ejemplo n.º 3
0
        //intervals...?
        public static void CreateManualClock()
        {
            //gui function, bound to the "plus" key (=/+)
            GUIFunction debugClock = new GUIFunction("DebugClock", InputDevice.Keyboard, "Plus");
            //bind it to the numpad as well
            InputDevice.Keyboard.Bind("NumPlus", 107, debugClock);

            //make sure that the debug layer is rendered...
            Debug.Render();

            //keybinding
            //InputManager.InputDevice.Keyboard.Bind("Plus", 0, debugClock);
            Debug.DebugLayer.SetGUIFunction(debugClock, Debug.DebugClock);

            //clock itself...

            Debug.manualClockCreated = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new gui function with the given name, binds it to the named button on the given device.
        /// </summary>
        /// <param name="name">The GUI Function's name</param>
        /// <param name="bindingDevice">The Input Device to bind to.</param>
        /// <param name="defaultButtonName"></param>
        public GUIFunction(string name, InputDevice bindingDevice, string defaultButtonName, ButtonCommand buttonCommand)
        {
            if (GUIFunction.GetByName(name) != null)
            {
                Debug.log("Warning! GUI Function with this name already exists! You really need a factory!");
            }

            this.eventName = name;
            bindingDevice.Bind(defaultButtonName, 0, buttonCommand, this);

            //if there is no default function, it's this now
            if (GUIFunction.defaultFunction == null)
            {
                GUIFunction.defaultFunction = this;
            }

            GUIFunction.guiFunctions.Add(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Bind a button to a function. If the buttonName is null or empty, the function will identify the button with the id.
        /// </summary>
        /// <param name="buttonName"></param>
        /// <param name="buttonId"></param>
        /// <param name="buttonFunction"></param>
        public void Bind(string buttonName, int buttonId, ButtonCommand buttonCommand, GUIFunction buttonFunction)
        {
            if (buttonName != "" && buttonName != null)
            {
                buttonId = this.GetButtonId(buttonName);
            }

            if(!this.buttonFunctions.ContainsKey(buttonId))
            {
                this.buttonFunctions[buttonId] = new Dictionary<ButtonCommand,GUIFunction>();
            }
            this.buttonFunctions[buttonId][buttonCommand] = buttonFunction;
            //this.buttonFunctions[buttonId] = buttonFunction;
        }
Ejemplo n.º 6
0
 public void Bind(string buttonName, int buttonId, GUIFunction buttonFunction)
 {
     this.Bind(buttonName, buttonId, ButtonCommand.Down, buttonFunction);
 }
Ejemplo n.º 7
0
 public void SetGUIFunction(GUIFunction func, Action<GuiEvent> newEvent)
 {
     this.layerFunctions[func] = newEvent;
 }
Ejemplo n.º 8
0
        public void GUI_Event(GUIFunction buttonFunction, InputDevice callingDevice, Point eventPos)
        {
            //perform the gui function attached to the affected layer
            this.DoGUIFunction(buttonFunction, callingDevice, eventPos);

            //the gui element receiving the event
            GuiElement elementToNotify;

            //if the pos is null, then assume that the item to fire on is the focused item
            if (eventPos == null)
            {
                //there is no focused element, so we don't know what element to send the command to
                if (this.focusedElement == null)
                {
                    return;
                }
                elementToNotify = this.focusedElement;
            }
                //if eventpos is not null, find the element at the position
            else
            {
                elementToNotify = this.GetElementAt(eventPos.x, eventPos.y);
            }

            //check to make sure we have an element, don't proceed if it's null
            if (elementToNotify == null)
            {
                //Script.Eval("console.log('Sadface :(');");
                return;
            }

            //perform the gui function attached to the given gui element
            elementToNotify.DoGUIFunction(buttonFunction);
        }
Ejemplo n.º 9
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() + "');");
                }
                */
            }
        }
Ejemplo n.º 10
0
        public void CreateTestGUI()
        {
            //GUIFunction gfAction = new GUIFunction("Action", InputDevice.Mouse, "mouse0", ButtonCommand.Press);
            GUIFunction gfMouseDown = new GUIFunction("MouseDown", InputDevice.Mouse, "mouse0", ButtonCommand.Down);
            GUIFunction gfMouseUp = new GUIFunction("MouseUp", InputDevice.Mouse, "mouse0", ButtonCommand.Up);
            GuiLayer testLayer = View.GetMainView().AddLayer("CollisionLayer", DOM_Renderer.GetRenderer().As<DOM_Renderer>().BoardArea());

            GuiLayer cursorLayer = View.GetMainView().AddLayer("CursorLayer", new Rectangle(0, 0, 100, 100));
            cursorLayer.FollowCursor(true);
            cursorLayer.Deactivate();
            //add content to the cursor layer
            GuiElement cursorColorIndicator = cursorLayer.AddGUIElement("");
            //cursorColorIndicator.AddStyle("gradientMan");
            cursorColorIndicator.SetStyle("Background", Gradient.ToString(new Color(0, 80, 200)));
            cursorColorIndicator.SetSize(100, 100);
            cursorLayer.Hide();

            testLayer.SetGUIFunction(gfMouseDown, chargeLazer);
            testLayer.SetGUIFunction(gfMouseUp, fireLazer);
        }
Ejemplo n.º 11
0
        //create the GUI menu for building towers
        private void createTowerMenu()
        {
            //create the gui functions
            GUIFunction gfAction = new GUIFunction("Action", InputDevice.Mouse, "mouse0");
            GUIFunction gfContext = new GUIFunction("Context", InputDevice.Mouse, "mouse1");
            //InputDevice.Keyboard.Bind("enter", 0, gfAction);

            //create the layer itself
            GuiLayer towerMenu = View.GetMainView().AddLayer("TowerMenu", new Rectangle(-100, 40, 146, 300));
            //make this the active UI layer
            towerMenu.Activate();

            GuiElement label = towerMenu.AddGUIElement("Towers");
            label.SetPosition(0, 0);
            //create a GUI element to place a tower
            GuiElement nyanTower = towerMenu.AddGUIElement("Nyan Nest");
            //give it a single frame sprite for the tower icon
            nyanTower.SetSprite(Sprite.GetSpriteByName("NyanTower"));
            nyanTower.SetPosition(70, 32);
            //call the animation call once to get it to render
            nyanTower.SetCustomValue("NyanTower");
            //repeat for the other towers

            GuiElement xTheYTower = towerMenu.AddGUIElement("All The Things");
            xTheYTower.SetSprite(Sprite.GetSpriteByName("XTheYTower"));
            xTheYTower.SetPosition(20, 132);
            xTheYTower.SetCustomValue("XTheYTower");

            GuiElement tableFlipperTower = towerMenu.AddGUIElement("Table Flipper");
            tableFlipperTower.SetSprite(Sprite.GetSpriteByName("TableFlipperTower"));
            tableFlipperTower.SetPosition(20, 32);
            tableFlipperTower.SetCustomValue("TableFlipperTower");

            GuiElement barrelRollTower = towerMenu.AddGUIElement("Barrel Roll Tower");
            barrelRollTower.SetSprite(Sprite.GetSpriteByName("BarrelRollTower"));
            barrelRollTower.SetPosition(20, 82);
            barrelRollTower.SetCustomValue("BarrelRollTower");

            GuiElement arrowKneeTower = towerMenu.AddGUIElement("Guard Tower");
            arrowKneeTower.SetSprite(Sprite.GetSpriteByName("GuardTower"));
            arrowKneeTower.SetPosition(70, 82);
            arrowKneeTower.SetCustomValue("GuardTower");

            // Assign the click event for each button (tower) in the menu to the function that handles clicking for this menu.
            foreach (GuiElement towerIcon in towerMenu.GetGuiElements())
            {
                towerIcon.SetGUIFunction(gfAction, towerMenu_Click);
            }
        }
Ejemplo n.º 12
0
 public static void SetDefaultFunction(GUIFunction newFunc)
 {
     GUIFunction.defaultFunction = newFunc;
 }
Ejemplo n.º 13
0
        public void GUI_Event(GUIFunction buttonFunction, InputDevice sendingDevice, int clickX, int clickY)
        {
            clickX -= (int)this.GetArea().x;
            clickX -= (int)this.GetArea().y;

            //loop through all of the active gui layers
            //foreach (GuiLayer layer in this.guiLayers)
            for (int i = 0; i < this.guiLayers.Count; i++)
            {
                GuiLayer layer = this.guiLayers[i];
                Point actionLocation = new Point(clickX, clickY);

                //skip this layer if the layer doesn't exist in the clicked space
                //if (clickX > layer.GetArea().Right || clickX < layer.GetArea().x || clickY < layer.GetArea().y || clickY > layer.GetArea().Top)
                if (!layer.GetArea().Contains(actionLocation))
                {
                    continue;
                }

                //translate the coordinates to be relative to the gui layer?

                //fire a new gui event on the layer...
                //tell the GUI layer which action was triggered and (if applicable) where
                layer.GUI_Event(buttonFunction, sendingDevice, actionLocation);
            }
        }
Ejemplo n.º 14
0
 public void SetGUIFunction(GUIFunction func, Action<GuiEvent> newEvent)
 {
     elementFunctions[func] = newEvent;
 }