Changeset 439 for cafu/trunk

Show
Ignore:
Timestamp:
12/04/11 13:06:30 (6 months ago)
Author:
Carsten
Message:

CaWE: The models of static_detail_model entities now show their GUI panel in the 3D views of the editor (if they have any).

Location:
cafu/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Ca3DE/MainCanvas.cpp

    r424 r439  
    453453        if (MainMenuGui==NULL) 
    454454        { 
    455             MainMenuGui=new cf::GuiSys::GuiImplT(*m_GuiResources, "Err=gui:new('WindowT'); gui:SetRootWindow(Err); gui:activate(true); gui:setInteractive(true); gui:showMouse(true); Err:set('rect', 0, 0, 640, 480); Err:set('text', 'Error loading MainMenu_main.cgui,\\nsee console <F1> for details.');", true); 
     455            MainMenuGui=new cf::GuiSys::GuiImplT(*m_GuiResources, "Err=gui:new('WindowT'); gui:SetRootWindow(Err); gui:activate(true); gui:setInteractive(true); gui:showMouse(false); Err:set('rect', 0, 0, 640, 480); Err:set('textScale', 0.8); Err:set('text', 'Error loading MainMenu_main.cgui,\\nsee console <F1> for details.');", true); 
    456456            cf::GuiSys::GuiMan->Register(MainMenuGui); 
    457457        } 
  • cafu/trunk/CaWE/MapHelperModel.cpp

    r414 r439  
    5757      m_Model(NULL), 
    5858      m_ModelFrameNr(0.0f), 
     59      m_GuiNames(), 
     60      m_Guis(), 
    5961      m_Timer() 
    6062{ 
     
    6769      m_Model(Model.m_Model), 
    6870      m_ModelFrameNr(0.0f), 
     71      m_GuiNames(), 
     72      m_Guis(), 
    6973      m_Timer(Model.m_Timer) 
    7074{ 
     75} 
     76 
     77 
     78MapHelperModelT::~MapHelperModelT() 
     79{ 
     80    ClearGuis(); 
    7181} 
    7282 
     
    93103    m_ModelFrameNr=Model->m_ModelFrameNr; 
    94104    m_Timer       =Model->m_Timer; 
     105 
     106    ClearGuis(); 
    95107} 
    96108 
     
    167179        Pose->Draw(-1 /*default skin*/, CAFU_ENG_SCALE*ModelDist); 
    168180 
     181        const MatrixT ModelToWorld=MatSys::Renderer->GetMatrix(MatSys::RendererI::MODEL_TO_WORLD); 
     182 
     183        for (unsigned long GFNr=0; GFNr<m_Model->GetGuiFixtures().Size(); GFNr++) 
     184        { 
     185            Vector3fT GuiOrigin; 
     186            Vector3fT GuiAxisX; 
     187            Vector3fT GuiAxisY; 
     188 
     189            if (Pose->GetGuiPlane(GFNr, GuiOrigin, GuiAxisX, GuiAxisY)) 
     190            { 
     191                // It's pretty easy to derive this matrix geometrically, see my TechArchive note from 2006-08-22. 
     192                MatrixT M(GuiAxisX.x/640.0f, GuiAxisY.x/480.0f, 0.0f, GuiOrigin.x, 
     193                          GuiAxisX.y/640.0f, GuiAxisY.y/480.0f, 0.0f, GuiOrigin.y, 
     194                          GuiAxisX.z/640.0f, GuiAxisY.z/480.0f, 0.0f, GuiOrigin.z, 
     195                                       0.0f,              0.0f, 0.0f,        1.0f); 
     196 
     197                MatSys::Renderer->SetMatrix(MatSys::RendererI::MODEL_TO_WORLD, ModelToWorld*M); 
     198 
     199                m_Guis[GFNr]->Render(true /*zLayerCoating*/); 
     200            } 
     201        } 
     202 
    169203        MatSys::Renderer->PopMatrix(MatSys::RendererI::MODEL_TO_WORLD); 
    170204 
     
    180214 
    181215 
     216void MapHelperModelT::ClearGuis() const 
     217{ 
     218    for (unsigned long GuiNr=0; GuiNr<m_Guis.Size(); GuiNr++) 
     219    { 
     220        delete m_Guis[GuiNr]; 
     221        m_Guis[GuiNr]=NULL; 
     222    } 
     223 
     224    m_GuiNames.Overwrite(); 
     225    m_Guis.Overwrite(); 
     226} 
     227 
     228 
    182229void MapHelperModelT::UpdateModelCache() const 
    183230{ 
     231    GameConfigT& GameConfig=const_cast<GameConfigT&>(m_ParentEntity->GetClass()->GetGameConfig()); 
     232 
    184233    wxString ModelName=""; 
    185234    wxString ErrorMsg =""; 
     
    198247    } 
    199248 
    200     const CafuModelT* Model=m_ParentEntity->GetClass()->GetGameConfig().GetModel(ModelName, &ErrorMsg); 
     249    const CafuModelT* Model=GameConfig.GetModel(ModelName, &ErrorMsg); 
    201250 
    202251    if (m_Model!=Model) 
     
    208257        m_Model       =Model; 
    209258        m_ModelFrameNr=0.0f; 
     259 
     260        ClearGuis(); 
     261    } 
     262 
     263 
     264    while (m_GuiNames.Size() < m_Model->GetGuiFixtures().Size()) m_GuiNames.PushBack(""); 
     265    while (m_Guis.Size()     < m_Model->GetGuiFixtures().Size()) m_Guis.PushBack(NULL); 
     266 
     267    for (unsigned long GFNr=0; GFNr<m_Model->GetGuiFixtures().Size(); GFNr++) 
     268    { 
     269        const EntPropertyT* GuiProp=m_ParentEntity->FindProperty("gui"); 
     270 
     271        if (!GuiProp || GFNr>0) 
     272            GuiProp=m_ParentEntity->FindProperty(wxString::Format("gui%lu", GFNr+1)); 
     273 
     274        const wxString NewGuiName=GuiProp ? GuiProp->Value : ""; 
     275 
     276        if (!m_Guis[GFNr] || NewGuiName!=m_GuiNames[GFNr]) 
     277        { 
     278            m_GuiNames[GFNr]=NewGuiName; 
     279            delete m_Guis[GFNr]; 
     280            m_Guis[GFNr]=NULL; 
     281 
     282            try 
     283            { 
     284                if (m_GuiNames[GFNr]=="") 
     285                { 
     286                    m_Guis[GFNr]=new cf::GuiSys::GuiImplT(GameConfig.GetGuiResources(), 
     287                        "Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
     288                        "gui:setInteractive(true); gui:showMouse(false); Win1:set('rect', 0, 0, 640, 480); " 
     289                        "Win1:set('backColor', 150/255, 170/255, 204/255, 0.8); " 
     290                        "Win1:set('textAlignHor', 2); Win1:set('textAlignVer', 2); " 
     291                        "Win1:set('textColor', 15/255, 49/255, 106/255); " 
     292                        "Win1:set('text', 'This is a\\nfull-scale sample GUI.\\n\\n" 
     293                        "Set the \\\""+ std::string(GuiProp->Key) +"\\\" entity property\\nto assign the true GUI.');", true); 
     294                } 
     295                else 
     296                { 
     297                    m_Guis[GFNr]=new cf::GuiSys::GuiImplT(GameConfig.GetGuiResources(), std::string(GameConfig.ModDir + "/" + m_GuiNames[GFNr])); 
     298                } 
     299            } 
     300            catch (const cf::GuiSys::GuiImplT::InitErrorT& IE) 
     301            { 
     302                // This one must not throw again... 
     303                m_Guis[GFNr]=new cf::GuiSys::GuiImplT(GameConfig.GetGuiResources(), 
     304                    "Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
     305                    "gui:setInteractive(true); gui:showMouse(false); Win1:set('rect', 0, 0, 640, 480); " 
     306                    "Win1:set('backColor', 150/255, 170/255, 204/255, 0.8); " 
     307                    "Win1:set('textAlignHor', 2); Win1:set('textAlignVer', 2); " 
     308                    "Win1:set('textColor', 15/255, 49/255, 106/255); " 
     309                    "Win1:set('textScale', 0.6); " 
     310                    "Win1:set('text', [=====[Could not load GUI\n" + 
     311                    std::string(GameConfig.ModDir + "/" + m_GuiNames[GFNr]) + "\n\n" + IE.what() + "]=====]);", true); 
     312            } 
     313        } 
    210314    } 
    211315} 
  • cafu/trunk/CaWE/MapHelperModel.hpp

    r414 r439  
    3333 
    3434class CafuModelT; 
     35namespace cf { namespace GuiSys { class GuiImplT; } } 
    3536namespace cf { namespace TypeSys { class TypeInfoT; } } 
    3637namespace cf { namespace TypeSys { class TypeInfoManT; } } 
     
    4849    /// @param Model   The model to copy-construct this model from. 
    4950    MapHelperModelT(const MapHelperModelT& Model); 
     51 
     52    /// The destructor. 
     53    ~MapHelperModelT(); 
    5054 
    5155 
     
    6872    protected: 
    6973 
     74    void ClearGuis() const; 
    7075    void UpdateModelCache() const; 
    7176    int  GetSequenceNr() const; 
    7277 
    73     const HelperInfoT*        m_HelperInfo;     ///< The HelperInfoT instance that caused the instantiation of this helper. 
    74     mutable const CafuModelT* m_Model;          ///< Our model (obtained from the game config's model manager). 
    75     mutable float             m_ModelFrameNr;   ///< The frame number of the sequence to render this model in. 
    76     mutable TimerT            m_Timer; 
     78    const HelperInfoT*                    m_HelperInfo;     ///< The HelperInfoT instance that caused the instantiation of this helper. 
     79    mutable const CafuModelT*             m_Model;          ///< Our model (obtained from the game config's model manager). 
     80    mutable float                         m_ModelFrameNr;   ///< The frame number of the sequence to render this model in. 
     81    mutable ArrayT<wxString>              m_GuiNames;       ///< The names of the GUIs in m_Guis. 
     82    mutable ArrayT<cf::GuiSys::GuiImplT*> m_Guis;           ///< The GUIs that are rendered where the model has GUI fixtures. 
     83    mutable TimerT                        m_Timer; 
    7784}; 
    7885 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp

    r435 r439  
    7171      m_Gui(new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), 
    7272          "Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
    73           "gui:setInteractive(true); gui:showMouse(true); Win1:set('rect', 0, 0, 640, 480); " 
     73          "gui:setInteractive(true); gui:showMouse(false); Win1:set('rect', 0, 0, 640, 480); " 
    7474          "Win1:set('backColor', 150/255, 170/255, 204/255, 0.8); " 
    7575          "Win1:set('textAlignHor', 2); Win1:set('textAlignVer', 2); " 
  • cafu/trunk/CaWE/ParentFrame.cpp

    r428 r439  
    558558        wxMessageBox(wxString("The model file \"")+FileName+"\" could not be loaded:\n"+LE.what(), "Couldn't load or import model"); 
    559559    } 
    560     catch (const cf::GuiSys::GuiImplT::InitErrorT& /*E*/) 
    561     { 
    562         wxMessageBox(wxString("The GUI script \"")+FileName+"\" could not be loaded!", "Couldn't load GUI script"); 
     560    catch (const cf::GuiSys::GuiImplT::InitErrorT& IE) 
     561    { 
     562        wxMessageBox(wxString("The GUI script \"")+FileName+"\" could not be loaded:\n"+IE.what(), "Couldn't load GUI script"); 
    563563    } 
    564564 
  • cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.cpp

    r438 r439  
    312312            MatSys::Renderer->SetMatrix(MatSys::RendererI::MODEL_TO_WORLD, ModelToWorld*M); 
    313313 
    314             Gui->Render(); 
     314            Gui->Render();      // Set the zLayerCoating parameter to true here? 
    315315#else 
    316316            MatSys::Renderer->SetCurrentMaterial(cf::GuiSys::GuiMan->GetDefaultRM()); 
  • cafu/trunk/Games/Game.hpp

    r423 r439  
    5252            /// @param AsClient     Tells whether we're running as client. 
    5353            /// @param AsServer     Tells whether we're running as server. 
     54            /// @param ModelMan     The manager for all models that are used in this game. 
    5455            virtual void Initialize(bool AsClient, bool AsServer, ModelManagerT& ModelMan)=0; 
    5556 
  • cafu/trunk/Libs/GuiSys/Gui.hpp

    r415 r439  
    8787 
    8888            /// Renders this GUI. 
    89             /// Note that this method does *not* setup any of the MatSys's model, view or projection matrices: it's up to the caller to do that! 
    90             virtual void Render() const=0; 
     89            /// Note that this method does *not* setup any of the MatSys's model, view or projection matrices: 
     90            /// it's up to the caller to do that. 
     91            /// @param zLayerCoating   Whether a z-layer coating should be applied to the GUI screen when finishing the rendering. 
     92            ///     This is useful whenever the z-ordering of scene elements can be imperfect, e.g. in the Map Editor. 
     93            ///     Generally, 3D world GUIs should use \c true, 2D GUIs should use \c false. 
     94            virtual void Render(bool zLayerCoating=false) const=0; 
    9195 
    9296            /// Processes a keyboard event by forwarding it to the window that currently has the input focus. 
  • cafu/trunk/Libs/GuiSys/GuiImpl.cpp

    r423 r439  
    116116      m_GuiDefaultRM(NULL), 
    117117      m_GuiPointerRM(NULL), 
     118      m_GuiFinishZRM(NULL), 
    118119      m_GuiResources(GuiRes), 
    119120      RootWindow(NULL), 
     
    137138    } 
    138139 
    139     if (!m_MaterialMan.GetMaterial("Gui/Default")) 
     140    if (!m_MaterialMan.HasMaterial("Gui/Default")) 
    140141    { 
    141142        // This material has either not been defined in the .cmat file, or we're dealing with inline code. 
     
    151152    } 
    152153 
    153     if (!m_MaterialMan.GetMaterial("Gui/Cursors/Pointer")) 
     154    if (!m_MaterialMan.HasMaterial("Gui/Cursors/Pointer")) 
    154155    { 
    155156        // This material has either not been defined in the .cmat file, or we're dealing with inline code. 
     
    165166    } 
    166167 
     168    if (!m_MaterialMan.HasMaterial("Gui/FinishZ")) 
     169    { 
     170        // This material has either not been defined in the .cmat file, or we're dealing with inline code. 
     171        MaterialT Mat; 
     172 
     173        Mat.Name          ="Gui/FinishZ"; 
     174     // Mat.DiffMapComp   =...; 
     175        Mat.UseMeshColors =true; 
     176        Mat.AmbientMask[0]=false; 
     177        Mat.AmbientMask[1]=false; 
     178        Mat.AmbientMask[2]=false; 
     179        Mat.AmbientMask[3]=false; 
     180 
     181        m_MaterialMan.RegisterMaterial(Mat); 
     182    } 
     183 
    167184    m_GuiDefaultRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/Default")); 
    168185    m_GuiPointerRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/Cursors/Pointer")); 
     186    m_GuiFinishZRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/FinishZ")); 
    169187 
    170188 
     
    320338        MatSys::Renderer->FreeMaterial(m_GuiDefaultRM); 
    321339        MatSys::Renderer->FreeMaterial(m_GuiPointerRM); 
     340        MatSys::Renderer->FreeMaterial(m_GuiFinishZRM); 
    322341        throw InitErrorT("No root window set. Probable cause:\n"+ScriptInitResult); 
    323342    } 
     
    363382    MatSys::Renderer->FreeMaterial(m_GuiDefaultRM); 
    364383    MatSys::Renderer->FreeMaterial(m_GuiPointerRM); 
     384    MatSys::Renderer->FreeMaterial(m_GuiFinishZRM); 
    365385} 
    366386 
     
    445465 
    446466 
    447 void GuiImplT::Render() const 
     467void GuiImplT::Render(bool zLayerCoating) const 
    448468{ 
    449469    RootWindow->Render(); 
    450470 
     471    static MatSys::MeshT Mesh(MatSys::MeshT::TriangleFan); 
     472 
     473    if (Mesh.Vertices.Size()<4) 
     474    { 
     475        Mesh.Vertices.PushBackEmpty(4); 
     476 
     477        for (unsigned long VNr=0; VNr<Mesh.Vertices.Size(); VNr++) 
     478        { 
     479            Mesh.Vertices[VNr].SetColor(1.0f, 1.0f, 1.0f, 1.0f); 
     480            Mesh.Vertices[VNr].SetTextureCoord(VNr==0 || VNr==3 ? 0.0f : 1.0f, VNr<2 ? 0.0f : 1.0f); 
     481        } 
     482    } 
     483 
    451484    if (MouseIsShown) 
    452485    { 
    453         static MatSys::MeshT Mesh(MatSys::MeshT::TriangleFan); 
    454  
    455         if (Mesh.Vertices.Size()<4) 
    456         { 
    457             Mesh.Vertices.PushBackEmpty(4); 
    458  
    459             for (unsigned long VNr=0; VNr<Mesh.Vertices.Size(); VNr++) 
    460             { 
    461                 Mesh.Vertices[VNr].SetColor(1.0f, 1.0f, 1.0f, 1.0f); 
    462                 Mesh.Vertices[VNr].SetTextureCoord(VNr==0 || VNr==3 ? 0.0f : 1.0f, VNr<2 ? 0.0f : 1.0f); 
    463             } 
    464         } 
    465  
    466486        const float b=(EntityName=="") ? 20.0f : 40.0f;     // The mouse cursor size (double for world GUIs). 
    467487 
     
    472492 
    473493        MatSys::Renderer->SetCurrentMaterial(m_GuiPointerRM); 
     494        MatSys::Renderer->RenderMesh(Mesh); 
     495    } 
     496 
     497    if (zLayerCoating) 
     498    { 
     499        // Finish by applying a z-layer coating to the GUI screen. 
     500        // This is important whenever the z-ordering of scene elements can be imperfect, e.g. in the Map Editor. 
     501        Mesh.Vertices[0].SetOrigin(  0.0f,   0.0f); 
     502        Mesh.Vertices[1].SetOrigin(640.0f,   0.0f); 
     503        Mesh.Vertices[2].SetOrigin(640.0f, 480.0f); 
     504        Mesh.Vertices[3].SetOrigin(  0.0f, 480.0f); 
     505 
     506        MatSys::Renderer->SetCurrentMaterial(m_GuiFinishZRM); 
    474507        MatSys::Renderer->RenderMesh(Mesh); 
    475508    } 
  • cafu/trunk/Libs/GuiSys/GuiImpl.hpp

    r415 r439  
    131131            void SetShowMouse(bool ShowMouse_); 
    132132            bool IsMouseShown() const { return MouseIsShown; } 
    133             void Render() const; 
     133            void Render(bool zLayerCoating=false) const; 
    134134            bool ProcessDeviceEvent(const CaKeyboardEventT& KE); 
    135135            bool ProcessDeviceEvent(const CaMouseEventT& ME); 
     
    173173            MatSys::RenderMaterialT* m_GuiDefaultRM;    ///< Used for the window borders and the backgrounds if no other material is specified. 
    174174            MatSys::RenderMaterialT* m_GuiPointerRM;    ///< Used for the mouse pointer. 
     175            MatSys::RenderMaterialT* m_GuiFinishZRM;    ///< Used for laying-down z-buffer values after all GUI elements have been rendered. 
    175176            GuiResourcesT&           m_GuiResources;    ///< The provider for resources (fonts and models) that are used in this GUI. 
    176177 
  • cafu/trunk/Libs/MaterialSystem/MaterialManagerImpl.cpp

    r306 r439  
    354354 
    355355 
     356bool MaterialManagerImplT::HasMaterial(const std::string& MaterialName) const 
     357{ 
     358    std::map<std::string, MaterialT*>::const_iterator It=Materials.find(MaterialName); 
     359 
     360    return It!=Materials.end(); 
     361} 
     362 
     363 
    356364MaterialT* MaterialManagerImplT::GetMaterial(const std::string& MaterialName) const 
    357365{ 
  • cafu/trunk/Libs/MaterialSystem/MaterialManagerImpl.hpp

    r303 r439  
    4646    /// If a material with the same name \c Mat.Name is already registered with the material manager, 
    4747    /// \c Mat is not registered, but a pointer to the already registered instance with the same name is returned 
    48     /// (use GetMaterial() in advance to unambigiously distingush between the two cases). 
     48    /// (use HasMaterial() in advance to unambigiously distingush between the two cases). 
    4949    /// 
    5050    /// @param Mat   The material of which a copy is to be registered with the material manager. 
    5151    /// @returns A pointer to the registered material instance (or a previously existing instance with the same name). 
    5252    MaterialT* RegisterMaterial(const MaterialT& Mat); 
     53 
     54    /// Returns whether the material with the given name is registered with the material manager, 
     55    /// i.e. if a call to <code>GetMaterial(MaterialName)</code> will return successfully. 
     56    /// Use this to avoid warning messages to the console if the material is not registered. 
     57    bool HasMaterial(const std::string& MaterialName) const; 
    5358 
    5459    // The MaterialManagerI interface.