public override void Draw(Rect position, GUIContent label)
        {
            var instructionHeight = AssetDisplayDrawer.GetHeight(label);
            var instructionRect   = RectHelper.TakeHeight(ref position, instructionHeight);

            DrawInstruction(instructionRect, label);
            RectHelper.TakeVerticalSpace(ref position);

            using (new EditorGUI.IndentLevelScope())
            {
                if (_caller.Inputs.Count > 0)
                {
                    var inputsHeight = _inputs.GetHeight();
                    var inputsRect   = RectHelper.TakeHeight(ref position, inputsHeight);

                    _inputs.Draw(inputsRect, _inputsLabel.Content);
                }

                if (_caller.Outputs.Count > 0)
                {
                    var outputsHeight = _outputs.GetHeight();
                    var outputsRect   = RectHelper.TakeHeight(ref position, outputsHeight);

                    _outputs.Draw(outputsRect, _outputsLabel.Content);
                }
            }
        }
Esempio n. 2
0
        private void DrawEncounter(Rect rect, IList list, int index)
        {
            var encounter = _table.GetValue(index);
            var weight    = _table.GetWeight(index);
            var percent   = _table.GetPercentageWeight(index);

            var control        = GetControl(index, encounter);
            var creatureHeight = control.GetHeight(null);
            var creatureRect   = RectHelper.TakeHeight(ref rect, creatureHeight);

            control.Draw(creatureRect, null);

            RectHelper.TakeVerticalSpace(ref rect);
            RectHelper.TakeWidth(ref rect, rect.width * 0.25f);

            var percentRect = RectHelper.TakeTrailingWidth(ref rect, rect.width * 0.25f);
            var sliderRect  = RectHelper.TakeWidth(ref rect, rect.width - RectHelper.HorizontalSpace);

            EditorGUI.LabelField(percentRect, string.Format("({0:f1}%)", percent));

            var selectedWeight = EditorGUI.IntSlider(sliderRect, weight, 1, _table.TotalWeight);

            if (weight != selectedWeight)
            {
                _table.ChangeWeight(index, selectedWeight);
            }
        }
Esempio n. 3
0
        public override void Draw(Rect position, GUIContent label)
        {
            if (Creature.Species != null)
            {
                var speciesHeight = _instructionCaller.GetHeight(null);
                var speciesRect   = RectHelper.TakeHeight(ref position, speciesHeight);

                RectHelper.TakeVerticalSpace(ref position);

                var labelRect = RectHelper.TakeWidth(ref speciesRect, speciesRect.width * 0.25f);
                var editRect  = RectHelper.AdjustHeight(RectHelper.TakeTrailingIcon(ref speciesRect), EditorGUIUtility.singleLineHeight, RectVerticalAlignment.Top);

                EditorGUI.LabelField(labelRect, Creature.Species.Name);
                _instructionCaller.Draw(speciesRect, GUIContent.none);

                if (GUI.Button(editRect, _editSpeciesButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = Creature.Species;
                }
            }

            if (Creature.Creature != null)
            {
                var editRect = RectHelper.TakeTrailingIcon(ref position);
                EditorGUI.LabelField(position, Creature.Creature.Name);

                if (GUI.Button(editRect, _editCreatureButton.Content, GUIStyle.none))
                {
                    Selection.activeObject = Creature.Creature;
                }
            }
        }
Esempio n. 4
0
        public static ValueDefinition Draw(Rect position, GUIContent label, ValueDefinition definition, VariableInitializerType initializer, TagList tags, bool showConstraintLabel, ref bool isExpanded)
        {
            var tag        = definition.Tag;
            var constraint = definition.Constraint;

            var hasInitializer = HasInitializer(definition.Type, initializer);
            var hasConstraint  = HasConstraint(definition.Type, definition.Constraint, definition.IsConstraintLocked);
            var hasTag         = HasTags(tags);

            var typeRect = RectHelper.TakeLine(ref position);

            if (label != GUIContent.none)
            {
                var labelRect = RectHelper.TakeWidth(ref typeRect, RectHelper.CurrentLabelWidth);
                EditorGUI.LabelField(labelRect, label);
            }

            var type = DrawType(typeRect, definition.IsTypeLocked, definition.Type);

            if (hasConstraint)
            {
                var constraintHeight = GetConstraintHeight(definition.Type, definition.Constraint);
                var constraintRect   = RectHelper.TakeHeight(ref position, constraintHeight);

                DrawConstraint(constraintRect, type, definition.IsConstraintLocked, ref constraint, showConstraintLabel);
            }

            if (hasInitializer && definition.Initializer != null)
            {
                if (initializer == VariableInitializerType.Expression)
                {
                    var initializerHeight = ExpressionControl.GetFoldoutHeight(definition.Initializer, isExpanded, true, 2, 3);
                    var initializerRect   = RectHelper.TakeHeight(ref position, initializerHeight);
                    RectHelper.TakeVerticalSpace(ref position);
                    DrawInitializer(initializerRect, ref definition, ref isExpanded);
                }
                else if (initializer == VariableInitializerType.DefaultValue)
                {
                    var initializerRect = RectHelper.TakeLine(ref position);
                    DrawDefaultValue(initializerRect, ref definition);
                }
            }

            if (hasTag)
            {
                var tagRect = RectHelper.TakeLine(ref position);
                tag = DrawTag(tagRect, tag, tags);
            }

            return(ValueDefinition.Create(type, constraint, tag, definition.Initializer, definition.IsTypeLocked, definition.IsConstraintLocked));
        }
Esempio n. 5
0
        private static void DrawError(Rect rect, Expression expression, GUIContent label, bool fullWidth)
        {
            if (expression.HasError)
            {
                RectHelper.TakeVerticalSpace(ref rect);

                if (fullWidth)
                {
                    RectHelper.TakeWidth(ref rect, RectHelper.Indent);
                }
                else if (!string.IsNullOrEmpty(label.text))
                {
                    RectHelper.TakeLabel(ref rect);
                }

                EditorGUI.HelpBox(rect, expression.CompilationResult.Message, MessageType.Error);
            }
        }
Esempio n. 6
0
        private static VariableValue DrawList(Rect rect, VariableValue value, ListVariableConstraint constraint, bool drawStores)
        {
            var itemDefinition = constraint != null
                                ? ValueDefinition.Create(constraint.ItemType, constraint.ItemConstraint)
                                : ValueDefinition.Create(VariableType.Empty);

            var remove = -1;

            for (var i = 0; i < value.List.Count; i++)
            {
                if (i != 0)
                {
                    RectHelper.TakeVerticalSpace(ref rect);
                }

                var item       = value.List.GetVariable(i);
                var height     = GetHeight(item, itemDefinition, drawStores);
                var itemRect   = RectHelper.TakeHeight(ref rect, height);
                var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                item = Draw(itemRect, GUIContent.none, item, itemDefinition, drawStores);
                value.List.SetVariable(i, item);

                if (GUI.Button(removeRect, _removeListButton.Content, GUIStyle.none))
                {
                    remove = i;
                }
            }

            var addRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(addRect, _addListButton.Content, GUIStyle.none))
            {
                value.List.AddVariable(itemDefinition.Generate(null));
            }

            if (remove >= 0)
            {
                value.List.RemoveVariable(remove);
            }

            return(value);
        }
Esempio n. 7
0
        private static void DrawStringConstraint(Rect rect, ref VariableConstraint constraint)
        {
            if (!(constraint is StringVariableConstraint stringConstraint))
            {
                stringConstraint = new StringVariableConstraint {
                    Values = new string[] { }
                };
                constraint = stringConstraint;
            }

            var remove = -1;

            for (var i = 0; i < stringConstraint.Values.Length; i++)
            {
                if (i != 0)
                {
                    RectHelper.TakeVerticalSpace(ref rect);
                }

                var item       = stringConstraint.Values[i];
                var itemRect   = RectHelper.TakeLine(ref rect);
                var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                stringConstraint.Values[i] = EditorGUI.TextField(itemRect, item);

                if (GUI.Button(removeRect, _removeButton.Content, GUIStyle.none))
                {
                    remove = i;
                }
            }

            var addRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(addRect, _addButton.Content, GUIStyle.none))
            {
                ArrayUtility.Add(ref stringConstraint.Values, string.Empty);
            }

            if (remove >= 0)
            {
                ArrayUtility.RemoveAt(ref stringConstraint.Values, remove);
            }
        }
Esempio n. 8
0
        private static VariableValue DrawStore(Rect rect, VariableValue value, StoreVariableConstraint constraint, bool drawStores)
        {
            if (drawStores)
            {
                var names  = value.Store.GetVariableNames();
                var remove = string.Empty;
                var first  = true;
                var empty  = ValueDefinition.Create(VariableType.Empty);

                foreach (var name in names)
                {
                    if (!first)
                    {
                        RectHelper.TakeVerticalSpace(ref rect);
                    }

                    var index = constraint?.Schema != null?constraint.Schema.GetIndex(name) : -1;

                    var definition = index >= 0 ? constraint.Schema[index].Definition : empty;

                    var item      = value.Store.GetVariable(name);
                    var height    = GetHeight(item, definition, true);
                    var itemRect  = RectHelper.TakeHeight(ref rect, height);
                    var labelRect = RectHelper.TakeWidth(ref itemRect, _storeLabelWidth);
                    labelRect = RectHelper.TakeLine(ref labelRect);

                    EditorGUI.LabelField(labelRect, name);

                    if (constraint?.Schema == null && value.Store is VariableStore)
                    {
                        var removeRect = RectHelper.TakeTrailingIcon(ref itemRect);

                        if (GUI.Button(removeRect, _removeStoreButton.Content, GUIStyle.none))
                        {
                            remove = name;
                        }
                    }

                    item = Draw(itemRect, GUIContent.none, item, definition, true);
                    value.Store.SetVariable(name, item);

                    first = false;
                }

                if (constraint?.Schema == null && value.Store is VariableStore store)
                {
                    var addRect = RectHelper.TakeTrailingIcon(ref rect);

                    if (GUI.Button(addRect, _addStoreButton.Content, GUIStyle.none))
                    {
                        AddToStorePopup.Store = store;
                        AddToStorePopup.Name  = "";
                        PopupWindow.Show(addRect, AddToStorePopup.Instance);
                    }

                    if (!string.IsNullOrEmpty(remove))
                    {
                        (value.Store as VariableStore).RemoveVariable(remove);
                    }
                }
            }
            else
            {
                EditorGUI.LabelField(rect, value.Store.ToString());
            }

            return(value);
        }