- Joined
- Dec 16, 2010
- Messages
- 233
- Reaction score
- 75
Hi there,
I've been requested to create the same function that is in Map ("M"), that moves character after click to clicked location on map to SmallMiniMap
Time spend: 14 hours
If you find any bugs, let me know I'll fix it ASAP.
SmallMiniMapWindow.cpp
SmallMiniMapWindow.h
Dont miss the "Like" button
Credits:
CodeSkilLs
I've been requested to create the same function that is in Map ("M"), that moves character after click to clicked location on map to SmallMiniMap
Time spend: 14 hours
If you find any bugs, let me know I'll fix it ASAP.
SmallMiniMapWindow.cpp
Code:
void cSmallMiniMapWindow::OnLButtonDown(const cUIPos& pos, bool ctrl, bool alt, bool)
{
unsigned long state = HERO->GetState();
cHero* hero = OBJECTMANAGER->GetHero();
switch (state)
{
case eOBJECT_STATE_IDLE:
case eOBJECT_STATE_MOVE:
case ePLAYER_STATE_GATHERING:
case ePLAYER_STATE_ITEMPICK:
case ePLAYER_STATE_SITDOWN:
break;
case eOBJECT_STATE_STOP:
{
unsigned int stopflag = HERO->GetStopFlag();
if (!(stopflag == eSTOP_ENHANCED || stopflag == eSTOP_ITEMMIX || stopflag == eSTOP_NPCSPEECH))
return;
}
break;
default:
return;
}
if (HERO->IsKeyMoving() == true)
return;
cNaviMesh* navi = WORLDMAN->GetNaviMesh();
cNaviField* field = WORLDMAN->GetNaviField();
if (!navi || !field)
return;
// Init Mouse Click on screen and in window
int mouseX = pos.mX;
int mouseY = pos.mY;
int mouseXWindow = pos.mX - GetAbsoluteRect().mLeft;
int mouseYWindow = pos.mY - GetAbsoluteRect().mTop;
float segLen = navi->GetSegmentLength();
int heroX = (int)(hero->GetXPos() / segLen * MAPTEX_W);
int heroY = (int)(MAPTEX_H - (hero->GetYPos() / segLen * MAPTEX_H));
/// Init Texture position with zoon and hero
double texX = heroX - mPerTexW * 0.5f;
double texY = heroY - mPerTexH * 0.5f;
double texRight = heroX + mPerTexW * 0.5f;
double texBottom = heroY + mPerTexH * 0.5f;
/// Texture corners (tl - Texture Left, etc...)
short tl = (short)(texX + 0.5f);
short tt = (short)(texY + 0.5f);
unsigned short tr = (unsigned short)(texRight + 0.5f);
unsigned short tb = (unsigned short)(texBottom + 0.5f);
/// Init Fix
int fixX = 0;
int fixY = 0;
if (tl < 0)
{
fixX = tl;
tl = 0;
tr = (short)mPerTexW;
}
else if (tr > MAPTEX_W)
{
fixX = tr - MAPTEX_W;
tl = (short)(MAPTEX_W - mPerTexW);
tr = MAPTEX_W;
}
if (tt < 0)
{
fixY = tt;
tt = 0;
tb = (short)mPerTexH;
}
else if (tb > MAPTEX_H)
{
fixY = tb - MAPTEX_H;
tt = (short)(MAPTEX_H - mPerTexH);
tb = MAPTEX_H;
}
/// Fix of texture
fixX = (int)((float)fixX / mPerTexW * MAP_W);
fixY = (int)((float)fixY / mPerTexH * MAP_H);
double xr = MAP_W * 0.5f + fixX + MAP_X;
double yr = MAP_H * 0.5f + fixY + MAP_Y;
// Get Hero position in Map Window
short heroScreenX = (short)xr - (short)(mHeroSize.mWidth * 0.5f);
short heroScreenY = (short)yr - (short)(mHeroSize.mHeight * 0.5f);
// Calculate Ratior (Zoom In/Out)
float fRatio = (float)((float)(((float)MAPTEX_W / (float)MAP_W)) * mPercent * 0.01);
// Calculate real X on Map
int nDeltaXWindow = heroScreenX - mouseXWindow;
int nDeltaXMap = (int)((float)nDeltaXWindow * fRatio);
int nMapX = heroX - nDeltaXMap;
// Calculate real Y on Map
int nDeltaYWindow = heroScreenY - mouseYWindow;
int nDeltaYMap = (int)((float)nDeltaYWindow * fRatio);
int nMapY = MAPTEX_W - heroY + nDeltaYMap;
// Fix Map ZOOM
mPercent -= ADD_PERCENT;
mPerTexW = MAPTEX_W * mPercent * 0.01;
mPerTexH = MAPTEX_H * mPercent * 0.01;
mPercent += ADD_PERCENT;
mPerTexW = MAPTEX_W * mPercent * 0.01;
mPerTexH = MAPTEX_H * mPercent * 0.01;
mNeedUpdate = true;
HERO->ActivePosition(((float)nMapX * 100.0f), ((float)nMapY* 100.0f));
}
SmallMiniMapWindow.h
Code:
// Add this after OnMouseLeft
void OnLButtonDown(const cUIPos& pos, bool ctrl, bool alt, bool);
Dont miss the "Like" button

Credits:
CodeSkilLs