Skip to content

Commit

Permalink
Merge branch 'FR7-Multiselect' into STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Norris authored and Tom Norris committed Sep 18, 2020
2 parents 1d6667f + 0a871c1 commit 914757d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 85 deletions.
122 changes: 89 additions & 33 deletions Code/JsonBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using System.Linq;
using Godot;
using LibT;
using LibT.Maths;
using LibT.Serialization;
using LibT.Services;
using RSG;
using RSG.Exceptions;
using Color = Godot.Color;
using File = Godot.File;
using Vector2 = Godot.Vector2;

public class JsonBuilder : ColorRect
{
Expand Down Expand Up @@ -84,20 +87,26 @@ public class JsonBuilder : ColorRect
[Export] private NodePath _helpInfoPopupPath;
private HelpPopup _helpInfoPopup;

public Dictionary<string, KeySlot> generatedKeys = new Dictionary<string, KeySlot>();
public readonly List<Tuple<KeyLinkSlot, string>> _loadingLinks = new List<Tuple<KeyLinkSlot, string>>();
public readonly List<Tuple<KeyLinkSlot, string>> loadingLinks = new List<Tuple<KeyLinkSlot, string>>();
public readonly Dictionary<string, KeySlot> generatedKeys = new Dictionary<string, KeySlot>();

private readonly Dictionary<string,GenericDataArray> _nodeData = new Dictionary<string, GenericDataArray>();
private readonly List<SlottedGraphNode> _nodes = new List<SlottedGraphNode>();
private readonly List<SlottedGraphNode> _selection = new List<SlottedGraphNode>();
private readonly List<GenericDataArray> _copied = new List<GenericDataArray>();
private readonly List<GenericDataArray> _duplicates = new List<GenericDataArray>();
private readonly List<Color> _parentChildColors = new List<Color> ();
private readonly List<Color> _keyColors = new List<Color>();
public bool includeNodeData = true;
public bool includeGraphData = true;
public bool pastingData = false;

public bool copyingData;
public bool pastingData;

private Vector2 _copiedCorner = new Vector2(50,100);
private Vector2 _offset = new Vector2(50,100);
private Vector2 _buffer = new Vector2(40,10);
private List<string> _recentTemplates = new List<string>();
private List<string> _recentFiles = new List<string>();
private Dictionary<string,GenericDataArray> _nodeData = new Dictionary<string, GenericDataArray>();
private List<SlottedGraphNode> _nodes = new List<SlottedGraphNode>();
private SlottedGraphNode _lastSelection;
private GenericDataArray _copied;
private PopupMenu _editMenu;
private PopupMenu _createSubmenu;
private PopupMenu _recentTemplateSubmenu;
Expand All @@ -120,9 +129,6 @@ private string SaveFilePath
}
private string _saveFilePath;

private List<Color> _parentChildColors = new List<Color> ();
private List<Color> _keyColors = new List<Color>();


public bool HasUnsavedChanges
{
Expand Down Expand Up @@ -786,55 +792,105 @@ private void OpenHelpPopup()

private void RequestCopyNode()
{
if( _lastSelection == null ) return;

if(_selection.Count <= 0) return;

_copied.Clear();
_duplicates.Clear();
includeNodeData = true;
includeGraphData = true;

_copied = _lastSelection.GetObjectData();
copyingData = true;

_copiedCorner = _selection[0].Offset;

foreach( SlottedGraphNode node in _selection )
{
_copiedCorner.x = Maths.Min( node.Offset.x, _copiedCorner.x );
_copiedCorner.y = Maths.Min( node.Offset.y, _copiedCorner.y );

_copied.Add( node.GetObjectData() );
}

for( int i = _copied.Count-1; i >=0; i-- )
{
GenericDataArray copied = _copied[i];
for( int k = _duplicates.Count-1; k >=0; k-- )
{
if( !copied.DeepEquals( _duplicates[k] ) ) continue;

_copied.RemoveAt( i );
_duplicates.RemoveAt( k );
break;
}
}

copyingData = false;
}

public bool IsSelected( SlottedGraphNode node )
{
if(_selection.Contains( node ))
{
_duplicates.Add( node.GetObjectData() );
return true;
}

return false;
}

private void RequestPasteNode()
{
if( _copied == null ) return;
if( _copied.Count <= 0 ) return;

pastingData = true;

int start = _nodes.Count;
LoadNode( _copied );

Vector2 startOffset = _offset - _nodes[start].Offset;
Vector2 startOffset = _offset - _copiedCorner;

for( int i = 0; i < _copied.Count; i++ )
{
LoadNode( _copied[i] );
}

for( int i = start; i < _nodes.Count; i++ )
{
_nodes[i].Offset = _nodes[i].Offset + startOffset;
_graph.SetSelected( _nodes[i] );
//_graph.SetSelected( _nodes[i] );
}

pastingData = false;
}

private void RequestDeleteNode()
{
if( _lastSelection == null ) return;
for( int i = _selection.Count-1; i >= 0; i-- )
{
if(_selection[i] == null) return;

_selection[i].CloseRequest();
}

_lastSelection.CloseRequest();
_selection.Clear();

HasUnsavedChanges = true;
}

private void SelectNode(Node node)
{
//Log.LogL( $"Selected {node.Name}" );
_lastSelection = node as SlottedGraphNode;
SlottedGraphNode graphNode = node as SlottedGraphNode;

if( _selection.Contains( graphNode ) ) return;

Log.LogL( $"Selected {node.Name}" );
_selection.Add( graphNode );

HasUnsavedChanges = true;
}

private void DeselectNode(Node node)
{
//Log.LogL( $"Deselected {node.Name}" );
//_lastSelection = null;
SlottedGraphNode graphNode = node as SlottedGraphNode;

if( !_selection.Contains( graphNode ) ) return;

Log.LogL( $"Deselected {node.Name}" );
_selection.Remove( graphNode );
}
#endregion

Expand Down Expand Up @@ -1031,12 +1087,12 @@ private void LoadData(GenericDataArray data)
LoadNode( data );
}

foreach( Tuple<KeyLinkSlot,string> loadingLink in _loadingLinks )
foreach( Tuple<KeyLinkSlot,string> loadingLink in loadingLinks )
{
LinkToKey( loadingLink.Item1, loadingLink.Item2 );
}

_loadingLinks.Clear();
loadingLinks.Clear();
}

public void CatchException( Exception ex )
Expand Down Expand Up @@ -1287,9 +1343,9 @@ private void OnDisconnectionRequest( string from, int fromSlot, string to, int t

public void FreeNode( SlottedGraphNode graphNode )
{
if( _lastSelection == graphNode )
if( _selection.Contains( graphNode ) )
{
_lastSelection = null;
_selection.Remove( graphNode );
}

Godot.Collections.Array connections = _graph.GetConnectionList();
Expand Down
2 changes: 1 addition & 1 deletion Code/NodeSlots/KeyLinkSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void SetObjectData( GenericDataArray objData )

if( string.IsNullOrEmpty( key ) ) return;

_builder.Get._loadingLinks.Add( new Tuple<KeyLinkSlot, string>( this, key ) );
_builder.Get.loadingLinks.Add( new Tuple<KeyLinkSlot, string>( this, key ) );
}

public string GetString()
Expand Down
1 change: 1 addition & 0 deletions Code/NodeSlots/KeySlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private void SetKey( string force = null )
{
force = null;
}

if(string.IsNullOrEmpty( force ))
{
force = Tool.GetUniqueKey( _keySize, builder.Get.generatedKeys.ContainsKey, 4, _keyPrefix );
Expand Down
4 changes: 3 additions & 1 deletion Code/NodeSlots/LinkToChildSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public bool UnLinkChild( SlottedGraphNode child )

public void GetObjectData( GenericDataArray objData )
{
if( _child == null )
if( _child == null ||
( _builderInjection.Get.copyingData &&
!_builderInjection.Get.IsSelected( _child )))
{
switch(emptyHandling)
{
Expand Down
Binary file modified DLLs/LibT.dll
Binary file not shown.
Binary file modified DLLs/RSG.Promises.dll
Binary file not shown.
56 changes: 7 additions & 49 deletions MetaMaker.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Godot.NET.Sdk/3.2.3">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EF4BBC8F-A1BF-4ADF-9A6D-BD13953C047A}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputPath>.mono\temp\bin\$(Configuration)</OutputPath>
<RootNamespace>MetaMaker</RootNamespace>
<AssemblyName>MetaMaker</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<GodotProjectGeneratorVersion>1.0.0.0</GodotProjectGeneratorVersion>
<BaseIntermediateOutputPath>.mono\temp\obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>
<ApiConfiguration Condition=" '$(Configuration)' != 'ExportRelease' ">Debug</ApiConfiguration>
<ApiConfiguration Condition=" '$(Configuration)' == 'ExportRelease' ">Release</ApiConfiguration>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ExportDebug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ExportRelease|AnyCPU' ">
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<DefineConstants>$(GodotDefineConstants);GODOT;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>$(GodotDefineConstants);GODOT;DEBUG;TOOLS;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TargetFramework>net472</TargetFramework>
<!--The following properties were overriden during migration to prevent errors.
Enabling them may require other manual changes to the project and its files.-->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies">
<Version>1.0.0</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<Reference Include="GodotSharp">
<Private>False</Private>
<HintPath>$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/GodotSharp.dll</HintPath>
</Reference>
<Reference Include="GodotSharpEditor" Condition=" '$(Configuration)' == 'Debug' ">
<Private>False</Private>
<HintPath>$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/GodotSharpEditor.dll</HintPath>
</Reference>
<Reference Include="LibT, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>DLLs\LibT.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -104,5 +63,4 @@
<Compile Include="DLLs\NodeExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion Resources/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.2

0 comments on commit 914757d

Please sign in to comment.