FeatureExamples.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Copyright (c) 2008-2016 the Urho3D project.
  3. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include <Atomic/Engine/Application.h>
  24. #include <Atomic/Graphics/Camera.h>
  25. #include <Atomic/Engine/Engine.h>
  26. #include <Atomic/IO/FileSystem.h>
  27. #include <Atomic/Graphics/Graphics.h>
  28. #include <Atomic/Input/Input.h>
  29. #include <Atomic/Input/InputEvents.h>
  30. #include <Atomic/Graphics/Renderer.h>
  31. #include <Atomic/Resource/ResourceCache.h>
  32. #include <Atomic/Scene/Scene.h>
  33. #include <Atomic/Scene/SceneEvents.h>
  34. #include <Atomic/Graphics/Texture2D.h>
  35. #include <Atomic/Core/Timer.h>
  36. #include <Atomic/UI/UI.h>
  37. #include <Atomic/UI/UIView.h>
  38. #include <Atomic/Resource/XMLFile.h>
  39. #include <Atomic/IO/Log.h>
  40. #include <Atomic/Engine/EngineDefs.h>
  41. #include "FeatureExamples.h"
  42. #include "SampleSelector.h"
  43. ATOMIC_DEFINE_APPLICATION_MAIN(FeatureExamples)
  44. WeakPtr<UIView> FeatureExamples::uiView_;
  45. FeatureExamples::FeatureExamples(Context* context) :
  46. Application(context)
  47. {
  48. }
  49. void FeatureExamples::Setup()
  50. {
  51. // Modify engine startup parameters
  52. engineParameters_[EP_WINDOW_TITLE] = GetTypeName();
  53. engineParameters_[EP_WINDOW_WIDTH] = 1440;
  54. engineParameters_[EP_WINDOW_HEIGHT] = 960;
  55. engineParameters_[EP_LOG_NAME] = GetSubsystem<FileSystem>()->GetAppPreferencesDir("atomic", "logs") + GetTypeName() + ".log";
  56. engineParameters_[EP_FULL_SCREEN] = false;
  57. engineParameters_[EP_HEADLESS ] = false;
  58. engineParameters_[EP_SOUND] = false;
  59. engineParameters_[EP_RESOURCE_PATHS] = "Data;PlayerData;CoreData";
  60. // Construct a search path to find the resource prefix with two entries:
  61. // The first entry is an empty path which will be substituted with program/bin directory -- this entry is for binary when it is still in build tree
  62. // The second and third entries are possible relative paths from the installed program/bin directory to the asset directory -- these entries are for binary when it is in the Atomic SDK installation location
  63. if (!engineParameters_.Contains(EP_RESOURCE_PREFIX_PATHS))
  64. {
  65. // TODO: This is dependent on a source build
  66. String resourcePrefix = ToString("%s/Resources;%s/Submodules/AtomicExamples/FeatureExamples/CPlusPlus", ATOMIC_ROOT_SOURCE_DIR, ATOMIC_ROOT_SOURCE_DIR);
  67. engineParameters_[EP_RESOURCE_PREFIX_PATHS] = resourcePrefix;
  68. }
  69. }
  70. void FeatureExamples::Start()
  71. {
  72. UI* ui = GetSubsystem<UI>();
  73. ui->Initialize("DefaultUI/language/lng_en.tb.txt");
  74. ui->LoadDefaultPlayerSkin();
  75. // create new UIView
  76. uiView_ = new UIView(context_);
  77. // Set custom window Title & Icon
  78. SetWindowTitleAndIcon();
  79. new SampleSelector(context_);
  80. SubscribeToEvent(E_KEYDOWN, ATOMIC_HANDLER(FeatureExamples, HandleKeyDown));
  81. }
  82. void FeatureExamples::Stop()
  83. {
  84. engine_->DumpResources(true);
  85. }
  86. void FeatureExamples::HandleKeyDown(StringHash eventType, VariantMap& eventData)
  87. {
  88. using namespace KeyDown;
  89. int key = eventData[P_KEY].GetInt();
  90. // Toggle console with F1
  91. if (key == KEY_F1)
  92. {
  93. GetSubsystem<UI>()->ToggleConsole();
  94. }
  95. // Toggle debug HUD with F2
  96. else if (key == KEY_F2)
  97. {
  98. GetSubsystem<UI>()->ToggleDebugHud();
  99. }
  100. }
  101. void FeatureExamples::SetWindowTitleAndIcon()
  102. {
  103. ResourceCache* cache = GetSubsystem<ResourceCache>();
  104. Graphics* graphics = GetSubsystem<Graphics>();
  105. Image* icon = cache->GetResource<Image>("Textures/UrhoIcon.png");
  106. graphics->SetWindowIcon(icon);
  107. graphics->SetWindowTitle("Atomic Sample");
  108. }