Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2009, 9:53:13 AM (15 years ago)
Author:
danielh
Message:
  • minor fix in PickupCollection
  • Made PickupInventory into a singleton
  • PickupInventory now only creates new CEGUI windows if needed, and does not destroy unused ones
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.cc

    r3001 r3016  
    5353        orxonox::CommandExecutor::addConsoleCommandShortcut(orxonox::createConsoleCommand(orxonox::createFunctor(&PickupInventory::toggleInventory), "toggleInventory"), true);
    5454
    55     static bool bInventoryVisible_ = false;
     55    PickupInventory* PickupInventory::pickupInventory_s = NULL;
     56    PickupInventory* PickupInventory::getSingleton()
     57    {
     58        if(!PickupInventory::pickupInventory_s)
     59            PickupInventory::pickupInventory_s = new PickupInventory();
     60
     61        return PickupInventory::pickupInventory_s;
     62    }
     63
     64    PickupInventory::PickupInventory()
     65    {
     66        this->bInventoryVisible_ = false;
     67        this->createdEquipmentWindows_ = this->createdUsableWindows_ = 0;
     68        this->visibleEquipmentWindows_ = this->visibleUsableWIndows_ = 0;
     69    }
     70    PickupInventory::~PickupInventory()
     71    {
     72    }
     73
     74   
     75
    5676    void PickupInventory::toggleInventory()
    5777    {
    58         if(bInventoryVisible_) {
     78        if(PickupInventory::getSingleton()->isVisible()) {
    5979            GUIManager::getInstancePtr()->executeCode("hideGUI(\"PickupInventory\")");
    6080            GUIManager::getInstancePtr()->executeCode("hideCursor()");
     
    6787            InputManager::getInstance().requestEnterState("guiMouseOnly");
    6888        }
    69         bInventoryVisible_ = !bInventoryVisible_;
    70     }
    71     void PickupInventory::tabChanged(CEGUI::Window *tab)
    72     {
    73         CEGUI::TabControl* tabCtrl = dynamic_cast<CEGUI::TabControl*>(tab);
    74         if(tabCtrl != NULL)
    75         {
    76             COUT(1) << "tabChanged() tab index: " << tabCtrl->getSelectedTabIndex() << std::endl;
    77         }
    78         else
    79         {
    80             COUT(1) << "tabChanged() argument is no CEGUI::TabControl!" << std::endl;
    81         }
     89        PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible());
    8290    }
    8391
     
    193201    }
    194202
    195     void PickupInventory::clearInventory(CEGUI::WindowManager* winMgr, int equipCount, int usableCount)
    196     {
    197         for(int i = 0; i < equipCount; i++)
     203    void PickupInventory::clearInventory(CEGUI::WindowManager* winMgr, CEGUI::Window* equipPane, CEGUI::Window* usablePane)
     204    {
     205        for(unsigned int i = 0; i < this->visibleEquipmentWindows_; i++)
    198206        {
    199207            std::ostringstream id;
    200208            id << i;
    201209
    202             winMgr->destroyWindow("orxonox/Inventory/Frame/equ/" + id.str());
    203             winMgr->destroyWindow("orxonox/Inventory/Title/equ/" + id.str());
    204             winMgr->destroyWindow("orxonox/Inventory/Items/equ/" + id.str());
    205         }
    206         for(int i = 0; i < usableCount; i++)
     210            winMgr->getWindow("orxonox/Inventory/Frame/equ/" + id.str())->setVisible(false);
     211            winMgr->getWindow("orxonox/Inventory/Title/equ/" + id.str())->setVisible(false);
     212            winMgr->getWindow("orxonox/Inventory/Items/equ/" + id.str())->setVisible(false);
     213
     214            /*equipPane->removeChildWindow("orxonox/Inventory/Frame/equ/" + id.str());
     215            equipPane->removeChildWindow("orxonox/Inventory/Title/equ/" + id.str());
     216            equipPane->removeChildWindow("orxonox/Inventory/Items/equ/" + id.str());*/
     217        }
     218        for(unsigned int i = 0; i < this->visibleUsableWIndows_; i++)
    207219        {
    208220            std::ostringstream id;
    209221            id << i;
    210222
    211             std::string s = id.str();
    212             winMgr->destroyWindow("orxonox/Inventory/Frame/use/" + id.str());
    213             winMgr->destroyWindow("orxonox/Inventory/Title/use/" + id.str());
    214             winMgr->destroyWindow("orxonox/Inventory/Items/use/" + id.str());
     223            winMgr->getWindow("orxonox/Inventory/Frame/use/" + id.str())->setVisible(false);
     224            winMgr->getWindow("orxonox/Inventory/Title/use/" + id.str())->setVisible(false);
     225            winMgr->getWindow("orxonox/Inventory/Items/use/" + id.str())->setVisible(false);
     226
     227            /*usablePane->removeChildWindow("orxonox/Inventory/Frame/use/" + id.str());
     228            usablePane->removeChildWindow("orxonox/Inventory/Title/use/" + id.str());
     229            usablePane->removeChildWindow("orxonox/Inventory/Items/use/" + id.str());*/
    215230        }
    216231    }
    217232    void PickupInventory::updateTabs(CEGUI::WindowManager *winMgr, CEGUI::Window *equipWindow, CEGUI::Window *usableWindow)
    218233    {
    219         PickupInventory::updateEquipment(winMgr, equipWindow);
    220         PickupInventory::updateUsable(winMgr, usableWindow);
     234        this->updateEquipment(winMgr, equipWindow);
     235        this->updateUsable(winMgr, usableWindow);
    221236    }
    222237
     
    234249                EquipmentItem* item = items.at(i);
    235250
    236                 PickupInventory::addItem(winMgr, target, id.str(), item, "FFFFFFFF", i % 5, i / 5);
     251                if(this->createdEquipmentWindows_ <= i)
     252                {
     253                    PickupInventory::createItemWindows(winMgr, id.str(), i % 5, i / 5);
     254                    this->createdEquipmentWindows_++;
     255                }
     256
     257                PickupInventory::setWindowProperties(winMgr, target, id.str(), item, "FFFFFFFF");
    237258            }
     259            this->visibleEquipmentWindows_ = items.size();
    238260        }
    239261    }
     
    257279                    colour = "FFFFFFFF";
    258280
    259                 PickupInventory::addItem(winMgr, target, id.str(), item, colour, i % 5, i / 5);
     281                if(this->createdUsableWindows_ <= i)
     282                {
     283                    PickupInventory::createItemWindows(winMgr, id.str(), i % 5, i / 5);
     284                    this->createdUsableWindows_++;
     285                }
     286
     287                PickupInventory::setWindowProperties(winMgr, target, id.str(), item, colour);
    260288            }
    261         }
    262     }
    263 
    264     void PickupInventory::addItem(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, BaseItem* item, const std::string& titleColour, int x, int y)
     289            this->visibleUsableWIndows_ = items.size();
     290        }
     291    }
     292
     293    void PickupInventory::createItemWindows(CEGUI::WindowManager* winMgr, const std::string& id, int x, int y)
    265294    {
    266         if(!winMgr || !target || !item) { return; }
    267 
    268         std::string image = PickupInventory::getImageForItem(item);
     295        if(!winMgr) { return; }
    269296
    270297        CEGUI::Window* frame = winMgr->createWindow("TaharezLook/StaticImage", "orxonox/Inventory/Frame/" + id);
     
    275302        text->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 5 + x * 70), CEGUI::UDim(0, 70 + y * 90)));
    276303        text->setSize(CEGUI::UVector2(CEGUI::UDim(0, 65), CEGUI::UDim(0, 20)));
    277         text->setProperty("Text", item->getGUIText());
    278304        text->setProperty("FrameEnabled", "False");
    279305        text->setProperty("BackgroundEnabled", "False");
    280306        text->setProperty("HorzFormatting", "HorzCentred");
    281307        text->setProperty("VertFormatting", "VertCentred");
    282         text->setProperty("TextColours", "tl:" + titleColour + " tr:" + titleColour + " bl:" + titleColour + " br:" + titleColour + "");
     308        text->setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
    283309
    284310        CEGUI::Window* btn = winMgr->createWindow("TaharezLook/Button", "orxonox/Inventory/Items/" + id);
    285311        btn->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 8 + x * 70), CEGUI::UDim(0, 8 + y * 90)));
    286312        btn->setSize(CEGUI::UVector2(CEGUI::UDim(0, 59), CEGUI::UDim(0, 59)));
     313        btn->subscribeScriptedEvent("Clicked", "itemClicked");
     314    }
     315    void PickupInventory::setWindowProperties(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, const BaseItem* item, const std::string& textColour)
     316    {
     317        CEGUI::Window* txt = winMgr->getWindow("orxonox/Inventory/Title/" + id);
     318        CEGUI::Window* btn = winMgr->getWindow("orxonox/Inventory/Items/" + id);
     319        CEGUI::Window* frm = winMgr->getWindow("orxonox/Inventory/Frame/" + id);
     320
     321        frm->setVisible(true);
     322
     323        txt->setVisible(true);
     324        txt->setProperty("Text", item->getGUIText());
     325        txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour + "");
     326
     327        std::string image = PickupInventory::getImageForItem(item);
     328        btn->setVisible(true);
    287329        btn->setProperty("NormalImage", image);
    288330        btn->setProperty("HoverImage", image);
     
    290332        btn->setProperty("DisabledImage", image);
    291333        btn->setProperty("Tooltip", item->getGUIText());
    292         btn->subscribeScriptedEvent("Clicked", "itemClicked");
    293 
    294         target->addChildWindow(text);
    295         target->addChildWindow(frame);
     334
     335        target->addChildWindow(frm);
     336        target->addChildWindow(txt);
    296337        target->addChildWindow(btn);
    297338    }
Note: See TracChangeset for help on using the changeset viewer.