Skip to content

Commit

Permalink
Fix #53, fix tile modification with zoom, fix upside down drawing.
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Mar 19, 2021
1 parent 6a5828d commit 8ee3b68
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
31 changes: 25 additions & 6 deletions HEROsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,36 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
}
catch (Exception e)
{
ModUtils.DebugText("PostDrawInInventory Error: " + e.Message + e.StackTrace);
ModUtils.DebugText("HerosMod: UI Error: " + e.Message + e.StackTrace);
}
return true;
},
InterfaceScaleType.UI)
);

// Technically before the above GameInterfaceLayer
layers.Insert(inventoryLayerIndex, new LegacyGameInterfaceLayer(
"HerosMod: UI (Game Scale)",
delegate {
try
{
if (ModUtils.NetworkMode != NetworkMode.Server)
{
foreach (var service in ServiceController.Services)
{
service.UpdateGameScale();
}
}
SelectionTool.Update();
}
catch (Exception e)
{
ModUtils.DebugText("HerosMod: UI (Game Scale) Error: " + e.Message + e.StackTrace);
}
return true;
},
InterfaceScaleType.Game)
);
}
}

Expand Down Expand Up @@ -501,7 +525,6 @@ public static void Update(/*GameTime gameTime*/)
service.Update();
}
MasterView.UpdateMaster();
SelectionTool.Update();
//if (Main.ingameOptionsWindow && (IngameOptions.category == 2 || IngameOptions.category == 3))
//{
// HEROsModMod.UIKit.MasterView.gameScreen.AddChild(new HEROsModMod.UIKit.UIComponents.KeybindWindow());
Expand Down Expand Up @@ -648,11 +671,7 @@ public static void DrawBehindUI(SpriteBatch spriteBatch)
if (!Main.gameMenu)
{
HEROsModVideo.Services.MobHUD.MobInfo.Draw(spriteBatch);
SelectionTool.Draw(spriteBatch);
if (RegionService.RegionsVisible)
RegionService.DrawRegions(spriteBatch);
//HEROsModNetwork.CTF.CaptureTheFlag.Draw(spriteBatch);
CheckTileModificationTool.DrawBoxOnCursor(spriteBatch);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions HEROsModModWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,21 @@ public override TagCompound Save()
}
return null;
}

public override void PostDrawTiles()
{
if (RegionService.RegionsVisible || SelectionTool.Visible || CheckTileModificationTool.ListeningForInput)
{
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState,
DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
if (SelectionTool.Visible)
SelectionTool.Draw(Main.spriteBatch);
if (RegionService.RegionsVisible)
RegionService.DrawRegions(Main.spriteBatch);
if(CheckTileModificationTool.ListeningForInput)
CheckTileModificationTool.DrawBoxOnCursor(Main.spriteBatch);
Main.spriteBatch.End();
}
}
}
}
13 changes: 6 additions & 7 deletions HEROsModServices/CheckTileModificationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace HEROsMod.HEROsModServices
{
internal class CheckTileModificationTool : HEROsModService
{
private static bool ListeningForInput = false;
internal static bool ListeningForInput = false;
internal static Vector2 CheckCoordinates;

public CheckTileModificationTool()
{
Expand All @@ -25,13 +26,14 @@ private void HotbarIcon_onLeftClick(object sender, EventArgs e)
ListeningForInput = !ListeningForInput;
}

public override void Update()
public override void UpdateGameScale()
{
if (ListeningForInput && !Main.gameMenu)
{
CheckCoordinates = ModUtils.CursorTileCoords;
if (ModUtils.MouseState.LeftButton == ButtonState.Pressed && ModUtils.PreviousMouseState.LeftButton == ButtonState.Released && !UIKit.UIView.GameMouseOverwritten)
{
HEROsModNetwork.GeneralMessages.RequestTileModificationCheck(ModUtils.CursorTileCoords);
HEROsModNetwork.GeneralMessages.RequestTileModificationCheck(CheckCoordinates);
}
if (ModUtils.MouseState.RightButton == ButtonState.Pressed && ModUtils.PreviousMouseState.RightButton == ButtonState.Released && !UIKit.UIView.GameMouseOverwritten)
{
Expand All @@ -46,10 +48,7 @@ public static void DrawBoxOnCursor(SpriteBatch spriteBatch)
{
if (ListeningForInput)
{
Vector2 pos = ModUtils.CursorWorldCoords;
pos.X = (int)pos.X / 16 * 16;
pos.Y = (int)pos.Y / 16 * 16;
ModUtils.DrawBorderedRect(spriteBatch, Color.Blue, ModUtils.CursorTileCoords, new Vector2(1, 1), 2);
ModUtils.DrawBorderedRect(spriteBatch, Color.Blue, CheckCoordinates, new Vector2(1, 1), 2);
}
}

Expand Down
4 changes: 4 additions & 0 deletions HEROsModServices/HEROsModService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public virtual void Update()
{
}

public virtual void UpdateGameScale()
{
}

/// <summary>
/// This method must be called before the Service is desposed.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion HEROsModServices/SelectionTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public static void Update()
if (ModUtils.MouseState.LeftButton == ButtonState.Pressed && ModUtils.PreviousMouseState.LeftButton == ButtonState.Released && !UIKit.UIView.GameMouseOverwritten)
{
_dragging = true;
Position = ModUtils.CursorTileCoords;
Position = Main.MouseWorld.ToTileCoordinates().ToVector2();
_anchor = Position;
Width = 1;
Height = 1;
}
else if (_dragging && ModUtils.MouseState.LeftButton == ButtonState.Pressed)
{
Expand Down
3 changes: 2 additions & 1 deletion ModUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ public static Vector2 CursorTileCoords
{
get
{
return GetTileCoordsFromWorldCoords(GetCursorWorldCoords());
return Main.MouseWorld.ToTileCoordinates().ToVector2();
//return GetTileCoordsFromWorldCoords(GetCursorWorldCoords());
}
}

Expand Down

0 comments on commit 8ee3b68

Please sign in to comment.