Beispiel #1
0
void GameLayer::initAnswerLayer(std::vector<std::string> &StrVector)
{
    CCArray *answerChildren = _answerLayer->getChildren();
    
    _canAnsImageSize = static_cast<UIButton *>(answerChildren->objectAtIndex(0))->getContentSize();
    
    CCObject *obj_butt;
    
    int countPerRow = 8;
    int row = 0,col = 0;
    int currCount = 0;
    
    CCARRAY_FOREACH(answerChildren, obj_butt)
    {
        row = currCount / countPerRow;
        col = currCount % countPerRow;
        
        UIButton *anButt = (UIButton *)(obj_butt);
        anButt->setTouchEnable(true);
        anButt->addTouchEventListener(this,toucheventselector(GameLayer::answerButt));
        
        CCPoint buttPoint = CCPointMake(CG_FISTANBUTT_POINT.x + (CG_ANSWER_BUTT_SPACE_SIZE.width)* col, CG_FISTANBUTT_POINT.y + (CG_ANSWER_BUTT_SPACE_SIZE.height) * row);
        
        anButt->setPosition(buttPoint);
        
        std::string butt_titlt_str = StrVector.at(currCount);
        
        if (!CGHelper::isChineseChar(butt_titlt_str.c_str())) {
            anButt->setTitleFontSize(20);
        }
        
        anButt->setText(butt_titlt_str.c_str());
        currCount++;
    }
Beispiel #2
0
UIFrame* UITexturingGUI::createTilesetLoader()
{
	float buttonSize = 150.0f;
	LoadTextureNames();

	int columns = tilesetDirectories.size() / 4;
	if (tilesetDirectories.size() % 4 != 0)
		columns++;

	UIButton * name;
	windowTilesetLoader = new UICloseWindow(
		video.xres() / 2.0f - 308.0f,
		video.yres() / 2.0f - 139.0f,
		856.0f,
		22.0f + 21.0f * columns + 5.0f,
		"Tileset Loading");
	windowTilesetLoader->movable(true);



	for (unsigned int i = 0; i < tilesetDirectories.size(); ++i)
	{
		name = new UIButton(
			5.0f + 212.0f * (i / columns),
			23.0f + 21.0f * (i % columns),
			210.0f,
			28.0f,
			"Interface\\Buttons\\UI-DialogBox-Button-Up.blp",
			"Interface\\Buttons\\UI-DialogBox-Button-Down.blp"
			);

		std::string setname;
		setname = tilesetDirectories[i];

		name->setText(setname);
		name->setClickFunc(LoadTileset, i);
		windowTilesetLoader->addChild(name);
	}



	windowTilesetLoader->hide();

	return windowTilesetLoader;
}
Beispiel #3
0
UIButton* UI::addButton(int id, int x, int y, int width, int height, 
            uint32_t textureID_idle, uint32_t textureID_hover, uint32_t textureID_press,  
            const char* text, void (*callback)(UINode* Sender), UINode* parent)
{
    UIButton* button;
    if(parent==NULL) button = new UIButton(mRootNode);
    else button = new UIButton(parent);
    button->nodeID = id;
    button->textureID_idle = textureID_idle;
    button->textureID_hover = textureID_hover;
    button->textureID_press = textureID_press;
    button->setPos(x, y);
    button->setText(text);
    button->setSize(width, height);
    button->setCallback(callback);
    nodeList.push_back(button);
    return button;
}
Beispiel #4
0
bool AdResponseBox::createButtons() {
    clearButtons();

    _scrollOffset = 0;
    for (uint32 i = 0; i < _responses.size(); i++) {
        UIButton *btn = new UIButton(_gameRef);
        if (btn) {
            btn->_parent = _window;
            btn->_sharedFonts = btn->_sharedImages = true;
            btn->_sharedCursors = true;
            // iconic
            if (_responses[i]->getIcon()) {
                btn->_image = _responses[i]->getIcon();
                if (_responses[i]->getIconHover()) {
                    btn->_imageHover = _responses[i]->getIconHover();
                }
                if (_responses[i]->getIconPressed()) {
                    btn->_imagePress = _responses[i]->getIconPressed();
                }

                btn->setCaption(_responses[i]->getText());
                if (_cursor) {
                    btn->_cursor = _cursor;
                } else if (_gameRef->_activeCursor) {
                    btn->_cursor = _gameRef->_activeCursor;
                }
            }
            // textual
            else {
                btn->setText(_responses[i]->getText());
                btn->_font = (_font == nullptr) ? _gameRef->getSystemFont() : _font;
                btn->_fontHover = (_fontHover == nullptr) ? _gameRef->getSystemFont() : _fontHover;
                btn->_fontPress = btn->_fontHover;
                btn->_align = _align;

                if (_gameRef->_touchInterface) {
                    btn->_fontHover = btn->_font;
                }


                if (_responses[i]->getFont()) {
                    btn->_font = _responses[i]->getFont();
                }

                btn->_width = _responseArea.right - _responseArea.left;
                if (btn->_width <= 0) {
                    btn->_width = _gameRef->_renderer->getWidth();
                }
            }
            btn->setName("response");
            btn->correctSize();

            // make the responses touchable
            if (_gameRef->_touchInterface) {
                btn->_height = MAX<int32>(btn->_height, 50);
            }

            //btn->SetListener(this, btn, _responses[i]->_iD);
            btn->setListener(this, btn, i);
            btn->_visible = false;
            _respButtons.add(btn);

            if (_responseArea.bottom - _responseArea.top < btn->_height) {
                _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->getText());
                _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top));
            }
        }
    }
    _ready = false;

    return STATUS_OK;
}