Skip to content

Commit 574c6d2

Browse files
committed
0.1.5.2 release, compatibility with UI scaling
1 parent 9242e7a commit 574c6d2

File tree

10 files changed

+115
-29
lines changed

10 files changed

+115
-29
lines changed

Commands/BecomeAdmin.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
using HEROsMod.HEROsModNetwork;
3+
using System;
4+
using Terraria;
5+
using Terraria.ModLoader;
6+
7+
namespace HEROsMod.Commands
8+
{
9+
internal class BecomeAdmin : ModCommand
10+
{
11+
public override CommandType Type => CommandType.World;
12+
13+
public override string Command => "auth";
14+
15+
public override string Description => "Makes you Admin in HERO's Mod";
16+
17+
public override string Usage => "/auth SecretCode";
18+
19+
public override void Action(CommandCaller caller, string input, string[] args)
20+
{
21+
if(Main.netMode == 0)
22+
{
23+
throw new UsageException("Only use this command while on server.");
24+
}
25+
if (args.Length != 1 || args[0].Length != 6)
26+
{
27+
throw new UsageException();
28+
}
29+
if (args[0] == Network.AuthCode.ToString())
30+
{
31+
32+
if (Network.Players[caller.Player.whoAmI].Username.Length > 0)
33+
{
34+
Network.Players[caller.Player.whoAmI].Group = Network.AdminGroup;
35+
DatabaseController.SetPlayerGroup(Network.Players[caller.Player.whoAmI].ID, Network.Players[caller.Player.whoAmI].Group.ID);
36+
LoginService.SendPlayerPermissions(caller.Player.whoAmI);
37+
Network.SendTextToPlayer("You are now Admin", caller.Player.whoAmI);
38+
return;
39+
}
40+
else
41+
{
42+
Network.SendTextToPlayer("Please login first", caller.Player.whoAmI);
43+
return;
44+
}
45+
}
46+
throw new UsageException("Auth code is incorrect");
47+
}
48+
}
49+
}
50+
*/

HEROsMod.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</ItemGroup>
6060
<ItemGroup>
6161
<Compile Include="Commands\AdminInstructionsCommand.cs" />
62+
<Compile Include="Commands\BecomeAdmin.cs" />
6263
<Compile Include="HEROsModNetwork\DatabaseController.cs" />
6364
<Compile Include="HEROsModNetwork\HEROsModPlayer.cs" />
6465
<Compile Include="HEROsModNetwork\GeneralMessages.cs" />

HEROsMod.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
77
<StartAction>Program</StartAction>
8-
<StartProgram>C:\Program Files %28x86%29\Steam\steamapps\common\Terraria\tModLoaderServerDebug.exe</StartProgram>
8+
<StartProgram>C:\Program Files %28x86%29\Steam\steamapps\common\Terraria\Terraria.exe</StartProgram>
99
<StartWorkingDirectory>C:\Program Files %28x86%29\Steam\steamapps\common\terraria</StartWorkingDirectory>
1010
</PropertyGroup>
1111
</Project>

Mod.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using Microsoft.Xna.Framework.Graphics;
66
using Microsoft.Xna.Framework.Input;
77
using System;
8+
using System.Collections.Generic;
89
using System.IO;
910
using Terraria;
1011
using Terraria.DataStructures;
1112
using Terraria.ModLoader;
1213
using Terraria.ModLoader.IO;
14+
using Terraria.UI;
1315

1416
// TODO, freeze is bypassable.
1517
// TODO, regions prevent all the chest movement and right click.
@@ -134,7 +136,7 @@ internal class HEROsMod : Mod
134136
public override void Load()
135137
{
136138
// Since we are using hooks not in older versions, and since ItemID.Count changed, we need to do this.
137-
if (ModLoader.version < new Version(0, 9, 2))
139+
if (ModLoader.version < new Version(0, 10))
138140
{
139141
throw new Exception("\nThis mod uses functionality only present in the latest tModLoader. Please update tModLoader to use this mod\n\n");
140142
}
@@ -199,23 +201,35 @@ public override void PostDrawFullscreenMap(ref string mouseText)
199201
MapRevealer.instance.PostDrawFullScreenMap();
200202
}
201203

202-
public override void PostDrawInterface(SpriteBatch spriteBatch)
204+
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
203205
{
204-
try
206+
int inventoryLayerIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));
207+
if (inventoryLayerIndex != -1)
205208
{
206-
HEROsMod.Update();
209+
layers.Insert(inventoryLayerIndex, new LegacyGameInterfaceLayer(
210+
"HerosMod: UI",
211+
delegate
212+
{
213+
try
214+
{
215+
HEROsMod.Update();
207216

208-
HEROsMod.ServiceHotbar.Update();
217+
HEROsMod.ServiceHotbar.Update();
209218

210-
HEROsMod.DrawBehindUI(spriteBatch);
219+
HEROsMod.DrawBehindUI(Main.spriteBatch);
211220

212-
HEROsMod.Draw(spriteBatch);
221+
HEROsMod.Draw(Main.spriteBatch);
213222

214-
KeybindController.DoPreviousKeyState();
215-
}
216-
catch (Exception e)
217-
{
218-
ModUtils.DebugText("PostDrawInInventory Error: " + e.Message + e.StackTrace);
223+
KeybindController.DoPreviousKeyState();
224+
}
225+
catch (Exception e)
226+
{
227+
ModUtils.DebugText("PostDrawInInventory Error: " + e.Message + e.StackTrace);
228+
}
229+
return true;
230+
},
231+
InterfaceScaleType.UI)
232+
);
219233
}
220234
}
221235

ModUtils.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,24 @@ public static void DebugText(string message)
905905
}
906906
}
907907
}
908+
909+
public static Rectangle GetClippingRectangle(SpriteBatch spriteBatch, Rectangle r)
910+
{
911+
//Vector2 vector = new Vector2(this._innerDimensions.X, this._innerDimensions.Y);
912+
//Vector2 position = new Vector2(this._innerDimensions.Width, this._innerDimensions.Height) + vector;
913+
Vector2 vector = new Vector2(r.X, r.Y);
914+
Vector2 position = new Vector2(r.Width, r.Height) + vector;
915+
vector = Vector2.Transform(vector, Main.UIScaleMatrix);
916+
position = Vector2.Transform(position, Main.UIScaleMatrix);
917+
Rectangle result = new Rectangle((int)vector.X, (int)vector.Y, (int)(position.X - vector.X), (int)(position.Y - vector.Y));
918+
int width = spriteBatch.GraphicsDevice.Viewport.Width;
919+
int height = spriteBatch.GraphicsDevice.Viewport.Height;
920+
result.X = Utils.Clamp<int>(result.X, 0, width);
921+
result.Y = Utils.Clamp<int>(result.Y, 0, height);
922+
result.Width = Utils.Clamp<int>(result.Width, 0, width - result.X);
923+
result.Height = Utils.Clamp<int>(result.Height, 0, height - result.Y);
924+
return result;
925+
}
908926
}
909927

910928
public enum NetworkMode : byte

UIKit/MasterView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public static void UpdateMaster()
9393
public static void DrawMaster(SpriteBatch spriteBatch)
9494
{
9595
spriteBatch.End();
96-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
96+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.AnisotropicClamp, DepthStencilState.None, null, null, Main.UIScaleMatrix);
9797
masterView.Draw(spriteBatch);
9898
spriteBatch.End();
99-
spriteBatch.Begin();
99+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.AnisotropicClamp, DepthStencilState.None, null, null, Main.UIScaleMatrix);
100100
//Console.WriteLine("update: " + UpdateCalls + "draws: " + DrawCalls);
101101
}
102102

UIKit/UIComponents/UIHotbar.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ public override void Draw(SpriteBatch spriteBatch)
138138
{
139139
spriteBatch.End();
140140
//spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, this._rasterizerState);
141-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, this._rasterizerState);
141+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, this._rasterizerState, null, Main.UIScaleMatrix);
142142
// Rectangle scissorRectangle = new Rectangle((int)base.X- (int)base.Width, (int)base.Y, (int)base.Width, (int)base.Height);
143143
//Parent.Position.Y
144144
// Main.NewText((int)Parent.Position.Y + " " + (int)shownPosition);
145145
// Rectangle scissorRectangle = new Rectangle((int)(base.X - base.Width / 2), (int)(shownPosition), (int)base.Width, (int)base.Height);
146146
Rectangle scissorRectangle = new Rectangle((int)(base.X - base.Width / 2), (int)(shownPosition), (int)base.Width, (int)(HotBarParent.Position.Y - shownPosition));
147-
if (scissorRectangle.X < 0)
147+
/*if (scissorRectangle.X < 0)
148148
{
149149
scissorRectangle.Width += scissorRectangle.X;
150150
scissorRectangle.X = 0;
@@ -161,15 +161,16 @@ public override void Draw(SpriteBatch spriteBatch)
161161
if ((float)scissorRectangle.Y + base.Height > (float)Main.screenHeight)
162162
{
163163
scissorRectangle.Height = Main.screenHeight - scissorRectangle.Y;
164-
}
164+
}*/
165+
scissorRectangle = ModUtils.GetClippingRectangle(spriteBatch, scissorRectangle);
165166
Rectangle scissorRectangle2 = spriteBatch.GraphicsDevice.ScissorRectangle;
166167
spriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle;
167168

168169
base.Draw(spriteBatch);
169170

170171
spriteBatch.GraphicsDevice.ScissorRectangle = scissorRectangle2;
171172
spriteBatch.End();
172-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
173+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Main.UIScaleMatrix);
173174
}
174175
// base.Draw(spriteBatch);
175176
}

UIKit/UIScrollView.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ public override void Draw(SpriteBatch spriteBatch)
228228
if (pos.X <= Main.screenWidth && pos.Y <= Main.screenHeight && pos.X + Width >= 0 && pos.Y + Height >= 0)
229229
{
230230
spriteBatch.End();
231-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState);
231+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState, null, Main.UIScaleMatrix);
232232

233233
Rectangle cutRect = new Rectangle((int)pos.X, (int)pos.Y, (int)Width, (int)Height);
234-
if (cutRect.X < 0)
234+
/*if (cutRect.X < 0)
235235
{
236236
cutRect.Width += cutRect.X;
237237
cutRect.X = 0;
@@ -242,7 +242,8 @@ public override void Draw(SpriteBatch spriteBatch)
242242
cutRect.Y = 0;
243243
}
244244
if (cutRect.X + Width > Main.screenWidth) cutRect.Width = Main.screenWidth - cutRect.X;
245-
if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;
245+
if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;*/
246+
cutRect = ModUtils.GetClippingRectangle(spriteBatch, cutRect);
246247

247248
Rectangle currentRect = spriteBatch.GraphicsDevice.ScissorRectangle;
248249
spriteBatch.GraphicsDevice.ScissorRectangle = cutRect;
@@ -255,7 +256,7 @@ public override void Draw(SpriteBatch spriteBatch)
255256

256257
spriteBatch.GraphicsDevice.ScissorRectangle = currentRect;
257258
spriteBatch.End();
258-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
259+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Main.UIScaleMatrix);
259260
scrollBar.Draw(spriteBatch);
260261
}
261262
}

UIKit/UITextbox.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public override void Draw(SpriteBatch spriteBatch)
265265
OnEnterPress?.Invoke(this, new EventArgs());
266266
}
267267
spriteBatch.End();
268-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
268+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Main.UIScaleMatrix);
269269
Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
270270
}
271271

@@ -286,10 +286,10 @@ public override void Draw(SpriteBatch spriteBatch)
286286
if (pos.X <= Main.screenWidth && pos.Y <= Main.screenHeight && pos.X + Width >= 0 && pos.Y + Height >= 0)
287287
{
288288
spriteBatch.End();
289-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState);
289+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState, null, Main.UIScaleMatrix);
290290

291291
Rectangle cutRect = new Rectangle((int)pos.X, (int)pos.Y, (int)Width, (int)Height);
292-
if (cutRect.X < 0)
292+
/*if (cutRect.X < 0)
293293
{
294294
cutRect.Width += cutRect.X;
295295
cutRect.X = 0;
@@ -300,7 +300,8 @@ public override void Draw(SpriteBatch spriteBatch)
300300
cutRect.Y = 0;
301301
}
302302
if (cutRect.X + Width > Main.screenWidth) cutRect.Width = Main.screenWidth - cutRect.X;
303-
if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;
303+
if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;*/
304+
cutRect = ModUtils.GetClippingRectangle(spriteBatch, cutRect);
304305

305306
Rectangle currentRect = spriteBatch.GraphicsDevice.ScissorRectangle;
306307
spriteBatch.GraphicsDevice.ScissorRectangle = cutRect;
@@ -309,7 +310,7 @@ public override void Draw(SpriteBatch spriteBatch)
309310

310311
spriteBatch.GraphicsDevice.ScissorRectangle = currentRect;
311312
spriteBatch.End();
312-
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
313+
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Main.UIScaleMatrix);
313314
}
314315
}
315316
}

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
author = HERO, jopojelly
2-
version = 0.1.5.1
2+
version = 0.1.5.2
33
displayName = HERO's Mod
44
homepage = http://forums.terraria.org/index.php?threads/heros-mod-creative-mode-server-management-and-over-25-tools-1-3-1-1-compatible.44650/
55
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, tmod\*, ignore\*, ZVidBuild\*, Images\Old*, Images\AllIcons.psd, .git\*, LICENSE, .travis.yml, .gitignore

0 commit comments

Comments
 (0)