Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualJuliean

Posted 21 September 2013 - 04:22 AM

Have you ever been told, or told someone not to unroll their own gui framework but to rely on the established available libaries? Well, this pretty much shows why they are right:

TowerStateCtrl::TowerStateCtrl(gui::Widget& parent, const ecs::Entity& tower, const ecs::MessageManager& messages): m_pTower(&tower), m_pMessages(&messages)
{
    gui::Area& area = AddWidget<gui::Area>(0, 0, parent.GetWidth(), parent.GetHeight());
    SetAsMainWidget(&area);
    parent.AddChild(area);

    const int imageX = parent.GetWidth()/12;
    const int imageY = parent.GetHeight()/12;
    const int imageWidth = parent.GetWidth() - imageX*2;
    const int imageHeight = parent.GetHeight() - (int)(imageY*3.75f);
    AddWidget<gui::Image>(imageX, imageY, imageWidth, imageHeight, L"GuiStateback");

    const Tower* pTower = m_pTower->GetComponent<Tower>();

    // name display
    m_pNameLabel = &AddWidget<gui::Label>(0, area.GetHeight() / 16, area.GetWidth(), 32, pTower->m_stName.c_str());

    const int iconSize = area.GetWidth() / 20;
    const int iconOffsetX = area.GetWidth() / 8;

    const int offsetX = iconOffsetX + iconOffsetX;
    const int offsetY = area.GetHeight() / 7;
    const int halfWidth = area.GetWidth() / 2;

    const int labelWidth = halfWidth - offsetX;
    const int labelOffsetX = offsetX + labelWidth;

    // damage display
    AddWidget<gui::Image>(iconOffsetX, offsetY, iconSize, iconSize, L"IcoThunder");
    gui::Label& damageLabel = AddWidget<gui::Label>(offsetX, offsetY, labelWidth, 32, L"Damage");
    damageLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pDamageLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY, labelWidth, 32, conv::ToString( pTower->m_atk ).c_str() );
    m_pDamageLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // speed display
    AddWidget<gui::Image>(iconOffsetX, offsetY*2, iconSize, iconSize, L"IcoHourglass");
    gui::Label& speedLabel = AddWidget<gui::Label>(offsetX, offsetY*2, labelWidth, 32, L"Speed");
    speedLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pSpeedLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*2, labelWidth, 32, conv::ToString( pTower->m_speed ).c_str() );
    m_pSpeedLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // range display
    AddWidget<gui::Image>(iconOffsetX, offsetY*3, iconSize, iconSize, L"IcoWorld");
    gui::Label& rangeLabel = AddWidget<gui::Label>(offsetX, offsetY*3, labelWidth, 32, L"Range");
    rangeLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pRangeLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*3, labelWidth, 32, conv::ToString( pTower->m_range ).c_str() );
    m_pRangeLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // level display
    AddWidget<gui::Image>(iconOffsetX, offsetY*4, iconSize, iconSize, L"IcoStar");
    gui::Label& levelLabel = AddWidget<gui::Label>(offsetX, offsetY*4, labelWidth, 32, L"Level");
    levelLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pLevelLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*4, labelWidth, 32, conv::ToString( pTower->m_level + 1 ).c_str() );
    m_pLevelLabel->SetAlign(gui::RIGHT | gui::VCENTER);

	// upgrade button
    const int buttonY = (int)(offsetY * 5.75f);
	m_pUpgradeButton = &AddWidget<gui::Button>(16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Upgrade:" + conv::ToString( 50 )).c_str() );
	m_pUpgradeButton->SigReleased.Connect(this, &TowerStateCtrl::OnUpgradeTower);

    const int iconOff = (m_pUpgradeButton->GetHeight() - iconSize) / 2;
    gui::Image& sell = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoUpgrade");
	sell.OnDisable();
    m_pUpgradeButton->AddChild(sell);

    // sell button
    m_pSellButton = &AddWidget<gui::Button>(halfWidth + 16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Sell:" + conv::ToString( (int)(pTower->m_cost * 0.75) )).c_str() );
    m_pSellButton->SigReleased.Connect(this, &TowerStateCtrl::OnSellTower);

    gui::Image& money = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoMoney");
	money.OnDisable();
    m_pSellButton->AddChild(money);

    Update();

    OnFocus(true);
}

That monstrousity just to display a small status-widget, without any functionality mind you. I probably could have used more constants (yieks!) or seperated this huge method into smaller ones, but its a mess anyway. Anyone else here who encountered their own "gui horrors"? biggrin.png


#2Juliean

Posted 21 September 2013 - 04:21 AM

Have you ever been told, or told someone not to unroll their own gui framework but to rely on the established available libaries? Well, this pretty much shows why this is true:

TowerStateCtrl::TowerStateCtrl(gui::Widget& parent, const ecs::Entity& tower, const ecs::MessageManager& messages): m_pTower(&tower), m_pMessages(&messages)
{
    gui::Area& area = AddWidget<gui::Area>(0, 0, parent.GetWidth(), parent.GetHeight());
    SetAsMainWidget(&area);
    parent.AddChild(area);

    const int imageX = parent.GetWidth()/12;
    const int imageY = parent.GetHeight()/12;
    const int imageWidth = parent.GetWidth() - imageX*2;
    const int imageHeight = parent.GetHeight() - (int)(imageY*3.75f);
    AddWidget<gui::Image>(imageX, imageY, imageWidth, imageHeight, L"GuiStateback");

    const Tower* pTower = m_pTower->GetComponent<Tower>();

    // name display
    m_pNameLabel = &AddWidget<gui::Label>(0, area.GetHeight() / 16, area.GetWidth(), 32, pTower->m_stName.c_str());

    const int iconSize = area.GetWidth() / 20;
    const int iconOffsetX = area.GetWidth() / 8;

    const int offsetX = iconOffsetX + iconOffsetX;
    const int offsetY = area.GetHeight() / 7;
    const int halfWidth = area.GetWidth() / 2;

    const int labelWidth = halfWidth - offsetX;
    const int labelOffsetX = offsetX + labelWidth;

    // damage display
    AddWidget<gui::Image>(iconOffsetX, offsetY, iconSize, iconSize, L"IcoThunder");
    gui::Label& damageLabel = AddWidget<gui::Label>(offsetX, offsetY, labelWidth, 32, L"Damage");
    damageLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pDamageLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY, labelWidth, 32, conv::ToString( pTower->m_atk ).c_str() );
    m_pDamageLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // speed display
    AddWidget<gui::Image>(iconOffsetX, offsetY*2, iconSize, iconSize, L"IcoHourglass");
    gui::Label& speedLabel = AddWidget<gui::Label>(offsetX, offsetY*2, labelWidth, 32, L"Speed");
    speedLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pSpeedLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*2, labelWidth, 32, conv::ToString( pTower->m_speed ).c_str() );
    m_pSpeedLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // range display
    AddWidget<gui::Image>(iconOffsetX, offsetY*3, iconSize, iconSize, L"IcoWorld");
    gui::Label& rangeLabel = AddWidget<gui::Label>(offsetX, offsetY*3, labelWidth, 32, L"Range");
    rangeLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pRangeLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*3, labelWidth, 32, conv::ToString( pTower->m_range ).c_str() );
    m_pRangeLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // level display
    AddWidget<gui::Image>(iconOffsetX, offsetY*4, iconSize, iconSize, L"IcoStar");
    gui::Label& levelLabel = AddWidget<gui::Label>(offsetX, offsetY*4, labelWidth, 32, L"Level");
    levelLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pLevelLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*4, labelWidth, 32, conv::ToString( pTower->m_level + 1 ).c_str() );
    m_pLevelLabel->SetAlign(gui::RIGHT | gui::VCENTER);

	// upgrade button
    const int buttonY = (int)(offsetY * 5.75f);
	m_pUpgradeButton = &AddWidget<gui::Button>(16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Upgrade:" + conv::ToString( 50 )).c_str() );
	m_pUpgradeButton->SigReleased.Connect(this, &TowerStateCtrl::OnUpgradeTower);

    const int iconOff = (m_pUpgradeButton->GetHeight() - iconSize) / 2;
    gui::Image& sell = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoUpgrade");
	sell.OnDisable();
    m_pUpgradeButton->AddChild(sell);

    // sell button
    m_pSellButton = &AddWidget<gui::Button>(halfWidth + 16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Sell:" + conv::ToString( (int)(pTower->m_cost * 0.75) )).c_str() );
    m_pSellButton->SigReleased.Connect(this, &TowerStateCtrl::OnSellTower);

    gui::Image& money = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoMoney");
	money.OnDisable();
    m_pSellButton->AddChild(money);

    Update();

    OnFocus(true);
}

That monstrousity just to display a small status-widget, without any functionality mind you. I probably could have used more constants (yieks!) or seperated this huge method into smaller ones, but its a mess anyway. Anyone else here who encountered their own "gui horrors"? biggrin.png


#1Juliean

Posted 21 September 2013 - 04:18 AM

Have you ever been told, or told someone not to unroll their own gui framework but to rely on the established available libaries? Well, this pretty much shows why this is true:

TowerStateCtrl::TowerStateCtrl(gui::Widget& parent, const ecs::Entity& tower, const ecs::MessageManager& messages): m_pTower(&tower), m_pMessages(&messages)
{
    gui::Area& area = AddWidget<gui::Area>(0, 0, parent.GetWidth(), parent.GetHeight());
    SetAsMainWidget(&area);
    parent.AddChild(area);

    const int imageX = parent.GetWidth()/12;
    const int imageY = parent.GetHeight()/12;
    const int imageWidth = parent.GetWidth() - imageX*2;
    const int imageHeight = parent.GetHeight() - (int)(imageY*3.75f);
    AddWidget<gui::Image>(imageX, imageY, imageWidth, imageHeight, L"GuiStateback");

    const Tower* pTower = m_pTower->GetComponent<Tower>();

    // name display
    m_pNameLabel = &AddWidget<gui::Label>(0, area.GetHeight() / 16, area.GetWidth(), 32, pTower->m_stName.c_str());

    const int iconSize = area.GetWidth() / 20;
    const int iconOffsetX = area.GetWidth() / 8;

    const int offsetX = iconOffsetX + iconOffsetX;
    const int offsetY = area.GetHeight() / 7;
    const int halfWidth = area.GetWidth() / 2;

    const int labelWidth = halfWidth - offsetX;
    const int labelOffsetX = offsetX + labelWidth;

    // damage display
    AddWidget<gui::Image>(iconOffsetX, offsetY, iconSize, iconSize, L"IcoThunder");
    gui::Label& damageLabel = AddWidget<gui::Label>(offsetX, offsetY, labelWidth, 32, L"Damage");
    damageLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pDamageLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY, labelWidth, 32, conv::ToString( pTower->m_atk ).c_str() );
    m_pDamageLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // speed display
    AddWidget<gui::Image>(iconOffsetX, offsetY*2, iconSize, iconSize, L"IcoHourglass");
    gui::Label& speedLabel = AddWidget<gui::Label>(offsetX, offsetY*2, labelWidth, 32, L"Speed");
    speedLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pSpeedLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*2, labelWidth, 32, conv::ToString( pTower->m_speed ).c_str() );
    m_pSpeedLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // range display
    AddWidget<gui::Image>(iconOffsetX, offsetY*3, iconSize, iconSize, L"IcoWorld");
    gui::Label& rangeLabel = AddWidget<gui::Label>(offsetX, offsetY*3, labelWidth, 32, L"Range");
    rangeLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pRangeLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*3, labelWidth, 32, conv::ToString( pTower->m_range ).c_str() );
    m_pRangeLabel->SetAlign(gui::RIGHT | gui::VCENTER);

    // level display
    AddWidget<gui::Image>(iconOffsetX, offsetY*4, iconSize, iconSize, L"IcoStar");
    gui::Label& levelLabel = AddWidget<gui::Label>(offsetX, offsetY*4, labelWidth, 32, L"Level");
    levelLabel.SetAlign(gui::LEFT | gui::VCENTER);
    m_pLevelLabel = &AddWidget<gui::Label>(labelOffsetX, offsetY*4, labelWidth, 32, conv::ToString( pTower->m_level + 1 ).c_str() );
    m_pLevelLabel->SetAlign(gui::RIGHT | gui::VCENTER);

	// upgrade button
    const int buttonY = (int)(offsetY * 5.75f);
	m_pUpgradeButton = &AddWidget<gui::Button>(16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Upgrade:" + conv::ToString( 50 )).c_str() );
	m_pUpgradeButton->SigReleased.Connect(this, &TowerStateCtrl::OnUpgradeTower);

    const int iconOff = (m_pUpgradeButton->GetHeight() - iconSize) / 2;
    gui::Image& sell = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoUpgrade");
	sell.OnDisable();
    m_pUpgradeButton->AddChild(sell);

    // sell button
    m_pSellButton = &AddWidget<gui::Button>(halfWidth + 16, buttonY, halfWidth - 32, area.GetHeight() / 6, (L"Sell:" + conv::ToString( (int)(pTower->m_cost * 0.75) )).c_str() );
    m_pSellButton->SigReleased.Connect(this, &TowerStateCtrl::OnSellTower);

    gui::Image& money = AddWidget<gui::Image>(iconOff, iconOff, iconSize, iconSize, L"IcoMoney");
	money.OnDisable();
    m_pSellButton->AddChild(money);

    Update();

    OnFocus(true);
}

That monstrousity just to display a small status-widget, without any functionality mind you. I probably could have used more constants (yieks!) or seperated this huge method into smaller ones, but its a mess anyway. Anyone else here who encountered their own "gui horrors"? :D


PARTNERS