More NKM stuff

This commit is contained in:
Gericom 2015-01-30 19:30:37 +01:00
parent 36fa018b3e
commit d5d3b33912
20 changed files with 591 additions and 81 deletions

View File

@ -7,7 +7,29 @@ using LibEveryFileExplorer.ComponentModel;
namespace LibEveryFileExplorer.Collections
{
[TypeConverter(typeof(ValueTypeTypeConverter))]
public class Vector3TypeConverter : ValueTypeTypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string)) return true;
else return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value.GetType() == typeof(string))
{
string input = (string)value;
input = input.Trim('(', ')', ' ');
string[] parts = input.Split(';');
if (parts.Length != 3) throw new Exception("Wrong formatting!");
return new Vector3(float.Parse(parts[0]), float.Parse(parts[1]), float.Parse(parts[2]));
}
else return base.ConvertFrom(context, culture, value);
}
}
[TypeConverter(typeof(Vector3TypeConverter))]//ValueTypeTypeConverter))]
public struct Vector3
{
public Vector3(float Value)

View File

@ -11,33 +11,36 @@ namespace LibEveryFileExplorer.ComponentModel
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
else
{
return base.CanConvertFrom(context, sourceType);
}
if (sourceType == typeof(string)) return true;
else return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
else
{
return base.CanConvertTo(context, destinationType);
}
if (destinationType == typeof(string)) return true;
else return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType != typeof(string)) return base.ConvertTo(context, culture, value, destinationType);
bool reverse = false;
foreach (var v in context.PropertyDescriptor.Attributes)
PropertyDescriptor p = context.PropertyDescriptor;
if (context.PropertyDescriptor.GetType().Name == "MergePropertyDescriptor")
{
System.Type propertyType = context.PropertyDescriptor.GetType();
System.Reflection.FieldInfo fieldInfo = propertyType.GetField(
"descriptors",
System.Reflection.BindingFlags.NonPublic
| System.Reflection.BindingFlags.Instance
);
PropertyDescriptor[] descriptors =
(PropertyDescriptor[])(fieldInfo.GetValue(context.PropertyDescriptor));
p = descriptors[0];
}
foreach (var v in p.Attributes)
{
if (v is HexReversedAttribute) reverse = ((HexReversedAttribute)v).HexReversed;
}
@ -73,8 +76,22 @@ namespace LibEveryFileExplorer.ComponentModel
string input = (string)value;
if (input.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) input = input.Substring(2);
PropertyDescriptor p = context.PropertyDescriptor;
if (context.PropertyDescriptor.GetType().Name == "MergePropertyDescriptor")
{
System.Type propertyType = context.PropertyDescriptor.GetType();
System.Reflection.FieldInfo fieldInfo = propertyType.GetField(
"descriptors",
System.Reflection.BindingFlags.NonPublic
| System.Reflection.BindingFlags.Instance
);
PropertyDescriptor[] descriptors =
(PropertyDescriptor[])(fieldInfo.GetValue(context.PropertyDescriptor));
p = descriptors[0];
}
bool reverse = false;
foreach (var v in context.PropertyDescriptor.Attributes)
foreach (var v in p.Attributes)
{
if (v is HexReversedAttribute) reverse = ((HexReversedAttribute)v).HexReversed;
}

View File

@ -6,15 +6,15 @@ using LibEveryFileExplorer.GameData;
namespace LibEveryFileExplorer.UI
{
public delegate void SelectedEventHandler(IGameDataSectionViewer Viewer, object Entry);
public delegate void SelectedEventHandler(IGameDataSectionViewer Viewer, object[] Entries);
public interface IGameDataSectionViewer
{
event SelectedEventHandler OnSelected;
void RefreshListView();
void UpdateListViewEntry(object Entry);
void Select(object Entry);
void UpdateListViewEntry(params object[] Entries);
void Select(params object[] Entries);
void RemoveSelection();
}
@ -29,11 +29,49 @@ namespace LibEveryFileExplorer.UI
this.Section = Section;
base.Load += new EventHandler(GameDataSectionViewer_Load);
base.listViewNF1.SelectedIndexChanged += new EventHandler(listViewNF1_SelectedIndexChanged);
base.buttonAdd.Click += new EventHandler(buttonAdd_Click);
base.buttonRemove.Click += new EventHandler(buttonRemove_Click);
buttonRemove.Enabled = buttonUp.Enabled = buttonDown.Enabled = false;
}
void buttonRemove_Click(object sender, EventArgs e)
{
if (listViewNF1.SelectedIndices.Count != 0)
{
List<T> entries = new List<T>();
foreach (int a in listViewNF1.SelectedIndices) entries.Add(Section.Entries[a]);
listViewNF1.SelectedIndices.Clear();
foreach (T a in entries)
{
Section.Entries.Remove(a);
Section.NrEntries--;
}
RefreshListView();
}
}
void buttonAdd_Click(object sender, EventArgs e)
{
T tmp = new T();
Section.Entries.Add(tmp);
Section.NrEntries++;
listViewNF1.BeginUpdate();
listViewNF1.Items.Add(tmp.GetListViewItem());
listViewNF1.EndUpdate();
Select(tmp);
}
void listViewNF1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listViewNF1.SelectedIndices.Count != 0 && OnSelected != null) OnSelected.Invoke(this, Section[listViewNF1.SelectedIndices[0]]);
if (listViewNF1.SelectedIndices.Count != 0 && OnSelected != null)
{
List<T> entries = new List<T>();
foreach (int a in listViewNF1.SelectedIndices) entries.Add(Section.Entries[a]);
OnSelected(this, entries.ToArray()); //Section[listViewNF1.SelectedIndices[0]]);
}
if (listViewNF1.SelectedIndices.Count != 0) buttonRemove.Enabled = buttonUp.Enabled = buttonDown.Enabled = true;
else buttonRemove.Enabled = buttonUp.Enabled = buttonDown.Enabled = false;
if (listViewNF1.SelectedIndices.Count == 0 && OnSelected != null) OnSelected(this, null);
}
void GameDataSectionViewer_Load(object sender, EventArgs e)
@ -47,38 +85,62 @@ namespace LibEveryFileExplorer.UI
public void RefreshListView()
{
int sel = -1;
if (listViewNF1.SelectedIndices.Count != 0) sel = listViewNF1.SelectedIndices[0];
int[] sel = null;
if (listViewNF1.SelectedIndices.Count != 0)
{
sel = new int[listViewNF1.SelectedIndices.Count];
listViewNF1.SelectedIndices.CopyTo(sel, 0);
}
listViewNF1.BeginUpdate();
listViewNF1.Items.Clear();
listViewNF1.Items.AddRange(Section.GetListViewItems());
listViewNF1.EndUpdate();
if (sel != -1 && sel < Section.Entries.Count) listViewNF1.SelectedIndices.Add(sel);
else if (sel != -1) listViewNF1.SelectedIndices.Add(Section.Entries.Count - 1);
if (sel != null)
{
foreach (int i in sel)
{
if(i < Section.Entries.Count) listViewNF1.SelectedIndices.Add(i);
}
}
}
public void UpdateListViewEntry(object Entry)
public void UpdateListViewEntry(params object[] Entries)
{
if (!(Entry is T)) return;
foreach (object Entry in Entries)
{
if (!(Entry is T)) continue;
int idx = Section.Entries.IndexOf((T)Entry);
if (idx < 0) return;
int sel = -1;
if (listViewNF1.SelectedIndices.Count != 0) sel = listViewNF1.SelectedIndices[0];
if (idx < 0) continue;
int[] sel = null;
if (listViewNF1.SelectedIndices.Count != 0)
{
sel = new int[listViewNF1.SelectedIndices.Count];
listViewNF1.SelectedIndices.CopyTo(sel, 0);
}
listViewNF1.BeginUpdate();
listViewNF1.Items[idx] = ((T)Entry).GetListViewItem();
listViewNF1.Items[idx].Text = idx.ToString();
listViewNF1.EndUpdate();
if (sel != -1 && sel < Section.Entries.Count) listViewNF1.SelectedIndices.Add(sel);
else if (sel != -1) listViewNF1.SelectedIndices.Add(Section.Entries.Count - 1);
if (sel != null)
{
foreach (int i in sel)
{
if (i < Section.Entries.Count) listViewNF1.SelectedIndices.Add(i);
}
}
}
}
public void Select(object Entry)
public void Select(params object[] Entries)
{
RemoveSelection();
if (!(Entry is T)) return;
foreach (object Entry in Entries)
{
if (!(Entry is T)) continue;
int idx = Section.Entries.IndexOf((T)Entry);
listViewNF1.SelectedIndices.Add(idx);
UpdateListViewEntry(Entry);
}
UpdateListViewEntry(Entries);
}
public void RemoveSelection()

View File

@ -101,7 +101,6 @@
this.listViewNF1.GridLines = true;
this.listViewNF1.HideSelection = false;
this.listViewNF1.Location = new System.Drawing.Point(0, 25);
this.listViewNF1.MultiSelect = false;
this.listViewNF1.Name = "listViewNF1";
this.listViewNF1.Size = new System.Drawing.Size(535, 352);
this.listViewNF1.TabIndex = 1;

View File

@ -197,7 +197,7 @@ namespace MarioKart.MK7.KMP
{
Position = v.Points[ii].Position,
Duration = (short)v.Points[ii].Setting1,
Index = (short)ii
Index = (byte)ii
});
}
}

View File

@ -18,12 +18,12 @@ namespace MarioKart.MKDS.NKM
public class IPOI : GameDataSection<IPOI.IPOIEntry>
{
public IPOI() { Signature = "IPOI"; }
public IPOI(EndianBinaryReaderEx er)
public IPOI(EndianBinaryReaderEx er, UInt16 Version)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "IPOI") throw new SignatureNotCorrectException(Signature, "IPOI", er.BaseStream.Position - 4);
NrEntries = er.ReadUInt32();
for (int i = 0; i < NrEntries; i++) Entries.Add(new IPOIEntry(er));
for (int i = 0; i < NrEntries; i++) Entries.Add(new IPOIEntry(er, Version));
}
public void Write(EndianBinaryWriter er)
@ -46,20 +46,24 @@ namespace MarioKart.MKDS.NKM
public class IPOIEntry : GameDataSectionEntry
{
private UInt16 Version = 37;
public IPOIEntry()
{
}
public IPOIEntry(EndianBinaryReaderEx er)
public IPOIEntry(EndianBinaryReaderEx er, UInt16 Version)
{
er.ReadObject(this);
this.Version = Version;
Position = er.ReadVecFx32();
Unknown1 = er.ReadUInt32();
if (Version >= 34) Unknown2 = er.ReadUInt32();
}
public override void Write(EndianBinaryWriter er)
{
er.WriteVecFx32(Position);
er.Write(Unknown1);
er.Write(Unknown2);
if (Version >= 34) er.Write(Unknown2);
}
public override ListViewItem GetListViewItem()

View File

@ -43,9 +43,19 @@ namespace MarioKart.MKDS.NKM
"Next",
"Next",
"Next",
"Next",
"Next",
"Next",
"Next",
"Next",
"Previous",
"Previous",
"Previous",
"Previous",
"Previous",
"Previous",
"Previous",
"Previous",
"Previous"
};
}

View File

@ -85,7 +85,7 @@ namespace MarioKart.MKDS.NKM
[BinaryFixedPoint(true, 19, 12)]
public Single PointSize { get; set; }
[Category("Enemy Point")]
public Int16 Drifting { get; set; }
public Int32 Drifting { get; set; }
[TypeConverter(typeof(HexTypeConverter)), HexReversed]
public UInt32 Unknown1 { get; set; }
}

View File

@ -51,7 +51,7 @@ namespace MarioKart.MKDS.NKM
case "KTPM": KartPointMission = new KTPM(er); break;
case "CPOI": CheckPoint = new CPOI(er); break;
case "CPAT": CheckPointPath = new CPAT(er); break;
case "IPOI": ItemPoint = new IPOI(er); break;
case "IPOI": ItemPoint = new IPOI(er, Header.Version); break;
case "IPAT": ItemPath = new IPAT(er); break;
case "EPOI": EnemyPoint = new EPOI(er); break;
case "EPAT": EnemyPath = new EPAT(er); break;

View File

@ -40,6 +40,7 @@ namespace MarioKart.MKDS.NKM
"ID",
"X", "Y", "Z",
"Index",
"?",
"Duration",
"?"
};
@ -51,8 +52,9 @@ namespace MarioKart.MKDS.NKM
{
Position = new Vector3(0, 0, 0);
Index = 0;
Unknown1 = 0;
Duration = 0;
Unknown = 0;
Unknown2 = 0;
}
public POITEntry(EndianBinaryReaderEx er)
{
@ -63,8 +65,9 @@ namespace MarioKart.MKDS.NKM
{
er.WriteVecFx32(Position);
er.Write(Index);
er.Write(Unknown1);
er.Write(Duration);
er.Write(Unknown);
er.Write(Unknown2);
}
public override ListViewItem GetListViewItem()
@ -75,20 +78,23 @@ namespace MarioKart.MKDS.NKM
m.SubItems.Add(Position.Z.ToString("#####0.############"));
m.SubItems.Add(Index.ToString());
m.SubItems.Add(HexUtil.GetHexReverse(Unknown1));
m.SubItems.Add(Duration.ToString());
m.SubItems.Add(HexUtil.GetHexReverse(Unknown));
m.SubItems.Add(HexUtil.GetHexReverse(Unknown2));
return m;
}
[Category("Transformation")]
[BinaryFixedPoint(true, 19, 12)]
public Vector3 Position { get; set; }
[Category("Point")]
public Int16 Index { get; set; }
public Byte Index { get; set; }
[Category("Point")]
public Byte Unknown1 { get; set; }
[Category("Point")]
public Int16 Duration { get; set; }
[Category("Point")]
[TypeConverter(typeof(HexTypeConverter)), HexReversedAttribute]
public UInt32 Unknown { get; set; }
public UInt32 Unknown2 { get; set; }
}
}
}

View File

@ -115,9 +115,15 @@
<Compile Include="UI\CDMDViewer.Designer.cs">
<DependentUpon>CDMDViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\MapViewer\MKDSObjectRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSRouteLineRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSAreaRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSMiniGameEnemyPointLineRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSEnemyPointLineRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSCheckPointLineRenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSCheckPointPoint2RenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSCheckPointPoint1RenderGroup.cs" />
<Compile Include="UI\MapViewer\MKDSItemPointLineRenderGroup.cs" />
<Compile Include="UI\NKMDViewer2.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarioKart.MKDS.NKM;
using System.Drawing;
using Tao.OpenGl;
using LibEveryFileExplorer.Collections;
namespace MarioKart.UI.MapViewer
{
public class MKDSAreaRenderGroup : RenderGroup
{
AREA Areas;
public MKDSAreaRenderGroup(AREA Areas, Color AreaColor)
{
this.Areas = Areas;
this.AreaColor = AreaColor;
}
public Color AreaColor { get; private set; }
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{
if (Picking) return;
Gl.glColor4f(AreaColor.R / 255f, AreaColor.G / 255f, AreaColor.B / 255f, AreaColor.A / 255f);
Gl.glBegin(Gl.GL_QUADS);
foreach (var o in Areas.Entries)
{
Vector3[] cube = o.GetCube();
//We're interested in points 0, 1, 5 and 3 (ground plane)
Vector3 Point1 = cube[3];
Vector3 Point2 = cube[5];
Vector3 Point3 = cube[1];
Vector3 Point4 = cube[0];
Gl.glVertex2f(Point1.X, Point1.Z);
Gl.glVertex2f(Point2.X, Point2.Z);
Gl.glVertex2f(Point3.X, Point3.Z);
Gl.glVertex2f(Point4.X, Point4.Z);
}
Gl.glEnd();
}
}
}

View File

@ -25,10 +25,7 @@ namespace MarioKart.UI.MapViewer
public Color Point1Color { get; private set; }
public Color Point2Color { get; private set; }
public override bool Interactable
{
get { return false; }
}
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{

View File

@ -21,10 +21,7 @@ namespace MarioKart.UI.MapViewer
public Color PointColor { get; private set; }
public override bool Interactable
{
get { return true; }
}
public override bool Interactable { get { return true; } }
public override void Render(bool Picking, int PickingId)
{

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarioKart.MKDS.NKM;
using System.Drawing;
using Tao.OpenGl;
namespace MarioKart.UI.MapViewer
{
public class MKDSEnemyPointLineRenderGroup : RenderGroup
{
EPOI EnemyPoints;
EPAT EnemyPointPaths;
public MKDSEnemyPointLineRenderGroup(EPOI EnemyPoints, EPAT EnemyPointPaths, Color LineColor)
{
this.EnemyPoints = EnemyPoints;
this.EnemyPointPaths = EnemyPointPaths;
this.LineColor = LineColor;
}
public Color LineColor { get; private set; }
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{
if (Picking) return;
Gl.glLineWidth(1.5f);
Gl.glBegin(Gl.GL_LINES);
Gl.glColor3f(LineColor.R / 255f, LineColor.G / 255f, LineColor.B / 255f);
for (int j = 0; j < EnemyPointPaths.Entries.Count; j++)
{
if (EnemyPoints.Entries.Count < EnemyPointPaths[j].StartIndex + EnemyPointPaths[j].Length) break;
for (int i = EnemyPointPaths[j].StartIndex; i < EnemyPointPaths.Entries[j].StartIndex + EnemyPointPaths[j].Length - 1; i++)
{
Gl.glVertex2f(EnemyPoints[i].Position.X, EnemyPoints[i].Position.Z);
Gl.glVertex2f(EnemyPoints[i + 1].Position.X, EnemyPoints[i + 1].Position.Z);
}
for (int i = 0; i < 3; i++)
{
if (EnemyPointPaths[j].GoesTo[i] == -1 || EnemyPointPaths[j].GoesTo[i] >= EnemyPointPaths.Entries.Count) continue;
Gl.glVertex2f(EnemyPoints[EnemyPointPaths[j].StartIndex + EnemyPointPaths[j].Length - 1].Position.X, EnemyPoints[EnemyPointPaths[j].StartIndex + EnemyPointPaths[j].Length - 1].Position.Z);
Gl.glVertex2f(EnemyPoints[EnemyPointPaths[EnemyPointPaths[j].GoesTo[i]].StartIndex].Position.X, EnemyPoints[EnemyPointPaths[EnemyPointPaths[j].GoesTo[i]].StartIndex].Position.Z);
}
for (int i = 0; i < 3; i++)
{
if (EnemyPointPaths[j].ComesFrom[i] == -1 || EnemyPointPaths[j].ComesFrom[i] >= EnemyPointPaths.Entries.Count) continue;
Gl.glVertex2f(EnemyPoints[EnemyPointPaths[j].StartIndex].Position.X, EnemyPoints[EnemyPointPaths[j].StartIndex].Position.Z);
Gl.glVertex2f(EnemyPoints[EnemyPointPaths[EnemyPointPaths[j].ComesFrom[i]].StartIndex + EnemyPointPaths[EnemyPointPaths[j].ComesFrom[i]].Length - 1].Position.X, EnemyPoints[EnemyPointPaths[EnemyPointPaths[j].ComesFrom[i]].StartIndex + EnemyPointPaths[EnemyPointPaths[j].ComesFrom[i]].Length - 1].Position.Z);
}
}
Gl.glEnd();
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarioKart.MKDS.NKM;
using System.Drawing;
using Tao.OpenGl;
namespace MarioKart.UI.MapViewer
{
public class MKDSItemPointLineRenderGroup : RenderGroup
{
IPOI ItemPoints;
IPAT ItemPointPaths;
public MKDSItemPointLineRenderGroup(IPOI ItemPoints, IPAT ItemPointPaths, Color LineColor)
{
this.ItemPoints = ItemPoints;
this.ItemPointPaths = ItemPointPaths;
this.LineColor = LineColor;
}
public Color LineColor { get; private set; }
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{
if (Picking) return;
Gl.glLineWidth(1.5f);
Gl.glBegin(Gl.GL_LINES);
Gl.glColor3f(LineColor.R / 255f, LineColor.G / 255f, LineColor.B / 255f);
for (int j = 0; j < ItemPointPaths.Entries.Count; j++)
{
if (ItemPoints.Entries.Count < ItemPointPaths[j].StartIndex + ItemPointPaths[j].Length) break;
for (int i = ItemPointPaths[j].StartIndex; i < ItemPointPaths.Entries[j].StartIndex + ItemPointPaths[j].Length - 1; i++)
{
Gl.glVertex2f(ItemPoints[i].Position.X, ItemPoints[i].Position.Z);
Gl.glVertex2f(ItemPoints[i + 1].Position.X, ItemPoints[i + 1].Position.Z);
}
for (int i = 0; i < 3; i++)
{
if (ItemPointPaths[j].GoesTo[i] == -1 || ItemPointPaths[j].GoesTo[i] >= ItemPointPaths.Entries.Count) continue;
Gl.glVertex2f(ItemPoints[ItemPointPaths[j].StartIndex + ItemPointPaths[j].Length - 1].Position.X, ItemPoints[ItemPointPaths[j].StartIndex + ItemPointPaths[j].Length - 1].Position.Z);
Gl.glVertex2f(ItemPoints[ItemPointPaths[ItemPointPaths[j].GoesTo[i]].StartIndex].Position.X, ItemPoints[ItemPointPaths[ItemPointPaths[j].GoesTo[i]].StartIndex].Position.Z);
}
for (int i = 0; i < 3; i++)
{
if (ItemPointPaths[j].ComesFrom[i] == -1 || ItemPointPaths[j].ComesFrom[i] >= ItemPointPaths.Entries.Count) continue;
Gl.glVertex2f(ItemPoints[ItemPointPaths[j].StartIndex].Position.X, ItemPoints[ItemPointPaths[j].StartIndex].Position.Z);
Gl.glVertex2f(ItemPoints[ItemPointPaths[ItemPointPaths[j].ComesFrom[i]].StartIndex + ItemPointPaths[ItemPointPaths[j].ComesFrom[i]].Length - 1].Position.X, ItemPoints[ItemPointPaths[ItemPointPaths[j].ComesFrom[i]].StartIndex + ItemPointPaths[ItemPointPaths[j].ComesFrom[i]].Length - 1].Position.Z);
}
}
Gl.glEnd();
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarioKart.MKDS.NKM;
using System.Drawing;
using Tao.OpenGl;
namespace MarioKart.UI.MapViewer
{
public class MKDSMiniGameEnemyPointLineRenderGroup : RenderGroup
{
MEPO MiniGameEnemyPoints;
MEPA MiniGameEnemyPointPaths;
public MKDSMiniGameEnemyPointLineRenderGroup(MEPO MiniGameEnemyPoints, MEPA MiniGameEnemyPointPaths, Color LineColor)
{
this.MiniGameEnemyPoints = MiniGameEnemyPoints;
this.MiniGameEnemyPointPaths = MiniGameEnemyPointPaths;
this.LineColor = LineColor;
}
public Color LineColor { get; private set; }
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{
if (Picking) return;
Gl.glLineWidth(1.5f);
Gl.glBegin(Gl.GL_LINES);
Gl.glColor3f(LineColor.R / 255f, LineColor.G / 255f, LineColor.B / 255f);
for (int j = 0; j < MiniGameEnemyPointPaths.Entries.Count; j++)
{
if (MiniGameEnemyPoints.Entries.Count < MiniGameEnemyPointPaths[j].StartIndex + MiniGameEnemyPointPaths[j].Length) break;
for (int i = MiniGameEnemyPointPaths[j].StartIndex; i < MiniGameEnemyPointPaths.Entries[j].StartIndex + MiniGameEnemyPointPaths[j].Length - 1; i++)
{
Gl.glVertex2f(MiniGameEnemyPoints[i].Position.X, MiniGameEnemyPoints[i].Position.Z);
Gl.glVertex2f(MiniGameEnemyPoints[i + 1].Position.X, MiniGameEnemyPoints[i + 1].Position.Z);
}
for (int i = 0; i < 8; i++)
{
if (MiniGameEnemyPointPaths[j].GoesTo[i] == -1 || MiniGameEnemyPointPaths[j].GoesTo[i] >= MiniGameEnemyPoints.Entries.Count) continue;
Gl.glVertex2f(MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].StartIndex + MiniGameEnemyPointPaths[j].Length - 1].Position.X, MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].StartIndex + MiniGameEnemyPointPaths[j].Length - 1].Position.Z);
Gl.glVertex2f(MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].GoesTo[i]].Position.X, MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].GoesTo[i]].Position.Z);
}
for (int i = 0; i < 8; i++)
{
if (MiniGameEnemyPointPaths[j].ComesFrom[i] == -1 || MiniGameEnemyPointPaths[j].ComesFrom[i] >= MiniGameEnemyPoints.Entries.Count) continue;
Gl.glVertex2f(MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].StartIndex].Position.X, MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].StartIndex].Position.Z);
Gl.glVertex2f(MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].ComesFrom[i]].Position.X, MiniGameEnemyPoints[MiniGameEnemyPointPaths[j].ComesFrom[i]].Position.Z);
}
}
Gl.glEnd();
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using Tao.OpenGl;
namespace MarioKart.UI.MapViewer
{
public class MKDSObjectRenderGroup : RenderGroup
{
MKDS.NKM.OBJI Objects;
public MKDSObjectRenderGroup(MKDS.NKM.OBJI Objects, Color PointColor)
{
this.Objects = Objects;
this.PointColor = PointColor;
}
public Color PointColor { get; private set; }
public override bool Interactable { get { return true; } }
public override void Render(bool Picking, int PickingId)
{
Gl.glPointSize((Picking ? 6f : 5));
Gl.glBegin(Gl.GL_POINTS);
if (!Picking) Gl.glColor3f(PointColor.R / 255f, PointColor.G / 255f, PointColor.B / 255f);
int objidx = 1;
foreach (var o in Objects.Entries)
{
if (Picking)
{
Color c = Color.FromArgb(objidx | PickingId);
Gl.glColor4f(c.R / 255f, c.G / 255f, c.B / 255f, 1);
objidx++;
}
Bitmap b;
if ((b = (Bitmap)OBJI.ResourceManager.GetObject("OBJ_" + BitConverter.ToString(BitConverter.GetBytes(o.ObjectID), 0).Replace("-", ""))) == null)
{
Gl.glVertex2f(o.Position.X, o.Position.Z);
}
else
{
Gl.glEnd();
if (!Picking)
{
Gl.glColor3f(1, 1, 1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, o.ObjectID);
}
Gl.glPushMatrix();
Gl.glTranslatef(o.Position.X, o.Position.Z, 0);
Gl.glRotatef(o.Rotation.Y, 0, 0, 1);
int[] viewport = new int[4];
float[] pm = new float[16];
Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);
Gl.glGetFloatv(Gl.GL_PROJECTION_MATRIX, pm);
float scale = 1f / pm[0] / viewport[2] * 2f;
Gl.glScalef(scale, scale, 1);
Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(0, 0);
Gl.glVertex2f(-b.Width / 2f, -b.Height / 2f);
Gl.glTexCoord2f(1, 0);
Gl.glVertex2f(b.Width / 2f, -b.Height / 2f);
Gl.glTexCoord2f(1, 1);
Gl.glVertex2f(b.Width / 2f, b.Height / 2f);
Gl.glTexCoord2f(0, 1);
Gl.glVertex2f(-b.Width / 2f, b.Height / 2f);
Gl.glEnd();
Gl.glPopMatrix();
if (!Picking)
{
Gl.glColor3f(PointColor.R / 255f, PointColor.G / 255f, PointColor.B / 255f);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
}
Gl.glBegin(Gl.GL_POINTS);
}
}
Gl.glEnd();
}
public override object GetEntry(int Index)
{
return Objects[Index];
}
public override Vector3 GetPosition(int Index)
{
return Objects[Index].Position;
}
public override void SetPosition(int Index, Vector3 Position, bool ValidY = false)
{
if (!ValidY) Position.Y = Objects[Index].Position.Y;
Objects[Index].Position = Position;
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarioKart.MKDS.NKM;
using LibEveryFileExplorer.Collections;
using System.Drawing;
using Tao.OpenGl;
namespace MarioKart.UI.MapViewer
{
public class MKDSRouteLineRenderGroup : RenderGroup
{
PATH Paths;
POIT Points;
public MKDSRouteLineRenderGroup(PATH Paths, POIT Points, Color LineColor)
{
this.Paths = Paths;
this.Points = Points;
this.LineColor = LineColor;
}
public Color LineColor { get; private set; }
public override bool Interactable { get { return false; } }
public override void Render(bool Picking, int PickingId)
{
if (Picking) return;
Gl.glLineWidth(1.5f);
Gl.glColor3f(LineColor.R / 255f, LineColor.G / 255f, LineColor.B / 255f);
int idx = 0;
foreach (var o in Paths.Entries)
{
if (Points.NrEntries < o.NrPoit + idx) break;
Gl.glBegin(Gl.GL_LINE_STRIP);
for (int i = 0; i < o.NrPoit; i++)
{
Gl.glVertex2f(Points[idx + i].Position.X, Points[idx + i].Position.Z);
if (!(i + 1 < o.NrPoit) && o.Loop)
{
Gl.glVertex2f(Points[idx].Position.X, Points[idx].Position.Z);
}
}
Gl.glEnd();
idx += o.NrPoit;
}
}
}
}

View File

@ -65,17 +65,28 @@ namespace MarioKart.UI
if (NKMD.Area != null) AddTab<AREA.AREAEntry>("AREA", NKMD.Area);
if (NKMD.Camera != null) AddTab<CAME.CAMEEntry>("CAME", NKMD.Camera);
mapViewer1.Groups.Add(new PointRenderGroup<MKDS.NKM.OBJI.OBJIEntry>(Color.Red, NKMD.ObjectInformation, typeof(MKDS.NKM.OBJI.OBJIEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<KTPS.KTPSEntry>(Color.Black, NKMD.KartPointStart, typeof(KTPS.KTPSEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<KTPJ.KTPJEntry>(Color.Orange, NKMD.KartPointJugem, typeof(KTPJ.KTPJEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<KTP2.KTP2Entry>(Color.FromArgb(0, 230, 255), NKMD.KartPointSecond, typeof(KTP2.KTP2Entry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<KTPC.KTPCEntry>(Color.FromArgb(255, 0, 128), NKMD.KartPointCannon, typeof(KTPC.KTPCEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new MKDSCheckPointLineRenderGroup(NKMD.CheckPoint, NKMD.CheckPointPath, Color.FromArgb(0, 170, 0), Color.FromArgb(170, 0, 0)));
mapViewer1.Groups.Add(new MKDSCheckPointPoint1RenderGroup(NKMD.CheckPoint, Color.FromArgb(0, 170, 0)));
mapViewer1.Groups.Add(new MKDSCheckPointPoint2RenderGroup(NKMD.CheckPoint, Color.FromArgb(170, 0, 0)));
mapViewer1.Groups.Add(new PointRenderGroup<AREA.AREAEntry>(Color.CornflowerBlue, NKMD.Area, typeof(AREA.AREAEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<IPOI.IPOIEntry>(Color.FromArgb(255, 230, 0), NKMD.ItemPoint, typeof(IPOI.IPOIEntry).GetProperty("Position")));
mapViewer1.Groups.Add(new PointRenderGroup<EPOI.EPOIEntry>(Color.FromArgb(0, 204, 0), NKMD.EnemyPoint, typeof(EPOI.EPOIEntry).GetProperty("Position")));
if (NKMD.Area != null) mapViewer1.Groups.Add(new MKDSAreaRenderGroup(NKMD.Area, Color.FromArgb(64, Color.CornflowerBlue)));
if (NKMD.Point != null && NKMD.Path != null) mapViewer1.Groups.Add(new MKDSRouteLineRenderGroup(NKMD.Path, NKMD.Point, Color.FromArgb(0, 0, 128)));
if (NKMD.CheckPoint != null && NKMD.CheckPointPath != null) mapViewer1.Groups.Add(new MKDSCheckPointLineRenderGroup(NKMD.CheckPoint, NKMD.CheckPointPath, Color.FromArgb(0, 170, 0), Color.FromArgb(170, 0, 0)));
if (NKMD.ItemPoint != null && NKMD.ItemPath != null) mapViewer1.Groups.Add(new MKDSItemPointLineRenderGroup(NKMD.ItemPoint, NKMD.ItemPath, Color.FromArgb(/*255, 230*/204, 153, 0)));
if (NKMD.EnemyPoint != null && NKMD.EnemyPath != null) mapViewer1.Groups.Add(new MKDSEnemyPointLineRenderGroup(NKMD.EnemyPoint, NKMD.EnemyPath, Color.FromArgb(0, 204, 0)));
if (NKMD.MiniGameEnemyPoint != null && NKMD.MiniGameEnemyPath != null) mapViewer1.Groups.Add(new MKDSMiniGameEnemyPointLineRenderGroup(NKMD.MiniGameEnemyPoint, NKMD.MiniGameEnemyPath, Color.FromArgb(0, 204, 0)));
if (NKMD.Point != null) mapViewer1.Groups.Add(new PointRenderGroup<POIT.POITEntry>(Color.FromArgb(0, 0, 128), NKMD.Point, typeof(POIT.POITEntry).GetProperty("Position")));
if (NKMD.ObjectInformation != null) mapViewer1.Groups.Add(new MKDSObjectRenderGroup(NKMD.ObjectInformation, Color.Red));
if (NKMD.KartPointStart != null) mapViewer1.Groups.Add(new PointRenderGroup<KTPS.KTPSEntry>(Color.Black, NKMD.KartPointStart, typeof(KTPS.KTPSEntry).GetProperty("Position")));
if (NKMD.KartPointJugem != null) mapViewer1.Groups.Add(new PointRenderGroup<KTPJ.KTPJEntry>(Color.Orange, NKMD.KartPointJugem, typeof(KTPJ.KTPJEntry).GetProperty("Position")));
if (NKMD.KartPointSecond != null) mapViewer1.Groups.Add(new PointRenderGroup<KTP2.KTP2Entry>(Color.FromArgb(0, 230, 255), NKMD.KartPointSecond, typeof(KTP2.KTP2Entry).GetProperty("Position")));
if (NKMD.KartPointCannon != null) mapViewer1.Groups.Add(new PointRenderGroup<KTPC.KTPCEntry>(Color.FromArgb(255, 0, 128), NKMD.KartPointCannon, typeof(KTPC.KTPCEntry).GetProperty("Position")));
if (NKMD.KartPointMission != null) mapViewer1.Groups.Add(new PointRenderGroup<KTPM.KTPMEntry>(Color.MediumPurple, NKMD.KartPointMission, typeof(KTPM.KTPMEntry).GetProperty("Position")));
if (NKMD.CheckPoint != null) mapViewer1.Groups.Add(new MKDSCheckPointPoint1RenderGroup(NKMD.CheckPoint, Color.FromArgb(0, 170, 0)));
if (NKMD.CheckPoint != null) mapViewer1.Groups.Add(new MKDSCheckPointPoint2RenderGroup(NKMD.CheckPoint, Color.FromArgb(170, 0, 0)));
if (NKMD.Area != null) mapViewer1.Groups.Add(new PointRenderGroup<AREA.AREAEntry>(Color.CornflowerBlue, NKMD.Area, typeof(AREA.AREAEntry).GetProperty("Position")));
if (NKMD.ItemPoint != null) mapViewer1.Groups.Add(new PointRenderGroup<IPOI.IPOIEntry>(Color.FromArgb(/*255, 230*/204, 153, 0), NKMD.ItemPoint, typeof(IPOI.IPOIEntry).GetProperty("Position")));
if (NKMD.EnemyPoint != null) mapViewer1.Groups.Add(new PointRenderGroup<EPOI.EPOIEntry>(Color.FromArgb(0, 204, 0), NKMD.EnemyPoint, typeof(EPOI.EPOIEntry).GetProperty("Position")));
if (NKMD.MiniGameEnemyPoint != null) mapViewer1.Groups.Add(new PointRenderGroup<MEPO.MEPOEntry>(Color.FromArgb(0, 204, 0), NKMD.MiniGameEnemyPoint, typeof(MEPO.MEPOEntry).GetProperty("Position")));
if (NKMD.Camera != null) mapViewer1.Groups.Add(new PointRenderGroup<CAME.CAMEEntry>(Color.BurlyWood, NKMD.Camera, typeof(CAME.CAMEEntry).GetProperty("Position")));
}
private void AddTab<T>(String Name, GameDataSection<T> Section) where T : GameDataSectionEntry, new()
@ -88,9 +99,9 @@ namespace MarioKart.UI
tabControl1.TabPages.Add(p);
}
void GameDataSectionViewer_OnSelected(IGameDataSectionViewer Viewer, object Entry)
void GameDataSectionViewer_OnSelected(IGameDataSectionViewer Viewer, object[] Entry)
{
propertyGrid1.SelectedObject = Entry;
propertyGrid1.SelectedObjects = Entry;
propertyGrid1.ExpandAllGridItems();
foreach (var v in SectionViewers)
{
@ -157,7 +168,7 @@ namespace MarioKart.UI
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
foreach (var v in SectionViewers) v.UpdateListViewEntry(propertyGrid1.SelectedObject);
foreach (var v in SectionViewers) v.UpdateListViewEntry(propertyGrid1.SelectedObjects);
mapViewer1.Render();
mapViewer1.Render();
}