⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		}
		tree->Refresh();
	}
}

void LoadAFile(long TitleID,_TCHAR *filespec,_TCHAR *excludelist[],void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*))
{
	C_Window *win;
	C_Button *btn;
	C_Text *txt;
	C_TreeList *tree;
	C_EditBox *ebox;

	if(!YesCB || !filespec)
		return;

	win=gMainHandler->FindWindow(SAVE_WIN);
	if(win)
	{
		txt=(C_Text*)win->FindControl(TITLE_LABEL);
		if(txt)
		{
			txt->Refresh();
			txt->SetText(TitleID);
			txt->Refresh();
		}
		btn=(C_Button *)win->FindControl(SAVE);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(NULL);
		}
		btn=(C_Button *)win->FindControl(LOAD_VIRTUAL);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(LOAD);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(CANCEL);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		btn=(C_Button *)win->FindControl(CLOSE_WINDOW);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		ebox=(C_EditBox*)win->FindControl(FILE_NAME);
		if(ebox)
		{
			ebox->Refresh();
			ebox->SetText("");
			ebox->SetFlagBitOff(C_BIT_ENABLED);
		}
		tree=(C_TreeList*)win->FindControl(FILELIST_TREE);
		if(tree)
		{
			tree->DeleteBranch(tree->GetRoot());
			tree->SetUserNumber(0,1);
			tree->SetSortType(TREE_SORT_CALLBACK);
			tree->SetSortCallback(FileNameSortCB);
			tree->SetCallback(LoadSaveSelectFileCB);
			GetFileListTree(tree,filespec,excludelist,C_TYPE_ITEM,TRUE,DELETE_FILE_POPUP);
			tree->RecalcSize();
			if(tree->Parent_)
				tree->Parent_->RefreshClient(tree->GetClient());
		}
		gMainHandler->ShowWindow(win);
		gMainHandler->WindowToFront(win);
	}
}

void LoadVirtualFile(long TitleID,_TCHAR *filespec,_TCHAR *excludelist[],void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*),_TCHAR virtuallist[200][64],void (*VirtualCB)(long,short,C_Base*))
{
	C_Window *win;
	C_Button *btn;
	C_TreeList *tree;
	C_Text *txt;
	C_EditBox *ebox;

	if(!YesCB || !filespec)
		return;

	win=gMainHandler->FindWindow(SAVE_WIN);
	if(win)
	{
		txt=(C_Text*)win->FindControl(TITLE_LABEL);
		if(txt)
		{
			txt->Refresh();
			txt->SetText(TitleID);
			txt->Refresh();
		}
		btn=(C_Button *)win->FindControl(SAVE);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(NULL);
		}
		btn=(C_Button *)win->FindControl(LOAD);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(LOAD_VIRTUAL);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(VirtualCB);
		}
		btn=(C_Button *)win->FindControl(CANCEL);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		btn=(C_Button *)win->FindControl(CLOSE_WINDOW);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		ebox=(C_EditBox*)win->FindControl(FILE_NAME);
		if(ebox)
		{
			ebox->Refresh();
			ebox->SetText("");
			ebox->SetFlagBitOff(C_BIT_ENABLED);
		}
		tree=(C_TreeList*)win->FindControl(FILELIST_TREE);
		if(tree)
		{
			tree->DeleteBranch(tree->GetRoot());
			tree->SetUserNumber(0,1);
			tree->SetSortType(TREE_SORT_CALLBACK);
			tree->SetSortCallback(FileNameSortCB);
			tree->SetCallback(LoadVirtualSelectFileCB);
			if(virtuallist)
				GetVirtualFileListTree(tree,virtuallist,C_TYPE_ITEM);
			GetFileListTree(tree,filespec,excludelist,C_TYPE_ITEM,TRUE,DELETE_FILE_POPUP);
			tree->RecalcSize();
			if(tree->Parent_)
				tree->Parent_->RefreshClient(tree->GetClient());
		}
		gMainHandler->ShowWindow(win);
		gMainHandler->WindowToFront(win);
	}
}

void SaveAFile(long TitleID,_TCHAR *filespec,_TCHAR *excludelist[],void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*))
{
	C_Window *win;
	C_Button *btn;
	C_Text *txt;
	C_EditBox *ebox;
	C_TreeList *tree;

	if(!YesCB || !filespec)
		return;

	win=gMainHandler->FindWindow(SAVE_WIN);
	if(win)
	{
		txt=(C_Text*)win->FindControl(TITLE_LABEL);
		if(txt)
		{
			txt->Refresh();
			txt->SetText(TitleID);
			txt->Refresh();
		}
		btn=(C_Button *)win->FindControl(SAVE);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(LOAD);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(LOAD_VIRTUAL);
		if(btn)
		{
			btn->SetFlagBitOn(C_BIT_INVISIBLE);
			btn->SetCallback(YesCB);
		}
		btn=(C_Button *)win->FindControl(CANCEL);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		btn=(C_Button *)win->FindControl(CLOSE_WINDOW);
		if(btn)
		{
			btn->SetFlagBitOff(C_BIT_INVISIBLE);
			btn->SetCallback(NoCB);
		}
		ebox=(C_EditBox*)win->FindControl(FILE_NAME);
		if(ebox)
		{
			ebox->Refresh();
			ebox->SetText("");
			ebox->SetFlagBitOn(C_BIT_ENABLED);
		}
		tree=(C_TreeList*)win->FindControl(FILELIST_TREE);
		if(tree)
		{
			tree->DeleteBranch(tree->GetRoot());
			tree->SetUserNumber(0,1);
			tree->SetSortType(TREE_SORT_CALLBACK);
			tree->SetSortCallback(FileNameSortCB);
			tree->SetCallback(LoadSaveSelectFileCB);
			GetFileListTree(tree,filespec,excludelist,C_TYPE_ITEM,TRUE,DELETE_FILE_POPUP);
			tree->RecalcSize();
			if(tree->Parent_)
				tree->Parent_->RefreshClient(tree->GetClient());
		}
		gMainHandler->ShowWindow(win);
		gMainHandler->WindowToFront(win);
	}
}

void CloseAYS()
{
	C_Window *win;
	win=gMainHandler->FindWindow(AYS_WIN);
	if(win)
		gMainHandler->HideWindow(win);
}

void AreYouSure(long TitleID,_TCHAR *text,void (*OkCB)(long,short,C_Base*),void (*CancelCB)(long,short,C_Base*))
{
	C_Window *win;
	C_Button *btn;
	C_Text *txt;
	short x,y;

	if(!text)
		return;

	win=gMainHandler->FindWindow(AYS_WIN);
	if(win)
	{
		txt=(C_Text *)win->FindControl(MODAL_TITLE);
		if(txt)
			txt->SetText(TitleID);

		btn=(C_Button *)win->FindControl(ALERT_CANCEL);
		if(btn)
		{
			if(CancelCB)
			{
				btn->SetFlagBitOn(C_BIT_ENABLED);
				btn->SetCallback(CancelCB);
			}
			else
				btn->SetFlagBitOff(C_BIT_ENABLED);
		}

		btn=(C_Button *)win->FindControl(ALERT_OK);
		if(btn)
		{
			if(OkCB)
			{
				btn->SetFlagBitOn(C_BIT_ENABLED);
				btn->SetCallback(OkCB);
			}
			else
				btn->SetFlagBitOff(C_BIT_ENABLED);
		}

		x=0; y=0;
		DeleteGroupList(win->GetID());
		AddWordWrapTextToWindow(win,&x,&y,0,static_cast<short>(win->ClientArea_[1].right-win->ClientArea_[1].left),0xe0e0e0,text,1);

		gMainHandler->ShowWindow(win);
		gMainHandler->WindowToFront(win);
	}
}

void AreYouSure(long TitleID,long MessageID,void (*OkCB)(long,short,C_Base*),void (*CancelCB)(long,short,C_Base*))
{
	AreYouSure(TitleID,gStringMgr->GetString(MessageID),OkCB,CancelCB);
}

BOOL CheckExclude(_TCHAR *filename,_TCHAR *directory,_TCHAR *ExcludeList[],_TCHAR *extension)
{
	_TCHAR fname[MAX_PATH];
	short i;

	i=0;
	while(ExcludeList[i])
	{
		_stprintf(fname,"%s\\%s.%s",directory,ExcludeList[i],extension);
		if(!_tcsicmp(filename,fname))
			return(TRUE);
		i++;
	}
	return(FALSE);
}

void VerifyDelete(long TitleID, void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*))
{
	AreYouSure(TitleID,TXT_DELETE_FILE,YesCB,NoCB);
}

void ExitVerify(long TitleID,void (*OkCB)(long,short,C_Base*),void (*CancelCB)(long,short,C_Base*))
{
	C_Window *win;
	C_Button *btn;
	C_Text *txt;

	win=gMainHandler->FindWindow(EXIT_WIN);
	if(win)
	{
		txt=(C_Text *)win->FindControl(MODAL_TITLE);
		if(txt)
			txt->SetText(TitleID);

		btn=(C_Button *)win->FindControl(ALERT_CANCEL);
		if(btn)
		{
			if(CancelCB)
			{
				btn->SetFlagBitOn(C_BIT_ENABLED);
				btn->SetCallback(CancelCB);
			}
			else
				btn->SetFlagBitOff(C_BIT_ENABLED);
		}

		btn=(C_Button *)win->FindControl(ALERT_OK);
		if(btn)
		{
			if(OkCB)
			{
				btn->SetFlagBitOn(C_BIT_ENABLED);
				btn->SetCallback(OkCB);
			}
			else
				btn->SetFlagBitOff(C_BIT_ENABLED);
		}

		gMainHandler->ShowWindow(win);
		gMainHandler->WindowToFront(win);
	}
}

void MakeVirtualListFromRsc(long ID,long startid)
{
	C_Resmgr *res;
	C_Hash *lst;
	C_HASHNODE *me;
	IMAGE_RSC *cur;
	long i=startid,curidx;

	if(i >= 200)
		return;

	VirtualFileList[i][0]=0;

	res=gImageMgr->GetImageRes(ID);
	if(res)
	{
		lst=res->GetIDList();
		if(lst)
		{
			cur=(IMAGE_RSC*)lst->GetFirst(&me,&curidx);
			while(cur && i < 200)
			{
				_tcscpy(VirtualFileList[i++],cur->Header->ID);
				cur=(IMAGE_RSC*)lst->GetNext(&me,&curidx);
			}
			VirtualFileList[i][0]=0;
		}
	}

}

extern int MRX;
extern int MRY;
extern int MAXOI;
extern short Map_Max_X;
extern short Map_Max_Y;

void MakeOccupationMap(IMAGE_RSC *Map)
{
	short x,y,i;
	uchar *ddPtr,*dst;
	uchar *src;
	WORD *Palette;
	long w,h;

	if(!Map)
		return;
	if(!Map->Owner)
		return;

	// HACK: Set uninitialized variables in CampMap
	// KCK TODO: Fix this, OR GetOwner() function for Terrain Team editor tool
//	MRX=Map_Max_X/MAP_RATIO;
//	MRY=Map_Max_Y/MAP_RATIO;
//	MAXOI = (sizeof(uchar)*MRX*MRY)/2;
	ShiAssert(MRX && MRY && MAXOI);

	Palette=Map->GetPalette();

	if(Palette)
	{
		Palette[0]=UI95_RGB24Bit(0);
		if(TheCampaign.Flags & CAMP_TACTICAL)
		{
			for(i=1;i<NUM_TEAMS;i++)
			{
				if(TheCampaign.IsLoaded() && TeamInfo[i])
					Palette[i]=UI95_RGB24Bit(TeamColorList[TeamInfo[i]->GetColor()]);
				else
					Palette[i]=UI95_RGB24Bit(TeamColorList[TheCampaign.team_colour[i]]);
			}
		}
		else
		{
			for(i=1;i<NUM_TEAMS;i++)
				Palette[i]=UI95_RGB24Bit(TeamColorList[i]);
		}
	}
	src=TheCampaign.CampMapData;
	ddPtr=(uchar*)Map->GetImage();
	if(ddPtr == NULL)
		return;
	if (src == NULL)
		return;

	w=Map->Header->w;
	h=Map->Header->h;
	dst=ddPtr+(h-2)*w;
	src+=w/2;
	y=1; // Skip pixels on edges of map 
	while(y < (h-2) && y < h)
	{
		x=2;
		dst+=2;
		src++;
		while(x < (h-2) && x < w)
		{
			*dst++=static_cast<uchar>((*src)&0x0f);
			*dst++=static_cast<uchar>((*src) >> 4);
			src++;
			x+=2;
		}
		src+=((w)-x)/2;
		dst+=(w-x);
		dst-=w*2;
		y++;
	}
}

static long PlaneIDTable[4][4]=
{
	{ CB_1_1,0,0,0,},
	{ CB_2_1,CB_2_2,0,0,},
	{ CB_3_1,CB_3_2,CB_3_3,0,},
	{ CB_4_1,CB_4_2,CB_4_3,CB_4_4,},
};

BOOL DisplayTarget(short MissType)
{
	switch(MissType)
	{
		case AMIS_BARCAP:
		case AMIS_BARCAP2:
		case AMIS_HAVCAP:
		case AMIS_TARCAP:
		case AMIS_RESCAP:
		case AMIS_AMBUSHCAP:
		case AMIS_SWEEP:
		case AMIS_FAC:
		case AMIS_ONCALLCAS:
		case AMIS_SAD:
		case AMIS_INT:
		case AMIS_BAI:
		case AMIS_PATROL:
		case AMIS_RECONPATROL:
			return(FALSE);
			break;
		default:
			return(TRUE);
			break;
	}
	return(FALSE);
}

void GetMissionTarget(Package curpackage,Flight curflight,_TCHAR Buffer[])
{
	WayPoint wp;
	CampEntity ent;
	GridIndex x=0,y=0;

	if(((curflight) && (curflight->GetUnitMission() != AMIS_ABORT)) || (!curflight))
	{
		ent=FindEntity(curpackage->GetMissionRequest()->targetID);
		
		if(ent && DisplayTarget(static_cast<short>(curflight->GetUnitMission())))
		{
			if (ent->IsObjective())
				ent->GetName(Buffer,39,TRUE);
			else
				ent->GetName(Buffer,39,FALSE);
		}
		else
		{
			wp=curflight->GetFirstUnitWP();
			if (!wp)
			{
				_tcscpy (Buffer, gStringMgr->GetString(TXT_NO_TARGET));
				return;
			}

			while(wp)
			{
				if(wp->GetWPFlags() & WPF_TARGET)
				{
					wp->GetWPLocation(&x,&y);
					
					wp=NULL;
				}
				else
				{
					wp=wp->GetNextWP();
				}
			}

			if (!x && !y)
			{
				_tcscpy (Buffer, gStringMgr->GetString(TXT_NO_TARGET));
				return;
			}

			Buffer[0]=0;
			AddLocationToBuffer('N',x,y,Buffer);
		}
	}
	else
		_tcscpy(Buffer,gStringMgr->GetString(TXT_ABORTED));
}

void GetFlightStatus(Flight element,_TCHAR buffer[])
{
	WayPoint wp;
	short found;

	wp=element->GetCurrentUnitWP();
	if(wp)
	{
		if(wp->GetWPAction() == WP_TAKEOFF)
			_tcscpy(buffer,gStringMgr->GetString(TXT_BRIEFING));
		else
		{
			found=0;
			_tcscpy(buffer,gStringMgr->GetString(TXT_RETURNTOBASE));
			while(found == 0 && wp)
			{
				if(wp->GetWPAction() == WP_ASSEMBLE)
				{
					_tcscpy(buffer,gStringMgr->GetString(TXT_ENROUTE));
					found=1;
				}
				else if(wp->GetWPAction() == WP_POSTASSEMBLE)
				{
					_tcscpy(buffer,gStringMgr->GetString(TXT_EGRESS));
					found=1;
				}
				else if(wp->GetWPFlags() & WPF_TARGET)
				{
					_tcscpy(buffer,gStringMgr->GetString(TXT_INGRESS));
					found=1;
				}
				else if(wp->GetWPAction() == WP_LAND)
				{
					_tcscpy(buffer,gStringMgr->GetString(TXT_LANDING));
					found=0;
				}
				if(wp->GetWPAction() == WP_LAND)
					wp=NULL;
				else
					wp=wp->GetNextWP();
			}
		}
	}
	else
		_tcscpy(buffer,gStringMgr->GetString(TXT_RETURNTOBASE));
}

void UpdateMissionWindow(long ID)
{
	C_Window *win;
	C_Button *btn;
	C_Text *txt;
	TREELIST *cur;
	C_TreeList *tree;
	Package curpackage;
	Flight curflight;
	WayPoint wp;
	_TCHAR Task[200];
	_TCHAR Mission[200];
	_TCHAR TOT[200];
	_TCHAR Buffer[200];
	_TCHAR PilotName[40];
	F4CSECTIONHANDLE *Leave;
	FalconSessionEntity *session;
	short i,planecount;

	if (!gMainHandler)
	{
		return;
	}

	win=gMainHandler->FindWindow(ID);
	if(win)
	{
		Leave=UI_Enter(win);
		curflight=(Flight)vuDatabase->Find(gCurrentFlightID);
		if(curflight)
			curpackage=(Package)curflight->GetUnitParent();
		else
			curpackage=NULL;

		tree=(C_TreeList*)win->FindControl(MISSION_LIST_TREE);
		if(tree)
		{
			cur=tree->GetRoot();
			while(cur)
			{
				if(((C_Mission*)cur->Item_)->GetVUID() == FalconLocalSession->GetPlayerFlightID())
					cur->Item_->SetState(2);
				else
					cur->Item_->SetState(0);

				if(((C_Mission*)cur->Item_)->GetVUID() == gCurrentFlightID)
					cur->Item_->SetState(static_cast<short>(cur->Item_->GetState() | 1));

				cur=cur->Next;
			}
		}
		planecount=0;
		if(curflight)
		{			
			while(curflight->plane_stats[planecount] != AIRCRAFT_NOT_ASSIGNED && planecount < PILOTS_PER_FLIGHT)
				planecount++;
		}
		if(curflight && curpackage && planecount)
		{
			txt=(C_Text *)win->FindControl(FLIGHT_LABEL);
			if(txt)
			{
				GetCallsign(curflight, Buffer);
				_tcscat(Buffer,": ");
				_tcscat(Buffer,MissStr[curflight->GetUnitMission()]);
				txt->SetText(Buffer);
			}

			if(PlaneIDTable[planecount-1][0])
			{
				for(i=0;i<planecount;i++)
				{
					btn=(C_Button *)win->FindControl(PlaneIDTable[planecount-1][i]);
					if(btn)
					{
						switch(curflight->plane_stats[i])
						{
							case AIRCRAFT_AVAILABLE:
								session=gCommsMgr->FindCampaignPlayer(curflight->Id(),static_cast<uchar>(i));
								btn->Refresh();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -