dmuratshin 9 years ago
parent
commit
4e4698a284

+ 4 - 11
example/HelloWorldBilling/src/example.cpp

@@ -74,13 +74,15 @@ void example_init()
 
 	billing::dispatcher()->addEventListener(billing::PurchasedEvent::EVENT, [](Event* e){
 		
-        Test::instance->notify("purchased");
+        //Test::instance->notify("purchased");
 
         billing::PurchasedEvent *ev = safeCast<billing::PurchasedEvent*>(e);
 
         billing::ParsePurchasedData parced(ev);
         lastPurchasedItemToken = parced.purchaseToken;
         Test::instance->updateText("consume", "Consume item: " + parced.productID + ":" + lastPurchasedItemToken);
+
+        Test::instance->notify(ev->data, 10000, true);
 	});
 
 	billing::dispatcher()->addEventListener(billing::DetailsEvent::EVENT, [](Event* e){
@@ -88,17 +90,8 @@ void example_init()
 
         billing::DetailsEvent *ev = safeCast<billing::DetailsEvent*>(e);
         billing::ParsedDetailsData parced(ev);
-        
-        for (size_t i = 0; i < parced.items.size(); ++i)
-        {
-            const billing::ParsedDetailsData::Item &item = parced.items.front();
-            std::string str;
-            str = item.productId + " " + item.price;
-
-            Test::instance->notify(str);
-        }
-        
 
+        Test::instance->notify(ev->data, 10000, true);
 	});
 
 	Test::init();

+ 21 - 3
example/HelloWorldBilling/src/test.cpp

@@ -203,7 +203,7 @@ void Test::back(Event* event)
 }
 
 
-void Test::notify(std::string txt, int time)
+void Test::notify(std::string txt, int time, bool autoSize)
 {
     size_t N = 0;
     for (size_t i = 0; i < MAX_NOTIFIES; ++i)
@@ -235,12 +235,30 @@ void Test::notify(std::string txt, int time)
 
     sprite->addTween(tq);
     sprite->attachTo(ui);
-    sprite->setPosition(2.0f, getHeight() - 100.0f - N * sprite->getHeight() * 1.1f);
+    
 
     spTextField text = createText(txt);
     text->attachTo(sprite);
     text->setColor(Color::Black);
-    text->setPosition(sprite->getSize() / 2);
+
+    if (autoSize)
+    {
+        text->setWidth(getStage()->getWidth() / 2);
+        text->setHAlign(TextStyle::HALIGN_LEFT);
+        text->setVAlign(TextStyle::VALIGN_TOP);
+        text->setX(0);
+        text->setMultiline(true);
+        text->setBreakLongWords(true);
+        sprite->setSize(text->getTextRect().getSize());
+
+    }
+    else
+    {
+        text->setPosition(sprite->getSize() / 2);
+    }
+    
+    sprite->setPosition(2.0f, getHeight() - 100.0f - N * sprite->getHeight() * 1.1f);
+    
 }
 
 void Test::notifyDone(Event* ev)

+ 1 - 1
example/HelloWorldBilling/src/test.h

@@ -63,7 +63,7 @@ public:
     void _toggleClicked(Event* event);
     void back(Event* event);
 
-    void notify(string text, int time = 400);
+    void notify(string text, int time = 400, bool autosize = false);
 
 protected:
     void notifyDone(Event* ev);