Esempio n. 1
0
    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);
        }
    }
Esempio n. 2
0
    public Blueprint CreateNewBlueprint(BlueprintGroup g)
    {
        var c = BlueprintModelAsset.Create <Blueprint> (Component);

        c.rect = new Rect(100, 100, 128, 128);
        if (HotBP != null)
        {
            c.rect.x = HotBP.rect.x + HotBP.rect.width + 50;
            c.rect.y = HotBP.rect.y + 50;
        }
        Component.blueprints.Add(c);
        c.group      = g;
        ActiveGroup  = g;
        HotBP        = c;
        focusControl = "blueprintID";
        Component.SetDirty();
        return(c);
    }
Esempio n. 3
0
    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);
    }
Esempio n. 4
0
    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]);
        }
    }
Esempio n. 5
0
    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]);
        }
    }
Esempio n. 6
0
    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);
                }
            }
        }
    }
Esempio n. 7
0
    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;
            }
        }
    }
Esempio n. 8
0
    public override void Draw()
    {
        var mX = 0f;
        var mY = 0f;

        maxConstructionTime = 0;
        maxResources.Clear();


        for (var i = 0; i < Component.blueprints.Count; i++)
        {
            var c = Component.blueprints [i];
            mX = Mathf.Max(mX, c.rect.xMax + 50);
            mY = Mathf.Max(mY, c.rect.yMax + 50);
            maxConstructionTime = Mathf.Max(maxConstructionTime, c.constructTime);
            foreach (var r in c.costs)
            {
                float maxR = 0;
                maxResources.TryGetValue(r.resource.ID, out maxR);
                maxR = Mathf.Max(maxR, r.qty);
                maxResources [r.resource.ID] = maxR;
            }
        }

        var maxRect = new Rect(0, 0, mX, mY);

        EditorGUI.BeginChangeCheck();
        GUILayout.BeginHorizontal("box");
        if (GUILayout.Button("New Group", GUILayout.Width(128)))
        {
            var c = BlueprintModelAsset.Create <BlueprintGroup> (Component);
            Component.groups.Add(c);
            Component.SetDirty();
        }
        showCharts = GUILayout.Toggle(showCharts, "Show Charts", "button", GUILayout.Width(128));
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        if (EditorGUI.EndChangeCheck())
        {
            editor.needRepaint = true;
        }
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
        var area = GUILayoutUtility.GetLastRect();

        postGUI.Clear();
        scroll = GUI.BeginScrollView(area, scroll, maxRect);
        editor.BeginWindows();

        for (var i = 0; i < Component.blueprints.Count; i++)
        {
            var c = Component.blueprints [i];
            if (c.group.visible)
            {
                GUI.backgroundColor = c == HotBP ? styles.CREATE_COLOR : styles.NORMAL_COLOR;
                c.rect = GUILayout.Window(i, c.rect, DrawBlueprintNodeWidget, c.ID, styles.nodeWindow, GUILayout.MaxWidth(128), GUILayout.MinWidth(96));
                GUI.backgroundColor = styles.NORMAL_COLOR;
                DrawExternalWidgets(c);
            }
        }



        foreach (var a in postGUI)
        {
            a();
        }
        var mouseRect = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 1, 1);

        if (_hotPre != null)
        {
            widget.DrawConnectionCurve(mouseRect, _hotPre.rect);
            //editor.needRepaint = true;
            editor.Repaint();
        }
        if (_hotPost != null)
        {
            widget.DrawConnectionCurve(_hotPost.rect, mouseRect);
            editor.Repaint();
            //editor.needRepaint = true;
        }
        var e = Event.current;

        if (e.type == EventType.MouseUp)
        {
            if (_hotPost != null || _hotPre != null)
            {
                var c   = editor.CreateNewBlueprint(ActiveGroup);
                var pos = e.mousePosition;
                c.rect.x = pos.x;
                c.rect.y = pos.y;
                if (_hotPost != null)
                {
                    AddPrerequisite(c, _hotPost);
                    _hotPost = null;
                }
                if (_hotPre != null)
                {
                    AddPrerequisite(_hotPre, c);
                    _hotPre = null;
                }
                HotBP = c;
            }
            else
            {
                HotBP = null;
            }
            Event.current.Use();
        }
        editor.EndWindows();
        GUI.EndScrollView();
    }
Esempio n. 9
0
    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();
        }
    }
Esempio n. 10
0
    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;
            }
        }
    }
Esempio n. 11
0
    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;
            }
        });
    }
Esempio n. 12
0
    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;
            }
        }
    }