当前位置: 首页>>代码示例>>C++>>正文


C++ Text类代码示例

本文整理汇总了C++中Text的典型用法代码示例。如果您正苦于以下问题:C++ Text类的具体用法?C++ Text怎么用?C++ Text使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST_F

TEST_F(StaticRangeTest, SplitTextNodeRangeWithinText)
{
    document().body()->setInnerHTML("1234", ASSERT_NO_EXCEPTION);
    Text* oldText = toText(document().body()->firstChild());

    StaticRange* staticRange04 = StaticRange::create(document(), oldText, 0, oldText, 4);
    StaticRange* staticRange02 = StaticRange::create(document(), oldText, 0, oldText, 2);
    StaticRange* staticRange22 = StaticRange::create(document(), oldText, 2, oldText, 2);
    StaticRange* staticRange24 = StaticRange::create(document(), oldText, 2, oldText, 4);

    Range* range04 = staticRange04->toRange(ASSERT_NO_EXCEPTION);
    Range* range02 = staticRange02->toRange(ASSERT_NO_EXCEPTION);
    Range* range22 = staticRange22->toRange(ASSERT_NO_EXCEPTION);
    Range* range24 = staticRange24->toRange(ASSERT_NO_EXCEPTION);

    oldText->splitText(2, ASSERT_NO_EXCEPTION);
    Text* newText = toText(oldText->nextSibling());

    // Range should mutate.
    EXPECT_TRUE(range04->boundaryPointsValid());
    EXPECT_EQ(oldText, range04->startContainer());
    EXPECT_EQ(0, range04->startOffset());
    EXPECT_EQ(newText, range04->endContainer());
    EXPECT_EQ(2, range04->endOffset());

    EXPECT_TRUE(range02->boundaryPointsValid());
    EXPECT_EQ(oldText, range02->startContainer());
    EXPECT_EQ(0, range02->startOffset());
    EXPECT_EQ(oldText, range02->endContainer());
    EXPECT_EQ(2, range02->endOffset());

    // Our implementation always moves the boundary point at the separation point to the end of the original text node.
    EXPECT_TRUE(range22->boundaryPointsValid());
    EXPECT_EQ(oldText, range22->startContainer());
    EXPECT_EQ(2, range22->startOffset());
    EXPECT_EQ(oldText, range22->endContainer());
    EXPECT_EQ(2, range22->endOffset());

    EXPECT_TRUE(range24->boundaryPointsValid());
    EXPECT_EQ(oldText, range24->startContainer());
    EXPECT_EQ(2, range24->startOffset());
    EXPECT_EQ(newText, range24->endContainer());
    EXPECT_EQ(2, range24->endOffset());

    // StaticRange shouldn't mutate.
    EXPECT_EQ(oldText, staticRange04->startContainer());
    EXPECT_EQ(0, staticRange04->startOffset());
    EXPECT_EQ(oldText, staticRange04->endContainer());
    EXPECT_EQ(4, staticRange04->endOffset());

    EXPECT_EQ(oldText, staticRange02->startContainer());
    EXPECT_EQ(0, staticRange02->startOffset());
    EXPECT_EQ(oldText, staticRange02->endContainer());
    EXPECT_EQ(2, staticRange02->endOffset());

    EXPECT_EQ(oldText, staticRange22->startContainer());
    EXPECT_EQ(2, staticRange22->startOffset());
    EXPECT_EQ(oldText, staticRange22->endContainer());
    EXPECT_EQ(2, staticRange22->endOffset());

    EXPECT_EQ(oldText, staticRange24->startContainer());
    EXPECT_EQ(2, staticRange24->startOffset());
    EXPECT_EQ(oldText, staticRange24->endContainer());
    EXPECT_EQ(4, staticRange24->endOffset());
}
开发者ID:endlessm,项目名称:chromium-browser,代码行数:65,代码来源:StaticRangeTest.cpp

示例2: ShiftItemSelection

TextSelection ShiftItemSelection(
		TextSelection selection,
		const Text &byText) {
	return ShiftItemSelection(selection, byText.length());
}
开发者ID:Emadpres,项目名称:tdesktop,代码行数:5,代码来源:history_view_element.cpp

示例3: Size

bool UIListViewTest_Vertical::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        _displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
                                              widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
        _uiLayer->addChild(_displayValueLabel);
        
        
        Text* alert = Text::create("ListView vertical", "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                 widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);
        
        Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
        
        Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
        Size backgroundSize = background->getContentSize();
        
        
        // create list view ex data
       
        for (int i = 0; i < 20; ++i)
        {
            std::string ccstr = StringUtils::format("listview_item_%d", i);
            _array.push_back(ccstr);
        }
        
        
        // Create the list view ex
        ListView* listView = ListView::create();
        // set list view ex direction
        listView->setDirection(ui::ScrollView::Direction::VERTICAL);
        listView->setBounceEnabled(true);
        listView->setBackGroundImage("cocosui/green_edit.png");
        listView->setBackGroundImageScale9Enabled(true);
        listView->setContentSize(Size(240, 130));
		listView->setPosition(Vec2((widgetSize - listView->getContentSize()) / 2.0f));
        listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEvent, this));
        listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEventScrollView,this));
		listView->setScrollBarPositionFromCorner(Vec2(7, 7));
        _uiLayer->addChild(listView);
        
        
        // create model
        Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
        default_button->setName("Title Button");
        
        Layout* default_item = Layout::create();
        default_item->setTouchEnabled(true);
        default_item->setContentSize(default_button->getContentSize());
		default_button->setPosition(Vec2(default_item->getContentSize() / 2.0f));
        default_item->addChild(default_button);
        
        // set model
        listView->setItemModel(default_item);
        
        // add default item
        ssize_t count = _array.size();
        for (int i = 0; i < count / 4; ++i)
        {
            listView->pushBackDefaultItem();
        }
        // insert default item
        for (int i = 0; i < count / 4; ++i)
        {
            listView->insertDefaultItem(0);
        }
        
        listView->removeAllChildren();
        
        Sprite* testSprite = Sprite::create("cocosui/backtotoppressed.png");
        testSprite->setPosition(Vec2(200,200));
        listView->addChild(testSprite);
        
        // add custom item
        for (int i = 0; i < count / 4; ++i)
        {
            Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
            custom_button->setName("Title Button");
            custom_button->setScale9Enabled(true);
            custom_button->setContentSize(default_button->getContentSize());
            
            Layout *custom_item = Layout::create();
            custom_item->setContentSize(custom_button->getContentSize());
            custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
            custom_item->addChild(custom_button);
            
            listView->addChild(custom_item);
        }
        // insert custom item
        Vector<Widget*>& items = listView->getItems();
        ssize_t items_count = items.size();
        for (int i = 0; i < count / 4; ++i)
        {
//.........这里部分代码省略.........
开发者ID:kaiqinetwork,项目名称:cocos2d-x,代码行数:101,代码来源:UIListViewTest.cpp

示例4: _

Game::menu_t Game::ScenarioInfo(void)
{
    Settings & conf = Settings::Get();

    AGG::PlayMusic(MUS::MAINMENU);

    MapsFileInfoList lists;
    if(!PrepareMapsFileInfoList(lists, (conf.GameType(Game::TYPE_MULTI))))
    {
	Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK);
        return MAINMENU;
    }

    menu_t result = QUITGAME;
    LocalEvent & le = LocalEvent::Get();

    // cursor
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    Display & display = Display::Get();

    Point top, pointDifficultyInfo, pointOpponentInfo, pointClassInfo;
    Rect rectPanel;
    Button* buttonSelectMaps = NULL;
    Button* buttonOk = NULL;
    Button* buttonCancel = NULL;

    // vector coord difficulty
    Rects coordDifficulty;
    coordDifficulty.reserve(5);

    const Sprite & ngextra = AGG::GetICN(ICN::NGEXTRA, 62);
    Dialog::FrameBorder* frameborder = NULL;

    // image background
    if(conf.QVGA())
    {
	frameborder = new Dialog::FrameBorder(Size(380, 224));
	rectPanel = frameborder->GetArea();

	pointDifficultyInfo = Point(rectPanel.x + 4, rectPanel.y + 24);
	pointOpponentInfo = Point(rectPanel.x + 4, rectPanel.y + 94);
	pointClassInfo = Point(rectPanel.x + 4, rectPanel.y + 148);

	coordDifficulty.push_back(Rect(rectPanel.x + 1, rectPanel.y + 21,   ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 78, rectPanel.y + 21,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 154, rectPanel.y + 21, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 231, rectPanel.y + 21, ngextra.w(), ngextra.h()));
        coordDifficulty.push_back(Rect(rectPanel.x + 308, rectPanel.y + 21, ngextra.w(), ngextra.h()));

	buttonOk = new Button(rectPanel.x + rectPanel.w / 2 - 160, rectPanel.y + rectPanel.h - 30, ICN::NGEXTRA, 66, 67);
	buttonCancel = new Button(rectPanel.x + rectPanel.w / 2 + 60, rectPanel.y + rectPanel.h - 30, ICN::NGEXTRA, 68, 69);

	Text text;
	text.Set(conf.CurrentFileInfo().name, Font::BIG);
	text.Blit(rectPanel.x + (rectPanel.w - text.w()) / 2, rectPanel.y + 5);
    }
    else
    {
	const Sprite &panel = AGG::GetICN(ICN::NGHSBKG, 0);
	const Sprite &back = AGG::GetICN(ICN::HEROES, 0);
	const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2);

	rectPanel = Rect(top.x + 204, top.y + 32, panel.w(), panel.h());
	pointDifficultyInfo = Point(rectPanel.x + 24, rectPanel.y + 93);
	pointOpponentInfo = Point(rectPanel.x + 24, rectPanel.y + 202);
	pointClassInfo = Point(rectPanel.x + 24, rectPanel.y + 282);

	coordDifficulty.push_back(Rect(rectPanel.x + 21, rectPanel.y + 91,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 98, rectPanel.y + 91,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 174, rectPanel.y + 91, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 251, rectPanel.y + 91, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 328, rectPanel.y + 91, ngextra.w(), ngextra.h()));

	buttonSelectMaps = new Button(rectPanel.x + 309, rectPanel.y + 45, ICN::NGEXTRA, 64, 65);
	buttonOk = new Button(rectPanel.x + 31, rectPanel.y + 380, ICN::NGEXTRA, 66, 67);
	buttonCancel = new Button(rectPanel.x + 287, rectPanel.y + 380, ICN::NGEXTRA, 68, 69);

	back.Blit(top);
    }

    const bool reset_starting_settings = conf.MapsFile().empty() || ! System::IsFile(conf.MapsFile());
    Players & players = conf.GetPlayers();
    Interface::PlayersInfo playersInfo(true, !conf.QVGA(), !conf.QVGA());

    // set first maps settings
    if(reset_starting_settings)
	conf.SetCurrentFileInfo(lists.front());

    playersInfo.UpdateInfo(players, pointOpponentInfo, pointClassInfo);

    RedrawScenarioStaticInfo(rectPanel);
    RedrawDifficultyInfo(pointDifficultyInfo, !conf.QVGA());

    playersInfo.RedrawInfo();

    TextSprite* rating = conf.QVGA() ? NULL : new TextSprite();
    if(rating)
//.........这里部分代码省略.........
开发者ID:mastermind-,项目名称:free-heroes,代码行数:101,代码来源:game_scenarioinfo.cpp

示例5: Panel

DlgEventKeyDown::DlgEventKeyDown(Actor *actor, bool bUp)
	: Panel("EventKeyDown", (GameControl::Get()->Width() - ((bUp || !Tutorial::IsCompatible(VERSION_GET_ANIMINDEX))?WIDTH:WIDTH_KEY_DOWN))/2, 
				          (GameControl::Get()->Height() - ((bUp || !Tutorial::IsCompatible(VERSION_GET_ANIMINDEX))?HEIGHT:HEIGHT_KEY_DOWN))/2,
						  ((bUp || !Tutorial::IsCompatible(VERSION_GET_ANIMINDEX))?WIDTH:WIDTH_KEY_DOWN), 
						  ((bUp || !Tutorial::IsCompatible(VERSION_GET_ANIMINDEX))?HEIGHT:HEIGHT_KEY_DOWN))
{
	SetModal();
	eventActor = actor;
	this->bUp = bUp;
	mode = SDLK_UNKNOWN;

	Text *text;
	Button *button;	
	Actor *add;
	int y;
	listMode = listRepeat = NULL;
	textPanel = NULL;

	//Title
	text = AddText(bUp?"Key Up Event":"Key Down Event", CENTER_TEXT, 5);
	y = DrawHLine(text->Down() + 2);
	

	if(bUp || !Tutorial::IsCompatible(VERSION_GET_ANIMINDEX))
	{
		//Body
		text = AddText("Press event key or\nright click for 'any' key: ", 10, y);	
		textKey = AddText("              ", 170, text->Down() - 13);
		
		y = textKey->Down() + 5;
		if(!bUp)
		{
			SetToolTip(TIP_DLG_KEYDOWN);
			
			text = AddText("Repeat: ", 10, y+2);
			listRepeat = AddListPop(text->Right(), text->Top(), 128); listRepeat->SetToolTip(TIP_DLG_KEYDOWN_REPEAT);			
			y = listRepeat->Down();
		}
		else
		{
			SetToolTip(TIP_DLG_KEYUP);
			y += 20;
		}
	}
	else
	{
		//New Key Down intreface
		SetToolTip(TIP_DLG_KEYDOWN);

		text =    AddText("Press the key or key sequence (right click for 'any' key)", 10, y);	
		text =    AddText("Keys: ", 10, text->Down() + 4);	

		textKey = AddText("                                                          \n                                                          "
			, text->Right(), text->Top() + 2);

		textPanel = new Panel("textKeyPanel", textKey->Left() - 5, textKey->Top() - 2, textKey->Width() + 5, textKey->Height() + 4,
				  this, true, false, true, false);

		//Transparent background
		KrRGBA *pixels = textPanel->getCanvasResource()->Pixels();	
		if(pixels)
		{
			KrRGBA colorBack;
			colorBack.c.alpha = 0;
			
			for(int i = 2; i < textKey->Width() + 3; i++)
			{
				for(int j = 2; j < textKey->Height() + 2; j++)
				{
					pixels[ j*textPanel->Width() + i ] = colorBack;
				}
			}
		}

		GetFocus(this);

		textKey->getImage()->SetZDepth(textPanel->getImage()->ZDepth() + 1000);

		button = AddButton("Clear", textPanel->Right() - 45, textPanel->Down() + 3, 45, 0, BT_CLEAR); button->SetToolTip(TIP_DLG_KEYDOWN_CLEAR);			

		y = DrawHLine(button->Down() + 3);		
		
		text = AddText("Execute when: ", 10, y+2);
		listMode = AddListPop(text->Right(), text->Top(), 230); listMode->SetToolTip(TIP_DLG_KEYDOWN_MODE);			

		text = AddText("      Repeat: ", 10, listMode->Down() + 2);
		listRepeat = AddListPop(text->Right(), text->Top(), 128); listRepeat->SetToolTip(TIP_DLG_KEYDOWN_REPEAT);

		listMode->AddText("At least one key is pressed");
		listMode->AddText("All keys are pressed");
		listMode->AddText("Keys are pressed in order");
		listMode->SetItem("At least one key is pressed");
		
		y = listRepeat->Down();
	}
	
	//Close
	y = DrawHLine(y + 5);
	if(Action::inNewActivationEvent())
	{
//.........这里部分代码省略.........
开发者ID:cubemoon,项目名称:game-editor,代码行数:101,代码来源:EventKeyDown.cpp

示例6: endingSelection

void InsertParagraphSeparatorCommand::doApply()
{
    bool splitText = false;
    if (endingSelection().isNone())
        return;
    
    Position insertionPosition = endingSelection().start();
        
    EAffinity affinity = endingSelection().affinity();
        
    // Delete the current selection.
    if (endingSelection().isRange()) {
        calculateStyleBeforeInsertion(insertionPosition);
        deleteSelection(false, true);
        insertionPosition = endingSelection().start();
        affinity = endingSelection().affinity();
    }
    
    // FIXME: The rangeCompliantEquivalent conversion needs to be moved into enclosingBlock.
    Node* startBlockNode = enclosingBlock(rangeCompliantEquivalent(insertionPosition).node());
    Position canonicalPos = VisiblePosition(insertionPosition).deepEquivalent();
    Element* startBlock = static_cast<Element*>(startBlockNode);
    if (!startBlockNode
            || !startBlockNode->isElementNode()
            || !startBlock->parentNode()
            || isTableCell(startBlock)
            || startBlock->hasTagName(formTag)
            || (canonicalPos.node()->renderer() && canonicalPos.node()->renderer()->isTable())
            || canonicalPos.node()->hasTagName(hrTag)) {
        applyCommandToComposite(InsertLineBreakCommand::create(document()));
        return;
    }
    
    // Use the leftmost candidate.
    insertionPosition = insertionPosition.upstream();
    if (!insertionPosition.isCandidate())
        insertionPosition = insertionPosition.downstream();

    // Adjust the insertion position after the delete
    insertionPosition = positionAvoidingSpecialElementBoundary(insertionPosition);
    VisiblePosition visiblePos(insertionPosition, affinity);
    calculateStyleBeforeInsertion(insertionPosition);

    //---------------------------------------------------------------------
    // Handle special case of typing return on an empty list item
    if (breakOutOfEmptyListItem())
        return;

    //---------------------------------------------------------------------
    // Prepare for more general cases.

    bool isFirstInBlock = isStartOfBlock(visiblePos);
    bool isLastInBlock = isEndOfBlock(visiblePos);
    bool nestNewBlock = false;

    // Create block to be inserted.
    RefPtr<Element> blockToInsert;
    if (startBlock == startBlock->rootEditableElement()) {
        blockToInsert = createDefaultParagraphElement(document());
        nestNewBlock = true;
    } else if (shouldUseDefaultParagraphElement(startBlock)) 
        blockToInsert = createDefaultParagraphElement(document());
    else
        blockToInsert = startBlock->cloneElementWithoutChildren();

    //---------------------------------------------------------------------
    // Handle case when position is in the last visible position in its block,
    // including when the block is empty. 
    if (isLastInBlock) {
        bool shouldApplyStyleAfterInsertion = true;
        if (nestNewBlock) {
            if (isFirstInBlock && !lineBreakExistsAtVisiblePosition(visiblePos)) {
                // The block is empty.  Create an empty block to
                // represent the paragraph that we're leaving.
                RefPtr<Element> extraBlock = createDefaultParagraphElement(document());
                appendNode(extraBlock, startBlock);
                appendBlockPlaceholder(extraBlock);
            }
            appendNode(blockToInsert, startBlock);
        } else {
            // We can get here if we pasted a copied portion of a blockquote with a newline at the end and are trying to paste it
            // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted.
            if (Node* highestBlockquote = highestEnclosingNodeOfType(canonicalPos, &isMailBlockquote)) {
                startBlock = static_cast<Element*>(highestBlockquote);
                // When inserting the newline after the blockquote, we don't want to apply the original style after the insertion
                shouldApplyStyleAfterInsertion = false;
            }
            insertNodeAfter(blockToInsert, startBlock);
        }

        appendBlockPlaceholder(blockToInsert);
        setEndingSelection(VisibleSelection(Position(blockToInsert.get(), 0), DOWNSTREAM));
        if (shouldApplyStyleAfterInsertion)
            applyStyleAfterInsertion(startBlock);
        return;
    }

    //---------------------------------------------------------------------
    // Handle case when position is in the first visible position in its block, and
    // similar case where previous position is in another, presumeably nested, block.
//.........这里部分代码省略.........
开发者ID:boyliang,项目名称:ComponentSuperAccessor,代码行数:101,代码来源:InsertParagraphSeparatorCommand.cpp

示例7: init

bool UIImageViewTest_ContentSize::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        Text* alert = Text::create("ImageView ContentSize Change", "fonts/Marker Felt.ttf", 26);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
        
        _uiLayer->addChild(alert);
        
        Text *status = Text::create("child ImageView position percent", "fonts/Marker Felt.ttf", 16);
        status->setColor(Color3B::RED);
        status->setPosition(Vec2(widgetSize.width/2, widgetSize.height/2 + 80));
        _uiLayer->addChild(status,20);
        
        // Create the imageview
        ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
        imageView->setScale9Enabled(true);
        imageView->setContentSize(Size(200, 80));
        imageView->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f ));
       
        
        ImageView* imageViewChild = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild->setScale9Enabled(true);
        imageViewChild->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f));
        
        ImageView* imageViewChild2 = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild2->setScale9Enabled(true);
        imageViewChild2->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild2->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild2->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild2->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->addChild(imageViewChild2);
        
        
        imageView->addChild(imageViewChild);
        
        imageView->setTouchEnabled(true);
        imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
            if (type == Widget::TouchEventType::ENDED) {
                float width = CCRANDOM_0_1() * 200 + 50;
                float height = CCRANDOM_0_1() * 80 + 30;
                imageView->setContentSize(Size(width, height));
                
                imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()));
                status->setString(StringUtils::format("child ImageView position percent: %f, %f",
                                                      imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y));
            }
        });
        
        _uiLayer->addChild(imageView);
        
        return true;
    }
    return false;
}
开发者ID:jafffy,项目名称:cocos2d-x,代码行数:65,代码来源:UIImageViewTest.cpp

示例8: RemoveAllChildren

void Text::RefreshSizeWrap()
{
    RemoveAllChildren();
    m_Lines.clear();

    stl::vector<Gwen::String> words;
    SplitWords( GetText().Get(), ' ', words );

    // Adding a bullshit word to the end simplifies the code below
    // which is anything but simple.
    words.push_back( "" );

    if ( !GetFont() )
    {
        Debug::AssertCheck( 0, "Text::RefreshSize() - No Font!!\n" );
        return;
    }

    Point pFontSize = GetSkin()->GetRender()->MeasureText( GetFont(), " " );

    int w = GetParent()->Width();
    int x = 0, y = 0;

    Gwen::String strLine;

    stl::vector<Gwen::String>::iterator it = words.begin();
    for (; it != words.end(); ++it )
    {
        bool bFinishLine = false;
        //bool bWrapped = false;

        // If this word is a newline - make a newline (we still add it to the text)
        if ( (*it).c_str()[0] == '\n' ) bFinishLine = true;

        // Does adding this word drive us over the width?
        {
            strLine += (*it);
            Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), strLine );
            if ( p.x > Width() ) {
                bFinishLine = true; /*bWrapped = true;*/
            }
        }

        // If this is the last word then finish the line
        // if ( --words.end() == it )
        // NOTE: replaced above commented out 'if' statement with this to appease
        //       the GCC compiler that comes with Marmalade SDK 6.0
        stl::vector<Gwen::String>::iterator temp = words.end() - 1;
        if ( temp == it )
        {
            bFinishLine = true;
        }

        if ( bFinishLine )
        {
            Text* t = new Text( this );
            t->SetFont( GetFont() );
            t->SetString( strLine.substr( 0, strLine.length() - (*it).length() ) );
            t->RefreshSize();
            t->SetPos( x, y );
            m_Lines.push_back( t );

            // newline should start with the word that was too big
            strLine = *it;

            // Position the newline
            y += pFontSize.y;
            x = 0;

            //if ( strLine[0] == ' ' ) x -= pFontSize.x;
        }

    }

    // Size to children height and parent width
    {
        Point childsize = ChildrenSize();
        SetSize( w, childsize.y );
    }

    InvalidateParent();
    Invalidate();
}
开发者ID:gered,项目名称:MyGameFramework,代码行数:83,代码来源:gwen_text.cpp

示例9: OptionsBaseState

/**
 * Initializes all the elements in the Mod Options window.
 * @param game Pointer to the core game.
 * @param origin Game section that originated this state.
 */
OptionsModsState::OptionsModsState(OptionsOrigin origin) : OptionsBaseState(origin)
{
	setCategory(_btnMods);

	// Create objects
	_txtMaster = new Text(114, 9, 94, 8);
	_cbxMasters = new ComboBox(this, 218, 16, 94, 18);
	_lstMods = new TextList(200, 104, 94, 40);

	add(_txtMaster, "text", "modsMenu");
	add(_lstMods, "optionLists", "modsMenu");
	add(_cbxMasters, "button", "modsMenu");

	centerAllSurfaces();

	// how much room do we need for YES/NO
	Text text = Text(100, 9, 0, 0);
	text.initText(_game->getResourcePack()->getFont("FONT_BIG"), _game->getResourcePack()->getFont("FONT_SMALL"), _game->getLanguage());
	text.setText(tr("STR_YES"));
	int yes = text.getTextWidth();
	text.setText(tr("STR_NO"));
	int no = text.getTextWidth();

	int rightcol = std::max(yes, no) + 2;
	int arrowCol = 25;
	int leftcol = _lstMods->getWidth() - (rightcol + arrowCol);

	// Set up objects
	_txtMaster->setText(tr("STR_GAME_TYPE"));

	// scan for masters
	const std::map<std::string, ModInfo> &modInfos(Options::getModInfos());
	size_t curMasterIdx = 0;
	std::vector<std::wstring> masterNames;
	for (std::vector< std::pair<std::string, bool> >::const_iterator i = Options::mods.begin(); i != Options::mods.end(); ++i)
	{
		std::string modId = i->first;
		ModInfo modInfo = modInfos.find(modId)->second;
		if (!modInfo.isMaster())
		{
			continue;
		}

		if (i->second)
		{
			_curMasterId = modId;
		}
		else if (_curMasterId.empty())
		{
			++curMasterIdx;
		}
		_masters.push_back(&modInfos.at(modId));
		masterNames.push_back(Language::utf8ToWstr(modInfo.getName()));
	}

	_cbxMasters->setOptions(masterNames);
	_cbxMasters->setSelected(curMasterIdx);
	_cbxMasters->onChange((ActionHandler)&OptionsModsState::cbxMasterChange);
	_cbxMasters->onMouseIn((ActionHandler)&OptionsModsState::txtTooltipIn);
	_cbxMasters->onMouseOut((ActionHandler)&OptionsModsState::txtTooltipOut);
	_cbxMasters->onMouseOver((ActionHandler)&OptionsModsState::cbxMasterHover);
	_cbxMasters->onListMouseIn((ActionHandler)&OptionsModsState::txtTooltipIn);
	_cbxMasters->onListMouseOut((ActionHandler)&OptionsModsState::txtTooltipOut);
	_cbxMasters->onListMouseOver((ActionHandler)&OptionsModsState::cbxMasterHover);

	_lstMods->setArrowColumn(leftcol + 1, ARROW_VERTICAL);
	_lstMods->setColumns(3, leftcol, arrowCol, rightcol);
	_lstMods->setAlign(ALIGN_RIGHT, 1);
	_lstMods->setSelectable(true);
	_lstMods->setBackground(_window);
	_lstMods->setWordWrap(true);
	_lstMods->onMouseClick((ActionHandler)&OptionsModsState::lstModsClick);
	_lstMods->onLeftArrowClick((ActionHandler)&OptionsModsState::lstModsLeftArrowClick);
	_lstMods->onRightArrowClick((ActionHandler)&OptionsModsState::lstModsRightArrowClick);
	_lstMods->onMousePress((ActionHandler)&OptionsModsState::lstModsMousePress);
	_lstMods->onMouseIn((ActionHandler)&OptionsModsState::txtTooltipIn);
	_lstMods->onMouseOut((ActionHandler)&OptionsModsState::txtTooltipOut);
	_lstMods->onMouseOver((ActionHandler)&OptionsModsState::lstModsHover);
	lstModsRefresh(0);
}
开发者ID:a-detiste,项目名称:OpenXcom,代码行数:85,代码来源:OptionsModsState.cpp

示例10: BREAK_IF

bool CMainUIFight::onInit()
{
	do 
	{
		BREAK_IF(!GameUIWithOutSideTouchEvent::onInit());
		//左上 左下 右上 右下 四个面板
		m_panelLT = (Layout*)Helper::seekWidgetByName(m_pWidget,"LeftTop");
		m_panelRT = (Layout*)Helper::seekWidgetByName(m_pWidget,"RightTop");
		m_panelLB = (Layout*)Helper::seekWidgetByName(m_pWidget,"LeftBottom");
		m_panelRB = (Layout*)Helper::seekWidgetByName(m_pWidget,"RightBottom");
		BREAK_IF( !(m_panelLT&&m_panelLB&&m_panelRT&&m_panelRB) );

		//修正上下左右panel位置
		//float fRatio = gDirector->getVisibleSize().height / gDirector->getVisibleSize().width;
		//float fNewHeight = fRatio * UI_ORIG_SIZE.width;
		//if (fNewHeight > UI_ORIG_SIZE.height)
		//{
		//	float fOffsetY = (fNewHeight -UI_ORIG_SIZE.height) / 2;
		//	m_panelLT->setPositionY(m_panelLT->getPositionY() + fOffsetY);
		//	m_panelRT->setPositionY(m_panelRT->getPositionY() + fOffsetY);
		//	m_panelLB->setPositionY(m_panelLB->getPositionY() - fOffsetY);
		//	m_panelRB->setPositionY(m_panelRB->getPositionY() - fOffsetY);
		//}
		m_buffListView = (ListView*)Helper::seekWidgetByName(m_pWidget,"buffListView");
		BREAK_IF( !m_buffListView );
		//m_buffListView->setItemsMargin(0.1);

		//玩家头像
		m_HeadIcon = (ImageView*)Helper::seekWidgetByName(m_pWidget,"HeadBtn");
		m_HeroLv = (Text*)Helper::seekWidgetByName(m_pWidget,"Lv");
		m_HeroHp = (Text*)Helper::seekWidgetByName(m_pWidget,"HpValue");
		m_HeroMp = (Text*)Helper::seekWidgetByName(m_pWidget,"MpValue");
		m_HeroHpBar = (Layout*)Helper::seekWidgetByName(m_pWidget,"HpBarFrame");
		m_HeroMpBar = (Layout*)Helper::seekWidgetByName(m_pWidget,"MpBarFrame");
		m_HeroHpSlot = (ImageView*)Helper::seekWidgetByName(m_pWidget,"Img_hp");
		m_HeroMpSlot = (ImageView*)Helper::seekWidgetByName(m_pWidget,"Img_mp");
		m_HeroName = (Text*)Helper::seekWidgetByName(m_pWidget,"Name");
		BREAK_IF( !(m_HeroLv&&m_HeroHp&&m_HeroMp&&m_HeroHpBar&&m_HeroMpBar&&m_HeroHpSlot&&m_HeroMpSlot&&m_HeadIcon&&m_HeroName));
		m_HeroHpBar->setClippingEnabled(true);
		m_HeroMpBar->setClippingEnabled(true);
		m_HeadIcon->addTouchEventListener(this,toucheventselector(CMainUIFight::clickHead));

		CheckBox*	pCheckBox = (CheckBox*)(Helper::seekWidgetByName(m_pWidget,"PlayMode"));
		Text*	pMyScore = (Text*)(Helper::seekWidgetByName(m_pWidget,"Label_43"));
		Text*	pEnemyScore = (Text*)(Helper::seekWidgetByName(m_pWidget,"Label_43_0"));
		pCheckBox->setEnabled(false);
		pMyScore->setEnabled(false);
		pEnemyScore->setEnabled(false);

		//摇杆
		m_JoyStick = (ImageView*)Helper::seekWidgetByName(m_pWidget,"JoyStick");
		BREAK_IF( !m_JoyStick );
		m_JoyStick->setTouchEnabled(true);
		m_JoyStick->addTouchEventListener(this,toucheventselector(CMainUIFight::ClickJoyStick));

		//技能栏
		InitSkillBtns();

		//队伍
		for (int i=0; i<Team_Max_Num; ++i)
		{
			m_TeamHead[i].ui = Helper::seekWidgetByName(m_pWidget,CCString::createWithFormat("Team_%d",i)->getCString());
			m_TeamHead[i].ui->setEnabled(false);
			m_TeamHead[i].icon = (ImageView*)Helper::seekWidgetByName(m_pWidget,CCString::createWithFormat("TeamIcon_%d",i)->getCString());
			m_TeamHead[i].Txtleave = (Text*)Helper::seekWidgetByName(m_pWidget,CCString::createWithFormat("Leave_%d",i)->getCString());
			m_TeamHead[i].progress = ProgressTimer::create(Sprite::create(team_head_cd_path));
			BREAK_IF( !(m_TeamHead[i].ui&&m_TeamHead[i].icon&&m_TeamHead[i].progress&&m_TeamHead[i].Txtleave) );
			m_TeamHead[i].ui->addChild(m_TeamHead[i].progress);
			m_TeamHead[i].Txtleave->setLocalZOrder(100);
			m_TeamHead[i].Txtleave->setEnabled(false);
			Size size = m_TeamHead[i].ui->getContentSize();
			m_TeamHead[i].progress->setPosition(Point(size.width/2,size.height/2));
			m_TeamHead[i].progress->setReverseDirection(true);
		}

		//聊天
		m_pChatUI = (Layout*)Helper::seekWidgetByName(m_pWidget,"ChatLayout");
		m_pButtonChat =  (Button*)Helper::seekWidgetByName(m_pWidget,"ChatBtn");
		m_pButtonChat->addTouchEventListener(this,toucheventselector(CMainUIFight::clickChat));

		m_pMsgWind = CScrollMsgForMainUI::create();
		m_pMsgWind->setSize(m_pChatUI->getSize()); 	/*msgWind size 为300*i时,排版合适*/
		m_pMsgWind->setTouchEnabled(false);
		m_pMsgWind->setOpacity(0);
		m_pMsgWind->SetMaxMsgNum(1);
		ChatMainUI *pChatUI = (ChatMainUI*)gGameUILayer->getUI(IDU_CHATMAINUI);
		if (pChatUI)
		{
			m_pMsgWind->SetTouchNameListenner(gGameUILayer->getUI(IDU_CHATMAINUI), (SEL_TouchNameLinkEvent)&ChatMainUI::clickNameLink4MainUI);
			m_pMsgWind->SetTouchItemListenner(gGameUILayer->getUI(IDU_CHATMAINUI), (SEL_TouchItemLinkEvent)&ChatMainUI::clickItemLink4MainUI);
		}
		m_pChatUI->addChild(m_pMsgWind);
		m_pChatUI->setVisible(false);

		//右上 副本
		m_pPvPSmallMap =  Helper::seekWidgetByName(m_panelRT,"PVP_Map");
		BREAK_IF(!(m_pPvPSmallMap));
		m_pPvPSmallMap->setEnabled(false);
		return true;
	} while (0);
//.........这里部分代码省略.........
开发者ID:SmallRaindrop,项目名称:LocatorApp,代码行数:101,代码来源:MainUIFight.cpp

示例11: GameStart

void GameStart() {
	RenderWindow window(VideoMode(MapWidth * SpriteSize, MapHeight * SpriteSize), "Snake");
	Clock clock;
	Game* game;
	NewGame(game);
	Text text = game->game_text->text;

	while (window.isOpen()) //разбить на 3 метода
	{
		float time = clock.getElapsedTime().asSeconds();
		clock.restart();
		game->consts->time_counter += time;

		ProcessEvents(window, game);

		if (game->state == STARTGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Snake!\n\nPress 'U' to start!");
			text.setPosition(250, 50);
			window.draw(text);
		}
		else if (game->state == RESTART) {
			DestroyGame(game);
			NewGame(game);
			text = game->game_text->text;
			game->state = PLAY;
		}
		else if (game->state == PAUSE) {
			window.clear();
			Render(window, game);
			text.setCharacterSize(150);
			text.setString("Pause");
			text.setPosition(455, 160);
			window.draw(text);
		}
		else if (game->state == PLAY) {
			while (game->consts->time_counter > game->consts->speed) {
				game->consts->time_counter = 0;

				//Snake movement

				Step(game->snake);

				int snake_draw_counter = SnakeLength(game->snake);

				ProcessCollisions(snake_draw_counter, game);
			}
			Render(window, game);
		}
		else if (game->state == ENDGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Score: " + ToString(game->consts->score) + "\n Press 'Esc' to exit\n Press 'R' to restart");
			text.setPosition(170, 28);
			window.draw(text);
		}

		window.display();
	}
	DestroyGame(game);
}
开发者ID:Dzzirt,项目名称:TP,代码行数:62,代码来源:game_engine.cpp

示例12: init

bool UIScrollViewDisableTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();

        // Add a label in which the scrollview alert will be displayed
        _displayValueLabel = Text::create("ScrollView Disable Test", "fonts/Marker Felt.ttf", 32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
                                              widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
        _uiLayer->addChild(_displayValueLabel);

        // Add the alert
        Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);

        Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));

        Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));

        // Create the scrollview by vertical
        ui::ScrollView* scrollView = ui::ScrollView::create();
        scrollView->setContentSize(Size(280.0f, 100.0f));
        Size backgroundSize = background->getContentSize();
        scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                               (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
                               (widgetSize.height - backgroundSize.height) / 2.0f +
                               (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
        scrollView->setScrollBarWidth(4);
        scrollView->setTouchEnabled(false);
        scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
        scrollView->setScrollBarColor(Color3B::WHITE);
        _uiLayer->addChild(scrollView);

        ImageView* imageView = ImageView::create("cocosui/ccicon.png");

        float innerWidth = scrollView->getContentSize().width;
        float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;

        scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));

        Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
        button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
        scrollView->addChild(button);

        Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
        scrollView->addChild(titleButton);

        Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
        button_scale9->setScale9Enabled(true);
        button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
        button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
        scrollView->addChild(button_scale9);

        imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
        scrollView->addChild(imageView);


        return true;
    }

    return false;
}
开发者ID:zengzhining,项目名称:cocos2d-x,代码行数:68,代码来源:UIScrollViewTest.cpp

示例13: strcpy_s

bool
NetGameClient::DoJoinBacklog(NetJoinAnnounce* join_ann)
{
	bool finished = false;

	if (!join_ann)
	return finished;

	Sim* sim = Sim::GetSim();
	if (!sim)
	return finished;

	DWORD nid       = join_ann->GetNetID();
	DWORD oid       = join_ann->GetObjID();
	Text  name      = join_ann->GetName();
	Text  elem_name = join_ann->GetElement();
	Text  region    = join_ann->GetRegion();
	Point loc       = join_ann->GetLocation();
	Point velocity  = join_ann->GetVelocity();
	int   index     = join_ann->GetIndex();
	int   shld_lvl  = join_ann->GetShield();
	Ship* ship      = 0;
	char  ship_name[128];

	strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data());

	if (nid && oid) {
		NetPlayer* remote_player = FindPlayerByObjID(oid);
		if (remote_player) {
			remote_player->SetName(name);
			remote_player->SetObjID(oid);

			if (index > 0)
			sprintf_s(ship_name, "%s %d", elem_name.data(), index);
			else
			sprintf_s(ship_name, "%s", elem_name.data());
		}
		else {
			Element* element = sim->FindElement(elem_name);

			if (element) {
				ship = element->GetShip(index);
			}

			if (ship) {
				strcpy_s(ship_name, ship->Name());

				SimRegion* rgn = ship->GetRegion();
				if (rgn && region != rgn->Name()) {
					SimRegion* dst = sim->FindRegion(region);
					if (dst) dst->InsertObject(ship);
				}

				ship->MoveTo(loc);
				ship->SetVelocity(velocity);

				Shield* shield = ship->GetShield();
				if (shield)
				shield->SetNetShieldLevel(shld_lvl);

				NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid);
				remote_player->SetName(name);
				remote_player->SetObjID(oid);
				remote_player->SetShip(ship);

				players.append(remote_player);
				finished = true;

				if (name == "Server A.I. Ship") {
					Print("NetGameClient::DoJoinBacklog() Remote Player '%s' has joined as '%s' with ID %d\n", name.data(), ship_name, oid);
				}
				else {
					HUDView::Message(Game::GetText("NetGameClient.remote-join").data(), name.data(), ship_name);
				}
			}
		}
	}

	return finished;
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:80,代码来源:NetGameClient.cpp

示例14: copySelectionHelper

void copySelectionHelper(Buffer const & buf, Text const & text,
	pit_type startpit, pit_type endpit,
	int start, int end, DocumentClassConstPtr dc, CutStack & cutstack)
{
	ParagraphList const & pars = text.paragraphs();

	// In most of these cases, we can try to recover.
	LASSERT(0 <= start, start = 0);
	LASSERT(start <= pars[startpit].size(), start = pars[startpit].size());
	LASSERT(0 <= end, end = 0);
	LASSERT(end <= pars[endpit].size(), end = pars[endpit].size());
	LASSERT(startpit != endpit || start <= end, return);

	// Clone the paragraphs within the selection.
	ParagraphList copy_pars(boost::next(pars.begin(), startpit),
				boost::next(pars.begin(), endpit + 1));

	// Remove the end of the last paragraph; afterwards, remove the
	// beginning of the first paragraph. Keep this order - there may only
	// be one paragraph!  Do not track deletions here; this is an internal
	// action not visible to the user

	Paragraph & back = copy_pars.back();
	back.eraseChars(end, back.size(), false);
	Paragraph & front = copy_pars.front();
	front.eraseChars(0, start, false);

	ParagraphList::iterator it = copy_pars.begin();
	ParagraphList::iterator it_end = copy_pars.end();

	for (; it != it_end; ++it) {
		// Since we have a copy of the paragraphs, the insets
		// do not have a proper buffer reference. It makes
		// sense to add them temporarily, because the
		// operations below depend on that (acceptChanges included).
		it->setBuffer(const_cast<Buffer &>(buf));
		// PassThru paragraphs have the Language
		// latex_language. This is invalid for others, so we
		// need to change it to the buffer language.
		if (it->isPassThru())
			it->changeLanguage(buf.params(), 
					   latex_language, buf.language());
	}

	// do not copy text (also nested in insets) which is marked as
	// deleted, unless the whole selection was deleted
	if (!isFullyDeleted(copy_pars))
		acceptChanges(copy_pars, buf.params());
	else
		rejectChanges(copy_pars, buf.params());


	// do some final cleanup now, to make sure that the paragraphs
	// are not linked to something else.
	it = copy_pars.begin();
	for (; it != it_end; ++it) {
		it->setBuffer(*static_cast<Buffer *>(0));
		it->setInsetOwner(0);
	}

	cutstack.push(make_pair(copy_pars, dc));
}
开发者ID:mandeepsimak,项目名称:Lyx,代码行数:62,代码来源:CutAndPaste.cpp

示例15: new

void
NetGameClient::DoElemCreate(NetMsg* msg)
{
	if (!msg) return;

	NetElemCreate elem_create;
	elem_create.Unpack(msg->Data());

	const char* elem_name = elem_create.GetName().data();

	::Print("NetGameClient::DoElemCreate name: %s iff: %d type %s\n",
	elem_name,
	elem_create.GetIFF(),
	Mission::RoleName(elem_create.GetType()));

	Sim*     sim   = Sim::GetSim();
	Element* elem  = sim->FindElement(elem_name);
	if (elem) {
		::Print("  element '%' already exists - ignored\n", elem_name);
		return;
	}

	elem = sim->CreateElement(elem_name,
	elem_create.GetIFF(),
	elem_create.GetType());

	int*     load     = elem_create.GetLoadout();
	int*     slots    = elem_create.GetSlots();
	int      squadron = elem_create.GetSquadron();
	int      code     = elem_create.GetObjCode();
	Text     target   = elem_create.GetObjective();
	bool     alert    = elem_create.GetAlert();
	bool     active   = elem_create.GetInFlight();

	elem->SetIntelLevel(elem_create.GetIntel());
	elem->SetLoadout(load);

	if (code > Instruction::RTB || target.length() > 0) {
		Instruction* obj  = new(__FILE__,__LINE__) Instruction(code, target);
		elem->AddObjective(obj);
	}

	Ship* carrier = sim->FindShip(elem_create.GetCarrier());
	if (carrier) {
		elem->SetCarrier(carrier);

		Hangar* hangar = carrier->GetHangar();
		if (hangar) {
			Text squadron_name = hangar->SquadronName(squadron);
			elem->SetSquadron(squadron_name);

			if (active) {
				for (int i = 0; i < 4; i++) {
					int slot = slots[i];
					if (slot > -1) {
						hangar->GotoActiveFlight(squadron, slot, elem, load);
					}
				}
			}

			else {
				FlightDeck* deck   = 0;
				int         queue  = 1000;

				for (int i = 0; i < carrier->NumFlightDecks(); i++) {
					FlightDeck* d = carrier->GetFlightDeck(i);

					if (d && d->IsLaunchDeck()) {
						int dq = hangar->PreflightQueue(d);

						if (dq < queue) {
							queue = dq;
							deck  = d;
						}
					}
				}

				for (int i = 0; i < 4; i++) {
					int slot = slots[i];
					if (slot > -1) {
						hangar->GotoAlert(squadron, slot, deck, elem, load, !alert);
					}
				}
			}
		}
	}
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:87,代码来源:NetGameClient.cpp


注:本文中的Text类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。