[CODE] Friend List

#1
agregas a Game.h:

Code: Select all

void LoadFriendList();//drajwer -friendlist
void SaveFriendList();//drajewr -friendlist 
void DrawDialogBox_FriendList(short msX, short msY);//43
void DlgBoxClick_FriendList(short msX, short msY); // 43 - drajwer



char m_cFriends[13][10];
int m_iTotalFriends;
int m_iFriendIndex;
int m_iFriendIndex2; //dunno about that but its work :)
y al Game.cpp:

Code: Select all

void CGame::DrawDialogBox_FriendList(short msX, short msY)//43
{
 short sX, sY, szX,szY;
 int j;
 char cTxt[120];
 char cNicks[13];

	sX = m_stDialogBoxInfo[43].sX;
	sY = m_stDialogBoxInfo[43].sY;
	szX = m_stDialogBoxInfo[43].sSizeX; 
	szY = m_stDialogBoxInfo[43].sSizeY;

	DrawNewDialogBox(DEF_SPRID_INTERFACE_ND_GAME2, sX, sY, 2);
	PutString_SprFont(sX+90, sY+35, "Friends List", 1,1,8);

	switch (m_stDialogBoxInfo[43].cMode) {
	case 0:
		for (int i = 0; i < m_iTotalFriends; i++) {
			if (m_cFriends[i] != NULL) {
				PutString(sX+25, ( sY+45+((i+1)*16) ), m_cFriends[i], RGB(0,0,0));
			}
		}  

		PutString_SprFont(sX+25, sY+45+(14*16), "Add", 1,1,8);

		if (m_iFriendIndex != -1) {
			PutString(sX+25, sY+45+(m_iFriendIndex*16), m_cFriends[m_iFriendIndex-1], RGB(255,255,255));
			m_stDialogBoxInfo[43].sV1 = m_iFriendIndex-1;
			wsprintf(cTxt, "Friend's name: %s", m_cFriends[m_iFriendIndex-1]);
			m_iFriendIndex2 = m_iFriendIndex-1;
			PutString(sX+25, sY+45+(13*16), cTxt, RGB(0,0,0));
			
			PutString_SprFont(sX+80, sY+45+(14*16), "Delete", 1,1,8);
			
			PutString_SprFont(sX+140, sY+45+(14*16), "Whisper", 1,1,8);
			
		}
		break;
	}
}
void CGame::DlgBoxClick_FriendList(short msX, short msY) // 43 - drajwer
{
 short sX, sY, szX,szY; 
 int tmp,i;
 char cTxt[100];

	sX = m_stDialogBoxInfo[43].sX;
	sY = m_stDialogBoxInfo[43].sY;
	szX = m_stDialogBoxInfo[43].sSizeX; 
	szY = m_stDialogBoxInfo[43].sSizeY;

	if ((msX > sX+25) && (msX < sX+szX-25) && (msY > sY+45+16) && (msY < sY+45+(13)*16)) {
		tmp = (msY-sY-45-16)/16;
		tmp++;
		if (strcmp(m_cFriends[tmp-1], " ") != 0) { //izzit not empty?
			m_iFriendIndex = tmp;
		}
		else {
			m_iFriendIndex = -1;
		}
		return;
	}
	if ((msX > sX+25) && (msX < sX+25+25) && (msY > sY+45+14*16) && (msY < sY+45+15*16)) {
		if (m_iTotalFriends == 12) {
			AddEventList("You can't have more than 12 friends.", 10);
			return;
		}
		m_bIsGetPointingMode = TRUE;
		m_iPointCommandType  = 250;
		PlaySound('E', 14, 5);
		AddEventList("Click the character which you want to add.", 10); //pointing mode 
		return;
	}
	if ((msX > sX+80) && (msX < sX+80+30) && (msY > sY+45+14*16) && (msY < sY+45+15*16)) {  
		for (i = m_iFriendIndex2+1; i < 13; i++) { //simple delete
			ZeroMemory(cTxt, sizeof(cTxt)); //just move down elements
			memcpy(cTxt, m_cFriends[i], 10);
			ZeroMemory(m_cFriends[i-1], sizeof(m_cFriends[i-1]));
			memcpy(m_cFriends[i-1], cTxt, 10);
		}
		m_iTotalFriends--;
		SaveFriendList();
	}

	if ((msX > sX+140) && (msX < sX+140+45) && (msY > sY+45+14*16) && (msY < sY+45+15*16)) {
		ZeroMemory(cTxt, sizeof(cTxt));
		wsprintf(cTxt, "/to %s", m_cFriends[m_iFriendIndex2]);
		bSendCommand(MSGID_COMMAND_CHATMSG, NULL, NULL, NULL, NULL, NULL, cTxt);
	}
}
void CGame::SaveFriendList()
{
char	cTxt[40];
 wsprintf(cTxt, "contents\\%s\\FriendList.txt", m_cPlayerName);
 FILE* f = fopen(cTxt, "w");
 char wr[16];

	if (f == NULL) return;
	for (int i = 0; i < m_iTotalFriends; i++) {
		ZeroMemory(wr, sizeof(wr));
		wsprintf(wr, "%s\n", m_cFriends[i]);
		fputs(wr, f);
	}
	fclose(f);
}
OnKeyUp agrega:

Code: Select all

	case 70: //'F'
		if (m_bCtrlPressed && m_cGameMode == DEF_GAMEMODE_ONMAINGAME && (!m_bInputStatus) )
		{	if (m_bIsDialogEnabled[43] == FALSE)
			{	EnableDialogBox(43, NULL, NULL, NULL);
				char buf[1024]; int konieclinii; unsigned long linie = 0;
				char	cTxt[40];
				wsprintf(cTxt, "contents\\%s\\FriendList.txt", m_cPlayerName);
				FILE * f = fopen(cTxt, "rt");
				if (f == NULL) break; // Centuu: si el archivo no existe, crash
				else
				{
					m_iTotalFriends = 0;
					while(fgets(buf, 1024, f)) {
						konieclinii = 0;
						int i = strlen(buf);
						if (i > 0 && buf[--i] == '\n') {
							buf[i] = 0; // kasujemy znak konca linii
							konieclinii = 1;
							linie++;
						}
						if (linie-1 < 13) {
							strcpy(m_cFriends[linie-1], buf);
							m_iTotalFriends++;
						}
					}
					if (m_iTotalFriends > 12) m_iTotalFriends = 12;
					fclose(f);
				}
			}else DisableDialogBox(43);
		} 
		break;
Despues:

_bCheckDlgBoxClick agregar:

Code: Select all

case 43:
   DlgBoxClick_FriendList(msX, msY);
   break;
  
DrawDialogBoxs agregar:

Code: Select all

case 43:
  DrawDialogBox_FriendList(msX,msY); //drajwer: friendlist
  break;
EnableDialogBox agregar:

Code: Select all

case 43:
 m_iFriendIndex = -1;

 break
_iCheckDlgBoxFocus agregar:

Code: Select all

case 43: // Drajwer - friendlist s
    m_stMCursor.cSelectedObjectType = DEF_SELECTEDOBJTYPE_DLGBOX;
    m_stMCursor.sSelectedObjectID   = cDlgID;
    break;
PointCommandHandler agregar

Code: Select all

else if (m_iPointCommandType == 250) 
{ if ((strlen(m_cMCName) == 0) || (strcmp(m_cMCName, m_cPlayerName) == 0) || (m_cMCName[0] == '_')) {
  AddEventList("Only players can be added.", 10);
  PlaySound('E', 14, 5);
 }else 
 {
  PlaySound('E', 14, 5);
  memcpy(m_cFriends[m_iTotalFriends],m_cMCName,10);
  m_iTotalFriends++;
  m_stDialogBoxInfo[43].sV1=0;
  SaveFriendList();
  return;
} }
Centuu.-

Sol Lucet Omnibus.-

Who is online

Users browsing this forum: No registered users and 1 guest