radar.diff

view_radar.h & view_radar.cpp diff - yricl, 09/29/2012 01:54 pm

Download (12.6 kB)

b/code/ryzom/client/src/interface_v3/view_radar.cpp Sat Sep 29 13:53:02 2012 +0200
39 39

40 40
// ----------------------------------------------------------------------------
41 41

42
CViewRadar::CViewRadar(const TCtorParam &param)
43
    : CViewBase(param)
44
{
45
    CInterfaceManager *pIM = CInterfaceManager::getInstance();
46
    CCDBNodeLeaf *pUIMI = pIM->getDbProp( "UI:SAVE:INSCENE:FRIEND:MISSION_ICON" );
47
    if (pUIMI)
48
    {
49
        ICDBNode::CTextId textId;
50
        pUIMI->addObserver( &_MissionIconsObs, textId);
51
    }
52

53
    CCDBNodeLeaf *pUIMMI = pIM->getDbProp( "UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON" );
54
    if (pUIMMI)
55
    {
56
        ICDBNode::CTextId textId;
57
        pUIMMI->addObserver( &_MiniMissionSpotsObs, textId);
58
    }
59
}
60

42 61
bool CViewRadar::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup)
43 62
{
44
	CXMLAutoPtr prop;
63
    CXMLAutoPtr prop;
45 64

46
	//try to get props that can be inherited from groups
47
	//if a property is not defined, try to find it in the parent group.
48
	//if it is undefined, set it to zero
49
	if (! CViewBase::parse(cur,parentGroup) )
50
	{
51
		string tmp = string("cannot parse view:")+getId()+", parent:"+parentGroup->getId();
52
		nlinfo (tmp.c_str());
53
		return false;
54
	}
65
    //try to get props that can be inherited from groups
66
    //if a property is not defined, try to find it in the parent group.
67
    //if it is undefined, set it to zero
68
    if (! CViewBase::parse(cur,parentGroup) )
69
    {
70
        string tmp = string("cannot parse view:")+getId()+", parent:"+parentGroup->getId();
71
        nlinfo (tmp.c_str());
72
        return false;
73
    }
55 74

56
	// World size
57
	_WorldSize = 100.0;
58
	prop = (char*) xmlGetProp( cur, (xmlChar*)"world_size" );
59
	if (prop) fromString((const char*)prop, _WorldSize);
75
    // World size
76
    _WorldSize = 100.0;
77
    prop = (char*) xmlGetProp( cur, (xmlChar*)"world_size" );
78
    if (prop) fromString((const char*)prop, _WorldSize);
60 79

61
	// Spot textures
62
	CInterfaceManager *pIM = CInterfaceManager::getInstance();
63
	CViewRenderer &rVR = pIM->getViewRenderer();
64
	
65
	// Large missions Icons
66
	const char *spotTextureNames[NbRadarSpotIds] = { "texture_std", "texture_missionlist", "texture_missionauto", "texture_missionstep" };
80
    // Spot textures
81
    CInterfaceManager *pIM = CInterfaceManager::getInstance();
82
    CViewRenderer &rVR = pIM->getViewRenderer();
67 83

68
	// Mini missions Icons
69
	const char *spotMiniTextureNames[NbRadarSpotIds] = { "texture_std", "mini_texture_missionlist", "mini_texture_missionauto", "mini_texture_missionstep" };
84
    // Large missions Icons
85
    const char *spotTextureNames[NbRadarSpotIds] = { "texture_std", "texture_missionlist", "texture_missionauto", "texture_missionstep" };
70 86

71
	for (uint i=0; i!=NbRadarSpotIds; ++i)
72
	{
73
		string txName;
87
    // Mini missions Icons
88
    const char *spotMiniTextureNames[NbRadarSpotIds] = { "texture_std", "mini_texture_missionlist", "mini_texture_missionauto", "mini_texture_missionstep" };
74 89

75
		// Large missions Icons
76
		prop = (char*) xmlGetProp( cur, (xmlChar*)spotTextureNames[i] );
77
		if (prop)
78
		{
79
			txName = (const char *) prop;
80
			txName = strlwr (txName);
81
		}
82
		_SpotDescriptions[i].TextureId.setTexture(txName.c_str());
83
		rVR.getTextureSizeFromId (_SpotDescriptions[i].TextureId, _SpotDescriptions[i].TxW, _SpotDescriptions[i].TxH);
90
    for (uint i=0; i!=NbRadarSpotIds; ++i)
91
    {
92
        string txName;
84 93

85
		// Mini missions Icons
86
		prop = (char*) xmlGetProp( cur, (xmlChar*)spotMiniTextureNames[i] );
87
		if (prop)
88
		{
89
			txName = (const char *) prop;
90
			txName = strlwr (txName);
91
		}
92
		_SpotDescriptions[i].MiniTextureId.setTexture(txName.c_str());
93
		rVR.getTextureSizeFromId (_SpotDescriptions[i].MiniTextureId, _SpotDescriptions[i].MTxW, _SpotDescriptions[i].MTxH);
94
        // Large missions Icons
95
        prop = (char*) xmlGetProp( cur, (xmlChar*)spotTextureNames[i] );
96
        if (prop)
97
        {
98
            txName = (const char *) prop;
99
            txName = strlwr (txName);
100
        }
101
        _SpotDescriptions[i].TextureId.setTexture(txName.c_str());
102
        rVR.getTextureSizeFromId (_SpotDescriptions[i].TextureId, _SpotDescriptions[i].TxW, _SpotDescriptions[i].TxH);
94 103

95
		if (i == 0)
96
			_SpotDescriptions[i].isMissionSpot = false;
97
		else
98
			_SpotDescriptions[i].isMissionSpot = true;
99
	}
104
        // Mini missions Icons
105
        prop = (char*) xmlGetProp( cur, (xmlChar*)spotMiniTextureNames[i] );
106
        if (prop)
107
        {
108
            txName = (const char *) prop;
109
            txName = strlwr (txName);
110
        }
111
        _SpotDescriptions[i].MiniTextureId.setTexture(txName.c_str());
112
        rVR.getTextureSizeFromId (_SpotDescriptions[i].MiniTextureId, _SpotDescriptions[i].MTxW, _SpotDescriptions[i].MTxH);
100 113

101
	return true;
114
        if (i == 0)
115
            _SpotDescriptions[i].isMissionSpot = false;
116
        else
117
            _SpotDescriptions[i].isMissionSpot = true;
118
    }
119

120
    return true;
102 121
}
103 122

104 123
// ----------------------------------------------------------------------------
105 124
void CViewRadar::draw ()
106 125
{
107
	CInterfaceManager *pIM = CInterfaceManager::getInstance();
108
	CViewRenderer &rVR = pIM->getViewRenderer();
109 126

110
	CEntityCL *user = EntitiesMngr.entity(0);
111
	if (user == NULL) return;
112
	CVectorD xyzRef = user->pos();
113
	CVector dir = user->front();
127
    CInterfaceManager *pIM = CInterfaceManager::getInstance();
128
    CViewRenderer &rVR = pIM->getViewRenderer();
114 129

115
	float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0));
116
	CMatrix mat;
117
	mat.identity();
118
	// Scale to transform from world to interface screen
119
	mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) );
120
	// local to user
121
	mat.rotateZ(-angle);
122
	xyzRef.z = 0;
123
	mat.translate(-xyzRef);
130
    CEntityCL *user = EntitiesMngr.entity(0);
131
    if (__builtin_expect((user == NULL), true))
132
        return;
124 133

125
	float	maxSqrRadius= (float)sqr(_WorldSize/2);
134
    CVectorD xyzRef = user->pos();
135
    const CVector dir = user->front();
126 136

127
	const bool displayMissionSpots = pIM->getDbProp("UI:SAVE:INSCENE:FRIEND:MISSION_ICON")->getValueBool();
128
	const bool displayMiniMissionSpots = pIM->getDbProp("UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON")->getValueBool();
137
    float angle = (float)(atan2(dir.y, dir.x) - Pi / 2.0);
138
    CMatrix mat;
139
    mat.identity();
140
    // Scale to transform from world to interface screen
141
    mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) );
142
    // local to user
143
    mat.rotateZ(-angle);
144
    xyzRef.z = 0;
145
    mat.translate(-xyzRef);
129 146

130
	for (sint32 i = 1; i < 256; ++i)
131
	{
132
		CEntityCL *entity = EntitiesMngr.entity(i);
133
		if (entity == NULL) continue;
147
    float	maxSqrRadius= (float)sqr(_WorldSize/2);
134 148

135
		// if the entity must not be shown in radar
136
		if(!entity->getDisplayInRadar())
137
			continue;
149
    for (sint32 i = 1; i < 256; ++i)
150
    {
151
        CEntityCL *entity = EntitiesMngr.entity(i);
152
        if (entity == NULL) continue;
138 153

139
		// get entity pos
140
		CVectorD xyz = entity->pos();
154
        // if the entity must not be shown in radar
155
        if(!entity->getDisplayInRadar())
156
            continue;
141 157

142
		xyz.z = 0;
143
		// if the distance is too big so do not display the entity
144
		if ((sqr(xyz.x - xyzRef.x)+sqr(xyz.y - xyzRef.y)) > maxSqrRadius) continue;
158
        // get entity pos
159
        CVectorD xyz = entity->pos();
145 160

146
		// Transform the dot
147
		xyz = mat * xyz;
161
        xyz.z = 0;
162
        // if the distance is too big so do not display the entity
163
        if ((sqr(xyz.x - xyzRef.x)+sqr(xyz.y - xyzRef.y)) > maxSqrRadius) continue;
148 164

149
		// Convert to screen
150
		sint32 x = OptFastFloor((float)xyz.x);
151
		sint32 y = OptFastFloor((float)xyz.y);
165
        // Transform the dot
166
        xyz = mat * xyz;
152 167

153
		CRGBA col = entity->getColor();
168
        // Convert to screen
169
        sint32 x = OptFastFloor((float)xyz.x);
170
        sint32 y = OptFastFloor((float)xyz.y);
154 171

155
		if(getModulateGlobalColor())
156
			col.modulateFromColor (col, pIM->getGlobalColorForContent());
157
		else
158
			col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8);
172
        CRGBA col = entity->getColor();
159 173

160
		// Select the icon to display and draw it
161
		uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId();
162
		CRadarSpotDesc spotDesc = _SpotDescriptions[spotId];
163
			
164
		if (!displayMissionSpots)
165
			spotDesc = _SpotDescriptions[0];
174
        if(getModulateGlobalColor())
175
            col.modulateFromColor (col, pIM->getGlobalColorForContent());
176
        else
177
            col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8);
166 178

167
		if (spotDesc.isMissionSpot)
168
			col = CRGBA(255, 255, 255, 255);
179
        // Select the icon to display and draw it
180
        uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId();
181
        CRadarSpotDesc spotDesc = _SpotDescriptions[spotId];
169 182

170
		if (entity->isTarget())
171
			spotId = 4; // to make it over other spots
183
        if (!_MissionIconsObs._displayMissionSpots)
184
            spotDesc = _SpotDescriptions[0];
172 185

173
		// Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range)
174
		if (spotDesc.isMissionSpot && displayMiniMissionSpots)
175
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2),
176
								spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col );
177
		else
178
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.TxW/2)+(_WReal/2), _YReal+y-(spotDesc.TxH/2)+(_HReal/2),
179
							spotDesc.TxW, spotDesc.TxH, 0, false, spotDesc.TextureId, col );
180
	}
186
        if (spotDesc.isMissionSpot)
187
            col = CRGBA(255, 255, 255, 255);
188

189
        if (entity->isTarget())
190
            spotId = 4; // to make it over other spots
191

192
        // Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range)
193
        if (spotDesc.isMissionSpot && _MiniMissionSpotsObs._displayMiniMissionSpots)
194
            rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2),
195
                                   spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col );
196
        else
197
            rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.TxW/2)+(_WReal/2), _YReal+y-(spotDesc.TxH/2)+(_HReal/2),
198
                                   spotDesc.TxW, spotDesc.TxH, 0, false, spotDesc.TextureId, col );
199
    }
181 200
}
182 201

183 202
// ----------------------------------------------------------------------------
184 203
void CViewRadar::updateCoords()
185 204
{
186
	CViewBase::updateCoords();
205
    CViewBase::updateCoords();
187 206
}
207

208
void CViewRadar::CDBMissionIconqObs::update(ICDBNode *node)
209
{
210
//    CInterfaceManager *pIM = CInterfaceManager::getInstance();
211
    _displayMissionSpots = ((CCDBNodeLeaf*)node)->getValueBool();
212
//    pIM->displaySystemInfo(ucstring("CDBMissionIconqObs: ") + toString(displayMissionSpots));
213
}
214

215
void CViewRadar::CDBMiniMissionSpotsObs::update(ICDBNode *node)
216
{
217
//    CInterfaceManager *pIM = CInterfaceManager::getInstance();
218
    _displayMiniMissionSpots = ((CCDBNodeLeaf*)node)->getValueBool();
219
//    pIM->displaySystemInfo(ucstring("CDBMiniMissionSpotsObs: ") + toString(displayMissionSpots));
220
}
b/code/ryzom/client/src/interface_v3/view_radar.h Sat Sep 29 13:53:02 2012 +0200
23 23
#include "nel/3d/u_texture.h"
24 24
#include "view_renderer.h"
25 25

26

27

28

26 29
/**
27 30
 * class implementing a radar view
28 31
 * \author Matthieu 'TrapII' Besson
......
45 48
	};
46 49

47 50
	/// Constructor
48
	CViewRadar(const TCtorParam &param) : CViewBase(param)
49
	{
50
	}
51
    CViewRadar(const TCtorParam &param);
51 52

52 53
	bool parse(xmlNodePtr cur,CInterfaceGroup * parentGroup);
53 54

......
64 65
	void setWorldSize(float f) { _WorldSize = f; }
65 66
	float getWorldSize() const { return (float)_WorldSize; }
66 67

68

69

67 70
protected:
68

69 71
	double _WorldSize;
70 72

71 73
	struct CRadarSpotDesc
......
79 81
		sint32 MTxH;
80 82
	};
81 83

82
	CRadarSpotDesc		_SpotDescriptions[NbRadarSpotIds];
84
private:
85
    CRadarSpotDesc		_SpotDescriptions[NbRadarSpotIds];
86

87
    class CDBMissionIconqObs : public ICDBNode::IPropertyObserver
88
    {
89
    public:
90
        virtual void update(ICDBNode *node);
91
        bool _displayMissionSpots;
92
    };
93
    CDBMissionIconqObs _MissionIconsObs;
94

95
    class CDBMiniMissionSpotsObs : public ICDBNode::IPropertyObserver
96
    {
97
    public:
98
        virtual void update(ICDBNode *node);
99
        bool _displayMiniMissionSpots;
100
    };
101
    CDBMiniMissionSpotsObs _MiniMissionSpotsObs;
102

83 103
};
84 104

85 105
#endif // RY_VIEW_RADAR_H