Exemple #1
0
void ChrsGrid::showAnswer()
{
	auto pAnswerChrs = &m_AnswerChrs;
	for (int i = 0; i < m_AnswerChrs.size(); i++)
	{
		auto chr = m_AnswerChrs.at(i);

		//系统演示步骤:1.显示可消除颜色和连接箭头 2.等待全部词组显示完 3.显示正常颜色,去掉连接箭头
		//共演示两次
		auto delay1 = DelayTime::create(i / 2.0);
		auto call1 = CallFunc::create([chr, i, pAnswerChrs](){
			//1.改变颜色 2.添加箭头
			chr->getBg()->setTexture("char_bg_crush.png");
			if (i > 0){	pAnswerChrs->at(i-1)->showArrow(chr); }
		});
		auto delay2 = DelayTime::create((m_AnswerChrs.size() - i) / 2.0);
		auto call2 = CallFunc::create([chr, i, pAnswerChrs](){
			//1.改变颜色为正常 2.隐藏箭头
			chr->getBg()->setTexture(chr->getNormalBG().c_str());
			chr->hideArrow();
		});
		auto delay3 = DelayTime::create(0.5);

		auto action = Repeat::create(Sequence::create(delay1, call1, delay2, call2, delay3, nullptr), 2);
		chr->runAction(action);
	}
}
void UIBuyBuildingLayer::initBg()
{
	setBg(Sprite::create("ui/bank.png"));
	getBg()->setAnchorPoint(Point(0,0));
	addChild(getBg());
    
	//四个标签页
	auto sprite1 = Sprite::create("ui/select.png");
	_curSp = sprite1;
	_taps.pushBack(sprite1);
	_taps.pushBack(Sprite::create("ui/normal.png"));
    _taps.pushBack(Sprite::create("ui/normal.png"));
	_taps.pushBack(Sprite::create("ui/normal.png"));

    auto width    = sprite1->getContentSize().width;
	auto height   = sprite1->getContentSize().height;
	auto beginpos = (Director::getInstance()->getWinSize().width - width * (_taps.size() - 1)) / 2;

	std::vector<std::string> str_vec;
	auto con = Configuration::getInstance();
	str_vec.push_back(con->getValue("text_fundation").asString());
	str_vec.push_back(con->getValue("text_def").asString());
	str_vec.push_back(con->getValue("text_resource").asString());
	str_vec.push_back(con->getValue("text_decorate").asString());

	auto index = 0;
	for (auto sp : _taps)
	{
	   sp->setAnchorPoint(Point(0.5f,0));
	   sp->setPosition(Point(beginpos,0));
	   sp->setTag(index + 1);
	   addChild(sp);
	   
	   auto lable = Label::createWithSystemFont(str_vec.at(index++),"",20);
	   lable->setColor(Color3B(200,200,200));
	   lable->setPosition(Point(width/2,height/2));
	   sp->addChild(lable);

	   beginpos += width;
	}

	_tableview = TableView::create(this, Size(Director::getInstance()->getWinSize().width, 317 + 200));
	_tableview->setDirection(ScrollView::Direction::HORIZONTAL);
	_tableview->setPosition(Point(0,65));
	_tableview->setDelegate(this);
	this->addChild(_tableview);
	_tableview->reloadData();

	

}
Exemple #3
0
Pixel
CwmCustomIcon::
getBgPixel(CwmScreen &screen) const
{
  std::string bg_color = getBg();

  return screen.getPixel(bg_color, screen.getWhitePixel());
}
Exemple #4
0
bool ChrsGrid::onTouchBegan(Touch* pTouch, Event*)
{
	//如果已经选择了汉字元素,那么不接受新的触摸
	if (!m_SelectedChrs.empty())
	{
		return false;
	}

	//重置系统提示汉字元素盒子,停止倒计时捕捉,即停止提示功能
	resetAnswerChrs();
	unschedule(schedule_selector(ChrsGrid::onCountdownCallBack));

	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否有按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前选中的汉字元素,设置选中颜色
		auto chr = m_ChrsBox[x][y];
		chr->getBg()->setTexture("char_bg_selected.png");

		//执行按住后动作
		chr->chrAciton();

		//加入临时选定汉字集合,然后更改游戏主界面的letter label显示
		m_SelectedChrs.pushBack(chr);
		getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), false);

		//得到能否消除的状态
		m_canCrush = canCrush();

		//log("touch coordinate: x=%d,y=%d", x, y);

		return true;
	}
	else
	{
		return false;
	}
}
Exemple #5
0
/**
*函数说明:移动触摸,将触摸到的新汉字元素放进已选汉字盒子
*如果是倒退,那么将最后一个汉字元素从已选汉字盒子中删除
*每一次增加/删除汉字元素,都会判断当前已选的汉字是否能消除
*/
void ChrsGrid::onTouchMoved(Touch* pTouch, Event*)
{
	//移动时也可选择
	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前触摸点的汉字元素,以及最后一次选择的汉字
		auto chr = m_ChrsBox[x][y];
		auto last_chr = m_SelectedChrs.back();

		//判断当前触摸点的汉字是否与最后一次选择的相邻
		int dx = abs(chr->getX() - last_chr->getX());
		int dy = abs(chr->getY() - last_chr->getY());
		int d = dx + dy;
		if (dx < 2 && dy < 2 && d <= 2 && d > 0)
		{
			//如果符合情况,那么将其加入临时选择汉字盒子,并设置选中颜色
			//只有当临时选择汉字集合中没有该汉字元素时,才添加
			if (!m_SelectedChrs.contains(chr))
			{
				//判断哪个箭头显示
				last_chr->showArrow(chr);

				m_SelectedChrs.pushBack(chr);
				chr->getBg()->setTexture("char_bg_selected.png");

				//执行按住后动作
				chr->chrAciton();

				//得到能否消除的状态
				m_canCrush = canCrush();
				if (m_canCrush)
				{
					for (auto &chr : m_SelectedChrs)
					{
						chr->chrAciton();
					}
				}
			}
		}

		//如果当前触摸点是已选汉字盒子中倒数第二个汉字,说明是后退操作
		//将倒数第一个元素删除出已选汉字盒子
		if (m_SelectedChrs.size() >= 2)
		{
			//得到倒数第二个元素,判断是否和触摸点的元素一致
			auto secondlast_chr = m_SelectedChrs.at(m_SelectedChrs.size()-2);
			if (secondlast_chr == chr)
			{
				//对最后一个元素执行释放后动作
				m_SelectedChrs.back()->chrAciton();

				//将最后一个元素删除出去
				m_SelectedChrs.back()->getBg()->setTexture(m_SelectedChrs.back()->getNormalBG());
				m_SelectedChrs.popBack();

				//然后将现有最后一个的汉字的箭头隐藏
				auto chr = m_SelectedChrs.back();
				auto arrow = chr->getArrow();
				for (int i = 0; i < 8; i++) { if (arrow[i]->isVisible()) arrow[i]->setVisible(false); }

				m_canCrush = canCrush();
				/*
				if (m_canCrush)
				{
				for (auto &chr : m_SelectedChrs)
				{
				chr->chrAciton();
				}
				}
				*/
			}

			//更改主界面的letter label的显示
			getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), m_canCrush);
		}
	}
}