axmol/tests/fairygui-tests/Classes/BagWindow.cpp

41 lines
1.3 KiB
C++
Raw Normal View History

2020-08-04 13:15:02 +08:00
#include "BagWindow.h"
USING_NS_AX;
2020-08-04 13:15:02 +08:00
void BagWindow::onInit()
{
setContentPane(UIPackage::createObject("Bag", "BagWin")->as<GComponent>());
center();
setModal(true);
_list = _contentPane->getChild("list")->as<GList>();
_list->addEventListener(UIEventType::ClickItem, CC_CALLBACK_1(BagWindow::onClickItem, this));
_list->itemRenderer = CC_CALLBACK_2(BagWindow::renderListItem, this);
2020-08-04 13:15:02 +08:00
_list->setNumItems(45);
}
void BagWindow::renderListItem(int index, GObject* obj)
{
2020-08-06 19:58:24 +08:00
obj->setIcon("icons/i" + std::to_string((int)(rand_0_1() * 10)) + ".png");
obj->setText(std::to_string((int)(rand_0_1() * 100)));
2020-08-04 13:15:02 +08:00
}
void BagWindow::doShowAnimation()
{
setScale(0.1f, 0.1f);
setPivot(0.5f, 0.5f);
GTween::to(getScale(), Vec2::ONE, 0.3f)->setTarget(this, TweenPropType::Scale)->onComplete(CC_CALLBACK_0(BagWindow::onShown, this));
2020-08-04 13:15:02 +08:00
}
void BagWindow::doHideAnimation()
{
GTween::to(getScale(), Vec2(0.1f, 0.1f), 0.3f)->setTarget(this, TweenPropType::Scale)->onComplete(CC_CALLBACK_0(BagWindow::hideImmediately, this));
2020-08-04 13:15:02 +08:00
}
void BagWindow::onClickItem(EventContext* context)
{
GObject* item = (GObject*)context->getData();
_contentPane->getChild("n11")->setIcon(item->getIcon());
_contentPane->getChild("n13")->setText(item->getText());
}