Skip to content

Commit

Permalink
MapManager.Position
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 10, 2023
1 parent e4a3ab3 commit 52b65a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 8 additions & 5 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public MapManager(GraphicsDevice gd)
{
StaticTiles.First(so => so.StaticTile.Equals(tile)).Hue = newHue;
};
Client.Moved += SetPos;
Client.Moved += (x, y) => Position = new Point(x,y);
Client.Connected += () =>
{
LandTiles.Clear();
Expand Down Expand Up @@ -236,11 +236,14 @@ public void Load(string clientPath, string clientVersion)
ValidStaticIds = staticIds.ToArray();
}

public void SetPos(ushort x, ushort y)
public Point Position
{
Camera.Position.X = x * TILE_SIZE;
Camera.Position.Y = y * TILE_SIZE;
Camera.Moved = true;
get => new((int)(Camera.Position.X * TILE_SIZE), (int)(Camera.Position.Y * TILE_SIZE));
set {
if(value != Position) Camera.Moved = true;
Camera.Position.X = value.X * TILE_SIZE;
Camera.Position.Y = value.Y * TILE_SIZE;
}
}

private enum MouseDirection
Expand Down
2 changes: 1 addition & 1 deletion CentrED/UI/Windows/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Draw()
ImGui.InputInt("Camera y", ref _gotoY);
if (ImGui.Button("Update pos"))
{
mapManager.SetPos((ushort)_gotoX, (ushort)_gotoY);
mapManager.Position = new Point(_gotoX, _gotoY);

Check failure on line 48 in CentrED/UI/Windows/DebugWindow.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, CentrED)

The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in CentrED/UI/Windows/DebugWindow.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, CentrED)

The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)
}

ImGui.Separator();
Expand Down
15 changes: 8 additions & 7 deletions CentrED/UI/Windows/MinimapWindow.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Numerics;
using CentrED.Client;
using CentrED.Client;
using CentrED.IO;
using CentrED.IO.Models;
using CentrED.Map;
using CentrED.Server.Map;
using ImGuiNET;
using Microsoft.Xna.Framework;
using static CentrED.Application;
using RadarMap = CentrED.Map.RadarMap;
using Vector2 = System.Numerics.Vector2;
using Vector4 = System.Numerics.Vector4;

namespace CentrED.UI.Windows;

Expand Down Expand Up @@ -40,9 +42,8 @@ public override void Draw()
{
ProfileManager.ActiveProfile.RadarFavorites.Add(_inputFavoriteName, new()
{
X = (ushort)(CEDGame.MapManager.Camera.Position.X / CEDGame.MapManager.TILE_SIZE),
Y = (ushort)(CEDGame.MapManager.Camera.Position.Y / CEDGame.MapManager.TILE_SIZE)

X = (ushort)CEDGame.MapManager.Position.X,
Y = (ushort)CEDGame.MapManager.Position.Y
});
ProfileManager.Save(ProfileManager.ActiveProfile);
_inputFavoriteName = "";
Expand Down Expand Up @@ -73,7 +74,7 @@ public override void Draw()

if (ImGui.Button($"{key}", new Vector2(75, 19)))
{
CEDGame.MapManager.SetPos((ushort)value.X, (ushort)value.Y);
CEDGame.MapManager.Position = new Point(value.X, value.Y);
}
ImGui.SetCursorPos(cursorPosition + new Vector2(ImGui.GetItemRectSize().X, 0));

Expand Down Expand Up @@ -149,7 +150,7 @@ public override void Draw()
var coords = ImGui.GetMousePos() - currentPos;
if (ImGui.IsWindowFocused() && ImGui.IsMouseDown(ImGuiMouseButton.Left))
{
CEDGame.MapManager.SetPos((ushort)(coords.X * 8), (ushort)(coords.Y * 8));
CEDGame.MapManager.Position = new Point((int)(coords.X * 8), (int)(coords.Y * 8));
}
_coordsText = $"x:{coords.X * 8} y:{coords.Y * 8}";

Expand Down

0 comments on commit 52b65a2

Please sign in to comment.