/// <summary> /// Adds an IconButton to the menu. /// If no free slot is available, an error will be thrown. /// </summary> /// <param name="button">The button which should be added</param> public void AddButton(IconButton button) { if (Buttons[1] == null) { button.SetPosition(new Vector2(this.Rectangle.Width - 70, this.Rectangle.Top + 10)); Buttons[1] = button; } else if (Buttons[0] == null) { button.SetPosition(new Vector2(this.Rectangle.Width - 140, this.Rectangle.Top + 10)); Buttons[0] = button; } else { throw new Exception("No free slot available!"); } }
/// <summary> /// Is called, when a field on the ShootingPlayground is selected as target /// </summary> /// <param name="sender">The Playground</param> /// <param name="e">The shoot event arguments</param> void ShootingPlayground_TargetSelected(object sender, ShootEventArgs e) { if (SendedShot == null) { Playground pgSender = (Playground)sender; pgSender.ResetFieldColors(); Field selectedField = pgSender.fields[e.Y, e.X]; selectedField.SetColor(FieldColor.Red); IconButton attack = new IconButton(TextureManager.IconAttack, "Attack", "btnAttack"); attack.Click += new EventHandler<EventArgs>(attack_Click); FooterMenu.RemoveButton("btnAttack"); FooterMenu.AddButton(attack); this.selectedField = selectedField; } }
/// <summary> /// Removes the given button from the menu /// </summary> /// <param name="button">The button to remove</param> public void RemoveButton(IconButton button) { for (int i = 0; i < Buttons.Length; i++) { if (Buttons[i].Equals(button)) { Buttons[i].DoRemove(); Buttons[i] = null; } } }
/// <summary> /// Initializes all complex objects. Because it handles content and textures, this method must not be called before the content /// of the static manager are loaded! /// </summary> public void Initialize() { this.OwnPlayground = new Playground(PlaygroundMode.Normal); this.ShootingPlayground = new Playground(PlaygroundMode.Minimap); this.ShootingPlayground.Click += new EventHandler<EventArgs>(shootingPlayground_Click); this.OwnPlayground.Click += new EventHandler<EventArgs>(OwnPlayground_Click); this.ShootingPlayground.TargetSelected += new EventHandler<ShootEventArgs>(ShootingPlayground_TargetSelected); AppCache.XmppManager.IncomingMatchPing += new EventHandler<MessageEventArgs>(XmppManager_IncomingPing); InitializeShips(); FooterMenu = new FooterMenu(DeviceCache.BelowGrid, DeviceCache.ScreenHeight - DeviceCache.BelowGrid); btnAccept = new IconButton(TextureManager.IconAccept, "Place", "btnPlace"); btnTurn = new IconButton(TextureManager.IconTurn, "Turn", "btnTurn"); btnAccept.Visible = false; btnTurn.Visible = false; FooterMenu.AddButton(btnAccept); FooterMenu.AddButton(btnTurn); btnTurn.Click += new EventHandler<EventArgs>(btnTurn_Click); btnAccept.Click += new EventHandler<EventArgs>(btnAccept_Click); AppCache.XmppManager.IncomingDiceroll += new EventHandler<RollingDiceEventArgs>(XmppManager_IncomingDiceroll); AppCache.XmppManager.IncomingShot += new EventHandler<ShootEventArgs>(XmppManager_IncomingShot); AppCache.XmppManager.IncomingShotResult += new EventHandler<ShootEventArgs>(XmppManager_IncomingShotResult); AppCache.XmppManager.IncomingGamestate += new EventHandler<MessageEventArgs>(XmppManager_IncomingGamestate); pingTimer = new DispatcherTimer(); pingTimer.Interval = new TimeSpan(0, 0, 10); pingTimer.Tick += new EventHandler(pingTimer_Tick); pingTimer.Start(); }