TeapotWarsView.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. //========================================================================
  3. // TeapotWarsView.h : source file for the sample game
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include "../GCC4/UserInterface/HumanView.h"
  40. #include "../GCC4/UserInterface/UserInterface.h"
  41. #include <imgui.h>
  42. #include <imgui_impl_sdl3.h>
  43. #include <imgui_impl_opengl3.h>
  44. class MainMenuUI : public BaseUI
  45. {
  46. private:
  47. bool m_bCreatingGame;
  48. int m_NumAIs;
  49. int m_NumPlayers;
  50. std::vector<std::string> m_Levels;
  51. int m_LevelIndex;
  52. std::string m_HostName;
  53. std::string m_HostListenPort;
  54. std::string m_ClientAttachPort;
  55. public:
  56. MainMenuUI();
  57. // IScreenElement Implementation
  58. virtual int VOnRestore();
  59. virtual int VOnRender(double fTime, float fElapsedTime);
  60. virtual int VGetZOrder() const { return 1; }
  61. virtual void VSetZOrder(int const zOrder) { }
  62. virtual int VOnMsgProc( SDL_Event &e );
  63. void _OnGUIEvent(unsigned int nEvent);
  64. };
  65. class MainMenuView : public HumanView
  66. {
  67. protected:
  68. std::shared_ptr<MainMenuUI> m_MainMenuUI;
  69. public:
  70. MainMenuView();
  71. ~MainMenuView();
  72. virtual int VOnMsgProc(SDL_Event &e);
  73. virtual void VRenderText();
  74. virtual void VOnUpdate(unsigned long deltaMs);
  75. };
  76. class TeapotWarsHumanView : public HumanView
  77. {
  78. protected:
  79. bool m_bShowUI; // If true, it renders the UI control text
  80. std::shared_ptr<MovementController> m_pFreeCameraController;
  81. std::shared_ptr<SceneNode> m_pTeapot;
  82. public:
  83. TeapotWarsHumanView(std::shared_ptr<IRenderer> renderer);
  84. virtual ~TeapotWarsHumanView();
  85. virtual int VOnMsgProc( SDL_Event &e );
  86. virtual void VRenderText();
  87. virtual void VOnUpdate(unsigned long deltaMs);
  88. virtual void VOnAttach(GameViewId vid, ActorId aid);
  89. virtual void VSetControlledActor(ActorId actorId);
  90. virtual bool VLoadGameDelegate(TiXmlElement* pLevelData) override;
  91. // event delegates
  92. void SetControlledActorDelegate(IEventDataPtr pEventData);
  93. private:
  94. void RegisterAllDelegates(void);
  95. void RemoveAllDelegates(void);
  96. };