Esempio n. 1
0
        public override void Update(Vector2 targetSize, GameTime gameTime)
        {
            alienText.Text          = dialogueStateMachine.Text();
            alienText.Position      = new Vector2(2 * padding, 2 * padding);
            alienText.MaxLineLength = (int)(targetSize.X - 4 * padding - alien.TexWidth());
            alien.Position          = new Vector2(targetSize.X - 2 * padding - alien.TexWidth(), 2 * padding);

            self.Position = new Vector2(2 * padding, targetSize.Y - self.TexHeight() - 2 * padding);

            // remove all the previous buttons
            if (dialogueStateMachine.State() != prevDialogState)
            {
                children = children.FindAll(pair => !typeof(ButtonAsset).IsInstanceOfType(pair.Value));
                buttons.Clear();

                var   buttonPos    = new Vector2(3 * padding + self.TexWidth(), targetSize.Y - self.TexHeight());
                float buttonOffset = 0;
                int   buttonIndex  = 0;
                foreach (DialogueOption option in dialogueStateMachine.Options())
                {
                    int         refIndex = buttonIndex;
                    Func <bool> onClick  = delegate()
                    {
                        dialogueStateMachine.SelectionOption(refIndex);
                        return(true);
                    };
                    Func <bool, bool> onHover = delegate(bool hovered)
                    {
                        return(true);
                    };

                    var buttonPrefix = (buttonIndex + 1).ToString() + ") ";
                    var button       = AddChild("dialogueOption", new ButtonAsset(buttonPrefix + option.Text, onClick, onHover));
                    buttons.Add(button);

                    button.Position = buttonPos + new Vector2(0, buttonOffset);
                    buttonOffset   += button.Size.Y + padding;
                    buttonIndex++;
                }
                prevDialogState = dialogueStateMachine.State();
            }
        }
 public DialogueStateMachine(DialogueState initState)
 {
     currentState = initState;
 }
 public void SelectionOption(int index)
 {
     currentState = currentState.Options[index].Outcome(currentState);
 }