Ejemplo n.º 1
0
 public override void OnMouseDown(MouseButtonEventArgs e)
 {
     base.OnMouseDown(e);
     if (ContentSelectable())
     {
         if (e.Button == MouseButton.Left || e.Button == MouseButton.Right)
         {
             Vector2 mouse    = GetLocalMousePosition();
             int     slotSize = GetContentWidth() / 5;
             mouse.X /= slotSize;
             mouse.Y /= slotSize;
             int itemIndex = (int)mouse.X + ((int)mouse.Y * 5);
             if (itemIndex >= 0 && itemIndex < _shopData.ShopItems.Count)
             {
                 if (e.Button == MouseButton.Left)
                 {
                     ClientCommand command = new ClientCommand(ClientCommand.CommandType.BuyShopItem);
                     command.SetParameter("ItemIndex", itemIndex);
                     command.SetParameter("Count", 1);
                     RpgClientConnection.Instance.AddClientCommand(command);
                 }
                 else if (e.Button == MouseButton.Right)
                 {
                     Vector2 mousePos = StateWindow.Instance.GetMousePosition();
                     ItemClickOptionsPanel.OptionType optionType = ItemClickOptionsPanel.OptionType.Buy;
                     int itemID = _shopData.ShopItems[itemIndex].ItemID;
                     ItemClickOptionsPanel optionPanel = new ItemClickOptionsPanel((int)mousePos.X, (int)mousePos.Y, optionType, itemIndex, itemID, -1, _gameState);
                     GameState.Instance.AddControl(optionPanel);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void CraftTrigger()
 {
     if (_selectedCraftable != -1)
     {
         ClientCommand command = new ClientCommand(ClientCommand.CommandType.CraftItem);
         command.SetParameter("CraftID", _craftableIDs[_selectedCraftable]);
         command.SetParameter("Count", _countControl.GetIndex());
         RpgClientConnection.Instance.AddClientCommand(command);
     }
 }
Ejemplo n.º 3
0
        public override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            if (ContentSelectable())
            {
                if (e.Button == MouseButton.Left || e.Button == MouseButton.Right)
                {
                    Vector2 mouse    = GetLocalMousePosition();
                    int     width    = (GetContentWidth() / 2) - 8;
                    int     slotSize = width / ItemsPerRow;

                    Rectangle selectionRect = new Rectangle(4, 4, width, GetContentHeight() - 58);
                    if (selectionRect.Contains((int)mouse.X, (int)mouse.Y))
                    {
                        mouse.X -= 4;
                        mouse.Y -= 4;
                        mouse.X /= slotSize;
                        mouse.Y /= slotSize;
                        int itemIndex = (int)mouse.X + ((int)mouse.Y * ItemsPerRow);

                        if (itemIndex >= 0 && itemIndex < this.TradeRequest.TradeOffer1.NumItems())
                        {
                            if (e.Button == MouseButton.Left)
                            {
                                if (this.TradeRequest.TradeOffer1.GetItem(itemIndex) != null)
                                {
                                    int removed = this.TradeRequest.TradeOffer1.RemoveItem(itemIndex, 1);
                                    if (removed > 0)
                                    {
                                        ClientCommand command = new ClientCommand(ClientCommand.CommandType.RemoveTradeItem);
                                        command.SetParameter("ItemIndex", itemIndex);
                                        command.SetParameter("Count", 1);
                                        RpgClientConnection.Instance.AddClientCommand(command);
                                    }
                                }
                            }
                            else if (e.Button == MouseButton.Right)
                            {
                                Vector2 mousePos = StateWindow.Instance.GetMousePosition();
                                ItemClickOptionsPanel.OptionType optionType = ItemClickOptionsPanel.OptionType.RemoveTrade;
                                int itemID = this.TradeRequest.TradeOffer1.GetItem(itemIndex).Item1;
                                int max    = this.TradeRequest.TradeOffer1.GetItem(itemIndex).Item2;
                                ItemClickOptionsPanel optionPanel = new ItemClickOptionsPanel((int)mousePos.X, (int)mousePos.Y, optionType, itemIndex, itemID, max, _gameState);
                                GameState.Instance.AddControl(optionPanel);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void OnKeyDown(OpenTK.Input.KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == Key.Escape)
            {
                StateWindow.Instance.PopState();
                this.Destroy();
                return;
            }
            else if (e.Key == OpenTK.Input.Key.Enter && e.Alt)
            {
                Renderer.SetFulscreen(Renderer.GetFulscreen() ? false : true);
            }
            else
            {
                if (e.Key == Key.Space)
                {
                    ClientCommand command = new ClientCommand(ClientCommand.CommandType.ActionTrigger);
                    RpgClientConnection.Instance.AddClientCommand(command);
                }
                else if (e.Key == Key.Enter)
                {
                    RpgClientConnection.Instance.CloseMessageBox();
                }
                else if (e.Key == Key.LShift)
                {
                    ClientCommand command = new ClientCommand(ClientCommand.CommandType.ToggleRunning);
                    command.SetParameter("Running", true);
                    RpgClientConnection.Instance.AddClientCommand(command);
                }
            }
        }
Ejemplo n.º 5
0
        public override void OnKeyUp(KeyboardKeyEventArgs e)
        {
            base.OnKeyUp(e);

            if (e.Key == Key.LShift)
            {
                ClientCommand command = new ClientCommand(ClientCommand.CommandType.ToggleRunning);
                command.SetParameter("Running", false);
                RpgClientConnection.Instance.AddClientCommand(command);
            }
        }
Ejemplo n.º 6
0
        private void Trigger()
        {
            int option = (int)Math.Floor(GetLocalMousePosition().Y / 32);

            if (option >= 0 && option < _options.Count)
            {
                MapClickOption clickOption = _options[option];
                ClientCommand  command;
                switch (clickOption.Option)
                {
                case MapClickOption.OptionType.PickupItem:
                    MapItem item = (MapItem)clickOption.Parameters["MapItem"];
                    command = new ClientCommand(ClientCommand.CommandType.PickupItem);
                    command.SetParameter("ItemIndex", clickOption.Parameters["ItemIndex"]);
                    command.SetParameter("Signature", item.GetSignature());
                    RpgClientConnection.Instance.AddClientCommand(command);
                    break;

                case MapClickOption.OptionType.AttackPlayer:
                    command = new ClientCommand(ClientCommand.CommandType.AttackPlayer);
                    command.SetParameter("PlayerID", clickOption.Parameters["PlayerID"]);
                    RpgClientConnection.Instance.AddClientCommand(command);
                    break;

                case MapClickOption.OptionType.AttackEnemy:
                    command = new ClientCommand(ClientCommand.CommandType.AttackEnemy);
                    command.SetParameter("EnemyID", clickOption.Parameters["EnemyID"]);
                    RpgClientConnection.Instance.AddClientCommand(command);
                    break;

                case MapClickOption.OptionType.Trade:
                    command = new ClientCommand(ClientCommand.CommandType.TradeRequest);
                    command.SetParameter("PlayerID", clickOption.Parameters["PlayerID"]);
                    RpgClientConnection.Instance.AddClientCommand(command);
                    break;
                }
            }

            this.Close();
        }
Ejemplo n.º 7
0
 private void RemoveEquipment()
 {
     for (int i = 0; i < _buttons.Count; i++)
     {
         if (_buttons[i].BodySelectable())
         {
             ClientCommand command = new ClientCommand(ClientCommand.CommandType.RemoveEquipment);
             command.SetParameter("EquipmentIndex", i);
             RpgClientConnection.Instance.AddClientCommand(command);
             break;
         }
     }
 }
Ejemplo n.º 8
0
 public void CloseMessageBox()
 {
     if (_messageBox != null)
     {
         if (_messageBox.GetSelectedOption() != -1)
         {
             ClientCommand command = new ClientCommand(ClientCommand.CommandType.SelectOption);
             command.SetParameter("Option", _messageBox.GetSelectedOption());
             this.AddClientCommand(command);
         }
         else
         {
             ClientCommand command = new ClientCommand(ClientCommand.CommandType.CloseMessage);
             this.AddClientCommand(command);
         }
         _messageBox.Close();
         _messageBox = null;
     }
 }
Ejemplo n.º 9
0
        public override void OnUpdateFrame(FrameEventArgs e)
        {
            if (_connection != null)
            {
                if (_connection.Connected())
                {
                    _connection.Update((float)e.Time);
                }
                else
                {
                    StateWindow.Instance.PopState();
                    this.Destroy();
                    return;
                }
            }

            base.OnUpdateFrame(e);

            if (_movementTimer > 0)
            {
                _movementTimer -= (float)e.Time;
            }

            if (_movementTimer <= 0)
            {
                KeyboardState     keyState  = Keyboard.GetState();
                bool              moving    = false;
                MovementDirection direction = MovementDirection.Down;

                if (keyState.IsKeyDown(Key.W))
                {
                    moving = true;
                    if (keyState.IsKeyDown(Key.A))
                    {
                        direction = MovementDirection.UpperLeft;
                    }
                    else if (keyState.IsKeyDown(Key.D))
                    {
                        direction = MovementDirection.UpperRight;
                    }
                    else
                    {
                        direction = MovementDirection.Up;
                    }
                }
                else if (keyState.IsKeyDown(Key.S))
                {
                    moving = true;
                    if (keyState.IsKeyDown(Key.A))
                    {
                        direction = MovementDirection.LowerLeft;
                    }
                    else if (keyState.IsKeyDown(Key.D))
                    {
                        direction = MovementDirection.LowerRight;
                    }
                    else
                    {
                        direction = MovementDirection.Down;
                    }
                }
                else if (keyState.IsKeyDown(Key.A))
                {
                    moving    = true;
                    direction = MovementDirection.Left;
                }
                else if (keyState.IsKeyDown(Key.D))
                {
                    moving    = true;
                    direction = MovementDirection.Right;
                }

                if (moving)
                {
                    ClientCommand command = new ClientCommand(ClientCommand.CommandType.MovePlayer);
                    command.SetParameter("Direction", (int)direction);
                    RpgClientConnection.Instance.AddClientCommand(command);
                    MapComponent.Instance.MovePlayer(direction);
                }

                _movementTimer = 0.1f;
            }
        }
Ejemplo n.º 10
0
        public override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            if (ContentSelectable())
            {
                if (e.Button == MouseButton.Left || e.Button == MouseButton.Right)
                {
                    ClientCommand command = null;

                    Vector2 mouse    = GetLocalMousePosition();
                    int     slotSize = GetContentWidth() / 5;
                    mouse.X /= slotSize;
                    if (mouse.Y >= 30)
                    {
                        mouse.Y -= 30;
                        mouse.Y /= slotSize;
                        int itemIndex = (int)mouse.X + ((int)mouse.Y * 5);

                        Tuple <int, int> itemInfo = MapComponent.Instance.GetLocalPlayerPacket().Data.GetInventoryItem(itemIndex);
                        if (itemInfo != null)
                        {
                            if (e.Button == MouseButton.Left)
                            {
                                if (ShopPanel.Instance != null)
                                {
                                    command = new ClientCommand(ClientCommand.CommandType.SellShopItem);
                                    command.SetParameter("Count", 1);
                                }
                                else if (TradePanel.Instance != null)
                                {
                                    int added = TradePanel.Instance.TradeRequest.TradeOffer1.AddItem(itemInfo.Item1, 1);
                                    if (added > 0)
                                    {
                                        command = new ClientCommand(ClientCommand.CommandType.AddTradeItem);
                                        command.SetParameter("Count", 1);
                                        TradePanel.Instance.TradeRequest.TradeOffer1.Accepted = false;
                                        TradePanel.Instance.TradeRequest.TradeOffer2.Accepted = false;
                                    }
                                }
                                else if (BankPanel.Instance != null)
                                {
                                    command = new ClientCommand(ClientCommand.CommandType.AddBankItem);
                                    command.SetParameter("Count", 1);
                                }
                                else if (WorkbenchPanel.Instance == null)
                                {
                                    command = new ClientCommand(ClientCommand.CommandType.SelectItem);
                                }
                            }
                            else if (e.Button == MouseButton.Right)
                            {
                                ItemClickOptionsPanel.OptionType optionType = ItemClickOptionsPanel.OptionType.None;

                                if (ShopPanel.Instance != null)
                                {
                                    optionType = ItemClickOptionsPanel.OptionType.Sell;
                                }
                                else if (TradePanel.Instance != null)
                                {
                                    optionType = ItemClickOptionsPanel.OptionType.AddTrade;
                                }
                                else if (BankPanel.Instance != null)
                                {
                                    optionType = ItemClickOptionsPanel.OptionType.AddBank;
                                }
                                else if ((WorkbenchPanel.Instance == null))
                                {
                                    optionType = ItemClickOptionsPanel.OptionType.Drop;
                                }

                                if (optionType != ItemClickOptionsPanel.OptionType.None)
                                {
                                    Vector2 mousePos = StateWindow.Instance.GetMousePosition();
                                    ItemClickOptionsPanel optionPanel = new ItemClickOptionsPanel((int)mousePos.X, (int)mousePos.Y, optionType, itemIndex, itemInfo.Item1, itemInfo.Item2, _gameState);
                                    GameState.Instance.AddControl(optionPanel);
                                }
                            }
                        }

                        if (command != null)
                        {
                            command.SetParameter("ItemIndex", itemIndex);
                            RpgClientConnection.Instance.AddClientCommand(command);
                        }
                    }
                }
            }
        }