Skip to content

Commit

Permalink
0.2.0.2 release, resizeable ui
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Jun 23, 2017
1 parent a174e43 commit 96ae5a3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
1 change: 1 addition & 0 deletions RecipeBrowserPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public override void ProcessTriggers(TriggersSet triggersSet)
if (RecipeBrowser.instance.ToggleRecipeBrowserHotKey.JustPressed)
{
RecipeBrowser.instance.recipeBrowserTool.visible = !RecipeBrowser.instance.recipeBrowserTool.visible;
// Debug assistance, allows for reinitializing RecipeBrowserUI
//if (!RecipeBrowser.instance.recipeBrowserTool.visible)
//{
// RecipeBrowserUI.instance.RemoveAllChildren();
Expand Down
8 changes: 5 additions & 3 deletions RecipeBrowserUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RecipeBrowserUI(UserInterface ui) : base(ui)

public override void OnInitialize()
{
mainPanel = new UIDragablePanel();
mainPanel = new UIDragablePanel(true);
mainPanel.SetPadding(6);
mainPanel.Left.Set(400f, 0f);
mainPanel.Top.Set(400f, 0f);
Expand Down Expand Up @@ -143,7 +143,9 @@ public override void OnInitialize()
inlaidPanel.Top.Pixels = 60;
//inlaidPanel.Width.Set(-25f, 1f);
inlaidPanel.Width.Set(0, 1f);
inlaidPanel.Height.Set(155, 0f);
//inlaidPanel.Height.Set(155, 0f);
// Use to be 155, now is 100% minus top minus what is below.
inlaidPanel.Height.Set(-60 - 121, 1f);
inlaidPanel.BackgroundColor = Color.DarkBlue;
mainPanel.Append(inlaidPanel);

Expand All @@ -165,7 +167,7 @@ public override void OnInitialize()
recipeGrid.SetScrollbar(lootItemsScrollbar);

recipeInfo = new UIRecipeInfo();
recipeInfo.Top.Pixels = 217;
recipeInfo.Top.Set(-118, 1f);
recipeInfo.Width.Set(0, 1f);
recipeInfo.Height.Set(120, 0f);
mainPanel.Append(recipeInfo);
Expand Down
67 changes: 57 additions & 10 deletions UIElements/UIDragablePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.Graphics;
using Terraria.UI;

namespace RecipeBrowser
{
class UIDragablePanel : UIPanel
{
Vector2 offset;
bool dragging = false;
private static Texture2D dragTexture;
private Vector2 offset;
private bool dragging;
private bool resizeing;
private bool resizeable;

public UIDragablePanel()
public UIDragablePanel(bool resizeable = false)
{
OnMouseDown += DragStart;
OnMouseUp += DragEnd;
this.resizeable = resizeable;
if (dragTexture == null)
{
dragTexture = TextureManager.Load("Images/UI/PanelBorder");
}
}

//public override void MouseDown(UIMouseEvent evt)
Expand All @@ -36,29 +45,39 @@ public UIDragablePanel()

private void DragStart(UIMouseEvent evt, UIElement listeningElement)
{
CalculatedStyle innerDimensions = GetInnerDimensions();
if (evt.Target == this || evt.Target == RecipeBrowserUI.instance.recipeInfo || evt.Target == RecipeBrowserUI.instance.RadioButtonGroup)
{
offset = new Vector2(evt.MousePosition.X - Left.Pixels, evt.MousePosition.Y - Top.Pixels);
dragging = true;
if (new Rectangle((int)(innerDimensions.X + innerDimensions.Width - 12), (int)(innerDimensions.Y + innerDimensions.Height - 12), 12 + 6, 12 + 6).Contains(evt.MousePosition.ToPoint()))
{
offset = new Vector2(evt.MousePosition.X - innerDimensions.X - innerDimensions.Width - 6, evt.MousePosition.Y - innerDimensions.Y - innerDimensions.Height - 6);
resizeing = true;
}
else
{
offset = new Vector2(evt.MousePosition.X - Left.Pixels, evt.MousePosition.Y - Top.Pixels);
dragging = true;
}
}
}

private void DragEnd(UIMouseEvent evt, UIElement listeningElement)
{
if (evt.Target == this || evt.Target == RecipeBrowserUI.instance.recipeInfo || evt.Target == RecipeBrowserUI.instance.RadioButtonGroup)
{
Vector2 end = evt.MousePosition;
//Vector2 end = evt.MousePosition;
dragging = false;
resizeing = false;

Left.Set(end.X - offset.X, 0f);
Top.Set(end.Y - offset.Y, 0f);

Recalculate();
//Left.Set(end.X - offset.X, 0f);
//Top.Set(end.Y - offset.Y, 0f);
//Recalculate();
}
}

protected override void DrawSelf(SpriteBatch spriteBatch)
{
CalculatedStyle dimensions = base.GetOuterDimensions();
if (ContainsPoint(Main.MouseScreen))
{
Main.LocalPlayer.mouseInterface = true;
Expand All @@ -70,7 +89,35 @@ protected override void DrawSelf(SpriteBatch spriteBatch)
Top.Set(Main.MouseScreen.Y - offset.Y, 0f);
Recalculate();
}
if (resizeing)
{
Height.Pixels = Utils.Clamp(Main.MouseScreen.Y - dimensions.Y - offset.Y, 243, 1000);
//Width.Pixels = Utils.Clamp(Main.MouseScreen.X - dimensions.X - offset.X, 415, 1000);
Recalculate();
}
base.DrawSelf(spriteBatch);
if (resizeable)
{
DrawDragAnchor(spriteBatch, dragTexture, this.BorderColor);
}
}

private void DrawDragAnchor(SpriteBatch spriteBatch, Texture2D texture, Color color)
{
CalculatedStyle dimensions = GetDimensions();
//CalculatedStyle innerDimensions = GetInnerDimensions();

//Rectangle hitbox = new Rectangle((int)(innerDimensions.X + innerDimensions.Width - 12), (int)(innerDimensions.Y + innerDimensions.Height - 12), 12 + 6, 12 + 6);
//Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.LightBlue * 0.6f);

Point point = new Point((int)dimensions.X, (int)dimensions.Y);
Point point2 = new Point(point.X + (int)dimensions.Width - 12, point.Y + (int)dimensions.Height - 12);
int width = point2.X - point.X - 12;
int height = point2.Y - point.Y - 12;
//spriteBatch.Draw(texture, new Rectangle(point2.X, point2.Y, 12, 12), new Rectangle?(new Rectangle(12 + 4, 12 + 4, 12, 12)), color);
spriteBatch.Draw(texture, new Rectangle(point2.X - 2, point2.Y - 2, 12 - 2, 12 - 2), new Rectangle?(new Rectangle(12 + 4, 12 + 4, 12, 12)), color);
spriteBatch.Draw(texture, new Rectangle(point2.X - 4, point2.Y - 4, 12 - 4, 12 - 4), new Rectangle?(new Rectangle(12 + 4, 12 + 4, 12, 12)), color);
spriteBatch.Draw(texture, new Rectangle(point2.X - 6, point2.Y - 6, 12 - 6, 12 - 6), new Rectangle?(new Rectangle(12 + 4, 12 + 4, 12, 12)), color);
}
}
}
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = jopojelly
version = 0.2.0.1
version = 0.2.0.2
displayName = Recipe Browser
homepage = http://forums.terraria.org/index.php?threads/cheat-sheet.41407/
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, unused\*
Expand Down

0 comments on commit 96ae5a3

Please sign in to comment.