The Game Engine  1
HUD.h
Go to the documentation of this file.
1 #ifndef __HUD_H__
2 #define __HUD_H__
3 
4 
14 class HUD
15 {
16 public:
17  HUD() {}
18 //
19 // TextScroller scroller;
20 // TextFader fader;
21 // vector<ProgressBar> bossHealthBars = new vector<ProgressBar>();
22 // vector<PlayerHUD> playerHUDS = new vector<PlayerHUD>();
23 // static Vector2 barSize = new Vector2(100, 20);
24 // static Vector2 barSpacing = new Vector2(10, 2);
25 // ItemArea items;
26 //
27 //
28 //
29 // public void LoadCommon(IHUDTheme Theme = null)
30 // {
31 // if (Theme != null)
32 // {
33 // theme = Theme;
34 // }
35 //
36 // Viewport v = This.Game.GraphicsDevice.Viewport;
37 // scroller = new TextScroller("scroller", theme);
38 // scroller.Pos = new Vector2(FrostbyteLevel.BORDER_WIDTH / 2,
39 // v.Height - scroller.GetAnimation().Height);
40 // scroller.Static = true;
41 //
42 // fader = new TextFader("fader", theme);
43 // fader.Pos = new Vector2(v.Width - 10, v.Height - 10 - 30);
44 // fader.Anchor = Orientations.Up_Right;
45 // fader.Static = true;
46 //
47 //
48 // items = new ItemArea("Items", theme);
49 // items.Pos = new Vector2(890, 10);
50 // items.Static = true;
51 //
52 // }
53 //
54 // public void AddPlayer(Player p)
55 // {
56 // int xoffset = 80 + playerHUDS.Count * (int)(barSize.X + barSpacing.X);
57 // playerHUDS.Add(new PlayerHUD(theme, p, xoffset, 10));
58 // }
59 //
60 // public void AddBossHealthBar(Boss b)
61 // {
62 // ProgressBar lastPlayerHealth = playerHUDS.Last().healthBar;
63 // Vector2 size = new Vector2(This.Game.GraphicsDevice.Viewport.Width * 0.8f, barSize.Y * 1.5f);
64 // ProgressBar healthBar = new ProgressBar(b.Name + "_health", b.MaxHealth,
65 // Color.DarkRed, Color.Firebrick, Color.Black, size);
66 // healthBar.Pos = new Vector2(
67 // (This.Game.GraphicsDevice.Viewport.Width - size.X) / 2,
68 // This.Game.GraphicsDevice.Viewport.Height - size.Y * 2);
69 // healthBar.Static = true;
70 // healthBar.Value = b.MaxHealth;
71 //
72 // b.HealthChanged += delegate(object obj, int value)
73 // {
74 // healthBar.Value = value;
75 // };
76 // bossHealthBars.Add(healthBar);
77 // }
78 //
79 // public void RemoveBossHealthBar(Boss b)
80 // {
81 // foreach (ProgressBar p in bossHealthBars.FindAll(p => p.Name == b.Name + "_health"))
82 // {
83 // This.Game.CurrentLevel.RemoveSprite(p);
84 // bossHealthBars.Remove(p);
85 // }
86 // }
87 //
88 // public void ScrollText(string s)
89 // {
90 // if (scroller != null && s != null)
91 // {
92 // scroller.ScrollText(s);
93 // }
94 // }
95 //
96 // public void FadeText(string s)
97 // {
98 // if (fader != null && s != null)
99 // {
100 // fader.FadeText(s);
101 // }
102 // }
103 //
104 //
105 // class PlayerHUD
106 // {
107 // public PlayerHUD(IHUDTheme theme, Player p, int xOffset, int yOffset)
108 // {
109 //
110 // Text name = new Text("player_name_" + p.Name, "Text", p.Name);
111 // name.DisplayColor = theme.TextColor;
112 // name.Pos = new Vector2(xOffset, yOffset);
113 // name.Static = true;
114 //
115 //
116 //
117 // healthBar = new ProgressBar("Health_" + p.Name, p.MaxHealth,
118 // Color.DarkRed, Color.Firebrick, Color.Black, barSize);
119 // healthBar.Pos = new Vector2(xOffset, name.Pos.Y + name.GetAnimation().Height);
120 // healthBar.Static = true;
121 // healthBar.Value = p.MaxHealth;
122 //
123 // p.HealthChanged += delegate(object obj, int value)
124 // {
125 // healthBar.Value = value;
126 // if (value == 0)
127 // {
128 // name.DisplayColor = Color.Tomato;
129 // }
130 // else
131 // {
132 // name.DisplayColor = theme.TextColor;
133 // }
134 // };
135 //
136 //
137 //
138 // manaBar = new ProgressBar("Mana_" + p.Name, p.MaxMana,
139 // Color.MidnightBlue, Color.Blue, Color.Black, barSize);
140 // manaBar.Pos = new Vector2(xOffset,
141 // healthBar.Pos.Y + barSize.Y + barSpacing.Y);
142 // manaBar.Static = true;
143 // manaBar.Value = p.MaxMana;
144 //
145 // p.ManaChanged += delegate(object obj, int value)
146 // {
147 // manaBar.Value = value;
148 // };
149 //
150 //
151 //
152 // spellQueue = new SpellQueue("Queue", theme, p);
153 // spellQueue.Pos = new Vector2(xOffset,
154 // healthBar.Pos.Y + barSize.Y + 2 * barSpacing.Y + barSize.Y);
155 // spellQueue.Static = true;
156 //
157 //
158 //
159 //
160 // }
161 //
162 // ~PlayerHUD()
163 // {
164 // This.Game.CurrentLevel.RemoveSprite(healthBar);
165 // This.Game.CurrentLevel.RemoveSprite(manaBar);
166 // }
167 //
168 //
169 // public ProgressBar healthBar;
170 // public ProgressBar manaBar;
171 // public SpellQueue spellQueue;
172 //
173 //
174 // public int Health
175 // {
176 // get
177 // {
178 // return healthBar.Value;
179 // }
180 // set
181 // {
182 // healthBar.Value = value;
183 // }
184 // }
185 // public int Mana
186 // {
187 // get
188 // {
189 // return manaBar.Value;
190 // }
191 // set
192 // {
193 // manaBar.Value = value;
194 // }
195 // }
196 //
197 // }
198 //
199 // class ItemArea : Sprite
200 // {
201 // public ItemArea(string name, IHUDTheme theme)
202 // : base(name, new Actor(new DummyAnimation(name,
203 // (int)HUD.barSize.X, (int)HUD.barSize.Y)))
204 // {
205 // ZOrder = 100;
206 // this.theme = theme;
207 // background = new Texture2D(This.Game.GraphicsDevice, 1, 1);
208 // background.SetData(new Color[] { theme.TransparentBackgroundColor });
209 // }
210 //
211 // IHUDTheme theme;
212 // Texture2D background;
213 //
214 // static Vector2 itemSpacing = new Vector2(3, 2);
215 // static int itemsPerRow = 5;
216 //
217 // public override void Draw(GameTime gameTime)
218 // {
219 // base.Draw(gameTime);
220 //
221 // This.Game.spriteBatch.Draw(background, new Rectangle(
222 // (int)Pos.X,
223 // (int)Pos.Y,
224 // (int)GetAnimation().Width,
225 // (int)GetAnimation().Height), Color.White);
226 //
227 // if (Player.ItemBag.Count > 0)
228 // {
229 // for (int x = 0; x < Player.ItemBag.Count; x++)
230 // {
231 // Sprite icon = Player.ItemBag[x].Icon;
232 // icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
233 // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
234 // icon.Pos.Y = Pos.Y + itemSpacing.Y +
235 // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
236 // icon.Visible = true;
237 // icon.Draw(gameTime);
238 // }
239 // }
240 // }
241 // }
242 //
243 // class SpellQueue : Sprite
244 // {
245 // public SpellQueue(string name, IHUDTheme theme, Player player)
246 // : base(name, new Actor(new DummyAnimation(name,
247 // (int)HUD.barSize.X, (int)HUD.barSize.Y)))
248 // {
249 // ZOrder = 100;
250 // this.theme = theme;
251 // background = new Texture2D(This.Game.GraphicsDevice, 1, 1);
252 // background.SetData(new Color[] { theme.TransparentBackgroundColor });
253 // this.player = player;
254 // }
255 //
256 // IHUDTheme theme;
257 // Texture2D background;
258 // Player player;
259 //
260 // static Vector2 itemSpacing = new Vector2(12, 2);
261 // static int itemsPerRow = 3;
262 //
263 // public override void Draw(GameTime gameTime)
264 // {
265 // base.Draw(gameTime);
266 //
267 // This.Game.spriteBatch.Draw(background, new Rectangle(
268 // (int)Pos.X,
269 // (int)Pos.Y,
270 // (int)GetAnimation().Width,
271 // (int)GetAnimation().Height), Color.White);
272 //
273 // int limit = 0;
274 // if (Characters.Mage.UnlockedSpells.HasFlag(Spells.EarthThree))
275 // limit = 3;
276 // else if (Characters.Mage.UnlockedSpells.HasFlag(Spells.EarthTwo))
277 // limit = 2;
278 // else
279 // limit = 1;
280 //
281 // for (int x = 0; x < (player as Frostbyte.Characters.Mage).attackCounter.Count && x < limit; x++)
282 // {
283 //
284 // if ((player as Frostbyte.Characters.Mage).attackCounter[x] == Element.Earth && Characters.Mage.UnlockedSpells.HasFlag(Spells.EarthOne))
285 // {
286 // Sprite icon = new ItemIcon("earth", new Actor(This.Game.CurrentLevel.GetAnimation("earthIcon.anim")));
287 // icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
288 // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
289 // icon.Pos.Y = Pos.Y + itemSpacing.Y +
290 // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
291 // icon.Visible = true;
292 // icon.Draw(gameTime);
293 // This.Game.CurrentLevel.RemoveSprite(icon);
294 // }
295 //
296 // else if ((player as Frostbyte.Characters.Mage).attackCounter[x] == Element.Lightning && Characters.Mage.UnlockedSpells.HasFlag(Spells.LightningOne))
297 // {
298 // Sprite icon = new ItemIcon("lightning", new Actor(This.Game.CurrentLevel.GetAnimation("lightningIcon.anim")));
299 // icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
300 // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
301 // icon.Pos.Y = Pos.Y + itemSpacing.Y +
302 // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
303 // icon.Visible = true;
304 // icon.Draw(gameTime);
305 // This.Game.CurrentLevel.RemoveSprite(icon);
306 // }
307 //
308 // else if ((player as Frostbyte.Characters.Mage).attackCounter[x] == Element.Water && Characters.Mage.UnlockedSpells.HasFlag(Spells.WaterOne))
309 // {
310 // Sprite icon = new ItemIcon("water", new Actor(This.Game.CurrentLevel.GetAnimation("waterIcon.anim")));
311 // icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
312 // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
313 // icon.Pos.Y = Pos.Y + itemSpacing.Y +
314 // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
315 // icon.Visible = true;
316 // icon.Draw(gameTime);
317 // This.Game.CurrentLevel.RemoveSprite(icon);
318 // }
319 //
320 // else if ((player as Frostbyte.Characters.Mage).attackCounter[x] == Element.Fire && Characters.Mage.UnlockedSpells.HasFlag(Spells.FireOne))
321 // {
322 // Sprite icon = new ItemIcon("fire", new Actor(This.Game.CurrentLevel.GetAnimation("fireIcon.anim")));
323 // icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
324 // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
325 // icon.Pos.Y = Pos.Y + itemSpacing.Y +
326 // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
327 // icon.Visible = true;
328 // icon.Draw(gameTime);
329 // This.Game.CurrentLevel.RemoveSprite(icon);
330 // }
331 //
332 // //Sprite icon = Player.ItemBag[x].Icon;
333 // //icon.Pos.X = Pos.X + itemSpacing.X + 1 + // Initial alignment of 1px
334 // // (x % itemsPerRow) * (icon.GetAnimation().Width + itemSpacing.X);
335 // //icon.Pos.Y = Pos.Y + itemSpacing.Y +
336 // // (x / itemsPerRow) * (icon.GetAnimation().Height + itemSpacing.Y);
337 // //icon.Visible = true;
338 // //icon.Draw(gameTime);
339 //
340 // }
341 // }
342 // }
343 //}
344 //
345 //public class TextFader : Sprite
346 //{
347 // public TextFader(string name, IHUDTheme theme)
348 // : this(name, theme, 0, 0)
349 // {
350 // }
351 //
352 // public TextFader(string name, int width, int height)
353 // : this(name, new GenericTheme(), width, height)
354 // {
355 // }
356 //
357 // public TextFader(string name, IHUDTheme theme, int width, int height)
358 // : base(name, new Actor(new DummyAnimation(name, width, height)))
359 // {
360 // ZOrder = 100;
361 // UpdateBehavior = update;
362 // this.theme = theme;
363 // Center = new Vector2(0, 0);
364 // Anchor = Orientations.Left;
365 //
366 // pendingText = new Queue<string>();
367 // mStates = States().GetEnumerator();
368 //
369 // toDisplay = new Text("fader_text", theme.TextFont, "");
370 // toDisplay.Visible = false;
371 // toDisplay.DisplayColor = theme.TextColor;
372 // toDisplay.Static = true;
373 // toDisplay.ZOrder = 101;
374 // }
375 //
376 // int MaxCharacters = 100;
377 // IHUDTheme theme;
378 // IEnumerator mStates;
379 // Queue<string> pendingText;
380 // Text toDisplay;
381 //
382 // float mAlpha;
383 // float mFadeIncrement = 0.01f;
384 // TimeSpan mFadeDelay = new TimeSpan(0, 0, 0, 1);
385 //
386 // public Orientations Anchor { get; set; }
387 //
388 // public void FadeText(string text)
389 // {
390 // text = String.Join("", text.Take(MaxCharacters)).Trim();
391 // if (!String.IsNullOrEmpty(text))
392 // {
393 // pendingText.Enqueue(text);
394 // }
395 // }
396 //
397 // public void update()
398 // {
399 // mStates.MoveNext();
400 // }
401 //
402 // IEnumerable States()
403 // {
404 // while (true)
405 // {
406 // if (pendingText.Count > 0)
407 // {
408 // toDisplay.Content = pendingText.Dequeue();
409 // Vector2 displayPos = new Vector2();
410 //
411 //
412 // switch (Anchor)
413 // {
414 // case Orientations.Right:
415 // displayPos.X = Pos.X - toDisplay.GetAnimation().Width;
416 // break;
417 // case Orientations.Up_Right:
418 // goto case Orientations.Right;
419 // case Orientations.Down_Right:
420 // goto case Orientations.Right;
421 // case Orientations.Left:
422 // goto default;
423 // case Orientations.Up_Left:
424 // goto case Orientations.Left;
425 // case Orientations.Down_Left:
426 // goto case Orientations.Left;
427 // default:
428 // displayPos.X = Pos.X;
429 // break;
430 // }
431 //
432 //
433 //
434 // switch (Anchor)
435 // {
436 // case Orientations.Down:
437 // displayPos.Y = Pos.Y - toDisplay.GetAnimation().Height;
438 // break;
439 // case Orientations.Down_Left:
440 // goto case Orientations.Down;
441 // case Orientations.Down_Right:
442 // goto case Orientations.Down;
443 // case Orientations.Up:
444 // goto default;
445 // case Orientations.Up_Left:
446 // goto case Orientations.Up;
447 // case Orientations.Up_Right:
448 // goto case Orientations.Up;
449 // default:
450 // displayPos.Y = Pos.Y;
451 // break;
452 // }
453 //
454 // toDisplay.Pos = displayPos;
455 // toDisplay.Visible = true;
456 //
457 // mAlpha = 0;
458 // toDisplay.DisplayColor = (theme.TextColor * mAlpha);
459 //
460 // foreach (string type in new string[] { "in", "out" })
461 // {
462 // // Leave faded in (or out) for mFadeDelay time
463 // TimeSpan endTime = This.gameTime.TotalGameTime + mFadeDelay;
464 // while (This.gameTime.TotalGameTime < endTime)
465 // {
466 // yield return null;
467 // }
468 //
469 // while (mAlpha >= 0 && mAlpha <= 1)
470 // {
471 // toDisplay.DisplayColor = (theme.TextColor * mAlpha);
472 // mAlpha += mFadeIncrement;
473 // yield return null;
474 // }
475 //
476 // mAlpha -= mFadeIncrement; // Put it back within alpha range
477 // mFadeIncrement *= -1; // Reverse fade direction
478 // }
479 // toDisplay.Visible = false;
480 // }
481 //
482 // yield return null;
483 // }
484 // }
485 //}
486 //
487 //public class TextScroller : Sprite
488 //{
489 // public TextScroller(string name, IHUDTheme theme)
490 // : this(name, theme, This.Game.GraphicsDevice.Viewport.Width - FrostbyteLevel.BORDER_WIDTH,
491 // This.Game.GraphicsDevice.Viewport.Height - (int)(2.5f * FrostbyteLevel.BORDER_HEIGHT))
492 // {
493 // }
494 //
495 // public TextScroller(string name, int width, int height)
496 // : this(name, new GenericTheme(), width, height)
497 // {
498 // }
499 //
500 // public TextScroller(string name, IHUDTheme theme, int width, int height)
501 // : base(name, new Actor(new DummyAnimation(name, width, height)))
502 // {
503 // ZOrder = 100;
504 // UpdateBehavior = update;
505 // this.theme = theme;
506 // background = new Texture2D(This.Game.GraphicsDevice, 1, 1);
507 // background.SetData(new Color[] { theme.TransparentBackgroundColor });
508 // Center = new Vector2(0, 0);
509 // }
510 //
511 // public int MaxCharactersPerLine = 62;
512 // public int TextSpacing = 2;
513 // public bool SplitOnWhitespace = true;
514 // IHUDTheme theme;
515 // vector<char> buffer = new vector<char>();
516 // vector<Text> onScreen = new vector<Text>();
517 // Texture2D background;
518 //
519 // int tickCount = 0;
520 // public int TicksPerScroll = 3;
521 //
522 //
523 // public void ScrollText(string s)
524 // {
525 // buffer.AddRange(s.Replace("\r\n", "\n"));
526 // buffer.AddRange("\n\n");
527 // }
528 //
529 //
530 //
531 // public bool Scrolling { get { return buffer.Count > 0 || onScreen.Count > 0; } }
532 //
533 //
534 //
535 // public void update()
536 // {
537 // tickCount = (tickCount + 1) % TicksPerScroll;
538 // if (onScreen.Count > 0 && tickCount == 0)
539 // {
540 // foreach (Text t in onScreen)
541 // {
542 // t.Pos.Y -= 1;
543 // }
544 //
545 // Sprite fst = onScreen.First();
546 // if (fst.Pos.Y < Pos.Y)
547 // {
548 // This.Game.CurrentLevel.RemoveSprite(fst);
549 // onScreen.RemoveAt(0);
550 // }
551 // }
552 // if (buffer.Count != 0)
553 // {
554 // // We have room to scroll another line of text
555 // if (onScreen.Count == 0 ||
556 // onScreen.Last().Pos.Y + onScreen.Last().GetAnimation().Height + TextSpacing <
557 // Pos.Y + GetAnimation().Height - onScreen.Last().GetAnimation().Height)
558 // {
559 // int width = GetAnimation().Width;
560 // string toDisplay;
561 //
562 // if (String.Join("", buffer.Take(2)) == "\n\n")
563 // {
564 // toDisplay = " ";
565 // buffer.RemoveRange(0, 2);
566 // }
567 // else
568 // {
569 // buffer = buffer.SkipWhile(x => char.IsWhiteSpace(x)).ToList();
570 // IEnumerable<char> pendingDisplay = buffer.TakeWhile((ch, ix) =>
571 // theme.TextFont.MeasureString(
572 // String.Join("", buffer.Take(ix + 1)).Trim()).X < width &&
573 // ch != '\n');
574 //
575 // if (SplitOnWhitespace &&
576 // buffer.Count > pendingDisplay.Count() &&
577 // buffer[pendingDisplay.Count()] != '\n')
578 // {
579 // // Find first instance of whitespace at end
580 // pendingDisplay = pendingDisplay.Reverse().SkipWhile(x => !char.IsWhiteSpace(x)).Reverse();
581 // }
582 //
583 // toDisplay = String.Join("", pendingDisplay).Trim();
584 // buffer.RemoveRange(0, pendingDisplay.Count());
585 // }
586 //
587 // Text line = new Text("text", theme.TextFont, toDisplay.ToString());
588 // line.DisplayColor = theme.TextColor;
589 // line.Pos = new Vector2(Pos.X, Pos.Y + GetAnimation().Height - line.GetAnimation().Height);
590 // line.Static = true;
591 // line.ZOrder = 101;
592 // onScreen.Add(line);
593 // }
594 // }
595 // }
596 //
597 //
598 //
599 // public override void Draw(GameTime gameTime)
600 // {
601 // base.Draw(gameTime);
602 // if (onScreen.Count > 0)
603 // {
604 // This.Game.spriteBatch.Draw(background, new Rectangle(
605 // (int)Pos.X,
606 // (int)Pos.Y,
607 // (int)GetAnimation().Width,
608 // (int)GetAnimation().Height), Color.White);
609 // }
610 // }
611 //
612 //}
613 };
614 #endif