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); }
/// <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); }
public static void InitializeDevices() { InputDevice.Mouse = new InputDevice("mouse", isCursor: true); InputDevice.Keyboard = new InputDevice("keyboard"); InputDevice.Mouse.SetButtonName(1, "mouse0"); //InputDevice.Mouse.SetButtonName(1, "mouse1"); // Set up basic values for mouse axes // X InputDevice.Mouse.SetAxisPosition(0, 0); // Y InputDevice.Mouse.SetAxisPosition(1, 0); //maybe use getkeycode or getkeychar javascript functions for the keyboard (for now)? InputDevice.Keyboard.SetButtonName(32, "space"); InputDevice.Keyboard.SetButtonName(65, "a"); InputDevice.Keyboard.SetButtonName(68, "d"); InputDevice.Keyboard.SetButtonName(83, "s"); InputDevice.Keyboard.SetButtonName(87, "w"); InputDevice.Keyboard.SetButtonName(187, "Plus"); InputDevice.Keyboard.SetButtonName(107, "NumPlus"); }
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); }
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() + "');"); } */ } }
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); } }