Exemple #1
0
void TabStrip::AddTab(string name)
{
	Label* label = new Label();
	label->SetSize(tabSize);
	label->SetLayoutMargin(Box(0, 0, 10, 10));
	label->SetGravity(GRAVITY_VCENTER | GRAVITY_HCENTER);
	label->SetText(name);
	label->SetParentView(this);
	label->SetRelativePosition(0, 0);
	label->SetTextSize(18);
	if (IsInitialized())
	{
		label->Initialize(context);
		label->CalculateLayout(Size(-1, -1));
	}

	tabs.push_back(label);
}
	//////////////////////////////
	// Level load Functions - UI
	//////////////////////////////
	void UIManager::Standard_Gameplay_UI()
	{
		std::vector<IUI_Object*> uiObjects;

		//////////////////////////////////////////////////////////////
		// Create UI objects for this setup (STANDARD_GAMEPLAY_UI)
		//
		// Note: This requires that there be an active camera set in
		// the g_Engine global reference.
		//////////////////////////////////////////////////////////////
		if (g_Engine->GetActiveCamera() != nullptr)
		{
			// Set up label dimensions and offset
			float lWidth = 200.0f;
			float lHeight = 75.0f;
			float offsetX = -((SCREENW / 2) * g_Engine->GetActiveCamera()->GetZoomFactor()) + 10;
			float offsetY = -((SCREENH / 2) * g_Engine->GetActiveCamera()->GetZoomFactor()) + 7.5f;

			#pragma region UIObjectCreation
			Label* pTemp = g_Engine->GetFactory()->CreateObject<Label>();
			if (pTemp)
			{
				pTemp->Initialize("Calibri", 10, offsetX, offsetY,
					"Health: ", LABELTEXTURES::STANDARD_LABEL_TEXTURE);

				// Health label
				Label* pTempLabel = g_Engine->GetFactory()->CreateObject<Label>();
				if (pTempLabel)
				{
					pTempLabel->Initialize("Calibri", 14, offsetX, offsetY,
						"Health:", LABELTEXTURES::STANDARD_LABEL_TEXTURE);

					uiObjects.push_back(pTempLabel);
					pTempLabel = nullptr;
				}
				else
					debug << "\tFailed to create 'Label - Health' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Hearts - 1
				PicBox* pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 40;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "heart.png", "heart");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - Heart' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Hearts - 2
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "heart.png", "heart");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - Heart' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Hearts - 3
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "heart.png", "heart");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - Heart' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Hearts - 4
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "heart.png", "heart");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - Heart' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Hearts - 5
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "heart.png", "heart");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - Heart' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Lives Label
				pTempLabel = g_Engine->GetFactory()->CreateObject<Label>();
				if (pTempLabel)
				{
					offsetX += 25;
					pTempLabel->Initialize("Calibri", 14, offsetX, offsetY,
						"Lives:", LABELTEXTURES::STANDARD_LABEL_TEXTURE);

					uiObjects.push_back(pTempLabel);
					pTempLabel = nullptr;
				}
				else
					debug << "\tFailed to create 'Label - Lives' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Player lives icon - 1
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 32;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "player_icon.png", "player_life");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - PlayerIcon' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Player lives icon - 2
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "player_icon.png", "player_life");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - PlayerIcon' in STANDARD_GAMEPLAY_UI" << std::endl;

				// Player lives icon - 3
				pTempPic = g_Engine->GetFactory()->CreateObject<PicBox>();
				if (pTempPic)
				{
					offsetX += 16;
					pTempPic->Initialize(16, 16, offsetX, offsetY,
						true, "player_icon.png", "player_life");

					uiObjects.push_back(pTempPic);
					pTempPic = nullptr;
				}
				else
					debug << "\tFailed to create 'PicBox - PlayerIcon' in STANDARD_GAMEPLAY_UI" << std::endl;
			}
			#pragma endregion			
		}

		// Set the UI Objects
		SetUIObjects(uiObjects);
	}