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

📄 controltab.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if(line)
	{
		win->RemoveControl(KEYCODES - count);
		retval = TRUE;
	}

	line = (C_Line *)win->FindControl(HLINE + count);
	if(line)
	{
		win->RemoveControl(HLINE + count);
		retval = TRUE;
	}

	line = (C_Line *)win->FindControl(VLINE + count);
	if(line)
	{
		win->RemoveControl(VLINE + count);
		retval = TRUE;
	}
	
	//need to remove them if they exist
	return retval;
}


int UpdateKeyMapList( char *fname,int flag )
{
	FILE *fp;
	
	char filename[_MAX_PATH];
	C_Window *win;


	win = gMainHandler->FindWindow(SETUP_WIN);
	if(!win)
	{
		KeyVar.NeedUpdate = TRUE;
		return FALSE;
	}

	if(flag)
		sprintf(filename,"%s\\config\\%s.key",FalconDataDirectory,fname);
	else
		sprintf(filename,"%s\\config\\keystrokes.key",FalconDataDirectory);

	fp = fopen(filename,"rt");
	if(!fp)
		return FALSE;
	
	UserFunctionTable.ClearTable();
	LoadFunctionTables(fname);
	
	char keydescrip[_MAX_PATH];
	C_Button	*button;
	C_Text		*text;
	
	keydescrip[0] = 0;
		
	int count = 0;
	int key1, mod1;
	int key2, mod2, editable;
//	int flags =0, 
	int buttonId, mouseSide;
	InputFunctionType theFunc;
	char buff[_MAX_PATH];
	char funcName[_MAX_PATH];
	char descrip[_MAX_PATH];
	char *parsed;
	HotSpotStruct HotSpot;
	
	C_Line *Vline;
	C_Line *Hline;
	C_Button *Keycodes;
	C_Text *Mapping;

	Keycodes = button = (C_Button *)win->FindControl(KEYCODES); //define this as KEYCODES
	Mapping = text = (C_Text *)win->FindControl(MAPPING);     //define this as MAPPING
	Hline = (C_Line *)win->FindControl(HLINE);     //define this as HLINE
	Vline = (C_Line *)win->FindControl(VLINE);     //define this as VLINE

	HotSpot.X = -3;
	HotSpot.Y = -1;
	if(Vline)
	{
		HotSpot.W = Vline->GetX() -1;
		HotSpot.H = Vline->GetH() - 1;
	}
	else
	{
		HotSpot.W = 30;
		HotSpot.H = 12;
	}

	KeyVar.Modified = FALSE;

	NumUndispKeys = 0;
	
	SetCursor(gCursors[CRSR_WAIT]);
	while(fgets(buff,_MAX_PATH,fp) )
	{
		
		if (buff[0] == ';' || buff[0] == '\n' || buff[0] == '#')
               continue;
		
		if(sscanf (buff, "%s %d %d %x %x %x %x %d %[^\n]s", funcName, &buttonId, &mouseSide, &key2, &mod2, &key1, &mod1, &editable, &descrip) < 8)
			continue;

		if(key2 < -1)
			continue;

		theFunc = FindFunctionFromString (funcName);
		
		keydescrip[0] = 0;

		if(!theFunc)
			continue;

		KeyMap Map;
		Map.func = theFunc;
		Map.buttonId = buttonId;
		Map.mouseSide = mouseSide;
		Map.editable = editable;
		strcpy(Map.descrip, descrip);
		Map.key1 = key1;
		Map.mod1 = mod1;
		Map.key2 = key2;
		Map.mod2 = mod2;

		if(editable == -2)
		{
			AddUndisplayedKey(Map);
		
			ShiAssert(NumUndispKeys < 300);

			continue;
		}
		
		parsed = descrip +1;
		parsed[strlen(descrip) -2] = 0;
		parsed[37] = 0;

		if(!count)
		{
			//first time through .. special case
			UpdateKeyMapButton(button, Map, count);

			Mapping->Refresh();
			Mapping->SetText(parsed);
			Mapping->Refresh();
		}
		else
		{
			SetHdrStatusLine(win, Keycodes, Vline, Map, HotSpot, count);
			//the rest of the times through
			UpdateKeyMap(win, Keycodes, Vline->GetH(), Map, HotSpot, count );

			UpdateMappingDescrip(win, Mapping, Vline->GetH(),parsed, count);//this will add the control if it doesn't exist

			AddKeyMapLines(win, Hline, Vline, count);
		 }

		count++;
		if(count > 10000)
			break;
	}

	NumDispKeys = count;

	fclose(fp);

	while(RemoveExcessControls(win,count++));

	gMainHandler->WindowToFront(win);

	SetCursor(gCursors[CRSR_F16]);
	return TRUE;
}

void LoadKeyCB(long,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(unsigned long i=0;i<_tcslen(fname);i++)
			if(fname[i] == '.')
				fname[i]=0;

		if(fname[0] == 0)
			return;
		
		KeyVar.Modified = TRUE;
		if(UpdateKeyMapList(fname, USE_FILENAME))
			_tcscpy(PlayerOptions.keyfile,ebox->GetText());
		
	}
}


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

	SetDeleteCallback(DelKeyFileCB);
	LoadAFile(TXT_LOAD_KEYBOARD,"config\\*.KEY",NULL,LoadKeyCB,CloseWindowCB);
}

int CreateKeyMapList( char *filename )
{
	FILE *fp;
	char path[_MAX_PATH];

	C_Window *win;

	win = gMainHandler->FindWindow(SETUP_WIN);
	if(!win)
		return FALSE;

	sprintf(path,"%s\\config\\%s.key",FalconDataDirectory,filename);
	
	fp = fopen(path,"rt");
	if(!fp)
	{
		sprintf(path,"%s\\config\\keystrokes.key",FalconDataDirectory);
		fp = fopen(path,"rt");
		if(!fp)
			return FALSE;
	}
	
	int count = 0;
	int key1, mod1;
	int key2, mod2;
//	int flags =0,
	int buttonId, mouseSide, editable;
	InputFunctionType theFunc;
	char buff[_MAX_PATH];
	char funcName[_MAX_PATH];
	char keydescrip[_MAX_PATH];
	char descrip[_MAX_PATH];
	char *parsed;
	HotSpotStruct HotSpot;
	//int	 HotX,HotY,HotW,HotH;
	UI95_RECT	client;

	C_Button *Keycodes;
	C_Text *Mapping;
	C_Line *Vline;
	C_Line *Hline;

	keydescrip[0] = 0;

	client = win->GetClientArea(3);
	Keycodes = (C_Button *)win->FindControl(KEYCODES); //define this as KEYCODES
	Mapping = (C_Text *)win->FindControl(MAPPING);     //define this as MAPPING
	Hline = (C_Line *)win->FindControl(HLINE);     //define this as HLINE
	Vline = (C_Line *)win->FindControl(VLINE);     //define this as VLINE
	
	HotSpot.X = -3;
	HotSpot.Y = -1;
	if(Vline)
	{
		HotSpot.W = Vline->GetX() -1;
		HotSpot.H = Vline->GetH() - 1;
	}
	else
	{
		HotSpot.W = 30;
		HotSpot.H = 12;
	}

	NumDispKeys = 0;
	NumUndispKeys = 0;

	while(fgets(buff,_MAX_PATH,fp) )
	{
		if (buff[0] == ';' || buff[0] == '\n' || buff[0] == '#')
               continue;
		
		if(sscanf (buff, "%s %d %d %x %x %x %x %d %[^\n]s", funcName, &buttonId, &mouseSide, &key2, &mod2, &key1, &mod1, &editable, &descrip) < 8)
			continue;

		if(key2 == -2)
			continue;

		theFunc = FindFunctionFromString (funcName);
		
		keydescrip[0] = 0;

		if(!theFunc)
			continue;

		KeyMap Map;
		Map.func = theFunc;
		Map.buttonId = buttonId;
		Map.mouseSide = mouseSide;
		Map.editable = editable;
		strcpy(Map.descrip, descrip);
		Map.key1 = key1;
		Map.mod1 = mod1;
		Map.key2 = key2;
		Map.mod2 = mod2;

		if(editable == -2)
		{
			AddUndisplayedKey(Map);
		
			ShiAssert(NumUndispKeys < 300);

			continue;
		}

		parsed = descrip +1;
		parsed[strlen(descrip) -2] = 0;
		parsed[37] = 0;

		if(!count)
		{
			NumDispKeys++;
			//first time through .. special case
			UpdateKeyMapButton(Keycodes, Map, count);
						
			Keycodes->SetCallback(KeycodeCB);
			Keycodes->SetHotSpot(HotSpot.X, HotSpot.Y, HotSpot.W, HotSpot.H);		
			Keycodes->Refresh();

			Mapping->Refresh();
			Mapping->SetText(parsed);
			Mapping->Refresh();
		}
		else
		{
			NumDispKeys++;
			SetHdrStatusLine(win, Keycodes, Vline, Map, HotSpot, count);
			//the rest of the times through
			UpdateKeyMap(win, Keycodes, Vline->GetH(), Map, HotSpot, count );

			UpdateMappingDescrip(win, Mapping, Vline->GetH(),parsed, count);//this will add the control if it doesn't exist

			AddKeyMapLines(win, Hline, Vline, count);
		 }

	count++;
	if(count > 10000)
		break;
	}
   	
	fclose(fp);
	return FALSE;

}


void SetKeyDefaultCB(long,short,C_Base *)
{
	if(UpdateKeyMapList( 0,USE_DEFAULT))
		KeyVar.Modified = TRUE;
}

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

	DIDEVICEOBJECTINSTANCE devobj;
	HRESULT hres;
	C_ListBox *lbox;
	lbox = (C_ListBox *)control;
	int JoystickSetupResult, newcontroller;

	//if( (lbox->GetTextID() < SIM_JOYSTICK1) || (lbox->GetTextID() > gTotalJoy + SIM_JOYSTICK1 - 1) )
	//	return;

	newcontroller = lbox->GetTextID() - 1;

	//Hack until other control modes work
	//newcontroller = SIM_JOYSTICK1;

	if(newcontroller == gCurController)
		return;

	if(gCurController == SIM_KEYBOARD)
	{
		SaveKeyMapList("laptop");
		UpdateKeyMapList( PlayerOptions.GetKeyfile(),TRUE );
	}

	if(newcontroller == SIM_MOUSE)
	{
		
	}
	else if(newcontroller == SIM_KEYBOARD)
	{
		SaveKeyMapList(PlayerOptions.GetKeyfile());
		UpdateKeyMapList("laptop",TRUE );
	}
	else if(newcontroller == SIM_NUMDEVICES)
	{
		//this is used to represent an intellipoint
	}
	else
	{
		C_Line		*line = NULL;
		C_Button	*button = NULL;
		int			hasPOV = FALSE;

		gCurJoyCaps.dwSize = sizeof(DIDEVCAPS);
		gpDIDevice[newcontroller]->GetCapabilities(&gCurJoyCaps);

		if(NumHats != -1)
			gCurJoyCaps.dwPOVs = NumHats;

		if(gCurJoyCaps.dwPOVs > 0)
			hasPOV = TRUE;

		button=(C_Button *)control->Parent_->FindControl(LEFT_HAT);
		if(button != NULL)
		{
			if (!hasPOV)
				button->SetFlagBitOn(C_BIT_INVISIBLE);
			else
				button->SetFlagBitOff(C_BIT_INVISIBLE);
			button->Refresh();
		}
		
		button=(C_Button *)control->Parent_->FindControl(RIGHT_HAT);
		if(button != NULL)
		{
			if (!hasPOV)
				button->SetFlagBitOn(C_BIT_INVISIBLE);
			else
				button->SetFlagBitOff(C_BIT_INVISIBLE);
			button->Refresh();
		}
		
		button=(C_Button *)control->Parent_->FindControl(CENTER_HAT);
		if(button != NULL)
		{
			if (!hasPOV)
				button->SetFlagBitOn(C_BIT_INVISIBLE);
			else
				button->SetFlagBitOff(C_BIT_INVISIBLE);
			button->Refresh();
		}
		
		button=(C_Button *)control->Parent_->FindControl(UP_HAT);
		if(button != NULL)
		{
			if (!hasPOV)
				button->SetFlagBitOn(C_BIT_INVISIBLE);
			else
				button->SetFlagBitOff(C_BIT_INVISIBLE);
			button->Refresh();
		}
		
		button=(C_Button *)control->Parent_->FindControl(DOWN_HAT);
		if(button != NULL)
		{
			if (!hasPOV)
				button->SetFlagBitOn(C_BIT_INVISIBLE);
			else
				button->SetFlagBitOff(C_BIT_INVISIBLE);
			button->Refresh();
		}
		devobj.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);
		
		hres = gpDIDevice[newcontroller]->GetObjectInfo(&devobj,DIJOFS_Z,DIPH_BYOFFSET);
		if(SUCCEEDED(hres))
			IO.SetAnalogIsUsed(2, TRUE);
		else
			IO.SetAnalogIsUsed(2, FALSE);

		line=(C_Line *)control->Parent_->FindControl(THROTTLE);
		if(line != NULL)
		{
			line->Refresh();
			if( !IO.AnalogIsUsed(2) )
			{
				line->SetColor(RGB(130,130,130)); //grey
				line->SetH(Throttle.bottom - Throttle.top);
				line->SetY(Throttle.top);
			}
			else
				line->SetColor(RGB(60,123,168)); //blue
			line->Refresh();
		}

		hres = gpDIDevice[newcontroller]->GetObjectInfo(&devobj,DIJOFS_RZ,DIPH_BYOFFSET);
		if(!NoRudder && SUCCEEDED(hres))
			IO.SetAnalogIsUsed(3, TRUE);
		else
			IO.SetAnalogIsUsed(3, FALSE);

		line=(C_Line *)control->Parent_->FindControl(RUDDER);
		if(line != NULL)
		{
			line->Refresh();
			if( !IO.AnalogIsUsed(3) )
			{
				line->SetColor(RGB(130,130,130)); //grey
				line->SetH(Rudder.bottom - Rudder.top);
				line->SetY(Rudder.top);
			}
			else
				line->SetColor(RGB(60,123,168)); //blue
			line->Refresh();
		}

		JoystickSetupResult = VerifyResult(gpDIDevice[newcontroller]->Acquire());
		gpDeviceAcquired[newcontroller] = JoystickSetupResult;
	}
	
	gCurController = newcontroller;
	//make selected joystick current joystick
}

void BuildControllerList(C_ListBox *lbox)
{	
	lbox->RemoveAllItems();
	
	//lbox->AddItem(SIM_MOUSE + 1,C_TYPE_ITEM,TXT_MOUSE);
	lbox->AddItem(SIM_KEYBOARD + 1,C_TYPE_ITEM,TXT_KEYBOARD);
	//lbox->AddItem(SIM_NUMDEVICES + 1,C_TYPE_ITEM,TXT_INTELLIPOINT);

	if(gTotalJoy)
	{
		for(int i = 0; i < gTotalJoy; i++)
		{
			if(!stricmp(gDIDevNames[SIM_JOYSTICK1 + i],"tm"))
			{
				delete [] gDIDevNames[SIM_JOYSTICK1 + i];
				gDIDevNames[SIM_JOYSTICK1 + i] = new TCHAR[MAX_PATH];
				_tcscpy(gDIDevNames[SIM_JOYSTICK1 + i],"Thrustmaster");
			}

			lbox->AddItem(i + SIM_JOYSTICK1 + 1,C_TYPE_ITEM,gDIDevNames[SIM_JOYSTICK1 + i]);
			if(mHelmetIsUR && i == mHelmetID)
				lbox->SetItemFlags(i + SIM_JOYSTICK1 + 1,0);
		}
	}
	lbox->Refresh();
}

⌨️ 快捷键说明

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