Skip to content

Commit

Permalink
Proper info in windows that require client to be connected
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Mar 16, 2024
1 parent 54020e9 commit 9ad7e90
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 115 deletions.
5 changes: 5 additions & 0 deletions CentrED/UI/Windows/HuesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ private void FilterHues()

protected override void InternalDraw()
{
if (!CEDGame.MapManager.Client.Initialized)
{
ImGui.Text("Not connected");
return;
}
if (ImGui.Button("Scroll to selected"))
{
_updateScroll = true;
Expand Down
12 changes: 9 additions & 3 deletions CentrED/UI/Windows/LandBrushWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CentrED.IO.Models.Centredplus;
using ClassicUO.Assets;
using ImGuiNET;
using static CentrED.Application;
using static CentrED.IO.Models.Direction;

namespace CentrED.UI.Windows;
Expand All @@ -24,6 +25,11 @@ public class LandBrushWindow : Window
public LandBrush? Selected;
protected override void InternalDraw()
{
if (!CEDGame.MapManager.Client.Initialized)
{
ImGui.Text("Not connected");
return;
}
ImGui.InputText("File", ref _tilesBrushPath, 512);
ImGui.SameLine();
if (ImGui.Button("..."))
Expand Down Expand Up @@ -67,7 +73,7 @@ protected override void InternalDraw()
foreach (var fullTile in Selected.Tiles)
{
var tex = TexmapsLoader.Instance.GetLandTexture(fullTile, out var bounds);
Application.CEDGame.UIManager.DrawImage(tex, bounds, TexSize);
CEDGame.UIManager.DrawImage(tex, bounds, TexSize);
ImGui.SameLine();
ImGui.Text($"0x{fullTile:X4}");
}
Expand All @@ -88,7 +94,7 @@ private void Draw(LandBrushTransition transition)
var tex = TexmapsLoader.Instance.GetLandTexture(transition.TileID, out var bounds);
if (tex != null)
{
Application.CEDGame.UIManager.DrawImage(tex, bounds, TexSize);
CEDGame.UIManager.DrawImage(tex, bounds, TexSize);
ImGui.SameLine();
}
var type = transition.Direction;
Expand Down Expand Up @@ -152,7 +158,7 @@ private void ImportLandBrush()
}
target.Add(newBrush.Name, newBrush);
}
Application.CEDGame.MapManager.InitLandBrushes();
CEDGame.MapManager.InitLandBrushes();
ProfileManager.Save();
}
catch (Exception e)
Expand Down
233 changes: 121 additions & 112 deletions CentrED/UI/Windows/MinimapWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,146 +21,155 @@ public class MinimapWindow : Window

protected override void InternalDraw()
{
if (CEDGame.MapManager.Client.Initialized)
if (!CEDGame.MapManager.Client.Initialized)
{
ImGui.InputText("Favorite Name", ref _inputFavoriteName, 64);
ImGui.SameLine();
if (ImGui.Button("Add Favorite"))
ImGui.Text("Not connected");
return;
}
ImGui.InputText("Favorite Name", ref _inputFavoriteName, 64);
ImGui.SameLine();
if (ImGui.Button("Add Favorite"))
{
if (string.IsNullOrEmpty(_inputFavoriteName) || ProfileManager.ActiveProfile.RadarFavorites.ContainsKey
(_inputFavoriteName))
{
if (string.IsNullOrEmpty(_inputFavoriteName) || ProfileManager.ActiveProfile.RadarFavorites.ContainsKey(_inputFavoriteName))
{
ImGui.OpenPopup("Error");
_showError = true;
}
else
{
ProfileManager.ActiveProfile.RadarFavorites.Add(_inputFavoriteName, new()
ImGui.OpenPopup("Error");
_showError = true;
}
else
{
ProfileManager.ActiveProfile.RadarFavorites.Add
(
_inputFavoriteName,
new()
{
X = (ushort)CEDGame.MapManager.Position.X,
Y = (ushort)CEDGame.MapManager.Position.Y
});
ProfileManager.Save();
_inputFavoriteName = "";
}
}
);
ProfileManager.Save();
_inputFavoriteName = "";
}

if (ImGui.BeginChild("Favorites", new Vector2(RadarMap.Instance.Texture.Width, 100)))
}

if (ImGui.BeginChild("Favorites", new Vector2(RadarMap.Instance.Texture.Width, 100)))
{
foreach (var (name, coords) in ProfileManager.ActiveProfile.RadarFavorites)
{
foreach (var (name, coords) in ProfileManager.ActiveProfile.RadarFavorites)
if (name != ProfileManager.ActiveProfile.RadarFavorites.First().Key)
{
if (name != ProfileManager.ActiveProfile.RadarFavorites.First().Key)
{
ImGui.SameLine();
}
if (ImGui.GetCursorPos().X + 75 >= RadarMap.Instance.Texture.Width)
{
ImGui.NewLine();
}
ImGui.SameLine();
}
if (ImGui.GetCursorPos().X + 75 >= RadarMap.Instance.Texture.Width)
{
ImGui.NewLine();
}

var cursorPosition = ImGui.GetCursorPos();
var cursorPosition = ImGui.GetCursorPos();

//tooltip for button what shows the key
if (ImGui.Button($"{name}", new Vector2(75, 19)))
{
CEDGame.MapManager.Position = new Point(coords.X, coords.Y);
}
UIManager.Tooltip($"{name}\nX:{coords.X} Y:{coords.Y}");
//tooltip for button what shows the key
if (ImGui.Button($"{name}", new Vector2(75, 19)))
{
CEDGame.MapManager.Position = new Point(coords.X, coords.Y);
}
UIManager.Tooltip($"{name}\nX:{coords.X} Y:{coords.Y}");

ImGui.SetCursorPos(cursorPosition + new Vector2(ImGui.GetItemRectSize().X, 0));

ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 0, 0, .2f));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(1, 0, 0, 1));
if (ImGui.Button($"x##{name}"))
{
_keyToDelete = name;
ImGui.OpenPopup("Confirmation");
_showConfirmation = true;
}
ImGui.PopStyleColor(2);
ImGui.SetCursorPos(cursorPosition + new Vector2(ImGui.GetItemRectSize().X, 0));

ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 0, 0, .2f));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Vector4(1, 0, 0, 1));
if (ImGui.Button($"x##{name}"))
{
_keyToDelete = name;
ImGui.OpenPopup("Confirmation");
_showConfirmation = true;
}
if (ImGui.BeginPopupModal("Confirmation", ref _showConfirmation, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar))
ImGui.PopStyleColor(2);
}
if (ImGui.BeginPopupModal
(
"Confirmation",
ref _showConfirmation,
ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar
))
{
ImGui.Text("Are you sure you want to delete this favorite?");
if (ImGui.Button("Yes"))
{
ImGui.Text("Are you sure you want to delete this favorite?");
if (ImGui.Button("Yes"))
if (!string.IsNullOrEmpty(_keyToDelete))
{
if (!string.IsNullOrEmpty(_keyToDelete))
{
ProfileManager.ActiveProfile.RadarFavorites.Remove(_keyToDelete);
ProfileManager.Save();
_keyToDelete = "";
}
ImGui.CloseCurrentPopup();
ProfileManager.ActiveProfile.RadarFavorites.Remove(_keyToDelete);
ProfileManager.Save();
_keyToDelete = "";
}
ImGui.SameLine();
if (ImGui.Button("No"))
{
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
if (ImGui.Button("No"))
{
ImGui.CloseCurrentPopup();
}
ImGui.EndChild();
ImGui.EndPopup();
}

if (ImGui.BeginPopupModal("Error", ref _showError, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar))
ImGui.EndChild();
}

if (ImGui.BeginPopupModal
("Error", ref _showError, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar))
{
ImGui.TextColored(new Vector4(1.0f, .0f, .0f, 1.0f), "Name already exists or empty value!");

if (ImGui.Button("Ok"))
{
ImGui.TextColored(new Vector4(1.0f, .0f, .0f, 1.0f), "Name already exists or empty value!");
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}
ImGui.Text(_coordsText);
if (ImGui.BeginChild("Minimap", Vector2.Zero, ImGuiChildFlags.None, ImGuiWindowFlags.HorizontalScrollbar))
{
var currentPos = ImGui.GetCursorScreenPos();
var tex = RadarMap.Instance.Texture;
CEDGame.UIManager.DrawImage(tex, tex.Bounds);

if (ImGui.Button("Ok"))
ImGui.SetCursorScreenPos(currentPos);
//So we can easily interact with minimap
ImGui.InvisibleButton("MinimapInvButton", new Vector2(tex.Width, tex.Height));
var hovered = ImGui.IsItemHovered();
var held = ImGui.IsItemActive();

if (ImGui.BeginPopupContextItem())
{
if (ImGui.Button("Reload"))
{
CEDClient.Send(new RequestRadarMapPacket());
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}
ImGui.Text(_coordsText);
if (ImGui.BeginChild("Minimap", Vector2.Zero, ImGuiChildFlags.None, ImGuiWindowFlags.HorizontalScrollbar))

if (hovered)
{
var currentPos = ImGui.GetCursorScreenPos();
var tex = RadarMap.Instance.Texture;
CEDGame.UIManager.DrawImage(tex, tex.Bounds);

ImGui.SetCursorScreenPos(currentPos);
//So we can easily interact with minimap
ImGui.InvisibleButton("MinimapInvButton", new Vector2(tex.Width, tex.Height));
var hovered = ImGui.IsItemHovered();
var held = ImGui.IsItemActive();

if (ImGui.BeginPopupContextItem())
{
if (ImGui.Button("Reload"))
{
CEDClient.Send(new RequestRadarMapPacket());
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}

if (hovered)
var newPos = (ImGui.GetMousePos() - currentPos) * 8;
if (held)
{
var newPos = (ImGui.GetMousePos() - currentPos) * 8;
if (held)
{
CEDGame.MapManager.Position = new Point((int)newPos.X, (int)newPos.Y);
}
_coordsText = $"x:{newPos.X} y:{newPos.Y}";
CEDGame.MapManager.Position = new Point((int)newPos.X, (int)newPos.Y);
}
else
{
var mapPos = CEDGame.MapManager.Position;
_coordsText = $"x:{mapPos.X} y:{mapPos.Y}";
}

var rect = CEDGame.MapManager.ViewRange;
var p1 = currentPos + new Vector2(rect.Left / 8, rect.Center.Y / 8);
var p2 = currentPos + new Vector2(rect.Center.X / 8, rect.Top / 8);
var p3 = currentPos + new Vector2(rect.Right / 8, rect.Center.Y / 8);
var p4 = currentPos + new Vector2(rect.Center.X / 8, rect.Bottom / 8);
ImGui.GetWindowDrawList().AddQuad(p1, p2, p3, p4, ImGui.GetColorU32(UIManager.Red));
ImGui.EndChild();
_coordsText = $"x:{newPos.X} y:{newPos.Y}";
}
}
else
{
ImGui.Text("Not connected");
else
{
var mapPos = CEDGame.MapManager.Position;
_coordsText = $"x:{mapPos.X} y:{mapPos.Y}";
}

var rect = CEDGame.MapManager.ViewRange;
var p1 = currentPos + new Vector2(rect.Left / 8, rect.Center.Y / 8);
var p2 = currentPos + new Vector2(rect.Center.X / 8, rect.Top / 8);
var p3 = currentPos + new Vector2(rect.Right / 8, rect.Center.Y / 8);
var p4 = currentPos + new Vector2(rect.Center.X / 8, rect.Bottom / 8);
ImGui.GetWindowDrawList().AddQuad(p1, p2, p3, p4, ImGui.GetColorU32(UIManager.Red));
ImGui.EndChild();
}
}
}
5 changes: 5 additions & 0 deletions CentrED/UI/Windows/TilesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private void FilterTiles()

protected override void InternalDraw()
{
if (!CEDGame.MapManager.Client.Initialized)
{
ImGui.Text("Not connected");
return;
}
if (ImGui.Button("Scroll to selected"))
{
_updateScroll = true;
Expand Down

0 comments on commit 9ad7e90

Please sign in to comment.