mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-15 10:57:01 +08:00
Refactored rendering and input code, added show skeletons option to WorldForm
This commit is contained in:
@@ -0,0 +1,336 @@
|
||||
using CodeWalker.Properties;
|
||||
using SharpDX;
|
||||
using SharpDX.XInput;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CodeWalker
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class InputManager
|
||||
{
|
||||
public Controller xbcontroller = null;
|
||||
public State xbcontrollerstate;
|
||||
public State xbcontrollerstateprev;
|
||||
public Vector4 xbmainaxes = Vector4.Zero;
|
||||
public Vector4 xbmainaxesprev = Vector4.Zero;
|
||||
public Vector2 xbtrigs = Vector2.Zero;
|
||||
public Vector2 xbtrigsprev = Vector2.Zero;
|
||||
public float xbcontrolvelocity = 0.0f;
|
||||
|
||||
public bool xbenable = false;
|
||||
public float xblx = 0; //left stick X axis
|
||||
public float xbly = 0; //left stick Y axis
|
||||
public float xbrx = 0; //right stick X axis
|
||||
public float xbry = 0; //right stick Y axis
|
||||
public float xblt = 0; //left trigger value
|
||||
public float xbrt = 0; //right trigger value
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public volatile bool kbmovefwd = false;
|
||||
public volatile bool kbmovebck = false;
|
||||
public volatile bool kbmovelft = false;
|
||||
public volatile bool kbmovergt = false;
|
||||
public volatile bool kbmoveup = false;
|
||||
public volatile bool kbmovedn = false;
|
||||
public volatile bool kbjump = false;
|
||||
public volatile bool kbmoving = false;
|
||||
|
||||
public KeyBindings keyBindings = new KeyBindings(Settings.Default.KeyBindings);
|
||||
|
||||
public bool CtrlPressed = false;
|
||||
public bool ShiftPressed = false;
|
||||
|
||||
|
||||
|
||||
|
||||
public void Init()
|
||||
{
|
||||
xbcontroller = new Controller(UserIndex.One);
|
||||
if (!xbcontroller.IsConnected)
|
||||
{
|
||||
var controllers = new[] { new Controller(UserIndex.Two), new Controller(UserIndex.Three), new Controller(UserIndex.Four) };
|
||||
foreach (var selectControler in controllers)
|
||||
{
|
||||
if (selectControler.IsConnected)
|
||||
{
|
||||
xbcontroller = selectControler;
|
||||
xbcontrollerstate = xbcontroller.GetState();
|
||||
xbcontrollerstateprev = xbcontrollerstate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xbcontrollerstate = xbcontroller.GetState();
|
||||
xbcontrollerstateprev = xbcontrollerstate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void Update(float elapsed)
|
||||
{
|
||||
if (elapsed > 0.1f) elapsed = 0.1f;
|
||||
|
||||
var s = Settings.Default;
|
||||
|
||||
xbenable = (xbcontroller != null) && (xbcontroller.IsConnected);
|
||||
xblx = 0; xbly = 0; xbrx = 0; xbry = 0; xblt = 0; xbrt = 0; //input axes
|
||||
|
||||
if (xbenable)
|
||||
{
|
||||
xbcontrollerstateprev = xbcontrollerstate;
|
||||
xbcontrollerstate = xbcontroller.GetState();
|
||||
xbmainaxesprev = xbmainaxes;
|
||||
xbtrigsprev = xbtrigs;
|
||||
xbmainaxes = ControllerMainAxes();
|
||||
xbtrigs = ControllerTriggers();
|
||||
xblx = xbmainaxes.X;
|
||||
xbly = xbmainaxes.Y;
|
||||
xbrx = xbmainaxes.Z;
|
||||
xbry = xbmainaxes.W;
|
||||
xblt = xbtrigs.X;
|
||||
xbrt = xbtrigs.Y;
|
||||
float lamt = s.XInputLThumbSensitivity * elapsed;
|
||||
float ramt = s.XInputRThumbSensitivity * elapsed;
|
||||
xbly = s.XInputLThumbInvert ? xbly : -xbly;
|
||||
xbry = s.XInputRThumbInvert ? xbry : -xbry;
|
||||
xblx *= lamt;
|
||||
xbly *= lamt;
|
||||
xbrx *= ramt;
|
||||
xbry *= ramt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void KeyDown(KeyEventArgs e, bool enablemove)
|
||||
{
|
||||
var k = e.KeyCode;
|
||||
CtrlPressed = (e.Modifiers & Keys.Control) > 0;
|
||||
ShiftPressed = (e.Modifiers & Keys.Shift) > 0;
|
||||
|
||||
//enablemove = enablemove && (!ctrl);
|
||||
|
||||
//WASD move...
|
||||
if (enablemove)
|
||||
{
|
||||
if (k == keyBindings.MoveForward) kbmovefwd = true;
|
||||
if (k == keyBindings.MoveBackward) kbmovebck = true;
|
||||
if (k == keyBindings.MoveLeft) kbmovelft = true;
|
||||
if (k == keyBindings.MoveRight) kbmovergt = true;
|
||||
if (k == keyBindings.MoveUp) kbmoveup = true;
|
||||
if (k == keyBindings.MoveDown) kbmovedn = true;
|
||||
if (k == keyBindings.Jump) kbjump = true;
|
||||
}
|
||||
|
||||
kbmoving = kbmovefwd || kbmovebck || kbmovelft || kbmovergt || kbmoveup || kbmovedn || kbjump;
|
||||
|
||||
}
|
||||
|
||||
public void KeyUp(KeyEventArgs e)
|
||||
{
|
||||
CtrlPressed = (e.Modifiers & Keys.Control) > 0;
|
||||
ShiftPressed = (e.Modifiers & Keys.Shift) > 0;
|
||||
|
||||
var k = e.KeyCode;
|
||||
if (k == keyBindings.MoveForward) kbmovefwd = false;
|
||||
if (k == keyBindings.MoveBackward) kbmovebck = false;
|
||||
if (k == keyBindings.MoveLeft) kbmovelft = false;
|
||||
if (k == keyBindings.MoveRight) kbmovergt = false;
|
||||
if (k == keyBindings.MoveUp) kbmoveup = false;
|
||||
if (k == keyBindings.MoveDown) kbmovedn = false;
|
||||
if (k == keyBindings.Jump) kbjump = false;
|
||||
|
||||
kbmoving = kbmovefwd || kbmovebck || kbmovelft || kbmovergt || kbmoveup || kbmovedn || kbjump;
|
||||
|
||||
}
|
||||
|
||||
public void KeyboardStop()
|
||||
{
|
||||
kbmovefwd = false;
|
||||
kbmovebck = false;
|
||||
kbmovelft = false;
|
||||
kbmovergt = false;
|
||||
kbmoveup = false;
|
||||
kbmovedn = false;
|
||||
kbjump = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Vector3 KeyboardMoveVec(bool mapview = false)
|
||||
{
|
||||
Vector3 movevec = Vector3.Zero;
|
||||
if (mapview)
|
||||
{
|
||||
if (kbmovefwd) movevec.Y += 1.0f;
|
||||
if (kbmovebck) movevec.Y -= 1.0f;
|
||||
if (kbmovelft) movevec.X -= 1.0f;
|
||||
if (kbmovergt) movevec.X += 1.0f;
|
||||
if (kbmoveup) movevec.Y += 1.0f;
|
||||
if (kbmovedn) movevec.Y -= 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kbmovefwd) movevec.Z -= 1.0f;
|
||||
if (kbmovebck) movevec.Z += 1.0f;
|
||||
if (kbmovelft) movevec.X -= 1.0f;
|
||||
if (kbmovergt) movevec.X += 1.0f;
|
||||
if (kbmoveup) movevec.Y += 1.0f;
|
||||
if (kbmovedn) movevec.Y -= 1.0f;
|
||||
}
|
||||
return movevec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Vector4 ControllerMainAxes()
|
||||
{
|
||||
var gp = xbcontrollerstate.Gamepad;
|
||||
var ldz = Gamepad.LeftThumbDeadZone;
|
||||
var rdz = Gamepad.RightThumbDeadZone;
|
||||
float ltnrng = -(short.MinValue + ldz);
|
||||
float ltprng = (short.MaxValue - ldz);
|
||||
float rtnrng = -(short.MinValue + rdz);
|
||||
float rtprng = (short.MaxValue - rdz);
|
||||
|
||||
float lx = (gp.LeftThumbX < 0) ? Math.Min((gp.LeftThumbX + ldz) / ltnrng, 0) :
|
||||
(gp.LeftThumbX > 0) ? Math.Max((gp.LeftThumbX - ldz) / ltprng, 0) : 0;
|
||||
float ly = (gp.LeftThumbY < 0) ? Math.Min((gp.LeftThumbY + ldz) / ltnrng, 0) :
|
||||
(gp.LeftThumbY > 0) ? Math.Max((gp.LeftThumbY - ldz) / ltprng, 0) : 0;
|
||||
float rx = (gp.RightThumbX < 0) ? Math.Min((gp.RightThumbX + rdz) / rtnrng, 0) :
|
||||
(gp.RightThumbX > 0) ? Math.Max((gp.RightThumbX - rdz) / rtprng, 0) : 0;
|
||||
float ry = (gp.RightThumbY < 0) ? Math.Min((gp.RightThumbY + rdz) / rtnrng, 0) :
|
||||
(gp.RightThumbY > 0) ? Math.Max((gp.RightThumbY - rdz) / rtprng, 0) : 0;
|
||||
|
||||
return new Vector4(lx, ly, rx, ry);
|
||||
}
|
||||
public Vector2 ControllerTriggers()
|
||||
{
|
||||
var gp = xbcontrollerstate.Gamepad;
|
||||
var tt = Gamepad.TriggerThreshold;
|
||||
float trng = byte.MaxValue - tt;
|
||||
float lt = Math.Max((gp.LeftTrigger - tt) / trng, 0);
|
||||
float rt = Math.Max((gp.RightTrigger - tt) / trng, 0);
|
||||
return new Vector2(lt, rt);
|
||||
}
|
||||
public bool ControllerButtonPressed(GamepadButtonFlags b)
|
||||
{
|
||||
return ((xbcontrollerstate.Gamepad.Buttons & b) != 0);
|
||||
}
|
||||
public bool ControllerButtonJustPressed(GamepadButtonFlags b)
|
||||
{
|
||||
return (((xbcontrollerstate.Gamepad.Buttons & b) != 0) && ((xbcontrollerstateprev.Gamepad.Buttons & b) == 0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class KeyBindings
|
||||
{
|
||||
public Keys MoveForward = Keys.W;
|
||||
public Keys MoveBackward = Keys.S;
|
||||
public Keys MoveLeft = Keys.A;
|
||||
public Keys MoveRight = Keys.D;
|
||||
public Keys MoveUp = Keys.R;
|
||||
public Keys MoveDown = Keys.F;
|
||||
public Keys MoveSlowerZoomIn = Keys.Z;
|
||||
public Keys MoveFasterZoomOut = Keys.X;
|
||||
public Keys ToggleMouseSelect = Keys.C;
|
||||
public Keys ToggleToolbar = Keys.T;
|
||||
public Keys ExitEditMode = Keys.Q;
|
||||
public Keys EditPosition = Keys.W;
|
||||
public Keys EditRotation = Keys.E;
|
||||
public Keys EditScale = Keys.R;
|
||||
public Keys Jump = Keys.Space; //for control mode
|
||||
public Keys FirstPerson = Keys.P;
|
||||
|
||||
public KeyBindings(StringCollection sc)
|
||||
{
|
||||
foreach (string s in sc)
|
||||
{
|
||||
string[] parts = s.Split(':');
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string sval = parts[1].Trim();
|
||||
Keys k = (Keys)Enum.Parse(typeof(Keys), sval);
|
||||
SetBinding(parts[0], k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBinding(string name, Keys k)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "Move Forwards": MoveForward = k; break;
|
||||
case "Move Backwards": MoveBackward = k; break;
|
||||
case "Move Left": MoveLeft = k; break;
|
||||
case "Move Right": MoveRight = k; break;
|
||||
case "Move Up": MoveUp = k; break;
|
||||
case "Move Down": MoveDown = k; break;
|
||||
case "Move Slower / Zoom In": MoveSlowerZoomIn = k; break;
|
||||
case "Move Faster / Zoom Out": MoveFasterZoomOut = k; break;
|
||||
case "Toggle Mouse Select": ToggleMouseSelect = k; break;
|
||||
case "Toggle Toolbar": ToggleToolbar = k; break;
|
||||
case "Exit Edit Mode": ExitEditMode = k; break;
|
||||
case "Edit Position": EditPosition = k; break;
|
||||
case "Edit Rotation": EditRotation = k; break;
|
||||
case "Edit Scale": EditScale = k; break;
|
||||
case "First Person Mode": FirstPerson = k; break;
|
||||
}
|
||||
}
|
||||
|
||||
public StringCollection GetSetting()
|
||||
{
|
||||
StringCollection sc = new StringCollection();
|
||||
sc.Add(GetSettingItem("Move Forwards", MoveForward));
|
||||
sc.Add(GetSettingItem("Move Backwards", MoveBackward));
|
||||
sc.Add(GetSettingItem("Move Left", MoveLeft));
|
||||
sc.Add(GetSettingItem("Move Right", MoveRight));
|
||||
sc.Add(GetSettingItem("Move Up", MoveUp));
|
||||
sc.Add(GetSettingItem("Move Down", MoveDown));
|
||||
sc.Add(GetSettingItem("Move Slower / Zoom In", MoveSlowerZoomIn));
|
||||
sc.Add(GetSettingItem("Move Faster / Zoom Out", MoveFasterZoomOut));
|
||||
sc.Add(GetSettingItem("Toggle Mouse Select", ToggleMouseSelect));
|
||||
sc.Add(GetSettingItem("Toggle Toolbar", ToggleToolbar));
|
||||
sc.Add(GetSettingItem("Exit Edit Mode", ExitEditMode));
|
||||
sc.Add(GetSettingItem("Edit Position", EditPosition));
|
||||
sc.Add(GetSettingItem("Edit Rotation", EditRotation));
|
||||
sc.Add(GetSettingItem("Edit Scale", EditScale));
|
||||
sc.Add(GetSettingItem("First Person Mode", FirstPerson));
|
||||
return sc;
|
||||
}
|
||||
|
||||
private string GetSettingItem(string name, Keys val)
|
||||
{
|
||||
return name + ": " + val.ToString();
|
||||
}
|
||||
|
||||
public KeyBindings Copy()
|
||||
{
|
||||
return (KeyBindings)MemberwiseClone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,764 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using SharpDX;
|
||||
using SharpDX.Direct3D11;
|
||||
using CodeWalker.Utils;
|
||||
using CodeWalker.World;
|
||||
using CodeWalker.GameFiles;
|
||||
|
||||
namespace CodeWalker
|
||||
{
|
||||
|
||||
|
||||
public class MapIcon
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Filepath { get; set; }
|
||||
public Texture2D Tex { get; set; }
|
||||
public ShaderResourceView TexView { get; set; }
|
||||
public Vector3 Center { get; set; } //in image pixels
|
||||
public float Scale { get; set; } //screen pixels per icon pixel
|
||||
public int TexWidth { get; set; }
|
||||
public int TexHeight { get; set; }
|
||||
|
||||
public MapIcon(string name, string filepath, int texw, int texh, float centerx, float centery, float scale)
|
||||
{
|
||||
Name = name;
|
||||
Filepath = filepath;
|
||||
TexWidth = texw;
|
||||
TexHeight = texh;
|
||||
Center = new Vector3(centerx, centery, 0.0f);
|
||||
Scale = scale;
|
||||
|
||||
if (!File.Exists(filepath))
|
||||
{
|
||||
throw new Exception("File not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadTexture(Device device, Action<string> errorAction)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (device != null)
|
||||
{
|
||||
Tex = TextureLoader.CreateTexture2DFromBitmap(device, TextureLoader.LoadBitmap(new SharpDX.WIC.ImagingFactory2(), Filepath));
|
||||
TexView = new ShaderResourceView(device, Tex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorAction("Could not load map icon " + Filepath + " for " + Name + "!\n\n" + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void UnloadTexture()
|
||||
{
|
||||
if (TexView != null)
|
||||
{
|
||||
TexView.Dispose();
|
||||
TexView = null;
|
||||
}
|
||||
if (Tex != null)
|
||||
{
|
||||
Tex.Dispose();
|
||||
Tex = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
public class MapMarker
|
||||
{
|
||||
public MapIcon Icon { get; set; }
|
||||
public Vector3 WorldPos { get; set; } //actual world pos
|
||||
public Vector3 CamRelPos { get; set; } //updated per frame
|
||||
public Vector3 ScreenPos { get; set; } //position on screen (updated per frame)
|
||||
public string Name { get; set; }
|
||||
public List<string> Properties { get; set; } //additional data
|
||||
public bool IsMovable { get; set; }
|
||||
public float Distance { get; set; } //length of CamRelPos, updated per frame
|
||||
|
||||
public void Parse(string s)
|
||||
{
|
||||
Vector3 p = new Vector3(0.0f);
|
||||
string[] ss = s.Split(',');
|
||||
if (ss.Length > 1)
|
||||
{
|
||||
FloatUtil.TryParse(ss[0].Trim(), out p.X);
|
||||
FloatUtil.TryParse(ss[1].Trim(), out p.Y);
|
||||
}
|
||||
if (ss.Length > 2)
|
||||
{
|
||||
FloatUtil.TryParse(ss[2].Trim(), out p.Z);
|
||||
}
|
||||
if (ss.Length > 3)
|
||||
{
|
||||
Name = ss[3].Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
Name = string.Empty;
|
||||
}
|
||||
for (int i = 4; i < ss.Length; i++)
|
||||
{
|
||||
if (Properties == null) Properties = new List<string>();
|
||||
Properties.Add(ss[i].Trim());
|
||||
}
|
||||
WorldPos = p;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string cstr = Get3DWorldPosString();
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
cstr += ", " + Name;
|
||||
if (Properties != null)
|
||||
{
|
||||
foreach (string prop in Properties)
|
||||
{
|
||||
cstr += ", " + prop;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cstr;
|
||||
}
|
||||
|
||||
public string Get2DWorldPosString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", WorldPos.X, WorldPos.Y);
|
||||
}
|
||||
public string Get3DWorldPosString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}", WorldPos.X, WorldPos.Y, WorldPos.Z);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public struct MapSphere
|
||||
{
|
||||
public Vector3 CamRelPos { get; set; }
|
||||
public float Radius { get; set; }
|
||||
}
|
||||
|
||||
public struct MapBox
|
||||
{
|
||||
public Vector3 CamRelPos { get; set; }
|
||||
public Vector3 BBMin { get; set; }
|
||||
public Vector3 BBMax { get; set; }
|
||||
public Quaternion Orientation { get; set; }
|
||||
public Vector3 Scale { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public struct MapSelection
|
||||
{
|
||||
public YmapEntityDef EntityDef { get; set; }
|
||||
public Archetype Archetype { get; set; }
|
||||
public DrawableBase Drawable { get; set; }
|
||||
public DrawableGeometry Geometry { get; set; }
|
||||
public MetaWrapper EntityExtension { get; set; }
|
||||
public MetaWrapper ArchetypeExtension { get; set; }
|
||||
public YmapTimeCycleModifier TimeCycleModifier { get; set; }
|
||||
public YmapCarGen CarGenerator { get; set; }
|
||||
public YmapGrassInstanceBatch GrassBatch { get; set; }
|
||||
public YmapDistantLODLights DistantLodLights { get; set; }
|
||||
public YmapEntityDef MloEntityDef { get; set; }
|
||||
public WaterQuad WaterQuad { get; set; }
|
||||
public Bounds CollisionBounds { get; set; }
|
||||
public YnvPoly NavPoly { get; set; }
|
||||
public YndNode PathNode { get; set; }
|
||||
public YndLink PathLink { get; set; }
|
||||
public TrainTrackNode TrainTrackNode { get; set; }
|
||||
public ScenarioNode ScenarioNode { get; set; }
|
||||
public MCScenarioChainingEdge ScenarioEdge { get; set; }
|
||||
public AudioPlacement Audio { get; set; }
|
||||
|
||||
public bool MultipleSelection { get; set; }
|
||||
public Vector3 MultipleSelectionCenter { get; set; }
|
||||
|
||||
public BoundingBox AABB { get; set; }
|
||||
public BoundingSphere BSphere { get; set; }
|
||||
public int GeometryIndex { get; set; }
|
||||
public Vector3 CamRel { get; set; }
|
||||
public float HitDist { get; set; }
|
||||
|
||||
|
||||
public bool HasValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EntityDef != null) ||
|
||||
(Archetype != null) ||
|
||||
(Drawable != null) ||
|
||||
(Geometry != null) ||
|
||||
(EntityExtension != null) ||
|
||||
(ArchetypeExtension != null) ||
|
||||
(TimeCycleModifier != null) ||
|
||||
(CarGenerator != null) ||
|
||||
(GrassBatch != null) ||
|
||||
(WaterQuad != null) ||
|
||||
(CollisionBounds != null) ||
|
||||
(NavPoly != null) ||
|
||||
(PathNode != null) ||
|
||||
(TrainTrackNode != null) ||
|
||||
(DistantLodLights != null) ||
|
||||
(MloEntityDef != null) ||
|
||||
(ScenarioNode != null) ||
|
||||
(Audio != null);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasHit
|
||||
{
|
||||
get { return (HitDist != float.MaxValue); }
|
||||
}
|
||||
|
||||
|
||||
public bool CheckForChanges(MapSelection mhit)
|
||||
{
|
||||
return (EntityDef != mhit.EntityDef)
|
||||
|| (Archetype != mhit.Archetype)
|
||||
|| (Drawable != mhit.Drawable)
|
||||
|| (TimeCycleModifier != mhit.TimeCycleModifier)
|
||||
|| (ArchetypeExtension != mhit.ArchetypeExtension)
|
||||
|| (EntityExtension != mhit.EntityExtension)
|
||||
|| (CarGenerator != mhit.CarGenerator)
|
||||
|| (MloEntityDef != mhit.MloEntityDef)
|
||||
|| (DistantLodLights != mhit.DistantLodLights)
|
||||
|| (GrassBatch != mhit.GrassBatch)
|
||||
|| (WaterQuad != mhit.WaterQuad)
|
||||
|| (CollisionBounds != mhit.CollisionBounds)
|
||||
|| (NavPoly != mhit.NavPoly)
|
||||
|| (PathNode != mhit.PathNode)
|
||||
|| (TrainTrackNode != mhit.TrainTrackNode)
|
||||
|| (ScenarioNode != mhit.ScenarioNode)
|
||||
|| (Audio != mhit.Audio);
|
||||
}
|
||||
public bool CheckForChanges()
|
||||
{
|
||||
return (EntityDef != null)
|
||||
|| (Archetype != null)
|
||||
|| (Drawable != null)
|
||||
|| (TimeCycleModifier != null)
|
||||
|| (ArchetypeExtension != null)
|
||||
|| (EntityExtension != null)
|
||||
|| (CarGenerator != null)
|
||||
|| (MloEntityDef != null)
|
||||
|| (DistantLodLights != null)
|
||||
|| (GrassBatch != null)
|
||||
|| (WaterQuad != null)
|
||||
|| (CollisionBounds != null)
|
||||
|| (NavPoly != null)
|
||||
|| (PathNode != null)
|
||||
|| (PathLink != null)
|
||||
|| (TrainTrackNode != null)
|
||||
|| (ScenarioNode != null)
|
||||
|| (Audio != null);
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
EntityDef = null;
|
||||
Archetype = null;
|
||||
Drawable = null;
|
||||
Geometry = null;
|
||||
EntityExtension = null;
|
||||
ArchetypeExtension = null;
|
||||
TimeCycleModifier = null;
|
||||
CarGenerator = null;
|
||||
GrassBatch = null;
|
||||
WaterQuad = null;
|
||||
CollisionBounds = null;
|
||||
NavPoly = null;
|
||||
PathNode = null;
|
||||
PathLink = null;
|
||||
TrainTrackNode = null;
|
||||
DistantLodLights = null;
|
||||
MloEntityDef = null;
|
||||
ScenarioNode = null;
|
||||
ScenarioEdge = null;
|
||||
Audio = null;
|
||||
MultipleSelection = false;
|
||||
AABB = new BoundingBox();
|
||||
GeometryIndex = 0;
|
||||
CamRel = new Vector3();
|
||||
HitDist = float.MaxValue;
|
||||
}
|
||||
|
||||
public string GetNameString(string defval)
|
||||
{
|
||||
string name = defval;
|
||||
if (MultipleSelection)
|
||||
{
|
||||
name = "Multiple items";
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
name = EntityDef.CEntityDef.archetypeName.ToString();
|
||||
}
|
||||
else if (Archetype != null)
|
||||
{
|
||||
name = Archetype.Hash.ToString();
|
||||
}
|
||||
else if (TimeCycleModifier != null)
|
||||
{
|
||||
name = TimeCycleModifier.CTimeCycleModifier.name.ToString();
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
name = CarGenerator.CCarGen.carModel.ToString();
|
||||
}
|
||||
else if (DistantLodLights != null)
|
||||
{
|
||||
name = DistantLodLights.Ymap?.Name ?? "";
|
||||
}
|
||||
else if (CollisionBounds != null)
|
||||
{
|
||||
name = CollisionBounds.GetName();
|
||||
}
|
||||
if (EntityExtension != null)
|
||||
{
|
||||
name = EntityExtension.Name;
|
||||
}
|
||||
if (ArchetypeExtension != null)
|
||||
{
|
||||
name = ArchetypeExtension.Name;
|
||||
}
|
||||
if (WaterQuad != null)
|
||||
{
|
||||
name = "WaterQuad " + WaterQuad.ToString();
|
||||
}
|
||||
if (NavPoly != null)
|
||||
{
|
||||
name = "NavPoly " + NavPoly.ToString();
|
||||
}
|
||||
if (PathNode != null)
|
||||
{
|
||||
name = "PathNode " + PathNode.AreaID.ToString() + "." + PathNode.NodeID.ToString(); //+ FloatUtil.GetVector3String(PathNode.Position);
|
||||
}
|
||||
if (TrainTrackNode != null)
|
||||
{
|
||||
name = "TrainTrackNode " + FloatUtil.GetVector3String(TrainTrackNode.Position);
|
||||
}
|
||||
if (ScenarioNode != null)
|
||||
{
|
||||
name = ScenarioNode.ToString();
|
||||
}
|
||||
if (Audio != null)
|
||||
{
|
||||
name = Audio.ShortTypeName + " " + Audio.GetNameString();// FloatUtil.GetVector3String(Audio.InnerPos);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public string GetFullNameString(string defval)
|
||||
{
|
||||
string name = defval;
|
||||
if (MultipleSelection)
|
||||
{
|
||||
name = "Multiple items";
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
name = EntityDef.CEntityDef.archetypeName.ToString();
|
||||
}
|
||||
else if (Archetype != null)
|
||||
{
|
||||
name = Archetype.Hash.ToString();
|
||||
}
|
||||
else if (CollisionBounds != null)
|
||||
{
|
||||
name = CollisionBounds.GetName();
|
||||
}
|
||||
if (Geometry != null)
|
||||
{
|
||||
name += " (" + GeometryIndex.ToString() + ")";
|
||||
}
|
||||
if (TimeCycleModifier != null)
|
||||
{
|
||||
name = TimeCycleModifier.CTimeCycleModifier.name.ToString();
|
||||
}
|
||||
if (CarGenerator != null)
|
||||
{
|
||||
name = CarGenerator.NameString();
|
||||
}
|
||||
if (EntityExtension != null)
|
||||
{
|
||||
name += ": " + EntityExtension.Name;
|
||||
}
|
||||
if (ArchetypeExtension != null)
|
||||
{
|
||||
name += ": " + ArchetypeExtension.Name;
|
||||
}
|
||||
if (WaterQuad != null)
|
||||
{
|
||||
name = "WaterQuad " + WaterQuad.ToString();
|
||||
}
|
||||
if (NavPoly != null)
|
||||
{
|
||||
name = "NavPoly " + NavPoly.ToString();
|
||||
}
|
||||
if (PathNode != null)
|
||||
{
|
||||
name = "PathNode " + PathNode.AreaID.ToString() + "." + PathNode.NodeID.ToString();// + FloatUtil.GetVector3String(PathNode.Position);
|
||||
}
|
||||
if (TrainTrackNode != null)
|
||||
{
|
||||
name = "TrainTrackNode " + FloatUtil.GetVector3String(TrainTrackNode.Position);
|
||||
}
|
||||
if (ScenarioNode != null)
|
||||
{
|
||||
name = ScenarioNode.ToString();
|
||||
}
|
||||
if (Audio != null)
|
||||
{
|
||||
name = Audio.ShortTypeName + " " + Audio.GetNameString();// + FloatUtil.GetVector3String(Audio.InnerPos);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool CanShowWidget
|
||||
{
|
||||
get
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
if (MultipleSelection)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
public Vector3 WidgetPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MultipleSelection)
|
||||
{
|
||||
return MultipleSelectionCenter;
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
return EntityDef.WidgetPosition;
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
return CarGenerator.Position;
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
return NavPoly.Position;
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
return PathNode.Position;
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
return TrainTrackNode.Position;
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
return ScenarioNode.Position;
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
return Audio.InnerPos;
|
||||
}
|
||||
return Vector3.Zero;
|
||||
}
|
||||
}
|
||||
public Quaternion WidgetRotation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MultipleSelection)
|
||||
{
|
||||
return Quaternion.Identity;
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
return EntityDef.WidgetOrientation;
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
return CarGenerator.Orientation;
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
return Quaternion.Identity;
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
return Quaternion.Identity;
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
return Quaternion.Identity;
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
return ScenarioNode.Orientation;
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
return Audio.Orientation;
|
||||
}
|
||||
return Quaternion.Identity;
|
||||
}
|
||||
}
|
||||
public WidgetAxis WidgetRotationAxes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MultipleSelection)
|
||||
{
|
||||
return WidgetAxis.XYZ;
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
return WidgetAxis.XYZ;
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
return WidgetAxis.Z;
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
return WidgetAxis.XYZ;
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
return WidgetAxis.None;
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
return WidgetAxis.None;
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
return WidgetAxis.Z;
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
return WidgetAxis.XYZ;
|
||||
}
|
||||
return WidgetAxis.None;
|
||||
}
|
||||
}
|
||||
public Vector3 WidgetScale
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MultipleSelection)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
return EntityDef.Scale;
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
return new Vector3(CarGenerator.CCarGen.perpendicularLength);
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
return Vector3.One;
|
||||
}
|
||||
return Vector3.One;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void SetPosition(Vector3 newpos, Vector3 oldpos, bool editPivot)
|
||||
{
|
||||
if (MultipleSelection)
|
||||
{
|
||||
//don't do anything here for multiselection
|
||||
}
|
||||
else if (EntityDef != null)
|
||||
{
|
||||
if (editPivot)
|
||||
{
|
||||
EntityDef.SetPivotPositionFromWidget(newpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityDef.SetPositionFromWidget(newpos);
|
||||
}
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
CarGenerator.SetPosition(newpos);
|
||||
}
|
||||
else if (PathNode != null)
|
||||
{
|
||||
PathNode.SetPosition(newpos);
|
||||
}
|
||||
else if (NavPoly != null)
|
||||
{
|
||||
//NavPoly.SetPosition(newpos);
|
||||
|
||||
//if (projectForm != null)
|
||||
//{
|
||||
// projectForm.OnWorldNavPolyModified(NavPoly);
|
||||
//}
|
||||
}
|
||||
else if (TrainTrackNode != null)
|
||||
{
|
||||
TrainTrackNode.SetPosition(newpos);
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
ScenarioNode.SetPosition(newpos);
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
Audio.SetPosition(newpos);
|
||||
}
|
||||
|
||||
}
|
||||
public void SetRotation(Quaternion newrot, Quaternion oldrot, bool editPivot)
|
||||
{
|
||||
if (EntityDef != null)
|
||||
{
|
||||
if (editPivot)
|
||||
{
|
||||
EntityDef.SetPivotOrientationFromWidget(newrot);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityDef.SetOrientationFromWidget(newrot);
|
||||
}
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
CarGenerator.SetOrientation(newrot);
|
||||
}
|
||||
else if (ScenarioNode != null)
|
||||
{
|
||||
ScenarioNode.SetOrientation(newrot);
|
||||
}
|
||||
else if (Audio != null)
|
||||
{
|
||||
Audio.SetOrientation(newrot);
|
||||
}
|
||||
}
|
||||
public void SetScale(Vector3 newscale, Vector3 oldscale, bool editPivot)
|
||||
{
|
||||
if (EntityDef != null)
|
||||
{
|
||||
EntityDef.SetScale(newscale);
|
||||
}
|
||||
else if (CarGenerator != null)
|
||||
{
|
||||
CarGenerator.SetScale(newscale);
|
||||
AABB = new BoundingBox(CarGenerator.BBMin, CarGenerator.BBMax);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return GetFullNameString("[Empty]");
|
||||
}
|
||||
}
|
||||
|
||||
public enum MapSelectionMode
|
||||
{
|
||||
None = 0,
|
||||
Entity = 1,
|
||||
EntityExtension = 2,
|
||||
ArchetypeExtension = 3,
|
||||
TimeCycleModifier = 4,
|
||||
CarGenerator = 5,
|
||||
Grass = 6,
|
||||
WaterQuad = 7,
|
||||
Collision = 8,
|
||||
NavMesh = 9,
|
||||
Path = 10,
|
||||
TrainTrack = 11,
|
||||
DistantLodLights = 12,
|
||||
MloInstance = 13,
|
||||
Scenario = 14,
|
||||
PopZone = 15,
|
||||
Audio = 16,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user