Page 1 of 1

How to manage ListboxItems in listbox via c++ code

Posted: Sat Oct 16, 2010 22:11
by wild_r
Hi all!

Today I have a little question:

1) I'm writing code for managing dialogs with NPC and I selected TaharezLook/ListBox for variants of answers in dialog window.

2) I'm try to do something, but my code doesn't work:

Code: Select all

void CUIManager::_InitDialog()
{
   m_WindowManager->getWindow("Root/NPSQuesting/Log")->setText("");
   CEGUI::Listbox *vars = (CEGUI::Listbox*) m_WindowManager->getWindow("Root/NPSQuesting/AnswerVariants");

   vector<string> answers=_pQuestManager->GetAnswers(-1);

   //CEGUI::String str;
   
   for (int i=0; i<answers.capacity(); i++)
   {
      //str.clear();
      //str.append("ListboxItem");
      //str+=(i+30);
      CEGUI::Window* foo = m_WindowManager->createWindow("TaharezLook/ListboxItem", "");
      vars->addChildWindow(foo);
      //vars->addItem((CEGUI::ListboxItem*) foo);

      ((CEGUI::ListboxItem*)foo)->setOwnerWindow(vars);

   }

   vars->subscribeEvent(CEGUI::Listbox::EventMouseClick, new CEGUI::Event::Subscriber(&CUIManager::_AnswerVariantsHandler, this));
}


3) I think, I should use vars->addItem((CEGUI::ListboxItem*) foo);, but MSVC gives me an rtc error "The value of ESP was not properly saved across a function call."

4) And the last question: where are ListBoxItem parameters for setting up size and position? Should I re - define a ListBoxItem class?

Thank you!

P.S. Maybe there is another method for creating interactive dialogs windows?

Re: How to manage ListboxItems in listbox via c++ code

Posted: Sun Oct 17, 2010 06:23
by Playerdark
I'm not sure, but what I do to create items is simply:

pc_item = new CEGUI::ListboxTextItem( zs_line, u32_object_id );


Items aren't windows so I dont think you can create them vie the window manager

Re: How to manage ListboxItems in listbox via c++ code

Posted: Sun Oct 17, 2010 08:01
by wild_r
Thank you! It works!

Re: How to manage ListboxItems in listbox via c++ code

Posted: Sun Oct 17, 2010 17:12
by wild_r
Another question: how to highlight a listbox text item under mouse cursor?

Thank you.

Re: How to manage ListboxItems in listbox via c++ code

Posted: Mon Oct 18, 2010 19:36
by Jamarr
It should highlight automatically if you are injecting the MousePosition into CEGUI via System::injectMousePosition/injectMouseMove.

Also, when using the the ListboxItem (or ListboxTextItem) you probably need to call ListboxTextItem::setTextColours(), ListboxItem::setSelectionBrushImage(), and ListboxItem::setSelectionColours() as I believe the default for all of these is white; so you will not see text or highlight colors unless you set these in code.