void SignedDistanceFieldText::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText("Use WASD keys and mouse/touch to move"); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void Character2D::HandleWoundedState(float timeStep) { auto* body = GetComponent<RigidBody2D>(); auto* animatedSprite = GetComponent<AnimatedSprite2D>(); // Play "hit" animation in loop if (animatedSprite->GetAnimation() != "hit") animatedSprite->SetAnimation("hit", LM_FORCE_LOOPED); // Update timer timer_ += timeStep; if (timer_ > 2.0f) { // Reset timer timer_ = 0.0f; // Clear forces (should be performed by setting linear velocity to zero, but currently doesn't work) body->SetLinearVelocity(Vector2::ZERO); body->SetAwake(false); body->SetAwake(true); // Remove particle emitter node_->GetChild("Emitter", true)->Remove(); // Update lifes UI and counter remainingLifes_ -= 1; auto* ui = GetSubsystem<UI>(); Text* lifeText = static_cast<Text*>(ui->GetRoot()->GetChild("LifeText", true)); lifeText->SetText(String(remainingLifes_)); // Update lifes UI counter // Reset wounded state wounded_ = false; // Handle death if (remainingLifes_ == 0) { HandleDeath(); return; } // Re-position the character to the nearest point if (node_->GetPosition().x_ < 15.0f) node_->SetPosition(Vector3(1.0f, 8.0f, 0.0f)); else node_->SetPosition(Vector3(18.8f, 9.2f, 0.0f)); } }
Button* Chat::CreateButton(const String& text, int width) { ResourceCache* cache = GetSubsystem<ResourceCache>(); Font* font = cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"); Button* button = buttonContainer_->CreateChild<Button>(); button->SetStyleAuto(); button->SetFixedWidth(width); Text* buttonText = button->CreateChild<Text>(); buttonText->SetFont(font, 12); buttonText->SetAlignment(HA_CENTER, VA_CENTER); buttonText->SetText(text); return button; }
void UIDrag::HandleDragMove(StringHash eventType, VariantMap& eventData) { using namespace DragBegin; Button* element = (Button*)eventData[P_ELEMENT].GetVoidPtr(); int buttons = eventData[P_BUTTONS].GetInt(); IntVector2 d = element->GetVar("DELTA").GetIntVector2(); int X = eventData[P_X].GetInt() + d.x_; int Y = eventData[P_Y].GetInt() + d.y_; int BUTTONS = element->GetVar("BUTTONS").GetInt(); Text* t = (Text*)element->GetChild(String("Event Touch")); t->SetText("Drag Move Buttons: " + String(buttons)); if (buttons == BUTTONS) element->SetPosition(IntVector2(X, Y)); }
void Urho2DSpriterAnimation::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText("Mouse click to play next animation, \nUse WASD keys to move, use PageUp PageDown keys to zoom."); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); instructionText->SetTextAlignment(HA_CENTER); // Center rows in relation to each other // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void Urho2DConstraints::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText("Use WASD keys and mouse to move, Use PageUp PageDown to zoom.\n Space to toggle debug geometry and joints - F5 to save the scene."); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); instructionText->SetTextAlignment(HA_CENTER); // Center rows in relation to each other // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void Maze::Intro() { float windowWidth = (float)this->mGe->GetEngineParameters().windowWidth; float windowHeight = (float)this->mGe->GetEngineParameters().windowHeight; float dx = (windowHeight * 4.0f) / 3.0f; float offSet = (windowWidth - dx) / 2.0f; float textHalfWidth = (dx * (205.0f / 800.0f)) * 0.5f; float y = this->mGe->GetEngineParameters().windowHeight * 0.4f; Text* intro = mGe->CreateText("Maze", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 2.0f, "Media/Fonts/1"); mGe->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png"); // Changed by MaloW intro->SetText(""); mGe->DeleteText(intro); this->mWindowWidth = (float)this->mGe->GetEngineParameters().windowWidth; this->mWindowHeight = (float)this->mGe->GetEngineParameters().windowHeight; this->mHud[0] = mGe->CreateText("",D3DXVECTOR2(0,0),1.25f,"Media/Fonts/1"); this->mHud[1] = mGe->CreateText("",D3DXVECTOR2(0,30),1.0f,"Media/Fonts/1"); this->mHud[2] = mGe->CreateText("",D3DXVECTOR2(0,60),1.0f,"Media/Fonts/1"); this->mHud[3] = mGe->CreateText("",D3DXVECTOR2(0,90),1.0f,"Media/Fonts/1"); this->mHud[4] = mGe->CreateText("",D3DXVECTOR2(0,120),1.25f,"Media/Fonts/1"); this->mHud[5] = mGe->CreateText("",D3DXVECTOR2(0,150),1.0f,"Media/Fonts/1"); this->mHud[6] = mGe->CreateText("",D3DXVECTOR2(0,180),1.0f,"Media/Fonts/1"); this->mHud[7] = mGe->CreateText("",D3DXVECTOR2(0,210),1.0f,"Media/Fonts/1"); this->mHud[8] = mGe->CreateText("",D3DXVECTOR2(0,240),1.0f,"Media/Fonts/1"); this->mHud[9] = mGe->CreateText("",D3DXVECTOR2(0,270),1.0f,"Media/Fonts/1"); this->mCreditSpeed = 0.05f; /* if(mGe->GetEngineParameters().CamType == TRD) ((TRDCamera*)mGe->GetCamera())->setBallToFollow(this->mBalls[0]); */ this->mTimeElapsedText = this->mGe->CreateText( "", D3DXVECTOR2(windowWidth - 150.0f, windowHeight - 100.0f), 1.0f, "Media/Fonts/1"); /* CheckBox for the change gamemode */ this->mCb = new CheckBox(0,0,0,"Media/Menus/CheckBoxFrame.png", dx * (30.0f / 1200.0f), windowHeight * (30.0f / 900.0f), "Media/Menus/CheckBoxChecked.png", true, new ChangeOptionEvent("MazeMode", "true"), "ChangeSet"); }
void ProfilerHudPanel::UpdatePanel(float /*frametime*/, const SharedPtr<Urho3D::UIElement> &widget) { if (profilerTimer_.GetMSec(false) < profilerInterval) return; Profiler* profiler = framework_->GetSubsystem<Profiler>(); Text *profilerText = dynamic_cast<Text*>(widget.Get()); if (!profiler || !profilerText) return; profilerTimer_.Reset(); String profilerOutput = profiler->PrintData(false, false, profilerMaxDepth); profilerText->SetText(profilerOutput); profiler->BeginInterval(); }
void HelloGUI::InitWindow() { // Create the Window and add it to the UI's root node window_ = new Window(context_); uiRoot_->AddChild(window_); // Set Window size and layout settings window_->SetMinSize(384, 192); window_->SetLayout(LM_VERTICAL, 6, IntRect(6, 6, 6, 6)); window_->SetAlignment(HA_CENTER, VA_CENTER); window_->SetName("Window"); // Create Window 'titlebar' container UIElement* titleBar = new UIElement(context_); titleBar->SetMinSize(0, 24); titleBar->SetVerticalAlignment(VA_TOP); titleBar->SetLayoutMode(LM_HORIZONTAL); // Create the Window title Text Text* windowTitle = new Text(context_); windowTitle->SetName("WindowTitle"); windowTitle->SetText("Hello GUI!"); // Create the Window's close button Button* buttonClose = new Button(context_); buttonClose->SetName("CloseButton"); // Add the controls to the title bar titleBar->AddChild(windowTitle); titleBar->AddChild(buttonClose); // Add the title bar to the Window window_->AddChild(titleBar); // Apply styles window_->SetStyleAuto(); windowTitle->SetStyleAuto(); buttonClose->SetStyle("CloseButton"); // Subscribe to buttonClose release (following a 'press') events SubscribeToEvent(buttonClose, E_RELEASED, HANDLER(HelloGUI, HandleClosePressed)); // Subscribe also to all UI mouse clicks just to see where we have clicked SubscribeToEvent(E_UIMOUSECLICK, HANDLER(HelloGUI, HandleControlClicked)); }
void UIDrag::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText("Drag on the buttons to move them around.\n" "Touch input allows also multi-drag.\n" "Press SPACE to show/hide tagged UI elements."); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); instructionText->SetTextAlignment(HA_CENTER); // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void HelloGUI::HandleControlClicked(StringHash eventType, VariantMap& eventData) { // Get the Text control acting as the Window's title Text* windowTitle = static_cast<Text*>(window_->GetChild("WindowTitle", true)); // Get control that was clicked UIElement* clicked = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr()); String name = "...?"; if (clicked) { // Get the name of the control that was clicked name = clicked->GetName(); } // Update the Window's title text windowTitle->SetText("Hello " + name + "!"); }
bool Console::PopulateInterpreter() { interpreters_->RemoveAllItems(); EventReceiverGroup* group = context_->GetEventReceivers(E_CONSOLECOMMAND); if (!group || group->receivers_.Empty()) return false; Vector<String> names; for (unsigned i = 0; i < group->receivers_.Size(); ++i) { Object* receiver = group->receivers_[i]; if (receiver) names.Push(receiver->GetTypeName()); } Sort(names.Begin(), names.End()); unsigned selection = M_MAX_UNSIGNED; for (unsigned i = 0; i < names.Size(); ++i) { const String& name = names[i]; if (name == commandInterpreter_) selection = i; Text* text = new Text(context_); text->SetStyle("ConsoleText"); text->SetText(name); interpreters_->AddItem(text); } const IntRect& border = interpreters_->GetPopup()->GetLayoutBorder(); interpreters_->SetMaxWidth(interpreters_->GetListView()->GetContentElement()->GetWidth() + border.left_ + border.right_); bool enabled = interpreters_->GetNumItems() > 1; interpreters_->SetEnabled(enabled); interpreters_->SetFocusMode(enabled ? FM_FOCUSABLE_DEFOCUSABLE : FM_NOTFOCUSABLE); if (selection == M_MAX_UNSIGNED) { selection = 0; commandInterpreter_ = names[selection]; } interpreters_->SetSelection(selection); return true; }
Button* SoundEffects::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->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->SetText(text); return button; }
void CaptureTheFlag::Intro() { float windowWidth = (float)this->mGe->GetEngineParameters().windowWidth; float windowHeight = (float)this->mGe->GetEngineParameters().windowHeight; float dx = (windowHeight * 4.0f) / 3.0f; float offSet = (windowWidth - dx) / 2.0f; float textHalfWidth = (dx * (675.0f / 800.0f)) * 0.5f; float y = this->mGe->GetEngineParameters().windowHeight * 0.4f; Text* intro = mGe->CreateText("Capture The Flag", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 2.0f,"Media/Fonts/1"); mGe->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png"); // Changed by MaloW intro->SetText(""); mGe->DeleteText(intro); //net while(this->mChooseTeamMenu->Run()); // Moved down by malow windowWidth = (float)this->mGe->GetEngineParameters().windowWidth; windowHeight = (float)this->mGe->GetEngineParameters().windowHeight; dx = (windowHeight * 4.0f) / 3.0f; offSet = (windowWidth - dx) / 2.0f; textHalfWidth = dx * (200.0f / 800.0f); float x = this->mGe->GetEngineParameters().windowWidth * 0.5f - textHalfWidth; y = 10.0f; this->mIntermediateText = this->mGe->CreateText("", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 1.0f, "Media/Fonts/1"); x = this->mGe->GetEngineParameters().windowWidth * 0.5f - textHalfWidth - this->mGe->GetEngineParameters().windowWidth * 0.1f - this->mGe->GetEngineParameters().windowWidth * 0.025f; this->mRedScoreText = this->mGe->CreateText("", D3DXVECTOR2(x, y), 1.0f, "Media/Fonts/3"); x = this->mGe->GetEngineParameters().windowWidth * 0.5f + textHalfWidth + this->mGe->GetEngineParameters().windowWidth * 0.1f; this->mBlueScoreText = this->mGe->CreateText("", D3DXVECTOR2(x, y), 1.0f, "Media/Fonts/2"); x = this->mGe->GetEngineParameters().windowWidth * 0.5f - this->mGe->GetEngineParameters().windowWidth * 0.4f; y = this->mGe->GetEngineParameters().windowHeight * 0.4f; this->mHud[0] = this->mGe->CreateText("", D3DXVECTOR2(x, y), 2.0f, "Media/Fonts/1"); // this->mRedScoreText->SetText("0"); this->mBlueScoreText->SetText("0"); string totalScore = MaloW::convertNrToString((float)this->mNumberOfRounds); this->mIntermediateText->SetText("Flags captured of " + totalScore); }
void Sample::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText( "Use WASD keys and mouse to move\n" "Space to toggle debug geometry" ); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 13); // The text has multiple rows. Center them in relation to each other instructionText->SetTextAlignment(HA_CENTER); // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void VehicleDemo::CreateInstructions() { ResourceCache* cache = GetSubsystem<ResourceCache>(); UI* ui = GetSubsystem<UI>(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText( "Use WASD keys to drive, mouse to rotate camera\n" "F5 to save scene, F7 to load" ); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); // The text has multiple rows. Center them in relation to each other instructionText->SetTextAlignment(HA_CENTER); // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void Console::HandlePostUpdate(StringHash eventType, VariantMap& eventData) { if (!rowContainer_->GetNumChildren()) return; rowContainer_->DisableLayoutUpdate(); for (unsigned i = 0; i < pendingRows_.Size(); ++i) { rowContainer_->RemoveChildAtIndex(0); Text* text = rowContainer_->CreateChild<Text>(); text->SetText(pendingRows_[i].second_); // Make error message highlight text->SetStyle(pendingRows_[i].first_ == LOG_ERROR ? "ConsoleHighlightedText" : "ConsoleText"); } pendingRows_.Clear(); rowContainer_->EnableLayoutUpdate(); rowContainer_->UpdateLayout(); }
Slider* SoundEffects::CreateSlider(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 text and slider below it Text* sliderText = root->CreateChild<Text>(); sliderText->SetPosition(x, y); sliderText->SetFont(font, 12); sliderText->SetText(text); Slider* slider = root->CreateChild<Slider>(); slider->SetStyleAuto(); slider->SetPosition(x, y + 20); slider->SetSize(xSize, ySize); // Use 0-1 range for controlling sound/music master volume slider->SetRange(1.0f); return slider; }
void ModalWindow::InitComponents(const String &title, const String &message, bool show_close_button) { assert(!m_ok_button); // ok button should not have been inited m_title_text = dynamic_cast<Text *>(GetChild("TitleText", true)); assert(m_title_text); m_title_text->SetText(m_l10n->Get(title)); m_message_text = dynamic_cast<Text *>(GetChild("MessageText", true)); m_message_text->SetText(m_l10n->Get(message)); m_ok_button = dynamic_cast<Button *>(GetChild("OkButton", true)); assert(m_ok_button); Button *cancel_button = dynamic_cast<Button *>(GetChild("CancelButton", true)); Text *cancelButtonText = dynamic_cast<Text *>(GetChild("CancelButtonText", true)); assert(cancel_button && cancelButtonText); cancelButtonText->SetText(m_l10n->Get(cancelButtonText->GetText())); Button *close_button = dynamic_cast<Button *>(GetChild("CloseButton", true)); assert(close_button); if (show_close_button) { SubscribeToEvent(close_button, E_RELEASED, URHO3D_HANDLER(ModalWindow, HandleMessageAcknowledged)); } else { close_button->Remove(); } SetModal(true); SubscribeToEvent(this, E_MODALCHANGED, URHO3D_HANDLER(ModalWindow, HandleMessageAcknowledged)); SubscribeToEvent(m_ok_button, E_RELEASED, URHO3D_HANDLER(ModalWindow, HandleMessageAcknowledged)); SubscribeToEvent(cancel_button, E_RELEASED, URHO3D_HANDLER(ModalWindow, HandleMessageAcknowledged)); SubscribeToEvent(E_KEYDOWN, URHO3D_HANDLER(ModalWindow, HandleKeyDown)); }
void Ragdolls::CreateInstructions() { ResourceCache* cache = GetContext()->m_ResourceCache.get(); UI* ui = GetContext()->m_UISystem.get(); // Construct new Text object, set string to display and font to use Text* instructionText = ui->GetRoot()->CreateChild<Text>(); instructionText->SetText( "Use WASD keys and mouse/touch to move\n" "LMB to spawn physics objects\n" "F5 to save scene, F7 to load\n" "Space to toggle physics debug geometry" ); instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15); // The text has multiple rows. Center them in relation to each other instructionText->SetTextAlignment(HA_CENTER); // Position the text relative to the screen center instructionText->SetHorizontalAlignment(HA_CENTER); instructionText->SetVerticalAlignment(VA_CENTER); instructionText->SetPosition(0, ui->GetRoot()->GetHeight() / 4); }
void UIDrag::HandleUpdate(StringHash eventType, VariantMap& eventData) { auto* ui = GetSubsystem<UI>(); UIElement* root = ui->GetRoot(); auto* input = GetSubsystem<Input>(); unsigned n = input->GetNumTouches(); for (unsigned i = 0; i < n; i++) { Text* t = (Text*)root->GetChild("Touch " + String(i)); TouchState* ts = input->GetTouch(i); t->SetText("Touch " + String(ts->touchID_)); IntVector2 pos = ts->position_; pos.y_ -= 30; t->SetPosition(pos); t->SetVisible(true); } for (unsigned i = n; i < 10; i++) { Text* t = (Text*)root->GetChild("Touch " + String(i)); t->SetVisible(false); } if (input->GetKeyPress(KEY_SPACE)) { PODVector<UIElement*> elements; root->GetChildrenWithTag(elements, "SomeTag"); for (PODVector<UIElement*>::ConstIterator i = elements.Begin(); i != elements.End(); ++i) { UIElement* element = *i; element->SetVisible(!element->IsVisible()); } } }
void Console::HandlePostUpdate(StringHash eventType, VariantMap& eventData) { // Ensure UI-elements are not detached if (!background_->GetParent()) { UI* ui = GetSubsystem<UI>(); UIElement* uiRoot = ui->GetRoot(); uiRoot->AddChild(background_); uiRoot->AddChild(closeButton_); } if (!rowContainer_->GetNumItems() || pendingRows_.Empty()) return; printing_ = true; rowContainer_->DisableLayoutUpdate(); Text* text = nullptr; for (unsigned i = 0; i < pendingRows_.Size(); ++i) { rowContainer_->RemoveItem((unsigned)0); text = new Text(context_); text->SetText(pendingRows_[i].second_); // Highlight console messages based on their type text->SetStyle(logStyles[pendingRows_[i].first_]); rowContainer_->AddItem(text); } pendingRows_.Clear(); rowContainer_->EnsureItemVisibility(text); rowContainer_->EnableLayoutUpdate(); rowContainer_->UpdateLayout(); UpdateElements(); // May need to readjust the height due to scrollbar visibility changes printing_ = false; }
void Console::HandleLogMessage(StringHash eventType, VariantMap& eventData) { // If the rows are not fully initialized yet, or we are recursing here, do not write the message if (inLogMessage_ || rows_.Empty() || !rows_.Back()) return; inLogMessage_ = true; using namespace LogMessage; // Be prepared for possible multi-line messages Vector<String> rows = eventData[P_MESSAGE].GetString().Split('\n'); for (unsigned i = 0; i < rows.Size(); ++i) { // Remove the first row, change its text and re-add to the bottom Text* text = static_cast<Text*>(rowContainer_->GetChild(0)); rowContainer_->RemoveChild(text); text->SetText(rows[i]); rowContainer_->AddChild(text); } inLogMessage_ = false; }
void Knockout::Intro() { float windowWidth = (float)this->mGe->GetEngineParameters().windowWidth; float windowHeight = (float)this->mGe->GetEngineParameters().windowHeight; float dx = (windowHeight * 4.0f) / 3.0f; float offSet = (windowWidth - dx) / 2.0f; float textHalfWidth = (dx * (350.0f / 800.0f)) * 0.5f; float y = this->mGe->GetEngineParameters().windowHeight * 0.4f; Text* intro = mGe->CreateText("Knockout", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 2.0f, "Media/Fonts/1"); mGe->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png"); // Changed by MaloW intro->SetText(""); mGe->DeleteText(intro); windowWidth = (float)this->mGe->GetEngineParameters().windowWidth; windowHeight = (float)this->mGe->GetEngineParameters().windowHeight; dx = (windowHeight * 4.0f) / 3.0f; offSet = (windowWidth - dx) / 2.0f; textHalfWidth = (dx * (455.0f / 800.0f)) * 0.5f; this->mTimeElapsedText = this->mGe->CreateText( "", D3DXVECTOR2(20.0f, 10.0f), 1.0f, "Media/Fonts/1"); //time this->mHud[0] = mGe->CreateText("",D3DXVECTOR2(20,50),1.0f,"Media/Fonts/1"); //player 1 score this->mHud[1] = mGe->CreateText("",D3DXVECTOR2(20,90),1.0f,"Media/Fonts/1"); //player 2 score this->mHud[2] = mGe->CreateText("",D3DXVECTOR2(20,130),1.0f,"Media/Fonts/1"); //number of rounds y = this->mGe->GetEngineParameters().windowHeight * 0.4f; this->mHud[3] = mGe->CreateText("", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 1.0f, "Media/Fonts/1"); //winner of round textHalfWidth = (dx * (230.0f / 800.0f)) * 0.5f; this->mHud[4] = mGe->CreateText("", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 1.0f, "Media/Fonts/1"); //round draw textHalfWidth = (dx * (650.0f / 800.0f)) * 0.5f; y = this->mGe->GetEngineParameters().windowHeight * 0.5f; this->mHud[5] = mGe->CreateText("", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 2.0f, "Media/Fonts/1"); //winner of game/match textHalfWidth = (dx * (455.0f / 800.0f)) * 0.5f; this->mHud[6] = mGe->CreateText("", D3DXVECTOR2(dx * 0.5f - textHalfWidth + offSet, y), 2.0f, "Media/Fonts/1"); //game/match draw }
void VehicleDemo::HandleUpdate(StringHash eventType, VariantMap& eventData) { using namespace Update; Input* input = GetSubsystem<Input>(); if (vehicle_) { UI* ui = GetSubsystem<UI>(); // Get movement controls and assign them to the vehicle component. If UI has a focused element, clear controls if (!ui->GetFocusElement()) { vehicle_->controls_.Set(CTRL_FORWARD, input->GetKeyDown('W')); vehicle_->controls_.Set(CTRL_BACK, input->GetKeyDown('S')); vehicle_->controls_.Set(CTRL_LEFT, input->GetKeyDown('A')); vehicle_->controls_.Set(CTRL_RIGHT, input->GetKeyDown('D')); vehicle_->controls_.Set(CTRL_SPACE, input->GetKeyDown(KEY_SPACE)); // Add yaw & pitch from the mouse motion or touch input. Used only for the camera, does not affect motion if (touchEnabled_) { for (unsigned i = 0; i < input->GetNumTouches(); ++i) { TouchState* state = input->GetTouch(i); if (!state->touchedElement_) // Touch on empty space { Camera* camera = cameraNode_->GetComponent<Camera>(); if (!camera) return; Graphics* graphics = GetSubsystem<Graphics>(); vehicle_->controls_.yaw_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.x_; vehicle_->controls_.pitch_ += TOUCH_SENSITIVITY * camera->GetFov() / graphics->GetHeight() * state->delta_.y_; } } } else { vehicle_->controls_.yaw_ += (float)input->GetMouseMoveX() * YAW_SENSITIVITY; vehicle_->controls_.pitch_ += (float)input->GetMouseMoveY() * YAW_SENSITIVITY; } // Limit pitch vehicle_->controls_.pitch_ = Clamp(vehicle_->controls_.pitch_, 0.0f, 80.0f); // Check for loading / saving the scene if (input->GetKeyPress(KEY_F5)) { File saveFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml", FILE_WRITE); scene_->SaveXML(saveFile); } if (input->GetKeyPress(KEY_F7)) { File loadFile(context_, GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Scenes/VehicleDemo.xml", FILE_READ); scene_->LoadXML(loadFile); // After loading we have to reacquire the weak pointer to the Vehicle component, as it has been recreated // Simply find the vehicle's scene node by name as there's only one of them Node* vehicleNode = scene_->GetChild("Vehicle", true); if (vehicleNode) vehicle_ = vehicleNode->GetComponent<Vehicle>(); } } else vehicle_->controls_.Set(CTRL_FORWARD | CTRL_BACK | CTRL_LEFT | CTRL_RIGHT | CTRL_SPACE, false); } // set vehicle speed to UI Text* speedText = (Text*)GetSubsystem<UI>()->GetRoot()->GetChild("UITextSpeed",true); speedText->SetText(String((int)vehicle_->getSpeed()) + " km/h"); // set vehicle gear to UI Text* gearText = (Text*)GetSubsystem<UI>()->GetRoot()->GetChild("UITextGear",true); gearText->SetText(String((int)vehicle_->getGear()) + " gear"); }
void Warlock::Intro() { float x = this->mGe->GetEngineParameters().windowWidth * 0.5f - this->mGe->GetEngineParameters().windowWidth * 0.2125f; float y = this->mGe->GetEngineParameters().windowHeight * 0.4f; Text* intro = mGe->CreateText("Warlock", D3DXVECTOR2(x, y), 2.0f, "Media/Fonts/1"); mGe->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png", 0.0f, 1.0f, 1.0f, 1.0f); // Changed by MaloW intro->SetText(""); mGe->DeleteText(intro); float width = GetGraphicsEngine()->GetEngineParameters().windowWidth; float height = GetGraphicsEngine()->GetEngineParameters().windowHeight; /* Set hud */ this->mHud[0] = NULL; this->mHud[1] = NULL; this->mHud[2] = NULL; this->mHud[3] = NULL; this->mHud[4] = NULL; this->mHud[5] = NULL; this->mHud[6] = NULL; this->mHud[7] = NULL; this->mHud[8] = NULL; this->mHud[9] = NULL; this->mHud[10] = NULL; // Rework ScreenWidth to 4:3 const float UISCALE = 0.5f; float screenHeight = this->mGe->GetEngineParameters().windowHeight; float screenWidth = (screenHeight * 4) / 3; float distX = (mGe->GetEngineParameters().windowWidth - screenWidth) / 2; distX /= UISCALE; D3DXVECTOR2 imgDim = D3DXVECTOR2(screenWidth / 5, screenWidth / 5) * UISCALE; distX = (this->mGe->GetEngineParameters().windowWidth / 2.0f) - ((imgDim.x * 5.0f) / 2.0f); for(int i = 11; i < 16; i++) { this->mHud[i] = mGe->CreateText("",D3DXVECTOR2(distX + imgDim.x * (i-11) + (imgDim.x * 0.2f), screenHeight - imgDim.y * 0.65f), 1.0f, "Media/Fonts/1"); } this->mHud[16] = NULL; this->mProgressBars = new ProgressBar*[6]; float percentX = 0.02f; float percentY = 0.88f; for(int i = 0; i<5;i++) { D3DXVECTOR2 temp = D3DXVECTOR2(percentX,percentY); this->mProgressBars[i] = new ProgressBar(distX + imgDim.x * i, screenHeight - imgDim.y - (screenHeight * 0.03f), imgDim.x, (screenHeight * 0.03f)); this->mProgressBars[i]->SetPercentOfProgressBarColor1(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor2(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor3(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor4(0.0f); percentX = percentX + 0.16f; } D3DXVECTOR2 temp = D3DXVECTOR2(percentX,percentY); this->mProgressBars[5] = new ProgressBar(distX, screenHeight - imgDim.y - (screenHeight * 0.08f) , imgDim.x * 5.0f, (screenHeight * 0.05f)); this->mProgressBars[5]->SetPercentOfProgressBarColor1(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor2(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor3(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor4(0.0f); percentX = percentX + 0.16f; this->mTimeElapsedText = this->mGe->CreateText( "", D3DXVECTOR2(15.0f, 10.0f), 1.0f, "Media/Fonts/1"); // Add spell Icons Image* charge = mGe->CreateImage(D3DXVECTOR2(distX, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/ChargeIcon.png"); Image* sprint = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/SprintIcon.png"); Image* harden = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 2, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/HardenIcon.png"); Image* invis = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 3, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/InvisIcon.png"); Image* jump = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 4, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/JumpIcon.png"); this->SpellIcons.add(charge); this->SpellIcons.add(sprint); this->SpellIcons.add(harden); this->SpellIcons.add(invis); this->SpellIcons.add(jump); }
void Board::Update(float timeStep) { if (gameOver_) { if (score_ > record_) { record_ = score_; SaveRecord(); } Restart(); return; } selectionNode_->Rotate(Quaternion(0.0f, timeStep * 50, 0.0f)); if (Path::GetTotalCount() > 0) return; if (needCheckLines_) { if (CheckLines()) { needSpawnBalls_ = false; } needCheckLines_ = false; // может быть что поле полностью занято, новых шаров спанить не надо и ходить некуда // не работает чот gameOver_ = true; for (int i = 0; i < height_; i++) { for (int j = 0; j < width_; j++) { if (!board_[i][j] || board_[i][j]->GetBallState() == BS_GHOST) { gameOver_ = false; break; } } } if (gameOver_) return; } if (needSpawnBalls_) { for (int i = 0; i < numAddBalls_; i++) { if (!SpawnBall()) { gameOver_ = true; return; } } if (difficulty_ <= D_NORMAL) { for (int i = 0; i < numAddBalls_; i++) CreateBall(true); } needSpawnBalls_ = false; } UIElement* uiRoot = GetSubsystem<UI>()->GetRoot(); Text* t = static_cast<Text*>(uiRoot->GetChild("Score", true)); t->SetText("Score: " + String(score_)); t = static_cast<Text*>(uiRoot->GetChild("Colors", true)); t->SetText("Colors: " + String(numColors_)); t = static_cast<Text*>(uiRoot->GetChild("LineLength", true)); t->SetText("Line length: " + String(lineLength_)); t = static_cast<Text*>(uiRoot->GetChild("Record", true)); t->SetText("Record: " + String(record_)); // нужно выбрасывать шары если после уделаения линий поле пустое }
void test() { GraphicsEngine* ge = GetGraphicsEngine(); // Example of GE useage GraphicsEngine* eng = GetGraphicsEngine(); eng->GetCamera()->setPosition(D3DXVECTOR3(0, 15, -15.6f)); eng->GetCamera()->LookAt(D3DXVECTOR3(30, 10, 10)); StaticMesh* testBall = eng->CreateStaticMesh("Media/Ball.obj", D3DXVECTOR3(8, 15, 8)); StaticMesh* testCylinder = eng->CreateStaticMesh("Media/Cylinder.obj", D3DXVECTOR3(10, 10, 10)); StaticMesh* bth = eng->CreateStaticMesh("Media/bth.obj", D3DXVECTOR3(5, 20, 15)); AnimatedMesh* flag = eng->CreateAnimatedMesh("Media/FlagRed.ani", D3DXVECTOR3(8, 15, 8)); flag->LoopSeamless(); AnimatedMesh* flagb = eng->CreateAnimatedMesh("Media/FlagBlue.ani", D3DXVECTOR3(10, 15, 8)); flagb->LoopSeamless(); StaticMesh* flag1 = eng->CreateStaticMesh("Media/FlagBlue1.obj", D3DXVECTOR3(12, 15, 8)); StaticMesh* flag2 = eng->CreateStaticMesh("Media/FlagBlue2.obj", D3DXVECTOR3(14, 15, 8)); StaticMesh* flag3 = eng->CreateStaticMesh("Media/FlagBlue3.obj", D3DXVECTOR3(16, 15, 8)); StaticMesh* flag4 = eng->CreateStaticMesh("Media/FlagBlue4.obj", D3DXVECTOR3(18, 15, 8)); StaticMesh* flag5 = eng->CreateStaticMesh("Media/FlagBlue5.obj", D3DXVECTOR3(20, 15, 8)); StaticMesh* ball1 = eng->CreateStaticMesh("Media/Ball1.obj", D3DXVECTOR3(12, 30, 8)); StaticMesh* ball2 = eng->CreateStaticMesh("Media/Ball2.obj", D3DXVECTOR3(14, 30, 8)); StaticMesh* ball3 = eng->CreateStaticMesh("Media/Ball3.obj", D3DXVECTOR3(16, 30, 8)); StaticMesh* ball4 = eng->CreateStaticMesh("Media/Ball4.obj", D3DXVECTOR3(18, 30, 8)); //StaticMesh* wlmap = eng->CreateStaticMesh("Media/WarlockMap.obj", D3DXVECTOR3(100, 4, 8)); //StaticMesh* hb = eng->CreateStaticMesh("Media/HardenedBall.obj", D3DXVECTOR3(12, 15, 12)); bth->Scale(0.1f); Light* testLight = eng->CreateLight(D3DXVECTOR3(15, 30, 15)); testLight->SetLookAt(testBall->GetPosition()); //testBall->SetSpecialColor(RED_COLOR); //testCylinder->SetSpecialColor(GREEN_COLOR); //AnimatedMesh* ani = eng->CreateAnimatedMesh("Media/AniTest.ani", D3DXVECTOR3(12, 16, 12)); //ani->LoopNormal(); //ani->LoopSeamless(); SoundEngine* seng = eng->GetSoundEngine(); SoundEffect* se1 = seng->LoadSoundEffect("Media/Sounds/SoundEffects/ball_vs_ball.mp3", false); //SoundEffect* se2 = seng->LoadSoundEffect("Media/Sounds/SoundEffects/ball_vs_wall.mp3", false); //SoundSong* ss1 = seng->LoadSong("Media/Sounds/Songs/america_fuck_yeah.mp3", true); seng->SetMasterVolume(0.5f); //ss1->Play(); //eng->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png"); // going to LoadingScreen to load the above meshes //eng->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png", 0.0f, 1.0f, 1.0f, 1.0f); eng->LoadingScreen("Media/LoadingScreen/StartScreen.png", "", 0.0f, 1.0f, 1.0f, 1.0f); Text* text = eng->CreateText("Lol ", D3DXVECTOR2(500, 500), 1.0f, "Media/Fonts/1"); //Image* testImg = eng->CreateImage(D3DXVECTOR2(50, 50), D3DXVECTOR2(500, 75), "Media/PowerBall.png"); //testLight->SetPosition(testBall->GetPosition() + D3DXVECTOR3(0, 5, 0)); //testLight->SetLookAt(testLight->GetPosition() - D3DXVECTOR3(0, 5, 0)); //Light* testLight2 = eng->CreateLight(D3DXVECTOR3(3, 20, 3)); CamRecording* camRec = new CamRecording(2000, true); // How many milliseconds between each way point camRec->Init(eng->GetCamera()); /*camRec->AddCameraWaypoint(D3DXVECTOR3(0, 0, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 30, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(30, 30, 30), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(-20, 20, 30), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 50, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 20, 0), D3DXVECTOR3(8, 16, 8));*/ //camRec->Load(CIRCLE_AROUND); camRec->CircleAround(true, 50, 1000, 0, D3DXVECTOR3(30, 50, 0), D3DXVECTOR3(0,0,30)); bool sw = true; float size = 1.0f; bool go = true; while(eng->isRunning() && go) // Returns true as long as ESC hasnt been pressed, if it's pressed the game engine will shut down itself (to be changed) { float diff = eng->Update(); // Updates camera etc, does NOT render the frame, another process is doing that, so diff should be very low. text->SetText("Distance to Lava: " + MaloW::convertNrToString(eng->GetCamera()->getPosition().y - eng->GetLavaHeightAt(eng->GetCamera()->getPosition().x, eng->GetCamera()->getPosition().z))); //testBall->Rotate(D3DXVECTOR3(2*PI, 0, 0) * (diff/1000.0f)); // Divide diff by 1000 to get seconds since diff is in milliseconds. testBall->RotateAxis(D3DXVECTOR3(2, 0, 0), 2* PI * (diff/1000.0f)); // Divide diff by 1000 to get seconds since diff is in milliseconds. CursorControl cc; if(eng->GetKeyListener()->IsPressed('W')) eng->GetCamera()->moveForward(diff); if(eng->GetKeyListener()->IsPressed(VK_RETURN)) // For keys other than the main-chars you use the VK_ Enums, rightclick on VK_RETURN and "Go to definition" to find the list of all keys cc.SetVisibility(true); if(eng->GetKeyListener()->IsPressed('A')) eng->GetCamera()->moveLeft(diff); if(eng->GetKeyListener()->IsPressed('S')) eng->GetCamera()->moveBackward(diff); if(eng->GetKeyListener()->IsPressed('D')) eng->GetCamera()->moveRight(diff); if(eng->GetKeyListener()->IsPressed(VK_ESCAPE)) go = false; if(eng->GetKeyListener()->IsPressed(VK_BACK)) { if(sw) { //se1->Play(); text->DeleteFromEnd(1); } sw = false; } else sw = true; if(eng->GetKeyListener()->IsClicked(1)) { size += diff * 0.001f; text->SetSize(size); //ss1->SetVolume(0.5f); text->AppendText("LoL "); //ss1->Play(); } //else //se1->Play(); if(eng->GetKeyListener()->IsClicked(2)) { testBall->UseInvisibilityEffect(true); } else testBall->UseInvisibilityEffect(false); if(eng->GetKeyListener()->IsPressed('G')) { //ani->LoopNormal(); flag->LoopNormal(); flagb->LoopNormal(); eng->GetEngineParameters().FXAAQuality = 4; ge->GetEngineParameters().FXAAQuality = 4; //camRec->Play(); // Play to start moving the camera along the path } camRec->Update(diff); // update needed to move the camera when play is initialized. if(eng->GetKeyListener()->IsPressed('V')) { //ani->NoLooping(); flag->NoLooping(); flagb->NoLooping(); } if(eng->GetKeyListener()->IsPressed('B')) { //ani->LoopSeamless(); flag->LoopSeamless(); flagb->LoopSeamless(); eng->GetEngineParameters().FXAAQuality = 0; //ge->GetEngineParameters().FXAAQuality = 0; for(int i = 0; i < 200; i++) { //se1->Play(); } } } // Delete camera recording delete camRec; }
void Urho2DPlatformer::HandleCollisionBegin(PhysicsWorld2D *, RigidBody2D *, RigidBody2D *, Node *nodeA, Node * nodeB, const std::vector<uint8_t> &, CollisionShape2D *, CollisionShape2D *) { // Get colliding node auto* hitNode = nodeA; if (hitNode->GetName() == "Imp") hitNode = nodeB; QString nodeName = hitNode->GetName(); Node* character2DNode = scene_->GetChild("Imp", true); // Handle ropes and ladders climbing if (nodeName == "Climb") { if (character2D_->isClimbing_) // If transition between rope and top of rope (as we are using split triggers) character2D_->climb2_ = true; else { character2D_->isClimbing_ = true; auto* body = character2DNode->GetComponent<RigidBody2D>(); body->SetGravityScale(0.0f); // Override gravity so that the character doesn't fall // Clear forces so that the character stops (should be performed by setting linear velocity to zero, but currently doesn't work) body->SetLinearVelocity(Vector2(0.0f, 0.0f)); body->SetAwake(false); body->SetAwake(true); } } if (nodeName == "CanJump") character2D_->aboveClimbable_ = true; // Handle coins picking if (nodeName == "Coin") { hitNode->Remove(); character2D_->remainingCoins_ -= 1; auto* ui = GetContext()->m_UISystem.get(); if (character2D_->remainingCoins_ == 0) { Text* instructions = static_cast<Text*>(ui->GetRoot()->GetChild("Instructions", true)); instructions->SetText("!!! Go to the Exit !!!"); } Text* coinsText = static_cast<Text*>(ui->GetRoot()->GetChild("CoinsText", true)); coinsText->SetText(QString(character2D_->remainingCoins_)); // Update coins UI counter sample2D_->PlaySoundEffect("Powerup.wav"); } // Handle interactions with enemies if (nodeName == "Enemy" || nodeName == "Orc") { auto* animatedSprite = character2DNode->GetComponent<AnimatedSprite2D>(); float deltaX = character2DNode->GetPosition().x_ - hitNode->GetPosition().x_; // Orc killed if character is fighting in its direction when the contact occurs (flowers are not destroyable) if (nodeName == "Orc" && animatedSprite->GetAnimation() == "attack" && (deltaX < 0 == animatedSprite->GetFlipX())) { static_cast<Mover*>(hitNode->GetComponent<Mover>())->emitTime_ = 1; if (!hitNode->GetChild("Emitter", true)) { hitNode->GetComponent("RigidBody2D")->Remove(); // Remove Orc's body sample2D_->SpawnEffect(hitNode); sample2D_->PlaySoundEffect("BigExplosion.wav"); } } // Player killed if not fighting in the direction of the Orc when the contact occurs, or when colliding with a flower else { if (!character2DNode->GetChild("Emitter", true)) { character2D_->wounded_ = true; if (nodeName == "Orc") { auto* orc = static_cast<Mover*>(hitNode->GetComponent<Mover>()); orc->fightTimer_ = 1; } sample2D_->SpawnEffect(character2DNode); sample2D_->PlaySoundEffect("BigExplosion.wav"); } } } // Handle exiting the level when all coins have been gathered if (nodeName == "Exit" && character2D_->remainingCoins_ == 0) { // Update UI auto* ui = GetContext()->m_UISystem.get(); Text* instructions = static_cast<Text*>(ui->GetRoot()->GetChild("Instructions", true)); instructions->SetText("!!! WELL DONE !!!"); instructions->SetPosition(IntVector2(0, 0)); // Put the character outside of the scene and magnify him character2DNode->SetPosition(Vector3(-20.0f, 0.0f, 0.0f)); character2DNode->SetScale(1.5f); } // Handle falling into lava if (nodeName == "Lava") { auto* body = character2DNode->GetComponent<RigidBody2D>(); body->ApplyForceToCenter(Vector2(0.0f, 1000.0f), true); if (!character2DNode->GetChild("Emitter", true)) { character2D_->wounded_ = true; sample2D_->SpawnEffect(character2DNode); sample2D_->PlaySoundEffect("BigExplosion.wav"); } } // Handle climbing a slope if (nodeName == "Slope") character2D_->onSlope_ = true; }
void FileSelector::RefreshFiles() { FileSystem* fileSystem = GetSubsystem<FileSystem>(); if (!fileSystem) return; ignoreEvents_ = true; fileList_->RemoveAllItems(); fileEntries_.Clear(); Vector<String> directories; Vector<String> files; fileSystem->ScanDir(directories, path_, "*", SCAN_DIRS, false); fileSystem->ScanDir(files, path_, GetFilter(), SCAN_FILES, false); fileEntries_.Reserve(directories.Size() + files.Size()); for (unsigned i = 0; i < directories.Size(); ++i) { FileSelectorEntry newEntry; newEntry.name_ = directories[i]; newEntry.directory_ = true; fileEntries_.Push(newEntry); } for (unsigned i = 0; i < files.Size(); ++i) { FileSelectorEntry newEntry; newEntry.name_ = files[i]; newEntry.directory_ = false; fileEntries_.Push(newEntry); } // Sort and add to the list view // While items are being added, disable layout update for performance optimization Sort(fileEntries_.Begin(), fileEntries_.End(), CompareEntries); UIElement* listContent = fileList_->GetContentElement(); listContent->DisableLayoutUpdate(); for (unsigned i = 0; i < fileEntries_.Size(); ++i) { String displayName; if (fileEntries_[i].directory_) displayName = "<DIR> " + fileEntries_[i].name_; else displayName = fileEntries_[i].name_; Text* entryText = new Text(context_); fileList_->AddItem(entryText); entryText->SetText(displayName); entryText->SetStyle("FileSelectorListText"); } listContent->EnableLayoutUpdate(); listContent->UpdateLayout(); ignoreEvents_ = false; // Clear filename from the previous dir so that there is no confusion SetFileName(String::EMPTY); lastUsedFilter_ = GetFilter(); }