add button to go from table tool to new tool

This commit is contained in:
haven1433
2022-11-06 22:34:07 -06:00
parent d23575cdb9
commit cc18f7944f
6 changed files with 76 additions and 7 deletions

View File

@@ -92,7 +92,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
var maps = banks[i].GetSubTable("maps");
if (maps == null) continue;
for (int j = 0; j < maps.Count; j++) {
var mapText = "maps." + BlockMapViewModel.MapIDToText(model, i * 1000 + j);
var mapText = "maps." + BlockMapViewModel.MapIDToText(model, i, j);
results.Add(new(i, j, mapText));
}
}

View File

@@ -318,9 +318,15 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
var allMaps = model.CurrentCacheScope?.GetAllMaps();
var results = allMaps?.Where(map => map.Name.MatchesPartial(text)).ToList() ?? new();
return //*
new() /*/ results //*/
;
//*
return new();
/*/
var lower = text.ToLower();
foreach (var result in results) {
if (result.Name.ToLower() == lower) return new() { result };
}
return results;
//*/
}
}

View File

@@ -1,17 +1,39 @@
using HavenSoft.HexManiac.Core.Models;
using HavenSoft.HexManiac.Core.Models.Runs;
using HavenSoft.HexManiac.Core.Models.Runs.Factory;
using HavenSoft.HexManiac.Core.Models.Runs.Sprites;
using HavenSoft.HexManiac.Core.ViewModels.Images;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows.Input;
namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
public class SpriteIndicatorElementViewModel : ViewModelCore, IArrayElementViewModel {
public IPixelViewModel Image { get; private set; }
private bool visible;
public bool Visible { get => visible; set => Set(ref visible, value); }
public bool IsInError => false;
public string ErrorText => string.Empty;
public int ZIndex => 1;
public event EventHandler DataChanged;
public event EventHandler DataSelected;
public SpriteIndicatorElementViewModel(IPixelViewModel image) => Image = image;
public bool TryCopy(IArrayElementViewModel other) {
if (other is not SpriteIndicatorElementViewModel indicator) return false;
Image = indicator.Image;
NotifyPropertyChanged(nameof(Image));
return true;
}
}
public class SpriteElementViewModel : PagedElementViewModel, IPixelViewModel {
private SpriteFormat format;

View File

@@ -1,6 +1,5 @@
using HavenSoft.HexManiac.Core.Models;
using HavenSoft.HexManiac.Core.Models.Runs;
using HavenSoft.HexManiac.Core.Models.Runs.Factory;
using HavenSoft.HexManiac.Core.ViewModels.DataFormats;
using System;
using System.Collections.Generic;

View File

@@ -1,7 +1,11 @@
using HavenSoft.HexManiac.Core.Models;
using HavenSoft.HexManiac.Core.Models.Map;
using HavenSoft.HexManiac.Core.Models.Runs;
using HavenSoft.HexManiac.Core.Models.Runs.Sprites;
using HavenSoft.HexManiac.Core.ViewModels.DataFormats;
using HavenSoft.HexManiac.Core.ViewModels.Images;
using HavenSoft.HexManiac.Core.ViewModels.Map;
using HexManiac.Core.Models.Runs.Sprites;
using System;
using System.Collections.ObjectModel;
using System.Linq;
@@ -101,6 +105,41 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
}
itemAddress += item.Length;
}
AddAdhocSpecialElementsToGroup(viewPort, table);
}
private void AddAdhocSpecialElementsToGroup(IViewPort viewPort, ITableRun table) {
if (table.ElementContent.Count == 14 && table.ElementCount == 1 && table.ElementContent.Select(seg => seg.Type).ToArray().SequenceEqual(new[] {
ElementContentType.Pointer, ElementContentType.Pointer, ElementContentType.Pointer, ElementContentType.Pointer,
ElementContentType.Integer, ElementContentType.Integer, ElementContentType.Integer, ElementContentType.Integer,
ElementContentType.Integer, ElementContentType.Integer, ElementContentType.Integer, ElementContentType.Integer,
ElementContentType.Integer, ElementContentType.Integer,
})) {
AddAdhocMapElementsToGroup(viewPort, table);
}
}
private void AddAdhocMapElementsToGroup(IViewPort viewPort, ITableRun table) {
var model = viewPort.Model;
if (table.PointerSources == null || table.PointerSources.Count != 1) return;
var addressInBankTable = table.PointerSources[0];
var bankTable = model.GetNextRun(addressInBankTable) as ITableRun;
if (bankTable == null || bankTable.PointerSources == null || bankTable.PointerSources.Count != 1) return;
var topTable = model.GetNextRun(bankTable.PointerSources[0]) as ITableRun;
if (topTable == null) return;
var bankOffset = topTable.ConvertByteOffsetToArrayOffset(bankTable.PointerSources[0]);
var mapOffset = bankTable.ConvertByteOffsetToArrayOffset(addressInBankTable);
var (bank, map) = (bankOffset.ElementIndex, mapOffset.ElementIndex);
var name = "maps." + BlockMapViewModel.MapIDToText(model, bank, map);
var matches = model.GetMatchingMaps(name);
if (matches.Count != 1) return;
var mapModel = new MapModel(new ModelArrayElement(model, table.Start, 0, () => viewPort.ChangeHistory.CurrentChange, table));
if (model.GetNextRun(mapModel.Layout.BlockMap.Start) is BlockmapRun blockmapRun) {
var image = (CanvasPixelViewModel)model.CurrentCacheScope.GetImage(blockmapRun);
image.SpriteScale = 128.0 / Math.Max(image.PixelWidth, image.PixelHeight);
Add(new SpriteIndicatorElementViewModel(image));
}
Add(new ButtonArrayElementViewModel("Edit Map", () => viewPort.Goto.Execute(name)));
}
private void AddChildrenFromPointerSegment(ViewPort viewPort, int itemAddress, ArrayRunElementSegment item, IArrayElementViewModel parent, int recursionLevel) {

View File

@@ -543,6 +543,9 @@
</Grid>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type hsg3hvmtr:SpriteIndicatorElementViewModel}">
<hsg3hv:PixelImage Visibility="{Binding Visible, Converter={StaticResource BoolToVisibility}}" SnapsToDevicePixels="True" DataContext="{Binding Image}" />
</DataTemplate>
<DataTemplate DataType="{x:Type hsg3hvmtr:PaletteElementViewModel}">
<StackPanel PreviewMouseDown="ActivatePalette" Visibility="{Binding Visible, Converter={StaticResource BoolToVisibility}}">
<hsg3hv:CommonTableStreamControl />