CEGUI with associative array

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 with associative array

Postby celest_3rd » Wed Aug 20, 2008 15:02

Code: Select all

bool EquipHead(const CEGUI::EventArgs& e)
   {
      const CEGUI::DragDropEventArgs& arg = static_cast<const CEGUI::DragDropEventArgs&>(e);
      CEGUI::String it = arg.dragDropItem->getName();
      CEGUI::String in = it.substr(it.find_first_of(":")+1);
      const char* ic = in.c_str();
      
      AddHistory("Equip :" + it);
      AddHistory("Equip Head :"+ Items[ic].Name);
      AddHistory("Drop at:" + arg.dragDropItem->getCurrentDropTarget()->getName());


      return true;
   }


Code: Select all

hash_map<const char*, item> Items;


Code: Select all

class item
{
public:
   item()
   {
      num = 0;
   }

   void Update(int pNo,char* pID,CEGUI::String pName,CEGUI::String pImage,CEGUI::String pDesc,CEGUI::String pDescColor)
   {
      no = pNo;
      ID = pID;
      Name = pName;
      Image = pImage;
      Icon = "";
      Desc = pDesc;
      DescColor = pDescColor;
      display();
   }

   void display(void)
   {
      CEGUI::WindowManager &wm = CEGUI::WindowManager::getSingleton();
      testitem *w1 = static_cast<testitem*>(wm.createWindow("TaharezLook/StaticImage","Item/Img:" + ID));
      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");

      CEGUI::DragContainer *d1 = (CEGUI::DragContainer*)(wm.createWindow("DragContainer","Item/Drag:" + ID));
      d1->setArea(CEGUI::UDim(0,0),CEGUI::UDim(0,0),CEGUI::UDim(0,32),CEGUI::UDim(0,32));

      CEGUI::Editbox *e1 = (CEGUI::Editbox*)(wm.createWindow("TaharezLook/StaticText","Item/Desc:" + ID));
      e1->setArea(CEGUI::UDim(0,35),CEGUI::UDim(0,12),CEGUI::UDim(0,190),CEGUI::UDim(0,15));
      e1->setText(Desc);

      CEGUI::ItemEntry *l1 = (CEGUI::ItemEntry*)(wm.createWindow("TaharezLook/ListboxItem","Item/List:" + ID));
      CEGUI::ItemListbox* list = static_cast<CEGUI::ItemListbox*>(wm.getWindow("Inventory/List"));
      l1->setHeight(CEGUI::UDim(0,40));
      l1->setText(Name);

      d1->addChildWindow(w1);
      l1->addChildWindow(d1);
      l1->addChildWindow(e1);
      list->addItem(l1);
      
   }

   void updateName(CEGUI::String &text)
   {
      CEGUI::Window* w1 = CEGUI::WindowManager::getSingletonPtr()->getWindow("Item/List:" + ID);
      w1->setText(text);
   }

   void updateIcon(CEGUI::String &set,CEGUI::String &image)
   {
      CEGUI::Window* w1 = CEGUI::WindowManager::getSingletonPtr()->getWindow("Item/Img:" + ID);
      w1->setProperty("Image","set:" + set + " image:" + image);
   }

   void updateDescribe(CEGUI::String &text)
   {
      CEGUI::Window* w1 = CEGUI::WindowManager::getSingletonPtr()->getWindow("Item/Desc:" + ID);
      w1->setText(text);
   }

   void updateDescColor(CEGUI::String &color)
   {
   }

   void Quantity(int number)
   {
      num += number;
   }

   int no; // Item ID (use in reference)
   String ID; // Item ID (use in interface)
   CEGUI::String Name; // Item Name
   CEGUI::String Image; // Icon Image (normal)
   CEGUI::String Icon; // Icon Image (small)
   
   CEGUI::String Desc; // Short description
   CEGUI::String DescColor; // Description color
   int num; // Item quantity
};


Code: Select all

Items["Item0001"].Update(200,"Item0001","Potion","","Potion","");
      Items["Item0002"].Update(201,"Item0002","Potion2","","Potion 2","");


when I drag icon to dragdropcontainer and have result like this

Image

How cegui accesses with associative array ?
or use other concept to manage Item class ?

Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 2 guests