#include "MainMenu.h"
#include "Game.h"
MainMenu::MainMenu()
{
}
void MainMenu::init()
{
this->view = IwGetUIView();
this->controller = IwGetUIController();
CIwResGroup* pResGroup = IwGetResManager()->LoadGroup("main_menu.group");
// this->create_button_style();
IwGetUIStyleManager()->SetStylesheet(this->CreateStyles());
//CIwUIElement* pElement = new CIwUIElement;
CIwUIElement* pDialog = CreateDialog();
this->view->AddElementToLayout(pDialog);
}
CIwUIElement* MainMenu::CreateDialog()
{
// Create scrollable view with vertical layout
CIwUILayoutGrid* pLayout = new CIwUILayoutGrid;
for(int i = 0; i < 4; i++)
{
pLayout->AddColumn();
}
for(int i = 0; i < 15 ; i++)
{
pLayout->AddRow();
}
CIwUIButton* pStartButton = new CIwUIButton;
pStartButton->SetStyle("<button>");
pStartButton->SetCaption("START");
CIwUIButton* pContinueButton = new CIwUIButton;
pContinueButton->SetStyle("<button>");
pContinueButton->SetCaption("CONTINUE");
CIwUIButton* pOptionButton = new CIwUIButton;
pOptionButton->SetStyle("<button>");
pOptionButton->SetCaption("OPTIONS");
CIwUIButton* pExtraButton = new CIwUIButton;
pExtraButton->SetStyle("<button>");
pExtraButton->SetCaption("EXTRA");
CIwUIImage* pImage = new CIwUIImage;
pImage->SetTexture(GetTexture("start"));
pImage->SetSizeToContent(true);
// pButton->AttachClickSlot("RequestQuit");
//pLayout->AddElement(pImage,0,0);
pLayout->AddElement(pStartButton, 2,9);
pLayout->AddElement(pContinueButton,2, 10);
//pLayout->AddElement(pOptionButton,2, 11);
//pLayout->AddElement(pExtraButton,2, 12);
CIwUIScrollableView* pContainer = new CIwUIScrollableView;
pContainer->SetSizeToContent(true);
pContainer->AddChild(pImage);//SET THE BACKGROUND
pContainer->AddChild(pStartButton);
pContainer->AddChild(pContinueButton);
//pContainer->AddChild(pOptionButton);
//pContainer->AddChild(pExtraButton);
pContainer->SetLayout(pLayout);
return pContainer;
}
CIwUIStylesheet* MainMenu::CreateStyles()
{
// Create stylesheet and make resource manager own it.
CIwUIStylesheet* pStylesheet = new CIwUIStylesheet;
IwGetResManager()->AddRes(IW_UI_RESTYPE_STYLESHEET, pStylesheet);
pStylesheet->AddPropertySet(this->create_button_style());
return pStylesheet;
}
void MainMenu::update(int delta)
{
this->controller->Update();
this->view->Update(delta); //IF I UNCOMMENT THIS IT WILL CENTERS THE BUTTON ELEMENT ON UPDATE
}
void MainMenu::render()
{
this->view->Render();
}
CIwUIPropertySet* MainMenu::create_button_style()
{
// Create button style
CIwUIPropertySet* pButton = new CIwUIPropertySet;
pButton->SetName("<button>");
pButton->SetProperty("font", GetFont("font"));
pButton->SetProperty("sizeToContent", true);
pButton->SetProperty("alignH", IW_UI_ALIGN_CENTRE);
pButton->SetProperty("alignV", IW_UI_ALIGN_MIDDLE);
pButton->SetProperty("sizeMin", CIwVec2(128, 32));
pButton->SetProperty("margin", CIwSVec2(16, 8));
// Create button up style
CIwUIStyle buttonUpStyle;
buttonUpStyle.InlinePropertySet();
CIwUIPropertySet& buttonUp = *buttonUpStyle.GetInlinePropertySet();
buttonUp.SetProperty("drawableType", IwHashString("border"));
buttonUp.SetProperty("border", CIwSVec2(3, 3));
buttonUp.SetProperty("texture", GetTexture("buttonUp"));
// Create button down style
CIwUIStyle buttonDownStyle;
buttonDownStyle.InlinePropertySet();
CIwUIPropertySet& buttonDown = *buttonDownStyle.GetInlinePropertySet();
buttonDown.SetProperty("drawableType", IwHashString("border"));
buttonDown.SetProperty("border", CIwSVec2(13, 13));
buttonDown.SetProperty("texture", GetTexture("buttonDown"));
// Attach inline styles to main style
pButton->SetProperty("buttonUp", buttonUpStyle);
pButton->SetProperty("buttonDown", buttonDownStyle);
return pButton;
}
CIwTexture* MainMenu::GetTexture(const char* pTextureName)
{
return IwSafeCast<CIwTexture*>(
IwGetResManager()->GetResNamed(pTextureName, IW_GX_RESTYPE_TEXTURE));
}
CIwGxFont* MainMenu::GetFont(const char* pFontName)
{
return IwSafeCast<CIwGxFont*>(
IwGetResManager()->GetResNamed(pFontName, IW_GX_RESTYPE_FONT));
}