65 lines
3.1 KiB
C#
65 lines
3.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using Terraria;
|
|
using Terraria.DataStructures;
|
|
using Terraria.GameContent;
|
|
using Terraria.Localization;
|
|
using Terraria.Map;
|
|
using Terraria.ModLoader;
|
|
using Terraria.UI;
|
|
using Terraria.ID;
|
|
|
|
namespace tTP.Common.UI
|
|
{
|
|
// ModMapLayers are used to draw icons and other things over the map. Pylons and spawn/bed icons are examples of vanilla map layers. This example adds an icon over the dungeon.
|
|
public class TeleportMapLayer : ModMapLayer
|
|
{
|
|
|
|
public override void Draw(ref MapOverlayDrawContext context, ref string text) {
|
|
Player p = Main.LocalPlayer;
|
|
// Here we define the scale that we wish to draw the icon when hovered and not hovered.
|
|
const float scaleIfNotSelected = 1f;
|
|
const float scaleIfSelected = scaleIfNotSelected * 2f;
|
|
|
|
// Here we retrieve the texture of the Skeletron boss head so that we can draw it. Remember that not all textures are loaded by default, so you might need to do something like `Main.instance.LoadItem(ItemID.BoneKey);` in your code to ensure the texture is loaded.
|
|
var dungeonTexture = TextureAssets.Item[ModContent.ItemType<Content.Items.Placeable.PersonalTeleporter>()];
|
|
|
|
foreach (DataRow row in tTP.table.Rows)
|
|
{
|
|
Int64 tpx = Convert.ToInt64(row["x"]);
|
|
Int64 tpy = Convert.ToInt64(row["y"]);
|
|
if (context.Draw((Texture2D)dungeonTexture, new Vector2(Convert.ToSingle(tpx), Convert.ToSingle(tpy)), Color.White, new SpriteFrame(1, 1, 0, 0), scaleIfNotSelected, scaleIfSelected, Alignment.Center).IsMouseOver)
|
|
{
|
|
text = Language.GetTextValue(row["name"].ToString());
|
|
if (ItemSlot.ShiftInUse)
|
|
{
|
|
IngameFancyUI.Close();
|
|
p.Teleport(new Vector2(Convert.ToSingle(tpx * 16), Convert.ToSingle((tpy * 16)-10)),TeleportationStyleID.Portal, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
// The MapOverlayDrawContext.Draw method used here handles many of the small details for drawing an icon and should be used if possible. It'll handle scaling, alignment, culling, framing, and accounting for map zoom. Handling these manually is a lot of work.
|
|
// Note that the `position` argument expects tile coordinates expressed as a Vector2. Don't scale tile coordinates to world coordinates by multiplying by 16.
|
|
// The return of MapOverlayDrawContext.Draw has a field that indicates if the mouse is currently over our icon.
|
|
}
|
|
}
|
|
}
|
|
|
|
// The game doesn't send Main.dungeonX or Main.dungeonY to multiplayer clients.
|
|
// This ModSystem will ensure that they are synced allowing ExampleMapLayer to work in multiplayer.
|
|
public class TeleportLayerSystem : ModSystem
|
|
{
|
|
public override void NetSend(BinaryWriter writer) {
|
|
writer.Write(Main.dungeonX);
|
|
writer.Write(Main.dungeonY);
|
|
}
|
|
public override void NetReceive(BinaryReader reader) {
|
|
Main.dungeonX = reader.ReadInt32();
|
|
Main.dungeonY = reader.ReadInt32();
|
|
}
|
|
} |