1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // ----------------------------------------------------------------------------
26 #include "view_radar.h"
27 #include "interface_manager.h"
28 #include "nel/misc/xml_auto_ptr.h"
29 #include "nel/gui/group_container.h"
30 #include "../npc_icon.h"
31 #include "nel/misc/fast_floor.h"
33 #include "../entities.h"
35 // ----------------------------------------------------------------------------
38 using namespace NLMISC
;
45 extern NL3D::UCamera MainCam
;
47 NLMISC_REGISTER_OBJECT(CViewBase
, CViewRadar
, std::string
, "radar");
49 // ----------------------------------------------------------------------------
51 CViewRadar::CViewRadar(const TCtorParam
¶m
)
54 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
55 CCDBNodeLeaf
*pUIMI
= CDBManager::getInstance()->getDbProp( "UI:SAVE:INSCENE:FRIEND:MISSION_ICON" );
58 ICDBNode::CTextId textId
;
59 pUIMI
->addObserver( &_MissionIconsObs
, textId
);
62 CCDBNodeLeaf
*pUIMMI
= CDBManager::getInstance()->getDbProp( "UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON" );
65 ICDBNode::CTextId textId
;
66 pUIMMI
->addObserver( &_MiniMissionSpotsObs
, textId
);
70 bool CViewRadar::parse(xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
74 //try to get props that can be inherited from groups
75 //if a property is not defined, try to find it in the parent group.
76 //if it is undefined, set it to zero
77 if (! CViewBase::parse(cur
,parentGroup
) )
79 string tmp
= string("cannot parse view:")+getId()+", parent:"+parentGroup
->getId();
86 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"world_size" );
87 if (prop
) fromString((const char*)prop
, _WorldSize
);
90 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
91 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
93 // Large missions Icons
94 const char *spotTextureNames
[NbRadarSpotIds
] = { "texture_std", "texture_missionlist", "texture_missionauto", "texture_missionstep" };
96 // Mini missions Icons
97 const char *spotMiniTextureNames
[NbRadarSpotIds
] = { "texture_std", "mini_texture_missionlist", "mini_texture_missionauto", "mini_texture_missionstep" };
99 for (uint i
=0; i
!=NbRadarSpotIds
; ++i
)
103 // Large missions Icons
104 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)spotTextureNames
[i
] );
107 txName
= toLowerAscii((const char *) prop
);
109 _SpotDescriptions
[i
].TextureId
.setTexture(txName
.c_str());
110 rVR
.getTextureSizeFromId (_SpotDescriptions
[i
].TextureId
, _SpotDescriptions
[i
].TxW
, _SpotDescriptions
[i
].TxH
);
112 // Mini missions Icons
113 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)spotMiniTextureNames
[i
] );
116 txName
= toLowerAscii((const char *) prop
);
118 _SpotDescriptions
[i
].MiniTextureId
.setTexture(txName
.c_str());
119 rVR
.getTextureSizeFromId (_SpotDescriptions
[i
].MiniTextureId
, _SpotDescriptions
[i
].MTxW
, _SpotDescriptions
[i
].MTxH
);
122 _SpotDescriptions
[i
].isMissionSpot
= false;
124 _SpotDescriptions
[i
].isMissionSpot
= true;
130 // ----------------------------------------------------------------------------
131 void CViewRadar::draw ()
133 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
134 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
136 CEntityCL
*user
= EntitiesMngr
.entity(0);
137 if (user
== NULL
) return;
140 CVectorD xyzRef
= user
->pos();
143 CVector projectedFront
= MainCam
.getMatrix().getJ();
144 if (projectedFront
.norm() <= 0.01f
)
146 projectedFront
= MainCam
.getMatrix().getK();
147 projectedFront
.z
= 0.f
;
149 CVector cam
= projectedFront
.normed();
150 angle
= (float)(atan2(cam
.y
, cam
.x
) - (Pi
/ 2.0));
154 const CVector dir
= user
->front();
155 angle
= (float)(atan2(dir
.y
, dir
.x
) - (Pi
/ 2.0));
160 // Scale to transform from world to interface screen
161 mat
.scale( CVector((float)(_WReal
/ _WorldSize
), (float)(_HReal
/ _WorldSize
), 1) );
165 mat
.translate(-xyzRef
);
167 float maxSqrRadius
= (float)sqr(_WorldSize
/2);
169 for (sint32 i
= 1; i
< 256; ++i
)
171 CEntityCL
*entity
= EntitiesMngr
.entity(i
);
172 if (entity
== NULL
) continue;
174 // if the entity must not be shown in radar
175 if(!entity
->getDisplayInRadar())
179 CVectorD xyz
= entity
->pos();
182 // if the distance is too big so do not display the entity
183 if ((sqr(xyz
.x
- xyzRef
.x
)+sqr(xyz
.y
- xyzRef
.y
)) > maxSqrRadius
) continue;
189 sint32 x
= OptFastFloor((float)xyz
.x
);
190 sint32 y
= OptFastFloor((float)xyz
.y
);
192 CRGBA col
= entity
->getColor();
194 if(getModulateGlobalColor())
195 col
.modulateFromColor (col
, CWidgetManager::getInstance()->getGlobalColorForContent());
197 col
.A
= (uint8
)(((sint32
)col
.A
*((sint32
)CWidgetManager::getInstance()->getGlobalColorForContent().A
+1))>>8);
199 // Select the icon to display and draw it
200 uint spotId
= CNPCIconCache::getInstance().getNPCIcon(entity
).getSpotId();
201 CRadarSpotDesc spotDesc
= _SpotDescriptions
[spotId
];
203 if (!_MissionIconsObs
._displayMissionSpots
)
204 spotDesc
= _SpotDescriptions
[0];
206 if (spotDesc
.isMissionSpot
)
207 col
= CRGBA(255, 255, 255, 255);
209 if (entity
->isTarget())
210 spotId
= 4; // to make it over other spots
212 // Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range)
213 if (spotDesc
.isMissionSpot
&& _MiniMissionSpotsObs
._displayMiniMissionSpots
)
214 rVR
.drawRotFlipBitmap (_RenderLayer
+spotId
, _XReal
+x
-(spotDesc
.MTxW
/2)+(_WReal
/2), _YReal
+y
-(spotDesc
.MTxH
/2)+(_HReal
/2),
215 spotDesc
.MTxW
, spotDesc
.MTxH
, 0, false, spotDesc
.MiniTextureId
, col
);
217 rVR
.drawRotFlipBitmap (_RenderLayer
+spotId
, _XReal
+x
-(spotDesc
.TxW
/2)+(_WReal
/2), _YReal
+y
-(spotDesc
.TxH
/2)+(_HReal
/2),
218 spotDesc
.TxW
, spotDesc
.TxH
, 0, false, spotDesc
.TextureId
, col
);
222 // ----------------------------------------------------------------------------
223 void CViewRadar::updateCoords()
225 CViewBase::updateCoords();
228 void CViewRadar::CDBMissionIconqObs::update(ICDBNode
*node
)
230 _displayMissionSpots
= ((CCDBNodeLeaf
*)node
)->getValueBool();
233 void CViewRadar::CDBMiniMissionSpotsObs::update(ICDBNode
*node
)
235 _displayMiniMissionSpots
= ((CCDBNodeLeaf
*)node
)->getValueBool();