Files
2026-06-01 12:46:52 +02:00

544 lines
14 KiB
C++

/// 2010.11.17 - prodongi
#include "stdafx.h"
#include <time.h>
#include "SUIWorldDetailMapWnd.h"
#include "SUIWorldMapWnd.h"
//#include "Util.h"
//#include "SGameMessageUI.h"
#include "SGameMessage.h"
#include "SPlayerInfoMgr.h"
#include "KUIControlStatic.h"
#include "SGameCamera.h"
//#include "SUIUtil.h" /// 2011.03.18 - prodongi
#include "SFieldPropResourceDB.h" /// 2011.07.21 - prodongi
#include "SGameSystem.h"
extern SGameSystem* g_pCurrentGameSystem;
/*
*/
SUIWorldDetailMapWnd::SUIWorldDetailMapWnd(SGameManager* pGameManager) : SUIWnd(pGameManager)
{
m_rtWorldWnd = NULL;
m_playerWnd = NULL;
m_isClosed = false;
m_playerRadian = 0.0f;
m_bPointSign = FALSE;
m_dwPlayerPointTime = 0;
}
/*
*/
SUIWorldDetailMapWnd::~SUIWorldDetailMapWnd()
{
m_npcList.clear();
}
/*
*/
bool SUIWorldDetailMapWnd::InitData( bool bReload )
{
if (!SUIWnd::InitData(bReload))
return false;
m_rtWorldWnd = GetChild("static_temp");
m_playerWnd = GetChild("worldmap_player");
/// 2011.03.16 test - prodongi
m_oriWorldRect = m_rtWorldWnd->GetRect();
return true;
}
/*
*/
void SUIWorldDetailMapWnd::createNpc(vecNpcInfo const& npcList)
{
if (!m_rtWorldWnd)
return ;
std::string iconName;
KPoint uiBasisPos(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
vecNpcInfo::const_iterator it = npcList.begin();
for (; it != npcList.end(); ++it)
{
if (m_worldRect.IsInRect(it->x, it->y))
{
getNpcIconAniName(iconName, it->type, 0); /// 2011.03.18 - prodongi
KUIWnd* wnd = m_pManager->CreateControl( KUIWND_CREATE_ARG( "iconstatic", it->strName.c_str(), " ", KRect(-1,-1,-1, -1), 0, 0, this, iconName.c_str(), "ui_frame.spr", m_pManager, 0, "", KANCHOR_LEFT | KANCHOR_TOP ) );
if( wnd )
{
wnd->SetShow(true);
std::string tooltip;
if( g_pCurrentGameSystem->GetLocalPlayerPermission() > 0 )
{
XStringUtil::Format( tooltip, "%s(%d,%d)", it->strName.c_str(), it->x, it->y );
}
else
{
tooltip = it->strName;
}
(( KUIControlIconStatic*)wnd)->SetTooltip( tooltip.c_str() );
setWorldToUiPos(KPoint(it->x, it->y), uiBasisPos, wnd);
SNpcResourceDB::NPCRenderInfo npc = *it;
npc.wnd = wnd;
m_npcList.push_back(npc);
}
}
}
SetChildAsTop("worldmap_player");
}
/// 2011.07.21 - prodongi
void SUIWorldDetailMapWnd::createDungeonGate(vecDungeonGateInfo const& dungeonGateList)
{
if (!m_rtWorldWnd)
return ;
std::string iconName;
KPoint uiBasisPos(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
vecDungeonGateInfo::const_iterator it = dungeonGateList.begin();
for (; it != dungeonGateList.end(); ++it)
{
if (m_worldRect.IsInRect(it->m_x, it->m_y))
{
FieldPropResource* prop = GetFieldPropResourceDB().GetFieldPropResource(it->m_id);
if (prop)
{
char const* name = S(prop->text_id);
getDungeonGateIconAniName(iconName, 1);//it->m_type);
KUIWnd* wnd = m_pManager->CreateControl( KUIWND_CREATE_ARG( "iconstatic", name, " ", KRect(-1,-1,-1, -1), 0, 0, this, iconName.c_str(), "ui_frame.spr", m_pManager, 0, "", KANCHOR_LEFT | KANCHOR_TOP ) );
if( wnd )
{
wnd->SetShow(true);
std::string tooltip;
if( g_pCurrentGameSystem->GetLocalPlayerPermission() > 0 )
{
XStringUtil::Format( tooltip, "%s(%d,%d)", name, it->m_x, it->m_y );
}
else
{
tooltip = name;
}
(( KUIControlIconStatic*)wnd)->SetTooltip(tooltip.c_str());
setWorldToUiPos(KPoint(it->m_x, it->m_y), uiBasisPos, wnd);
}
}
}
}
}
/* /// 2011.03.15 test 코드, 혹시 몰르니 남겨둔다 - prodongi
*/
/*
void SUIWorldDetailMapWnd::refreshNpcPos(KRect const& offset)
{
KRect r = m_rtWorldWnd->GetRect();
r.left += offset.left;
r.right += offset.right;
r.top += offset.top;
r.bottom += offset.bottom;
m_rtWorldWnd->SetRect(r);
_oprint("%d, %d, %d, %d / ", r.left, r.top, r.right, r.bottom);
_oprint("%d, %d, %d, %d\n", r.left - m_oriWorldRect.left, r.top - m_oriWorldRect.top,
r.right - m_oriWorldRect.right, r.bottom - m_oriWorldRect.bottom);
KPoint uiBasisPos(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
vecNpcInfo::iterator it = m_npcList.begin();
for (; it != m_npcList.end(); ++it)
{
setWorldToUiPos(KPoint(it->x, it->y), uiBasisPos, it->wnd);
}
}
*/
/*
*/
void SUIWorldDetailMapWnd::Process(DWORD dwTime, DWORD elapsedtime)
{
if (!IsShow())
return ;
KUIWnd::Process(dwTime);
procNpcPeriodic();
if (m_updateAlpha.m_active)
{
float e_t = (float)elapsedtime/1000.0f;
if (!m_updateAlpha.update(e_t * 2.0f))
{
if (true == m_updateAlpha.m_toggleDir)
m_isClosed = true;
}
ChangeAlpha(m_updateAlpha.m_elapsedTime);
}
if ( dwTime-m_dwPlayerPointTime > WORLDSIGNTIME )
{
m_playerWnd->SetShow(m_bPointSign);
m_bPointSign = !m_bPointSign;
m_dwPlayerPointTime = dwTime;
}
}
/*
*/
void SUIWorldDetailMapWnd::PumpUpMessage(LPCSTR lpszControlID, DWORD nMessage, DWORD lparam, DWORD wparam)
{
switch(nMessage)
{
case KUI_MESSAGE::KBUTTON_CLICK:
{
buttonClick(lpszControlID, lparam, wparam);
}
break;
case KUI_MESSAGE::KFOCUS_ACTIVATED:
#ifdef _DEV
MoveWorld(KPoint(lparam,wparam));
#else
if( GameRule::GetCurrentLocalBitSet() == GameRule::LOCAL_BITSET::KR &&
g_pCurrentGameSystem->GetLocalPlayerPermission() > 0 )
MoveWorld(KPoint(lparam,wparam));
#endif
break;
case KUI_MESSAGE::KGENWND_RIGHT_CLICK:
{
buttonClick("button_home_01", 0, 0);
}
break;
}
SUIWnd::PumpUpMessage( lpszControlID, nMessage, lparam, wparam );
}
/*
*/
void SUIWorldDetailMapWnd::ProcMsgAtStatic(SGameMessage* pMsg)
{
switch(pMsg->nType)
{
case IMSG_UI_2DPOS_INFO:
{
SIMSG_UI_2DPOS_INFO* p2DPosMsg = (SIMSG_UI_2DPOS_INFO*)pMsg;
switch( p2DPosMsg->nObjType )
{
case SIMSG_UI_2DPOS_INFO::TY_MY:
{
if( !m_PlayerInfoMgr.IsLocalPlayer(p2DPosMsg->handle) ) break;
setPlayerWorldPos( p2DPosMsg->nReal_X, p2DPosMsg->nReal_Y );
if( p2DPosMsg->fRadian )
{
if( m_playerRadian != p2DPosMsg->fRadian )
{
m_playerRadian = p2DPosMsg->fRadian;
/// 2011.03.14 - prodongi
//((KUIControlStatic*)m_playerWnd)->SetRotate( (SGameCamera::PI/2) - m_playerRadian );
setPlayerRotation(p2DPosMsg->fRadian);
}
}
}
break;
case SIMSG_UI_2DPOS_INFO::TY_PLAYER:
{
//if( m_PartyMgr.IsExistMember(p2DPosMsg->handle) )
// refreshPartyPlayerPos();
}
break;
}
pMsg->bUse = true;
}
break;
/* /// 2011.03.14 카메라 방향은 설정 안 하기로 한다 - prodongi
case IMSG_UI_MY_DEGREE:
{
if (IsShow() && m_playerWnd)
{
SIMSG_UI_MY_DEGREE* pRotateMsg = (SIMSG_UI_MY_DEGREE*)pMsg;
/// 2011.03.14 - prodongi
//((KUIControlStatic*)m_playerWnd)->SetRotate( (SGameCamera::PI/2) - pRotateMsg->fRadian );
setPlayerRotation(pRotateMsg->fRadian);
pMsg->bUse = true;
}
}
break;
*/
}
}
/*
*/
void SUIWorldDetailMapWnd::buttonClick(LPCSTR lpszControlID, DWORD lparam, DWORD wparam)
{
SUIWorldMapWnd* parentWnd = dynamicCast<SUIWorldMapWnd*>(GetParent());
if( ::_stricmp( lpszControlID, "button_home_01" ) == 0 )
{
parentWnd->readyCloseDetailMap();
}
else if (::_stricmp( lpszControlID, "button_map_move_to_01" ) == 0)
{
SetChildShow(lpszControlID, false); /// 맵이 이동될 때 up 버튼 이미지가 보기 안좋아서 안보이게 설정함 - prodongi
parentWnd->readyOpenTownDetailMap(0);
}
else if (::_stricmp( lpszControlID, "button_map_move_to_02" ) == 0)
{
SetChildShow(lpszControlID, false);
parentWnd->readyOpenTownDetailMap(1);
}
else if (::_stricmp( lpszControlID, "button_map_move_to_03" ) == 0)
{
SetChildShow(lpszControlID, false);
parentWnd->readyOpenTownDetailMap(2);
}
else if (::_stricmp( lpszControlID, "button_map_move_to_04" ) == 0)
{
SetChildShow(lpszControlID, false);
parentWnd->readyOpenTownDetailMap(3);
}
/// 2011.06.02 - prodongi
else if (::_stricmp(lpszControlID, "button_zoom_in_village_01") == 0)
{
parentWnd->readyOpenVillageDetailMap(0);
}
else if (::_stricmp(lpszControlID, "button_zoom_in_village_03") == 0)
{
parentWnd->readyOpenVillageDetailMap(2);
}
else if (::_stricmp(lpszControlID, "button_zoom_in_village_04") == 0)
{
parentWnd->readyOpenVillageDetailMap(3);
}
else if (::_stricmp(lpszControlID, "button_zoom_in_village_05") == 0)
{
parentWnd->readyOpenVillageDetailMap(4);
}
else if (::_stricmp(lpszControlID, "button_zoom_in_village_06") == 0)
{
parentWnd->readyOpenVillageDetailMap(5);
}
else if (::_stricmp( lpszControlID, "button_zoom_in_rondo_village_01" ) == 0)
{
parentWnd->readyOpenTownDetailMap(0);
}
else if (::_stricmp( lpszControlID, "button_zoom_in_rondo_village_02" ) == 0)
{
parentWnd->readyOpenTownDetailMap(1);
}
else if (::_stricmp( lpszControlID, "button_zoom_in_rondo_village_03" ) == 0)
{
parentWnd->readyOpenTownDetailMap(2);
}
else if (::_stricmp( lpszControlID, "button_zoom_in_rondo_village_04" ) == 0)
{
parentWnd->readyOpenTownDetailMap(3);
}
else if( ::_stricmp( lpszControlID, "button_zoom_out" ) == 0 )
{
int fieldIndex = calcFieldIndex();
if (0 <= fieldIndex)
parentWnd->readyOpenFieldDetailMap(fieldIndex);
}
}
/*
*/
void SUIWorldDetailMapWnd::setPlayerWorldPos(int worldX, int worldY)
{
m_playerWorldPos.x = worldX;
m_playerWorldPos.y = worldY;
refreshPlayerPos();
}
/*
*/
void SUIWorldDetailMapWnd::refreshPlayerPos()
{
KPoint uiBasisPos(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
setWorldToUiPos(m_playerWorldPos, uiBasisPos, m_playerWnd);
checkVisibleIsInRegionPlayer(); /// 2011.03.14 - prodongi
}
/*
*/
void SUIWorldDetailMapWnd::setWorldToUiPos(KPoint const& worldPos, KPoint const& uiBasisPos, KUIWnd* wnd)
{
if (!m_rtWorldWnd)
return ;
if (!wnd)
return ;
/// 상대 좌표
KPoint relativeWorldPos;
relativeWorldPos.x = worldPos.x - m_worldRect.left;
relativeWorldPos.y = worldPos.y - m_worldRect.top;
KPoint uiPos;
SUIWorldMapWnd::convertWorldToUiPos(relativeWorldPos, uiPos, m_rtWorldWnd->GetRect(), KPoint(m_worldRect.GetWidth(), m_worldRect.GetHeight()), 0, 0);
if(m_playerWnd)
{
wnd->MovePos(uiBasisPos.x + uiPos.x - (wnd->GetRect().GetWidth()/2),
uiBasisPos.y + uiPos.y - (wnd->GetRect().GetHeight()/2));
}
}
/*
*/
void SUIWorldDetailMapWnd::procNpcPeriodic()
{
vecNpcInfo::iterator it = m_npcList.begin();
for (; it != m_npcList.end(); ++it)
{
if ((*it).is_periodic)
{
time_t nowtime;
time(&nowtime);
if((*it).begin_of_period > nowtime || (*it).end_of_period < nowtime)
it->wnd->SetShow(false);
else
it->wnd->SetShow(true);
}
}
}
/*
*/
void SUIWorldDetailMapWnd::beginAlpha()
{
m_updateAlpha.m_toggle = true;
m_updateAlpha.m_toggleDir = true;
m_updateAlpha.begin(1.0f, false);
ChangeAlpha(m_updateAlpha.m_elapsedTime);
}
/*
*/
void SUIWorldDetailMapWnd::endAlpha()
{
m_updateAlpha.m_toggle = true;
m_updateAlpha.m_toggleDir = false;
m_updateAlpha.begin(1.0f, false);
m_updateAlpha.m_elapsedTime = GetAlpha();
}
/* /// 2011.03.14 - prodongi
*/
void SUIWorldDetailMapWnd::checkVisibleIsInRegionPlayer()
{
SUIWorldMapWnd* parentWnd = dynamicCast<SUIWorldMapWnd*>(GetParent());
bool isIn = parentWnd->checkVisibleIsInRegionPlayer(m_playerWnd->GetRect());
m_playerWnd->SetShow(isIn);
}
/* /// 2011.03.14 - prodongi
*/
void SUIWorldDetailMapWnd::setPlayerRotation(float radian)
{
float offset = SGameCamera::PI/4.0f;
((KUIControlStatic*)m_playerWnd)->SetRotate( (SGameCamera::PI/2) - radian + offset );
}
/// 2011.06.02 - prodongi
int SUIWorldDetailMapWnd::calcFieldIndex()
{
if (FIELD == m_type)
{
return -1;
}
else if (VILLAGE == m_type)
{
switch (m_index)
{
case 0: return 0;
case 2: return 11;
case 3: return 13;
case 4: return 15;
case 5: return 1;
}
}
else if (TOWN == m_type)
{
return 7;
}
return -1;
}
/// 2011.08.30 - prodongi
void SUIWorldDetailMapWnd::convertWorldToUiPos(KPoint const& worldPos, KPoint& uiPos)
{
KPoint uiBasisPos(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
KPoint relativeWorldPos;
relativeWorldPos.x = worldPos.x - m_worldRect.left;
relativeWorldPos.y = worldPos.y - m_worldRect.top;
SUIWorldMapWnd::convertWorldToUiPos(relativeWorldPos, uiPos, m_rtWorldWnd->GetRect(), KPoint(m_worldRect.GetWidth(), m_worldRect.GetHeight()), 0, 0);
uiPos.x += uiBasisPos.x;
uiPos.y += uiBasisPos.y;
}
void SUIWorldDetailMapWnd::changeNpcIconToFinish(const std::vector<int> &changeList)
{
size_t changeSize = changeList.size();
for (size_t c_i = 0; c_i < changeSize; ++c_i)
{
int changeId = changeList[c_i];
if (0 == changeId)
continue;
size_t npcSize = m_npcList.size();
for (size_t n_i = 0; n_i < npcSize; ++n_i)
{
if (m_npcList[n_i].nID.value() == changeId)
{
m_npcList[n_i].wnd->SetBack("ui_frame.spr", "common_mark_minimap_npc_quest03");
}
}
}
}
void SUIWorldDetailMapWnd::restoreNpcIconToOriginal(const std::vector<int> &restoreList)
{
std::string iconName;
size_t restoreSize = restoreList.size();
for (size_t c_i = 0; c_i < restoreSize; ++c_i)
{
int changeId = restoreList[c_i];
if (0 == changeId)
continue;
size_t npcSize = m_npcList.size();
for (size_t n_i = 0; n_i < npcSize; ++n_i)
{
if (m_npcList[n_i].nID.value() == changeId)
{
getNpcIconAniName(iconName, m_npcList[n_i].type, 0); /// 2011.03.18 - prodongi
m_npcList[n_i].wnd->SetBack("ui_frame.spr", iconName.c_str());
}
}
}
}
void SUIWorldDetailMapWnd::MoveWorld(KPoint uiPos)
{
if( !HIBYTE(GetAsyncKeyState(VK_CONTROL)) )
return;
if (!m_rtWorldWnd)
return ;
/// 상대 좌표
KPoint relativeWorldPos;
KPoint offset(m_rtWorldWnd->GetRect().left, m_rtWorldWnd->GetRect().top);
uiPos.x -= offset.x;
uiPos.y -= offset.y;
SUIWorldMapWnd::convertUiToWorldPos(uiPos, relativeWorldPos, m_rtWorldWnd->GetRect(), KPoint(m_worldRect.GetWidth(), m_worldRect.GetHeight()), 0, 0);
relativeWorldPos.x = relativeWorldPos.x + m_worldRect.left;
relativeWorldPos.y = relativeWorldPos.y + m_worldRect.top;
g_pCurrentGameSystem->OnMsgMoveMap ( relativeWorldPos.x, relativeWorldPos.y );
SDEBUGLOG( "[Detail map click pos ui= %d,%d world= %d,%d]", uiPos.x, uiPos.y, relativeWorldPos.x, relativeWorldPos.y);
}