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

Update Preset Parser and Presets.json #356

Merged
merged 18 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions AnnoDesigner/Models/LayoutObject.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using AnnoDesigner.Core.Helper;
Expand All @@ -16,6 +13,7 @@ namespace AnnoDesigner.Models
/// This class is mainly for performance and a wrapper for <see cref="AnnoObject"/>.
/// It caches all kinds of Visuals (e.g. Brushes, Pens) and calculations (e.g. CollisionRect).
/// </summary>
[DebuggerDisplay("{" + nameof(Identifier) + "}")]
public class LayoutObject : IBounded
{
private AnnoObject _wrappedAnnoObject;
Expand Down Expand Up @@ -503,7 +501,7 @@ public double GetScreenRadius(int gridSize)
// See https://github.com/AnnoDesigner/anno-designer/issues/299 for an explanation of the issue.

// check if Object Width and Height are odd numbers or not, if both are, adjust the circle size with -0.1
if ((WrappedAnnoObject.Size.Width %2 != 0 ) && (WrappedAnnoObject.Size.Height %2 != 0))
if ((WrappedAnnoObject.Size.Width % 2 != 0) && (WrappedAnnoObject.Size.Height % 2 != 0))
{
_screenRadius = _coordinateHelper.GridToScreen(WrappedAnnoObject.Radius - 0.1, gridSize);
}
Expand Down
25 changes: 23 additions & 2 deletions AnnoDesigner/ViewModels/BuildingSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class BuildingSettingsViewModel : Notify
private string _buildingIdentifier;
private double _buildingRadius;
private double _buildingInfluenceRange;
private double _buildingBlockedAreaLength;
private double _buildingBlockedAreaWidth;
private GridDirection _buildingDirection;
private bool _isPavedStreet;
private bool _isEnableLabelChecked;
private bool _isBorderlessChecked;
Expand Down Expand Up @@ -154,6 +157,24 @@ public double BuildingInfluenceRange
set { UpdateProperty(ref _buildingInfluenceRange, value); }
}

public double BuildingBlockedAreaLength
{
get { return _buildingBlockedAreaLength; }
set { UpdateProperty(ref _buildingBlockedAreaLength, value); }
}

public double BuildingBlockedAreaWidth
{
get { return _buildingBlockedAreaWidth; }
set { UpdateProperty(ref _buildingBlockedAreaWidth, value); }
}

public GridDirection BuildingDirection
{
get { return _buildingDirection; }
set { UpdateProperty(ref _buildingDirection, value); }
}

public bool IsPavedStreet
{
get { return _isPavedStreet; }
Expand Down Expand Up @@ -359,7 +380,7 @@ private void ApplyColorToSelection(object param)
{
PropertyName = nameof(LayoutObject.Color),
ObjectPropertyValues = AnnoCanvasToUse.SelectedObjects
.Select(obj => (obj, obj.Color, selectedColor: (SerializableColor) SelectedColor.Value))
.Select(obj => (obj, obj.Color, selectedColor: (SerializableColor)SelectedColor.Value))
.ToList(),
AfterAction = ColorChangeUndone
});
Expand Down Expand Up @@ -393,7 +414,7 @@ private void ApplyPredefinedColorToSelection(object param)
PropertyName = nameof(LayoutObject.Color),
ObjectPropertyValues = AnnoCanvasToUse.SelectedObjects
.Where(obj => ColorPresetsHelper.Instance.GetPredefinedColor(obj.WrappedAnnoObject).HasValue)
.Select(obj => (obj, obj.Color, (SerializableColor) ColorPresetsHelper.Instance.GetPredefinedColor(obj.WrappedAnnoObject).Value))
.Select(obj => (obj, obj.Color, (SerializableColor)ColorPresetsHelper.Instance.GetPredefinedColor(obj.WrappedAnnoObject).Value))
.ToList(),
AfterAction = ColorChangeUndone
});
Expand Down
120 changes: 23 additions & 97 deletions AnnoDesigner/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public MainViewModel(ICommons commonsToUse,
Languages.Add(new SupportedLanguage("Español")
{
FlagPath = "Flags/Spain.png"
});
});
//Languages.Add(new SupportedLanguage("Italiano"));
//Languages.Add(new SupportedLanguage("český"));

Expand Down Expand Up @@ -349,7 +349,7 @@ private void ApplyCurrentObject()
{
// parse user inputs and create new object
string RenameBuildingIdentifier = BuildingSettingsViewModel.BuildingName;
string TextBoxText = "TextBox";
string TextBoxText = "UnknownObject";
var obj = new AnnoObject
{
Size = new Size(BuildingSettingsViewModel.BuildingWidth, BuildingSettingsViewModel.BuildingHeight),
Expand All @@ -362,7 +362,10 @@ private void ApplyCurrentObject()
Borderless = BuildingSettingsViewModel.IsBorderlessChecked,
Road = BuildingSettingsViewModel.IsRoadChecked,
Identifier = BuildingSettingsViewModel.BuildingIdentifier,
Template = BuildingSettingsViewModel.BuildingTemplate
Template = BuildingSettingsViewModel.BuildingTemplate,
BlockedAreaLength = BuildingSettingsViewModel.BuildingBlockedAreaLength,
BlockedAreaWidth = BuildingSettingsViewModel.BuildingBlockedAreaWidth,
Direction = BuildingSettingsViewModel.BuildingDirection
};

var objIconFileName = "";
Expand All @@ -382,117 +385,40 @@ private void ApplyCurrentObject()
// do some sanity checks
if (obj.Size.Width > 0 && obj.Size.Height > 0 && obj.Radius >= 0)
{
if (!string.IsNullOrWhiteSpace(obj.Icon) && !obj.Icon.Contains(IconFieldNamesCheck))
//gets icons and origin building info
var buildingInfo = AnnoCanvas.BuildingPresets.Buildings.FirstOrDefault(_ => _.IconFileName?.Equals(objIconFileName, StringComparison.OrdinalIgnoreCase) ?? false);
if (buildingInfo != null)
{
//the identifier text 'Uknown Object' is localized within the StatisticsView, which is why it's not localized here
//gets icons origin building info
var buildingInfo = AnnoCanvas.BuildingPresets.Buildings.FirstOrDefault(_ => _.IconFileName?.Equals(objIconFileName, StringComparison.OrdinalIgnoreCase) ?? false);
if (buildingInfo != null)
//Put in the Blocked Area if there is one
if (buildingInfo.BlockedAreaLength > 0)
{
obj.BlockedAreaLength = buildingInfo.BlockedAreaLength;
obj.BlockedAreaWidth = buildingInfo.BlockedAreaWidth;
obj.Direction = buildingInfo.Direction;

// Check X and Z Sizes of the Building Info, if one or both not right, the Object will be Unknown
//Building could be in rotated form - so 5x4 should be equivalent to checking for 4x5
if ((obj.Size.Width == buildingInfo.BuildBlocker["x"] && obj.Size.Height == buildingInfo.BuildBlocker["z"])
|| (obj.Size.Height == buildingInfo.BuildBlocker["x"] && obj.Size.Width == buildingInfo.BuildBlocker["z"]))
{
//if sizes match and icon is a existing building in the presets, call it that object
//Exception are all other Residences of Anno 1800, that change back to Farmer Resident names
if (obj.Identifier != "Residence_New_World" && obj.Identifier != "Residence_Arctic_World" && obj.Identifier != "Residence_Africa_World")
{
obj.Identifier = buildingInfo.Identifier;
if (BuildingSettingsViewModel.BuildingRealName != RenameBuildingIdentifier)
{
if (BuildingSettingsViewModel.IsEnableLabelChecked)
{
if (RenameBuildingIdentifier.Length > 30)
{
obj.Identifier = TextBoxText;
obj.Template = TextBoxText;
}
else
{
//Keep label, tempate and identifiername
}
}
else
{
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}
}
//If one of the other world residents then the OW Residents in Anno 1800 are renamed to other tiers names rename them.
if ((obj.Identifier == "Residence_New_World" || obj.Identifier == "Residence_Arctic_World" || obj.Identifier == "Residence_Africa_World") && BuildingSettingsViewModel.BuildingRealName != RenameBuildingIdentifier)
{
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}
else
{
//Sizes and icon do not match
//obj.Identifier = "Unknown Object";
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}
else if (!BuildingSettingsViewModel.BuildingTemplate.Contains("field", StringComparison.OrdinalIgnoreCase)) //check if the icon is removed from a template field
{
//obj.Identifier = "Unknown Object";
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}
else if (!string.IsNullOrWhiteSpace(obj.Icon) && obj.Icon.Contains(IconFieldNamesCheck))
{
//Check if Field Icon belongs to the field identifier, else set the official icon
var buildingInfo = AnnoCanvas.BuildingPresets.Buildings.FirstOrDefault(_ => _.Identifier == obj.Identifier);
if (buildingInfo != null)
{
if (!string.Equals(objIconFileName, buildingInfo.IconFileName, StringComparison.OrdinalIgnoreCase))
{
obj.Icon = buildingInfo.IconFileName.Remove(buildingInfo.IconFileName.Length - 4, 4); //remove the .png for the combobox
try
{
SelectedIcon = string.IsNullOrEmpty(obj.Icon) ? _noIconItem : AvailableIcons.Single(_ => _.Name == Path.GetFileNameWithoutExtension(obj.Icon));
}
catch (Exception)
{
SelectedIcon = _noIconItem;
}
}
}
else

//if user entered a new Label Name (as in renaming existing building or naming own building) then name and identifier will be renamed
if (BuildingSettingsViewModel.BuildingRealName != BuildingSettingsViewModel.BuildingName)
{
//obj.Identifier = "Unknown Object";
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}
if (string.IsNullOrEmpty(obj.Icon) && !BuildingSettingsViewModel.BuildingTemplate.Contains("field", StringComparison.OrdinalIgnoreCase))
else
{
if (BuildingSettingsViewModel.IsEnableLabelChecked)
//if no Identifier is found or if user entered a new Label Name (as in renaming existing building or naming own building) then name and identifier will be renamed
if (string.IsNullOrWhiteSpace(BuildingSettingsViewModel.BuildingIdentifier) || BuildingSettingsViewModel.BuildingRealName != BuildingSettingsViewModel.BuildingName)
{
if (RenameBuildingIdentifier.Length > 30)
if (!string.IsNullOrWhiteSpace(RenameBuildingIdentifier))
{
obj.Identifier = TextBoxText;
obj.Template = TextBoxText;
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
else
{
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
obj.Identifier = TextBoxText;
}
}
else
{
//obj.Identifier = "Unknown Object";
obj.Identifier = RenameBuildingIdentifier;
obj.Template = RenameBuildingIdentifier;
}
}

AnnoCanvas.SetCurrentObject(new LayoutObject(obj, _coordinateHelper, _brushCache, _penCache));
Expand Down Expand Up @@ -1239,9 +1165,9 @@ private void ExecuteLoadLayoutFromJsonSub(string jsonString, bool forceLoad = fa
AnnoCanvas.SelectedObjects.Clear();
AnnoCanvas.PlacedObjects.Clear();
AnnoCanvas.PlacedObjects.AddRange(loadedLayout.Objects.Select(x => new LayoutObject(x, _coordinateHelper, _brushCache, _penCache)));

AnnoCanvas.UndoManager.Clear();

AnnoCanvas.LoadedFile = string.Empty;
AnnoCanvas.Normalize(1);

Expand Down
Loading