Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions NodeMarkup/Manager/MarkupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public TypeMarkup this[ushort id]
return markup;
}
}

public bool HasMarkup(ushort id) => Markups.ContainsKey(id);

protected abstract TypeMarkup NewMarkup(ushort id);

protected abstract void AddToUpdate(ushort id);
Expand Down
4 changes: 2 additions & 2 deletions NodeMarkup/Markup/Line/Style/LineStyleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public abstract class RegularLineStyle : LineStyle<RegularLineStyle>
public static Dictionary<RegularLineType, RegularLineStyle> Defaults { get; } = new Dictionary<RegularLineType, RegularLineStyle>()
{
{RegularLineType.Solid, new SolidLineStyle(DefaultColor, DefaultWidth)},
{RegularLineType.Dashed, new DashedLineStyle(DefaultColor, DefaultWidth, DefaultDashLength, DefaultSpaceLength)},
{RegularLineType.Dashed, new DashedLineStyle(DefaultColor, DefaultWidth, DefaultDashLength, DefaultSpaceLength, DefaultBackgroundEnabled, DefaultBackgroundColor)},
{RegularLineType.DoubleSolid, new DoubleSolidLineStyle(DefaultColor, DefaultWidth, DefaultDoubleOffset)},
{RegularLineType.DoubleDashed, new DoubleDashedLineStyle(DefaultColor, DefaultWidth, DefaultDashLength, DefaultSpaceLength, DefaultDoubleOffset)},
{RegularLineType.DoubleDashed, new DoubleDashedLineStyle(DefaultColor, DefaultWidth, DefaultDashLength, DefaultSpaceLength, DefaultDoubleOffset, DefaultBackgroundEnabled, DefaultBackgroundColor)},
{RegularLineType.SolidAndDashed, new SolidAndDashedLineStyle(DefaultColor, DefaultWidth, DefaultDashLength, DefaultSpaceLength, DefaultDoubleOffset)},
{RegularLineType.SharkTeeth, new SharkTeethLineStyle(DefaultColor, DefaultSharkBaseLength, DefaultSharkHeight, DefaultSharkSpaceLength) },
{RegularLineType.Pavement, new PavementLineStyle(Default3DWidth, Default3DHeigth) },
Expand Down
103 changes: 98 additions & 5 deletions NodeMarkup/Markup/Line/Style/RegularLineStyles2D.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ColossalFramework.UI;
using ModsCommon;
using ModsCommon.UI;
using ModsCommon.Utilities;
using NodeMarkup.Utilities;
Expand Down Expand Up @@ -105,14 +106,18 @@ public class DashedLineStyle : RegularLineStyle, IRegularLine, IDashedLine

public PropertyValue<float> DashLength { get; }
public PropertyValue<float> SpaceLength { get; }
public PropertyValue<bool> BackgroundEnabled { get; }
public PropertyColorValue BackgroundColor { get; }

public DashedLineStyle(Color32 color, float width, float dashLength, float spaceLength) : base(color, width)
public DashedLineStyle(Color32 color, float width, float dashLength, float spaceLength, bool backgroundEnabled, Color32 backgroundColor) : base(color, width)
{
DashLength = GetDashLengthProperty(dashLength);
SpaceLength = GetSpaceLengthProperty(spaceLength);
BackgroundEnabled = GetBackgroundEnabled(backgroundEnabled);
BackgroundColor = GetBackgroundColor(backgroundColor);
}

public override RegularLineStyle CopyLineStyle() => new DashedLineStyle(Color, Width, DashLength, SpaceLength);
public override RegularLineStyle CopyLineStyle() => new DashedLineStyle(Color, Width, DashLength, SpaceLength, BackgroundEnabled, BackgroundColor);
public override void CopyTo(LineStyle target)
{
base.CopyTo(target);
Expand All @@ -129,7 +134,15 @@ protected override IStyleData Calculate(MarkupRegularLine line, ITrajectory traj
return new MarkupStyleParts();

var borders = line.Borders;
return new MarkupStyleParts(StyleHelper.CalculateDashed(trajectory, DashLength, SpaceLength, GetDashes));
var parts = new List<MarkupStylePart>();
if (BackgroundEnabled)
parts.AddRange(StyleHelper.CalculateSolid(trajectory, lod, CalculateSolidDash));
parts.AddRange(StyleHelper.CalculateDashed(trajectory, DashLength, SpaceLength, GetDashes));

return new MarkupStyleParts(parts);

IEnumerable<MarkupStylePart> CalculateSolidDash(ITrajectory lineTrajectory)
=> CalculateSolid(trajectory, borders);

IEnumerable<MarkupStylePart> GetDashes(ITrajectory trajectory, float startT, float endT)
=> CalculateDashes(trajectory, startT, endT, borders);
Expand All @@ -141,25 +154,67 @@ protected virtual IEnumerable<MarkupStylePart> CalculateDashes(ITrajectory traje
yield return dash;
}

protected virtual IEnumerable<MarkupStylePart> CalculateSolid(ITrajectory trajectory, LineBorders borders)
{
if (StyleHelper.CalculateSolidPart(borders, trajectory, 0, Width, BackgroundColor, out MarkupStylePart back))
yield return back;
}

public override void GetUIComponents(MarkupRegularLine line, List<EditorItem> components, UIComponent parent, bool isTemplate = false)
{
base.GetUIComponents(line, components, parent, isTemplate);
components.Add(AddDashLengthProperty(this, parent));
components.Add(AddSpaceLengthProperty(this, parent));

var backgroundBool = AddBoolProperty(parent);
var backgroundColor = AddColorProperty(parent);
backgroundBool.OnSelectObjectChanged += ChangeBackgroundColorVisible;
ChangeBackgroundColorVisible(backgroundBool.SelectedObject);
components.Add(backgroundBool);
components.Add(backgroundColor);

BoolListPropertyPanel AddBoolProperty(UIComponent parent)
{
var boolProperty = ComponentPool.GetBefore<BoolListPropertyPanel>(parent, nameof(BackgroundColor), nameof(BackgroundEnabled));
boolProperty.Text = Localize.StyleOption_BackgroundEnabled;
boolProperty.Init(Localize.StyleOption_No, Localize.StyleOption_Yes, false);
boolProperty.SelectedObject = BackgroundEnabled;
boolProperty.OnSelectObjectChanged += (value) => BackgroundEnabled.Value = value;

return boolProperty;
}

UI.ColorAdvancedPropertyPanel AddColorProperty(UIComponent parent)
{
var colorProperty = ComponentPool.Get<UI.ColorAdvancedPropertyPanel>(parent, nameof(BackgroundColor));
colorProperty.Text = Localize.StyleOption_BackgroundColor;
colorProperty.WheelTip = Settings.ShowToolTip;
colorProperty.Init();
colorProperty.Value = BackgroundColor;
colorProperty.OnValueChanged += (Color32 color) => BackgroundColor.Value = color;

return colorProperty;
}

void ChangeBackgroundColorVisible(bool useSecondColor) => backgroundColor.isVisible = useSecondColor;
}

public override XElement ToXml()
{
var config = base.ToXml();
DashLength.ToXml(config);
SpaceLength.ToXml(config);
BackgroundEnabled.ToXml(config);
BackgroundColor.ToXml(config);
return config;
}
public override void FromXml(XElement config, ObjectsMap map, bool invert)
{
base.FromXml(config, map, invert);
DashLength.FromXml(config, DefaultDashLength);
SpaceLength.FromXml(config, DefaultSpaceLength);
BackgroundEnabled.FromXml(config, BackgroundEnabled);
BackgroundColor.FromXml(config, BackgroundColor);
}
}
public class DoubleDashedLineStyle : DashedLineStyle, IRegularLine, IDoubleLine, IDoubleAlignmentLine
Expand All @@ -169,13 +224,13 @@ public class DoubleDashedLineStyle : DashedLineStyle, IRegularLine, IDoubleLine,
public PropertyValue<float> Offset { get; }
public PropertyEnumValue<Alignment> Alignment { get; }

public DoubleDashedLineStyle(Color32 color, float width, float dashLength, float spaceLength, float offset) : base(color, width, dashLength, spaceLength)
public DoubleDashedLineStyle(Color32 color, float width, float dashLength, float spaceLength, float offset, bool backgroundEnabled, Color32 backgroundColor) : base(color, width, dashLength, spaceLength, backgroundEnabled, backgroundColor)
{
Offset = GetOffsetProperty(offset);
Alignment = GetAlignmentProperty(Manager.Alignment.Centre);
}

public override RegularLineStyle CopyLineStyle() => new DoubleDashedLineStyle(Color, Width, DashLength, SpaceLength, Offset);
public override RegularLineStyle CopyLineStyle() => new DoubleDashedLineStyle(Color, Width, DashLength, SpaceLength, Offset, BackgroundEnabled, BackgroundColor);
public override void CopyTo(LineStyle target)
{
base.CopyTo(target);
Expand Down Expand Up @@ -208,6 +263,44 @@ protected override IEnumerable<MarkupStylePart> CalculateDashes(ITrajectory traj
if (StyleHelper.CalculateDashedParts(borders, trajectory, startT, endT, DashLength, secondOffset, Width, Color, out MarkupStylePart secondDash))
yield return secondDash;
}

protected override IEnumerable<MarkupStylePart> CalculateSolid(ITrajectory trajectory, LineBorders borders)
{
var firstOffset = Alignment.Value switch
{
Manager.Alignment.Left => 2 * Offset,
Manager.Alignment.Centre => Offset,
Manager.Alignment.Right => 0,
_ => 0,
};
var secondOffset = Alignment.Value switch
{
Manager.Alignment.Left => 0,
Manager.Alignment.Centre => -Offset,
Manager.Alignment.Right => -2 * Offset,
_ => 0,
};

if (StyleHelper.CalculateSolidPart(borders, trajectory, firstOffset, Width, BackgroundColor, out MarkupStylePart firstBack))
yield return firstBack;

if (StyleHelper.CalculateSolidPart(borders, trajectory, secondOffset, Width, BackgroundColor, out MarkupStylePart secondBack))
yield return secondBack;
}

//public static MarkupStylePart CalculateDashedPart(ITrajectory trajectory, float startT, float endT, float dashLength, float offset, float width, Color32 color)
//{
// if (offset == 0)
// return CalculateDashedPart(trajectory, startT, endT, dashLength, Vector3.zero, Vector3.zero, width, color);
// else
// {
// var startOffset = trajectory.Tangent(startT).Turn90(true).normalized * offset;
// var endOffset = trajectory.Tangent(endT).Turn90(true).normalized * offset;
// return CalculateDashedPart(trajectory, startT, endT, dashLength, startOffset, endOffset, width, color);
// }
//}


public override void GetUIComponents(MarkupRegularLine line, List<EditorItem> components, UIComponent parent, bool isTemplate = false)
{
base.GetUIComponents(line, components, parent, isTemplate);
Expand Down
4 changes: 4 additions & 0 deletions NodeMarkup/Markup/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private static int TypeToInt(StyleType type)
}

public static Color32 DefaultColor { get; } = new Color32(136, 136, 136, 224);
public static Color32 DefaultBackgroundColor { get; } = new Color32(102, 102, 102, 255);
public static bool DefaultBackgroundEnabled { get; } = false;
public static float DefaultWidth { get; } = 0.15f;

protected virtual float WidthWheelStep { get; } = 0.01f;
Expand Down Expand Up @@ -226,6 +228,8 @@ protected ButtonPanel AddInvertProperty(IAsymLine asymStyle, UIComponent parent)
protected PropertyStructValue<float> GetLineWidthProperty(float defaultValue) => new PropertyStructValue<float>("LW", StyleChanged, defaultValue);
protected PropertyBoolValue GetParallelProperty(bool defaultValue) => new PropertyBoolValue("P", StyleChanged, defaultValue);
protected PropertyBoolValue GetUseSecondColorProperty(bool defaultValue) => new PropertyBoolValue("USC", StyleChanged, defaultValue);
protected PropertyBoolValue GetBackgroundEnabled(bool defaultValue) => new PropertyBoolValue("BGE", StyleChanged, defaultValue);
protected PropertyColorValue GetBackgroundColor(Color32 defaultValue) => new PropertyColorValue("BGC", StyleChanged, defaultValue);
protected PropertyStructValue<float> GetSquareSideProperty(float defaultValue) => new PropertyStructValue<float>("SS", StyleChanged, defaultValue);
protected PropertyStructValue<int> GetLineCountProperty(int defaultValue) => new PropertyStructValue<int>("LC", StyleChanged, defaultValue);
protected PropertyStructValue<float> GetAngleProperty(float defaultValue) => new PropertyStructValue<float>("A", StyleChanged, defaultValue);
Expand Down
3 changes: 2 additions & 1 deletion NodeMarkup/NodeMarkup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<Compile Include="Utilities\VersionMigration.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Localize.sk.resx" />
<EmbeddedResource Include="Properties\Localize.cs.resx" />
<EmbeddedResource Include="Properties\Localize.de.resx" />
<EmbeddedResource Include="Properties\Localize.en-GB.resx" />
Expand Down Expand Up @@ -326,7 +327,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_StartDate="2000/1/1" BuildVersion_ConfigurationName="Beta Debug" BuildVersion_DetectChanges="False" />
<UserProperties BuildVersion_DetectChanges="False" BuildVersion_ConfigurationName="Beta Debug" BuildVersion_StartDate="2000/1/1" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.None.Increment" />
</VisualStudio>
</ProjectExtensions>
<PropertyGroup Condition="'$(Configuration)' == 'Stable Release' OR '$(Configuration)' == 'Stable Debug'">
Expand Down
Loading