Skip to content

Commit

Permalink
💎 v0.2.0.1, tml 0.10 compatible
Browse files Browse the repository at this point in the history
Fixed some cloning issues with jopo,
migrated mod to work with tml 0.10.0.1
  • Loading branch information
Jofairden committed Jun 10, 2017
1 parent d46dbbe commit 375f154
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 88 deletions.
46 changes: 24 additions & 22 deletions DeconGlobalItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
Expand All @@ -7,33 +8,34 @@ namespace TheDeconstructor
{
internal class DeconGlobalItem : GlobalItem
{
public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
public bool addValueTooltip = false;

public override void NetSend(Item item, BinaryWriter writer)
{
var info = item.GetModInfo<DeconItemInfo>(mod);
if (info.addValueTooltip)
{
var tt = tooltips.FirstOrDefault(x=>
x.mod.Equals("Terraria", System.StringComparison.OrdinalIgnoreCase)
&& x.Name.Equals("ItemName", System.StringComparison.OrdinalIgnoreCase));
if (tt != null)
{
string value = new ItemValue().SetFromCopperValue(item.value * item.stack).ToSellValue().ToTagString();
//tooltips[0].text = $"[i/s1:{item.type}]{tooltips[0].text}";
//tooltips.Insert(1, new TooltipLine(mod, $"{mod.Name}: ValueTooltip", $"{value}"));
tooltips[0].text += value == "[No value]" ? $" {value}" : value;
}
}
writer.Write(addValueTooltip);
}
}

internal class DeconItemInfo : ItemInfo
{
public bool addValueTooltip = false;
public override void NetReceive(Item item, BinaryReader reader)
{
item.GetGlobalItem<DeconGlobalItem>(mod).addValueTooltip = reader.ReadBoolean();
}

public override ItemInfo Clone()
public override bool CloneNewInstances => true;
public override bool InstancePerEntity => true;

public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
{
var clone = new DeconItemInfo { addValueTooltip = this.addValueTooltip };
return clone;
if (!addValueTooltip) return;
var tt = tooltips.FirstOrDefault(x=>
x.mod.Equals("Terraria", System.StringComparison.OrdinalIgnoreCase)
&& x.Name.Equals("ItemName", System.StringComparison.OrdinalIgnoreCase));
if (tt != null)
{
string value = new ItemValue().SetFromCopperValue(item.value * item.stack).ToSellValue().ToTagString();
//tooltips[0].text = $"[i/s1:{item.type}]{tooltips[0].text}";
//tooltips.Insert(1, new TooltipLine(mod, $"{mod.Name}: ValueTooltip", $"{value}"));
tooltips[0].text += value == "[No value]" ? $" {value}" : value;
}
}
}
}
40 changes: 17 additions & 23 deletions Items/Cube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameContent.NetModules;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;

Expand Down Expand Up @@ -53,22 +55,20 @@ public override void NetRecieve(BinaryReader reader)
public override bool CloneNewInstances =>
true;

public override void SetStaticDefaults()
{
DisplayName.SetDefault("Cube");
Main.RegisterItemAnimation(item.type, new DrawAnimationVertical(5, 8));
ItemID.Sets.ItemNoGravity[item.type] = true;
}

public override void SetDefaults()
{
item.name = "Cube";
item.rare = 9;
item.maxStack = 1;
item.value = 1;
item.width = 20;
item.height = 28;
ItemID.Sets.ItemNoGravity[item.type] = true;
}

public override DrawAnimation GetAnimation()
{
// tiles are drawn every 5 frames, dont go below 5 ticks per frame
// so that the tile can draw the cubes at the same interval
return new DrawAnimationVertical(5, 8);
}

public virtual TagCompound CubeSave()
Expand Down Expand Up @@ -192,8 +192,8 @@ public virtual void NotifyLoss(int type, int stack)
{
string str = $"[i/s1:{type}] (x{stack}) was lost!";
Main.NewText(str, 255);
if (Main.netMode == NetmodeID.MultiplayerClient)
NetMessage.SendData(MessageID.ChatText, -1, -1, str, 255);
//if (Main.netMode == NetmodeID.MultiplayerClient)
// NetMessage.SendData(MessageID.ChatText, -1, -1, NetworkText.Empty, 255);
}

public override void ModifyTooltips(List<TooltipLine> tooltips)
Expand Down Expand Up @@ -230,7 +230,7 @@ public override void ModifyTooltips(List<TooltipLine> tooltips)
&& !SealedSource.IsAir)
{
tooltips.Add(new TooltipLine(mod, $"{mod.Name}: LunarCube: Source",
$"Sealed item:[i/s1:{SealedSource.type}][c/{SealedSource.GetTooltipColor().ToHexString().Substring(1)}:{SealedSource.name} ](x{SealedSource.stack})"));
$"Sealed item:[i/s1:{SealedSource.type}][c/{SealedSource.GetTooltipColor().ToHexString().Substring(1)}:{SealedSource.Name} ](x{SealedSource.stack})"));
}

// Contents
Expand All @@ -241,7 +241,7 @@ public override void ModifyTooltips(List<TooltipLine> tooltips)
{
if (!infoBagItem.IsAir)
tooltips.Add(new TooltipLine(mod, $"{mod.Name}: LunarCube: Content: {infoBagItem.type}",
$"[i/s1:{infoBagItem.type}][c/{infoBagItem.GetTooltipColor().ToHexString().Substring(1)}:{infoBagItem.name} ](x{infoBagItem.stack})"));
$"[i/s1:{infoBagItem.type}][c/{infoBagItem.GetTooltipColor().ToHexString().Substring(1)}:{infoBagItem.Name} ](x{infoBagItem.stack})"));
}
}

Expand All @@ -250,17 +250,11 @@ public override void ModifyTooltips(List<TooltipLine> tooltips)
/// <summary>
/// How our cube item is cloned
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public virtual Cube CubeClone<T>() where T : Cube, new()
public override ModItem Clone()
{
Cube clone = new T
{
SealedSource = (Item)this.SealedSource.Clone(),
SealedItems = new List<Item>(this.SealedItems),
CanFail = this.CanFail,
State = this.State
};
Cube clone = (Cube)MemberwiseClone();
clone.SealedSource = (Item)SealedSource.Clone();
clone.SealedItems = new List<Item>(SealedItems.Select(x => x.Clone()));
return clone;
}

Expand Down
12 changes: 9 additions & 3 deletions Items/Deconstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ namespace TheDeconstructor.Items
{
internal sealed class Deconstructor : ModItem
{
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
DisplayName.SetDefault("Lunar Deconsructor");
Tooltip.SetDefault("Can seal an item to return it to it's former state, for a price" +
"\nMaterials will be put into a sealed Lunar Cube");
}


public override void SetDefaults()
{
item.name = "Lunar Deconstructor";
item.toolTip = "Can seal an item to return it to it's former state, for a price";
item.toolTip2 = "Materials will be put into a sealed Lunar Cube";
item.useStyle = 1;
item.useTurn = true;
item.useAnimation = 15;
Expand Down
9 changes: 3 additions & 6 deletions Items/LunarCube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ namespace TheDeconstructor.Items
{
internal sealed class LunarCube : Cube
{
public override void SetDefaults()
public override void SetStaticDefaults()
{
base.SetDefaults();
item.name = "Lunar Cube";
base.SetStaticDefaults();
DisplayName.SetDefault("Lunar Cube");
}

public override ModItem Clone() =>
CubeClone<LunarCube>();

public override Color? GetAlpha(Color lightColor) =>
CubeColor<LunarCube>();

Expand Down
12 changes: 5 additions & 7 deletions Items/QueerLunarCube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ namespace TheDeconstructor.Items
{
internal sealed class QueerLunarCube : Cube
{
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
public override string Texture => $"{mod.Name}/Items/LunarCube";

public override void SetStaticDefaults()
{
texture = $"{mod.Name}/Items/LunarCube";
return base.Autoload(ref name, ref texture, equips);
base.SetStaticDefaults();
DisplayName.SetDefault("Queer Lunar Cube");
}

public override void SetDefaults()
{
base.SetDefaults();
item.name = "Queer Lunar Cube";
item.rare = 10;
}

public override ModItem Clone()
=> CubeClone<QueerLunarCube>();

public override Color? GetAlpha(Color lightColor) =>
CubeColor<QueerLunarCube>();

Expand Down
13 changes: 5 additions & 8 deletions TheDeconstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ public override void Load()
deconUI.SetState(deconGUI);
}

/// <summary>
/// Insert our UI layer between vanilla layers
/// </summary>
/// <param name="layers"></param>
public override void ModifyInterfaceLayers(List<MethodSequenceListItem> layers)

public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int insertLayer = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
if (insertLayer != -1)
{
layers.Insert(insertLayer, new MethodSequenceListItem($"{instance.Name}: UI",
layers.Insert(insertLayer, new LegacyGameInterfaceLayer($"{instance.Name}: UI",
delegate
{
if (deconGUI.visible)
Expand All @@ -57,11 +54,11 @@ public override void ModifyInterfaceLayers(List<MethodSequenceListItem> layers)
}
return true;
},
null));
InterfaceScaleType.UI));
}

insertLayer = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Interact Item Icon"));
layers[insertLayer].Skip = insertLayer != -1 && deconGUI.visible && deconGUI.IsMouseHovering;
layers[insertLayer].Active = !(insertLayer != -1 && deconGUI.visible && deconGUI.IsMouseHovering);
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions TheDeconstructor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\My Games\Terraria\ModLoader\Mod Sources\Mharadium\bin\Debug\Microsoft.Xna.Framework.Xact.dll</HintPath>
</Reference>
<Reference Include="ReLogic">
<HintPath>..\..\..\..\..\GitHub\tModLoader\references\ReLogic.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -54,9 +57,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="tModLoaderDebug, Version=1.3.4.4, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Terraria\tModLoaderDebug.exe</HintPath>
<Reference Include="Terraria">
<HintPath>..\..\..\..\..\..\..\Apps\Steam\steamapps\common\Terraria\Terraria.exe</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -107,7 +109,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>"C:\Program Files (x86)\Steam\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
<PostBuildEvent>"D:\Apps\Steam\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 5 additions & 2 deletions Tiles/Deconstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Terraria.DataStructures;
using Terraria.Enums;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ObjectData;
using TheDeconstructor.Items;
Expand Down Expand Up @@ -63,7 +64,7 @@ public override int Hook_AfterPlacement(int i, int j, int type, int style, int d
return Place(i, j);
// Multiplayer
NetMessage.SendTileSquare(Main.myPlayer, i, j, 4, TileChangeType.None);
NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, "", i, j, Type, 0f, 0, 0, 0);
NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, NetworkText.Empty ,i, j, Type, 0f, 0, 0, 0);
return -1;
}
}
Expand Down Expand Up @@ -91,7 +92,9 @@ public override void SetDefaults()
TileObjectData.newTile.DrawYOffset = 2;
TileObjectData.addTile(Type);
AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
AddMapEntry(new Color(50, 50, 50), "Lunar Deconstructor");
ModTranslation name = CreateMapEntryName();
name.SetDefault("The Deconstructor");
AddMapEntry(new Color(50, 50, 50), name);

disableSmartCursor = true;
}
Expand Down
10 changes: 5 additions & 5 deletions UI/ItemPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ protected override void DrawSelf(SpriteBatch spriteBatch)
drawColor = this.item.GetAlpha(Color.White);
if (base.IsMouseHovering)
{
Main.hoverItemName = item.name;
Main.toolTip = item.Clone();
Main.toolTip.GetModInfo<DeconItemInfo>(TheDeconstructor.instance).addValueTooltip = true;
Main.hoverItemName = item.Name;
Main.HoverItem = item.Clone();
Main.HoverItem.GetGlobalItem<DeconGlobalItem>(TheDeconstructor.instance).addValueTooltip = true;
//ItemValue value = new ItemValue().SetFromCopperValue(item.value*item.stack);
Main.toolTip.name =
$"{Main.toolTip.name}{Main.toolTip.modItem?.mod.Name.Insert((int)Main.toolTip.modItem?.mod.Name.Length, "]").Insert(0, " [")}";
Main.HoverItem.SetNameOverride(
$"{Main.HoverItem.Name}{Main.HoverItem.modItem?.mod.Name.Insert((int) Main.HoverItem.modItem?.mod.Name.Length, "]").Insert(0, " [")}");
}
}

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 = jofairden
version = 0.3
version = 0.2.0.1
displayName = Lunar Deconstructor
homepage = https://forums.terraria.org/index.php?threads/.55904/
hideCode = true
Expand Down
8 changes: 4 additions & 4 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Changelog from 0.2 to 0.3

General
Changelog from 0.2 to 0.2.0.1


General
Updated mod for tml v0.10.0.1
Fixed cloning issues (thanks jopo)

Changelog from 0.1.1 to 0.2

Expand Down
8 changes: 5 additions & 3 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Queer Lunar Cubes are recognizable by their morphing colors.
The Lunar Deconstructor will show which cube is currently being handled (when one is put into the UI that is)
Mod comes with fitting sound effects.

Changelog from 0.2 to 0.3

General
Changelog from 0.2 to 0.2.0.1

General
Updated mod for tml v0.10.0.1
Fixed cloning issues (thanks jopo)

0 comments on commit 375f154

Please sign in to comment.