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; }
/// <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; }
public void RemoveGUIElement(GuiElement gelm) { this.guiElements.Remove(gelm); //defocus the element if its focused }
//select the previous item in the list of gui elements public void PreviousItem() { //this is probably a terrible way to do this //the index of the currently focused item in the array of gui elements within this layer int focusedInex = this.guiElements.IndexOf(this.focusedElement); //if the element at the end of the list is the one that's currently selected, point to before the end of the list, so that it loops if (focusedInex <= 0) { focusedInex = this.guiElements.Count -1; } this.focusedElement = this.guiElements[focusedInex - 1]; }
//select the next item in the list of gui elements public void NextItem() { //the index of the currently focused item in the array of gui elements within this layer int focusedInex = this.guiElements.IndexOf(this.focusedElement); //if the element at the end of the list is the one that's currently selected, point to before the beginning of the list, so that it loops if (focusedInex >= this.guiElements.Count - 1) { focusedInex = -1; } this.focusedElement = this.guiElements[focusedInex + 1]; }
/// <summary> /// Add an existing GUI element to the layer. /// </summary> /// <param name="elementToAdd"></param> public void AddGUIElement(GuiElement elementToAdd) { if (!this.guiElements.Contains(elementToAdd)) { this.guiElements.Add(elementToAdd); } }
/// <summary> /// Create a new element and add it to the gui layer /// </summary> /// <param name="text">The text to appear with the element.</param> /// <param name="guiSprite">A sprite which represent's the GUI's graphical icon.</param> /// <returns></returns> public GuiElement AddGUIElement(string text) { //create a new element with this as the parent, and the given text as its caption GuiElement newElement = new GuiElement(this, text); //add the element to the list of elements in this layer //this.guiElements.Add(newElement); //if no element has the focus on this layer, give focus to the new element if (this.focusedElement == null) { this.focusedElement = newElement; } return newElement; }
public void SetNeedsUpdate(GuiElement gelm) { if (!this.guiElementsToUpdate.Contains(gelm.GetId())) { this.guiElementsToUpdate.Add(gelm.GetId()); } }
public void RenderGUIElement(GuiElement gelm) { HtmlElement guiElem = null; if (elementsByGuiId.ContainsKey(gelm.GetId())) { guiElem = elementsByGuiId[gelm.GetId()].As<HtmlElement>(); } //if it's not rendered, render it if (guiElem == null) { guiElem = document.createElement("div").As<HtmlElement>(); this.AddClass(guiElem, "GUIElement"); //document.getElementById("gameBoard").appendChild(gentlement); this.elementsByGuiId[gelm.GetParentLayer().GetId()].appendChild(guiElem); //!! Basing this on size 12 font right now, and it's going to be totally wrong, and needs to be done up properly if (gelm.GetText() != "" && gelm.GetSprite() == null) { guiElem.style.width = (gelm.GetText().Length * 12) + "px"; guiElem.style.height = 12 + "px"; guiElem.innerHTML = gelm.GetText(); } else { if (gelm.GetSize().width != 0 && gelm.GetSize().height != 0) { guiElem.style.width = gelm.GetSize().width + " px"; guiElem.style.height = gelm.GetSize().height + "px"; } //Debug.log("Setting width to " + gelm.GetSize().width + ". Width is " + gentlement.style.width); //Debug.log("Setting height to " + gelm.GetSize().height + ". Height is " + gentlement.style.height); } //since we're building this for the first time, put all the classes into a long list, to cut down on operations string styleString = ""; foreach (string style in gelm.GetStyles()) { styleString += style + " "; } //styleString = styleString.TrimEnd(); this.AddClass(guiElem, styleString); elementsByGuiId[gelm.GetId()] = guiElem; } //update the element with new position information if need be if (this.guiElementsToUpdate.Contains(gelm.GetId())) { guiElem.innerHTML = gelm.GetText(); //reposition the element based on game position guiElem.style.left = gelm.GetPosition().x + "px"; guiElem.style.top = gelm.GetPosition().y + "px"; if (gelm.GetStyle("Background") != null) { guiElem.style.background = gelm.GetStyle("Background"); } this.guiElementsToUpdate.Remove(gelm.GetId()); } if (gelm.GetSprite() == null) { return; } guiElem.innerHTML = ""; //call the sprite's animate function //it will return the id of the frame that the sprite and its animation are currently on string frameId = gelm.GetSprite().Animate(); //if that result is different from the value we have stored as this GameEntity's current display frame, if (frameId != gelm.GetSprite().CurrentRenderFrame) { //update this thing's CSS to the new frame //jQueryObject GameEntityDiv = jQuery.FromElement(GameEntityDiv); this.RemoveClass(guiElem, gelm.GetSprite().CurrentRenderFrame); this.AddClass(guiElem, frameId); //and update our current frameid gelm.GetSprite().CurrentRenderFrame = frameId; guiElem.style.width = gelm.GetSprite().Size.width + "px"; guiElem.style.height = gelm.GetSprite().Size.height + "px"; } }