Skip to content

Commit

Permalink
v0.12, Background Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Mar 9, 2019
1 parent 42d0183 commit d6f42d2
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ModdersToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public override void Load()
tools.Add(new Tools.Textures.TextureTool());
// Not ready yet tools.Add(new Tools.Loot.LootTool());
tools.Add(new Tools.UIPlayground.UIPlaygroundTool());
tools.Add(new Tools.Backgrounds.BackgroundsTool());
tools.Add(new Tools.Miscellaneous.MiscellaneousTool());

tools.ForEach(tool => tool.Initialize());
Expand Down Expand Up @@ -152,7 +153,7 @@ internal void DrawUpdateToggles()
{
Point mousePoint = new Point(Main.mouseX, Main.mouseY);
// calculate?
int xPosition = Main.screenWidth - 210; //62; //78;
int xPosition = Main.screenWidth - 230; //62; //78;
int yPosition = Main.screenHeight - 36 + 10 - 25;

// TODO, use UI/Settings_Toggle
Expand Down
2 changes: 2 additions & 0 deletions ModdersToolkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="ModdersToolkit.cs" />
<Compile Include="Tools\Backgrounds\BackgroundsTool.cs" />
<Compile Include="Tools\Backgrounds\BackgroundsUI.cs" />
<Compile Include="Tools\Dusts\DataRangeProperty.cs" />
<Compile Include="Tools\Dusts\DustChooserUI.cs" />
<Compile Include="Tools\Dusts\DustTool.cs" />
Expand Down
81 changes: 81 additions & 0 deletions Tools/Backgrounds/BackgroundsTool.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.Backgrounds
{
class BackgroundsTool : Tool
{
internal static BackgroundsUI backgroundsUI;
internal override void Initialize()
{
toggleTooltip = "Click to toggle Background Tool";
}

internal override void ClientInitialize()
{
userInterface = new UserInterface();
backgroundsUI = new BackgroundsUI(userInterface);
backgroundsUI.Activate();
userInterface.SetState(backgroundsUI);
}

internal override void UIDraw()
{
if (visible)
{
backgroundsUI.Draw(Main.spriteBatch);
}
}
}

class BackgroundsToolGlobalBgStyle : GlobalBgStyle
{
public override void ChooseSurfaceBgStyle(ref int style)
{
if (Main.gameMenu)
return;
int choice = BackgroundsTool.backgroundsUI.surfaceBgStyleDataProperty.Data;
if (choice > -1)
style = choice;

if(BackgroundsTool.backgroundsUI.quickChangeCheckbox.Selected)
Main.quickBG = 10;
}

public override void ChooseUgBgStyle(ref int style)
{
if (Main.gameMenu)
return;
int choice = BackgroundsTool.backgroundsUI.undergroundBgStyleDataProperty.Data;
if (choice > -1)
style = choice;

if (BackgroundsTool.backgroundsUI.quickChangeCheckbox.Selected)
Main.quickBG = 10;
}

public override void FillUgTextureArray(int style, int[] textureSlots)
{
if (Main.gameMenu)
return;
for (int i = 0; i < 7; i++)
{
var data = BackgroundsTool.backgroundsUI.undergroundTextureDataProperties[i].Data;
if (data > -1)
textureSlots[i] = data;
}
}

public override void ModifyFarSurfaceFades(int style, float[] fades, float transitionSpeed)
{
base.ModifyFarSurfaceFades(style, fades, transitionSpeed);
}
}
}
98 changes: 98 additions & 0 deletions Tools/Backgrounds/BackgroundsUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ModdersToolkit.UIElements;
using System.Reflection;
using Terraria;
using Terraria.GameContent.UI.Elements;
using Terraria.ModLoader;
using Terraria.UI;

namespace ModdersToolkit.Tools.Backgrounds
{
class BackgroundsUI : UIState
{
internal UIPanel mainPanel;
private UserInterface userInterface;

internal UICheckbox quickChangeCheckbox;
internal UIIntRangedDataValue surfaceBgStyleDataProperty;
internal UIIntRangedDataValue undergroundBgStyleDataProperty;
internal UIIntRangedDataValue[] undergroundTextureDataProperties;
//internal UIIntRangedDataValue undergroundTexture0DataProperty;
//internal UIIntRangedDataValue undergroundTexture1DataProperty;
//internal UIIntRangedDataValue undergroundTexture2DataProperty;
//internal UIIntRangedDataValue undergroundTexture3DataProperty;
//internal UIIntRangedDataValue undergroundTexture4DataProperty;
//internal UIIntRangedDataValue undergroundTexture5DataProperty;
//internal UIIntRangedDataValue undergroundTexture6DataProperty;

public BackgroundsUI(UserInterface userInterface)
{
this.userInterface = userInterface;
}

public override void OnInitialize()
{
mainPanel = new UIPanel();
mainPanel.SetPadding(6);
int width = 350;
int height = 340;
mainPanel.Left.Set(-40f - width, 1f);
mainPanel.Top.Set(-110f - height, 1f);
mainPanel.Width.Set(width, 0f);
mainPanel.Height.Set(height, 0f);
mainPanel.BackgroundColor = new Color(173, 94, 171);
Append(mainPanel);

UIText text = new UIText("Backgrounds:", 0.85f);
text.Top.Set(12f, 0f);
text.Left.Set(12f, 0f);
mainPanel.Append(text);

int nextSurfaceBgStyle = (int)typeof(SurfaceBgStyleLoader).GetField("nextSurfaceBgStyle", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
int nextUndergroundBgStyle = (int)typeof(UgBgStyleLoader).GetField("nextUgBgStyle", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
int nextBackground = (int)typeof(BackgroundTextureLoader).GetField("nextBackground", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

int top = 12;

top += 20;
quickChangeCheckbox = new UICheckbox("Quick Change", "Bypass background fade");
quickChangeCheckbox.Top.Set(top, 0f);
mainPanel.Append(quickChangeCheckbox);

top += 30;
surfaceBgStyleDataProperty = new UIIntRangedDataValue("SurfaceBgStyle:", -1, -1, nextSurfaceBgStyle - 1, true, true);
UIElement uiRange = new UIRange<int>(surfaceBgStyleDataProperty);
uiRange.Top.Set(top, 0f);
uiRange.Width.Set(0, 1f);
mainPanel.Append(uiRange);

top += 30;
undergroundBgStyleDataProperty = new UIIntRangedDataValue("UgBgStyle:", -1, -1, nextUndergroundBgStyle - 1, true, true);
uiRange = new UIRange<int>(undergroundBgStyleDataProperty);
uiRange.Top.Set(top, 0f);
uiRange.Width.Set(0, 1f);
mainPanel.Append(uiRange);

undergroundTextureDataProperties = new UIIntRangedDataValue[7];
for (int i = 0; i < 7; i++)
{
top += 30;
// TODO: Show names of Mod added Styles and slots
undergroundTextureDataProperties[i] = new UIIntRangedDataValue($"Ug Texture {i}:", -1, -1, nextBackground - 1, true, true);
uiRange = new UIRange<int>(undergroundTextureDataProperties[i]);
uiRange.Top.Set(top, 0f);
uiRange.Width.Set(0, 1f);
mainPanel.Append(uiRange);
}
}

protected override void DrawSelf(SpriteBatch spriteBatch)
{
if (mainPanel.ContainsPoint(Main.MouseScreen))
{
Main.LocalPlayer.mouseInterface = true;
}
}
}
}
2 changes: 2 additions & 0 deletions Tools/UIPlayground/UIPlaygroundTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace ModdersToolkit.Tools.UIPlayground
{
class UIPlaygroundTool : Tool
{
// TODO: Parallax to teach nesting

internal static UIPlaygroundUI uiPlaygroundUI;

internal override void Initialize()
Expand Down
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.11
version = 0.12
versionScheme = major when done, minor when new tool, build when new item within tool, revision for bug fix quick release
displayName = Modders Toolkit
homepage = https://forums.terraria.org/index.php?threads/modders-toolkit-a-mod-for-modders-doing-modding.55738/
Expand Down
1 change: 1 addition & 0 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Current Tools
-NPC Spawn Calculator
-Texture updating/editing tool
-UI Playground
-Background Tool
-Miscellaneous (NPC info, tile grid, chunk calculator)

Planned Tools
Expand Down

0 comments on commit d6f42d2

Please sign in to comment.