Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocked harbor area can now be shown on canvas (#323) #354

Merged
21 changes: 21 additions & 0 deletions AnnoDesigner.Core/Models/AnnoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public AnnoObject(AnnoObject obj)
Road = obj.Road;
// note: this is not really a copy, just a reference, but it is not supposed to change anyway
//BuildCosts = obj.BuildCosts;
BlockedAreaLength = obj.BlockedAreaLength;
BlockedAreaWidth = obj.BlockedAreaWidth;
Direction = obj.Direction;
}

#endregion
Expand Down Expand Up @@ -128,5 +131,23 @@ public AnnoObject(AnnoObject obj)

//[DataMember]
//public SerializableDictionary<int> BuildCosts { get; set; }

/// <summary>
/// Length of blocked area
/// </summary>
[DataMember(Order = 12)]
public double BlockedAreaLength { get; set; }

/// <summary>
/// Width of blocked area
/// </summary>
[DataMember(Order = 13)]
public double BlockedAreaWidth { get; set; }

/// <summary>
/// Direction of blocked area
/// </summary>
[DataMember(Order = 14)]
public GridDirection Direction { get; set; } = GridDirection.Down;
}
}
10 changes: 10 additions & 0 deletions AnnoDesigner.Core/Models/GridDirection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AnnoDesigner.Core.Models
{
public enum GridDirection
{
Up,
FroggieFrog marked this conversation as resolved.
Show resolved Hide resolved
Right,
Down,
Left
}
}
1 change: 1 addition & 0 deletions AnnoDesigner.Core/Models/IAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface IAppSettings
bool ShowGrid { get; set; }
bool ShowTrueInfluenceRange { get; set; }
bool ShowInfluences { get; set; }
bool ShowHarborBlockedArea { get; set; }
bool IsPavedStreet { get; set; }
string TreeViewSearchText { get; set; }
string PresetsTreeGameVersionFilter { get; set; }
Expand Down
18 changes: 18 additions & 0 deletions AnnoDesigner.Core/Presets/Models/BuildingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ public class BuildingInfo : IBuildingInfo
[DataMember(Order = 10)]
public bool Borderless { get; set; }

/// <summary>
/// Length of blocked area
/// </summary>
[DataMember(Order = 11)]
public double BlockedAreaLength { get; set; }

/// <summary>
/// Length of blocked area
/// </summary>
[DataMember(Order = 12)]
public double BlockedAreaWidth { get; set; }

/// <summary>
/// Direction of blocked area
/// </summary>
[DataMember(Order = 13)]
public GridDirection Direction { get; set; } = GridDirection.Down;
FroggieFrog marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The localized names of this building.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions AnnoDesigner.Core/Presets/Models/IBuildingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ public interface IBuildingInfo
bool Borderless { get; set; }
bool Road { get; set; }
SerializableDictionary<string> Localization { get; set; }
double BlockedAreaLength { get; set; }
double BlockedAreaWidth { get; set; }
GridDirection Direction { get; set; }
}
}
31 changes: 31 additions & 0 deletions AnnoDesigner/AnnoCanvas.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ public bool RenderTrueInfluenceRange
}
}

/// <summary>
/// Backing field of the RenderHarborBlockedArea property.
/// </summary>
private bool _renderHarborBlockedArea;

/// <summary>
/// Gets or sets value indication whether the blocked harbor aread should be rendered.
/// </summary>
public bool RenderHarborBlockedArea
{
get { return _renderHarborBlockedArea; }
set
{
if (_renderHarborBlockedArea != value)
{
InvalidateVisual();
}
_renderHarborBlockedArea = value;
}
}

/// <summary>
/// Backing field of the CurrentObject property
/// </summary>
Expand Down Expand Up @@ -1079,6 +1100,14 @@ private void RenderObjectList(DrawingContext drawingContext, List<LayoutObject>

var borderPen = obj.Borderless ? curLayoutObject.GetBorderlessPen(brush, _linePen.Thickness) : _linePen;
drawingContext.DrawRectangle(brush, borderPen, objRect);
if (RenderHarborBlockedArea)
{
var objBlockedRect = curLayoutObject.CalculateBlockedScreenRect(GridSize);
if (objBlockedRect.HasValue)
{
drawingContext.DrawRectangle(curLayoutObject.BlockedAreaBrush, borderPen, objBlockedRect.Value);
}
}

// draw object icon if it is at least 2x2 cells
var iconRendered = false;
Expand Down Expand Up @@ -1599,6 +1628,7 @@ private void InvalidateBounds()
var newRect = _coordinateHelper.Rotate(item.Bounds);
var oldRect = item.Bounds;
item.Bounds = newRect;
item.Direction = _coordinateHelper.Rotate(item.Direction);
yield return (item, oldRect);
}
}
Expand Down Expand Up @@ -2388,6 +2418,7 @@ private void ExecuteRotate(object param)
if (CurrentObjects.Count == 1)
{
CurrentObjects[0].Size = _coordinateHelper.Rotate(CurrentObjects[0].Size);
CurrentObjects[0].Direction = _coordinateHelper.Rotate(CurrentObjects[0].Direction);
}
else if (CurrentObjects.Count > 1)
{
Expand Down
5 changes: 4 additions & 1 deletion AnnoDesigner/BuildingInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public static AnnoObject ToAnnoObject(this IBuildingInfo buildingInfo, string se
Size = buildingInfo.BuildBlocker == null ? new Size() : new Size(buildingInfo.BuildBlocker["x"], buildingInfo.BuildBlocker["z"]),
Template = buildingInfo.Template,
Road = buildingInfo.Road,
Borderless = buildingInfo.Borderless
Borderless = buildingInfo.Borderless,
//BuildCosts = BuildCost
BlockedAreaLength = buildingInfo.BlockedAreaLength,
BlockedAreaWidth = buildingInfo.BlockedAreaWidth,
Direction = buildingInfo.Direction
};
}

Expand Down
11 changes: 11 additions & 0 deletions AnnoDesigner/Helper/CoordinateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using AnnoDesigner.Core.Models;
using AnnoDesigner.Models;

namespace AnnoDesigner.Helper
Expand Down Expand Up @@ -157,5 +158,15 @@ public Rect Rotate(Rect rect)

return new Rect(new Point(xPrime, yPrime), Rotate(rect.Size));
}

/// <summary>
/// Rotates the given GridDirection object 90 degrees clockwise.
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public GridDirection Rotate(GridDirection direction)
FroggieFrog marked this conversation as resolved.
Show resolved Hide resolved
{
return (GridDirection)((int)(direction + 1) % 4);
}
}
}
5 changes: 3 additions & 2 deletions AnnoDesigner/Helper/RoadSearchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public static Moved2DArray<AnnoObject> PrepareGridDictionary(IEnumerable<AnnoObj

// make an array with one free grid cell on each edge
var countY = (int)(statistics.MaxY - statistics.MinY + 2);
var result = Enumerable.Range(0, (int)(statistics.MaxX - statistics.MinX + 2))
var countX = (int)(statistics.MaxX - statistics.MinX + 2);
var result = Enumerable.Range(0, countX)
.Select(i => new AnnoObject[countY])
.ToArray();
.ToArrayWithCapacity(countX);

Parallel.ForEach(placedObjects, placedObject =>
{
Expand Down
20 changes: 13 additions & 7 deletions AnnoDesigner/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "There are unsaved changes",
["UnsavedChangedBeforeCrash"] = "Program crashed but there are unsaved changes",
["ColorPresetsVersion"] = "Color Presets Version",
["TreeLocalizationVersion"] = "Tree Localization Version"
["TreeLocalizationVersion"] = "Tree Localization Version",
["ShowHarborBlockedArea"] = "Show Harbor Areas"
},
["ger"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -438,7 +439,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "Es gibt nicht gespeicherte Änderungen",
["UnsavedChangedBeforeCrash"] = "Die Anwendung ist abgestürzt, aber es gibt nicht gespeicherte Änderungen.",
["ColorPresetsVersion"] = "Farbvorlagenversion",
["TreeLocalizationVersion"] = "Übersetzungsversion"
["TreeLocalizationVersion"] = "Übersetzungsversion",
["ShowHarborBlockedArea"] = "Hafengebiete anzeigen"
},
["fra"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -631,7 +633,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "Il y a des changements non sauvés",
["UnsavedChangedBeforeCrash"] = "Le programme a planté mais il y a des modifications non sauvegardées.",
["ColorPresetsVersion"] = "Version des préréglages de couleur",
["TreeLocalizationVersion"] = "Version de la localisation de l'arbre"
["TreeLocalizationVersion"] = "Version de la localisation de l'arbre",
["ShowHarborBlockedArea"] = "Afficher les zones portuaires"
},
["esp"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -690,7 +693,7 @@ public static void Init(ICommons commons)
["Both"] = "Ambos",
["PavedStreet"] = "Calle pavimentada",
["PavedStreetWarningTitle"] = "Selección de calles pavimentadas",
["PavedStreetToolTip"] = $"Marcando esta opción se cambiará el alcance de influencia de los edificios,{Environment.NewLine}representando el mayor alcance que reciben al utilizar calles pavimentadas.{Environment.NewLine}Usa el botón 'Colocar edificio' para colocar un objeto.",
["PavedStreetToolTip"] = $"Marcando esta opción se cambiará el alcance de influencia de los edificios,{Environment.NewLine}representando el mayor alcance que reciben al utilizar calles pavimentadas.{Environment.NewLine}Usa el botón \"Colocar edificio\" para colocar un objeto.",
["Options"] = "Opciones",
["EnableLabel"] = "Activar etiquetas",
["Borderless"] = "Sin bordes",
Expand Down Expand Up @@ -824,7 +827,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "Hay cambios no guardados",
["UnsavedChangedBeforeCrash"] = "El programa se ha interrumpido pero hay cambios no guardados",
["ColorPresetsVersion"] = "Versión de preajustes de color",
["TreeLocalizationVersion"] = "Versión de localización del árbol"
["TreeLocalizationVersion"] = "Versión de localización del árbol",
["ShowHarborBlockedArea"] = "Mostrar zonas portuarias"
},
["pol"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -1017,7 +1021,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "Istnieją niezbawione zmiany",
["UnsavedChangedBeforeCrash"] = "Program zawiesił się, ale są niezapisane zmiany",
["ColorPresetsVersion"] = "Presety kolorów Wersja",
["TreeLocalizationVersion"] = "Wersja lokalizacji drzewa"
["TreeLocalizationVersion"] = "Wersja lokalizacji drzewa",
["ShowHarborBlockedArea"] = "Pokaż obszary portowe"
},
["rus"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -1210,7 +1215,8 @@ public static void Init(ICommons commons)
["UnsavedChanged"] = "Есть неспасенные изменения",
["UnsavedChangedBeforeCrash"] = "Программа аварийно завершена, но есть несохраненные изменения",
["ColorPresetsVersion"] = "Версия предустановок цвета",
["TreeLocalizationVersion"] = "Версия локализации деревьев"
["TreeLocalizationVersion"] = "Версия локализации деревьев",
["ShowHarborBlockedArea"] = "Показать районы гавани"
},
};

Expand Down
3 changes: 3 additions & 0 deletions AnnoDesigner/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
<MenuItem Header="{l:Localize ShowInfluences}"
IsCheckable="True"
IsChecked="{Binding CanvasShowInfluences}" />
<MenuItem Header="{l:Localize ShowHarborBlockedArea}"
IsCheckable="True"
IsChecked="{Binding CanvasShowHarborBlockedArea}" />
</MenuItem>
<MenuItem Header="{l:Localize Tools}">
<MenuItem Header="{l:Localize Normalize}"
Expand Down
6 changes: 6 additions & 0 deletions AnnoDesigner/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public bool ShowInfluences
set => Settings.Default.ShowInfluences = value;
}

public bool ShowHarborBlockedArea
{
get => Settings.Default.ShowHarborBlockedArea;
set => Settings.Default.ShowHarborBlockedArea = value;
}

public bool IsPavedStreet
{
get => Settings.Default.IsPavedStreet;
Expand Down
1 change: 1 addition & 0 deletions AnnoDesigner/Models/IAnnoCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface IAnnoCanvas : IHotkeySource
bool RenderGrid { get; set; }
bool RenderInfluences { get; set; }
bool RenderTrueInfluenceRange { get; set; }
bool RenderHarborBlockedArea { get; set; }

bool RenderLabel { get; set; }
bool RenderIcon { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions AnnoDesigner/Models/ICoordinateHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using AnnoDesigner.Core.Models;

namespace AnnoDesigner.Models
{
Expand All @@ -16,6 +17,8 @@ public interface ICoordinateHelper

Rect Rotate(Rect rect);

GridDirection Rotate(GridDirection direction);

double RoundScreenToGrid(double screenLength, int gridStep);

Point RoundScreenToGrid(Point screenPoint, int gridStep);
Expand Down
Loading