CEGUI::String problem

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

celest_3rd
Just popping in
Just popping in
Posts: 6
Joined: Sat May 10, 2008 18:00

CEGUI::String problem

Postby celest_3rd » Thu Aug 21, 2008 07:00

I have another problem :oops: :oops:

Code: Select all

class testitem : public CEGUI::Window
{
public:
   int i_no;
   CEGUI::String i_ID;
   CEGUI::String i_name;
   int i_quantity;
};


Code: Select all

void create(int pNo,CEGUI::String pID,CEGUI::String pName,CEGUI::String pDesc)
   {
      CEGUI::WindowManager &wm = CEGUI::WindowManager::getSingleton();
         // Item icon
         testitem *w1 = static_cast<testitem*>(wm.createWindow("TaharezLook/StaticImage","Item/Img:" + pID));
         w1->setArea(CEGUI::UDim(0,0),CEGUI::UDim(0,0),CEGUI::UDim(1,0),CEGUI::UDim(1,0));
         w1->setProperty("Image","set:MenuHotkey image:mmnF01Normal");
         w1->setProperty("MousePassThroughEnabled","true");
         w1->i_no = pNo;
         w1->i_ID = pID; // Program breaks here
         w1->i_name = pName;
         w1->i_quantity = 0;
....


Code: Select all

item items;
items.create(1,"0001","Potion 1","Potion for use");
items.create(2,"0002","Potion 2","Potion for use");


Program breaks down when it reaches to those line.

How can I fix them ?
Thanks in advanced.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Thu Aug 21, 2008 07:44

Hi,

i think that you have some invalid code. You cast the Window to your 'testitem' class, which is larger. So you start writing out of the memory boundaries for that class. Even if this would work (maybe in Debug mode), the members (the "i_xxx's") have not been created at all(!)

In order to derive a class from Window and do what you are doing, you need to modify the Cegui sources and add a Factory.

It might be easier to change your design, so that the created window become a member. Is that possible? For example:

Code: Select all

class testitem
{
public:
  testitem(CEGUI::Window wrapped) {
    m_wrapped = wrapped;
  }
  // other code + members
}


Then in the window creation method:

Code: Select all

// Item icon
testitem *w1 = new testitem(wm.createWindow("TaharezLook/StaticImage","Item/Img:" + pID));
w1->i_no = pNo;


HTH.
Check out my released snake game using Cegui!

celest_3rd
Just popping in
Just popping in
Posts: 6
Joined: Sat May 10, 2008 18:00

Postby celest_3rd » Thu Aug 21, 2008 12:35

Thanks scriptkid for acknowledges :)

I can't resolve problem about Item recognize when user drags Icon into slot (#3506)

I think 2 ways now!

1. use associative array
- user drags icon into slot (in example: result is "Item/Drag:Item0001" (DragContainer) at "EquipContain/Head")
- substring "Item/Drag:Item0001" with first-find-of ":" to end (result would be "Item0001"
- compare with hash array Items but result is blank

2. inheriete CEGUI::Window class
- I tested this code

Code: Select all

class testitem : public CEGUI::Window
{
int i_name;
int i_no;
}

// --- somewhere of code ----
testitem* test1 = static_cast<testitem*>(wmgr.getWindow("Test1"));
test1->i_name = 22222;
test1->i_no = 50;


It works! and I can use class attributes (i_name and i_no) anywhere if I call getWindow("Test1") both set/get.

But CEGUI::String attribute give me program breaks because it can't assign value with operation =


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests