Skip to content

Commit 21045dd

Browse files
committed
Better word wrap for UIMessageBox + Improved DrawArmorColor hook for items
1 parent 3b97661 commit 21045dd

28 files changed

+395
-95
lines changed

ExampleMod/Items/Armor/BunnyMask.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.Xna.Framework;
4+
using Terraria;
5+
using Terraria.ModLoader;
6+
7+
namespace ExampleMod.Items.Armor
8+
{
9+
public class BunnyMask : ModItem
10+
{
11+
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
12+
{
13+
equips.Add(EquipType.Head);
14+
return true;
15+
}
16+
17+
public override void SetDefaults()
18+
{
19+
item.name = "Bunny Mask";
20+
item.width = 18;
21+
item.height = 18;
22+
item.rare = 1;
23+
item.vanity = true;
24+
}
25+
26+
public override bool DrawHead()
27+
{
28+
return false;
29+
}
30+
}
31+
}

ExampleMod/Items/Armor/BunnyMask.png

448 Bytes
Loading
1.61 KB
Loading
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.Xna.Framework;
4+
using Terraria;
5+
using Terraria.ModLoader;
6+
7+
namespace ExampleMod.Items.Armor
8+
{
9+
public class PuritySpiritMask : ModItem
10+
{
11+
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
12+
{
13+
equips.Add(EquipType.Head);
14+
return true;
15+
}
16+
17+
public override void SetDefaults()
18+
{
19+
item.name = "Spirit of Purity Mask";
20+
item.width = 18;
21+
item.height = 18;
22+
item.rare = 1;
23+
item.vanity = true;
24+
}
25+
26+
public override void DrawArmorColor(Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
27+
{
28+
color = drawPlayer.GetImmuneAlphaPure(Color.White, shadow);
29+
}
30+
}
31+
}
226 Bytes
Loading
864 Bytes
Loading

ExampleMod/Items/CarKey.cs

-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public override void SetDefaults()
1515
item.toolTip = "This is a modded mount.";
1616
item.useTime = 20;
1717
item.useAnimation = 20;
18-
item.pick = 220;
1918
item.useStyle = 1;
20-
item.knockBack = 6;
2119
item.value = 30000;
2220
item.rare = 2;
2321
item.useSound = 79;

ExampleMod/Items/Placeable/AbominationTrophy.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,9 @@ public override void SetDefaults()
2020
item.useStyle = 1;
2121
item.consumable = true;
2222
item.value = 50000;
23+
item.rare = 1;
2324
item.createTile = mod.TileType("BossTrophy");
2425
item.placeStyle = 0;
2526
}
26-
27-
public override void AddRecipes()
28-
{
29-
ModRecipe recipe = new ModRecipe(mod);
30-
recipe.AddIngredient(null, "ExampleBlock", 10);
31-
recipe.SetResult(this);
32-
recipe.AddRecipe();
33-
}
3427
}
3528
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Terraria;
3+
using Terraria.ID;
4+
using Terraria.ModLoader;
5+
6+
namespace ExampleMod.Items.Placeable
7+
{
8+
public class BunnyTrophy : ModItem
9+
{
10+
public override void SetDefaults()
11+
{
12+
item.name = "Bunny Trophy";
13+
item.width = 30;
14+
item.height = 30;
15+
item.maxStack = 99;
16+
item.useTurn = true;
17+
item.autoReuse = true;
18+
item.useAnimation = 15;
19+
item.useTime = 10;
20+
item.useStyle = 1;
21+
item.consumable = true;
22+
item.value = 50000;
23+
item.rare = 1;
24+
item.createTile = mod.TileType("BossTrophy");
25+
item.placeStyle = 2;
26+
}
27+
}
28+
}
616 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Terraria;
3+
using Terraria.ID;
4+
using Terraria.ModLoader;
5+
6+
namespace ExampleMod.Items.Placeable
7+
{
8+
public class PuritySpiritTrophy : ModItem
9+
{
10+
public override void SetDefaults()
11+
{
12+
item.name = "Spirit of Purity Trophy";
13+
item.width = 30;
14+
item.height = 30;
15+
item.maxStack = 99;
16+
item.useTurn = true;
17+
item.autoReuse = true;
18+
item.useAnimation = 15;
19+
item.useTime = 10;
20+
item.useStyle = 1;
21+
item.consumable = true;
22+
item.value = 50000;
23+
item.rare = 1;
24+
item.createTile = mod.TileType("BossTrophy");
25+
item.placeStyle = 1;
26+
}
27+
}
28+
}
657 Bytes
Loading
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Terraria;
3+
using Terraria.ID;
4+
using Terraria.ModLoader;
5+
6+
namespace ExampleMod.Items.Placeable
7+
{
8+
public class TreeTrophy : ModItem
9+
{
10+
public override void SetDefaults()
11+
{
12+
item.name = "Tree Trophy";
13+
item.width = 30;
14+
item.height = 30;
15+
item.maxStack = 99;
16+
item.useTurn = true;
17+
item.autoReuse = true;
18+
item.useAnimation = 15;
19+
item.useTime = 10;
20+
item.useStyle = 1;
21+
item.consumable = true;
22+
item.value = 50000;
23+
item.rare = 1;
24+
item.createTile = mod.TileType("BossTrophy");
25+
item.placeStyle = 3;
26+
}
27+
}
28+
}
675 Bytes
Loading

ExampleMod/Items/PurityShield.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using Microsoft.Xna.Framework;
3+
using Terraria;
4+
using Terraria.ModLoader;
5+
6+
namespace ExampleMod.Items
7+
{
8+
public class PurityShield : ModItem
9+
{
10+
public override void SetDefaults()
11+
{
12+
item.name = "Shield of Purity";
13+
item.width = 32;
14+
item.height = 32;
15+
item.toolTip = "WIP until bluemagic123 learns how to make mounts";
16+
item.useTime = 20;
17+
item.useAnimation = 20;
18+
item.useStyle = 1;
19+
item.value = Item.sellPrice(2, 0, 0, 0);
20+
item.rare = 11;
21+
item.useSound = 79;
22+
item.noMelee = true;
23+
}
24+
}
25+
}

ExampleMod/Items/PurityShield.png

259 Bytes
Loading

ExampleMod/Items/PuritySpiritBag.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using Terraria;
3+
using Terraria.ID;
4+
using Terraria.ModLoader;
5+
6+
namespace ExampleMod.Items
7+
{
8+
public class PuritySpiritBag : ModItem
9+
{
10+
public override void SetDefaults()
11+
{
12+
item.name = "Treasure Bag";
13+
item.maxStack = 999;
14+
item.consumable = true;
15+
item.width = 24;
16+
item.height = 24;
17+
item.toolTip = "Right click to open";
18+
item.rare = 11;
19+
item.expert = true;
20+
bossBagNPC = mod.NPCType("PuritySpirit");
21+
}
22+
23+
public override bool CanRightClick()
24+
{
25+
return true;
26+
}
27+
28+
public override void OpenBossBag(Player player)
29+
{
30+
player.TryGettingDevArmor();
31+
player.TryGettingDevArmor();
32+
int choice = Main.rand.Next(7);
33+
if (choice == 0)
34+
{
35+
player.QuickSpawnItem(mod.ItemType("PuritySpiritMask"));
36+
}
37+
else if (choice == 1)
38+
{
39+
player.QuickSpawnItem(mod.ItemType("BunnyMask"));
40+
}
41+
if (choice != 1)
42+
{
43+
player.QuickSpawnItem(ItemID.Bunny);
44+
}
45+
player.QuickSpawnItem(mod.ItemType("PurityShield"));
46+
}
47+
}
48+
}

ExampleMod/Items/PuritySpiritBag.png

565 Bytes
Loading

ExampleMod/NPCs/PuritySpirit/PuritySpirit.cs

+40-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public override void SetDefaults()
4343
}
4444
NPCID.Sets.MustAlwaysDraw[npc.type] = true;
4545
music = MusicID.Title;
46+
bossBag = mod.ItemType("PuritySpiritBag");
4647
}
4748

4849
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
@@ -665,7 +666,45 @@ public void FinishFight2()
665666

666667
public override void NPCLoot()
667668
{
668-
669+
int choice = Main.rand.Next(10);
670+
int item = 0;
671+
switch (choice)
672+
{
673+
case 0:
674+
item = mod.ItemType("PuritySpiritTrophy");
675+
break;
676+
case 1:
677+
item = mod.ItemType("BunnyTrophy");
678+
break;
679+
case 2:
680+
item = mod.ItemType("TreeTrophy");
681+
break;
682+
}
683+
if (item > 0)
684+
{
685+
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, item);
686+
}
687+
if (Main.expertMode)
688+
{
689+
npc.DropBossBags();
690+
}
691+
else
692+
{
693+
choice = Main.rand.Next(7);
694+
if (choice == 0)
695+
{
696+
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PuritySpiritMask"));
697+
}
698+
else if (choice == 1)
699+
{
700+
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("BunnyMask"));
701+
}
702+
if (choice != 1)
703+
{
704+
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Bunny);
705+
}
706+
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PurityShield"));
707+
}
669708
}
670709

671710
public override void BossLoot(ref string name, ref int potionType)

ExampleMod/Tiles/BossTrophy.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,25 @@ public override void SetDefaults()
2424

2525
public override void KillMultiTile(int i, int j, int frameX, int frameY)
2626
{
27-
if (frameX == 0)
27+
int item = 0;
28+
switch (frameX / 54)
2829
{
29-
Item.NewItem(i * 16, j * 16, 48, 48, mod.ItemType("AbominationTrophy"));
30+
case 0:
31+
item = mod.ItemType("AbominationTrophy");
32+
break;
33+
case 1:
34+
item = mod.ItemType("PuritySpiritTrophy");
35+
break;
36+
case 2:
37+
item = mod.ItemType("BunnyTrophy");
38+
break;
39+
case 3:
40+
item = mod.ItemType("TreeTrophy");
41+
break;
42+
}
43+
if (item > 0)
44+
{
45+
Item.NewItem(i * 16, j * 16, 48, 48, item);
3046
}
3147
}
3248
}

ExampleMod/Tiles/BossTrophy.png

2.11 KB
Loading

ExampleMod/build.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
author = bluemagic123
22
version = v0.7
33
displayName = Example Mod
4+
homepage = http://forums.terraria.org/index.php?threads/1-3-tmodloader-a-modding-api.23726/
45
hideCode = false
56
hideResources = false
67
includeSource = true

patches/tModLoader/Terraria.ModLoader.UI/UIMessageBox.cs

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ protected override void DrawSelf(SpriteBatch spriteBatch)
4444
remainder = drawString[drawString.Length - 1] + remainder;
4545
drawString = drawString.Substring(0, drawString.Length - 1);
4646
}
47+
if (remainder.Length > 0)
48+
{
49+
int index = drawString.LastIndexOf(' ');
50+
if (index >= 0)
51+
{
52+
remainder = drawString.Substring(index + 1) + remainder;
53+
drawString = drawString.Substring(0, index);
54+
}
55+
}
4756
if (position + textHeight > space.Height)
4857
{
4958
flag = true;

patches/tModLoader/Terraria.ModLoader/EquipTexture.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,19 @@ public virtual bool DrawLegs()
114114
return item == null || item.DrawLegs();
115115
}
116116

117-
public virtual void DrawArmorColor(ref Color color, ref int glowMask, ref Color glowMaskColor,
118-
ref int armGlowMask, ref Color armGlowMaskColor)
117+
public virtual void DrawArmorColor(Player drawPlayer, float shadow, ref Color color, ref int glowMask, ref Color glowMaskColor)
119118
{
120119
if (item != null)
121120
{
122-
item.DrawArmorColor(ref color, ref glowMask, ref glowMaskColor, ref armGlowMask, ref armGlowMaskColor);
121+
item.DrawArmorColor(drawPlayer, shadow, ref color, ref glowMask, ref glowMaskColor);
122+
}
123+
}
124+
125+
public virtual void ArmorArmGlowMask(Player drawPlayer, float shadow, ref int glowMask, ref Color color)
126+
{
127+
if (item != null)
128+
{
129+
item.ArmorArmGlowMask(drawPlayer, shadow, ref glowMask, ref color);
123130
}
124131
}
125132

0 commit comments

Comments
 (0)