LONG CTranscendenceWnd::WMKeyDown (int iVirtKey, DWORD dwKeyData)

//	WMKeyDown
//
//	Handle WM_KEYDOWN

	{
	bool bKeyRepeat = uiIsKeyRepeat(dwKeyData);

	switch (m_State)
		{
		case gsInGame:
			{
			//	If no player, then nothing to do

			if (GetPlayer() == NULL)
				NULL;

			//	Deal with console

			else if (m_bDebugConsole)
				{
				if (iVirtKey == VK_ESCAPE)
					m_bDebugConsole = false;
				else
					m_DebugConsole.OnKeyDown(iVirtKey, dwKeyData);
				}

			//	If we're paused, then check for unpause key

			else if (m_bPaused)
				{
				if ((iVirtKey < 'A' || iVirtKey > 'Z') && iVirtKey != VK_SPACE && iVirtKey != VK_F9)
					{
					m_bPaused = false;
					DisplayMessage(CONSTLIT("Game continues"));
					}

				//	We allow access to the debug console

				else
					{
					CGameKeys::Keys iCommand = m_pTC->GetKeyMap().GetGameCommand(iVirtKey);
					if (iCommand == CGameKeys::keyShowConsole 
							&& m_pTC->GetOptionBoolean(CGameSettings::debugMode)
							&& !g_pUniverse->IsRegistered())
						m_bDebugConsole = !m_bDebugConsole;
					}
				}

			//	Handle menu, if it is up

			else if (m_CurrentMenu != menuNone)
				{
				if (iVirtKey == VK_ESCAPE)
					m_CurrentMenu = menuNone;
				else
					{
					CGameKeys::Keys iCommand = m_pTC->GetKeyMap().GetGameCommand(iVirtKey);
					if ((iCommand == CGameKeys::keyInvokePower && m_CurrentMenu == menuInvoke)
							|| (iCommand == CGameKeys::keyCommunications && m_CurrentMenu == menuCommsTarget))
						m_CurrentMenu = menuNone;
					}
				}

			//	Handle picker

			else if (m_CurrentPicker != pickNone)
				{
				if (iVirtKey == VK_RETURN)
					{
					switch (m_CurrentPicker)
						{
						case pickUsableItem:
							DoUseItemCommand(m_MenuData.GetItemData(m_PickerDisplay.GetSelection()));
							break;

						case pickEnableDisableItem:
							GetPlayer()->SetUIMessageEnabled(uimsgEnableDeviceHint, false);
							DoEnableDisableItemCommand(m_MenuData.GetItemData(m_PickerDisplay.GetSelection()));
							break;
						}
					}
				else if (iVirtKey == VK_LEFT)
					m_PickerDisplay.SelectPrev();

				else if (iVirtKey == VK_RIGHT)
					m_PickerDisplay.SelectNext();

				else if (iVirtKey == VK_ESCAPE)
					m_CurrentPicker = pickNone;

				else
					{
					CGameKeys::Keys iCommand = m_pTC->GetKeyMap().GetGameCommand(iVirtKey);
					if ((iCommand == CGameKeys::keyEnableDevice && m_CurrentPicker == pickEnableDisableItem)
							|| (iCommand == CGameKeys::keyUseItem && m_CurrentPicker == pickUsableItem))
						m_CurrentPicker = pickNone;
					}
				}

			//	Otherwise we're in normal game mode

			else
				{
				//	If showing the map, then we need to handle some keys

				if (m_bShowingMap)
					{
					switch (iVirtKey)
						{
						case 'H':
							GetPlayer()->SetMapHUD(!GetPlayer()->IsMapHUDActive());
							break;

						case VK_SUBTRACT:
						case VK_OEM_MINUS:
							if (m_iMapScale < (MAP_SCALE_COUNT - 1))
								{
								m_iMapScale++;
								m_iMapZoomEffect = 100;
								}
							break;

						case VK_ADD:
						case VK_OEM_PLUS:
							if (m_iMapScale > 0)
								{
								m_iMapScale--;
								m_iMapZoomEffect = -100;
								}
							break;
						}

					//	Fall through because normal commands are available with the map
					}

				//	See if this is a command

				CGameKeys::Keys iCommand = m_pTC->GetKeyMap().GetGameCommand(iVirtKey);
				switch (iCommand)
					{
					case CGameKeys::keyAutopilot:
						Autopilot(!m_bAutopilot);
						GetPlayer()->SetUIMessageEnabled(uimsgAutopilotHint, false);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyEnableDevice:
						if (!GetPlayer()->DockingInProgress() 
								&& !GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							ShowEnableDisablePicker();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyCommunications:
						if (!GetPlayer()->DockingInProgress()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetUIMessageEnabled(uimsgCommsHint, false);
							ShowCommsTargetMenu();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyDock:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped()
								&& !bKeyRepeat)
							{
							Autopilot(false);
							GetPlayer()->Dock();
							m_bDockKeyDown = true;
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyTargetNextFriendly:
						GetPlayer()->SelectNextFriendly(1);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyTargetPrevFriendly:
						GetPlayer()->SelectNextFriendly(-1);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyEnterGate:
						if (!GetPlayer()->DockingInProgress()
								&& !GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->Gate();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyInvokePower:
						if (!GetPlayer()->DockingInProgress()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							ShowInvokeMenu();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyShowMap:
						if (m_bShowingMap)
							Autopilot(false);
						m_bShowingMap = !m_bShowingMap;
						GetPlayer()->SetUIMessageEnabled(uimsgMapHint, false);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyShowGalacticMap:
						g_pHI->HICommand(CONSTLIT("uiShowGalacticMap"));
						GetPlayer()->SetUIMessageEnabled(uimsgGalacticMapHint, false);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyPause:
						{
						m_bPaused = true;
						if (GetPlayer())
							{
							GetPlayer()->SetThrust(false);
							GetPlayer()->SetManeuver(IShipController::NoRotation);
							GetPlayer()->SetFireMain(false);
							GetPlayer()->SetFireMissile(false);
							}
						DisplayMessage(CONSTLIT("Game paused"));
						m_chKeyDown = iVirtKey;
						break;
						}

					case CGameKeys::keySquadronCommands:
						if (!GetPlayer()->DockingInProgress()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							ShowCommsSquadronMenu();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyClearTarget:
						GetPlayer()->SetTarget(NULL);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyShipStatus:
						if (!GetPlayer()->DockingInProgress())
							GetModel().ShowShipScreen();
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyTargetNextEnemy:
						GetPlayer()->SelectNextTarget(1);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyTargetPrevEnemy:
						GetPlayer()->SelectNextTarget(-1);
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyUseItem:
						if (!GetPlayer()->DockingInProgress()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							ShowUsePicker();
							}
						m_chKeyDown = iVirtKey;
						break;

					case CGameKeys::keyNextWeapon:
						if (GetPlayer() && !m_bNextWeaponKey)
							{
							Autopilot(false);
							GetPlayer()->SetFireMain(false);
							GetPlayer()->ReadyNextWeapon(1);
							UpdateWeaponStatus();
							m_chKeyDown = iVirtKey;
							m_bNextWeaponKey = true;
							}
						break;

					case CGameKeys::keyPrevWeapon:
						if (GetPlayer() && !m_bPrevWeaponKey)
							{
							Autopilot(false);
							GetPlayer()->SetFireMain(false);
							GetPlayer()->ReadyNextWeapon(-1);
							UpdateWeaponStatus();
							m_chKeyDown = iVirtKey;
							m_bPrevWeaponKey = true;
							}
						break;

					case CGameKeys::keyThrustForward:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetThrust(true);
							}
						break;

					case CGameKeys::keyRotateLeft:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetManeuver(IShipController::RotateLeft);
							}
						break;

					case CGameKeys::keyRotateRight:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetManeuver(IShipController::RotateRight);
							}
						break;

					case CGameKeys::keyStop:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetStopThrust(true);
							}
						break;

					case CGameKeys::keyFireWeapon:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetFireMain(true);
							}
						break;

					case CGameKeys::keyFireMissile:
						if (!GetPlayer()->GetShip()->IsOutOfFuel()
								&& !GetPlayer()->GetShip()->IsTimeStopped())
							{
							Autopilot(false);
							GetPlayer()->SetFireMissile(true);
							GetPlayer()->SetUIMessageEnabled(uimsgFireMissileHint, false);
							}
						break;

					case CGameKeys::keyNextMissile:
						if (!m_bNextMissileKey)
							{
							Autopilot(false);
							GetPlayer()->ReadyNextMissile(1);
							UpdateWeaponStatus();
							GetPlayer()->SetUIMessageEnabled(uimsgSwitchMissileHint, false);
							m_bNextMissileKey = true;
							}
						break;

					case CGameKeys::keyPrevMissile:
						if (!m_bPrevMissileKey)
							{
							Autopilot(false);
							GetPlayer()->ReadyNextMissile(-1);
							UpdateWeaponStatus();
							GetPlayer()->SetUIMessageEnabled(uimsgSwitchMissileHint, false);
							m_bPrevMissileKey = true;
							}
						break;

					case CGameKeys::keyShowHelp:
						g_pHI->HICommand(CONSTLIT("uiShowHelp"));
						break;

					case CGameKeys::keyShowGameStats:
						g_pHI->HICommand(CONSTLIT("uiShowGameStats"));
						break;

					case CGameKeys::keyVolumeDown:
						{
						int iVolume = GetSoundVolumeOption();
						if (--iVolume >= 0)
							{
							SetSoundVolumeOption(iVolume);
							DisplayMessage(strPatternSubst(CONSTLIT("Volume %d"), iVolume));
							}
						break;
						}

					case CGameKeys::keyVolumeUp:
						{
						int iVolume = GetSoundVolumeOption();
						if (++iVolume <= 10)
							{
							SetSoundVolumeOption(iVolume);
							DisplayMessage(strPatternSubst(CONSTLIT("Volume %d"), iVolume));
							}
						break;
						}

					case CGameKeys::keyShowConsole:
						{
						if (m_pTC->GetOptionBoolean(CGameSettings::debugMode)
								&& !g_pUniverse->IsRegistered())
							m_bDebugConsole = !m_bDebugConsole;
						break;
						}

					case CGameKeys::keyEnableAllDevices:
						if (!GetPlayer()->GetShip()->IsTimeStopped())
							{
							GetPlayer()->SetUIMessageEnabled(uimsgEnableDeviceHint, false);
							GetPlayer()->EnableAllDevices(true);
							}
						break;

					case CGameKeys::keyDisableAllDevices:
						if (!GetPlayer()->GetShip()->IsTimeStopped())
							{
							GetPlayer()->SetUIMessageEnabled(uimsgEnableDeviceHint, false);
							GetPlayer()->EnableAllDevices(false);
							}
						break;

					case CGameKeys::keyEnableAllDevicesToggle:
						if (!GetPlayer()->GetShip()->IsTimeStopped())
							{
							GetPlayer()->SetUIMessageEnabled(uimsgEnableDeviceHint, false);
							GetPlayer()->EnableAllDevices(!GetPlayer()->AreAllDevicesEnabled());
							}
						break;

					default:
						{
						if (iCommand >= CGameKeys::keyEnableDeviceToggle00 
								&& iCommand <= CGameKeys::keyEnableDeviceToggle31)
							{
							if (!GetPlayer()->GetShip()->IsTimeStopped())
								{
								int iDevice = (iCommand - CGameKeys::keyEnableDeviceToggle00);

								GetPlayer()->SetUIMessageEnabled(uimsgEnableDeviceHint, false);
								GetPlayer()->ToggleEnableDevice(iDevice);
								}
							}
						else if (iVirtKey == VK_ESCAPE)
							{
							if (m_bShowingMap)
								m_bShowingMap = false;
							else if (m_bAutopilot)
								Autopilot(false);
							else
								ShowGameMenu();
							}
						break;
						}
					}
				}
			break;
			}

		case gsIntro:
			OnKeyDownIntro(iVirtKey, dwKeyData);
			break;

		case gsProlog:
			m_bContinue = true;
			break;

		case gsDocked:
			{
			//	Deal with console

			if (m_bDebugConsole)
				{
				if (iVirtKey == VK_ESCAPE)
					m_bDebugConsole = false;
				else
					m_DebugConsole.OnKeyDown(iVirtKey, dwKeyData);
				}

			//	Other commands

			else
				{
				CGameKeys::Keys iCommand = m_pTC->GetKeyMap().GetGameCommand(iVirtKey);
				switch (iCommand)
					{
					case CGameKeys::keyShowConsole:
						{
						if (m_pTC->GetOptionBoolean(CGameSettings::debugMode)
								&& !g_pUniverse->IsRegistered())
							m_bDebugConsole = !m_bDebugConsole;
						break;
						}

					default:
						switch (iVirtKey)
							{
							case VK_F1:
								g_pHI->HICommand(CONSTLIT("uiShowHelp"));
								break;

							case VK_F2:
								g_pHI->HICommand(CONSTLIT("uiShowGameStats"));
								break;

							default:
								{
								//	Let the dock screen handle it.

								m_CurrentDock.HandleKeyDown(iVirtKey);
								}
							}
						break;
					}
				}

			break;
			}
		}

	return 0;
	}
Example #2
0
__myevic__ void DrawScreen()
{
	if ( Screen == 2 && FireDuration && FireDuration != CurrentFD )
	{
		CurrentFD = FireDuration;
		ScreenDuration = 1;
		ShowFDTimer = 0;
		gFlags.refresh_display = 1;
	}

	if ( gFlags.refresh_display )
	{
		gFlags.refresh_display = 0;
		ClearScreenBuffer();

		switch ( Screen )
		{
			case  0: // Black
				break;

			case  1: // Main view
			case  3: // Main view (?)
			case  4: // (unused?)
				ShowMainView();
				break;

			case  2: // Firing
				if ( !dfStealthOn )
				{
					ShowMainView();
				}
				break;

			case  5: // Black w/ Battery
				ShowBatCharging();
				break;

			case 20: // No Atomizer Found
				ShowNoAtoFound();
				break;

			case 21: // Atomizer Short
				ShowAtoShort();
				break;

				case 22: // Atomizer Low
				ShowAtoLow();
				break;

			case 23: // 10s Protection
				Show10sProtec();
				break;

			case 24: // Battery Low
				ShowBatLow();
				break;

			case 25: // Battery Low Lock
				ShowBatLowLock();
				break;

			case 28: // Key Lock
				ShowKeyLock();
				break;

			case 29: // Device too hot
				ShowDevTooHot();
				break;

			case 31: // Key UnLock
				ShowKeyUnLock();
				break;

			case 37: // Board Temp
				ShowBoardTemp();
				break;

			case 40: // Stealth ON/OFF
				ShowStealthMode();
				break;

			case 41: // Ti ON/OFF
				ShowTiOnOff();
				break;

			case 50: // FW Version
				ShowVersion();
				break;

			case 51: // New Coil
				ShowNewCoil();
				break;

			case 54: // Battery Voltage
				ShowBattVolts();
				break;

			case 59: // TCR Set Menu
				ShowTCRSet();
				break;

			case 82: // LOGO Menu
				ShowLOGOMenu();
				break;

			case 83: // Game Menu
				ShowGameMenu();
				break;

			case 100:
				ShowInfos();
				break;

			case 101:
				ShowContrast();
				break;

			case 102:
				ShowMenus();
				break;

			case 103:
				ShowRTCSpeed();
				break;

			case 104:
				ShowRTCAdjust();
				break;

			default:
				break;
		}

		if ( myDbgFlag & 1 )
		{
			int nd = (Screen<100?Screen<10?1:2:3);
			DrawValue( 64-6*nd, 120, Screen, 0, 0x01, nd );
			DrawValue( 0, 120, ScreenDuration, 0, 0x01, 0 );
		}
		
		DisplayRefresh();
	}

	if (( gFlags.firing ) && ISMODETC(dfMode))
	{
		ShowFDTimer += 5;
	}
	else
	{
		ShowFDTimer += 1;
	}

	if ( ShowFDTimer < 10 )
		return;

	ShowFDTimer = 0;

	if ( ScreenDuration && --ScreenDuration )
		return;

	switch ( Screen )
	{
		case   0: // Black
			if ( dfStatus.off )
			{
				SleepTimer = 0;
			}
			break;

		case   2: // Firing
			if ( dfStealthOn )
			{
				gFlags.refresh_display = 1;
				if ( !(gFlags.battery_charging) )
				{
					Screen = 0;
					SleepTimer = 18000;
				}
				else
				{
					Screen = 5;
				}
			}
			else
			{
				MainView();
			}
			break;

		case   5: // Black w/ Battery
			break;

		case  20: // No Atomizer Found
		case  21: // Atomizer Short
			MainView();
			break;

		case  22: // Atomizer Low
		case  23: // 10s Protection
		case  24: // Battery Low
		case  25: // Battery Low Lock
			break;

		case  29: // Device too hot
			MainView();
			break;

		case 101: // Contrast Menu
		case 102: // Menus
		case 103: // RTC Speed
			gFlags.edit_capture_evt = 0;
			// NOBREAK
		case  59: // TCR Set Menu
		case  82: // LOGO Menu
		case  83: // Game Menu
			UpdateDataFlash();
			// NOBREAK
		case   1: // Main view
		case  28: // Key Lock
		case  31: // Key UnLock
		case  37: // Board Temp
		case  40: // Stealth ON/OFF
		case  41: // Ti ON/OFF
		case  54: // Battery Voltage
		case 100: // Ferox's page
		case 104: // Adjust Clock
			if ( !dfScreenSave )
			{
				if ( Screen != 1 )
					MainView();
				break;
			}
			if ( !(gFlags.battery_charging) )
			{
				gFlags.refresh_display = 1;
				Screen = 0;
				SleepTimer = 18000;
			}
			else
			{
				Screen = 5;
			}
			break;

		case  50: // FW Version
			break;

		case  51: // New Coil
			MainView();
			break;

		default:
			break;
	}

	return;
}