Skip to content

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MrQuba committed Apr 30, 2024
1 parent d64108c commit ead814a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 36 deletions.
69 changes: 46 additions & 23 deletions Content/Keystroke.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.ModLoader;
using Terraria.UI;

namespace Keystrokes.Content
Expand All @@ -9,31 +12,39 @@ namespace Keystrokes.Content
// https://forums.terraria.org/index.php?threads/terraria-interface-for-dummies.79356/
public class Keystroke : UIState
{
public static bool visible;
public static bool visible;
public static Color border = Config.borderColor;
public static Color background = Config.backgroundColor;
public static Color pressedBackground = Config.pressedBackgroundColor;
public UIText text;
public Square sq;
Vector2 left, top, width, height;
Microsoft.Xna.Framework.Input.Keys key;
float t_width;
float t_height;
bool big;

Microsoft.Xna.Framework.Input.Keys key;
/// <summary>
/// Constructor for Keystroke
/// .Y of every Vector2 is percentage
/// </summary>
/// <param name="left">.X - distance from left side of the screen</param>
/// <param name="top">.X - distance from top of the screen</param>
/// <param name="width">.X - width of keystroke</param>
/// <param name="height">.X - height of keystroke</param>
public Keystroke(Microsoft.Xna.Framework.Input.Keys k, Vector2 left, Vector2 top, Vector2 width, Vector2 height)
{
this.key = k;
this.left = left;
this.top = top;
this.width = width;
this.height = height;
}
/// Constructor for Keystroke
/// .Y of every Vector2 is percentage
/// </summary>
/// <param name="left">.X - distance from left side of the screen</param>
/// <param name="top">.X - distance from top of the screen</param>
/// <param name="width">.X - width of keystroke</param>
/// <param name="height">.X - height of keystroke</param>
public Keystroke(Microsoft.Xna.Framework.Input.Keys k, Vector2 left, Vector2 top, Vector2 width, Vector2 height, float t_width, float t_height, bool big)
{
key = k;
this.left = left;
this.top = top;
this.width = width;
this.height = height;
this.t_width = t_width;
this.t_height = t_height;
this.big = big;
}

public override void OnInitialize()
public override void OnInitialize()
{
visible = true;

Expand All @@ -42,14 +53,26 @@ public override void OnInitialize()
sq.Top.Set(top.X, top.Y);
sq.Width.Set(width.X, width.Y);
sq.Height.Set(height.X, height.Y);

Append(sq);
}
public override void Update(GameTime gameTime)
Append(sq);
text = new UIText(key.ToString());
if(big)
{
text.Left.Set(left.X + 0.25f * (sq.Width.Pixels - text.Width.Pixels), left.Y);
}
else
{
text.Left.Set(left.X + 0.02f * (sq.Width.Pixels - text.Width.Pixels), left.Y);
}
text.Top.Set(top.X + 0.25f * (sq.Height.Pixels + text.Height.Pixels), top.Y);
text.Width.Set(t_width, 0f);
text.Height.Set(t_height, 0f);
Append(text);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
sq.Update(gameTime);
if (Main.keyState.IsKeyDown(this.key))
if (Main.keyState.IsKeyDown(key))
{
sq.BackgroundColor = pressedBackground;
}
Expand Down
26 changes: 14 additions & 12 deletions Keystrokes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Keystrokes.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
Expand All @@ -15,6 +16,7 @@ public void KeystrokeInit()
TopInterface = new UserInterface();
TopInterface.SetState(Upkeystroke);


Downkeystroke.Initialize();
BottomInterface = new UserInterface();
BottomInterface.SetState(Downkeystroke);
Expand All @@ -32,24 +34,24 @@ public void KeystrokeInit()
JumpInterface.SetState(Spacekeystroke);
}

internal Keystroke Upkeystroke;
internal Keystroke Upkeystroke;
internal Keystroke Downkeystroke;
internal Keystroke Leftkeystroke;
internal Keystroke Rightkeystroke;
internal Keystroke Spacekeystroke;
public UserInterface TopInterface, BottomInterface, LeftInterface, RightInterface, JumpInterface;

public override void Load()
public override void Load()
{
Config.Load();
if (!Main.dedServ)
{

Upkeystroke = new Keystroke(Config.up, new Vector2(Config.posX + 32, 0), new Vector2(Config.posY + 128, 0), new Vector2(32, 0), new Vector2(32, 0));
Downkeystroke = new Keystroke(Config.down, new Vector2(Config.posX + 32, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0));
Leftkeystroke = new Keystroke(Config.left, new Vector2(Config.posX, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0));
Rightkeystroke = new Keystroke(Config.right, new Vector2(Config.posX + 64, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0));
Spacekeystroke = new Keystroke(Config.jump, new Vector2(Config.posX, 0), new Vector2(Config.posY + 192, 0), new Vector2(96, 0), new Vector2(32, 0));
Upkeystroke = new Keystroke(Config.up, new Vector2(Config.posX + 32, 0), new Vector2(Config.posY + 128, 0), new Vector2(32, 0), new Vector2(32, 0), 32, 32, false);
Downkeystroke = new Keystroke(Config.down, new Vector2(Config.posX + 32, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0), 32, 32, false);
Leftkeystroke = new Keystroke(Config.left, new Vector2(Config.posX, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0), 32, 32, false);
Rightkeystroke = new Keystroke(Config.right, new Vector2(Config.posX + 64, 0), new Vector2(Config.posY + 160, 0), new Vector2(32, 0), new Vector2(32, 0), 32, 32, false);
Spacekeystroke = new Keystroke(Config.jump, new Vector2(Config.posX, 0), new Vector2(Config.posY + 192, 0), new Vector2(96, 0), new Vector2(32, 0), 32, 32, true);
KeystrokeInit();
}
}
Expand All @@ -73,12 +75,12 @@ private bool DrawKeystroke()
&& Keystroke.visible)
{
TopInterface.Draw(Main.spriteBatch, new GameTime());
BottomInterface.Draw(Main.spriteBatch, new GameTime());
LeftInterface.Draw(Main.spriteBatch, new GameTime());
RightInterface.Draw(Main.spriteBatch, new GameTime());
JumpInterface.Draw(Main.spriteBatch, new GameTime());
BottomInterface.Draw(Main.spriteBatch, new GameTime());
LeftInterface.Draw(Main.spriteBatch, new GameTime());
RightInterface.Draw(Main.spriteBatch, new GameTime());
JumpInterface.Draw(Main.spriteBatch, new GameTime());

}
}
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = Keystrokes
author = MrQuba
version = 1.1
version = 1.4
languageVersion = 6

0 comments on commit ead814a

Please sign in to comment.