Skip to content

Commit

Permalink
Add support users spot-marks for map
Browse files Browse the repository at this point in the history
Partial #58
  • Loading branch information
ForserX committed Jul 30, 2024
1 parent 8f67349 commit f7ef54c
Show file tree
Hide file tree
Showing 13 changed files with 685 additions and 56 deletions.
22 changes: 22 additions & 0 deletions gamedata/configs/ui/pda_spot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<w>
<background x="353" y="226" width="600" height="300">
<auto_static x="-5" y="0" width="240" height="85" stretch="1">
<texture>ui_inGame2_message_box</texture>
</auto_static>
</background>

<spot_name_edit x="368" y="246" width="200" height="30">
<text x="5" font="letterica16" vert_align="c" align="l"/>
<texture>ui_inGame2_edit_box_2</texture>
</spot_name_edit>

<btn_apply x="395" y="279" width="70" height="28" check_mode="0">
<text font="letterica18">ui_inv_ok</text>
<texture>ui_inGame2_Mp_bigbuttone</texture>
</btn_apply>

<btn_cancel x="471" y="279" width="70" height="28" check_mode="0">
<text font="letterica18">ui_inv_cancel</text>
<texture>ui_inGame2_Mp_bigbuttone</texture>
</btn_cancel>
</w>
22 changes: 22 additions & 0 deletions gamedata/configs/ui/pda_spot_16.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<w>
<background x="260" y="226" width="600" height="300">
<auto_static x="-5" y="0" width="240" height="85" stretch="1">
<texture>ui_inGame2_message_box</texture>
</auto_static>
</background>

<spot_name_edit x="275" y="246" width="200" height="30">
<text x="5" font="letterica16" vert_align="c" align="l"/>
<texture>ui_inGame2_edit_box_2</texture>
</spot_name_edit>

<btn_apply x="302" y="279" width="70" height="28" check_mode="0">
<text font="letterica18">ui_inv_ok</text>
<texture>ui_inGame2_Mp_bigbuttone</texture>
</btn_apply>

<btn_cancel x="379" y="279" width="70" height="28" check_mode="0">
<text font="letterica18">ui_inv_cancel</text>
<texture>ui_inGame2_Mp_bigbuttone</texture>
</btn_cancel>
</w>
179 changes: 142 additions & 37 deletions src/xrGame/map_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "Inventory.h"
//#include "CustomMonster.h"

CMapLocation::CMapLocation(LPCSTR type, u16 object_id)
CMapLocation::CMapLocation(LPCSTR type, u16 object_id, bool is_user_loc)
{
m_flags.zero ();

Expand All @@ -49,9 +49,14 @@ CMapLocation::CMapLocation(LPCSTR type, u16 object_id)
m_mini_map_spot_border_na = nullptr;
m_complex_spot_border_na = nullptr;

if (is_user_loc)
{
m_flags.set(eUserDefined, TRUE);
}

m_objectID = object_id;
m_actual_time = 0;
m_owner_se_object = (ai().get_alife()) ? ai().alife().objects().object(m_objectID,true) : nullptr;
m_owner_se_object = (ai().get_alife() && !IsUserDefined()) ? ai().alife().objects().object(m_objectID, true) : nullptr;
m_flags.set (eHintEnabled, TRUE);
LoadSpot (type, false);

Expand Down Expand Up @@ -87,6 +92,41 @@ void CMapLocation::destroy()
delete_data(m_complex_spot_border_na);
}

void CMapLocation::InitUserSpot(const shared_str& level_name, const Fvector& pos)
{
m_cached.m_LevelName = level_name;
m_position_global = pos;
m_position_on_map.set(pos.x, pos.z);
m_cached.m_graphID = GameGraph::_GRAPH_ID(-1);
m_cached.m_Position.set(pos.x, pos.z);
m_cached.m_Direction.set(0.f, 0.f);

if (ai().get_alife())
{
const CGameGraph::SLevel& level = ai().game_graph().header().level(*level_name);
float min_dist = 128; // flt_max;

GameGraph::_GRAPH_ID n = ai().game_graph().header().vertex_count();

for (GameGraph::_GRAPH_ID i = 0; i < n; ++i)
{
if (ai().game_graph().vertex(i)->level_id() == level.id())
{
float distance = ai().game_graph().vertex(i)->game_point().distance_to_sqr(m_position_global);
if (distance < min_dist)
{
min_dist = distance;
m_cached.m_graphID = i;
}
}
}
if (!ai().game_graph().vertex(m_cached.m_graphID))
{
R_ASSERT(ai().game_graph().vertex(m_cached.m_graphID));
}
}
}

CUIXml* g_uiSpotXml=nullptr;
void CMapLocation::LoadSpot(LPCSTR type, bool bReload)
{
Expand Down Expand Up @@ -228,33 +268,47 @@ void CMapLocation::LoadSpot(LPCSTR type, bool bReload)
}
}

void CMapLocation::CalcPosition()
Fvector2 CMapLocation::CalcPosition()
{
if(m_flags.test( ePosToActor) && Level().CurrentEntity())
if (IsUserDefined())
return m_cached.m_Position;

Fvector2 pos;
pos.set(0.0f, 0.0f);

if (m_flags.test(ePosToActor) && Level().CurrentEntity())
{
m_position_global = Level().CurrentEntity()->Position();
m_cached.m_Position.set (m_position_global.x, m_position_global.z);
return;
m_position_global = Level().CurrentEntity()->Position();
pos.set(m_position_global.x, m_position_global.z);
m_cached.m_Position = pos;
return pos;
}

CObject* pObject = Level().Objects.net_Find(m_objectID);
if(!pObject)
CObject* pObject = Level().Objects.net_Find(m_objectID);
if (!pObject)
{
if(m_owner_se_object)
if (m_owner_se_object)
{
m_position_global = m_owner_se_object->draw_level_position();
m_cached.m_Position.set (m_position_global.x, m_position_global.z);
m_position_global = m_owner_se_object->draw_level_position();
pos.set(m_position_global.x, m_position_global.z);
}

}else

}
else
{
m_position_global = pObject->Position();
m_cached.m_Position.set (m_position_global.x, m_position_global.z);
m_position_global = pObject->Position();
pos.set(m_position_global.x, m_position_global.z);
}

m_cached.m_Position = pos;
return m_cached.m_Position;
}

const Fvector2& CMapLocation::CalcDirection()
{
if (IsUserDefined())
return m_cached.m_Direction;

if(Level().CurrentViewEntity()&&Level().CurrentViewEntity()->ID()==m_objectID )
{
m_cached.m_Direction.set(Device.vCameraDirection.x,Device.vCameraDirection.z);
Expand Down Expand Up @@ -284,6 +338,9 @@ const Fvector2& CMapLocation::CalcDirection()

void CMapLocation::CalcLevelName()
{
if (IsUserDefined())
return;

if(m_owner_se_object && ai().get_game_graph())
{
if(m_cached.m_graphID != m_owner_se_object->m_tGraphID)
Expand Down Expand Up @@ -321,8 +378,11 @@ bool CMapLocation::Update() //returns actual
CalcLevelName ();

CalcPosition ();
}else
m_cached.m_Actuality = false;
}
else if (IsUserDefined())
m_cached.m_Actuality = true;
else
m_cached.m_Actuality = false;

m_cached.m_updatedFrame = Device.dwFrame;
return m_cached.m_Actuality;
Expand All @@ -335,16 +395,18 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp )
{
if( map->MapName() == GetLevelName() )
{
bool b_alife = !!ai().get_alife();

if ( b_alife && m_flags.test(eHideInOffline) && !m_owner_se_object->m_bOnline )
if (!IsUserDefined())
{
return;
}
bool b_alife = !!ai().get_alife();
if (b_alife && m_flags.test(eHideInOffline) && !m_owner_se_object->m_bOnline)
{
return;
}

if (b_alife && m_owner_se_object->m_flags.test(CSE_ALifeObject::flVisibleForMap) == FALSE)
{
return;
if (b_alife && m_owner_se_object->m_flags.test(CSE_ALifeObject::flVisibleForMap) == FALSE)
{
return;
}
}

CGameTask* ml_task = Level().GameTaskManager().HasGameTask( this, true );
Expand Down Expand Up @@ -375,17 +437,20 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp )

Frect wnd_rect = sp->GetWndRect();

if ( map->IsRectVisible(wnd_rect) )
if (map->IsRectVisible(wnd_rect))
{
//update heading if needed
if( sp->Heading() && !sp->GetConstHeading() )
if (!IsUserDefined())
{
Fvector2 dir_global = CalcDirection();
float h = dir_global.getH();
float h_ = map->GetHeading()+h;
sp->SetHeading( h_ );
//update heading if needed
if (sp->Heading() && !sp->GetConstHeading())
{
Fvector2 dir_global = CalcDirection();
float h = dir_global.getH();
float h_ = map->GetHeading() + h;
sp->SetHeading(h_);
}
}
map->AttachChild (sp);
map->AttachChild(sp);
}

CMapSpot* s = GetSpotBorder(sp);
Expand All @@ -410,7 +475,10 @@ void CMapLocation::UpdateSpot(CUICustomMap* map, CMapSpot* sp )
{
GameGraph::_GRAPH_ID dest_graph_id;

dest_graph_id = m_owner_se_object->m_tGraphID;
if (!IsUserDefined())
dest_graph_id = m_owner_se_object->m_tGraphID;
else
dest_graph_id = m_cached.m_graphID;

map_point_path.clear();

Expand Down Expand Up @@ -574,6 +642,13 @@ void CMapLocation::save(IWriter &stream)
stream.w_stringZ(m_hint);
stream.w_u32 (m_flags.flags);
stream.w_stringZ(m_owner_task_id);

if (IsUserDefined())
{
save_data(m_cached.m_LevelName, stream);
save_data(m_cached.m_Position, stream);
save_data(m_cached.m_graphID, stream);
}
}

void CMapLocation::load(IReader &stream)
Expand All @@ -585,6 +660,16 @@ void CMapLocation::load(IReader &stream)

stream.r_stringZ(str);
m_owner_task_id = str.c_str();

if (IsUserDefined())
{
load_data(m_cached.m_LevelName, stream);
load_data(m_cached.m_Position, stream);
load_data(m_cached.m_graphID, stream);

m_position_on_map = m_cached.m_Position;
m_position_global.set(m_position_on_map.x, 0.f, m_position_on_map.y);
}
}

void CMapLocation::SetHint(const shared_str& hint)
Expand All @@ -596,7 +681,12 @@ void CMapLocation::SetHint(const shared_str& hint)
return;
}
m_hint = hint;
};
}

Fvector2 CMapLocation::SpotSize()
{
return m_level_spot->GetWndSize();
}

LPCSTR CMapLocation::GetHint()
{
Expand Down Expand Up @@ -855,4 +945,19 @@ void CRelationMapLocation::Dump ()
inherited::Dump();
Msg("--CRelationMapLocation m_curr_spot_name=[%s]",*m_curr_spot_name);
}
#endif
#endif

void CMapLocation::HighlightSpot(bool state, const Fcolor& color)
{
CUIStatic* st = smart_cast<CUIStatic*>(m_level_spot);
if (state)
{
u32 clr = color_rgba((u32)color.r, (u32)color.g, (u32)color.b, (u32)color.a);
st->SetTextureColor(clr);
}
else
{
if (st->GetTextureColor() != 0xffffffff)
st->SetTextureColor(0xffffffff);
}
}
13 changes: 11 additions & 2 deletions src/xrGame/map_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ enum ELocationFlags
eSpotEnabled = (1<<5),
eCollidable = (1<<6),
eHintEnabled = (1<<7),
eUserDefined = (1 << 8),
};

protected:
LPCSTR m_type;
flags32 m_flags;
shared_str m_hint;
CMapSpot* m_level_spot;
Expand Down Expand Up @@ -71,10 +73,17 @@ protected :
CMapSpotPointer* GetSpotPointer (CMapSpot* sp);
CMapSpot* GetSpotBorder (CMapSpot* sp);
public:
CMapLocation (LPCSTR type, u16 object_id);
CMapLocation (LPCSTR type, u16 object_id, bool is_user_loc = false);
virtual ~CMapLocation ();
virtual void destroy ();

IC LPCSTR GetType () const { return m_type; };
Fvector2 SpotSize ();
IC bool IsUserDefined () const { return !!m_flags.test(eUserDefined); }
IC void SetUserDefinedFlag (BOOL state) { m_flags.set(eUserDefined, state); }
void InitUserSpot (const shared_str& level_name, const Fvector& pos);
void HighlightSpot (bool state, const Fcolor& color);

IC bool HintEnabled () {return !!m_flags.test(eHintEnabled);}
LPCSTR GetHint ();
void SetHint (const shared_str& hint);
Expand All @@ -93,7 +102,7 @@ protected :
virtual void UpdateMiniMap (CUICustomMap* map);
virtual void UpdateLevelMap (CUICustomMap* map);

void CalcPosition ();
Fvector2 CalcPosition ();
const Fvector2& CalcDirection ();
IC const shared_str& GetLevelName () {return m_cached.m_LevelName;}
const Fvector2& GetPosition () {return m_cached.m_Position;}
Expand Down
Loading

0 comments on commit f7ef54c

Please sign in to comment.