Changeset 439
- Timestamp:
- 12/04/11 13:06:30 (6 months ago)
- Location:
- cafu/trunk
- Files:
-
- 12 modified
-
Ca3DE/MainCanvas.cpp (modified) (1 diff)
-
CaWE/MapHelperModel.cpp (modified) (7 diffs)
-
CaWE/MapHelperModel.hpp (modified) (3 diffs)
-
CaWE/ModelEditor/ModelDocument.cpp (modified) (1 diff)
-
CaWE/ParentFrame.cpp (modified) (1 diff)
-
Games/DeathMatch/Code/StaticDetailModel.cpp (modified) (1 diff)
-
Games/Game.hpp (modified) (1 diff)
-
Libs/GuiSys/Gui.hpp (modified) (1 diff)
-
Libs/GuiSys/GuiImpl.cpp (modified) (8 diffs)
-
Libs/GuiSys/GuiImpl.hpp (modified) (2 diffs)
-
Libs/MaterialSystem/MaterialManagerImpl.cpp (modified) (1 diff)
-
Libs/MaterialSystem/MaterialManagerImpl.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/Ca3DE/MainCanvas.cpp
r424 r439 453 453 if (MainMenuGui==NULL) 454 454 { 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); 456 456 cf::GuiSys::GuiMan->Register(MainMenuGui); 457 457 } -
cafu/trunk/CaWE/MapHelperModel.cpp
r414 r439 57 57 m_Model(NULL), 58 58 m_ModelFrameNr(0.0f), 59 m_GuiNames(), 60 m_Guis(), 59 61 m_Timer() 60 62 { … … 67 69 m_Model(Model.m_Model), 68 70 m_ModelFrameNr(0.0f), 71 m_GuiNames(), 72 m_Guis(), 69 73 m_Timer(Model.m_Timer) 70 74 { 75 } 76 77 78 MapHelperModelT::~MapHelperModelT() 79 { 80 ClearGuis(); 71 81 } 72 82 … … 93 103 m_ModelFrameNr=Model->m_ModelFrameNr; 94 104 m_Timer =Model->m_Timer; 105 106 ClearGuis(); 95 107 } 96 108 … … 167 179 Pose->Draw(-1 /*default skin*/, CAFU_ENG_SCALE*ModelDist); 168 180 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 169 203 MatSys::Renderer->PopMatrix(MatSys::RendererI::MODEL_TO_WORLD); 170 204 … … 180 214 181 215 216 void 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 182 229 void MapHelperModelT::UpdateModelCache() const 183 230 { 231 GameConfigT& GameConfig=const_cast<GameConfigT&>(m_ParentEntity->GetClass()->GetGameConfig()); 232 184 233 wxString ModelName=""; 185 234 wxString ErrorMsg =""; … … 198 247 } 199 248 200 const CafuModelT* Model= m_ParentEntity->GetClass()->GetGameConfig().GetModel(ModelName, &ErrorMsg);249 const CafuModelT* Model=GameConfig.GetModel(ModelName, &ErrorMsg); 201 250 202 251 if (m_Model!=Model) … … 208 257 m_Model =Model; 209 258 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 } 210 314 } 211 315 } -
cafu/trunk/CaWE/MapHelperModel.hpp
r414 r439 33 33 34 34 class CafuModelT; 35 namespace cf { namespace GuiSys { class GuiImplT; } } 35 36 namespace cf { namespace TypeSys { class TypeInfoT; } } 36 37 namespace cf { namespace TypeSys { class TypeInfoManT; } } … … 48 49 /// @param Model The model to copy-construct this model from. 49 50 MapHelperModelT(const MapHelperModelT& Model); 51 52 /// The destructor. 53 ~MapHelperModelT(); 50 54 51 55 … … 68 72 protected: 69 73 74 void ClearGuis() const; 70 75 void UpdateModelCache() const; 71 76 int GetSequenceNr() const; 72 77 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; 77 84 }; 78 85 -
cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp
r435 r439 71 71 m_Gui(new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), 72 72 "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); " 74 74 "Win1:set('backColor', 150/255, 170/255, 204/255, 0.8); " 75 75 "Win1:set('textAlignHor', 2); Win1:set('textAlignVer', 2); " -
cafu/trunk/CaWE/ParentFrame.cpp
r428 r439 558 558 wxMessageBox(wxString("The model file \"")+FileName+"\" could not be loaded:\n"+LE.what(), "Couldn't load or import model"); 559 559 } 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"); 563 563 } 564 564 -
cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.cpp
r438 r439 312 312 MatSys::Renderer->SetMatrix(MatSys::RendererI::MODEL_TO_WORLD, ModelToWorld*M); 313 313 314 Gui->Render(); 314 Gui->Render(); // Set the zLayerCoating parameter to true here? 315 315 #else 316 316 MatSys::Renderer->SetCurrentMaterial(cf::GuiSys::GuiMan->GetDefaultRM()); -
cafu/trunk/Games/Game.hpp
r423 r439 52 52 /// @param AsClient Tells whether we're running as client. 53 53 /// @param AsServer Tells whether we're running as server. 54 /// @param ModelMan The manager for all models that are used in this game. 54 55 virtual void Initialize(bool AsClient, bool AsServer, ModelManagerT& ModelMan)=0; 55 56 -
cafu/trunk/Libs/GuiSys/Gui.hpp
r415 r439 87 87 88 88 /// 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; 91 95 92 96 /// Processes a keyboard event by forwarding it to the window that currently has the input focus. -
cafu/trunk/Libs/GuiSys/GuiImpl.cpp
r423 r439 116 116 m_GuiDefaultRM(NULL), 117 117 m_GuiPointerRM(NULL), 118 m_GuiFinishZRM(NULL), 118 119 m_GuiResources(GuiRes), 119 120 RootWindow(NULL), … … 137 138 } 138 139 139 if (!m_MaterialMan. GetMaterial("Gui/Default"))140 if (!m_MaterialMan.HasMaterial("Gui/Default")) 140 141 { 141 142 // This material has either not been defined in the .cmat file, or we're dealing with inline code. … … 151 152 } 152 153 153 if (!m_MaterialMan. GetMaterial("Gui/Cursors/Pointer"))154 if (!m_MaterialMan.HasMaterial("Gui/Cursors/Pointer")) 154 155 { 155 156 // This material has either not been defined in the .cmat file, or we're dealing with inline code. … … 165 166 } 166 167 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 167 184 m_GuiDefaultRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/Default")); 168 185 m_GuiPointerRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/Cursors/Pointer")); 186 m_GuiFinishZRM=MatSys::Renderer->RegisterMaterial(m_MaterialMan.GetMaterial("Gui/FinishZ")); 169 187 170 188 … … 320 338 MatSys::Renderer->FreeMaterial(m_GuiDefaultRM); 321 339 MatSys::Renderer->FreeMaterial(m_GuiPointerRM); 340 MatSys::Renderer->FreeMaterial(m_GuiFinishZRM); 322 341 throw InitErrorT("No root window set. Probable cause:\n"+ScriptInitResult); 323 342 } … … 363 382 MatSys::Renderer->FreeMaterial(m_GuiDefaultRM); 364 383 MatSys::Renderer->FreeMaterial(m_GuiPointerRM); 384 MatSys::Renderer->FreeMaterial(m_GuiFinishZRM); 365 385 } 366 386 … … 445 465 446 466 447 void GuiImplT::Render( ) const467 void GuiImplT::Render(bool zLayerCoating) const 448 468 { 449 469 RootWindow->Render(); 450 470 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 451 484 if (MouseIsShown) 452 485 { 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 466 486 const float b=(EntityName=="") ? 20.0f : 40.0f; // The mouse cursor size (double for world GUIs). 467 487 … … 472 492 473 493 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); 474 507 MatSys::Renderer->RenderMesh(Mesh); 475 508 } -
cafu/trunk/Libs/GuiSys/GuiImpl.hpp
r415 r439 131 131 void SetShowMouse(bool ShowMouse_); 132 132 bool IsMouseShown() const { return MouseIsShown; } 133 void Render( ) const;133 void Render(bool zLayerCoating=false) const; 134 134 bool ProcessDeviceEvent(const CaKeyboardEventT& KE); 135 135 bool ProcessDeviceEvent(const CaMouseEventT& ME); … … 173 173 MatSys::RenderMaterialT* m_GuiDefaultRM; ///< Used for the window borders and the backgrounds if no other material is specified. 174 174 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. 175 176 GuiResourcesT& m_GuiResources; ///< The provider for resources (fonts and models) that are used in this GUI. 176 177 -
cafu/trunk/Libs/MaterialSystem/MaterialManagerImpl.cpp
r306 r439 354 354 355 355 356 bool 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 356 364 MaterialT* MaterialManagerImplT::GetMaterial(const std::string& MaterialName) const 357 365 { -
cafu/trunk/Libs/MaterialSystem/MaterialManagerImpl.hpp
r303 r439 46 46 /// If a material with the same name \c Mat.Name is already registered with the material manager, 47 47 /// \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). 49 49 /// 50 50 /// @param Mat The material of which a copy is to be registered with the material manager. 51 51 /// @returns A pointer to the registered material instance (or a previously existing instance with the same name). 52 52 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; 53 58 54 59 // The MaterialManagerI interface.
