Exemplo n.º 1
0
        public void ShowMessage(string message, Action onStartCallback, Action onAfterConfirmCallback)
        {
            if (_textPanel != null)
            {
                UserInterface.Active.RemoveEntity(_textPanel);
                _textPanel = null;
            }

            _onAfterConfirmCallback = onAfterConfirmCallback;

            _bufferedStrings = SplitByLength(message, 110);

            float scaleY = HarvestMoon.Instance.Graphics.GraphicsDevice.Viewport.Height / 480.0f;

            // create a panel and position in bottom center of screen
            _textPanel = new Panel(new Vector2(620 * scaleY, 120 * scaleY), PanelSkin.Default, Anchor.BottomCenter);

            _textPanel.SetCustomSkin(_window_11Texture);

            UserInterface.Active.AddEntity(_textPanel);

            var paragraph = new Paragraph("");

            _textAnimator = new TypeWriterAnimator();

            _textAnimator.TextToType = _bufferedStrings.First();
            _bufferedStrings.Remove(_bufferedStrings.First());

            paragraph.AttachAnimator(_textAnimator);

            _textPanel.AddChild(paragraph);

            //_textPanel.Opacity = 200;

            onStartCallback();
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            _dayToolSprite.Update(gameTime);
            _goldSprite.Update(gameTime);

            foreach (var staminaSprite in _staminaSprites)
            {
                staminaSprite.Update(gameTime);
            }

            // GeonBit.UIL update UI manager
            UserInterface.Active.Update(gameTime);
            var deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (_npcCoolDown)
            {
                _coolingTimer += deltaSeconds;

                if (_coolingTimer >= _npcCoolingDelay)
                {
                    _coolingTimer = 0.0f;
                    _npcCoolDown  = false;
                    _busy         = false;
                }
            }

            var keyboardState = HarvestMoon.Instance.Input;

            if (keyboardState.IsKeyUp(InputDevice.Keys.A))
            {
                _isActionButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.B))
            {
                _isCancelButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Up))
            {
                _isUpButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Down))
            {
                _isDownButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Left))
            {
                _isLeftButtonDown = false;
            }

            if (keyboardState.IsKeyUp(InputDevice.Keys.Right))
            {
                _isRightButtonDown = false;
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Left) && !_isLeftButtonDown))
            {
                _isLeftButtonDown = true;

                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            _upfrontStoreList.ClearItems();

                            _upfrontStoreList.LockedItems[0] = true;
                            _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                            _amounts[_selectedIndex - 1] = _amounts[_selectedIndex - 1] - 1;

                            if (_amounts[_selectedIndex - 1] < 0)
                            {
                                _amounts[_selectedIndex - 1] = 0;
                            }

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                // add items as formatted table
                                _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                            }

                            UpdateTotal();
                        }
                        break;
                    }
                }
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Right) && !_isRightButtonDown))
            {
                _isRightButtonDown = true;


                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            _upfrontStoreList.ClearItems();

                            _upfrontStoreList.LockedItems[0] = true;
                            _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                            _amounts[_selectedIndex - 1] = _amounts[_selectedIndex - 1] + 1;

                            if (_amounts[_selectedIndex - 1] > 10)
                            {
                                _amounts[_selectedIndex - 1] = 10;
                            }

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                // add items as formatted table
                                _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                            }

                            UpdateTotal();
                        }
                        break;
                    }
                }
            }

            if ((keyboardState.IsKeyDown(InputDevice.Keys.Up) && !_isUpButtonDown) || (keyboardState.IsKeyDown(InputDevice.Keys.Down) && !_isDownButtonDown))
            {
                if (keyboardState.IsKeyDown(InputDevice.Keys.Up))
                {
                    _isUpButtonDown = true;
                }

                if (keyboardState.IsKeyDown(InputDevice.Keys.Down))
                {
                    _isDownButtonDown = true;
                }

                if (_isDisplayingMenu)
                {
                    switch (_npcMenu)
                    {
                    case NPCMenu.YesNo:
                        if (_textParagraph.Text == "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last())
                        {
                            _textParagraph.Text = "  " + _menuStrings.First() + "\n" + "> " + _menuStrings.Last();
                        }
                        else
                        {
                            _textParagraph.Text = "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last();
                        }

                        break;

                    case NPCMenu.UpfrontStore:
                        if (!UpfrontStore.ConfirmPurchase)
                        {
                            if (_isDownButtonDown)
                            {
                                _selectedIndex++;

                                if (_selectedIndex == _upfrontStoreList.Items.Length)
                                {
                                    _selectedIndex = 1;
                                }
                            }

                            if (_isUpButtonDown)
                            {
                                _selectedIndex--;

                                if (_selectedIndex == 0)
                                {
                                    _selectedIndex = _upfrontStoreList.Items.Length - 1;
                                }
                            }
                        }
                        break;

                    case NPCMenu.Bookshelf:
                        if (!Bookshelf.Reading)
                        {
                            if (_isDownButtonDown)
                            {
                                _selectedIndex++;

                                if (_selectedIndex == _bookshelfList.Items.Length)
                                {
                                    _selectedIndex = 1;
                                }
                            }

                            if (_isUpButtonDown)
                            {
                                _selectedIndex--;

                                if (_selectedIndex == 0)
                                {
                                    _selectedIndex = _bookshelfList.Items.Length - 1;
                                }
                            }
                        }
                        break;
                    }
                }
            }

            if (_isDisplayingMenu)
            {
                if (_npcMenu == NPCMenu.UpfrontStore)
                {
                    _gParagraph.Text = "Current G: " + HarvestMoon.Instance.Gold.ToString() + "G";

                    if (_upfrontStoreList.SelectedIndex != _selectedIndex)
                    {
                        _upfrontStoreList.SelectedIndex = _selectedIndex;
                        _selectedAmount = 0;
                        _selectedTotal  = 0;
                    }
                }
                else if (_npcMenu == NPCMenu.Bookshelf)
                {
                    if (_bookshelfList.SelectedIndex != _selectedIndex)
                    {
                        _bookshelfList.SelectedIndex  = _selectedIndex;
                        _bookshelfList.ScrollPosition = _selectedIndex - 1;
                    }
                }
            }

            if (keyboardState.IsKeyDown(InputDevice.Keys.B) && !_isCancelButtonDown)
            {
                _isCancelButtonDown = true;

                if (_textPanel != null)
                {
                    if (_isDisplayingMenu)
                    {
                        if (_npcMenu == NPCMenu.UpfrontStore)
                        {
                            if (UpfrontStore.ConfirmPurchase)
                            {
                                UpdateTotal();
                                UpfrontStore.ConfirmPurchase = false;
                            }
                            else
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;

                                _storeOnAfterConfirmCallback?.Invoke();
                                _storeOnAfterConfirmCallback = null;
                            }
                        }
                        else if (_npcMenu == NPCMenu.Bookshelf)
                        {
                            if (!Bookshelf.Reading)
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;

                                _bookshelfOnAfterConfirmCallback?.Invoke();
                                _bookshelfOnAfterConfirmCallback = null;
                            }
                        }
                    }
                }
            }

            if (keyboardState.IsKeyDown(InputDevice.Keys.A) && !_isActionButtonDown)
            {
                _isActionButtonDown = true;
                if (_textPanel != null)
                {
                    if (_isDisplayingMenu)
                    {
                        switch (_npcMenu)
                        {
                        case NPCMenu.YesNo:
                            if (_textParagraph.Text == "> " + _menuStrings.First() + "\n" + "  " + _menuStrings.Last())
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;
                                _menuCallbacks[0]();
                            }
                            else
                            {
                                UserInterface.Active.RemoveEntity(_textPanel);
                                _textPanel        = null;
                                _npcCoolDown      = true;
                                _busy             = true;
                                _isDisplayingMenu = false;
                                _menuCallbacks[1]();
                            }

                            break;

                        case NPCMenu.UpfrontStore:
                            _npcCoolDown = true;
                            _busy        = true;

                            List <string> items   = new List <string>();
                            List <int>    amounts = new List <int>();

                            for (int i = 0; i < _items.Count; ++i)
                            {
                                if (_amounts[i] > 0)
                                {
                                    items.Add(_items[i]);
                                    amounts.Add(_amounts[i]);
                                }
                            }

                            UpdateTotal();

                            var result = _onPurchaseCallback?.Invoke(items, amounts, _selectedTotal);

                            if (!UpfrontStore.ConfirmPurchase)
                            {
                                for (int i = 0; i < _amounts.Count; ++i)
                                {
                                    _amounts[i] = 0;
                                }

                                UpdateTotal(result);

                                _upfrontStoreList.ClearItems();

                                _upfrontStoreList.LockedItems[0] = true;
                                _upfrontStoreList.AddItem(System.String.Format("{0}{1,-8} {2,-8} {3, -10} {4, -10}", "{{RED}}", "Name", "Class", "Price", "Amount"));

                                for (int i = 0; i < _items.Count; ++i)
                                {
                                    // add items as formatted table
                                    _upfrontStoreList.AddItem(System.String.Format("{0,-8} {1,-8} {2,-10} {3, -10}", _items[i], _classes[i], _prices[i].ToString(), _amounts[i].ToString()));
                                }
                            }
                            else
                            {
                                UpdateTotal(result);
                            }
                            break;

                        case NPCMenu.Bookshelf:
                        {
                            _npcCoolDown = true;
                            _busy        = true;
                            if (_textAnimator != null)
                            {
                                if (_textAnimator.IsDone)
                                {
                                    if (_bufferedStrings.Count > 0)
                                    {
                                        _textAnimator.TextToType = _bufferedStrings.First();
                                        _bufferedStrings.Remove(_bufferedStrings.First());
                                    }
                                    else
                                    {
                                        ShowBookshelf(_title, _items, _text, _bookshelfOnAfterConfirmCallback);
                                        _textAnimator = null;
                                    }
                                }
                            }
                            else
                            {
                                Bookshelf.Reading = true;
                                _bufferedStrings  = SplitByLength(_text[_selectedIndex - 1], 300);

                                _textAnimator = new TypeWriterAnimator();

                                _textAnimator.TextToType = _bufferedStrings.First();
                                _bufferedStrings.Remove(_bufferedStrings.First());

                                _textPanel.RemoveChild(_bookshelfList);

                                var paragraph = new Paragraph("");
                                paragraph.AttachAnimator(_textAnimator);
                                float scaleY = HarvestMoon.Instance.Graphics.GraphicsDevice.Viewport.Height / 480.0f;

                                Panel panel = new Panel(new Vector2(0, 280 * scaleY));

                                panel.AddChild(paragraph);

                                _textPanel.AddChild(panel);
                                _textPanel.Opacity = 0;
                                //_textPanel.Visible = false;
                            }
                        }

                        break;
                        }
                    }
                    else
                    {
                        if (_textAnimator != null)
                        {
                            if (_textAnimator.IsDone)
                            {
                                if (_bufferedStrings.Count > 0)
                                {
                                    _textAnimator.TextToType = _bufferedStrings.First();
                                    _bufferedStrings.Remove(_bufferedStrings.First());
                                    _npcCoolDown = true;
                                    _busy        = true;
                                }
                                else
                                {
                                    UserInterface.Active.RemoveEntity(_textPanel);
                                    _textPanel    = null;
                                    _npcCoolDown  = true;
                                    _busy         = true;
                                    _textAnimator = null;

                                    _onAfterConfirmCallback?.Invoke();
                                }
                            }
                        }
                    }
                }
            }
        }