public override void Input() { base.Input(); IsDragging = false; InBorder = false; if (IsFocused) { var mousePos = (Vec2)GuiData.getMousePos(); InBorder = IsInBorder(mousePos); if (!InBorder && !IsPressed && GuiData.isMouseLeftDown()) { OriginalClickPosition = mousePos - Rect.Position; ClickPositionOffset = OriginalClickPosition - Rect.Position; } if (IsPressed) { var movePos = new Vec2(MovedPosition); if (XBound != null) { movePos.X = mousePos.X - Rect.X - OriginalClickPosition.X; movePos.X = Math.Min(Math.Max(Rect.Y + movePos.X, XBound.Y), XBound.X) - Rect.X; } if (YBound != null) { movePos.Y = mousePos.Y - Rect.Y - OriginalClickPosition.Y; movePos.Y = Math.Min(Math.Max(Rect.Y + movePos.Y, YBound.Y), YBound.X) - Rect.Y; } MovedPosition = movePos; IsDragging = true; } GuiData.blockingInput |= IsFocused || IsPressed; } }
public override bool Draw() { IsDragging = false; if (IsActive && !InBorder) { if (!IsHeldDown) { if (GuiData.mouseWasPressed()) { OriginalClickPosition = GuiData.getMousePos(); OriginalClickPosition.X -= X; OriginalClickPosition.Y -= Y; ClickPositionOffset = new Vector2(OriginalClickPosition.X - X, OriginalClickPosition.Y - Y); } } } if (IsHeldDown) { float mvx = MovedPosition.X, mvy = MovedPosition.Y; if (XBound.HasValue) { mvx = GuiData.mouse.X - X - OriginalClickPosition.X; mvx = Math.Min(Math.Max(Y + mvx, XBound.Value.Min), XBound.Value.Max) - X; } if (YBound.HasValue) { mvy = GuiData.mouse.Y - Y - OriginalClickPosition.Y; mvy = Math.Min(Math.Max(Y + mvy, YBound.Value.Min), YBound.Value.Max) - Y; } MovedPosition = new Vector2(mvx, mvy); IsDragging = true; } GuiData.blockingInput |= IsActive || IsHeldDown; base.Draw(); return(IsDragging); }
public static Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height, float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX, float xMax, float yMax, float xMin, float yMin) { DraggableRectangle.isDragging = false; if (!selectedColor.HasValue) { selectedColor = new Color?(GuiData.Default_Selected_Color); } if (!deselectedColor.HasValue) { deselectedColor = new Color?(GuiData.Default_Unselected_Color); } Vector2 temp = GuiData.temp; temp.X = 0.0f; temp.Y = 0.0f; Rectangle tmpRect1 = GuiData.tmpRect; tmpRect1.X = (int)x; tmpRect1.Y = (int)y; tmpRect1.Width = width; tmpRect1.Height = height; Rectangle tmpRect2 = GuiData.tmpRect; tmpRect2.X = (int)((double)x + (double)selectableBorder); tmpRect2.Y = (int)((double)y + (double)selectableBorder); tmpRect2.Width = (double)selectableBorder == -1.0 ? 0 : (int)((double)width - 2.0 * (double)selectableBorder); tmpRect2.Height = (double)selectableBorder == -1.0 ? 0 : (int)((double)height - 2.0 * (double)selectableBorder); if (tmpRect1.Contains(GuiData.getMousePoint()) && !tmpRect2.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; if (GuiData.active != myID && GuiData.mouseWasPressed()) { GuiData.active = myID; DraggableRectangle.originalClickPos = GuiData.getMousePos(); DraggableRectangle.originalClickPos.X -= x; DraggableRectangle.originalClickPos.Y -= y; DraggableRectangle.originalClickOffset = new Vector2(DraggableRectangle.originalClickPos.X - x, DraggableRectangle.originalClickPos.Y - y); } } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.active == myID) { if (GuiData.mouseLeftUp()) { GuiData.active = -1; } else { if (canMoveX) { temp.X = (float)GuiData.mouse.X - x - DraggableRectangle.originalClickPos.X; temp.X = Math.Min(Math.Max((float)tmpRect1.X + temp.X, xMin), xMax) - (float)tmpRect1.X; } if (canMoveY) { temp.Y = (float)GuiData.mouse.Y - y - DraggableRectangle.originalClickPos.Y; temp.Y = Math.Min(Math.Max((float)tmpRect1.Y + temp.Y, yMin), yMax) - (float)tmpRect1.Y; } tmpRect1.X += (int)temp.X; tmpRect1.Y += (int)temp.Y; DraggableRectangle.isDragging = true; } } if (GuiData.active == myID || GuiData.hot == myID) { GuiData.blockingInput = true; } GuiData.spriteBatch.Draw(Utils.white, tmpRect1, GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value); return(temp); }
public static int doList(int myID, int x, int y, int width, int height, string[] text, int lastSelectedIndex, Color?selectedColor) { if (!selectedColor.HasValue) { selectedColor = new Color?(GuiData.Default_Selected_Color); } int num1 = -1; SelectableTextList.wasActivated = false; int num2 = lastSelectedIndex; SelectableTextList.selectionWasChanged = false; Vector2 mousePos = GuiData.getMousePos(); Rectangle tmpRect = GuiData.tmpRect; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = height; if (tmpRect.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; SelectableTextList.scrollOffset += (int)GuiData.getMouseWheelScroll(); SelectableTextList.scrollOffset = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0))); } else if (GuiData.hot == myID) { GuiData.hot = -1; } int num3 = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0))); if (GuiData.hot == myID) { for (int index = 0; index < text.Length; ++index) { if ((double)mousePos.Y >= (double)y + (double)index * 18.0 && (double)mousePos.Y <= (double)y + (double)(index + 1) * 18.0 && (double)mousePos.Y < (double)(y + height)) { num1 = index + num3; SelectableTextList.wasActivated = true; } } } if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp()) { lastSelectedIndex = num1; } GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Backing_Color); tmpRect.X += 2; tmpRect.Width -= 4; tmpRect.Y += 2; tmpRect.Height -= 4; GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.Default_Dark_Background_Color); Vector2 position = new Vector2((float)tmpRect.X, (float)tmpRect.Y); tmpRect.Height = 18; for (int index = num3; index < text.Length; ++index) { GuiData.spriteBatch.Draw(Utils.white, tmpRect, lastSelectedIndex == index ? selectedColor.Value : (num1 == index ? GuiData.Default_Unselected_Color : GuiData.Default_Dark_Neutral_Color)); Vector2 scale = GuiData.UITinyfont.MeasureString(text[index]); scale.X = (double)scale.X <= (double)(width - 4) ? 1f : (float)(width - 4) / scale.X; scale.Y = (double)scale.Y <= 18.0 ? 1f : 14f / scale.Y; GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], position, Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.5f); position.Y += 18f; tmpRect.Y += 18; if ((double)position.Y > (double)(y + height - 4)) { break; } } if ((double)text.Length * 18.0 > (double)height) { float num4 = 2f; float num5 = (float)height / ((float)text.Length * 18f) * (float)height; height -= 4; float num6 = (float)-height + (float)(((double)height - (double)num5) * ((double)num3 / (((double)text.Length * 18.0 - (double)height) / 18.0))); tmpRect.X = (int)((double)position.X + (double)width - 3.0 * (double)num4 - 2.0); tmpRect.Y = (int)((double)position.Y + (double)num6 + 2.0); tmpRect.Height = (int)num5; tmpRect.Width = (int)num4; GuiData.spriteBatch.Draw(Utils.white, tmpRect, SelectableTextList.scrollBarColor); } if (lastSelectedIndex != num2) { SelectableTextList.selectionWasChanged = true; } return(lastSelectedIndex); }
public static int doFancyList(int myID, int x, int y, int width, int height, string[] text, int lastSelectedIndex, Color?selectedColor, bool HasDraggableScrollbar = false) { if (!selectedColor.HasValue) { selectedColor = new Color?(GuiData.Default_Selected_Color); } int num1 = -1; SelectableTextList.wasActivated = false; int num2 = lastSelectedIndex; SelectableTextList.selectionWasChanged = false; Vector2 mousePos = GuiData.getMousePos(); Rectangle tmpRect = GuiData.tmpRect; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = height; if (tmpRect.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; SelectableTextList.scrollOffset += (int)GuiData.getMouseWheelScroll(); SelectableTextList.scrollOffset = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0))); } else if (GuiData.hot == myID) { GuiData.hot = -1; } int num3 = Math.Max(0, Math.Min(SelectableTextList.scrollOffset, text.Length - (int)((double)height / 18.0))); float num4 = HasDraggableScrollbar ? 4f : 2f; if (GuiData.hot == myID && (!HasDraggableScrollbar || (double)mousePos.X < (double)(x + width) - 2.0 * (double)num4)) { for (int index = 0; index < text.Length; ++index) { if ((double)mousePos.Y >= (double)y + (double)index * 18.0 && (double)mousePos.Y <= (double)y + (double)(index + 1) * 18.0 && (double)mousePos.Y < (double)(y + height)) { num1 = index + num3; } } } if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp()) { lastSelectedIndex = num1; SelectableTextList.wasActivated = true; } tmpRect.X += 2; tmpRect.Width -= 4; tmpRect.Y += 2; tmpRect.Height -= 4; Vector2 input = new Vector2((float)tmpRect.X, (float)tmpRect.Y); tmpRect.Height = 18; for (int index = num3; index < text.Length; ++index) { GuiData.spriteBatch.Draw(Utils.white, tmpRect, lastSelectedIndex == index ? selectedColor.Value : (num1 == index ? selectedColor.Value * 0.45f : GuiData.Default_Dark_Neutral_Color)); Vector2 scale = GuiData.UITinyfont.MeasureString(text[index]); scale.X = (double)scale.X <= (double)(width - 4) ? 1f : (float)(width - 4) / scale.X; scale.Y = (double)scale.Y <= 18.0 ? 1f : 18f / scale.Y; scale.X = Math.Min(scale.X, scale.Y); scale.Y = Math.Min(scale.X, scale.Y); bool flag = !LocaleActivator.ActiveLocaleIsCJK() && Settings.ActiveLocale != "en-us"; if (flag) { input.Y += 3f; } GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], Utils.ClipVec2ForTextRendering(input), lastSelectedIndex == index ? Color.Black : Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.5f); if (flag) { input.Y -= 3f; } input.Y += 18f; tmpRect.Y += 18; if ((double)input.Y > (double)(y + height - 4)) { break; } } if ((double)text.Length * 18.0 > (double)height) { float num5 = num4; float num6 = (float)height / ((float)text.Length * 18f) * (float)height; height -= 4; float num7 = (float)-height + (float)(((double)height - (double)num6) * ((double)num3 / (((double)text.Length * 18.0 - (double)height) / 18.0))); tmpRect.X = (int)((double)input.X + (double)width - (HasDraggableScrollbar ? 2.0 : 3.0) * (double)num5 - 2.0); tmpRect.Y = (int)((double)input.Y + (double)num7 + 2.0); tmpRect.Height = (int)num6; tmpRect.Width = (int)num5; if (!HasDraggableScrollbar) { GuiData.spriteBatch.Draw(Utils.white, tmpRect, SelectableTextList.scrollBarColor); } else { SelectableTextList.scrollOffset = (int)((double)ScrollBar.doVerticalScrollBar(myID + 101, tmpRect.X, y, tmpRect.Width, height, (int)((double)text.Length * 18.0), (float)num3 * 18f) / 18.0); } } if (lastSelectedIndex != num2) { SelectableTextList.selectionWasChanged = true; } return(lastSelectedIndex); }
public void DoGui(float t) { int num = -1; Color color = this.userScreen.highlightColor; if (dragging != null) { if (GuiData.getKeyboadState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.LeftControl)) { dragging = null; } else { dragging.position = MousePosToNMap(GuiData.getMousePos()); } } lock (this.nodeList) { for (int i = 0; i < this.nodeList.Count; i++) { color = this.userScreen.highlightColor; Vector2 nodeDrawPos2 = this.GetNodeDrawPosDebug(this.nodeList[i].position); if (userScreen.activeSession != null && userScreen.activeSession.ip == nodeList[i].ip) { color = Color.White; } if (Hacknet.Gui.Button.doButton(2000 + i, this.bounds.X + (int)nodeDrawPos2.X, this.bounds.Y + (int)nodeDrawPos2.Y, NetworkMap.NODE_SIZE, NetworkMap.NODE_SIZE, "", new Color?(color), this.nodeCircle)) { if (this.dragging == null) { if (GuiData.getKeyboadState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl)) { dragging = nodeList[i]; } else { this.userScreen.Execute("connect " + this.nodeList[i].ip); } } } if (GuiData.hot == 2000 + i) { num = i; } } } if (num != -1) { try { int i = num; int num3 = i; Vector2 vector = this.GetNodeDrawPosDebug(this.nodeList[num3].position); Vector2 ttpos = new Vector2((float)(this.bounds.X + (int)vector.X + NetworkMap.NODE_SIZE), (float)(this.bounds.Y + (int)vector.Y)); string text = this.nodeList[num3].ip;//getTooltipString(); Vector2 textSize = GuiData.tinyfont.MeasureString(text); userScreen.postFXDrawActions = (Action)System.Delegate.Combine(userScreen.postFXDrawActions, new Action(delegate { GuiData.spriteBatch.Draw(Utils.white, new Rectangle((int)ttpos.X, (int)ttpos.Y, (int)textSize.X, (int)textSize.Y), this.userScreen.netmapToolTipBackground); Hacknet.Gui.TextItem.doFontLabel(ttpos, text, GuiData.tinyfont, new Color?(this.userScreen.netmapToolTipColor), 3.40282347E+38f, 3.40282347E+38f, false); })); } catch (System.Exception ex) { DebugLog.add(ex.ToString()); } } }
public static int doFancyList(int myID, int x, int y, int width, int height, string[] text, int lastSelectedIndex, Color? selectedColor, bool HasDraggableScrollbar = false) { if (!selectedColor.HasValue) selectedColor = GuiData.Default_Selected_Color; var num1 = -1; wasActivated = false; var num2 = lastSelectedIndex; selectionWasChanged = false; var mousePos = GuiData.getMousePos(); var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = height; if (destinationRectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; scrollOffset += (int) GuiData.getMouseWheelScroll(); scrollOffset = Math.Max(0, Math.Min(scrollOffset, text.Length - (int) (height/18.0))); } else if (GuiData.hot == myID) GuiData.hot = -1; var num3 = Math.Max(0, Math.Min(scrollOffset, text.Length - (int) (height/18.0))); var num4 = HasDraggableScrollbar ? 4f : 2f; if (GuiData.hot == myID && (!HasDraggableScrollbar || mousePos.X < x + width - 2.0*num4)) { for (var index = 0; index < text.Length; ++index) { if (mousePos.Y >= y + index*18.0 && mousePos.Y <= y + (index + 1)*18.0 && mousePos.Y < (double) (y + height)) { num1 = index + num3; wasActivated = true; } } } if (num1 != -1 && num1 != lastSelectedIndex && GuiData.mouseLeftUp()) lastSelectedIndex = num1; destinationRectangle.X += 2; destinationRectangle.Width -= 4; destinationRectangle.Y += 2; destinationRectangle.Height -= 4; var position = new Vector2(destinationRectangle.X, destinationRectangle.Y); destinationRectangle.Height = 18; for (var index = num3; index < text.Length; ++index) { GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, lastSelectedIndex == index ? selectedColor.Value : (num1 == index ? selectedColor.Value*0.45f : GuiData.Default_Dark_Neutral_Color)); var scale = GuiData.UITinyfont.MeasureString(text[index]); scale.X = scale.X <= (double) (width - 4) ? 1f : (width - 4)/scale.X; scale.Y = scale.Y <= 18.0 ? 1f : 14f/scale.Y; scale.X = Math.Min(scale.X, scale.Y); scale.Y = Math.Min(scale.X, scale.Y); GuiData.spriteBatch.DrawString(GuiData.UITinyfont, text[index], position, Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.5f); position.Y += 18f; destinationRectangle.Y += 18; if (position.Y > (double) (y + height - 4)) break; } if (text.Length*18.0 > height) { var num5 = num4; var num6 = height/(text.Length*18f)*height; height -= 4; var num7 = -height + (float) ((height - (double) num6)*(num3/((text.Length*18.0 - height)/18.0))); destinationRectangle.X = (int) (position.X + (double) width - (HasDraggableScrollbar ? 2.0 : 3.0)*num5 - 2.0); destinationRectangle.Y = (int) (position.Y + (double) num7 + 2.0); destinationRectangle.Height = (int) num6; destinationRectangle.Width = (int) num5; if (!HasDraggableScrollbar) GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, scrollBarColor); else scrollOffset = (int) (ScrollBar.doVerticalScrollBar(myID + 101, destinationRectangle.X, y, destinationRectangle.Width, height, (int) (text.Length*18.0), num3*18f)/18.0); } if (lastSelectedIndex != num2) selectionWasChanged = true; return lastSelectedIndex; }
public static Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height, float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX, float xMax, float yMax, float xMin, float yMin) { isDragging = false; if (!selectedColor.HasValue) { selectedColor = GuiData.Default_Selected_Color; } if (!deselectedColor.HasValue) { deselectedColor = GuiData.Default_Unselected_Color; } var vector2 = GuiData.temp; vector2.X = 0.0f; vector2.Y = 0.0f; var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = (int)x; destinationRectangle.Y = (int)y; destinationRectangle.Width = width; destinationRectangle.Height = height; var rectangle = GuiData.tmpRect; rectangle.X = (int)(x + (double)selectableBorder); rectangle.Y = (int)(y + (double)selectableBorder); rectangle.Width = selectableBorder == -1.0 ? 0 : (int)(width - 2.0 * selectableBorder); rectangle.Height = selectableBorder == -1.0 ? 0 : (int)(height - 2.0 * selectableBorder); if (destinationRectangle.Contains(GuiData.getMousePoint()) && !rectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; if (GuiData.active != myID && GuiData.mouseWasPressed()) { GuiData.active = myID; originalClickPos = GuiData.getMousePos(); originalClickPos.X -= x; originalClickPos.Y -= y; originalClickOffset = new Vector2(originalClickPos.X - x, originalClickPos.Y - y); } } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.active == myID) { if (GuiData.mouseLeftUp()) { GuiData.active = -1; } else { if (canMoveX) { vector2.X = GuiData.mouse.X - x - originalClickPos.X; vector2.X = Math.Min(Math.Max(destinationRectangle.X + vector2.X, xMin), xMax) - destinationRectangle.X; } if (canMoveY) { vector2.Y = GuiData.mouse.Y - y - originalClickPos.Y; vector2.Y = Math.Min(Math.Max(destinationRectangle.Y + vector2.Y, yMin), yMax) - destinationRectangle.Y; } destinationRectangle.X += (int)vector2.X; destinationRectangle.Y += (int)vector2.Y; isDragging = true; } } if (GuiData.active == myID || GuiData.hot == myID) { GuiData.blockingInput = true; } GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value); return(vector2); }