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

📄 controltab.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#include "falclib.h"
#include "chandler.h"
#include "userids.h"
#include "PlayerOp.h"
#include <mmsystem.h>
#include "sim\include\stdhdr.h"
#include "sim\include\simio.h"
#include "ui_setup.h"
#include <tchar.h>
#include "sim\include\inpFunc.h"
#include "sim\include\commands.h"
#include "f4find.h"
#include "sim\include\sinput.h"

//temporary until logbook is working
#include "uicomms.h"

#pragma warning (disable : 4706)	// assignment within conditional expression

extern C_Handler *gMainHandler;
extern C_Parser *gMainParser;
extern char **KeyDescrips;  
extern long Cluster;

#define SECOND_KEY_MASK 0xFFFF00
#define MOD2_MASK 0x0000FF
#define KEY1_MASK 0x00FF00
#define MOD1_MASK 0xFF0000

typedef struct
{
	InputFunctionType	func;
	int					buttonId;
	int					mouseSide;
	int					key2;
	int					mod2;
	int					key1;
	int					mod1;
	int					editable;
	char				descrip[_MAX_PATH];
}KeyMap;

typedef struct
{
	int		X;
	int		Y;
	int		W;
	int		H;
}HotSpotStruct;

enum{
	KEY2,
	FLAGS,
	BUTTON_ID,
	MOUSE_SIDE,
	EDITABLE,
	FUNCTION_PTR,
};

KeyVars KeyVar = {FALSE,0,0,0,0,FALSE,FALSE};
KeyMap	UndisplayedKeys[300] = {NULL,0,0,0,0,0,0,0};
int	NumUndispKeys = 0;
int	NumDispKeys = 0;
extern int NoRudder;
extern long mHelmetIsUR; // hack for Italian 1.06 version - Only gets set to true IF UR Helmet detected
extern long mHelmetID;

extern int setABdetent;

extern int NumHats;
//CalibrateStruct Calibration = {FALSE,1,0,TRUE};

//defined in this file
int CreateKeyMapList( C_Window *win);
//SIM_INT Calibrate ( void );


//defined in another file
void InitKeyDescrips(void);
void CleanupKeys(void);
void SetDeleteCallback(void (*cb)(long,short,C_Base*));
void SaveAFile(long TitleID,_TCHAR *filespec,_TCHAR *excludelist[],void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*));
void LoadAFile(long TitleID,_TCHAR *filespec,_TCHAR *excludelist[],void (*YesCB)(long,short,C_Base*),void (*NoCB)(long,short,C_Base*));
void CloseWindowCB(long ID,short hittype,C_Base *control);
void AreYouSure(long TitleID,long MessageID,void (*OkCB)(long,short,C_Base*),void (*CancelCB)(long,short,C_Base*));
void AreYouSure(long TitleID,_TCHAR *text,void (*OkCB)(long,short,C_Base*),void (*CancelCB)(long,short,C_Base*));
void SetJoystickCenter(void);
void DelSTRFileCB(long ID,short hittype,C_Base *control);
void DelDFSFileCB(long ID,short hittype,C_Base *control);
void DelLSTFileCB(long ID,short hittype,C_Base *control);
void DelCamFileCB(long ID,short hittype,C_Base *control);
void DelTacFileCB(long ID,short hittype,C_Base *control);
void DelTGAFileCB(long ID,short hittype,C_Base *control);
void DelVHSFileCB(long ID,short hittype,C_Base *control);
void DelKeyFileCB(long ID,short hittype,C_Base *control);

///////////////
////ControlsTab
///////////////

void HideKeyStatusLines(C_Window *win)
{
	if(!win)
		return;

	C_Line *line;
	C_Button *button;
	int count = 1;

	line = (C_Line *)win->FindControl(KEYCODES - count);
	while(line)
	{
		button = (C_Button *)win->FindControl(KEYCODES + count);
		if(!button || button->GetUserNumber(EDITABLE) != -1 )
		{
			line->SetFlagBitOn(C_BIT_INVISIBLE);
			line->Refresh();
		}

		line = (C_Line *)win->FindControl(KEYCODES - ++count);
	}
}

void SetButtonColor(C_Button *button)
{
	if(button->GetUserNumber(EDITABLE) < 1)
		button->SetFgColor(0,RGB(0,255,0)); //green
	else
	{
		button->SetFgColor(0,RGB(230,230,230)); //white
	}
	button->Refresh();
}

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

	SetJoystickCenter();
}

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

	setABdetent = TRUE;
}

void RefreshJoystickCB(long,short,C_Base *)
{
	
	static SIM_FLOAT JoyXPrev,JoyYPrev,RudderPrev,ThrottlePrev,ABDetentPrev;
	static DWORD ButtonPrev[SIMLIB_MAX_DIGITAL],POVPrev;
	static int Initialize = 1, state = 1;
	C_Bitmap	*bmap;
	C_Window	*win;
	C_Line		*line;
	C_Button	*button;
	
	
	GetJoystickInput();
	
	
		win=gMainHandler->FindWindow(SETUP_WIN);
		if(win != NULL)
		{
			//test to see if joystick moved, if so update the control
			if((IO.analog[0].engrValue != JoyXPrev)||(IO.analog[1].engrValue != JoyYPrev)||Initialize)
			{				
				bmap=(C_Bitmap *)win->FindControl(JOY_INDICATOR);
				if(bmap != NULL)
				{
					bmap->Refresh();
					bmap->SetX((int)(JoyScale + IO.analog[0].engrValue * JoyScale));
					bmap->SetY((int)(JoyScale + IO.analog[1].engrValue * JoyScale));
					bmap->Refresh();					
					win->RefreshClient(1);
				}
			}
			

			if(IO.AnalogIsUsed(3))
			{
				//test to see if rudder moved, if so update the control
				if(((IO.analog[3].engrValue != RudderPrev)||Initialize) && state )
				{
					line=(C_Line *)win->FindControl(RUDDER);
					if(line != NULL)
					{	
						line->Refresh();
						line->SetY((int)(Rudder.top + RudderScale - IO.analog[3].engrValue * RudderScale + .5));
						if(line->GetY() < Rudder.top)
							line->SetY(Rudder.top);
						if(line->GetY() > Rudder.bottom)
							line->SetY(Rudder.bottom);
						line->SetH(Rudder.bottom - line->GetY());
						line->Refresh();					
					}
				}
			}
			
			if(IO.AnalogIsUsed(2))
			{
				//test to see if throttle moved, if so update the control
				if(((IO.analog[2].engrValue != ThrottlePrev)||Initialize) && state )
				{
					line=(C_Line *)win->FindControl(THROTTLE);
					if(line != NULL)
					{
						line->Refresh();
						line->SetY(FloatToInt32(static_cast<float>(Throttle.top + IO.analog[2].ioVal/15000.0F * ThrottleScale + .5)));
						if(line->GetY() < Throttle.top)
							line->SetY(Throttle.top);
						if(line->GetY() > Throttle.bottom)
							line->SetY(Throttle.bottom);
						line->SetH(Throttle.bottom - line->GetY());
						line->Refresh();
					} 
				}

				if(ABDetentPrev != IO.analog[2].center||Initialize)
				{
					line=(C_Line *)win->FindControl(AB_DETENT);
					if(line != NULL)
					{
						line->Refresh();
						line->SetY(FloatToInt32(static_cast<float>(Throttle.top + IO.analog[2].center/15000.0F * ThrottleScale + .5)));
						if(line->GetY() <= Throttle.top - 1)
							line->SetY(Throttle.top);
						if(line->GetY() >= Throttle.bottom)
							line->SetY(Throttle.bottom + 1);
						line->Refresh();
					}
				}
			}
			
			
			unsigned long i;
			for(i=0;i<gCurJoyCaps.dwButtons;i++)
			{
				//only have 8 controls on screen, but joystick
				//may have more than 8 buttons
				int j = i;
				while(j > 7)
					j -= 8;

				button=(C_Button *)win->FindControl(J1 + j);
				if(button != NULL)
				{
					if(IO.digital[i])
						button->SetState(C_STATE_1);
					else
						button->SetState(C_STATE_0);
					button->Refresh();
				}

				if(IO.digital[i])
				{
					C_Text *text = (C_Text *)win->FindControl(CONTROL_KEYS); 
					if(text)
					{
						char string[_MAX_PATH];
						text->Refresh();
						sprintf(string,"%s %d",gStringMgr->GetString(TXT_BUTTON),i+1);							
						text->SetText(string);
						text->Refresh();
					}
					
					if(KeyVar.EditKey)
					{
						button = (C_Button *)win->FindControl(KeyVar.CurrControl);
						UserFunctionTable.SetButtonFunction(i,(InputFunctionType)button->GetUserPtr(FUNCTION_PTR),button->GetUserNumber(BUTTON_ID));
						KeyVar.EditKey = FALSE;
						KeyVar.Modified = TRUE;
						SetButtonColor(button);
					}

					text = (C_Text *)win->FindControl(FUNCTION_LIST);
					if(text)
					{
						InputFunctionType func;
						char *descrip;

						text->Refresh();
						if(func = UserFunctionTable.GetButtonFunction(i,NULL))
						{
							int i = 0;

							C_Button *tButton = (C_Button *)win->FindControl(KEYCODES);
							while(tButton)
							{								
								if(func == (InputFunctionType)tButton->GetUserPtr(5))
								{
									C_Text *temp = (C_Text *)win->FindControl(tButton->GetID()- KEYCODES + MAPPING);
									
									if(temp)
									{
										descrip = temp->GetText();
										if(descrip)
										{
											text->SetText(descrip);
											break;
										}
									}
									text->SetText("");
									break;
								}
								else
								{
									tButton = (C_Button *)win->FindControl(KEYCODES + i++);
								}
							}
						}
						else
						{
							if(i == 0)
							{
								text->SetText(TXT_FIRE_GUN);
							}
							else if(i == 1)
							{
								text->SetText(TXT_FIRE_WEAPON);
							}
							else
							{
								text->SetText(TXT_NO_FUNCTION);
							}
						}
						text->Refresh();
					}							
				}
			}			
			
			int Direction;
			int flags = 0;

			for(i= 0;i<gCurJoyCaps.dwPOVs;i++)
			{
				Direction = 0;
				if((IO.povHatAngle[i] < 2250 || IO.povHatAngle[i] > 33750) && IO.povHatAngle[i] != -1)
				{
					flags |= 0x01;
					Direction = 0;
				}
				else if(IO.povHatAngle[i] < 6750 )
				{
					flags |= 0x03;
					Direction = 1;
				}
				else if(IO.povHatAngle[i] < 11250)
				{
					flags |= 0x02;
					Direction = 2;
				}
				else if(IO.povHatAngle[i] < 15750)
				{
					flags |= 0x06;
					Direction = 3;
				}
				else if(IO.povHatAngle[i] < 20250)
				{
					flags |= 0x04;
					Direction = 4;
				}
				else if(IO.povHatAngle[i] < 24750)
				{
					flags |= 0x0C;
					Direction = 5;
				}
				else if(IO.povHatAngle[i] < 29250)
				{
					flags |= 0x08;
					Direction = 6;
				}
				else if(IO.povHatAngle[i] < 33750)
				{
					flags |= 0x09;
					Direction = 7;
				}

				if(KeyVar.EditKey && IO.povHatAngle[i] != -1)
				{
					C_Button *button;

					button = (C_Button *)win->FindControl(KeyVar.CurrControl);
					UserFunctionTable.SetPOVFunction(i,Direction,(InputFunctionType)button->GetUserPtr(FUNCTION_PTR),button->GetUserNumber(BUTTON_ID));
					KeyVar.EditKey = FALSE;
					KeyVar.Modified = TRUE;
					SetButtonColor(button);
				}

				C_Text *text = (C_Text *)win->FindControl(FUNCTION_LIST);
				if(text && IO.povHatAngle[i] != -1)
				{
					C_Text *text2 = (C_Text *)win->FindControl(CONTROL_KEYS); 
					if(text2)
					{
						char button[_MAX_PATH];
						text2->Refresh();
						sprintf(button,"%s %d : %s", gStringMgr->GetString(TXT_POV), i+1, gStringMgr->GetString(TXT_UP + Direction));																		
						text2->SetText(button);
						text2->Refresh();
					}

					InputFunctionType func;
					char *descrip;

					text->Refresh();
					if(func = UserFunctionTable.GetPOVFunction(i,Direction,NULL))
					{
						int i = 0;

						C_Button *tButton = (C_Button *)win->FindControl(KEYCODES);
						while(tButton)
						{								
							if(func == (InputFunctionType)tButton->GetUserPtr(5))
							{
								C_Text *temp = (C_Text *)win->FindControl(tButton->GetID()- KEYCODES + MAPPING);
								
								if(temp)
								{
									descrip = temp->GetText();
									if(descrip)
									{
										text->SetText(descrip);
										break;
									}
								}
								text->SetText("");
								break;
							}
							else
							{
								tButton = (C_Button *)win->FindControl(KEYCODES + i++);
							}
						}
					}
					else
					{
						text->SetText(TXT_NO_FUNCTION);
					}
					text->Refresh();
				}		
			}

			button=(C_Button *)win->FindControl(UP_HAT);
			if(button != NULL && button->GetState() != C_STATE_DISABLED)
			{
				if(flags & 0x01)
					button->SetState(C_STATE_1);
				else
					button->SetState(C_STATE_0);
				button->Refresh();
			}
			
			button=(C_Button *)win->FindControl(RIGHT_HAT);
			if(button != NULL && button->GetState() != C_STATE_DISABLED)
			{
				if(flags & 0x02)
					button->SetState(C_STATE_1);
				else
					button->SetState(C_STATE_0);
				button->Refresh();
			}
			
			button=(C_Button *)win->FindControl(DOWN_HAT);
			if(button != NULL && button->GetState() != C_STATE_DISABLED)
			{
				if(flags & 0x04)
					button->SetState(C_STATE_1);
				else
					button->SetState(C_STATE_0);
				button->Refresh();
			}
			
			button=(C_Button *)win->FindControl(LEFT_HAT);
			if(button != NULL && button->GetState() != C_STATE_DISABLED)
			{
				if(flags & 0x08)
					button->SetState(C_STATE_1);
				else
					button->SetState(C_STATE_0);
				button->Refresh();
			}
			
			Initialize = 0;
			JoyXPrev = IO.analog[0].engrValue;
			JoyYPrev = IO.analog[1].engrValue; 
			ThrottlePrev = IO.analog[2].engrValue;
			RudderPrev = IO.analog[3].engrValue;
			ABDetentPrev = static_cast<float>(IO.analog[2].center);
			POVPrev = IO.povHatAngle[0];
		}
	//if(Calibration.calibrating)
	//	Calibrate();
	
}//RefreshJoystickCB

SIM_INT CalibrateFile (void)
{
	int i, numAxis;
	FILE* filePtr;
	
	char fileName[_MAX_PATH];
	sprintf(fileName,"%s\\config\\joystick.dat",FalconDataDirectory);

	filePtr = fopen (fileName, "rb");
	if(filePtr != NULL)
	{
		fread (&numAxis, sizeof(int), 1, filePtr);
		
		for (i=0; i<numAxis; i++)
		{
			fread (&(IO.analog[i]), sizeof(SIMLIB_ANALOG_TYPE), 1, filePtr);
		}
		fclose (filePtr);
		
		return (TRUE);
	}
	return FALSE;
}
/*
void StopCalibrating(C_Base *control)
{
	C_Text *text;
	C_Button *button;

	Calibration.calibrating = FALSE;
	Calibration.step = 0;
	Calibration.disp_text = TRUE;
	Calibration.state = 1;

	Calibration.calibrated = CalibrateFile();

	text=(C_Text *)control->Parent_->FindControl(CAL_TEXT);
	text->Refresh();
	text->SetFlagBitOn(C_BIT_INVISIBLE);
	text->Refresh();

	text=(C_Text *)control->Parent_->FindControl(CAL_TEXT2);
	text->Refresh();
	text->SetFlagBitOn(C_BIT_INVISIBLE);
	text->Refresh();

	button = (C_Button *)control->Parent_->FindControl(CALIBRATE);
	button->SetState(C_STATE_0);
	button->Refresh();
}*/

/*
SIM_INT Calibrate ( void )

⌨️ 快捷键说明

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