Esempio n. 1
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. 2
0
        private void DrawVariable(Rect rect, IList list, int index)
        {
            var name       = _pool.Names[index];
            var variable   = _pool.Variables[index];
            var definition = _pool.Definitions[index];

            var labelRect = RectHelper.TakeWidth(ref rect, _labelWidth);

            labelRect = RectHelper.TakeHeight(ref labelRect, EditorGUIUtility.singleLineHeight);
            var editRect = RectHelper.TakeLeadingIcon(ref labelRect);

            if (GUI.Button(editRect, _editButton.Content, GUIStyle.none))
            {
                _editPopup.Setup(this, index);
                PopupWindow.Show(editRect, _editPopup);
            }

            EditorGUI.LabelField(labelRect, name);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                var value = VariableValueDrawer.Draw(rect, GUIContent.none, variable, definition, true);

                if (changes.changed)
                {
                    _pool.SetVariable(index, value);
                }
            }
        }
Esempio n. 3
0
        private void DrawDoor(Rect rect, IList list, int index)
        {
            var door = _building.Doors[index];

            var nameRect = RectHelper.TakeLine(ref rect);

            RectHelper.TakeWidth(ref rect, RectHelper.LeftMargin);
            var positionRect = RectHelper.TakeLine(ref rect);
            var orderRect    = RectHelper.TakeLine(ref rect);
            var spriteRect   = RectHelper.TakeLine(ref rect);
            var openARect    = RectHelper.TakeLine(ref rect);
            var closeARect   = RectHelper.TakeLine(ref rect);
            var openSRect    = RectHelper.TakeLine(ref rect);
            var closeSRect   = RectHelper.TakeLine(ref rect);

            door.GameObject.name = EditorGUI.TextField(nameRect, door.GameObject.name);
            var position = EditorGUI.Vector2Field(positionRect, _accessoryPositionContent, door.Bounds.position);

            door.OrderOffset         = door.Renderer.sortingOrder = EditorGUI.IntSlider(orderRect, _orderOffsetContent, door.Renderer.sortingOrder, 0, _MaxOrderOffset);
            door.Renderer.sprite     = EditorGUI.ObjectField(spriteRect, _spriteContent, door.Renderer.sprite, typeof(Sprite), false) as Sprite;
            door.Door.OpenAnimation  = EditorGUI.ObjectField(openARect, _openAnimationContent, door.Door.OpenAnimation, typeof(AnimationClip), false) as AnimationClip;
            door.Door.CloseAnimation = EditorGUI.ObjectField(closeARect, _closeAnimationContent, door.Door.CloseAnimation, typeof(AnimationClip), false) as AnimationClip;
            door.Door.OpenSound      = EditorGUI.ObjectField(openSRect, _openSoundContent, door.Door.OpenSound, typeof(AudioClip), false) as AudioClip;
            door.Door.CloseSound     = EditorGUI.ObjectField(closeSRect, _closeSoundContent, door.Door.CloseSound, typeof(AudioClip), false) as AudioClip;

            UpdatePartTransform(door, position);
        }
Esempio n. 4
0
        private static void DrawIndentedLabel(ref Rect rect, GUIContent label)
        {
            var labelRect = RectHelper.TakeWidth(ref rect, RectHelper.CurrentLabelWidth);

            RectHelper.TakeWidth(ref labelRect, RectHelper.Indent);
            EditorGUI.LabelField(labelRect, label);
        }
Esempio n. 5
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. 6
0
        private void DrawRule(Rect rect, IList list, int index)
        {
            var rule         = _ruleOverrideTile.Rules[index];
            var overrideRule = _ruleOverrideTile.OverrideTile.Rules[index];

            var width           = EditorGUIUtility.singleLineHeight * 3 + RectHelper.VerticalSpace * 2;
            var referenceRect   = RectHelper.TakeLine(ref rect);
            var isReferenceRect = RectHelper.TakeWidth(ref referenceRect, referenceRect.width * 0.5f - RectHelper.HorizontalSpace);

            RectHelper.TakeHorizontalSpace(ref referenceRect);

            var matrixRect = RectHelper.TakeWidth(ref rect, width);

            RectHelper.TakeHorizontalSpace(ref rect);

            DrawRuleMatrix(_ruleOverrideTile.OverrideTile, matrixRect, overrideRule);

            rule.UseReference = EditorGUI.Toggle(isReferenceRect, _isReferenceContent.Content, rule.UseReference);

            if (rule.UseReference)
            {
                rule.Tile.Sprite = null;
                rule.Reference   = EditorGUI.ObjectField(referenceRect, _referenceContent, rule.Reference, typeof(TileBase), false) as TileBase;

                if (rule.Reference == _ruleOverrideTile)
                {
                    rule.Reference = null;
                }
            }
            else
            {
                rule.Tile      = TileTransformInfoControl.Draw(rect, GUIContent.none, rule.Tile);
                rule.Reference = null;
            }
        }
Esempio n. 7
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. 8
0
        private void Draw(Rect rect, IList list, int index)
        {
            var command   = _composition.CustomCommands[index];
            var labelRect = RectHelper.TakeWidth(ref rect, _labelWidth);

            EditorGUI.LabelField(labelRect, command.Name);

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                ExpressionControl.DrawFoldout(rect, command.Expression, GUIContent.none);

                if (changes.changed)
                {
                    _composition.SetExpression(index, command.Expression);
                }
            }
        }
Esempio n. 9
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. 10
0
        private void DrawAccessory(Rect rect, IList list, int index)
        {
            var accessory = _building.Accessories[index];

            var nameRect = RectHelper.TakeLine(ref rect);

            RectHelper.TakeWidth(ref rect, RectHelper.LeftMargin);
            var orderRect    = RectHelper.TakeLine(ref rect);
            var positionRect = RectHelper.TakeLine(ref rect);
            var spriteRect   = RectHelper.TakeLine(ref rect);

            var animationRect       = RectHelper.TakeLine(ref rect);
            var animationLabelRect  = RectHelper.TakeLabel(ref animationRect);
            var animationToggleRect = RectHelper.TakeLeadingIcon(ref animationRect);

            accessory.GameObject.name = EditorGUI.TextField(nameRect, accessory.GameObject.name);
            var position = EditorGUI.Vector2Field(positionRect, _accessoryPositionContent, accessory.Bounds.position);

            accessory.OrderOffset     = accessory.Renderer.sortingOrder = EditorGUI.IntSlider(orderRect, _orderOffsetContent, accessory.Renderer.sortingOrder, 0, _MaxOrderOffset);
            accessory.Renderer.sprite = EditorGUI.ObjectField(spriteRect, _spriteContent, accessory.Renderer.sprite, typeof(Sprite), false) as Sprite;

            EditorGUI.LabelField(animationLabelRect, _animationsContent);

            var hasAnimations         = accessory.Animation != null;
            var selectedHasAnimations = EditorGUI.Toggle(animationToggleRect, hasAnimations);

            if (selectedHasAnimations && !hasAnimations)
            {
                AddAnimations(accessory);
            }
            else if (!selectedHasAnimations && hasAnimations)
            {
                RemoveAnimations(accessory);
            }

            if (selectedHasAnimations)
            {
                accessory.Animation.Animation = EditorGUI.ObjectField(animationRect, accessory.Animation.Animation, typeof(AnimationClip), false) as AnimationClip;
            }

            UpdatePartTransform(accessory, position);
        }
Esempio n. 11
0
        private static TileTransformInfo Draw(Rect position, GUIContent label, Sprite sprite, int rotation, bool horizontal, bool vertical)
        {
            var rect       = EditorGUI.PrefixLabel(position, label);
            var spriteRect = RectHelper.TakeWidth(ref rect, Height);

            RectHelper.TakeHorizontalSpace(ref rect);
            var rotationRect   = RectHelper.TakeLine(ref rect);
            var horizontalRect = RectHelper.TakeLine(ref rect);
            var verticalRect   = RectHelper.TakeLine(ref rect);

            var info = new TileTransformInfo
            {
                Sprite         = EditorGUI.ObjectField(spriteRect, sprite, typeof(Sprite), false) as Sprite,
                Rotation       = EditorGUI.IntPopup(rotationRect, _rotationContent.Content, rotation, _rotationsContent, TileTransformInfo.Rotations),
                FlipHorizontal = EditorGUI.Toggle(horizontalRect, _flipHorizontalContent.Content, horizontal),
                FlipVertical   = EditorGUI.Toggle(verticalRect, _flipVerticalContent.Content, vertical)
            };

            return(info);
        }
        private void DrawOutput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var output    = _caller.Outputs[index];
            var labelRect = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect  = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, output.Name);
            output.Type = (InstructionOutputType)EditorGUI.EnumPopup(typeRect, output.Type);

            switch (output.Type)
            {
            case InstructionOutputType.Ignore: break;

            case InstructionOutputType.Reference: VariableReferenceControl.Draw(rect, output.Reference, GUIContent.none); break;
            }
        }
        private void DrawInput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var input      = _caller.Inputs[index];
            var definition = _caller.GetInputDefinition(input);
            var labelRect  = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect   = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, definition.Name);

            input.Type = (InstructionInputType)EditorGUI.EnumPopup(typeRect, input.Type);

            switch (input.Type)
            {
            case InstructionInputType.Reference: VariableReferenceControl.Draw(rect, input.Reference, GUIContent.none); break;

            case InstructionInputType.Value: input.Value = VariableValueDrawer.Draw(rect, GUIContent.none, input.Value, definition.Definition, true); break;
            }
        }
Esempio n. 14
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var target   = PropertyHelper.GetObject <VariableValueSource>(property);
            var typeRect = RectHelper.TakeLine(ref position);

            RectHelper.TakeLabel(ref position);

            using (new EditObjectScope(property.serializedObject))
            {
                using (new UndoScope(property.serializedObject.targetObject, false))
                {
                    target.Type = (VariableSourceType)EnumDisplayDrawer.Draw(typeRect, label, (int)target.Type, typeof(VariableSourceType), EnumDisplayType.Buttons, false, 50);

                    if (target.Type == VariableSourceType.Value)
                    {
                        if (!target.Definition.IsTypeLocked)
                        {
                            var variableRect = RectHelper.TakeWidth(ref position, position.width * 0.5f);
                            RectHelper.TakeHorizontalSpace(ref position);
                            var definitionType = (VariableType)EditorGUI.EnumPopup(variableRect, target.Definition.Type);

                            if (definitionType != target.Definition.Type)
                            {
                                target.Definition = ValueDefinition.Create(definitionType, target.Definition.Constraint, target.Definition.Tag, target.Definition.Initializer, false, false);
                                target.Value      = target.Definition.Generate(null);
                            }
                        }

                        target.Value = VariableValueDrawer.Draw(position, GUIContent.none, target.Value, target.Definition, true);
                    }
                    else if (target.Type == VariableSourceType.Reference)
                    {
                        VariableReferenceControl.Draw(position, target.Reference, GUIContent.none);
                    }
                }
            }
        }
Esempio n. 15
0
        private void DrawInput(Rect rect, IList list, int index)
        {
            var labelWidth = rect.width * 0.25f;
            var typeWidth  = rect.width * 0.25f;

            var input     = _caller.Inputs[index];
            var labelRect = RectHelper.TakeWidth(ref rect, labelWidth);
            var typeRect  = RectHelper.TakeWidth(ref rect, typeWidth);

            RectHelper.TakeHorizontalSpace(ref rect);

            EditorGUI.LabelField(labelRect, input.Definition.Name);

            if (input.Definition.Type == VariableType.Empty)
            {
                var typeIndex = input.Type == InstructionInputType.Reference ? 6 : GetIndexForType(input.Value.Type);
                var newIndex  = EditorGUI.Popup(typeRect, typeIndex, _inputTypeOptions);

                if (newIndex != typeIndex)
                {
                    input.Type  = newIndex == 6 ? InstructionInputType.Reference : InstructionInputType.Value;
                    input.Value = VariableValue.Create(GetTypeFromIndex(newIndex));
                }
            }
            else
            {
                input.Type = (InstructionInputType)EditorGUI.EnumPopup(typeRect, input.Type);
            }

            switch (input.Type)
            {
            case InstructionInputType.Reference: VariableReferenceControl.Draw(rect, input.Reference, GUIContent.none); break;

            case InstructionInputType.Value: input.Value = VariableValueDrawer.Draw(rect, GUIContent.none, input.Value, input.Definition); break;
            }
        }
        protected override void Draw(Rect rect, int index)
        {
            var name       = _proxy.GetName(index);
            var value      = Store.GetVariable(name);
            var definition = ValueDefinition.Create(VariableType.Empty);

            if (value.IsEmpty)
            {
                EditorGUI.LabelField(rect, name, EmptyText);
            }
            else
            {
                if (value.HasStore)
                {
                    if (DrawStoreView(ref rect))
                    {
                        Selected     = value.Store;
                        SelectedName = name;
                    }
                }

                using (var changes = new EditorGUI.ChangeCheckScope())
                {
                    var labelRect = RectHelper.TakeWidth(ref rect, _labelWidth);
                    labelRect = RectHelper.TakeHeight(ref labelRect, EditorGUIUtility.singleLineHeight);

                    EditorGUI.LabelField(labelRect, name);
                    value = VariableValueDrawer.Draw(rect, GUIContent.none, value, definition, false);

                    if (changes.changed)
                    {
                        Store.SetVariable(name, value);
                    }
                }
            }
        }
Esempio n. 17
0
        private static void DrawNumberConstraint(Rect rect, VariableType type, ref VariableConstraint constraint)
        {
            var fromLabel = _minimumConstraintLabel;
            var toLabel   = _maximumConstraintLabel;

            var fromSize = EditorStyles.label.CalcSize(fromLabel);
            var toSize   = EditorStyles.label.CalcSize(toLabel);
            var spacing  = 5.0f;

            var inputWidth = (rect.width - rect.height - fromSize.x - toSize.x - spacing * 4) * 0.5f;

            var checkboxRect = RectHelper.TakeWidth(ref rect, rect.height);

            RectHelper.TakeWidth(ref rect, spacing);
            var fromRect = RectHelper.TakeWidth(ref rect, fromSize.x);

            RectHelper.TakeWidth(ref rect, spacing);
            var minimumRect = RectHelper.TakeWidth(ref rect, inputWidth);

            RectHelper.TakeWidth(ref rect, spacing);
            var toRect = RectHelper.TakeWidth(ref rect, toSize.x);

            RectHelper.TakeWidth(ref rect, spacing);
            var maximumRect = RectHelper.TakeWidth(ref rect, inputWidth);

            var useRangeConstraint = GUI.Toggle(checkboxRect, constraint != null, _useRangeConstraintLabel);

            if (!useRangeConstraint)
            {
                constraint = null;
            }
            else if (type == VariableType.Int)
            {
                if (!(constraint is IntVariableConstraint intConstraint))
                {
                    intConstraint = new IntVariableConstraint {
                        Minimum = 0, Maximum = 100
                    };
                    constraint = intConstraint;
                }

                GUI.Label(fromRect, fromLabel);
                intConstraint.Minimum = EditorGUI.IntField(minimumRect, intConstraint.Minimum);
                GUI.Label(toRect, toLabel);
                intConstraint.Maximum = EditorGUI.IntField(maximumRect, intConstraint.Maximum);
            }
            else if (type == VariableType.Float)
            {
                if (!(constraint is FloatVariableConstraint floatConstraint))
                {
                    floatConstraint = new FloatVariableConstraint {
                        Minimum = 0, Maximum = 100
                    };
                    constraint = floatConstraint;
                }

                GUI.Label(fromRect, fromLabel);
                floatConstraint.Minimum = EditorGUI.FloatField(minimumRect, floatConstraint.Minimum);
                GUI.Label(toRect, toLabel);
                floatConstraint.Maximum = EditorGUI.FloatField(maximumRect, floatConstraint.Maximum);
            }
        }
Esempio n. 18
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);
        }