Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / view_radar.cpp
blob49f305bb20785a4f711afee4641bdee6e848ffee
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
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 // ----------------------------------------------------------------------------
24 #include "stdpch.h"
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 // ----------------------------------------------------------------------------
37 using namespace std;
38 using namespace NLMISC;
39 using namespace NL3D;
41 #ifdef DEBUG_NEW
42 #define new DEBUG_NEW
43 #endif
45 extern NL3D::UCamera MainCam;
47 NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar");
49 // ----------------------------------------------------------------------------
51 CViewRadar::CViewRadar(const TCtorParam &param)
52 : CViewBase(param)
54 CInterfaceManager *pIM = CInterfaceManager::getInstance();
55 CCDBNodeLeaf *pUIMI = CDBManager::getInstance()->getDbProp( "UI:SAVE:INSCENE:FRIEND:MISSION_ICON" );
56 if (pUIMI)
58 ICDBNode::CTextId textId;
59 pUIMI->addObserver( &_MissionIconsObs, textId);
62 CCDBNodeLeaf *pUIMMI = CDBManager::getInstance()->getDbProp( "UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON" );
63 if (pUIMMI)
65 ICDBNode::CTextId textId;
66 pUIMMI->addObserver( &_MiniMissionSpotsObs, textId);
70 bool CViewRadar::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup)
72 CXMLAutoPtr prop;
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();
80 nlinfo (tmp.c_str());
81 return false;
84 // World size
85 _WorldSize = 100.0;
86 prop = (char*) xmlGetProp( cur, (xmlChar*)"world_size" );
87 if (prop) fromString((const char*)prop, _WorldSize);
89 // Spot textures
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)
101 string txName;
103 // Large missions Icons
104 prop = (char*) xmlGetProp( cur, (xmlChar*)spotTextureNames[i] );
105 if (prop)
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] );
114 if (prop)
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);
121 if (i == 0)
122 _SpotDescriptions[i].isMissionSpot = false;
123 else
124 _SpotDescriptions[i].isMissionSpot = true;
127 return 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;
139 float angle;
140 CVectorD xyzRef = user->pos();
141 if (_UseCamera)
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));
152 else
154 const CVector dir = user->front();
155 angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0));
158 CMatrix mat;
159 mat.identity();
160 // Scale to transform from world to interface screen
161 mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) );
162 // local to user
163 mat.rotateZ(-angle);
164 xyzRef.z = 0;
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())
176 continue;
178 // get entity pos
179 CVectorD xyz = entity->pos();
181 xyz.z = 0;
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;
185 // Transform the dot
186 xyz = mat * xyz;
188 // Convert to screen
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());
196 else
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 );
216 else
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();