Example #1
0
/*--------------------------------------------------------------------------------------------------------------------------
--FUNCTION:		WndProcMain
--
--DATE :		Sep 26, 2015
--
--REVISIONS :	Sep 26, 2015     - actions after connecting port.
--				Oct 20, 2015		- added edit box, added listener for window resize
--				Jan 18, 2016	- add font for textbox
--
--DESIGNER :	 Eunwon Moon
--
--PROGRAMMER :	 Eunwon Moon
--
--INTERFACE : LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
--					HWND hwnd     : a handle to the winmain window procedure which received the message.
--					UNIT Message  : the received control message which is generated by user action.
--					WPARAM wParam : tha additional message information de
--					LPARAM lParam : the additional message information  
--
--RETURNS : LRESULT
--
--NOTES :
-- Call this functions depending on users action after connecting. initialize dialog information
-- and detect menu item use or event which is set using WSAAsycSelect.
--
----------------------------------------------------------------------------------------------------------------------*/
INT_PTR CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{


	switch (Message)
	{

		case WM_INITDIALOG:
			dialogInit(hwnd);
			
			return TRUE;
		
		case WM_COMMAND:
			menuAction(hwnd, wParam);
			break;
		case WM_TCPSERV:
		case WM_UDPSERV:
		case WM_TCPSERVCONN:
			ServWinProc(hwnd, Message, wParam, lParam, &server_sock);
			break;
		case WM_TCPCLENT:
		case WM_UDPCLENT:
			ClientProc(hwnd, Message, wParam, lParam, &client_sock);
			break;

			// Terminate program
		case WM_DESTROY:
			PostQuitMessage(0);
			shutdown(op_type == SERVER ? server_sock : client_sock, SD_BOTH);
			closesocket(op_type == CLIENT ? server_sock : client_sock);

			WSACleanup();
			break;

		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
			break;
	}
	return 0;
}
Example #2
0
dialog buildtileinfodialog_id(ZZTworld * w, int x, int y, ZZTtile tile)
{
	dialog dia;
	char buf[256];
	
	dialogComponent label = dialogComponentMake(DIALOG_COMP_LABEL,  0, 1, LABEL_COLOR,  NULL, ID_NONE);
	dialogComponent option = dialogComponentMake(DIALOG_COMP_OPTION, 13, 1, OPTION_COLOR, NULL, ID_NONE);

	/* Also use _addlabel() and _addoption() from buildparamdialog() */
#define _addvalue(TEXT)      { option.text  = (TEXT); option.type = DIALOG_COMP_LABEL; dialogAddComponent(&dia, option); option.y++; option.type = DIALOG_COMP_OPTION; }

	/* Initialize the dialog */
	dialogInit(&dia);

	/* Generate the title */
	dialogAddComponent(&dia, dialogComponentMake(DIALOG_COMP_TITLE, 0, 0, 0x0F, (char *) zztTileGetName(tile), ID_NONE));

	/* Common information to all types */
	_addlabel("ZZT-OOP Kind");
	_addlabel("Id Number");
	_addlabel("Color");
	_addlabel("Coordinate");

	_addoption((char *) zztTileGetKind(tile), ID_KIND);

	sprintf(buf, "%d, %02Xh", tile.type, tile.type);
	_addoption(buf, ID_TILEID);

	_addoption(colorname(buf, tile.color), ID_COLOR);

	sprintf(buf, "(%d, %d)", x + 1, y + 1);
	_addvalue(buf);

	/* Advance option position */
	option.y += 2; option.x = 0;

	/* Stats vs. No Stats */
	if (tile.param == NULL) {
		dialogAddComponent(&dia, dialogComponentMake(DIALOG_COMP_HEADING, 0, option.y - 1, 0x0F, "No Stats", ID_NONE));
		_addoption("Add Stats", ID_ADDPARAM);
	} else {
		ZZTtile under = { 0, 0, NULL};

		dialogAddComponent(&dia, dialogComponentMake(DIALOG_COMP_HEADING, 0, option.y - 1, 0x0F, "Stats", ID_NONE));
		_addoption("Edit Stats", ID_EDITPARAM);
		_addoption("Remove Stats", ID_RMPARAM);

		/* Advance the label/value templates */
		option.y++; option.x = 13;
		label.y = option.y;

		/* Stat index */
		_addlabel("Stat Index");
		sprintf(buf, "%d", tile.param->index);
		_addoption(buf, ID_NONE);

		/* Tile under info */
		under.type = tile.param->utype;
		under.color = tile.param->ucolor;

		_addlabel("Under Type");
		_addlabel("Under Color");

		sprintf(buf, "%d, %02X: %s", under.type, under.type, zztTileGetName(under));
		_addoption(buf, ID_UTYPE);
		_addoption(colorname(buf, under.color), ID_UCOLOR);

		if (tile.param->program != NULL) {
			int i, instr = tile.param->instruction, plen = tile.param->length;

			_addlabel("Code Length");
			_addlabel("Current Code");

			sprintf(buf, "%d", plen);
			_addvalue(buf);

			for (i = 0; instr + i < plen && tile.param->program[instr + i] != '\r' && i < 255; i++)
				buf[i] = tile.param->program[instr + i];
			buf[i] = '\x0';

			if ((int16_t) instr == -1)
				strcpy(buf, "(Program Execution #end-ed)");

			_addvalue(buf);
		}
	}

	return dia;
}
Example #3
0
dialog buildparamdialog_id(ZZTworld * w, ZZTtile tile)
{
	u_int8_t properties = zztParamGetProperties(tile);
	dialog dia;

	int i;
	char buffer[100];

	dialogComponent label  = dialogComponentMake(DIALOG_COMP_LABEL,   0, 1, LABEL_COLOR,  NULL, ID_NONE);
	dialogComponent option = dialogComponentMake(DIALOG_COMP_OPTION, 20, 1, OPTION_COLOR, NULL, ID_NONE);

	/* Handy macros for using template label & option */
#define _addlabel(TEXT)      { label.text  = (TEXT); dialogAddComponent(&dia, label); label.y++; }
#define _addoption(TEXT, ID) { option.text = (TEXT); option.id = (ID); dialogAddComponent(&dia, option); option.y++; }

	/* Initialize the dialog */
	dialogInit(&dia);

	/* Generate the title */
	dialogAddComponent(&dia, dialogComponentMake(DIALOG_COMP_TITLE, 0, 0, 0x0F, (char *) zztTileGetName(tile), ID_NONE));


	/* Add "edit program" option */
	// force program --GM
	//if (properties & ZZT_PROPERTY_PROGRAM) {
		_addlabel(tile.type == ZZT_OBJECT ? "Program" : "Text");
		_addoption("Edit", ID_PROGRAM);
	//}

	/* Direction option */
	if (properties & ZZT_PROPERTY_STEP) {
		_addlabel("Direction");
		_addoption((char *) direction_table[getdirection(tile.param->xstep, tile.param->ystep)], ID_DIRECTION);
	}

	for (i = 0; i < 3; i++) {
		int datause = zztParamDatauseGet(tile, i);
		if (datause == ZZT_DATAUSE_FIRERATEMODE) {
			/* Confounded special case */

			int rate = tile.param->data[i];
			/* Remove the projectile-type component for printing */
			if (rate > 128) rate -= 128;
			_addlabel("Firing Rate");
			sprintf(buffer, "%d", rate);
			_addoption(buffer, ID_FIRERATE);

			_addlabel("Projectile");
			_addoption(tile.param->data[i] < 128 ? "Bullets" : "Throwstars", ID_PROJECTILE);
		} else if (datause != ZZT_DATAUSE_NONE) {
			char * usename = (char *) zztParamDatauseGetName(tile, i);
			_addlabel(usename);
			paramdatavaluestring(buffer, tile, i, w);
			_addoption(buffer, zztParamDatauseGet(tile, i));
		}
	}

	if (properties & ZZT_PROPERTY_CYCLE) {
		/* Add a blank line before cycle if not the first item */
		if (label.y > 1) { label.y++; option.y++; }

		_addlabel("Cycle");
		sprintf(buffer, "%d", tile.param->cycle);
		_addoption(buffer, ID_CYCLE);
	}

	/* Advanced configuration */
	//label.y = option.y += 2;
	//label.x = 0; option.x = 8;

	//dialogAddComponent(&dia, dialogComponentMake(DIALOG_COMP_HEADING, 0, label.y - 1, 0x0F, "Advanced Tweaking", ID_NONE));
	
	/* If cycle is not a normal property, add it as an advanced tweak */
	if (!(properties & ZZT_PROPERTY_CYCLE)) {
		_addlabel("Cycle");
		sprintf(buffer, "%d", tile.param->cycle);
		_addoption(buffer, ID_CYCLE);
		label.y++; option.y++;
	}

	_addlabel("X Step");
	_addlabel("Y Step");
	_addlabel("X Pos");
	_addlabel("Y Pos");
	_addlabel("Data 1");
	_addlabel("Data 2");
	_addlabel("Data 3");

	sprintf(buffer, "%d", (char) tile.param->xstep); _addoption(buffer, ID_XSTEP);
	sprintf(buffer, "%d", (char) tile.param->ystep); _addoption(buffer, ID_YSTEP);
	sprintf(buffer, "%d", (char) tile.param->x); _addoption(buffer, ID_XPOS);
	sprintf(buffer, "%d", (char) tile.param->y); _addoption(buffer, ID_YPOS);
	sprintf(buffer, "%d", tile.param->data[0]); _addoption(buffer, ID_DATA0);
	sprintf(buffer, "%d", tile.param->data[1]); _addoption(buffer, ID_DATA1);
	sprintf(buffer, "%d", tile.param->data[2]); _addoption(buffer, ID_DATA2);

	// force program --GM
	if (/*properties & ZZT_PROPERTY_PROGRAM ||*/ tile.param->length != 0 || tile.param->bindindex != 0) {
		char * bindname;
		if (tile.param->bindindex != 0)
			bindname = buildparamdescription(zztBoardGetBlock(w), tile.param->bindindex);
		else
			bindname = str_dup("(none)");

		_addlabel("Bind to");
		_addoption(bindname, ID_BIND);
		free(bindname);

		option.x = 20;
		_addlabel("Program Instruction");
		sprintf(buffer, "%d", (int16_t) tile.param->instruction); _addoption(buffer, ID_INSTRUCTION);
	}

	if (properties & ZZT_PROPERTY_LEADER) {
		/* Edit follower/leader values */
		char * name;

		label.y++; option.y++;
		option.x++;

		/* Add the leader */
		if (tile.param->leaderindex != 0xFFFF)
			name = buildparamdescription(zztBoardGetBlock(w), tile.param->leaderindex);
		else
			name = str_dup("(none)");
		
		_addlabel("Leader");
		_addoption(name, ID_LEADER);

		free(name);

		/* Add the follower */
		if (tile.param->followerindex != 0xFFFF)
			name = buildparamdescription(zztBoardGetBlock(w), tile.param->followerindex);
		else
			name = str_dup("(none)");
		
		_addlabel("Follower");
		_addoption(name, ID_FOLLOWER);

		free(name);
	}

	return dia;
}