public Button( Vector2 size, Vector2 position, string text, Color textColor, IUserInterfaceElement parent, Action action) { this.Parent = parent; this.Size = size; this.Position = position; this.Color = parent.Color; this.HoverColor = this.Color + new Color(50, 50, 50); this.PushColor = new Color(this.Color.R - 50, this.Color.G - 50, this.Color.B - 50); this.Action = action; this.Visible = this.Parent.Visible; this.button = new DrawRect(this.Color) { Position = this.realPosition, Size = this.Size }; this.text = new DrawText { Color = textColor, Text = text, TextSize = new Vector2(size.Y) }; this.text.CenterOnRectangle(this.button); }
public TeamEntry(IAbilityTeam team, IUserInterfaceElement parent) { this.Team = team; this.Parent = parent; this.teamNameBg.Size = new Vector2(parent.Size.X, HUDInfo.GetHpBarSizeY() * 2); this.teamName.Text = team.Name.ToString(); this.teamName.TextSize = new Vector2(this.teamNameBg.Size.Y); this.hideButton = new Button( new Vector2(this.teamNameBg.Size.Y), new Vector2(this.teamNameBg.Size.X - this.teamNameBg.Size.Y, 0), "-", Color.White, this, () => { this.drawElements = !this.drawElements; if (this.drawElements) { this.hideButton.Text = "-"; } else { this.hideButton.Text = "+"; } this.UpdateSize(); }); // foreach (var abilityUnit in this.Team.UnitManager.Units) // { // this.unitEntries.Add(abilityUnit.Key, new UnitEntry(abilityUnit.Value, this)); // } this.Team.UnitManager.UnitAdded.Subscribe( new DataObserver <IAbilityUnit>( unit => { this.unitEntries.Add(unit.UnitHandle, new UnitOverlayEntry(unit, this)); this.UpdateSize(); })); this.Team.UnitManager.UnitRemoved.Subscribe( new DataObserver <IAbilityUnit>( unit => { this.unitEntries.Remove(unit.UnitHandle); this.UpdateSize(); })); this.UpdateSize(); }
/// <summary> /// Initializes a new instance of the <see cref="UnitOverlayEntry" /> class. /// </summary> /// <param name="unit"> /// The unit. /// </param> /// <param name="parent"> /// The parent. /// </param> public UnitOverlayEntry(IAbilityUnit unit, IUserInterfaceElement parent) { this.Unit = unit; this.Parent = parent; this.Size = new Vector2(this.Parent.Size.X, this.Parent.Size.X / 15); this.bg.Size = this.Size; this.RoundIcon = Textures.GetHeroRoundTexture(this.Unit.SourceUnit.Name); this.roundIcon = new DrawRect(this.RoundIcon) { Size = new Vector2(this.Parent.Size.X / 20) }; this.healthBar = new HealthBar( unit, new Vector2((float)(this.roundIcon.Size.X * 2.3), this.roundIcon.Size.X / 4)) { Color = this.Unit.IsEnemy ? new Color(230, 70, 70) : new Color(90, 200, 70), BackgroundColor = Color.Black }; this.manaBar = new ManaBar(unit, new Vector2(this.healthBar.Size.X, this.roundIcon.Size.X / 8)) { Color = new Color(70, 90, 200), BackgroundColor = Color.Black }; var spellSize = this.roundIcon.Size / (float)1.5; foreach (var keyValuePair in this.Unit.SkillBook.Spells) { var entry = keyValuePair.Value.OverlayProvider.Generate(); this.skillOverlays.Add(keyValuePair.Key, entry); entry.Size = spellSize; } var itemSize = new Vector2(this.roundIcon.Size.X / (float)1.2, (float)(this.Size.Y / 2.1)); foreach (var keyValuePair in this.Unit.SkillBook.Items) { var entry = keyValuePair.Value.OverlayProvider.Generate(); this.itemOverlays.Add(keyValuePair.Key, entry); entry.Size = itemSize; } this.Position = this.position; this.Unit.SkillBook.SkillAdd.Subscribe( new DataObserver <SkillAdd>( add => { if (!add.Skill.IsItem) { var entry = add.Skill.OverlayProvider.Generate(); this.skillOverlays.Add(add.Skill.SkillHandle, entry); entry.Size = spellSize; } else { var entry = add.Skill.OverlayProvider.Generate(); this.itemOverlays.Add(add.Skill.SkillHandle, entry); entry.Size = itemSize; } this.Position = this.position; })); this.Unit.SkillBook.SkillRemove.Subscribe( new DataObserver <SkillRemove>( remove => { if (!remove.Skill.IsItem) { this.skillOverlays.Remove(remove.Skill.SkillHandle); } else { this.itemOverlays.Remove(remove.Skill.SkillHandle); } this.Position = this.position; })); }
/// <summary> /// The generate. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <returns> /// The <see cref="IUnitOverlayEntry" />. /// </returns> public IUnitOverlayEntry Generate(IUserInterfaceElement parent) { return(new UnitOverlayEntry(this.Unit, parent)); }