Exemplo n.º 1
0
void Player::CreateGUI()
{
    UI* ui = GetSubsystem<UI>();
    Text* scoreText = ui->GetRoot()->CreateChild<Text>();
    scoreText->SetName("Score");
    scoreTextName_ = scoreText->GetName();
    scoreText->SetText(String(score_));
    scoreText->SetFont(masterControl_->cache_->GetResource<Font>("Resources/Fonts/skirmishergrad.ttf"), 32);
    scoreText->SetColor(Color(0.5f, 0.95f, 1.0f, 0.666f));
    scoreText->SetHorizontalAlignment(HA_CENTER);
    scoreText->SetVerticalAlignment(VA_CENTER);
    scoreText->SetPosition(0, ui->GetRoot()->GetHeight()/2.5f);

    //Setup 3D GUI elements
    guiNode_ = masterControl_->world.scene->CreateChild("GUI3D");
    healthBarNode_ = guiNode_->CreateChild("HealthBar");
    healthBarNode_->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    healthBarNode_->SetScale(Vector3(health_, 1.0f, 1.0f));
    healthBarModel_ = healthBarNode_->CreateComponent<StaticModel>();
    healthBarModel_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Bar.mdl"));
    healthBarModel_->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/GreenGlowEnvmap.xml"));

    shieldBarNode_ = guiNode_->CreateChild("HealthBar");
    shieldBarNode_->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    shieldBarNode_->SetScale(Vector3(health_, 0.9f, 0.9f));
    shieldBarModel_ = shieldBarNode_->CreateComponent<StaticModel>();
    shieldBarModel_->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Bar.mdl"));
    shieldBarModel_->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/BlueGlowEnvmap.xml"));

    Node* healthBarHolderNode = guiNode_->CreateChild("HealthBarHolder");
    healthBarHolderNode->SetPosition(Vector3(0.0f, 1.0f, 21.0f));
    StaticModel* healthBarHolderModel = healthBarHolderNode->CreateComponent<StaticModel>();
    healthBarHolderModel->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/BarHolder.mdl"));
    healthBarHolderModel->SetMaterial(masterControl_->cache_->GetResource<Material>("Resources/Materials/Metal.xml"));

    appleCounterRoot_ = guiNode_->CreateChild("AppleCounter");
    for (int a = 0; a < 5; a++){
        appleCounter_[a] = appleCounterRoot_->CreateChild();
        appleCounter_[a]->SetEnabled(false);
        appleCounter_[a]->SetPosition(Vector3(-(a + 8.0f), 1.0f, 21.0f));
        appleCounter_[a]->SetScale(0.333f);
        StaticModel* apple = appleCounter_[a]->CreateComponent<StaticModel>();
        apple->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Apple.mdl"));
        apple->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/GoldEnvmap.xml"));
    }

    heartCounterRoot_ = guiNode_->CreateChild("HeartCounter");
    for (int h = 0; h < 5; h++){
        heartCounter_[h] = heartCounterRoot_->CreateChild();
        heartCounter_[h]->SetEnabled(false);
        heartCounter_[h]->SetPosition(Vector3(h + 8.0f, 1.0f, 21.0f));
        heartCounter_[h]->SetScale(0.333f);
        StaticModel* heart = heartCounter_[h]->CreateComponent<StaticModel>();
        heart->SetModel(masterControl_->cache_->GetResource<Model>("Resources/Models/Heart.mdl"));
        heart->SetMaterial(masterControl_->cache_->GetTempResource<Material>("Resources/Materials/RedEnvmap.xml"));
    }
}
Exemplo n.º 2
0
void GameApplication::CreateUI()
{
	Input* input = GetSubsystem<Input>();
	input->SetMouseVisible(true);

    ResourceCache* cache = GetSubsystem<ResourceCache>();
    UI* ui = GetSubsystem<UI>();
    
    // Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
    // control the camera, and when visible, it will point the raycast target
    XMLFile* style = cache->GetResource<XMLFile>("UI/DefaultStyle.xml");
    SharedPtr<Cursor> cursor(new Cursor(context_));
    cursor->SetStyleAuto(style);
    ui->SetCursor(cursor);
    // Set starting position of the cursor at the rendering window center
    Graphics* graphics = GetSubsystem<Graphics>();
    cursor->SetPosition(graphics->GetWidth() / 2, graphics->GetHeight() / 2);
    
    // Construct new Text object, set string to display and font to use
    scoreText = ui->GetRoot()->CreateChild<Text>();
    scoreText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
    // The text has multiple rows. Center them in relation to each other
    scoreText->SetTextAlignment(HA_CENTER);
	scoreText->SetColor(Color::BLUE);
	scoreText->SetTextEffect(TextEffect::TE_SHADOW);
    // Position the text relative to the screen center
    scoreText->SetHorizontalAlignment(HA_CENTER);
    scoreText->SetVerticalAlignment(VA_CENTER);
    scoreText->SetPosition(0, ui->GetRoot()->GetHeight() / 4 + 80);

	//开始按钮
	//UIButton* btnStart = new UIButton(context_);
	//btnStart->SetPosition(100,100);
	//btnStart->SetSize(120,50);

	//ui->GetRoot()->AddChild(btnStart);

	Button* btnStart = CreateButton(80,100,120,50,"Start");// ui->GetRoot()->CreateChild<Button>();
	btnStart->SetName("btnStart");
	btnStart->SetMinHeight(24);
	btnStart->SetStyleAuto();
	btnStart->SetPosition(100,100);
	btnStart->SetSize(120,50);

	Text* buttonText = btnStart->CreateChild<Text>();
	buttonText->SetAlignment(HA_CENTER, VA_CENTER);
	buttonText->SetColor(Color::BLUE);
	Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");
	buttonText->SetFont(font, 12);
	buttonText->SetText("Start");

	SubscribeToEvent(btnStart,E_PRESSED,HANDLER(GameApplication,OnButtonStartClick));

	UpdateScore();
}
Exemplo n.º 3
0
int ScriptBinding::text_setColor(lua_State * s)
{
	Text * text = (Text*)lua_tointeger(s,1);
	Color c;
	c.r = (float)lua_tointeger(s,2)/255.0f;
	c.g = (float)lua_tointeger(s,3)/255.0f;
	c.b = (float)lua_tointeger(s,4)/255.0f;

	text->SetColor(c);

	return 0;
}
Exemplo n.º 4
0
 void ProcessTextChange(EditorRange& Modification,
              Text& input) {
   size_t start = Modification.fEdit.fStart;
   if (start > 6) start -= 5; // not -= 6: we require at least one changed char
   else start = 0;
   size_t P = input.GetText().find("return", start, 6);
   if (P != std::string::npos) {
     for (size_t i = P; i < P + 6; ++i) {
       input.SetColor(i, 1);
     }
     Modification.fDisplay.Extend(Range(P, 6));
   }
 }
Exemplo n.º 5
0
void PhoneModeAddressBook::AddContact(uint8_t Index)
{
    uint16_t AddressMask = 1 << Index;
    if (this->AddressMask & AddressMask)
        return;

    string Name = sExe->ReadStringIndirect(VA_PHONE_ADDRMENU, Index, 0xC, 0x4);
    Text ContactText;
    ContactText.SetPosition(PHONE_WALLPAPER_X, BLUE_HEADER_POS_Y + BLUE_HEADER_HEIGHT + Contacts.size() * 20);
    ContactText.SetColor(Nsb::Color::BLACK);
    ContactText.SetCharacterSize(20);
    ContactText.CreateFromString(Name);
    Contacts.push_back({ ContactText, Index });
    this->AddressMask |= AddressMask;
}
Exemplo n.º 6
0
Button* GameApplication::CreateButton(int x,int y,int xSize,int ySize,const String& text)
{
	UIElement* root = GetSubsystem<UI>()->GetRoot();
	ResourceCache* cache = GetSubsystem<ResourceCache>();
	Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf");

	// Create the button and center the text onto it
	Button* button = root->CreateChild<Button>();
	button->SetTexture(cache->GetResource<Texture2D>("Urho2D/Box.png"));
	button->SetStyleAuto();
	button->SetPosition(x, y);
	button->SetSize(xSize, ySize);

	Text* buttonText = button->CreateChild<Text>();
	buttonText->SetAlignment(HA_CENTER, VA_CENTER);
	buttonText->SetFont(font, 12);
	buttonText->SetColor(Color::BLUE);
	buttonText->SetText(text);

	return button;
}
Exemplo n.º 7
0
 void ProcessPromptChange(Text& prompt) {
   prompt.SetColor(Range::AllText(), 1);
 }