From 477ebaed5a4304d1c04b9ff89f21f074a4530072 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 28 May 2020 18:19:02 -0400 Subject: [PATCH] preliminary implementation of New World Computing map editor for Heroes of Might and Magic II --- .../NewWorldComputing/Map/MapEditor.glade | 30 +++++ ...lEditor.Content.PlatformIndependent.csproj | 1 + .../Map/Controls/MapViewControl.cs | 108 ++++++++++++++++++ .../NewWorldComputing/Map/MapEditor.cs | 74 ++++++++++++ .../Properties/AssemblyInfo.cs | 46 ++++++++ ...ins.NewWorldComputing.UserInterface.csproj | 79 +++++++++++++ UniversalEditor.sln | 7 ++ 7 files changed, 345 insertions(+) create mode 100644 Content/UniversalEditor.Content.PlatformIndependent/Editors/NewWorldComputing/Map/MapEditor.glade create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/Controls/MapViewControl.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Properties/AssemblyInfo.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface.csproj diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/NewWorldComputing/Map/MapEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/NewWorldComputing/Map/MapEditor.glade new file mode 100644 index 00000000..82b06d86 --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/NewWorldComputing/Map/MapEditor.glade @@ -0,0 +1,30 @@ + + + + + + False + + + + + + True + False + vertical + + + UniversalEditor.Plugins.NewWorldComputing.UserInterface.Editors.NewWorldComputing.Map.Controls.MapViewControl + True + False + + + True + True + 0 + + + + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 0fc02b36..aaffcb62 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -739,6 +739,7 @@ + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/Controls/MapViewControl.cs b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/Controls/MapViewControl.cs new file mode 100644 index 00000000..53e92c55 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/Controls/MapViewControl.cs @@ -0,0 +1,108 @@ +// +// MapViewControl.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Drawing; +using UniversalEditor.Accessors; +using UniversalEditor.DataFormats.FileSystem.NewWorldComputing.AGG; +using UniversalEditor.DataFormats.Multimedia.Picture.NewWorldComputing.ICN; +using UniversalEditor.DataFormats.Multimedia.Picture.NewWorldComputing.TIL; +using UniversalEditor.ObjectModels.FileSystem; +using UniversalEditor.ObjectModels.Multimedia.Picture; +using UniversalEditor.ObjectModels.Multimedia.Picture.Collection; +using UniversalEditor.ObjectModels.NewWorldComputing.Map; + +using UniversalEditor.Plugins.Multimedia.UserInterface; + +namespace UniversalEditor.Plugins.NewWorldComputing.UserInterface.Editors.NewWorldComputing.Map.Controls +{ + public class MapViewControl : CustomControl + { + private int _TileSize = 32; + public int TileSize { get { return _TileSize; } set { _TileSize = value; } } + + private MBS.Framework.UserInterface.Drawing.Pen pbk = new MBS.Framework.UserInterface.Drawing.Pen(SystemColors.HighlightBackground); + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + MapEditor ed = (Parent as MapEditor); + if (ed == null) return; + + MapObjectModel map = (ed.ObjectModel as MapObjectModel); + e.Graphics.DrawRectangle(pbk, new MBS.Framework.Drawing.Rectangle(0, 0, map.Width * TileSize, map.Height * TileSize)); + + int x = 0, y = 0; + for (int i = 0; i < map.Tiles.Count; i++) + { + if (x >= (TileSize * map.Width)) + { + x = 0; + y += TileSize; + } + + if (!(x >= HorizontalAdjustment.Value + Size.Width || y >= VerticalAdjustment.Value + Size.Height)) + { + DrawTile(e.Graphics, map.Tiles[i], x, y); + } + + x += TileSize; + } + } + + PictureCollectionObjectModel spriteTile = null; + + /// + /// Initializes the with tile images from the game. This function should be called only once. + /// + private void InitSpriteTile() + { + if (spriteTile != null) return; // already done + + string aggpath = @"/opt/fheroes2/data/HEROES2.AGG"; + string tilepath = "GROUND32.TIL"; + + FileSystemObjectModel fsomAgg = new FileSystemObjectModel(); + using (Document.Load(fsomAgg, new AGGDataFormat(), new FileAccessor(aggpath), false)) + { + File fileTile = fsomAgg.Files[tilepath]; + if (fileTile == null) return; + + byte[] dataTile = fileTile.GetData(); + MemoryAccessor maTile = new MemoryAccessor(dataTile); + + TILDataFormat icndf = new TILDataFormat(); + + spriteTile = new PictureCollectionObjectModel(); + Document.Load(spriteTile, icndf, maTile); + } + } + + private void DrawTile(Graphics graphics, MapTile tile, int x, int y) + { + InitSpriteTile(); + + PictureObjectModel pic = spriteTile.Pictures[tile.IndexName2]; + graphics.DrawImage(pic.ToImage(), x, y); + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs new file mode 100644 index 00000000..c26a53b4 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs @@ -0,0 +1,74 @@ +// +// MyClass.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using UniversalEditor.ObjectModels.NewWorldComputing.Map; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.NewWorldComputing.UserInterface.Editors.NewWorldComputing.Map +{ + [ContainerLayout("~/Editors/NewWorldComputing/Map/MapEditor.glade")] + public class MapEditor : Editor + { + private Controls.MapViewControl mapView; + + private static EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = base.MakeReference(); + _er.SupportedObjectModels.Add(typeof(MapObjectModel)); + } + return _er; + } + + public override void UpdateSelections() + { + throw new NotImplementedException(); + } + + protected override EditorSelection CreateSelectionInternal(object content) + { + throw new NotImplementedException(); + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + OnObjectModelChanged(e); + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + if (!IsCreated) return; + + MapObjectModel map = (ObjectModel as MapObjectModel); + if (map == null) return; + + mapView.Refresh(); + } + + + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Properties/AssemblyInfo.cs b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0e050611 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.NewWorldComputing.UserInterface")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Mike Becker's Software")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker's Software")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface.csproj new file mode 100644 index 00000000..2d488685 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface.csproj @@ -0,0 +1,79 @@ + + + + Debug + AnyCPU + {03B0D6C8-1C3C-4972-B102-3350FB628C5D} + Library + UniversalEditor.Plugins.NewWorldComputing.UserInterface + UniversalEditor.Plugins.NewWorldComputing.UserInterface + v4.7 + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + + + + {8622EBC4-8E20-476E-B284-33D472081F5C} + UniversalEditor.UserInterface + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + {26095090-3F7D-4DB5-A9BF-4C687230FC0F} + UniversalEditor.Plugins.NewWorldComputing + + + {29E1C1BB-3EA5-4062-B62F-85EEC703FE07} + MBS.Framework.UserInterface + + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + {BE4D0BA3-0888-42A5-9C09-FC308A4509D2} + UniversalEditor.Plugins.Multimedia + + + {D9D5AC3B-9AC0-4D4E-B295-2134FDCF166C} + UniversalEditor.Plugins.Multimedia.UserInterface + + + + \ No newline at end of file diff --git a/UniversalEditor.sln b/UniversalEditor.sln index 02133080..d8f54c93 100644 --- a/UniversalEditor.sln +++ b/UniversalEditor.sln @@ -171,6 +171,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Ami EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Designer.UserInterface", "Plugins.UserInterface\UniversalEditor.Plugins.Designer.UserInterface\UniversalEditor.Plugins.Designer.UserInterface.csproj", "{08168BEA-E652-4493-8D89-5AB72B225841}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.NewWorldComputing.UserInterface", "Plugins.UserInterface\UniversalEditor.Plugins.NewWorldComputing.UserInterface\UniversalEditor.Plugins.NewWorldComputing.UserInterface.csproj", "{03B0D6C8-1C3C-4972-B102-3350FB628C5D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -495,6 +497,10 @@ Global {08168BEA-E652-4493-8D89-5AB72B225841}.Debug|Any CPU.Build.0 = Debug|Any CPU {08168BEA-E652-4493-8D89-5AB72B225841}.Release|Any CPU.ActiveCfg = Release|Any CPU {08168BEA-E652-4493-8D89-5AB72B225841}.Release|Any CPU.Build.0 = Release|Any CPU + {03B0D6C8-1C3C-4972-B102-3350FB628C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03B0D6C8-1C3C-4972-B102-3350FB628C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03B0D6C8-1C3C-4972-B102-3350FB628C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03B0D6C8-1C3C-4972-B102-3350FB628C5D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {6F0AB1AF-E1A1-4D19-B19C-05BBB15C94B2} = {05D15661-E684-4EC9-8FBD-C014BA433CC5} @@ -575,6 +581,7 @@ Global {C8953DB2-AE48-4F04-87EC-549E6A3E30D8} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} {BCEB66A6-24E3-4877-B8D4-83FCF8EC748B} = {2ED32D16-6C06-4450-909A-40D32DA67FB4} {08168BEA-E652-4493-8D89-5AB72B225841} = {7B535D74-5496-4802-B809-89ED88274A91} + {03B0D6C8-1C3C-4972-B102-3350FB628C5D} = {7B535D74-5496-4802-B809-89ED88274A91} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0