Skip to content

Commit

Permalink
0.1.1 release, dust tool
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Mar 20, 2017
1 parent c56075c commit cf525d1
Show file tree
Hide file tree
Showing 18 changed files with 1,013 additions and 33 deletions.
15 changes: 15 additions & 0 deletions ModdersToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override void Load()
tools = new List<Tool>();
tools.Add(new Tools.REPL.REPLTool());
tools.Add(new Tools.Hitboxes.HitboxesTool());
tools.Add(new Tools.Dusts.DustTool());

tools.ForEach(tool => tool.Initialize());

Expand All @@ -34,6 +35,11 @@ public override void Load()
}
}

public override void PostSetupContent()
{
tools.ForEach(tool => tool.PostSetupContent());
}


public override void ModifyInterfaceLayers(List<MethodSequenceListItem> layers)
{
Expand Down Expand Up @@ -80,6 +86,7 @@ internal void DrawUpdateToggles()
int xPosition = Main.screenWidth - 190; //62; //78;
int yPosition = Main.screenHeight - 36 + 10;

// TODO, use UI/Settings_Toggle
Texture2D toggleTexture = visible ? Main.inventoryTickOnTexture : Main.inventoryTickOffTexture;

Rectangle toggleToolkitButtonRectangle = new Rectangle(xPosition, yPosition, toggleTexture.Width, toggleTexture.Height);
Expand Down Expand Up @@ -116,6 +123,14 @@ internal void DrawUpdateToggles()
toggleToolkitButtonHover = true;
if (Main.mouseLeft && Main.mouseLeftRelease)
{
foreach (var otherTool in tools)
{
if(tool != otherTool && otherTool.visible)
{
otherTool.visible = false;
otherTool.Toggled();
}
}
tool.visible = !tool.visible;
Main.PlaySound(tool.visible ? SoundID.MenuOpen : SoundID.MenuClose);
tool.Toggled();
Expand Down
9 changes: 8 additions & 1 deletion ModdersToolkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E555C67A-5195-412B-8BBB-E2B0F12D7396}</ProjectGuid>
<ProjectGuid>{7B5C574E-3759-45FE-9468-7F2A60EBB23D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModdersToolkit</RootNamespace>
Expand Down Expand Up @@ -72,6 +72,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ModdersToolkit.cs" />
<Compile Include="Tools\Dusts\DataRangeProperty.cs" />
<Compile Include="Tools\Dusts\DustTool.cs" />
<Compile Include="Tools\Dusts\DustUI.cs" />
<Compile Include="Tools\Hitboxes\HitboxesTool.cs" />
<Compile Include="Tools\Hitboxes\HitboxesUI.cs" />
<Compile Include="Tools\REPL\REPLTool.cs" />
Expand All @@ -82,6 +85,10 @@
<Compile Include="Tools\Tool.cs" />
<Compile Include="UIElements\UICheckbox.cs" />
<Compile Include="UIElements\UICodeEntry.cs" />
<Compile Include="UIElements\UIRadioButton.cs" />
<Compile Include="UIElements\UIRadioButtonGroup.cs" />
<Compile Include="UIElements\UIRange.cs" />
<Compile Include="UIElements\UISlider.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="build.txt" />
Expand Down
133 changes: 133 additions & 0 deletions Tools/Dusts/DataRangeProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using Microsoft.Xna.Framework;
using ModdersToolkit.UIElements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terraria;

namespace ModdersToolkit.Tools.Dusts
{
class FloatDataRangeProperty
{
internal float min = 0f;
internal float max = 5f;
private float data = 1f;
internal float Data
{
get { return data; }
set
{
data = value;
range.input.SetText(data.ToString("0.00"));
}
}

public UIRange range;

public FloatDataRangeProperty(string label, float defaultValue, float min, float max)
{
data = defaultValue;
this.min = min;
this.max = max;
range = new UIRange(label, () => (Data - min) / (max - min), (s) => { Data = (s * (max - min) + min); }, ValidateInput);
//range.Top.Set(top, 0f);
range.Width.Set(0, 1f);
Data = data;
}

private void ValidateInput()
{
float result;
if (float.TryParse(range.input.Text, out result))
{
Data = result;
}
else
{
Data = data;
}
}
}

class IntDataRangeProperty
{
internal int max = 5;
private int data = 1;
internal int Data
{
get { return data; }
set
{
data = value;
range.input.SetText(data.ToString());
}
}

public UIRange range;

public IntDataRangeProperty(string label, int defaultValue, int max, bool fine = false)
{
data = defaultValue;
this.max = max;
range = new UIRange(label, () => (float)Data / max, (s) => { Data = (int)(s * max); }, ValidateInput, fine);
range.intDataRangeProperty = this;
//range.Top.Set(top, 0f);
range.Width.Set(0, 1f);
Data = data;
}

private void ValidateInput()
{
int result;
if (int.TryParse(range.input.Text, out result))
{
Data = result;
}
else
{
Data = data;
}
}
}

class ColorDataRangeProperty
{
private Color data = Color.White;
internal Color Data
{
get { return data; }
set
{
data = value;
//range.input.SetText($"{data.R}-{data.G}-{data.B}");
range.input.SetText(data.Hex3());
}
}

public UIRange range;

public ColorDataRangeProperty(string label)
{
//Main.hslToRgb(amount, 1f, 0.5f)
range = new UIRange(label, () => Main.rgbToHsl(Data).X, (s) => { Data = Main.hslToRgb(s, 1f, 0.5f); }, ValidateInput);
range.Width.Set(0, 1f);
range.slider.SetHueMode(true);
Data = data;
}

private void ValidateInput()
{
//int result;
//if (int.TryParse(range.input.Text, out result))
//{
// Data = result;
//}
//else
//{
// Data = data;
//}
Data = data;
}
}
}
81 changes: 81 additions & 0 deletions Tools/Dusts/DustTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ModLoader;
using Terraria.UI;

namespace ModdersToolkit.Tools.Dusts
{
class DustTool : Tool
{
//internal static UserInterface userInterface;
internal static DustUI dustUI;
internal override void Initialize()
{
toggleTooltip = "Click to toggle Dust Tool";
}

// should ui even initialize during load? are static members nulled out on reload?
internal override void ClientInitialize()
{
userInterface = new UserInterface();
//dustUI = new DustUI(userInterface);
//dustUI.Activate();
//userInterface.SetState(dustUI);
}
//internal override void ScreenResolutionChanged()
//{
// userInterface.Recalculate();
//}
//internal override void UIUpdate()
//{
// if (visible)
// {
// userInterface.Update(Main._drawInterfaceGameTime);
// }
//}
internal override void UIDraw()
{
if (visible)
{
dustUI.Draw(Main.spriteBatch);
//if (showProjectileHitboxes) drawProjectileHitboxes();
}
}

internal static int shaderCount;
internal static int dustCount;
internal override void PostSetupContent()
{
if (!Main.dedServ)
{
int count = 0;
ArmorShaderData shader;
do
{
shader = GameShaders.Armor.GetSecondaryShader(count + 1, Main.LocalPlayer);
count++;
} while (shader != null);
shaderCount = count - 1;

count = Terraria.ID.DustID.Count;
ModDust dust;
while (true)
{
dust = ModDust.GetDust(count);
if (dust == null) break;
count++;
}
dustCount = count;

dustUI = new DustUI(userInterface);
dustUI.Activate();
userInterface.SetState(dustUI);
}
}
}
}
Loading

0 comments on commit cf525d1

Please sign in to comment.