HoverRace  2.0
HudPeer.h
Go to the documentation of this file.
1 
2 // HudPeer.h
3 //
4 // Copyright (c) 2013-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <luabind/luabind.hpp>
25 #include <luabind/object.hpp>
26 
27 #include "../../../engine/Display/Hud.h"
28 #include "../../../engine/Script/Core.h"
29 #include "../../../engine/Script/Peer.h"
30 
31 namespace HoverRace {
32  namespace Display {
33  class Chronometer;
34  class Counter;
35  class Display;
36  class HudText;
37  }
38  namespace Util {
39  class Clock;
40  }
41 }
42 
43 namespace HoverRace {
44 namespace Client {
45 namespace HoverScript {
46 
51 class HudPeer : public Script::Peer
52 {
55 
56 public:
57  HudPeer(Script::Core &scripting, Display::Display &display,
58  std::weak_ptr<Display::Hud> hud);
59  virtual ~HudPeer() { }
60 
61 public:
62  static void Register(Script::Core &scripting);
63 
64 private:
72  {
73  try {
74  return HudAlignment::FromInt(align);
75  }
76  catch (Exception &ex) {
77  luaL_error(GetScripting().GetState(), "%s", ex.what());
78  throw; // Never actually reached (luaL_error doesn't return).
79  }
80  }
81 
82 public:
83  std::shared_ptr<Display::Chronometer> LAddChronometer(int align,
84  const std::string &title, std::shared_ptr<Util::Clock> clock);
85 
86  std::shared_ptr<Display::Counter> LAddCounter_V(int align,
87  const std::string &title, double initValue);
88  std::shared_ptr<Display::Counter> LAddCounter_VT(int align,
89  const std::string &title, double initValue, double total);
90 
91  std::shared_ptr<Display::HudText> LAddText(int align,
92  const std::string &text);
93 
94  template<class T>
95  std::shared_ptr<T> LAddDecor(int align)
96  {
97  HudAlignment::type ha = ValidateAlignment(align);
98  if (auto sp = hud.lock()) {
99  return sp->At(ha).NewChild<T>(display);
100  }
101  else {
102  return std::shared_ptr<T>();
103  }
104  }
105 
106  void LClear();
107 
108  void LUseRaceDefault();
109 
110 private:
112  std::weak_ptr<Display::Hud> hud;
113 };
114 
115 } // namespace HoverScript
116 } // namespace Client
117 } // namespace HoverRace
std::weak_ptr< Display::Hud > hud
Definition: HudPeer.h:112
const char * what() const noexceptoverride
Definition: Exception.h:52
Display::Display & display
Definition: HudPeer.h:111
HudAlignment::type ValidateAlignment(int align)
Convert an int into an alignment value, raising a Lua error if the the value is out of range...
Definition: HudPeer.h:71
HoverRace::Display::Hud::HudAlignment HudAlignment
Definition: HudPeer.cpp:35
Base class for display managers.
Definition: Display.h:73
std::shared_ptr< T > LAddDecor(int align)
Definition: HudPeer.h:95
Scripting peer for access to the HUD for a player.
Definition: HudPeer.h:51
Base class for script peers.
Definition: Peer.h:47
Definition: Announcement.h:24
Base exception, providing constructors for setting the message.
Definition: Exception.h:42
static type FromInt(int t)
Safely convert from an int.
Definition: Hud.h:107
virtual ~HudPeer()
Definition: HudPeer.h:59
A script environment.
Definition: Core.h:66