Commit 4e19e0d9 authored by Jitnaught's avatar Jitnaught
Browse files

Add groups. Convert to LemonUI. Fix "attach to object bone" setting attaching to vehicles.

parent 45bb7045
......@@ -7,6 +7,7 @@ namespace RopeCreator
{
class AttachedRope
{
internal RopeGroup group;
internal Rope rope;
internal Entity firstEntity, secondEntity;
internal Vector3 firstOffset, secondOffset;
......@@ -55,6 +56,7 @@ namespace RopeCreator
rope.AttachEntities(firstEntity, firstPos, secondEntity, secondPos, distance);
rope.ActivatePhysics();
this.group = RopeCreator.ropeGroups[Menu.liGroupIndex.SelectedIndex];
this.rope = rope;
this.firstEntity = firstEntity;
this.firstOffset = firstEntity.GetOffsetFromWorldCoords(firstPos);
......
using GTA;
using GTA.Math;
using NativeUI;
using LemonUI.Menus;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
......@@ -39,43 +39,43 @@ namespace RopeCreator
bool attachToPedBone = settingsFile.GetValue("Rope", "DefaultAttachToPedBone", false);
Menu.modEnabled = enabled;
if (Menu.cbEnabled != default(UIMenuCheckboxItem))
if (Menu.cbEnabled != default(NativeCheckboxItem))
{
Menu.cbEnabled.Checked = enabled;
}
Menu.showAimMarker = showAimMarker;
if (Menu.cbShowAimMarker != default(UIMenuCheckboxItem))
if (Menu.cbShowAimMarker != default(NativeCheckboxItem))
{
Menu.cbShowAimMarker.Checked = showAimMarker;
}
Menu.showEditMarkers = showEditMarkers;
if (Menu.cbShowEditMarkers != default(UIMenuCheckboxItem))
if (Menu.cbShowEditMarkers != default(NativeCheckboxItem))
{
Menu.cbShowEditMarkers.Checked = showEditMarkers;
}
Menu.type = ropeType;
if (Menu.liRopeIndex != default(UIMenuListItem))
if (Menu.liRopeIndex != default(NativeListItem<int>))
{
Menu.liRopeIndex.Index = ropeType - 1;
Menu.liRopeIndex.SelectedIndex = ropeType - 1;
}
Menu.breakable = breakable;
if (Menu.cbBreakable != default(UIMenuCheckboxItem))
if (Menu.cbBreakable != default(NativeCheckboxItem))
{
Menu.cbBreakable.Checked = breakable;
}
Menu.attachObjBone = attachToObjBone;
if (Menu.cbAttachObjBone != default(UIMenuCheckboxItem))
if (Menu.cbAttachObjBone != default(NativeCheckboxItem))
{
Menu.cbAttachObjBone.Checked = attachToObjBone;
}
Menu.attachPedBone = attachToPedBone;
if (Menu.cbAttachPedBone != default(UIMenuCheckboxItem))
if (Menu.cbAttachPedBone != default(NativeCheckboxItem))
{
Menu.cbAttachPedBone.Checked = attachToPedBone;
}
......
using GTA;
using GTA.Math;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace RopeCreator
......@@ -10,7 +11,7 @@ namespace RopeCreator
readonly Vector3 aimMarkerScale = new Vector3(0.05f, 0.05f, 0.05f), ropeMarkerScale = new Vector3(0.2f, 0.2f, 0.2f);
Vector3 aimMarkerPos = Vector3.Zero;
Vector3 ropeMarker1Pos = Vector3.Zero, ropeMarker2Pos = Vector3.Zero;
List<Vector3> ropeMarkerPositions = new List<Vector3>();
int nextGetMarkerPos = 0;
......@@ -32,20 +33,39 @@ namespace RopeCreator
private void GetEditRopeMarkerPos()
{
if (Menu.showEditMarkers && Menu.editRopeMenu.Visible)
{
int selectedRopeIndex = (int)Menu.liRopeIndex.Items[Menu.liRopeIndex.Index];
ropeMarkerPositions.Clear();
if (selectedRopeIndex > -1)
if (Menu.showEditMarkers)
{
if ((Menu.mainMenu.Visible && Menu.mainMenu.SelectedItem == Menu.liGroupIndex) || Menu.editGroupMenu.Visible || Menu.editRopeMenu.Visible)
{
var selectedRope = RopeCreator.ropes[selectedRopeIndex];
var group = RopeCreator.ropeGroups[Menu.liGroupIndex.SelectedIndex];
if ((Menu.mainMenu.Visible && Menu.mainMenu.SelectedItem == Menu.liGroupIndex) || Menu.editGroupMenu.Visible)
{
if (group.ropes.Count > 0)
{
foreach (var rope in group.ropes)
{
ropeMarkerPositions.Add(rope.firstEntity.GetOffsetInWorldCoords(rope.firstOffset));
ropeMarkerPositions.Add(rope.secondEntity.GetOffsetInWorldCoords(rope.secondOffset));
}
}
}
else
{
int selectedRopeIndex = Menu.liRopeIndex.SelectedItem;
ropeMarker1Pos = selectedRope.firstEntity.GetOffsetInWorldCoords(selectedRope.firstOffset);
ropeMarker2Pos = selectedRope.secondEntity.GetOffsetInWorldCoords(selectedRope.secondOffset);
if (selectedRopeIndex > -1)
{
var selectedRope = group.ropes[selectedRopeIndex];
ropeMarkerPositions.Add(selectedRope.firstEntity.GetOffsetInWorldCoords(selectedRope.firstOffset));
ropeMarkerPositions.Add(selectedRope.secondEntity.GetOffsetInWorldCoords(selectedRope.secondOffset));
}
}
}
else ropeMarker1Pos = ropeMarker2Pos = Vector3.Zero;
}
else ropeMarker1Pos = ropeMarker2Pos = Vector3.Zero;
}
private void GetAllMarkerPos()
......@@ -58,7 +78,7 @@ namespace RopeCreator
nextGetMarkerPos = Game.GameTime + 10;
}
}
private void DrawMarkers()
{
if (Game.IsScreenFadedIn && Game.Player.CanControlCharacter && Menu.modEnabled)
......@@ -68,10 +88,12 @@ namespace RopeCreator
World.DrawMarker(MarkerType.DebugSphere, aimMarkerPos, Vector3.Zero, Vector3.Zero, aimMarkerScale, Color.Blue);
}
if (Menu.showEditMarkers && ropeMarker1Pos != Vector3.Zero && ropeMarker2Pos != Vector3.Zero)
if (Menu.showEditMarkers && ropeMarkerPositions.Count > 0)
{
World.DrawMarker(MarkerType.DebugSphere, ropeMarker1Pos, Vector3.Zero, Vector3.Zero, ropeMarkerScale, Color.Purple);
World.DrawMarker(MarkerType.DebugSphere, ropeMarker2Pos, Vector3.Zero, Vector3.Zero, ropeMarkerScale, Color.Purple);
foreach (var pos in ropeMarkerPositions)
{
World.DrawMarker(MarkerType.DebugSphere, pos, Vector3.Zero, Vector3.Zero, ropeMarkerScale, Color.Purple);
}
}
}
}
......
This diff is collapsed.
using GTA;
using GTA.Math;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace RopeCreator
{
public class RopeCreator : Script
{
internal static List<AttachedRope> ropes = new List<AttachedRope>();
internal static RopeGroup[] ropeGroups = { new RopeGroup(), new RopeGroup(), new RopeGroup(), new RopeGroup(), new RopeGroup() };
int nextDeleteBadRopes = 0, nextReattachRopes = 0;
Vector3 firstPos = Vector3.Zero, firstOffset = Vector3.Zero;
......@@ -24,27 +23,24 @@ namespace RopeCreator
Interval = 1;
Tick += RopeCreator_Tick;
}
internal static void DeleteAllRopes()
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
rope.Delete();
}
ropes.Clear();
group.DeleteRopes();
}
}
internal static void DeleteLastRope(bool showSubtitle = false)
{
if (ropes.Count > 0)
var group = ropeGroups[Menu.liGroupIndex.SelectedIndex];
if (group.ropes.Count > 0)
{
int lastIndex = ropes.Count - 1;
ropes[lastIndex].Delete();
ropes.RemoveAt(lastIndex);
int lastIndex = group.ropes.Count - 1;
group.ropes[lastIndex].Delete();
group.ropes.RemoveAt(lastIndex);
UI.ShowSubtitle("Deleted last rope");
}
......@@ -52,71 +48,67 @@ namespace RopeCreator
internal static bool AreAllRopesWinding()
{
if (ropes.Count == 0) return false;
foreach (var rope in ropes)
bool oneNotEmpty = false;
foreach (var group in ropeGroups)
{
if (!rope.winding) return false;
if (group.ropes.Count == 0) continue; //skip empty groups
oneNotEmpty = true;
if (!group.AreAllRopesWinding()) return false;
}
return true;
//only return true if there is at least one rope
return oneNotEmpty;
}
internal static bool AreAllRopesUnwinding()
{
if (ropes.Count == 0) return false;
bool oneNotEmpty = false;
foreach (var rope in ropes)
foreach (var group in ropeGroups)
{
if (!rope.unwinding) return false;
if (group.ropes.Count == 0) continue; //skip empty groups
oneNotEmpty = true;
if (!group.AreAllRopesUnwinding()) return false;
}
return true;
//only return true if there is at least one rope
return oneNotEmpty;
}
internal static void StartWindAllRopes()
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
rope.StopUnwind();
rope.StartWind();
}
group.StartWindRopes();
}
}
internal static void StartUnwindAllRopes()
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
rope.StopWind();
rope.StartUnwind();
}
group.StartUnwindRopes();
}
}
internal static void StopWindAllRopes()
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
rope.StopWind();
}
group.StopWindRopes();
}
}
internal static void StopUnwindAllRopes()
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
rope.StopUnwind();
}
group.StopUnwindRopes();
}
}
......@@ -124,22 +116,11 @@ namespace RopeCreator
{
if (Game.GameTime >= nextDeleteBadRopes)
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
for (int i = 0; i < ropes.Count; i++)
{
var rope = ropes[i];
group.DeleteRopesWithBadEntity();
if (rope.firstEntity == null || !rope.firstEntity.Exists() || (rope.firstEntity.Model.IsPed && rope.firstEntity.IsDead) ||
rope.secondEntity == null || !rope.secondEntity.Exists() || (rope.secondEntity.Model.IsPed && rope.secondEntity.IsDead))
{
rope.Delete();
ropes.RemoveAt(i);
i--;
}
Yield();
}
Yield();
}
nextDeleteBadRopes = Game.GameTime + 1000;
......@@ -150,16 +131,9 @@ namespace RopeCreator
{
if (Game.GameTime >= nextReattachRopes)
{
if (ropes.Count > 0)
foreach (var group in ropeGroups)
{
foreach (var rope in ropes)
{
if ((rope.firstEntity.Model.IsPed && ((Ped)rope.firstEntity).IsRagdoll) ||
(rope.secondEntity.Model.IsPed && ((Ped)rope.secondEntity).IsRagdoll))
{
rope.Reattach();
}
}
group.ReattachRagdollPeds();
}
nextReattachRopes = Game.GameTime + 500;
......@@ -182,7 +156,7 @@ namespace RopeCreator
{
firstEntity = ray.HitEntity;
firstOffset = firstEntity.GetOffsetFromWorldCoords(firstPos);
firstAttachBone = !firstEntity.Model.IsVehicle && (Menu.attachPedBone && firstEntity.Model.IsPed) || (Menu.attachObjBone && !firstEntity.Model.IsPed);
firstAttachBone = !firstEntity.Model.IsVehicle && ((Menu.attachPedBone && firstEntity.Model.IsPed) || (Menu.attachObjBone && !firstEntity.Model.IsPed));
}
UI.ShowSubtitle("First position");
......@@ -199,7 +173,7 @@ namespace RopeCreator
if (secondEntity != null && secondEntity.Exists())
{
secondAttachBone = !secondEntity.Model.IsVehicle && (Menu.attachPedBone && secondEntity.Model.IsPed) || (Menu.attachObjBone && !secondEntity.Model.IsPed);
secondAttachBone = !secondEntity.Model.IsVehicle && ((Menu.attachPedBone && secondEntity.Model.IsPed) || (Menu.attachObjBone && !secondEntity.Model.IsPed));
}
}
......@@ -210,15 +184,17 @@ namespace RopeCreator
var rope = new AttachedRope(firstEntity, firstPos, firstAttachBone, secondEntity, secondPos, secondAttachBone);
ropes.Add(rope);
var group = ropeGroups[Menu.liGroupIndex.SelectedIndex];
if (ropes.Count > INI.maxRopes)
group.ropes.Add(rope);
if (group.ropes.Count > INI.maxRopes)
{
ropes[0].Delete();
ropes.RemoveAt(0);
group.ropes[0].Delete();
group.ropes.RemoveAt(0);
}
Menu.ReloadRopeIndices(ropes.Count, ropes.Count - 1);
Menu.ReloadRopeIndices(true); //true = select last item
firstPos = Vector3.Zero;
firstEntity = null;
......@@ -243,8 +219,10 @@ namespace RopeCreator
{
if (Helper.AreControlsJustPressed(INI.removeLastControls))
{
var group = ropeGroups[Menu.liGroupIndex.SelectedIndex];
DeleteLastRope(true);
Menu.ReloadRopeIndices(ropes.Count);
Menu.ReloadRopeIndices();
}
else if (Game.IsControlJustPressed(0, INI.attachControl))
{
......@@ -281,8 +259,10 @@ namespace RopeCreator
}
else if (e.KeyCode == INI.removeLastKey)
{
var group = ropeGroups[Menu.liGroupIndex.SelectedIndex];
DeleteLastRope(true);
Menu.ReloadRopeIndices(ropes.Count);
Menu.ReloadRopeIndices();
}
}
}
......
......@@ -23,8 +23,9 @@
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<Reference Include="NativeUI">
<HintPath>..\..\..\Downloaded Mods\Scripts\NativeUI-Release\NativeUI.dll</HintPath>
<Reference Include="LemonUI.SHVDN2, Version=1.3.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Downloaded Mods\Scripts\LemonUI_1.3\SHVDN2\LemonUI.SHVDN2.dll</HintPath>
</Reference>
<Reference Include="ScriptHookVDotNet2">
<HintPath>..\..\..\Downloaded Mods\Scripts\ScriptHookVDotNet_2.10.10\ScriptHookVDotNet2.dll</HintPath>
......@@ -43,10 +44,11 @@
<Compile Include="Menu.cs" />
<Compile Include="RopeCreator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RopeGroup.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetPath)" "C:\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\$(TargetFileName)"</PostBuildEvent>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName)*" "C:\Games\Grand Theft Auto V\scripts\"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
using GTA;
using System.Collections.Generic;
namespace RopeCreator
{
class RopeGroup
{
internal List<AttachedRope> ropes = new List<AttachedRope>();
internal void StartWindRopes()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
rope.StopUnwind();
rope.StartWind();
}
}
internal void StopWindRopes()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
rope.StopWind();
}
}
internal void StartUnwindRopes()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
rope.StopWind();
rope.StartUnwind();
}
}
internal void StopUnwindRopes()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
rope.StopUnwind();
}
}
internal void DeleteRopes()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
rope.Delete();
}
ropes.Clear();
}
internal bool AreAllRopesWinding()
{
if (ropes.Count == 0) return false;
foreach (var rope in ropes)
{
if (!rope.winding) return false;
}
return true;
}
internal bool AreAllRopesUnwinding()
{
if (ropes.Count == 0) return false;
foreach (var rope in ropes)
{
if (!rope.unwinding) return false;
}
return true;
}
internal void DeleteRopesWithBadEntity()
{
if (ropes.Count == 0) return;
for (int i = 0; i < ropes.Count; i++)
{
var rope = ropes[i];
if (rope.firstEntity == null || !rope.firstEntity.Exists() || (rope.firstEntity.Model.IsPed && rope.firstEntity.IsDead) ||
rope.secondEntity == null || !rope.secondEntity.Exists() || (rope.secondEntity.Model.IsPed && rope.secondEntity.IsDead))
{
rope.Delete();
ropes.RemoveAt(i);
i--;
}
}
}
internal void ReattachRagdollPeds()
{
if (ropes.Count == 0) return;
foreach (var rope in ropes)
{
if ((rope.firstEntity.Model.IsPed && ((Ped)rope.firstEntity).IsRagdoll) ||
(rope.secondEntity.Model.IsPed && ((Ped)rope.secondEntity).IsRagdoll))
{
rope.Reattach();
}
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment