Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6996


Ignore:
Timestamp:
May 27, 2010, 10:44:10 PM (14 years ago)
Author:
dafrick
Message:

Loads of changes.
1) PickupInventory should now be working even for extreme cases.
2) Added support for inactive Spawnpoints in Gametype.
3) Made Pickupable rewardble. meaning from now on any Pickupable can be given as a reward for completing Quests.
4) Added some keybinds to KeybindMenu, such as PickupInventory, QuestGUI and Chat.

Location:
code/branches/presentation3
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/gui/scripts/KeyBindMenu.lua

    r6748 r6996  
    2828    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
    2929    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
     30    table.insert(commandList, "OrxonoxOverlay toggleVisibility QuestGUI")
     31    table.insert(commandList, "OrxonoxOverlay toggleVisibility PickupInventory")
     32    table.insert(commandList, "startchat")
     33    table.insert(commandList, "startchat_small")
    3034    table.insert(commandList, "mouseLook")
    3135    table.insert(commandList, "pause")
     
    5357    table.insert(nameList, "Show Debug")
    5458    table.insert(nameList, "Show Stats")
     59    table.insert(nameList, "Show Quests")
     60    table.insert(nameList, "Show Pickups")
     61    table.insert(nameList, "Show Chat")
     62    table.insert(nameList, "Show small Chat")
    5563    table.insert(nameList, "Look Around")
    5664    table.insert(nameList, "Pause")
  • code/branches/presentation3/data/gui/scripts/PickupInventory.lua

    r6965 r6996  
    33local P = createMenuSheet("PickupInventory")
    44
    5 P.carrierList = {}
    65P.wrapper = nil
    76P.detailsWindows = {}
     7P.detailPickups = {}
    88P.pickupsList = {}
    99
     
    1717
    1818function P.onLoad()
    19     carrierList = {}
     19    P.wrapper = nil
     20    P.detailsWindows = {}
     21    P.detailPickups = {}
     22    P.pickupsList = {}
    2023end
    2124
     
    2730function P.onHide()
    2831    P.showing = false
    29     P.cleanup()
     32    P.cleanup(true)
    3033end
    3134
     
    3437        return
    3538    end
    36    
    37     P.cleanup()
    38    
     39
     40    -- Update opened detail windows.
     41    for k,v in pairs(P.detailsWindows) do
     42        if v ~= nil then
     43            local pickup = P.detailPickups[k]
     44            if pickup ~= nil and pickup ~= 0 then
     45                local useButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/UseButton")
     46                local dropButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/DropButton")
     47                if orxonox.PickupManager:getInstance():isValidPickup(pickup) == false then
     48                    useButton:setEnabled(false)
     49                    dropButton:setEnabled(false)
     50                    P.detailPickups[k] = nil
     51                else
     52                    useButton:setEnabled(true)
     53                    if pickup:isUsed() == true then
     54                        useButton:setText("unuse")
     55                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
     56                    else
     57                        useButton:setText("use")
     58                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
     59                    end
     60
     61                    if pickup:isPickedUp() == false then
     62                        useButton:setEnabled(false)
     63                        dropButton:setEnabled(false)
     64                        P.detailPickups[k] = nil
     65                    end
     66                end
     67            end
     68        end
     69    end
     70
     71    -- Update main inventory.
     72    P.cleanup(false)
    3973    P.createInventory()
     74    -- TODO: Recover scrolling position
     75   
    4076end
    4177
     
    83119    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
    84120    title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight+5), CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
    85     title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, P.textHeight)))
     121    title:setSize(CEGUI.UVector2(CEGUI.UDim(0.3, 0), CEGUI.UDim(0, P.textHeight)))
    86122    title:setText(representation:getPickupName())
    87123    title:setProperty("FrameEnabled", "set:False")
     
    89125
    90126    local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
    91     useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
     127    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
    92128    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
    93129    if pickup:isUsed() == false then
     
    101137
    102138    local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
    103     dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+15+P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
     139    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+15+P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
    104140    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
    105141    dropButton:setText("drop")
     
    108144
    109145    local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DetailsButton")
    110     detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+20+2*P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
     146    detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+20+2*P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
    111147    detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
    112148    detailsButton:setText("details")
     
    117153end
    118154
    119 function P.cleanup()
     155function P.cleanup(destroyDetails)
    120156    if P.wrapper ~= nil then
    121157        winMgr:destroyWindow(P.wrapper)
     
    123159   
    124160    --Destroy details windows.
     161    if destroyDetails == false then
     162        return
     163    end
    125164    for k,v in pairs(P.detailsWindows) do
    126165        if v ~= nil then
     
    143182    local pickup = P.pickupsList[pickupIndex]
    144183    local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup)
    145    
    146     local headerOffset = 35
    147     --Design parameters
    148     local imageSize = 100
    149    
    150     local name = "orxonox/PickupInventory/Pickup" .. pickupIndex .. "/Details" .. P.getNewDetailNumber()
     184
     185    local index = P.getNewDetailNumber()
     186    local name = "orxonox/PickupInventory/Details" .. index
    151187   
    152188    local window = winMgr:createWindow("MenuWidgets/FrameWindow", name)
     
    192228    if pickup:isUsed() == false then
    193229        useButton:setText("use")
    194         orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
     230        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
    195231    else
    196232        useButton:setText("unuse")
    197         orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
     233        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
    198234    end
    199235    wrapper:addChildWindow(useButton)
     
    203239    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
    204240    dropButton:setText("drop")
    205     orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
     241    orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropDetailButton_clicked")
    206242    wrapper:addChildWindow(dropButton)
    207    
    208     table.insert(P.detailsWindows, window)
    209    
    210 end
    211 
     243
     244    P.detailsWindows[index] = window
     245    P.detailPickups[index] = pickup
     246   
     247end
     248
     249-- TODO: Smarter
    212250function P.getNewDetailNumber()
    213251    local number = table.getn(P.detailsWindows)
     
    217255        end
    218256    end
    219     return number
     257    return number+1
    220258end
    221259
     
    238276    local pickupIndex = P.windowToPickupHelper(e)
    239277    P.createDetailsWindow(pickupIndex)
     278end
     279
     280function P.InventoryUseDetailButton_clicked(e)
     281    local pickupIndex = P.windowToPickupHelper(e)
     282    orxonox.PickupManager:getInstance():usePickup(P.detailPickups[pickupIndex], true)
     283end
     284
     285function P.InventoryUnuseDetailButton_clicked(e)
     286    local pickupIndex = P.windowToPickupHelper(e)
     287    orxonox.PickupManager:getInstance():usePickup(P.detailPickups[pickupIndex], false)
     288end
     289
     290function P.InventoryDropDetailButton_clicked(e)
     291    local pickupIndex = P.windowToPickupHelper(e)
     292    orxonox.PickupManager:getInstance():dropPickup(P.detailPickups[pickupIndex])
    240293end
    241294
     
    245298    local name = we.window:getName()
    246299    local match = string.gmatch(name, "%d+")
    247     local pickupNr = tonumber(match())
    248300    local detailNr = tonumber(match())
    249301   
    250     local window = P.detailsWindows[detailNr+1]
     302    local window = P.detailsWindows[detailNr]
    251303    winMgr:destroyWindow(window)
    252     P.detailsWindows[detailNr+1] = nil
     304    P.detailsWindows[detailNr] = nil
     305    P.detailPickups[detailNr] = nil
    253306end
    254307
  • code/branches/presentation3/src/libraries/core/GUIManager.h

    r6749 r6996  
    8484        //! Creates a new InputState to be used with a GUI Sheet
    8585        const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
     86        LuaState* getLuaState(void)
     87            { return this->luaState_.get(); }
    8688
    8789        //! Returns the root window for all menu sheets
     
    102104
    103105        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
    104 
     106       
    105107    private:
    106108        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
    107 
    108109        void executeCode(const std::string& str);
     110       
    109111        template <typename FunctionType>
    110112        bool protectedCall(FunctionType function);
  • code/branches/presentation3/src/modules/pickup/PickupManager.cc

    r6965 r6996  
    3939#include "core/ScopedSingletonManager.h"
    4040#include "core/Identifier.h"
     41#include "util/Convert.h"
    4142#include "interfaces/PickupCarrier.h"
    4243#include "infos/PlayerInfo.h"
     
    6465       
    6566        this->defaultRepresentation_ = new PickupRepresentation();
    66         this->pickupsIndex_ = 0;
    6767       
    6868        COUT(3) << "PickupManager created." << std::endl;
     
    154154    {
    155155        this->pickupsList_.clear();
    156         this->pickupsIndex_ = 0;
    157156       
    158157        PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
     
    169168            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
    170169            {
    171                 this->pickupsList_.insert(*pickup);
     170                this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
    172171            }
    173172        }
     
    199198    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
    200199    {
     200        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     201        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     202            return;
     203
    201204        if(!pickup->isPickedUp())
    202205            return;
    203        
     206
    204207        PickupCarrier* carrier = pickup->getCarrier();
    205208        if(pickup != NULL && carrier != NULL)
     209        {
    206210            carrier->drop(pickup);
     211        }
    207212    }
    208213
    209214    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
    210215    {
     216        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     217        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     218            return;
     219       
    211220        if(!pickup->isPickedUp())
    212221            return;
  • code/branches/presentation3/src/modules/pickup/PickupManager.h

    r6965 r6996  
    3939#include <map>
    4040#include "util/Singleton.h"
     41#include "core/WeakPtr.h"
    4142#include "pickup/PickupIdentifier.h"
    4243#include "PickupRepresentation.h"
     
    7273            // tolua_begin
    7374            int getNumPickups(void);
    74             orxonox::Pickupable* popPickup(void) { this->pickupsIndex_++; return *(this->pickupsIterator_++); }
    75             int getPickupIndex(void) { return this->pickupsIndex_-1; }
     75            orxonox::Pickupable* popPickup(void) { return (this->pickupsIterator_++)->first; }
    7676            orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup) { if(pickup != NULL) return this->getRepresentation(pickup->getPickupIdentifier()); return NULL; }
    7777
    7878            void dropPickup(orxonox::Pickupable* pickup);
    7979            void usePickup(orxonox::Pickupable* pickup, bool use);
     80            bool isValidPickup(orxonox::Pickupable* pickup) { std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); if(it == this->pickupsList_.end()) return false; return it->second.get() != NULL; }
    8081            // tolua_end
    8182           
     
    8788            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
    8889
    89             std::set<Pickupable*> pickupsList_;
    90             std::set<Pickupable*>::iterator pickupsIterator_;
    91             int pickupsIndex_;
     90            std::map<Pickupable*, WeakPtr<Pickupable> > pickupsList_;
     91            std::map<Pickupable*, WeakPtr<Pickupable> >::iterator pickupsIterator_;
    9292
    9393            std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier);
  • code/branches/presentation3/src/orxonox/gametypes/Gametype.cc

    r6417 r6996  
    309309        if (this->spawnpoints_.size() > 0)
    310310        {
     311            SpawnPoint* fallbackSpawnPoint = NULL;
    311312            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    312313            unsigned int index = 0;
     314            std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;
    313315            for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
     316            {
     317                if (index == randomspawn)
     318                    fallbackSpawnPoint = (*it);
     319
     320                if (!(*it)->isActive())
     321                    activeSpawnPoints.erase(*it);
     322
     323                ++index;
     324            }
     325
     326            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
     327            index = 0;
     328            for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it)
    314329            {
    315330                if (index == randomspawn)
    316331                    return (*it);
    317 
     332               
    318333                ++index;
    319334            }
     335
     336            return fallbackSpawnPoint;
    320337        }
    321338        return 0;
  • code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc

    r6901 r6996  
    3434#include "Pickupable.h"
    3535
     36#include "core/LuaState.h"
     37#include "core/GUIManager.h"
    3638#include "core/Identifier.h"
    3739#include "core/CoreIncludes.h"
     40#include "util/Convert.h"
     41#include "infos/PlayerInfo.h"
    3842#include "pickup/PickupIdentifier.h"
     43#include "worldentities/pawns/Pawn.h"
    3944#include "PickupCarrier.h"
    4045
     
    9196        this->used_ = used;
    9297        this->changedUsed();
     98
     99        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
    93100        return true;
    94101    }
     
    196203        this->pickedUp_ = pickedUp;
    197204        this->changedPickedUp();
     205        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
    198206        return true;
    199207    }
     
    273281        SUPER(Pickupable, clone, item);
    274282    }
     283
     284    /**
     285    @brief
     286        Method to transcribe a Pickupable as a Rewardable to the player.
     287    @param player
     288        A pointer to the PlayerInfo, do whatever you want with it.
     289    @return
     290        Return true if successful.
     291    */
     292    bool Pickupable::reward(PlayerInfo* player)
     293    {
     294        ControllableEntity* entity = player->getControllableEntity();
     295        Pawn* pawn = static_cast<Pawn*>(entity);
     296        PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn);
     297        return carrier->pickup(this);
     298    }
    275299   
    276300}
  • code/branches/presentation3/src/orxonox/interfaces/Pickupable.h

    r6965 r6996  
    4141
    4242#include "core/OrxonoxClass.h"
     43#include "Rewardable.h"
    4344
    4445namespace orxonox // tolua_export
     
    5253    */
    5354    class _OrxonoxExport Pickupable  // tolua_export
    54         : virtual public OrxonoxClass
     55        : virtual public OrxonoxClass, public Rewardable
    5556    {  // tolua_export
    5657        protected:
     
    141142            std::list<Identifier*> targets_; //!< The possible targets of this pickup.
    142143
     144        // For implementing the Rewardable interface:
     145        public:
     146            virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player.
     147
    143148    };  // tolua_export
    144149   
  • code/branches/presentation3/src/orxonox/interfaces/Rewardable.h

    r6417 r6996  
    4848        Damian 'Mozork' Frick
    4949    */
    50     class _OrxonoxExport Rewardable : public OrxonoxClass
     50    class _OrxonoxExport Rewardable : virtual public OrxonoxClass
    5151    {
    5252        public:
     
    5959                Must be implemented by every class inheriting from Rewardable.
    6060            @param player
    61                 A pointer to the ControllableEntity, do whatever you want with it.
     61                A pointer to the PlayerInfo, do whatever you want with it.
    6262            @return
    6363                Return true if successful.
Note: See TracChangeset for help on using the changeset viewer.