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

📄 ui_lgbk.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	gMainHandler->HideWindow(control->Parent_);

	ebox=(C_EditBox*)control->Parent_->FindControl(FILE_NAME);
	if(ebox)
	{
		_tcscpy(fname,ebox->GetText());

		if(fname[0] == 0)
			return;

		if(CurControl == PATCH_PIC)
			res=gImageMgr->GetImageRes(PATCHES_RESOURCE);
		else
			res=gImageMgr->GetImageRes(PILOTS_RESOURCE);

		if(res)
		{
			imageID=gMainParser->FindID(fname);

			if(SetResourceImage(CurControl, imageID))
			{
				if(CurControl==PATCH_PIC)
				{
					UI_logbk.SetPatch(imageID);
				}
				else if(CurControl == PILOT_PIC)
					UI_logbk.SetPicture(imageID);
			}
		}
	}
}


void ChangeImageCB(long ID,short hittype,C_Base *control)
{
	if(LogState & LB_OPPONENT || !(LogState & LB_EDITABLE))
		return;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	CurControl = ID;
	if(CurControl==PATCH_PIC)
	{
		MakeVirtualListFromRsc(PATCHES_RESOURCE,0);
		LoadVirtualFile(TXT_LOAD_PATCH,"patches\\*.tga",NULL,LoadTGACB,CloseWindowCB,VirtualFileList,LoadVirtualTGACB);
		//LoadAFile("patches\\*.tga",NULL,LoadTGACB,CloseWindowCB);
	}
	else
	{
		MakeVirtualListFromRsc(PILOTS_RESOURCE,0);
		LoadVirtualFile(TXT_LOAD_PICTURE,"pictures\\*.tga",NULL,LoadTGACB,CloseWindowCB,VirtualFileList,LoadVirtualTGACB);
		//LoadAFile("pictures\\*.tga",NULL,LoadTGACB,CloseWindowCB);
	}
	
	control->Refresh();
}

int SetResourceImage(long ID,long ImageID)
{
	C_Window	*win;
	win=gMainHandler->FindWindow(LOG_WIN);
	if(win != NULL)
	{
		C_Button *button = (C_Button *)win->FindControl(ID);
		if(button)
		{
			button->Refresh();
			
			button->SetImage(C_STATE_0,ImageID);
			button->SetImage(C_STATE_1,ImageID);
			button->SetImage(C_STATE_SELECTED,ImageID);
			button->SetImage(C_STATE_DISABLED,ImageID);
			button->Refresh();
		}

		if(ID == PILOT_PIC)
			CurPic = 0;
		else if(ID == PATCH_PIC)
			CurPatch = 0;
		return TRUE;
	}
	return FALSE;
}

//sets image for button with ID == ID
int SetImage(long ID,_TCHAR *filename ,long ImageID)
{
	C_Button	*button;
	C_Window	*win;
	C_Resmgr *resmgr=NULL;
	IMAGE_RSC *Image=NULL;
//	IMAGE_RSC *PrevImage=NULL;
	F4CSECTIONHANDLE *Leave;

	win=gMainHandler->FindWindow(LOG_WIN);
	if(win != NULL)
	{
		long OldImageID = ImageID;
		Leave=UI_Enter(win);
		switch(ImageID)
		{
		case LOGBOOK_PICTURE_ID:
			ImageID = LOGBOOK_PICTURE_ID_2;
			break;
		case LOGBOOK_PICTURE_ID_2:
			ImageID = LOGBOOK_PICTURE_ID;
			break;
		case LOGBOOK_SQUADRON_ID:
			ImageID = LOGBOOK_SQUADRON_ID_2;
			break;
		case LOGBOOK_SQUADRON_ID_2:
			ImageID = LOGBOOK_SQUADRON_ID;
			break;
		default:
			if(ID == PATCH_PIC)
				ImageID = LOGBOOK_PICTURE_ID;
			else if(ID == PILOT_PIC)
				ImageID = LOGBOOK_SQUADRON_ID;
			break;
		};
		resmgr=gImageMgr->LoadImage(ImageID,filename,-1,-1);

		Image=gImageMgr->GetImage(ImageID);
		if(!Image)
		{
			MonoPrint("FUNCTION: void SetImage()  -> Failed to load PHOTO file: %s \n",filename);
			UI_Leave(Leave);
			return FALSE;
		}

		if(CurControl == PATCH_PIC)
		{
			if(Image->Header->w > 96 || Image->Header->h > 96)
			{
				MonoPrint("Patch %s is too large\n",filename);
				UI_Leave(Leave);
				return FALSE;
			}
			if(Image->Header->w % 2)
			{
				MonoPrint("Patch %s is an odd width\n",filename);
				//return FALSE;
			}
		}
		else
		{
			if(Image->Header->w > 96 || Image->Header->h > 96)
			{
				MonoPrint("Picture %s is too large\n",filename);
				UI_Leave(Leave);
				return FALSE;
			}
			if(Image->Header->w % 2)
			{
				MonoPrint("Picture %s is an odd width\n",filename);
				//return FALSE;
			}
		}

		
		button = (C_Button *)win->FindControl(ID);
		if(button)
		{
			button->Refresh();
			/*
			int CenX,CenY,NewX,NewY;
			
			if(ID == PATCH_PIC)
			{
				CenX = 508;
				CenY = 322;
			}
			else if(ID == PILOT_PIC)
			{
				CenX = PicArea.left + (PicArea.right - PicArea.left)/2;
				CenY = PicArea.top + (PicArea.bottom - PicArea.top)/2;
			}

			
			NewX = CenX - (Image->Header->w/2);
			NewY = CenY - (Image->Header->h/2);

			button->SetXY(NewX,NewY);*/

			button->SetImage(C_STATE_0,ImageID);
			button->SetImage(C_STATE_1,ImageID);
			button->SetImage(C_STATE_SELECTED,ImageID);
			button->SetImage(C_STATE_DISABLED,ImageID);
			button->Refresh();
		}
		if(OldImageID)
			gImageMgr->RemoveImage(OldImageID);

		if(ID == PILOT_PIC)
			CurPic = ImageID;
		else if(ID == PATCH_PIC)
			CurPatch = ImageID;
		
		UI_Leave(Leave);
	}
	return TRUE;
}
/*
void LoadLogCB(long ID,short hittype,C_Base *control)
{
	C_EditBox * ebox;
	_TCHAR fname[MAX_PATH];

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	gMainHandler->HideWindow(control->Parent_);

	ebox=(C_EditBox*)control->Parent_->FindControl(FILE_NAME);
	if(ebox)
	{
		_tcscpy(fname,ebox->GetText());
		for(int i=0;i<_tcslen(fname);i++)
			if(fname[i] == '.')
				fname[i]=0;

		if(fname[0] == 0)
			return;
		UI_logbk.LoadData(fname);
		LogState &= ~LB_CHECKED;
		if(!UI_logbk.CheckPassword(_T("")))
			PasswordWindow(TXT_LOG_IN,TXT_LOG_IN_MESSAGE,CheckPasswordCB,NoPasswordCB);
		LBSetupControls();
		PlayerOptions.LoadOptions(UI_logbk.OptionsFile());
		UpdateKeyMapList(PlayerOptions.keyfile,1);
	}
}
*/
void PasswordChangeVerifiedCB(long,short hittype,C_Base *control)
{
	C_EditBox * ebox;
	C_EditBox * pwdbox;
	C_Window *win;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	win=gMainHandler->FindWindow(LOG_WIN);
	if(win == NULL)
		return;

	ebox=(C_EditBox*)control->Parent_->FindControl(PASSWORD);
	if(ebox)
	{
		pwdbox=(C_EditBox *)win->FindControl(PASSWORD_LIST);
		if(pwdbox != NULL)
		{
			if( _tcscmp( ebox->GetText(), pwdbox->GetText() ) )
				return;
			
			UI_logbk.SetPassword(ebox->GetText());
			pwdbox->SetText(ebox->GetText());
			pwdbox->Refresh();
			ebox->SetText(_T(""));
			ebox->Refresh();
			gMainHandler->HideWindow(control->Parent_);
			control = win->FindControl(LOG_OK);
			SaveLogBookCB(LOG_OK,hittype,control);
			LogState |= LB_CHECKED;
		}
	}
	
}

void PwdVerifiedContLoading(long,short hittype,C_Base *control)
{
	C_EditBox * ebox;
	C_EditBox * pwdbox;
	C_Window *win;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	win=gMainHandler->FindWindow(LOG_WIN);
	if(win == NULL)
		return;

	ebox=(C_EditBox*)control->Parent_->FindControl(PASSWORD);
	if(ebox)
	{
		pwdbox=(C_EditBox *)win->FindControl(PASSWORD_LIST);
		if(pwdbox != NULL)
		{
			if( _tcscmp( ebox->GetText(), pwdbox->GetText() ) )
				return;
			
			//password verified, save new value and continue opening
			UI_logbk.SetPassword(ebox->GetText());
			ebox->SetText(_T(""));
			ebox->Refresh();
			gMainHandler->HideWindow(control->Parent_);
			LogState |= LB_CHECKED;

			
			UI_logbk.SaveData();
			C_ListBox *lbox;
			lbox = (C_ListBox *)win->FindControl(LOGBOOK_LIST);
			if(lbox)
			{
				//if current log is selected do nothing
				if(!_tcscmp(lbox->GetText(),UI_logbk.Callsign()))
					return;

				if( UI_logbk.LoadData(lbox->GetText()) )
				{
					LogState &= ~LB_CHECKED;
					if(!UI_logbk.CheckPassword(_T("")))
						PasswordWindow(TXT_LOG_IN,TXT_LOG_IN_MESSAGE,CheckPasswordCB,NoPasswordCB);
					LBSetupControls();
				}
			}
		}
	}
	
}


void LoadPilotCB(long,short hittype,C_Base *control)
{
	C_EditBox *ebox;

	if(hittype == C_TYPE_SELECT)
	{
		//if password was changed, confirm it (do it here after list window is closed
		//so we don't have two exclusive windows at once)
		ebox=(C_EditBox *)control->Parent_->FindControl(PASSWORD_LIST);
		if(ebox != NULL)
		{
			if(!UI_logbk.CheckPassword(ebox->GetText()))
			{
				LogState &= ~LB_CHECKED;
				PasswordWindow(TXT_VERIFY_PASSWORD,TXT_VERIFY_PASS_MESSAGE,PwdVerifiedContLoading,CloseWindowCB);
				return;
			}
		}

		_TCHAR Pilot[MAX_PATH];
		_tcscpy(Pilot,((C_ListBox *)control)->GetText());

		//return if current logbook is selected
		if(!_tcscmp(Pilot,UI_logbk.Callsign()))
		{
			if(LogState & LB_INVALID_CALLSIGN)
			{
				AreYouSure(TXT_ERROR,TXT_INVALID_CALLSIGN,CloseWindowCB,NULL);
				LogState &= ~LB_INVALID_CALLSIGN;
				//return;
			}
			return;
		}

		ebox=(C_EditBox *)control->Parent_->FindControl(PASSWORD_LIST);
		if(ebox != NULL)
		{
			SaveControlValues();
			UI_logbk.SaveData();
			
			//load data for selected pilot and check password
			if( UI_logbk.LoadData(Pilot) )
			{
				LogState &= ~LB_CHECKED;
				//if password check is passed, allow access, otherwise
				//initialize UI_logbk and update controls
				if(!UI_logbk.CheckPassword(_T("")))
					PasswordWindow(TXT_LOG_IN,TXT_LOG_IN_MESSAGE,CheckPasswordCB,NoPasswordCB);
				else
				{
					PlayerOptions.LoadOptions(UI_logbk.OptionsFile());
					UpdateKeyMapList(PlayerOptions.keyfile,1);
				}

				LBSetupControls();
				
				
				C_Window *stpwin;
				stpwin = gMainHandler->FindWindow(SETUP_WIN);
				if(stpwin)
				{
					C_Button *button;
					button = (C_Button *)stpwin->FindControl(SET_LOGBOOK);
					if(button)
					{
						button->SetText(0,UI_logbk.Callsign());
						button->Refresh();
					}
				}
				
				//notify user the callsign entered was invalid
				if(LogState & LB_INVALID_CALLSIGN)
				{
					AreYouSure(TXT_ERROR,TXT_INVALID_CALLSIGN,CloseWindowCB,NULL);
					LogState &= ~LB_INVALID_CALLSIGN;
					//return;
				}
			}
		}
	}
	else if(hittype == C_TYPE_LMOUSEUP)
	{
		

		//if callsign is invalid note it for later use
		ebox=(C_EditBox *)control->Parent_->FindControl(CALLSIGN_LIST);
		if(ebox != NULL)
		{
			if(!CheckCallsign(ebox->GetText()) )
			{
				ebox->SetText(UI_logbk.Callsign());
				LogState |= LB_INVALID_CALLSIGN;
				ebox->Refresh();
			}
			
			C_EditBox *pbox;
			//if password was changed, confirm it in select event CB
			pbox=(C_EditBox *)control->Parent_->FindControl(PASSWORD_LIST);
			if(pbox != NULL)
			{
				if(!UI_logbk.CheckPassword(pbox->GetText()))
				{
					return;
				}
			}

			//was the callsign changed? if so rename file, save change, and update list
			if( _tcsicmp( UI_logbk.Callsign(),ebox->GetText() ) )
			{
				_TCHAR orig[MAX_PATH];
				_TCHAR newfile[MAX_PATH];
				
				//rename file
				_stprintf(orig,_T("%s\\config\\%s.lbk"),FalconDataDirectory,UI_logbk.Callsign());
				_stprintf(newfile,_T("%s\\config\\%s.lbk"),FalconDataDirectory,ebox->GetText());
				_trename(orig,newfile);

				_stprintf(orig,_T("%s\\config\\%s.plc"),FalconDataDirectory,UI_logbk.Callsign());
				_stprintf(newfile,_T("%s\\config\\%s.plc"),FalconDataDirectory,ebox->GetText());
				_trename(orig,newfile);
				//store change in memory
				UI_logbk.SetCallsign(ebox->GetText());
			}
			
			//save changes to file
			UI_logbk.SaveData();

			//build new list and select correct pilot
			_TCHAR buf[MAX_PATH];
			_stprintf(buf,_T("%s\\config\\*.lbk"),FalconDataDirectory);
			GetPilotList( control->Parent_, buf, NULL, (C_ListBox *)control, TRUE, TRUE );
			SetPilot(UI_logbk.Callsign(),(C_ListBox *)control);			
		}
	}
}

/*
void LoadLogBookCB(long ID,short hittype,C_Base *control)
{
	if(hittype != C_TYPE_LMOUSEUP)
		return;
	
	LoadAFile("config\\*.lbk",NULL,LoadLogCB,CloseWindowCB);
}
*/

void OpenLogBookCB(long,short hittype,C_Base *control)
{
	if(hittype != C_TYPE_LMOUSEUP)
		return;

	SetCursor(gCursors[CRSR_WAIT]);

	LoadLogBookWindows();
	
	gMainHandler->EnableWindowGroup(control->GetGroup());
	SetCursor(gCursors[CRSR_F16]);

	if(!LogBook.CheckPassword(_T("")))
		PasswordWindow(TXT_LOG_IN,TXT_LOG_IN_MESSAGE,CheckPasswordCB,NoPasswordCB);
}


void NewLogbookCB(long,short hittype,C_Base *)
{
	if(LogState & LB_OPPONENT)
		return;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	LogState |= LB_EDITABLE | LB_CHECKED;

	UI_logbk.Initialize();
	LBSetupControls();
}

void ClearCB(long,short hittype,C_Base *control)
{
	if(hittype != C_TYPE_LMOUSEUP)
		return;
	
	UI_logbk.Clear();
	gMainHandler->HideWindow(control->Parent_);
	LBSetupControls();
}

void ClearLogBookCB(long,short hittype,C_Base *)
{
	if(LogState & LB_OPPONENT)
		return;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	AreYouSure(TXT_WARNING,TXT_CLEAR_LOGBOOK,ClearCB,CloseWindowCB);
}

int CheckCallsign(_TCHAR *filename)
{
	if(!_tcslen(filename))
		return FALSE;


	unsigned long pos = _tcscspn(filename,_T("\\/:?\"<>|") );

	if(pos < _tcslen(filename))
		return FALSE;

	
	_TCHAR *ptr = filename;

	int numchars = 0;
	
	for(; *ptr; ptr++)
	{
		if(_istalnum(*ptr))
			numchars++;
		else if(*ptr != ' ')
			return FALSE;
	}

	if(numchars < 3)
		return FALSE;


	return TRUE;
}

int SaveControlValues(void)
{
	C_Window	*win;
	C_EditBox	*ebox;
	C_Text		*text;
	C_ListBox	*lbox;

	win=gMainHandler->FindWindow(LOG_WIN);
	if(win == NULL)
		return FALSE;

	

	ebox=(C_EditBox *)win->FindControl(CALLSIGN_LIST);
	if(ebox != NULL)
	{
		if(!CheckCallsign(ebox->GetText()) )
		{
			AreYouSure(TXT_ERROR,TXT_INVALID_CALLSIGN,CloseWindowCB,CloseWindowCB);
			return FALSE;
		}

		_TCHAR *callsign;
		_TCHAR *ptr = callsign = ebox->GetText();

		ptr = callsign;
		while(*ptr == ' ')
			ptr++;

⌨️ 快捷键说明

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