Пример #1
0
  void UpdateHelp(unsigned index) {
    if (!visible || item_help_callback == nullptr)
      return;

    help_widget->SetText(item_help_callback(index));
    two_widgets->UpdateLayout();
  }
Resource* CreateTextWidget( XMLIterator i, XMLCreatorEnv *env )
{
    XMLCreatorEnv ch_env;
    XMLAttributes attributes;
    XMLStyle      branch_style;
    CascadeStyles( i, env, attributes, branch_style, ch_env );

    std::string font = get_attribute( attributes, "font" );

    int bodyAsLink = 0;
    try_attribute_i( attributes, "body_as_link", &bodyAsLink );
    Text text;
    if ( bodyAsLink )
        text = QueryText( make_string( (*i)._value ));
    else
        text = MakeText(to_chars( (*i)._value ));


    Widget *ptr;
    XMLIterator ch_i = i;
    int line_spacing = 0;
    std::string alignment;

    bool adv_text = try_attribute_i( attributes, "spacing", &line_spacing );
    adv_text |= try_attribute( attributes, "align", &alignment );

    // create DualText
    if ( !!ch_i.StepInto() )
    {
        int shift = 2;
        try_attribute_i( attributes, "shift", &shift );

        std::wstring left, right;
        for ( ; !!ch_i; ++ch_i )
        {
            if ( (*ch_i)._name == "left" )
                left = to_chars( (*ch_i)._value );
            else
                if ( (*ch_i)._name == "right" )
                    right = to_chars( (*ch_i)._value );
        }
        
        int bodyAsLink = 0;
        try_attribute_i( attributes, "body_as_link", &bodyAsLink );
        Text leftT, rightT;
        if ( bodyAsLink )
        {
            leftT  = QueryText( make_string( left ));
            rightT = QueryText( make_string( right ));
        }
        else
        {
            leftT  = MakeText(left);
            rightT = MakeText(right);
        }

        DualTextWidget *p_dual;
        ptr = p_dual = new DualTextWidget( 100, QueryFont(font), leftT, rightT, shift );

        std::string dotcode;
        if ( try_attribute( attributes, "dot", &dotcode ) )
            p_dual->SetDotCode( ( dotcode.size()>0 ? dotcode[0] : ' ' ) );    
    }
    else
    if ( adv_text )
    {
        int align = 0;
        if ( alignment == "left"   ) { align = 0; } else
        if ( alignment == "right"  ) { align = 1; } else
        if ( alignment == "center" ) { align = 2; }

        if ( (*i)._name == "activetext" )
        {
            ptr = new ActiveText( QueryFont(font), text, line_spacing, align );
        }
        else
        {
            ptr = new AdvTextWidget( QueryFont(font), text, line_spacing, align );
        }
    }   
    else
    {
         TextWidget *ptrTW = new TextWidget( QueryFont(font), text );
         ptr = ptrTW;
         ptrTW->SetText( text );
    }

    InsertChildWidget( ptr, attributes, env);
    return new AnyResource<Widget*>( ptr );
}
Пример #3
0
// true: block les zones de checks
bool TextWidget::OnMouseClick() {
	
	if(!enabled) {
		return false;
	}
	
	if(clicked) {
		clicked(this);
	}
	
	switch(eState) {
		case EDIT:
			eState=EDIT_TIME;
			return true;
		case GETTOUCH:
			eState=GETTOUCH_TIME;
			lOldColor=lColorHighlight;
			return true;
		default: break;
	}
	
	switch(m_id) {
		// MENULOADQUEST
		case BUTTON_MENUEDITQUEST_LOAD: {
			if(pWindowMenu) {
				pLoadConfirm->SetCheckOn();
				pLoadConfirm->lColor = pLoadConfirm->lOldColor;
				pDeleteConfirm->SetCheckOn();
				pDeleteConfirm->lColor = pDeleteConfirm->lOldColor;
				
				for(size_t i = 0; i < pWindowMenu->m_pages.size(); i++) {
					MenuPage * page = pWindowMenu->m_pages[i];
					
					if(page->eMenuState == EDIT_QUEST_LOAD) {
						page->m_savegame = m_savegame;
						
						for(size_t j = 0; j < page->m_children.m_widgets.size(); j++) {
							Widget * widget = page->m_children.m_widgets[j];
							
							if(widget->m_id == BUTTON_MENUEDITQUEST_LOAD) {
								((TextWidget *)widget)->bSelected = false;
							}
						}
						bSelected = true;
					}
				}
			}
		}
		break;
		case BUTTON_MENUEDITQUEST_LOAD_CONFIRM: {
			if(pWindowMenu) {
				for(size_t i = 0; i < pWindowMenu->m_pages.size(); i++) {
					MenuPage * page = pWindowMenu->m_pages[i];
		
					if(page->eMenuState == EDIT_QUEST_LOAD) {
						
						m_savegame = page->m_savegame;
						if(m_savegame != SavegameHandle()) {
							m_targetMenu = MAIN;
							GRenderer->Clear(Renderer::DepthBuffer);
							ARXMenu_LoadQuest(m_savegame);
							bNoMenu=true;
							if(pTextManage) {
								pTextManage->Clear();
							}
							break;
						}
					}
				}
				
				pLoadConfirm->SetCheckOff();
				pLoadConfirm->lColor = Color::grayb(127);
				pDeleteConfirm->SetCheckOff();
				pDeleteConfirm->lColor = Color::grayb(127);
			}
		}
		break;
		// MENUSAVEQUEST
		case BUTTON_MENUEDITQUEST_SAVE: {
			if(pWindowMenu)
			for(size_t i = 0; i < pWindowMenu->m_pages.size(); i++) {
				MenuPage * page = pWindowMenu->m_pages[i];
				
				if(page->eMenuState == EDIT_QUEST_SAVE_CONFIRM) {
					page->m_savegame = m_savegame;
					TextWidget * me = (TextWidget *) page->m_children.m_widgets[1];
					
					if(me) {
						m_targetMenu = MAIN;
						ARXMenu_SaveQuest(me->m_text, me->m_savegame);
						break;
					}
				}
			}
		}
		break;
		
		// Delete save from the load menu
		case BUTTON_MENUEDITQUEST_DELETE_CONFIRM: {
			if(pWindowMenu) {
				for(size_t i = 0 ; i < pWindowMenu->m_pages.size(); i++) {
					MenuPage * page = pWindowMenu->m_pages[i];
					if(page->eMenuState == EDIT_QUEST_LOAD) {
						m_savegame = page->m_savegame;
						if(m_savegame != SavegameHandle()) {
							m_targetMenu = EDIT_QUEST_LOAD;
							mainMenu->bReInitAll = true;
							savegames.remove(m_savegame);
							break;
						}
					}
				}
			}
			pLoadConfirm->SetCheckOff();
			pLoadConfirm->lColor = Color::grayb(127);
			pDeleteConfirm->SetCheckOff();
			pDeleteConfirm->lColor = Color::grayb(127);
			break;
		}
			
		// Delete save from the save menu
		case BUTTON_MENUEDITQUEST_DELETE: {
			if(pWindowMenu) {
				for(size_t i = 0 ; i < pWindowMenu->m_pages.size(); i++) {
					MenuPage * page = pWindowMenu->m_pages[i];
					if(page->eMenuState == EDIT_QUEST_SAVE_CONFIRM) {
						page->m_savegame = m_savegame;
						TextWidget * me = (TextWidget *) page->m_children.m_widgets[1];
						if(me) {
							m_targetMenu = EDIT_QUEST_SAVE;
							mainMenu->bReInitAll = true;
							savegames.remove(me->m_savegame);
							break;
						}
					}
				}
			}
			break;
		}
		default:
			break;
	}

	if(m_targetMenu == EDIT_QUEST_SAVE_CONFIRM) {
		for(size_t i = 0; i < pWindowMenu->m_pages.size(); i++) {
			MenuPage * page = pWindowMenu->m_pages[i];

			if(page->eMenuState == m_targetMenu) {
				page->m_savegame = m_savegame;
				TextWidget * me = (TextWidget *) page->m_children.m_widgets[1];

				if(me) {
					me->m_savegame = m_savegame;
					
					if(m_savegame != SavegameHandle()) {
						me->SetText(savegames[m_savegame.handleData()].name);
						pDeleteButton->lColor = pDeleteButton->lOldColor;
						pDeleteButton->SetCheckOn();
					} else {
						pDeleteButton->lColor = Color::grayb(127);
						pDeleteButton->SetCheckOff();
						me->SetText(getLocalised("system_menu_editquest_newsavegame"));
					}
					
					page->AlignElementCenter(me);
				}
			}
		}
	}
	
	ARX_SOUND_PlayMenu(SND_MENU_CLICK);
	
	return false;
}