protected void drawPositionItemNormalMode(int index) { //Label GUILayout.Label("<color=white>" + snapshots[index].GetValue("name") + "</color>"); GUILayout.BeginHorizontal(); //Up arrow if (index > 0) { if (GUILayout.Button(upIcon, buttonOptions)) { editIndexPos = index; editStatePos = EEditStates.MoveUp; } } //Down arrow if (index < snapshots.Count - 1) { if (GUILayout.Button(downIcon, buttonOptions)) { editIndexPos = index; editStatePos = EEditStates.MoveDown; } } //Play if (GUILayout.Button(playIcon, buttonOptions)) { servoManager.PlaySnapshot(snapshots[index]); } //Edit if (GUILayout.Button(editIcon, buttonOptions)) { positionName = snapshots[index].GetValue("name"); editIndexPos = index; editStatePos = EEditStates.EditMode; } //Delete if (GUILayout.Button(deleteIcon, buttonOptions)) { editIndexPos = index; editStatePos = EEditStates.Delete; } GUILayout.EndHorizontal(); }
protected void drawRecorder() { ConfigNode curNode = null; //Draw directions if need be. if (directionsVisible) { drawDirections(); return; } GUILayout.BeginVertical(); //Sequence name GUILayout.BeginHorizontal(); GUILayout.Label("<b><color=white>Name:</color></b>"); sequenceName = GUILayout.TextField(sequenceName); //Play sequence button if (GUILayout.Button(playIcon, buttonOptions)) { servoManager.PlaySnapshot(snapshots); } GUILayout.EndHorizontal(); //Positions GUILayout.BeginHorizontal(); GUILayout.Label("<b><color=white>Positions</color></b>"); //New snapshot button if (GUILayout.Button(newIcon, buttonOptions)) { ConfigNode snapshotNode = servoManager.TakeSnapshot(); snapshots.Add(snapshotNode); snapshotNode.AddValue("name", "Position" + snapshots.Count); } //Home button: set all controllers to their home position if (GUILayout.Button(homeIcon, buttonOptions)) { //First item in the sequences list is the home sequence. if (sequences.Count >= 1) { servoManager.PlaySequence(0); } } GUILayout.EndHorizontal(); //Snapshots list recorderScrollPos = GUILayout.BeginScrollView(recorderScrollPos); for (int index = 0; index < snapshots.Count; index++) { if (editStatePos != EEditStates.EditMode) { drawPositionItemNormalMode(index); } else { drawPositionItemEditMode(index); } } //Handle index repositioning and deletion events switch (editStatePos) { case EEditStates.MoveUp: curNode = snapshots[editIndexPos]; snapshots[editIndexPos] = snapshots[editIndexPos - 1]; snapshots[editIndexPos - 1] = curNode; editIndexPos = -1; editStatePos = EEditStates.None; break; case EEditStates.MoveDown: curNode = snapshots[editIndexPos]; snapshots[editIndexPos] = snapshots[editIndexPos + 1]; snapshots[editIndexPos + 1] = curNode; editIndexPos = -1; editStatePos = EEditStates.None; break; case EEditStates.Delete: snapshots.RemoveAt(editIndexPos); editIndexPos = -1; editStatePos = EEditStates.None; break; default: break; } GUILayout.EndScrollView(); //OK & Cancel buttons GUILayout.BeginHorizontal(); if (GUILayout.Button(okIcon, okCancelOptions)) { recorderIsVisible = false; //Set the name pendingSequenceNode.SetValue("name", sequenceName); //Add the snapshots if (pendingSequenceNode.HasNode(WBIServoManager.SNAPSHOT_NODE)) { pendingSequenceNode.RemoveNodes(WBIServoManager.SNAPSHOT_NODE); } foreach (ConfigNode snapshotNode in snapshots) { pendingSequenceNode.AddNode(snapshotNode); } //Either add a new sequence or update the selected one if (editIndexSeq == -1) { sequences.Add(pendingSequenceNode); } else { sequences[editIndexSeq] = pendingSequenceNode; } //Cleanup editIndexSeq = -1; } if (GUILayout.Button(cancelIcon, okCancelOptions)) { recorderIsVisible = false; } GUILayout.FlexibleSpace(); if (GUILayout.Button(helpIcon, okCancelOptions)) { directionsVisible = true; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
protected void drawPositionItemEditMode(int index) { //If this isn't the item we're editing then just show the label. if (index != editIndexPos) { GUILayout.Label("<color=white>" + snapshots[index].GetValue("name") + "</color>"); return; } //Position name GUILayout.Label("<b><color=white>Name:</color></b>"); positionName = GUILayout.TextField(positionName); GUILayout.BeginHorizontal(); //Update if (GUILayout.Button(cameraIcon, buttonOptions)) { pendingSnapshotUpdate = servoManager.TakeSnapshot(); pendingSnapshotUpdate.AddValue("name", positionName); } //Play if (GUILayout.Button(playIcon, buttonOptions)) { if (pendingSnapshotUpdate != null) { servoManager.PlaySnapshot(pendingSnapshotUpdate); } else { servoManager.PlaySnapshot(snapshots[index]); } } //OK if (GUILayout.Button(okIcon, buttonOptions)) { if (pendingSnapshotUpdate != null) { pendingSnapshotUpdate.SetValue("name", positionName); snapshots[editIndexPos] = pendingSnapshotUpdate; } else { snapshots[editIndexPos].SetValue("name", positionName); } editStatePos = EEditStates.None; pendingSnapshotUpdate = null; } //Cancel if (GUILayout.Button(cancelIcon, buttonOptions)) { editStatePos = EEditStates.None; pendingSnapshotUpdate = null; } GUILayout.EndHorizontal(); }