Skip to content

Commit 57876af

Browse files
authored
Merge pull request #169 from mjavaly/graham/atn-indices-fix
AssociatedTwineNodes editor fix -- no more shuffling of indices
2 parents d4a18d9 + ccaf1a6 commit 57876af

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed
Binary file not shown.

Project/Assets/Editor/Utilities/PrairieGUI.cs

+23-3
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,32 @@ public static List<int> drawTwineNodeDropdownList (string listTitle, string item
152152
}
153153
EditorGUILayout.EndHorizontal ();
154154
}
155-
if (GUILayout.Button(addRowContent, plusButtonWidth))
156-
{
157-
selectedIndices.Add (0);
155+
156+
if (nodes.Length != selectedIndices.Count) {
157+
// Only show button if there are more nodes available to select:
158+
if (GUILayout.Button (addRowContent, plusButtonWidth)) {
159+
int firstAvailableIndex = GetFirstIndexNotInList (selectedIndices, nodes.Length - 1);
160+
selectedIndices.Add (firstAvailableIndex);
161+
}
158162
}
159163
EditorGUI.indentLevel -= 1;
160164

161165
return selectedIndices;
162166
}
167+
168+
/// <summary>
169+
/// Gets the first index that does not appear in a list of indices.
170+
/// </summary>
171+
/// <returns>The first index not in list.</returns>
172+
/// <param name="indexList">Index list.</param>
173+
/// <param name="highestPossibleIndex">Highest possible index.</param>
174+
private static int GetFirstIndexNotInList(List<int> indexList, int highestPossibleIndex) {
175+
for (int i = 0; i <= highestPossibleIndex; i++) {
176+
if (!indexList.Contains (i)) {
177+
return i;
178+
}
179+
}
180+
181+
return 0;
182+
}
163183
}

Project/Assets/Prairie/Framework/Script/Interaction/AssociatedTwineNodes.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,8 @@
55
[AddComponentMenu("Prairie/Twine/Associated Twine Nodes")]
66
public class AssociatedTwineNodes : PromptInteraction
77
{
8+
// This list is updated through the AssociatedTwineNodesEditor:
89
public List<GameObject> associatedTwineNodeObjects = new List<GameObject>();
9-
public List<int> selectedTwineNodeIndices;
10-
11-
public void UpdateTwineNodeObjectsFromIndices(TwineNode[] nodes)
12-
{
13-
14-
if (this.associatedTwineNodeObjects != null) {
15-
// Clear the list of twine nodes and re-add them based on the new indices:
16-
this.associatedTwineNodeObjects.Clear ();
17-
} else {
18-
// Make sure it exists!
19-
this.associatedTwineNodeObjects = new List<GameObject> ();
20-
}
21-
foreach (int index in this.selectedTwineNodeIndices) {
22-
GameObject twineNodeObject = nodes [index].gameObject;
23-
this.associatedTwineNodeObjects.Add (twineNodeObject);
24-
}
25-
}
2610

2711
protected override void PerformAction ()
2812
{

0 commit comments

Comments
 (0)