AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzMarket.h
Go to the documentation of this file.
00001 #if !defined(_CPLATFORM_MARKET_H_)
00002 #define _CPLATFORM_MARKET_H_
00003 
00004 #include "IzPlatformSys.h"
00005 #include "IzPlatformMarket.h"
00006 #include "CzString.h"
00007 #include "CzUtil.h"
00008 #include "CzXoml.h"
00009 #include "CzActions.h"
00010 #include "CzEvents.h"
00011 #include "CzScript.h"
00012 #include "CzTime.h"
00013 
00014 //
00015 //
00016 // CzMarketProduct - A product that can be purchased
00017 // 
00018 //
00019 struct CzMarketProduct
00020 {
00021 public:
00022     CzString            Name;       // Name of product
00023     CzString            ProductID;  // External product ID (com.companyname.appname.productname for example)
00024     bool                Purchased;  // Purchased state
00025     bool                Consumable; // True if this is a consumable item that can be repurchased when depleted
00026     float               Price;      // Price of product
00027 
00028     CzMarketProduct() : Purchased(false), Consumable(false), Price(0) {}
00029 
00030     bool                Save();
00031     bool                Load();
00032 };
00033 
00034 
00035 //
00036 //
00037 //
00038 //
00039 // CzMarket - A market object that can be declared and instantiated from XOML
00040 //
00041 //
00042 // 
00043 //
00044 class CzMarket : public IzXomlResource
00045 {
00046 public:
00047     typedef CzList<CzMarketProduct*>::iterator _ProductIterator;
00048     _ProductIterator                begin() { return Products.begin(); }
00049     _ProductIterator                end() { return Products.end(); }
00050 
00051 protected:
00052     // Properties
00053     CzList<CzMarketProduct*> Products;              ///< Available products
00054     CzEventManager*         EventsManager;          ///< List of events that the animation handles
00055     CzScriptCallback        ScriptCallback;         ///< Script call back
00056     CzString                CurrentProductID;       ///< Current Product ID (e.g. com.companyname.appname.productname)
00057     bool                    Busy;                   ///< When true the market is busy
00058 public:
00059     CzEventManager*         getEventsManager()                                  { return EventsManager; }
00060     void                    addProduct(CzMarketProduct* product)                { Products.push_back(product); }
00061     void                    removeProduct(CzMarketProduct* product);
00062     CzMarketProduct*        findProduct(const char* product_id);
00063     CzMarketProduct*        findProductByName(unsigned int name_hash);
00064     void                    setCurrentProductID(const char* product_id);
00065     const char*             getCurrentProductID() const                         { return CurrentProductID.c_str(); }
00066     int                     getProductCount() const                             { return Products.size(); }
00067     void                    setPurchased(const char* product_id, bool purchased = true);
00068     CzScriptCallback&       getScriptCallback()                                 { return ScriptCallback; }
00069     bool                    isBusy() const                                      { return Busy; }
00070     void                    setBusy(bool busy)                                  { Busy = busy; }
00071     // Properties end
00072 
00073 protected:
00074     void                    ProcessEventActions(unsigned int event_name, IzXomlResource* parent);
00075 
00076 public:
00077     CzMarket() : IzXomlResource(), EventsManager(NULL), Busy(false) { setClassType("market"); }
00078     virtual ~CzMarket()
00079     {
00080         Release();
00081     }
00082 
00083     int                     Init(const char* public_key);
00084     void                    Release();
00085 
00086     void                    Save();
00087     void                    Load();
00088 
00089     // Implementation of IzXomlClass interface
00090     int                     LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00091 
00092     bool                    QueryProduct(const char* product_id);
00093     bool                    PurchaseProduct(const char* product_id);
00094     bool                    RestoreProducts();
00095 
00096     void                    NotifyUnavailable();
00097     void                    NotifyComplete();
00098     void                    NotifyError();
00099     void                    NotifyBillingDisabled();
00100     void                    NotifyRefund();
00101     void                    NotifyInfoAvailable();
00102 
00103 };
00104 
00105 //
00106 //  CzMarketCreator - Creates an instance of the market 
00107 //
00108 class CzMarketCreator : public IzXomlClassCreator
00109 {
00110 public:
00111     CzMarketCreator()
00112     {
00113         setClassName("market");
00114     }
00115     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzMarket(); }
00116 };
00117 
00118 
00119 #endif  // _CPLATFORM_MARKET_H_
00120