public override void Draw(SpriteBatch graphics, BFBContentManager content) { InventorySlot slot = ClientDataRegistry.GetInstance()?.Client?.Meta?.MouseSlot; if (slot == null) { return; } AtlasTexture atlas = content.GetAtlasTexture(slot.TextureKey); int maxHeight = RootUI.RenderAttributes.Height / 10; int scale = maxHeight / atlas.Height; int w = atlas.Width * scale; int h = atlas.Height * scale; int x = (int)Mouse.X - w / 2; int y = (int)Mouse.Y - h / 2; graphics.DrawAtlas( atlas, new Rectangle( x, y, w, h ), Color.White); if (slot.ItemType == ItemType.Wall) { graphics.DrawAtlas( atlas, new Rectangle( x, y, w, h ), new Color(0, 0, 0, 0.4f)); } SpriteFont font = content.GetFont("default"); (float width, float height) = font.MeasureString(slot.Count.ToString()) * 0.6f; graphics.DrawString( font, slot.Count.ToString(), new Vector2(Mouse.X - width + 3, Mouse.Y - height + 3), Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 1); }
protected override void Init() { Inventory = ClientDataRegistry.GetInstance().Inventory; AddInputListener("keypress", e => { switch (e.Keyboard.KeyEnum) { case Keys.Escape: case Keys.E: ParentScene.Client.Emit("/inventory/throwHolding"); UIManager.StopLayer(Key); break; } e.StopPropagation(); }); AddInputListener("mouseclick", e => { if (e.Mouse.RightButton == ButtonState.Pressed) { ParentScene.Client.Emit("/inventory/throwHolding", new DataMessage { Message = "one" }); } else { ParentScene.Client.Emit("/inventory/throwHolding"); } }); AddInputListener("mousemove", e => { Mouse = new BfbVector(e.Mouse.X, e.Mouse.Y); }); }
protected override void Init() { ClientDataRegistry.GetInstance().Entities.Clear(); }
protected override void Init() { ClientData = ClientDataRegistry.GetInstance(); #region Keypress Events AddInputListener("keypress", e => { switch (e.Keyboard.KeyEnum) { case Keys.Escape: UIManager.StartLayer(nameof(GameMenuUI), ParentScene); break; case Keys.E: UIManager.LaunchLayer(nameof(InventoryUI), ParentScene); break; case Keys.T: UIManager.StartLayer(nameof(ChatUI), ParentScene); break; case Keys.D1: ClientData.Inventory.ActiveSlot = 0; break; case Keys.D2: ClientData.Inventory.ActiveSlot = 1; break; case Keys.D3: ClientData.Inventory.ActiveSlot = 2; break; case Keys.D4: ClientData.Inventory.ActiveSlot = 3; break; case Keys.D5: ClientData.Inventory.ActiveSlot = 4; break; case Keys.D6: ClientData.Inventory.ActiveSlot = 5; break; case Keys.D7: ClientData.Inventory.ActiveSlot = 6; break; } }); #endregion #region MouseScroll Events AddInputListener("mousescroll", e => { if (Math.Abs(e.Mouse.VerticalScrollAmount) <= 200 || e.Keyboard.KeyboardState.IsKeyDown(Keys.LeftControl)) { return; } if (e.Mouse.VerticalScrollAmount > 0) { ClientData.Inventory.ActiveSlot++; } else { if (ClientData.Inventory.ActiveSlot == 0) { ClientData.Inventory.ActiveSlot = 6; } else { ClientData.Inventory.ActiveSlot--; } } if (ClientData.Inventory.ActiveSlot > 6) { ClientData.Inventory.ActiveSlot = 0; } }); #endregion }
protected override void Init() { _clientData = ClientDataRegistry.GetInstance(); UIManager.StartLayer(nameof(LoadingGameUI), this); /** * Scene events */ #region Update Input State _playerInput.Init(this); #endregion /** * Reserved Socket Manager routes */ #region Client Connect Client.OnConnect = (m) => { GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Server Connected...")); Thread.Sleep(100); AudioManager.PlaySong("HumanSong"); }; #endregion #region Client Authentication Client.OnAuthentication = (m) => { GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Authenticating User...")); Thread.Sleep(100); return(null); }; #endregion #region Client Prepare Client.OnPrepare = message => { GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Preparing World...")); Thread.Sleep(100); _clientData.World.ApplyWorldInitData((WorldDataMessage)message); _worldRenderer.Init(_clientData.World, ContentManager, GraphicsDeviceManager.GraphicsDevice); }; #endregion #region Client Ready Client.OnReady = () => { GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Ready...")); }; Client.On("PlayerUIRequest", (m) => { UIManager.StartLayer(m.Message, this); }); #endregion #region Client Disconnect Client.OnDisconnect = (m) => { UIManager.StartLayer(nameof(LoadingGameUI), this); GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Disconnected By Server")); AudioManager.StopSong(); }; #endregion /** * Custom Socket Routes */ #region Handle Entity Disconnect Client.On("/player/disconnect", message => { //Remove entity who disconnected lock (_lock) { _clientData.Entities.Remove(message.Message); } }); #endregion #region Handle Entity Updates Client.On("/players/updates", message => { EntityUpdateMessage m = (EntityUpdateMessage)message; lock (_lock) { foreach (EntityMessage em in m.Updates) { if (_clientData.Entities.ContainsKey(em.EntityId)) { _clientData.Entities[em.EntityId].Position = em.Position; _clientData.Entities[em.EntityId].Velocity = em.Velocity; _clientData.Entities[em.EntityId].Rotation = em.Rotation; _clientData.Entities[em.EntityId].AnimationState = em.AnimationState; _clientData.Entities[em.EntityId].Facing = em.Facing; _clientData.Entities[em.EntityId].Meta = em.Meta; if (em.EntityId == Client.ClientId) { _clientData.Client = _clientData.Entities[em.EntityId]; _worldRenderer.Camera.Focus = _clientData.Entities[em.EntityId].OriginPosition.ToVector2(); } } else { _clientData.Entities.Add(em.EntityId, ClientEntity.ClientEntityFactory(em, ContentManager)); } } } }); #endregion #region Handle Chunk Updates Client.On("/players/chunkUpdates", message => { _clientData.World.ApplyChunkUpdateMessage((ChunkUpdatesMessage)message); }); #endregion #region HandleInventoryUpdates Client.On("/players/inventoryUpdates", message => { _clientData.Inventory.ApplySlotUpdates((InventorySlotMessage)message); }); #endregion #region KeyEventListener AddInputListener("keypress", e => { if (e.Keyboard.KeyEnum == Keys.M) { UIManager.StartLayer(nameof(MonsterMenuUI), this); } else if (e.Keyboard.KeyEnum == Keys.F3) { _worldRenderer.Debug = !_worldRenderer.Debug; } }); #endregion #region ScrollEventListener AddInputListener("mousescroll", e => { if (e.Keyboard.KeyboardState.IsKeyDown(Keys.LeftControl)) { _worldRenderer.Camera.ApplyZoom(e.Mouse.VerticalScrollAmount / 1000f); } }); #endregion Client.Ip = ConnectionSettings.Ip; Client.Port = ConnectionSettings.Port; if (!Client.Connect()) { GlobalEventManager.Emit("onConnectionStatus", new GlobalEvent("Connection Failed")); } }