forked from hamstar0/tml-wormholes-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWormholesUI.cs
105 lines (78 loc) · 3.83 KB
/
WormholesUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using HamstarHelpers.HudHelpers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Wormholes.Utils;
namespace Wormholes {
class WormholesUI {
private static Texture2D Tex = null;
internal static void Initialize() {
if( Main.netMode != 2 ) {
WormholesUI.Tex = WormholesMod.Instance.GetTexture( "Wormholes/MiniWormhole" );
}
}
////////////////
private SpriteAnimator TexAnim;
////////////////
public WormholesUI() {
if( Main.netMode == 2 ) {
throw new Exception("Cannot create class instance on server.");
}
this.TexAnim = new SpriteAnimator( 12, 4, WormholesUI.Tex, Color.White );
}
////////////////
public void Update() {
this.TexAnim.Animate();
}
////////////////
public void DrawMiniMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) {
var mymod = ctx.MyMod;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; }
float scale = Main.mapMinimapScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height );
Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height );
Vector2? l_pos = HudMapHelpers.GetMiniMapPosition( l_rect );
if( l_pos != null ) {
Color l_color = link.LeftPortal.BaseColor * Main.mapMinimapAlpha;
sb.Draw( tex, (Vector2)l_pos, this.TexAnim.Frame, l_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );
}
Vector2? r_pos = HudMapHelpers.GetMiniMapPosition( r_rect );
if( r_pos != null ) {
Color r_color = link.RightPortal.BaseColor * Main.mapMinimapAlpha;
sb.Draw( tex, (Vector2)r_pos, this.TexAnim.Frame, r_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );
}
}
public void DrawOverlayMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) {
var mymod = ctx.MyMod;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; }
float scale = Main.mapOverlayScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height );
Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height );
Vector2? l_pos = HudMapHelpers.GetOverlayMapPosition( l_rect );
if( l_pos != null ) {
Color l_color = link.LeftPortal.BaseColor * Main.mapOverlayAlpha;
sb.Draw( tex, (Vector2)l_pos, this.TexAnim.Frame, l_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );
}
Vector2? r_pos = HudMapHelpers.GetOverlayMapPosition( r_rect );
if( r_pos != null ) {
Color r_color = link.RightPortal.BaseColor * Main.mapOverlayAlpha;
sb.Draw( tex, (Vector2)r_pos, this.TexAnim.Frame, r_color, 0f, new Vector2(), scale, SpriteEffects.None, 1f );
}
}
public void DrawFullscreenMap( WormholeModContext ctx, WormholeLink link, SpriteBatch sb ) {
var mymod = ctx.MyMod;
if( !link.IsCharted( Main.LocalPlayer ) && !mymod.IsDebugWormholeViewMode() ) { return; }
float scale = Main.mapFullscreenScale / 1.5f;
Texture2D tex = WormholesUI.Tex;
Rectangle l_rect = new Rectangle( (int)link.LeftPortal.Pos.X, (int)link.LeftPortal.Pos.Y, tex.Width, tex.Height );
Vector2 l_pos = HudMapHelpers.GetFullMapPosition( l_rect );
sb.Draw( tex, l_pos, this.TexAnim.Frame, link.LeftPortal.BaseColor, 0f, new Vector2 { }, scale, SpriteEffects.None, 1f );
Rectangle r_rect = new Rectangle( (int)link.RightPortal.Pos.X, (int)link.RightPortal.Pos.Y, tex.Width, tex.Height );
Vector2 r_pos = HudMapHelpers.GetFullMapPosition( r_rect );
sb.Draw( tex, r_pos, this.TexAnim.Frame, link.RightPortal.BaseColor, 0f, new Vector2 { }, scale, SpriteEffects.None, 1f );
}
}
}