void StatsPanel::SetUpCombatantMap(){ int labelsPosX[] = {5,170,5,170,5,5}; int labelsPosY[] = {160,160,230,230,300,370}; std::string labelsString[] = {"Strength","Endure","Technique","Speed","Health","Endurance"}; for (int x = 0; x < 6; x++){ Label* element = new Label(labelsPosX[x],labelsPosY[x],"blank.png",Label::Fonts::Game,labelsString[x] + ":"); AddCombatantElement(MyPair(std::to_string(x), element)); if(x < 4){ Label* valueElement = new Label(labelsPosX[x] + element->GetText()->getLocalBounds().width + 15,labelsPosY[x],"blank.png",Label::Fonts::Game,"null"); AddCombatantElement(MyPair(labelsString[x] + "Value",valueElement)); } else{ float tempFloat = 1; ProgressBar* progBar = new ProgressBar(labelsPosX[x] + element->GetText()->getLocalBounds().width + 15,labelsPosY[x], 180, &tempFloat); AddCombatantElement(MyPair(labelsString[x] + "Bar",progBar)); } } Button* tempButton = new Button(127.5,15,"attacktextures/background.png","attacktextures/default.png"); tempButton->SetTarget(this); tempButton->SetFunction("none"); tempButton->CenterForeground(); AddCombatantElement(MyPair("Image",tempButton)); Label* label = new Label(103,110,120,"menubackground.png",Label::Fonts::Game,"null"); label->CenterText(); AddCombatantElement(MyPair("Name",label)); Drawn* barPlaceHolder = new Drawn("blank.png"); barPlaceHolder->SetPosition(sf::Vector2f(0,0)); barPlaceHolder->texturePart.height = 35; barPlaceHolder->texturePart.width = GetSize().x; barPlaceHolder->SetRotation(0); barPlaceHolder->SetZ(2); combatantMap.insert(MyPair("barPlaceHolder",barPlaceHolder)); };
void RClickMenu::SetOrgin(Orgins orgin){ for(int x = 0; x < labels.size(); x++){ Label* tempLabel = labels[x]; sf::Sprite* tempSprite = tempLabel->GetSprite(); sf::Vector2f halfSize = sf::Vector2f(tempLabel->GetSize().x / 2,tempLabel->GetSize().y / 2); sf::Text* tempText = tempLabel->GetText(); switch(orgin){ case(TopLeft): tempLabel->SetOrgin(0,0); tempLabel->CenterText(); break; case(TopRight): tempLabel->SetOrgin(halfSize.x * 2,0); tempLabel->CenterText(); break; case(BottomLeft): tempLabel->SetOrgin(0,halfSize.y * 2); tempLabel->CenterText(); break; case(BottomRight): tempLabel->SetOrgin(halfSize.x * 2,halfSize.y * 2); tempLabel->CenterText(); break; } } };
CGameChapterPanel( CNewGameDialog *parent, const char *name, const char *chapterName, int chapterIndex, const char *chapterNumber, const char *chapterConfigFile, bool bCommentary ) : BaseClass( parent, name ) { Q_strncpy( m_szConfigFile, chapterConfigFile, sizeof(m_szConfigFile) ); Q_strncpy( m_szChapter, chapterNumber, sizeof(m_szChapter) ); m_pLevelPicBorder = SETUP_PANEL( new ImagePanel( this, "LevelPicBorder" ) ); m_pLevelPic = SETUP_PANEL( new ImagePanel( this, "LevelPic" ) ); m_pCommentaryIcon = NULL; m_bCommentaryMode = bCommentary; wchar_t text[32]; wchar_t num[32]; wchar_t *chapter = g_pVGuiLocalize->Find("#GameUI_Chapter"); g_pVGuiLocalize->ConvertANSIToUnicode( chapterNumber, num, sizeof(num) ); _snwprintf( text, sizeof(text), L"%s %s", chapter ? chapter : L"CHAPTER", num ); if ( ModInfo().IsSinglePlayerOnly() ) { m_pChapterLabel = new Label( this, "ChapterLabel", text ); m_pChapterNameLabel = new Label( this, "ChapterNameLabel", chapterName ); } else { m_pChapterLabel = new Label( this, "ChapterLabel", chapterName ); m_pChapterNameLabel = new Label( this, "ChapterNameLabel", "#GameUI_LoadCommentary" ); } SetPaintBackgroundEnabled( false ); // the image has the same name as the config file char szMaterial[ MAX_PATH ]; Q_snprintf( szMaterial, sizeof(szMaterial), "chapters/%s", chapterConfigFile ); char *ext = strstr( szMaterial, "." ); if ( ext ) { *ext = 0; } m_pLevelPic->SetImage( szMaterial ); KeyValues *pKeys = NULL; LoadControlSettings( "Resource/NewGameChapterPanel.res", NULL, pKeys ); int px, py; m_pLevelPicBorder->GetPos( px, py ); SetSize( m_pLevelPicBorder->GetWide(), py + m_pLevelPicBorder->GetTall() ); // create a selection panel the size of the page CSelectionOverlayPanel *overlay = new CSelectionOverlayPanel( this, parent, chapterIndex ); overlay->SetBounds(0, 0, GetWide(), GetTall()); overlay->MoveToFront(); // HACK: Detect new episode teasers by the "Coming Soon" text wchar_t w_szStrTemp[256]; m_pChapterNameLabel->GetText( w_szStrTemp, sizeof(w_szStrTemp) ); m_bTeaserChapter = !wcscmp(w_szStrTemp, L"Coming Soon"); m_bHasBonus = false; }
//--------------------------------------- std::string Button::GetLabel() const { std::string result; Label* labelElement = GetLabelElement(); if( labelElement ) { // Get the text of the label. result = labelElement->GetText(); } else { WarnFail( "Could not get label for Button \"%s\" because no label element \"%s\" was found!", GetFullName().c_str(), mLabelElementName.GetCString() ); } return result; }
void ReflectInterpreter::InterpretType(const std::vector<Reflect::Element*>& instances, Container* parent, i32 includeFlags, i32 excludeFlags, bool expandPanel) { const Class* typeInfo = instances[0]->GetClass(); // create a panel PanelPtr panel = m_Container->GetCanvas()->Create<Panel>(this); // parse ContainerPtr scriptOutput = m_Container->GetCanvas()->Create<Container>(this); tstring typeInfoUI; typeInfo->GetProperty( TXT( "UIScript" ), typeInfoUI ); bool result = Script::Parse(typeInfoUI, this, parent->GetCanvas(), scriptOutput); // compute panel label tstring labelText; if (result) { V_Control::const_iterator itr = scriptOutput->GetControls().begin(); V_Control::const_iterator end = scriptOutput->GetControls().end(); for( ; itr != end; ++itr ) { Label* label = Reflect::ObjectCast<Label>( *itr ); if (label) { bool converted = Helium::ConvertString( label->GetText(), labelText ); HELIUM_ASSERT( converted ); if ( !labelText.empty() ) { break; } } } } if (labelText.empty()) { std::vector<Reflect::Element*>::const_iterator itr = instances.begin(); std::vector<Reflect::Element*>::const_iterator end = instances.end(); for ( ; itr != end; ++itr ) { Reflect::Element* instance = *itr; if ( labelText.empty() ) { labelText = instance->GetTitle(); } else { if ( labelText != instance->GetTitle() ) { labelText.clear(); break; } } } if ( labelText.empty() ) { labelText = typeInfo->m_UIName; } } tstring temp; bool converted = Helium::ConvertString( labelText, temp ); HELIUM_ASSERT( converted ); panel->SetText( temp ); M_Panel panelsMap; panelsMap.insert( std::make_pair( TXT( "" ), panel) ); // don't bother including Element's fields int offset = Reflect::GetClass<Element>()->m_LastFieldID; // for each field in the type M_FieldIDToInfo::const_iterator itr = typeInfo->m_FieldIDToInfo.find(offset + 1); M_FieldIDToInfo::const_iterator end = typeInfo->m_FieldIDToInfo.end(); for ( ; itr != end; ++itr ) { const Field* field = itr->second; bool noFlags = ( field->m_Flags == 0 && includeFlags == 0xFFFFFFFF ); bool doInclude = ( field->m_Flags & includeFlags ) != 0; bool dontExclude = ( excludeFlags == 0 ) || !(field->m_Flags & excludeFlags ); bool hidden = (field->m_Flags & Reflect::FieldFlags::Hide) != 0; // if we don't have flags (or we are included, and we aren't excluded) then make UI if ( ( noFlags || doInclude ) && ( dontExclude ) ) { // // Handle sub panels for grouping content // bool groupExpanded = false; field->GetProperty( TXT( "UIGroupExpanded" ), groupExpanded ); tstring fieldUIGroup; field->GetProperty( TXT( "UIGroup" ), fieldUIGroup ); if ( !fieldUIGroup.empty() ) { M_Panel::iterator itr = panelsMap.find( fieldUIGroup ); if ( itr == panelsMap.end() ) { // This panel isn't in our list so make a new one PanelPtr newPanel = m_Container->GetCanvas()->Create<Panel>(this); panelsMap.insert( std::make_pair(fieldUIGroup, newPanel) ); PanelPtr parent; tstring groupName; size_t idx = fieldUIGroup.find_last_of( TXT( "/" ) ); if ( idx != tstring::npos ) { tstring parentName = fieldUIGroup.substr( 0, idx ); groupName = fieldUIGroup.substr( idx+1 ); if ( panelsMap.find( parentName ) == panelsMap.end() ) { parent = m_Container->GetCanvas()->Create<Panel>(this); // create the parent hierarchy since it hasn't already been made tstring currentParent = parentName; for (;;) { idx = currentParent.find_last_of( TXT( "/" ) ); if ( idx == tstring::npos ) { // no more parents so we add it to the root panelsMap.insert( std::make_pair(currentParent, parent) ); parent->SetText( currentParent ); panelsMap[ TXT( "" ) ]->AddControl( parent ); break; } else { parent->SetText( currentParent.substr( idx+1 ) ); if ( panelsMap.find( currentParent ) != panelsMap.end() ) { break; } else { PanelPtr grandParent = m_Container->GetCanvas()->Create<Panel>(this); grandParent->AddControl( parent ); panelsMap.insert( std::make_pair(currentParent, parent) ); parent = grandParent; } currentParent = currentParent.substr( 0, idx ); } } panelsMap.insert( std::make_pair(parentName, parent) ); } parent = panelsMap[parentName]; } else { parent = panelsMap[ TXT( "" )]; groupName = fieldUIGroup; } newPanel->SetText( groupName ); if( groupExpanded ) { newPanel->SetExpanded( true ); } parent->AddControl( newPanel ); } panel = panelsMap[fieldUIGroup]; } else { panel = panelsMap[ TXT( "" )]; } // // Pointer support // if (field->m_SerializerID == Reflect::GetType<Reflect::PointerSerializer>()) { if (hidden) { continue; } std::vector<Reflect::Element*> fieldInstances; std::vector<Reflect::Element*>::const_iterator elementItr = instances.begin(); std::vector<Reflect::Element*>::const_iterator elementEnd = instances.end(); for ( ; elementItr != elementEnd; ++elementItr ) { uintptr fieldAddress = (uintptr)(*elementItr) + itr->second->m_Offset; Element* element = *((ElementPtr*)(fieldAddress)); if ( element ) { fieldInstances.push_back( element ); } } if ( !fieldInstances.empty() && fieldInstances.size() == instances.size() ) { InterpretType(fieldInstances, panel); } continue; } // // Attempt to find a handler via the factory // ReflectFieldInterpreterPtr fieldInterpreter; for ( const Reflect::Class* type = Registry::GetInstance()->GetClass( field->m_SerializerID ); type != Reflect::GetClass<Reflect::Element>() && !fieldInterpreter; type = Reflect::Registry::GetInstance()->GetClass( type->m_Base ) ) { fieldInterpreter = ReflectFieldInterpreterFactory::Create( type->m_TypeID, field->m_Flags, m_Container ); } if ( fieldInterpreter.ReferencesObject() ) { Interpreter::ConnectInterpreterEvents( this, fieldInterpreter ); fieldInterpreter->InterpretField( field, instances, panel ); m_Interpreters.push_back( fieldInterpreter ); continue; } // // ElementArray support // #pragma TODO("Move this out to an interpreter") if (field->m_SerializerID == Reflect::GetType<ElementArraySerializer>()) { if (hidden) { continue; } if ( instances.size() == 1 ) { uintptr fieldAddress = (uintptr)(instances.front()) + itr->second->m_Offset; V_Element* elements = (V_Element*)fieldAddress; if ( elements->size() > 0 ) { PanelPtr childPanel = panel->GetCanvas()->Create<Panel>( this ); tstring temp; bool converted = Helium::ConvertString( field->m_UIName, temp ); HELIUM_ASSERT( converted ); childPanel->SetText( temp ); V_Element::const_iterator elementItr = elements->begin(); V_Element::const_iterator elementEnd = elements->end(); for ( ; elementItr != elementEnd; ++elementItr ) { std::vector<Reflect::Element*> childInstances; childInstances.push_back(*elementItr); InterpretType(childInstances, childPanel); } panel->AddControl( childPanel ); } } continue; } // // Lastly fall back to the value interpreter // const Reflect::Class* type = Registry::GetInstance()->GetClass( field->m_SerializerID ); if ( !type->HasType( Reflect::GetType<Reflect::ContainerSerializer>() ) ) { fieldInterpreter = CreateInterpreter< ReflectValueInterpreter >( m_Container ); fieldInterpreter->InterpretField( field, instances, panel ); m_Interpreters.push_back( fieldInterpreter ); continue; } } } // Make sure we have the base panel panel = panelsMap[TXT( "" )]; if (parent == m_Container) { panel->SetExpanded(expandPanel); } if ( !panel->GetControls().empty() ) { parent->AddControl(panel); } }