public void AddPrerequisite(Blueprint child, Blueprint pre) { var bpr = (from i in child.prerequisites select i.blueprint).ToList(); if (!bpr.Contains(pre)) { var newPre = BlueprintModelAsset.Create <BlueprintPrerequisite>(Component); BlueprintModelAsset.Rename(newPre, pre.ID); newPre.blueprint = pre; child.prerequisites.Add(newPre); } }
public bool DrawIDWidget(BlueprintModelAsset asset, SerializedObject so, GUILayoutOption labelWidth, GUILayoutOption widgetWidth, string widgetID = null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("ID", labelWidth); var idProp = so.FindProperty("ID"); if (widgetID != null) { GUI.SetNextControlName(widgetID); } EditorGUILayout.PropertyField(idProp, GUIContent.none, widgetWidth); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); BlueprintModelAsset.Rename(asset, idProp.stringValue); return(true); } return(false); }
public ResourceConsumptionRate GetConsumer(List <ResourceConsumptionRate> rates, Resource newResource) { var costs = (from i in rates select i.resource).ToList(); var index = costs.IndexOf(newResource); if (index < 0) { var newCost = BlueprintModelAsset.Create <ResourceConsumptionRate> (Component); newCost.resource = newResource; rates.Add(newCost); BlueprintModelAsset.Rename(newCost, "" + "-" + newResource.ID); Component.SetDirty(); needRepaint = true; return(newCost); } else { return(rates [index]); } }
public ResourceCost GetCost(List <ResourceCost> costs, Resource newResource) { var recosts = (from i in costs select i.resource).ToList(); var index = recosts.IndexOf(newResource); if (index < 0) { var newCost = BlueprintModelAsset.Create <ResourceCost> (Component); newCost.resource = newResource; costs.Add(newCost); BlueprintModelAsset.Rename(newCost, "" + "-" + newResource.ID); Component.SetDirty(); needRepaint = true; return(newCost); } else { return(costs [index]); } }
public void ValidateModel() { if (Component == null) { Debug.Log("NULL"); return; } Component.groups.RemoveAll((i) => i == null); Component.blueprints.RemoveAll((i) => i == null); foreach (var b in Component.blueprints) { b.prerequisites.RemoveAll((i) => i == null); if (b.isFactory) { if (b.factory == null) { b.factory = BlueprintModelAsset.Create <Factory> (Component); BlueprintModelAsset.Rename(b.factory, b.ID); Component.SetDirty(); } b.factory.blueprints.RemoveAll((i) => i == null); } foreach (var r in Component.resources) { GetCost(b.costs, r); GetConsumer(b.consumptionRates, r); GetProducer(b.productionRates, r); foreach (var u in b.upgradeLevels) { GetCost(u.costs, r); GetConsumer(u.consumptionRates, r); GetProducer(u.productionRates, r); } } } }
public override void Draw() { DrawHelp(); widget.DrawRow(() => { GUILayout.Label("ID", GUILayout.Width(64)); GUILayout.Label("Qty", GUILayout.Width(64)); GUILayout.Label("MaxCost", GUILayout.Width(64)); GUILayout.Label("Regen?", GUILayout.Width(64)); GUILayout.Label("Rate", GUILayout.Width(64)); GUILayout.Label("Capped?", GUILayout.Width(64)); GUILayout.Label("Max", GUILayout.Width(64)); GUILayout.Label("Prefab", GUILayout.Width(128)); GUILayout.Label("Color", GUILayout.Width(128)); }); var deleteId = -1; var background = GUI.backgroundColor; for (var i = 0; i < Component.resources.Count; i++) { var r = Component.resources [i]; widget.DrawBoxedRow(() => { GUI.backgroundColor = r.ID == null || r.ID == "" ? styles.MISSING_COLOR : background; var so = new SerializedObject(r); so.Update(); var idWidth = GUILayout.Width(64); EditorGUI.BeginChangeCheck(); var idProp = so.FindProperty("ID"); EditorGUILayout.PropertyField(idProp, GUIContent.none, idWidth); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); BlueprintModelAsset.Rename(r, idProp.stringValue); Component.SetDirty(); } EditorGUILayout.PropertyField(so.FindProperty("qty"), GUIContent.none, idWidth); EditorGUILayout.PropertyField(so.FindProperty("maxPossibleCost"), GUIContent.none, idWidth); EditorGUILayout.PropertyField(so.FindProperty("autoReplenish"), GUIContent.none, GUILayout.Width(64)); GUI.enabled = r.autoReplenish; EditorGUILayout.PropertyField(so.FindProperty("autoReplenishRate"), GUIContent.none, GUILayout.Width(64)); GUI.enabled = true; EditorGUILayout.PropertyField(so.FindProperty("hasMaximumCapacity"), GUIContent.none, GUILayout.Width(64)); GUI.enabled = r.hasMaximumCapacity; EditorGUILayout.PropertyField(so.FindProperty("maximumCapacity"), GUIContent.none, GUILayout.Width(64)); GUI.enabled = true; EditorGUILayout.PropertyField(so.FindProperty("gameObject"), GUIContent.none, GUILayout.Width(128)); EditorGUILayout.PropertyField(so.FindProperty("color"), GUIContent.none, GUILayout.Width(128)); so.ApplyModifiedProperties(); GUILayout.Space(10); if (widget.ControlButton(styles.DELETE_COLOR, "Delete Resource")) { deleteId = i; } }); GUILayout.Space(10); } GUI.backgroundColor = background; if (widget.ControlButton(styles.CREATE_COLOR, "Add a new Resouce")) { editor.RunNext(() => { Component.resources.Add(BlueprintModelAsset.Create <Resource> (Component)); Component.SetDirty(); editor.needRepaint = true; editor.ValidateModel(); }); } if (deleteId >= 0) { var performDelete = true; var ID = Component.resources [deleteId].ID; if (!(ID == null || ID == "")) { performDelete = EditorUtility.DisplayDialog("This operation can not be undone!", "Are you sure you want to remove this Resource?", "Yes", "Cancel"); } if (performDelete) { Component.Delete(Component.resources [deleteId]); Component.SetDirty(); editor.needRepaint = true; } } }
public void DrawBlueprints() { GUILayout.Label("Statistics per Blueprint Level"); GUILayout.BeginHorizontal("box"); var groupList = (from i in Component.groups select i.ID).ToArray(); var bpList = (from i in Component.blueprints where i.@group == Component.groups [groupIndex] select i.ID).ToArray(); if (bpList.Length == 0) { return; } var bp = Component.FindBlueprint(bpList [bpIndex]); var levelList = (from i in Enumerable.Range(0, bp.upgradeLevels.Count + 1) select i.ToString()).ToArray(); var statList = (from i in Component.stats select i.ID).ToArray(); GUILayout.Label("Group:"); groupIndex = EditorGUILayout.Popup(groupIndex, groupList); GUILayout.Label("Blueprint"); bpIndex = EditorGUILayout.Popup(bpIndex, bpList); GUILayout.Label("Level"); levelIndex = EditorGUILayout.Popup(levelIndex, levelList); GUILayout.EndHorizontal(); var statValues = (from i in bp.statValues where i.level == levelIndex select i).ToArray(); var headWidth = GUILayout.Width(128); var colWidth = GUILayout.Width(96); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("Statistic", headWidth); GUILayout.Label("Start Value", colWidth); GUILayout.Label("Max Value", colWidth); GUILayout.Label("Regen?", colWidth); GUILayout.Label("Regen Rate", colWidth); GUILayout.Label("Notify If Zero?", colWidth); GUILayout.Space(10); GUILayout.EndHorizontal(); foreach (var statValue in statValues) { var so = new SerializedObject(statValue); so.Update(); if (statValue.stat == null) { continue; } GUILayout.BeginHorizontal("box"); GUILayout.Label(statValue.stat.ID, headWidth); EditorGUILayout.PropertyField(so.FindProperty("startValue"), GUIContent.none, colWidth); EditorGUILayout.PropertyField(so.FindProperty("maxValue"), GUIContent.none, colWidth); EditorGUILayout.PropertyField(so.FindProperty("regen"), GUIContent.none, colWidth); EditorGUILayout.PropertyField(so.FindProperty("regenRate"), GUIContent.none, colWidth); EditorGUILayout.PropertyField(so.FindProperty("notifyIfZero"), GUIContent.none, colWidth); GUILayout.Space(10); so.ApplyModifiedProperties(); if (widget.ControlButton(styles.DELETE_COLOR, "Delete Stat")) { bp.statValues.Remove(statValue); BlueprintModelAsset.Remove(statValue); } GUILayout.EndHorizontal(); } if (Component.stats.Count > 0) { GUILayout.BeginHorizontal(); statIndex = EditorGUILayout.Popup(statIndex, statList, headWidth); if (statIndex > Component.stats.Count) { statIndex = 0; } var statToAdd = Component.stats [statIndex]; var enabled = GUI.enabled; GUI.enabled = (from i in statValues where i.stat == statToAdd select i).Count() == 0; if (widget.ControlButton(styles.CREATE_COLOR, "Add Stat")) { var newStatValue = BlueprintModelAsset.Create <UnitStatValue> (Component); newStatValue.stat = statToAdd; newStatValue.level = levelIndex; BlueprintModelAsset.Rename(newStatValue, bp.ID + "-" + statToAdd.ID); bp.statValues.Add(newStatValue); Component.SetDirty(); editor.needRepaint = true; } GUI.enabled = enabled; GUILayout.EndHorizontal(); } }
public void DrawStats() { DrawHelp(); GUILayout.Label("Statistics"); widget.DrawRow(() => { GUILayout.Label("ID", GUILayout.Width(64)); GUILayout.Label("Color", GUILayout.Width(128)); }); var deleteId = -1; var background = GUI.backgroundColor; for (var i = 0; i < Component.stats.Count; i++) { var r = Component.stats [i]; widget.DrawBoxedRow(() => { GUI.backgroundColor = r.ID == null || r.ID == "" ? styles.MISSING_COLOR : background; var so = new SerializedObject(r); so.Update(); var idWidth = GUILayout.Width(64); EditorGUI.BeginChangeCheck(); var idProp = so.FindProperty("ID"); EditorGUILayout.PropertyField(idProp, GUIContent.none, idWidth); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); BlueprintModelAsset.Rename(r, idProp.stringValue); Component.SetDirty(); } EditorGUILayout.PropertyField(so.FindProperty("color"), GUIContent.none, GUILayout.Width(128)); so.ApplyModifiedProperties(); GUILayout.Space(10); if (widget.ControlButton(styles.DELETE_COLOR, "Delete Stat")) { deleteId = i; } }); GUILayout.Space(10); } GUI.backgroundColor = background; if (widget.ControlButton(styles.CREATE_COLOR, "Add a new Stat")) { Component.stats.Add(BlueprintModelAsset.Create <UnitStat> (Component)); Component.SetDirty(); editor.needRepaint = true; } if (deleteId >= 0) { var performDelete = true; var ID = Component.stats [deleteId].ID; if (!(ID == null || ID == "")) { performDelete = EditorUtility.DisplayDialog("This operation can not be undone!", "Are you sure you want to remove this Stat?", "Yes", "Cancel"); } if (performDelete) { Component.Delete(Component.stats [deleteId]); Component.SetDirty(); editor.needRepaint = true; } } }
void DrawFactory(Blueprint bp, GUILayoutOption labelWidth) { if (bp.factory == null) { bp.factory = BlueprintModelAsset.Create <Factory> (Component); BlueprintModelAsset.Rename(bp.factory, bp.ID); Component.SetDirty(); } var so = new SerializedObject(bp.factory); so.Update(); widget.DrawBoxed(() => { EditorGUILayout.LabelField("Factory Settings"); EditorGUILayout.PropertyField(so.FindProperty("type")); foreach (var g in Component.groups) { var factoryChoices = new List <string> (); foreach (var i in Component.blueprints) { if (i.group == g) { factoryChoices.Add(i.ID); } } factoryChoices.Insert(0, "** ALL **"); var addUnitIndex = widget.ControlPopup("Add from " + g.ID + " group", factoryChoices.ToArray()); if (addUnitIndex >= 0) { editor.needRepaint = true; if (addUnitIndex == 0) { foreach (var i in Component.blueprints) { if (i.group == g) { bp.factory.AddBlueprint(i); } } } else { var factoryUnit = factoryChoices [addUnitIndex]; bp.factory.AddBlueprint(Component.FindBlueprint(factoryUnit)); } } so.ApplyModifiedProperties(); } var deleteIndex = -1; factoryScroll = GUILayout.BeginScrollView(factoryScroll); for (var i = 0; i < bp.factory.blueprints.Count; i++) { var back = GUI.backgroundColor; var factoryUnit = bp.factory.blueprints [i]; widget.DrawBoxedRow(() => { GUILayout.Label(factoryUnit.ID); GUILayout.FlexibleSpace(); if (widget.ControlButton(styles.DELETE_COLOR, "Delete")) { deleteIndex = i; } }); GUI.backgroundColor = back; } GUILayout.EndScrollView(); if (deleteIndex >= 0) { bp.factory.blueprints.RemoveAt(deleteIndex); editor.needRepaint = true; } }); }
void DrawUnitResourceCosts(Blueprint unit, GUILayoutOption labelWidth) { widget.DrawBoxed(() => { EditorGUILayout.LabelField("Resource Costs (to build a unit)"); DrawResourceCostWidget(unit.costs, labelWidth); }); if (unit.isUpgradeable) { GUILayout.Space(10); widget.DrawBoxed(() => { EditorGUILayout.LabelField("Upgrade Costs"); if (GUILayout.Button("Add Upgrade Level")) { var rc = BlueprintModelAsset.Create <UpgradeLevel> (Component); BlueprintModelAsset.Rename(rc, unit.ID); unit.upgradeLevels.Add(rc); } }); var deleteIndex = -1; for (int i = 0; i < unit.upgradeLevels.Count; i++) { var uc = unit.upgradeLevels [i]; if (uc == null || uc.costs == null) { deleteIndex = i; continue; } widget.DrawBoxed(() => { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Level " + (i + 1)); if (widget.ControlButton(styles.DELETE_COLOR, "Delete")) { deleteIndex = i; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Upgrade Time"); uc.constructTime = EditorGUILayout.FloatField(uc.constructTime); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Prefab"); uc.gameObject = EditorGUILayout.ObjectField(uc.gameObject, typeof(GameObject), false) as GameObject; GUILayout.EndHorizontal(); DrawResourceCostWidget(uc.costs, labelWidth); }); } if (deleteIndex >= 0) { BlueprintModelAsset.Remove(unit.upgradeLevels [deleteIndex]); unit.upgradeLevels.RemoveAt(deleteIndex); Component.SetDirty(); editor.needRepaint = true; } } }