Example #1
0
// generic error handler
void error(char* text)
{
	switchgs(GS_NONE);
	deinit();
	DlgMessage(LC_ERROR, text, BT_OK, BT_NONE);
	exit(1);
}
Example #2
0
// drawHiScoreBoard - draws the hiscore board, and updates it with the hiscore from the latest game
void drawHiScoreBoard(unsigned long int newscore) {
	SCORE scores[MAX_HISCORES];
	short int loop, pos = -1;
	char name[10], str[50], *error = "File I/O Error";
	HANDLE dlg;

	// restore interrupt handlers
	OSSetSR(0x0000);

	if (!loadHiScores(scores)) {
		// cannot open hiscore file -- display error
		DlgMessage(error,"Unable to Load HiScore Data",BT_OK,BT_NONE);
		return;
	}

	// check if latest score is a highscore
	for (loop = (MAX_HISCORES - 1); loop >= 0; loop--) {
		if (newscore > scores[loop].score) {
			// new HiScore!!
			pos = loop;
		}
	}

	if (pos != -1) {
		// if we found a new hiscore
		if ((dlg = DialogNewSimple(DLGWIDTH,DLGHEIGHT)) == H_NULL) {
			DlgMessage("Memory Allocation Error","Not Enough Free Memory!",BT_OK,BT_NONE);
		} else {
			DialogAddTitle(dlg,"New Hiscore!",BT_OK,BT_NONE);
			DialogAddRequest(dlg,5,25,"Your Name:",0,9,11);

			sprintf(str,"You earned the #%hd hiscore position!",pos+1);
			DialogAddText(dlg,5,15,str);

			do {
				// truncate name variable
				name[0] = 0;
			} while (DialogDo(dlg,CENTER,CENTER,name,NULL) != KEY_ENTER);

			// free the dialog box memory
			HeapFree(dlg);

			// move the hiscore list down
			if (pos < (MAX_HISCORES - 1)) {
				for (loop = (MAX_HISCORES - 1); loop > pos; loop--) {
					scores[loop].score = scores[loop - 1].score;
					scores[loop].name[0] = 0;
					strcpy(scores[loop].name,scores[loop - 1].name);
				}
			}

			// fill in the new hiscore
			scores[pos].score = newscore;
			scores[pos].name[0] = 0;
			strcpy(scores[pos].name,name);

			if (!saveHiScores(scores)) {
				DlgMessage(error,"Unable to save HiScore Board",BT_OK,BT_NONE);
			}
		}
	}

	// display the hiscore board

	// clear the screen
	ClrScr();

	// draw the screen borders
	drawBorder();

	// draw the game logo
	drawLogo();

	FontSetSys(F_8x10);
	DrawStr(25,35,"Hiscore Board",A_NORMAL);
	FontSetSys(F_6x8);

	for (loop = 0; loop < 5; loop++) {
		printf_xy(20,50+loop*10,"#%hd %-9s %lu",loop+1,scores[loop].name,scores[loop].score);
	}

	ngetchx();

	// disable interrupts
	OSSetSR(0x0700);

	// wait for keypresses to dissipate
	delay(KEYDELAY);
}
Example #3
0
int		Panel::ProcessKey(int Key, unsigned int ControlState) {
	switch (Key) {
		case VK_F3:
			if (ControlState == PKF_SHIFT) {
				return	true;
			}
			break;
		case VK_F4:
			switch (ControlState) {
				case 0:
					DlgShutdown();
					return true;
				case PKF_SHIFT:
					return	true;
			}
			break;
		case VK_F6:
			switch (ControlState) {
				case 0:
					if (DlgConnection()) {
						psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
						psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
					}
					return	true;
				case PKF_SHIFT:
					try {
						m_conn->Open(nullptr);
					} catch (WinError &e) {
						farebox_code(e.code(), e.where().c_str());
					}
					psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
					psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
					return	true;
			}
			break;
		case VK_F7:
			switch (ControlState) {
				case 0:
					AutoUTF cmd = L"mstsc.exe";
					if (!Empty(m_conn->host())) {
						cmd += L" /v:";
						cmd += m_conn->host();
					}
					ExecCMD(cmd);
					return true;
			}
			break;
	}
	if ((ControlState == 0 && (Key == VK_F3 || Key == VK_F5 || Key == VK_F8)) ||
		(ControlState == PKF_SHIFT && (Key == VK_F7 || Key == VK_F8))) {
		FarPnl pInfo(this, FCTL_GETPANELINFO);
		WinTS::iterator m_cur;
		if (pInfo.ItemsNumber() && pInfo.CurrentItem() &&
			(m_cur = std::find(m_ts.begin(), m_ts.end(), pInfo[pInfo.CurrentItem()].FindData.nFileSize)) != m_ts.end()) {
			if (ControlState == 0 && Key == VK_F3) {
				AutoUTF	tmp(TempFile(TempDir()));
				HANDLE	hfile = ::CreateFileW(tmp.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
				if (hfile != INVALID_HANDLE_VALUE) {
					FileWrite(hfile, Info(m_cur));
					::CloseHandle(hfile);
					psi.Viewer(tmp.c_str(), nullptr, 0, 0, -1, -1,
							   VF_DELETEONLYFILEONCLOSE | VF_ENABLE_F6 | VF_DISABLEHISTORY |
							   VF_NONMODAL | VF_IMMEDIATERETURN, CP_AUTODETECT);
				}
				return	true;
			} else if (ControlState == 0 && Key == VK_F5) {
				DlgMessage(m_cur->id());
			} else 	if (ControlState == PKF_SHIFT && Key == VK_F7) {
				WinTSession::ConnectLocal(m_cur->id());
			} else 	if (ControlState == 0 && Key == VK_F8) {
				if (farquestion(GetMsg(txtAreYouSure), GetMsg(txtDisconnectSession)))
					WinTSession::Disconnect(m_cur->id(), m_conn->host());
			} else if (ControlState == PKF_SHIFT && Key == VK_F8) {
				if (farquestion(GetMsg(txtAreYouSure), GetMsg(txtLogoffSession)))
					WinTSession::LogOff(m_cur->id(), m_conn->host());
			}
			psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
			psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
			return	true;
		}
	}
	return	false;
}