Skip to content
Snippets Groups Projects
Commit c9c55f8b authored by WJohnM18's avatar WJohnM18
Browse files

Update code so visual blueprint object is updated via preset

parent 990f5a71
No related branches found
No related tags found
1 merge request!10Evaluation
......@@ -111,38 +111,54 @@ public class ObservableRenderPreset : IRenderPreset, IObservable<IRenderPreset>
return;
}
bool validNameChange = false;
string currentBlueprintName;
foreach (IVisualBlueprint currentBlueprint in visualBlueprints)
if (BlueprintNameInUse(newName))
{
currentBlueprintName = currentBlueprint.GetName();
if (currentBlueprintName == blueprint.GetName())
{
validNameChange = true;
}
else if (currentBlueprintName == newName)
OnErrorAll(new ArgumentException(string.Format("Blueprint {0} already exists. Choose a different name", newName)));
}
else
{
string currentBlueprintName = "";
foreach (IVisualBlueprint currentBlueprint in visualBlueprints)
{
validNameChange = false;
break;
currentBlueprintName = currentBlueprint.GetName();
if (currentBlueprintName == blueprint.GetName())
{
blueprint.SetName(newName);
}
}
}
}
if (validNameChange)
public void UpdateVisualBlueprintObject(IVisualBlueprint blueprint, GameObject blueprintObject)
{
try
{
try
foreach (IVisualBlueprint currentBlueprint in visualBlueprints)
{
blueprint.SetName(newName);
OnNextAll();
} catch(InvalidVisualBlueprintNameException e)
{
OnErrorAll(e);
if (currentBlueprint.GetName() == blueprint.GetName())
{
blueprint.SetBlueprintObject(blueprintObject);
}
}
} catch(NullBlueprintObjectException e)
{
OnErrorAll(e);
}
else
}
private bool BlueprintNameInUse(string nameToCheck)
{
foreach(IVisualBlueprint blueprint in visualBlueprints)
{
OnErrorAll(new ArgumentException(string.Format("Blueprint {0} already exists. Choose a different name", newName)));
if (blueprint.GetName() == nameToCheck)
{
return true;
}
}
return false;
}
public HashSet<IVisualBlueprint> GetVisualBlueprints()
......
......@@ -89,18 +89,8 @@ public class ObservableRenderPresetManager : IRenderPresetManager, IObservable<I
return;
}
bool newNameAlreadyInUse = false;
string currentPresetName;
foreach (IRenderPreset currentPreset in renderSettingPresets)
{
currentPresetName = currentPreset.GetName();
bool newNameAlreadyInUse = IsPresetNameInUse(newName);
if (currentPresetName == newName)
{
newNameAlreadyInUse = true;
break;
}
}
if (!newNameAlreadyInUse)
{
......@@ -114,6 +104,19 @@ public class ObservableRenderPresetManager : IRenderPresetManager, IObservable<I
}
}
private bool IsPresetNameInUse(string newName)
{
foreach (IRenderPreset currentPreset in renderSettingPresets)
{
if (currentPreset.GetName() == newName)
{
return true;
}
}
return false;
}
private IRenderPreset GetPresetWithName(string name)
{
foreach (IRenderPreset preset in renderSettingPresets)
......
......@@ -10,7 +10,8 @@ public interface IRenderPreset {
HashSet<IVisualBlueprint> GetVisualBlueprints();
void RemoveVisualBlueprint(IVisualBlueprint blueprint);
void UpdateVisualBlueprintName(IVisualBlueprint blueprint, string newName);
void SetPeripheralSettings(IPeripheralSettings peripheralSettings);
void UpdateVisualBlueprintObject(IVisualBlueprint blueprint, GameObject blueprintObject);
void SetPeripheralSettings(IPeripheralSettings peripheralSettings);
IPeripheralSettings GetPeripheralSettings();
void SetGraphicalFidelity(IGraphicalFidelity graphicalFidelity);
IGraphicalFidelity GetGraphicalFidelity();
......
......@@ -27,14 +27,9 @@ public class VisualBlueprintPanel: IVisualBlueprintPanel
this.preset.UpdateVisualBlueprintName(visualBlueprint, EditorGUILayout.TextField(nameLabel, visualBlueprint.GetName()));
GameObject o = (GameObject)EditorGUILayout.ObjectField(templateLabel, visualBlueprint.GetBlueprintObject(), typeof(GameObject), false);
try
{
visualBlueprint.SetBlueprintObject(o);
} catch (NullBlueprintObjectException e)
{
EditorUtility.DisplayDialog("Invalid blueprint object",
"Blueprint object cannot be None", "Okay", "Cancel");
}
this.preset.UpdateVisualBlueprintObject(visualBlueprint, o);
if (GUILayout.Button("Apply", GUILayout.Width(50)))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment