GameCenter.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifdef TORQUE_ALLOW_GAMEKIT
  23. #ifndef _CONSOLEINTERNAL_H_
  24. #include "console/consoleInternal.h"
  25. #import <Foundation/Foundation.h>
  26. #import <GameKit/GameKit.h>
  27. class Achievement : public SimObject
  28. {
  29. typedef SimObject Parent;
  30. public:
  31. // Constructor (currently does nothing)
  32. Achievement();
  33. // Called when an object is created in script or registered in C++
  34. bool onAdd();
  35. // Called when an object is deleted from the system
  36. void onRemove();
  37. // Exposes the Achievement member variables to TorqueScript
  38. static void initPersistFields();
  39. // Debug function used to print all achievement data to the console
  40. void printAchievement();
  41. // Helper function that sets a Achievement's member variables in C++
  42. void setAchievementFields(const char* identifier, const char* title, const char* achievedDescription, const char* unachievedDescription, int maxPoints, bool hidden);
  43. // The following member variables are the iT2D equivalent of what is found in Game Center
  44. // It is important to note that the actual properties in Game Center are read-only.
  45. // A unique string used to identify the achievement
  46. StringTableEntry mIdentifier;
  47. // A localized description of the completed achievement
  48. StringTableEntry mTitle;
  49. // A localized description of the completed achievement
  50. StringTableEntry mAchievedDescription;
  51. // A localized description of the achievement, to be used when the achievement has not been completed
  52. StringTableEntry mUnachievedDescription;
  53. // A Boolean value that states whether this achievement should be visible to players
  54. bool mHidden;
  55. // The number of points earned by completing this achievement
  56. int mMaximumPoints;
  57. DECLARE_CONOBJECT(Achievement);
  58. };
  59. #endif
  60. // Main Game Center interface. This is what is responsible for all Game Center functionality
  61. // This object is exposed to the rest of the engine via a static variable: gameCenterManager
  62. // The declaration of this is found at the bottom of this header
  63. @interface GameCenterManager : UIViewController <GKLeaderboardViewControllerDelegate, GKAchievementViewControllerDelegate>
  64. {
  65. NSMutableDictionary* achievementCache;
  66. UIViewController *gameCenterViewController;
  67. BOOL isAuthenticated;
  68. BOOL gameCenterAvailable;
  69. int achievementCount;
  70. }
  71. @property (retain) NSMutableDictionary* achievementCache;
  72. @property int achievementCount;
  73. @property (nonatomic, retain) UIViewController* gameCenterViewController;
  74. - (void) authenticateLocalUser;
  75. - (void) registerForAuthenticationNotification: (NSError*) error;
  76. - (void) reportScore: (int64_t) score forCategory: (NSString*) category;
  77. - (void) reloadHighScoresForCategory: (NSString*) category;
  78. - (void) showLeaderboard;
  79. - (void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController;
  80. - (void) submitAchievement: (NSString*) identifier percentComplete: (float) percentComplete;
  81. - (void) resetAchievements;
  82. - (void) showAchievements;
  83. - (void) cacheAchievements;
  84. - (void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController;
  85. @end
  86. // The global variable used when interfacing with TorqueScript
  87. static GameCenterManager* gameCenterManager;
  88. #endif //TORQUE_ALLOW_GAMEKIT