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

📄 controltab.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
	int retval;
		
	if (S_joyret == JOYERR_NOERROR)
	{
		retval = SIMLIB_OK;
		int size;
		FILE* filePtr;
		C_Base	*control;
		C_Window	*win;
		C_Text		*text,*text2;
		C_Button	*button;
		RECT		client;

		if(Calibration.state)
		{
			Calibration.state = 0;
			Calibration.disp_text = TRUE;
			//waiting for user to let go of all buttons
			for(int i =0;i < S_joycaps.wNumButtons;i++)
			{
				if(IO.digital[i]) //button pressed
				{
					Calibration.state = 1; 
					break;
				}
			}
		}
		else
		{
			win = gMainHandler->FindWindow(SETUP_WIN);
			control = win->FindControl(JOY_INDICATOR);
			
			text=(C_Text *)win->FindControl(CAL_TEXT);
			text2=(C_Text *)win->FindControl(CAL_TEXT2);

			switch(Calibration.step)
			{
			int i;

			case 0:
			
				if(Calibration.disp_text)
				{
					MonoPrint ("Center the joystick, throttle, and rudder and push a button.\n");
					if(text != NULL)
					{
						text->Refresh();
						text->SetFlagBitOff(C_BIT_INVISIBLE);
						text->SetText(TXT_CTR_JOY);
						text->Refresh();
					}

					if(text2)
					{
						text2->Refresh();
						text2->SetFlagBitOff(C_BIT_INVISIBLE);
						text2->Refresh();
					}

					if(!Calibration.calibrated)
					{
						IO.analog[0].mUp = IO.analog[0].mDown = IO.analog[0].bUp = IO.analog[0].bDown = 0.0F;
						IO.analog[1].mUp = IO.analog[1].mDown = IO.analog[1].bUp = IO.analog[1].bDown = 1.1F;
						IO.analog[2].mUp = IO.analog[2].mDown = IO.analog[2].bUp = IO.analog[2].bDown = 2.2F;
						IO.analog[3].mUp = IO.analog[3].mDown = IO.analog[3].bUp = IO.analog[3].bDown = 3.3F;
					}

					IO.analog[0].min = IO.analog[1].min = IO.analog[2].min = IO.analog[3].min = 65536.0F;
					IO.analog[0].max = IO.analog[1].max = IO.analog[2].max = IO.analog[3].max = 0.0F;

					IO.analog[0].isUsed = IO.analog[1].isUsed = TRUE;

					if (!(S_joycaps.wCaps & JOYCAPS_HASZ))
					{
						IO.analog[2].isUsed = FALSE;
						IO.analog[2].max = 0;
						IO.analog[2].min = -1;
						IO.analog[2].engrValue = 1.0F;
					}
					else
					{
						IO.analog[2].isUsed = TRUE;
					}
					
					if (!(S_joycaps.wCaps & JOYCAPS_HASR))
					{
						IO.analog[3].isUsed= FALSE;
						IO.analog[3].max = 1;
						IO.analog[3].min = -1;
						IO.analog[3].engrValue = 0.0F;
					}
					else
					{
						IO.analog[3].isUsed = TRUE;
					}

					IO.analog[2].center = 32768;

					Calibration.disp_text = FALSE;
				}

				IO.analog[0].center = IO.analog[0].ioVal;
				IO.analog[1].center = IO.analog[1].ioVal;
				IO.analog[3].center = IO.analog[3].ioVal;
				
				for(i =0;i < S_joycaps.wNumButtons;i++)
				{
					if(IO.digital[i])
						Calibration.state = 1;		//button pressed
				}
				
				if(Calibration.state)
					Calibration.step++;

				break;
			
			case 1:

				if(Calibration.disp_text)
				{
					MonoPrint ("Move the joystick to the corners and push a button.\n");
					if(text != NULL)
					{
						text->Refresh();
						text->SetText(TXT_MV_JOY);
						text->Refresh();
					}
					Calibration.disp_text = FALSE;
				}
				
				IO.analog[0].max = max(IO.analog[0].max, IO.analog[0].ioVal);
				IO.analog[1].max = max(IO.analog[1].max, IO.analog[1].ioVal);
				IO.analog[0].min = min(IO.analog[0].min, IO.analog[0].ioVal);
				IO.analog[1].min = min(IO.analog[1].min, IO.analog[1].ioVal);
				
				for(i =0;i < S_joycaps.wNumButtons;i++)
				{
					if(IO.digital[i])
						Calibration.state = 1;		//button pressed
				}

				if(Calibration.state)
					Calibration.step++;

				break;

			case 2:

				if (S_joycaps.wCaps & JOYCAPS_HASZ)
				{
					if(Calibration.disp_text)
					{
						MonoPrint ("Move the throttle to the ends and push a button\n");
						if(text != NULL && IO.analog[2].isUsed)
						{
							text->Refresh();
							text->SetText(TXT_MV_THR);
							text->Refresh();
						}
						Calibration.disp_text = FALSE;
					}
					
					IO.analog[2].max = max(IO.analog[2].max, IO.analog[2].ioVal);
					IO.analog[2].min = min(IO.analog[2].min, IO.analog[2].ioVal);
					
					for(i =0;i < S_joycaps.wNumButtons;i++)
					{
						if(IO.digital[i])
							Calibration.state = 1;		//button pressed
					}

					if(Calibration.state)
						Calibration.step++;
				}
				else
				{
					Calibration.step++;
					Calibration.state = 1;
				}
				break;

			case 3:
				if (S_joycaps.wCaps & JOYCAPS_HASR)
				{
					if(Calibration.disp_text)
					{
						MonoPrint ("Move the rudder to the ends and push a button\n");
						if(text != NULL && IO.analog[3].isUsed)
						{
							text->Refresh();
							text->SetText(TXT_MV_RUD);
							text->Refresh();
						}
						Calibration.disp_text = FALSE;
					}
					
					IO.analog[3].max = max(IO.analog[3].max, IO.analog[3].ioVal);
					IO.analog[3].min = min(IO.analog[3].min, IO.analog[3].ioVal);

					for(int i =0;i < S_joycaps.wNumButtons;i++)
					{
						if(IO.digital[i])
							Calibration.state = 1;		//button pressed
					}

					if(Calibration.state)
						Calibration.step++;
					
				}
				else
				{
					Calibration.step++;
					Calibration.state = 1;
				}
				break;

			case 4:
				for (i=0; i<S_joycaps.wNumAxes; i++)
				{
					if (IO.analog[i].isUsed)
					{
						IO.analog[i].mUp = 1.0F /(IO.analog[i].max - IO.analog[i].center);
						IO.analog[i].bUp = -IO.analog[i].mUp * IO.analog[i].center;
						IO.analog[i].mDown = 1.0F / (IO.analog[i].center - IO.analog[i].min);
						IO.analog[i].bDown = -IO.analog[i].mDown * IO.analog[i].center;
					}
					else
					{
						IO.analog[i].mUp = IO.analog[i].mDown = 0.0F;
						IO.analog[i].bUp = IO.analog[i].bDown = 0.0F;
					}
				}
				
				char filename[_MAX_PATH];
				sprintf(filename,"%s\\config\\joystick.dat",FalconDataDirectory);
				filePtr = fopen (filename, "wb");
				if(filePtr)
				{
					fwrite (&S_joycaps.wNumAxes, sizeof(int), 1, filePtr);
					
					for (i=0; i<S_joycaps.wNumAxes; i++)
					{
						fwrite (&(IO.analog[i]), sizeof(SIMLIB_ANALOG_TYPE), 1, filePtr);
					}
					fclose (filePtr);
				}
				else
				{
					ShiAssert(filePtr == NULL);
				}
				
				button = (C_Button *)win->FindControl(CALIBRATE);
				button->SetState(C_STATE_0);
				button->Refresh();
				
				
				
				if(text != NULL)
				{
					text->Refresh();
					text->SetFlagBitOn(C_BIT_INVISIBLE);
					text->Refresh();
				}

				if(text2)
				{
					text2->Refresh();
					text2->SetFlagBitOn(C_BIT_INVISIBLE);
					text2->Refresh();
				}
					
				client = win->GetClientArea(1);
				
				if(control)
				{
					size = ((C_Bitmap *)control)->GetH();
				}
				
				JoyScale = (float)(client.right - client.left - size)/2.0F;
				RudderScale = (Rudder.bottom - Rudder.top )/2.0F;
				ThrottleScale = (Throttle.bottom - Throttle.top )/2.0F;
				
				Calibration.calibrated = TRUE;
				Calibration.calibrating = FALSE;
				Calibration.step = 0;
				Calibration.state = 1;
			}
		}
		
	}
	else if (S_joyret == MMSYSERR_NODRIVER)
	{
		SimLibPrintError ("MMSYSERR No Driver");
		return SIMLIB_ERR;
	}
	else if (S_joyret == MMSYSERR_INVALPARAM)
	{
		SimLibPrintError ("MMSYSERR Invalid Parameter");
		return SIMLIB_ERR;
	}

	return retval;
}




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

	Calibration.calibrating = 1;
	//Calibrate();
	
}//CalibrateCB

*/

//function assumes you have passed a char * that has enough memory allocated
void DoShiftStates(char *mods, int ShiftStates)
{
	int plus = 0;

	if(ShiftStates & _SHIFT_DOWN_)
	{
		strcat(mods,gStringMgr->GetString(TXT_SHIFT_KEY));
		plus++;
	}

	if(ShiftStates & _CTRL_DOWN_)
	{
		if(plus)
		{
			strcat(mods,"+");
			plus--;
		}
		strcat(mods,gStringMgr->GetString(TXT_CONTROL_KEY));
		plus++;
	}
	
	if(ShiftStates & _ALT_DOWN_)
	{
		if(plus)
		{
			strcat(mods,"+");
			plus--;
		}

		strcat(mods,gStringMgr->GetString(TXT_ALTERNATE_KEY));
		plus++;
	}
	
	if(plus)
		strcat(mods," ");
}


BOOL KeystrokeCB(unsigned char DKScanCode,unsigned char,unsigned char ShiftStates,long)
{
	if(DKScanCode == DIK_ESCAPE)
		return FALSE; 

	if(Cluster == 8004)
	{
		if(	DKScanCode == DIK_LSHIFT	|| DKScanCode == DIK_RSHIFT		|| \
			DKScanCode == DIK_LCONTROL	|| DKScanCode == DIK_RCONTROL	|| \
			DKScanCode == DIK_LMENU		|| DKScanCode == DIK_RMENU		|| \
			DKScanCode == 0x45)
				return TRUE;

		if( GetAsyncKeyState(VK_SHIFT) & 0x8001 )
			ShiftStates |= _SHIFT_DOWN_;
		else
			ShiftStates &= ~_SHIFT_DOWN_;		
		
		//int flags = ShiftStates;
		int flags = ShiftStates + (KeyVar.CommandsKeyCombo << SECOND_KEY_SHIFT) + (KeyVar.CommandsKeyComboMod << SECOND_KEY_MOD_SHIFT);

		C_Window *win;
		int CommandCombo = 0;

		win = gMainHandler->FindWindow(SETUP_WIN);		

		if(KeyVar.EditKey)
		{
			C_Button *button;
			long ID;

			button = (C_Button *)win->FindControl(KeyVar.CurrControl);
			flags = ShiftStates + (button->GetUserNumber(FLAGS) & SECOND_KEY_MASK);
			KeyVar.CommandsKeyCombo = (button->GetUserNumber(FLAGS) & KEY1_MASK) >> SECOND_KEY_SHIFT;
			KeyVar.CommandsKeyComboMod = (button->GetUserNumber(FLAGS) & MOD1_MASK) >> SECOND_KEY_MOD_SHIFT;

			//here is where we need to change the key combo for the function
			if(DKScanCode != button->GetUserNumber(KEY2) || flags != button->GetUserNumber(FLAGS))
			{
				char keydescrip[_MAX_PATH];
				keydescrip[0] = 0;
				int pmouse, pbutton;
				InputFunctionType theFunc;
				InputFunctionType oldFunc;
				theFunc = (InputFunctionType)button->GetUserPtr(FUNCTION_PTR);
				//is the key combo already used?
				if(oldFunc = UserFunctionTable.GetFunction(DKScanCode,flags,&pmouse,&pbutton))
				{
					C_Button *temp;

					ID = UserFunctionTable.GetControl(DKScanCode,flags);
					KeyVar.OldControl = ID;
					

					//there is a function mapped but it's not visible
					//don't allow user to remap this key combo
					if(!ID && oldFunc)
						return TRUE;

					
					temp = (C_Button *)win->FindControl(ID);
					if( temp && (temp->GetUserNumber(EDITABLE) < 1) )
					{
						//this keycombo is not remappable
						return TRUE;
					}
					//remove old function from place user wants to use
					UserFunctionTable.RemoveFunction(DKScanCode,flags);
				}
					
				//remove function that's being remapped from it's old place
				UserFunctionTable.RemoveFunction(button->GetUserNumber(KEY2),button->GetUserNumber(FLAGS));
				
				//add function into it's new place
				UserFunctionTable.AddFunction(DKScanCode,flags,button->GetUserNumber(BUTTON_ID),button->GetUserNumber(MOUSE_SIDE), theFunc);
				UserFunctionTable.SetControl(DKScanCode,flags,KeyVar.CurrControl);

				//mark that the keymapping needs to be saved
				KeyVar.Modified = TRUE;

				//setup button with new values
				button->SetUserNumber(KEY2,DKScanCode);
				button->SetUserNumber(FLAGS,flags);
				
				char mods[40] = {0};
				_TCHAR firstKey[MAX_PATH] = {0};
				_TCHAR totalDescrip[MAX_PATH] = {0};

				if(KeyVar.CommandsKeyCombo > 0)
				{
					DoShiftStates(firstKey,KeyVar.CommandsKeyComboMod);
					DoShiftStates(mods,ShiftStates);
					_stprintf(totalDescrip,"%s%s : %s%s",firstKey,KeyDescrips[KeyVar.CommandsKeyCombo],mods,KeyDescrips[DKScanCode]);
				}
				else
				{
					DoShiftStates(totalDescrip,ShiftStates);
					strcat(totalDescrip,KeyDescrips[DKScanCode]);
				}

				//DoShiftStates(keydescrip,ShiftStates);
				//strcat(keydescrip,KeyDescrips[DKScanCode]);
				
				button->Refresh();
				button->SetText(0,totalDescrip);
				button->Refresh();

				if(KeyVar.OldControl)
				{
					//if we unmapped another function to map this one we 
					//need to update the first functions buttton
					C_Button *temp;

					temp = (C_Button *)win->FindControl(KeyVar.OldControl);
					//strcpy(keydescrip,"No Key Assigned");
					if(temp)
					{
						SetButtonColor(temp);
						temp->SetUserNumber(KEY2,-1);
						temp->SetUserNumber(FLAGS,temp->GetUserNumber(FLAGS) & SECOND_KEY_MASK);
						temp->Refresh();
						temp->SetText(0,TXT_NO_KEY);
						temp->Refresh();
					}
				}
			}
			SetButtonColor(button);
		}

		if(KeyVar.OldControl)
		{
			// if we stole another functions mapping, move to the function
			// and leave ourselves in edit mode
			C_Button *temp;
			UI95_RECT Client;

			temp = (C_Button *)win->FindControl(KeyVar.OldControl);
			if(temp)
			{
				temp->SetFgColor(0,RGB(0,255,255));

				Client = win->GetClientArea(temp->GetClient());

				win->SetVirtualY(temp->GetY()-Client.top,temp->GetClient());
				win->AdjustScrollbar(temp->GetClient()); 
				win->RefreshClient(temp->GetClient());
			}

			KeyVar.CurrControl = KeyVar.OldControl;
			KeyVar.OldControl = 0;
		}
		else
		{
			//key changed leave edit mode
			KeyVar.EditKey = FALSE;
		}

		C_Text	*text;
		
		if(DKScanCode == 0xC5)
			DKScanCode = 0x45;

		//build description for display at bottom of window
		if(KeyDescrips[DKScanCode])
		{
			
			//if(DKScanCode == 0x44)

			char mods[40] = {0};
			char *descrip = NULL;
			int pmouse,pbutton;
			InputFunctionType function;
			
			text = (C_Text *)win->FindControl(CONTROL_KEYS); //CONTROL_KEYS
			if(text)
			{
				_TCHAR firstKey[MAX_PATH] = {0};
				_TCHAR totalDescrip[MAX_PATH] = {0};
				if(KeyVar.CommandsKeyCombo > 0)
				{
					DoShiftStates(firstKey,KeyVar.CommandsKeyComboMod);
					DoShiftStates(mods,ShiftStates);
					_stprintf(totalDescrip,"%s%s : %s%s",firstKey,KeyDescrips[KeyVar.CommandsKeyCombo],mods,KeyDescrips[DKScanCode]);
				}
				else
				{
					DoShiftStates(totalDescrip,ShiftStates);
					strcat(totalDescrip,KeyDescrips[DKScanCode]);
				}
				//DoShiftStates(mods,ShiftStates);
				//strcat(mods,KeyDescrips[DKScanCode]);
				text->Refresh();
				text->SetText(totalDescrip);
				text->Refresh();

⌨️ 快捷键说明

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