Esempio n. 1
0
        public void Build(Action action = null, Action finishedWriting = null)
        {
            FinishedWriting = finishedWriting;

            if (Speaker != null && Speaker != "")
            {
                PassedText = Speaker + "\n" + PassedText;
            }


            // Build and position text
            TextObject = new Entity(entity => {
                entity.LayerName    = DefaultLayerName;
                entity.SortingLayer = DefaultSortingLayer + 1;
                entity.Position     = PassedPosition;

                entity.AddComponent(new Text()).Run <Text>(component => {
                    component.String = PassedText.Replace("|", "");
                    TextString       = component;

                    // Final positioning
                    entity.Position = entity.BoundingBox.Location.ToVector2();
                });
            });

            // Build container based on text
            Container = new Entity(entity => {
                entity.LayerName    = DefaultLayerName;
                entity.SortingLayer = DefaultSortingLayer;
                entity.Origin       = Vector2.Zero;
                entity.Position     = new Vector2(TextObject.Position.X - Padding.X, (TextObject.Position.Y - Padding.Y) + 1);
                entity.AddComponent(new Drawable()
                {
                    Texture2D = GameMethods.RoundedRect(Global.Content.Load <Texture2D>("Defaults/9Patch_8"),
                                                        new Point(TextObject.BoundingBox.Width + (Padding.X * 2) + ((ThisType == Type.PressToProgress) ? 8 : 0), TextObject.BoundingBox.Height + Padding.Y * 2))
                });
            });

            // Build arrow flasher
            if (ThisType == Type.PressToProgress)
            {
                ArrowFlash = new Entity(entity => {
                    entity.LayerName    = DefaultLayerName;
                    entity.SortingLayer = DefaultSortingLayer + 1;
                    entity.Position     = new Vector2(TextObject.Position.X + TextObject.BoundingBox.Width + 6, TextObject.BoundingBox.Bottom + 2);
                    entity.AddComponent(new Sprite()
                    {
                        Texture2D = Global.Content.Load <Texture2D>("Defaults/ArrowFlash")
                    }).Run <Sprite>(sprite => {
                        sprite.AddAnimation(new Animation("Flashing", 0.5f, new Point(8, 8), new Point(0, 0), new Point(1, 0)));
                        sprite.RunAnimation("Flashing");
                        sprite.Visible = false;
                    });
                });
            }

            if (Speaker != null && Speaker != "")
            {
                TextString.String = Speaker + "\n";
                TestString        = Speaker + "\n";
            }
            else
            {
                TextString.String = "";
                TestString        = "";
            }

            ProgressText(action);
        }
Esempio n. 2
0
        public void Build(Vector2 position, List <Option> optionList, Action <string> action = null, bool closeAfter = true, string texture9Patch = "Defaults/9Patch_8")
        {
            Selecting      = true;
            CloseAfter     = closeAfter;
            CurrentOptions = optionList;

            Selector = new Entity(entity => {
                entity.LayerName    = DefaultLayerName;
                entity.SortingLayer = DefaultSortingLayer + 1;
                entity.AddComponent(new Sprite()
                {
                    Texture2D = Global.Content.Load <Texture2D>("Defaults/OptionSelector")
                });
            });

            Container = new Entity(entity => {
                entity.Position     = position;
                entity.LayerName    = DefaultLayerName;
                entity.SortingLayer = DefaultSortingLayer;
                entity.Origin       = Vector2.Zero;

                float w = 0, h = 0;

                foreach (var option in optionList)
                {
                    float optionBoundsX = option.Position.X + option.Size.X;
                    if (optionBoundsX > w)
                    {
                        w = optionBoundsX;
                    }

                    float optionBoundsY = option.Position.Y + option.Size.Y;
                    if (optionBoundsY > h)
                    {
                        h = optionBoundsY;
                    }

                    option.Position = (entity.Position + option.Position + (Padding.ToVector2() / 2) + new Vector2(SelectorSize.X, 0));
                }

                if (texture9Patch != null)
                {
                    entity.AddComponent(new Drawable()
                    {
                        Texture2D = GameMethods.RoundedRect(Global.Content.Load <Texture2D>(texture9Patch),
                                                            new Point((int)w + (int)(Padding.X * 1.5f) + (int)SelectorSize.X, (int)h + Padding.Y))
                    });
                }

                SelectedOption = optionList.First <Option>();

                StaticCoroutines.CoroutineHelper.RunUntil(() => { return(!Selecting); }, () => {
                    if (Global.InputManager.Pressed(InputManager.Input.Up))
                    {
                        FindOption(optionList, "Up");
                    }
                    else if (Global.InputManager.Pressed(InputManager.Input.Down))
                    {
                        FindOption(optionList, "Down");
                    }
                    else if (Global.InputManager.Pressed(InputManager.Input.Left))
                    {
                        FindOption(optionList, "Left");
                    }
                    else if (Global.InputManager.Pressed(InputManager.Input.Right))
                    {
                        FindOption(optionList, "Right");
                    }
                    else if (Global.InputManager.Pressed(InputManager.Input.Action1))
                    {
                        Finished(optionList, action);
                    }
                });
            });
        }