Lists in MyGUI

chilligirl

12-08-2008 23:02:29

Hallo there. I can't seem to find an example of how to create a delegate method that does something with an object selected from a list. Can anyone help me? I have a GuiManager class with the following instance:

MyGUI::ListPtr inventoryList;
inventoryList = mGUI->findWidget<MyGUI::List("InventoryList");
populateInventory();

I now want to select a specific string from the list and do something with it...I know it must be simple, but...sigh

Altren

13-08-2008 01:28:25

I don't understand your question, but here's some examples:
Get string by indexconst Ogre::UTFString & getItem(size_t _index);Set another stringvoid setItem(size_t _index, const Ogre::UTFString & _item);
If you want to handle event when user select string from list then you should use eventListChangePosition:inventoryList->eventListChangePosition = MyGUI::newDelegate(...); /** Event : Selected item position changed.\n
signature : void method(MyGUI::WidgetPtr _sender, size_t _index)\n
@param _index of new item
*/
EventInfo_WidgetSizeT eventListChangePosition;

chilligirl

13-08-2008 21:10:46

Yeah, thank you, that is exactly what I want to do...I am not sure I understand your notation thoroughly though, but I will try that now. Thank you!

chilligirl

13-08-2008 21:31:22

Ok, I kind of tried it, bit It doesn't want to work. Here is some of my code, sorry if I'm being dumb...

#ifndef GUIMANAGER_H
#define GUIMANAGER_H
#include "ExampleApplication.h"
#include "MyGUI.h"
#include "Inventory.h"

class GuiManager{

public:
MyGUI::Gui * mGUI;
float alpha;
bool visiblegui;
Inventory* inventory;

//Gui stuff
MyGUI::VectorWidgetPtr GUI;
MyGUI::TabPtr guitabs;
MyGUI::ListPtr inventoryList;
MyGUI::ListPtr weaponList;



static GuiManager* createGUI(RenderWindow* mWindow, Inventory* i){
if(guiInstance==0){
guiInstance = new GuiManager(mWindow, i);
}
return guiInstance;
};

void changeVisibility(){

if(!visiblegui){

//create GUI
GUI = MyGUI::LayoutManager::getInstance().load("GUI.layout");

//GUI tabs widget
guitabs = mGUI->findWidget<MyGUI::Tab>("GUI");
guitabs->setAlpha(alpha);

//inventory List
inventoryList = mGUI->findWidget<MyGUI::List>("InventoryList");

weaponList = mGUI->findWidget<MyGUI::List>("WeaponsList");
inventoryList->eventListChangePosition = MyGUI::newDelegate(selectObjectFromInvList);
populateInventory();

//show mouse cursor
MyGUI::PointerManager::getInstance().show();

//set gui visibility to true
visiblegui = true;
}

else{
MyGUI::WidgetManager::getInstance().destroyWidgetsVector(GUI);
guitabs = 0;
MyGUI::PointerManager::getInstance().hide();
visiblegui = false;
}

};


void selectObjectFromInvList(MyGUI::WidgetPtr sender, size_t index)
{
//do something here according to the list entry that was selected...
} ;


void shutdown(){
mGUI->shutdown();
delete mGUI;
};

protected:
GuiManager(RenderWindow* mWindow, Inventory* i){

//instantiate a lot of stuff

};

void populateInventory(){
//add a lot of stuff to the lists here
};

private:
static GuiManager* guiInstance;
};

GuiManager* GuiManager::guiInstance = 0;
#endif

klumhru

14-08-2008 10:53:16

I think the delegate you want is eventListSelectAccept.

From the API docs:
EventInfo_WidgetSizeT MyGUI::List::eventListSelectAccept

Event : Enter pressed or double click.
signature : void method(MyGUI::WidgetPtr _sender, size_t _index)

Parameters:
_index of selected item


Took me a while to find too ;)

chilligirl

14-08-2008 13:23:04

Thanks, I tried that, and got the following compile errors:

1>Compiling...
1>main.cpp
1>c:\testogre\gameprototype4\sampleapp\include\guimanager.h(63) : error C3867: 'GuiManager::selectObjectFromInvList': function call missing argument list; use '&GuiManager::selectObjectFromInvList' to create a pointer to member
1>c:\testogre\gameprototype4\sampleapp\include\guimanager.h(63) : error C2780: 'MyGUI::delegates::IDelegate1<TP1> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1))' : expects 2 arguments - 1 provided
1> c:\ogresdk\samples\mygui_2.2.0_rc1_source\myguiengine\include\mygui_delegateimplement.h(72) : see declaration of 'MyGUI::delegates::newDelegate'
1>c:\testogre\gameprototype4\sampleapp\include\guimanager.h(63) : error C2780: 'MyGUI::delegates::IDelegate2<TP1,TP2> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2))' : expects 2 arguments - 1 provided
1> c:\ogresdk\samples\mygui_2.2.0_rc1_source\myguiengine\include\mygui_delegateimplement.h(72) : see declaration of 'MyGUI::delegates::newDelegate'
1>c:\testogre\gameprototype4\sampleapp\include\guimanager.h(63) : error C2780: 'MyGUI::delegates::IDelegate3<TP1,TP2,TP3> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2,TP3))' : expects 2 arguments - 1 provided
1> c:\ogresdk\samples\mygui_2.2.0_rc1_source\myguiengine\include\mygui_delegateimplement.h(72) : see declaration of 'MyGUI::delegates::newDelegate'
1>c:\testogre\gameprototype4\sampleapp\include\guimanager.h(63) : error C2780: 'MyGUI::delegates::IDelegate4<TP1,TP2,TP3,TP4> *MyGUI::delegates::newDelegate(TObj *,void (__thiscall TObj::* )(TP1,TP2,TP3,TP4))' : expects 2 arguments - 1 provided
1> c:\ogresdk\samples\mygui_2.2.0_rc1_source\myguiengine\include\mygui_delegateimplement.h(72) : see declaration of 'MyGUI::delegates::newDelegate'
1>Build log was saved at "file://c:\TESTOGRE\GamePrototype4\sampleapp\sampleapp\Debug\BuildLog.htm"
1>sampleapp - 5 error(s), 0 warning(s)

Altren

14-08-2008 13:55:20

You should read this.
You delegate is member funtion of GuiManager, so you should create delegates this way:inventoryList->eventListChangePosition = MyGUI::newDelegate(this, &GuiManager::selectObjectFromInvList);

chilligirl

14-08-2008 14:43:05

Thank you! It is working now! Awesome! I knew I was doing something little wrong!

chilligirl

14-08-2008 14:47:45

Ok, just for clarity, both delegated do basically the same thing:

//inventoryList->eventListSelectAccept =MyGUI::newDelegate(this, &GuiManager::selectObjectFromInvList); //This only happens on double click

inventoryList->eventListChangePosition = MyGUI::newDelegate(this, &GuiManager::selectObjectFromInvList); //this happens on single click

Altren

14-08-2008 15:43:41

eventListSelectAccept - when you double click or press enter after selecting item (by mouse or keyboard).
eventListChangePosition - when selected item changed (by mouse or keyboard).

skatt

12-07-2011 07:20:29

I know this is an old thread, but using the method described here:

inventoryList->eventListChangePosition = MyGUI::newDelegate(this, &GuiManager::selectObjectFromInvList);


I get the following warning:
warning: 'void MyGUI::EventPair<EventObsolete, Event>::operator=(T*) [with T = MyGUI::delegates::IDelegate2<MyGUI::Widget*, long unsigned int>, EventObsolete = MyGUI::delegates::CMultiDelegate2<MyGUI::Widget*, long unsigned int>, Event = MyGUI::delegates::CMultiDelegate2<MyGUI::MultiListBox*, long unsigned int>]' is deprecated (declared at /usr/local/include/MYGUI/MyGUI_EventPair.h:37)
I get the warning when using the += operator as well.


I cannot seem to find any information on forums, websearch, or in the source code regarding the new method for handling this situation. Would someone kindly point me in the correct direction?

Altren

12-07-2011 12:39:28

Probably you have Widget* instead of List* in GuiManager::selectObjectFromInvList

skatt

12-07-2011 18:08:48

Hmm, my case is not exactly the same. Here is the section of code that is creating the warning:

if(widgetType == "MultiListBox") {
MultiListBox *list = (MultiListBox*) widget;
list->eventListChangePosition += newDelegate(
this, &MyGUISystem::widgetSelectionChanged);
}


As you can see, I am actually dealing with a MultiListBox. I do not know what difference this actually makes though. I feel silly that I cannot find the solution to this myself. :(

Altren

12-07-2011 18:43:31

Your MyGUISystem::widgetSelectionChanged method have wrong signature. There should be MultiListBox* _sender instead of Widget* _sender.