Skip to content
10 changes: 9 additions & 1 deletion Mappy/Models/FeatureViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public sealed class FeatureViewViewModel : ISectionViewViewModel, IDisposable

private readonly FeatureService featureService;

public FeatureViewViewModel(FeatureService featureService)
private readonly Dispatcher dispatcher;

public FeatureViewViewModel(FeatureService featureService, Dispatcher dispatcher)
{
featureService.FeaturesChanged += this.OnFeaturesChanged;

Expand Down Expand Up @@ -58,6 +60,7 @@ public FeatureViewViewModel(FeatureService featureService)
.Subscribe(_ => this.UpdateFeatures());

this.featureService = featureService;
this.dispatcher = dispatcher;
}

public IObservable<ComboBoxViewModel> ComboBox1Model => this.worlds;
Expand All @@ -76,6 +79,11 @@ public void SelectComboBox2Item(int index)
this.selectCategoryEvent.OnNext(index);
}

public void SetSelectedItem(string featureName)
{
this.dispatcher.SetSelectedFeature(featureName);
}

public void Dispose()
{
this.worlds.Dispose();
Expand Down
4 changes: 3 additions & 1 deletion Mappy/Models/IMapViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public interface IMapViewViewModel

IObservable<Point> ViewportLocation { get; }

void MouseDown(Point location);
void MouseLeftDown(Point location);

void MouseRightDown(Point location);

void MouseMove(Point locattion);

Expand Down
2 changes: 2 additions & 0 deletions Mappy/Models/ISectionViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface ISectionViewViewModel
void SelectComboBox1Item(int index);

void SelectComboBox2Item(int index);

void SetSelectedItem(string selectedItemName);
}
}
18 changes: 17 additions & 1 deletion Mappy/Models/MapViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void ScrollPositionChanged(Point position)
this.dispatcher.SetViewportLocation(position);
}

public void MouseDown(Point location)
public void MouseLeftDown(Point location)
{
this.mouseDown = true;
this.lastMousePos = location;
Expand All @@ -207,6 +207,22 @@ public void MouseDown(Point location)
}
}

public void MouseRightDown(Point location)
{
this.mouseDown = true;
this.lastMousePos = location;

if (!this.itemsLayer.Value.IsInSelection(location.X, location.Y) &&
this.featureService.SelectedFeature != null)
{
this.dispatcher.DragDropFeature(
this.featureService.SelectedFeature.Name,
location.X,
location.Y
);
}
}

public void MouseMove(Point location)
{
this.dispatcher.UpdateMousePosition(Maybe.Return(location));
Expand Down
10 changes: 9 additions & 1 deletion Mappy/Models/SectionViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public sealed class SectionViewViewModel : ISectionViewViewModel, IDisposable

private readonly SectionService sectionService;

public SectionViewViewModel(SectionService sectionService)
private readonly Dispatcher dispatcher;

public SectionViewViewModel(SectionService sectionService, Dispatcher dispatcher)
{
sectionService.SectionsChanged += this.OnSectionsChanged;

Expand All @@ -44,6 +46,7 @@ public SectionViewViewModel(SectionService sectionService)
});

this.sectionService = sectionService;
this.dispatcher = dispatcher;
}

public IObservable<ComboBoxViewModel> ComboBox1Model => this.worlds;
Expand All @@ -62,6 +65,11 @@ public void SelectComboBox2Item(int index)
this.selectCategoryEvent.OnNext(index);
}

public void SetSelectedItem(string sectionName)
{
// this.dispatcher.SetSelectedSection(sectionName);
}

public void Dispose()
{
this.worlds.Dispose();
Expand Down
4 changes: 2 additions & 2 deletions Mappy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static void Main()
tileCache);
mainForm.SetModel(new MainFormViewModel(model, dispatcher, featureService));

mainForm.SectionView.SetModel(new SectionViewViewModel(sectionsService));
mainForm.FeatureView.SetModel(new FeatureViewViewModel(featureService));
mainForm.SectionView.SetModel(new SectionViewViewModel(sectionsService, dispatcher));
mainForm.FeatureView.SetModel(new FeatureViewViewModel(featureService, dispatcher));

mainForm.MapViewPanel.SetModel(new MapViewViewModel(model, dispatcher, featureService));

Expand Down
9 changes: 9 additions & 0 deletions Mappy/Services/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ public void SelectStartPosition(int index)
this.model.Map.IfSome(x => x.SelectStartPosition(index));
}

public void SetSelectedFeature(string featureName)
{
var featureFromTag = this.featureService.TryGetFeature(featureName);
if (featureFromTag.HasValue)
{
this.featureService.SelectedFeature = featureFromTag.UnsafeValue;
}
}

private static IEnumerable<string> GetMapNames(HpiArchive hpi)
{
return hpi.GetFiles("maps")
Expand Down
86 changes: 44 additions & 42 deletions Mappy/Services/FeatureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public FeatureService()

public event EventHandler FeaturesChanged;

public Feature SelectedFeature { get; set; }

public void AddFeatures(IEnumerable<FeatureInfo> features)
{
foreach (var f in features)
Expand Down Expand Up @@ -88,31 +90,31 @@ private static OffsetBitmap LoadRenderFile(HpiArchive archive, HpiArchive.FileIn

private static OffsetBitmap LoadBitmap(GafEntry[] gaf, string sequenceName)
{
var entry = gaf.FirstOrDefault(
x => string.Equals(x.Name, sequenceName, StringComparison.OrdinalIgnoreCase));
if (entry == null)
{
// skip if the sequence is not in this gaf file
return null;
}
var entry = gaf.FirstOrDefault(
x => string.Equals(x.Name, sequenceName, StringComparison.OrdinalIgnoreCase));
if (entry == null)
{
// skip if the sequence is not in this gaf file
return null;
}

var frame = entry.Frames[0];
var frame = entry.Frames[0];

Bitmap bmp;
if (frame.Data == null || frame.Width == 0 || frame.Height == 0)
{
bmp = new Bitmap(50, 50);
}
else
{
bmp = BitmapConvert.ToBitmap(
frame.Data,
frame.Width,
frame.Height,
frame.TransparencyIndex);
}
Bitmap bmp;
if (frame.Data == null || frame.Width == 0 || frame.Height == 0)
{
bmp = new Bitmap(50, 50);
}
else
{
bmp = BitmapConvert.ToBitmap(
frame.Data,
frame.Width,
frame.Height,
frame.TransparencyIndex);
}

return new OffsetBitmap(-frame.OffsetX, -frame.OffsetY, bmp);
return new OffsetBitmap(-frame.OffsetX, -frame.OffsetY, bmp);
}

private static GafEntry[] LoadGafEntries(HpiArchive.FileInfo fileInfo, HpiArchive archive)
Expand Down Expand Up @@ -193,16 +195,16 @@ private IEnumerable<Feature> EnumerateFeaturesFromInternal(IEnumerable<KeyValueP
}

var f = new Feature
{
Name = item.Value.Name,
World = item.Value.World,
Category = item.Value.Category,
Footprint = item.Value.Footprint,
Image = bitmap.Bitmap,
Offset = new Point(-bitmap.OffsetX, -bitmap.OffsetY),
ReclaimInfo = item.Value.ReclaimInfo,
Permanent = item.Value.Permanent,
};
{
Name = item.Value.Name,
World = item.Value.World,
Category = item.Value.Category,
Footprint = item.Value.Footprint,
Image = bitmap.Bitmap,
Offset = new Point(-bitmap.OffsetX, -bitmap.OffsetY),
ReclaimInfo = item.Value.ReclaimInfo,
Permanent = item.Value.Permanent,
};
this.featureCache.Add(item.Key, f);
yield return f;
}
Expand All @@ -220,16 +222,16 @@ private IEnumerable<Feature> EnumerateFeaturesFromInternal(IEnumerable<KeyValueP
var bitmap = LoadRenderFile(archive, objectFile);

var f = new Feature
{
Name = entry.Value.Name,
World = entry.Value.World,
Category = entry.Value.Category,
Footprint = entry.Value.Footprint,
Image = bitmap.Bitmap,
Offset = new Point(-bitmap.OffsetX, -bitmap.OffsetY),
ReclaimInfo = entry.Value.ReclaimInfo,
Permanent = entry.Value.Permanent,
};
{
Name = entry.Value.Name,
World = entry.Value.World,
Category = entry.Value.Category,
Footprint = entry.Value.Footprint,
Image = bitmap.Bitmap,
Offset = new Point(-bitmap.OffsetX, -bitmap.OffsetY),
ReclaimInfo = entry.Value.ReclaimInfo,
Permanent = entry.Value.Permanent,
};
this.featureCache.Add(entry.Key, f);
yield return f;
}
Expand Down
25 changes: 17 additions & 8 deletions Mappy/UI/Controls/DoubleComboListView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Mappy/UI/Controls/DoubleComboListView.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
namespace Mappy.UI.Controls
{
using System.Drawing;
using System.Windows.Forms;

public partial class DoubleComboListView : UserControl
{
private readonly Pen selectionPen;
private readonly Pen defaultPen;

private ListViewItem previousSelection;

public DoubleComboListView()
{
this.InitializeComponent();
this.selectionPen = new Pen(Color.Red, 3);
this.defaultPen = new Pen(Color.White, 3);
}

public ComboBox ComboBox1 => this.comboBox1;

public ComboBox ComboBox2 => this.comboBox2;

public ListView ListView => this.listView1;

private void ListView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
e.DrawDefault = true;
}

private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawDefault = true;
if (e.Item.Selected)
{
e.Graphics.DrawRectangle(this.selectionPen, e.Bounds);
this.previousSelection = e.Item;
}
else if (sender is ListView && ((ListView)sender).SelectedItems.Count <= 0 &&
this.previousSelection != null && this.previousSelection.Index == e.Item.Index)
{
e.Graphics.DrawRectangle(this.selectionPen, this.previousSelection.Bounds);
}
else
{
e.Graphics.DrawRectangle(this.defaultPen, e.Bounds);
}
}

private void ListView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
this.ListView.Refresh();
}
}
}
9 changes: 8 additions & 1 deletion Mappy/UI/Controls/MapViewPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ private void MapViewDragDrop(object sender, DragEventArgs e)
private void MapViewMouseDown(object sender, MouseEventArgs e)
{
var loc = this.mapView.ToVirtualPoint(e.Location);
this.model.MouseDown(loc);
if (e.Button == MouseButtons.Left)
{
this.model.MouseLeftDown(loc);
}
else if (e.Button == MouseButtons.Right)
{
this.model.MouseRightDown(loc);
}
}

private void MapViewMouseMove(object sender, MouseEventArgs e)
Expand Down
Loading