network_gui.c
branch0.4
changeset 10036 1b119438cefb
parent 10016 7f1dc0e2e0f5
child 10068 0d713ced91d5
equal deleted inserted replaced
10035:23985f53225c 10036:1b119438cefb
    12 #ifdef ENABLE_NETWORK
    12 #ifdef ENABLE_NETWORK
    13 
    13 
    14 #include "table/strings.h"
    14 #include "table/strings.h"
    15 #include "functions.h"
    15 #include "functions.h"
    16 #include "network_data.h"
    16 #include "network_data.h"
       
    17 #include "network_client.h"
    17 #include "network_gamelist.h"
    18 #include "network_gamelist.h"
    18 #include "window.h"
    19 #include "window.h"
    19 #include "gui.h"
    20 #include "gui.h"
    20 #include "gfx.h"
    21 #include "gfx.h"
    21 #include "command.h"
    22 #include "command.h"
  1462 	_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
  1463 	_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
  1463 	AllocateWindowDesc(&_network_join_status_window_desc);
  1464 	AllocateWindowDesc(&_network_join_status_window_desc);
  1464 }
  1465 }
  1465 
  1466 
  1466 
  1467 
       
  1468 static byte _chat_type;
       
  1469 static byte _chat_dest;
       
  1470 
       
  1471 
       
  1472 static void SendChat(const char* buf)
       
  1473 {
       
  1474 	if (buf[0] == '\0') return;
       
  1475 	if (!_network_server) {
       
  1476 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + _chat_type, _chat_type, _chat_dest, buf);
       
  1477 	} else {
       
  1478 		NetworkServer_HandleChat(NETWORK_ACTION_CHAT + _chat_type, _chat_type, _chat_dest, buf, NETWORK_SERVER_INDEX);
       
  1479 	}
       
  1480 }
       
  1481 
       
  1482 
  1467 /* uses querystr_d WP macro */
  1483 /* uses querystr_d WP macro */
  1468 static void ChatWindowWndProc(Window *w, WindowEvent *e)
  1484 static void ChatWindowWndProc(Window *w, WindowEvent *e)
  1469 {
  1485 {
  1470 	switch (e->event) {
  1486 	switch (e->event) {
  1471 	case WE_CREATE:
  1487 	case WE_CREATE:
  1478 		DrawEditBox(w, &WP(w, querystr_d), 1);
  1494 		DrawEditBox(w, &WP(w, querystr_d), 1);
  1479 		break;
  1495 		break;
  1480 
  1496 
  1481 	case WE_CLICK:
  1497 	case WE_CLICK:
  1482 		switch (e->click.widget) {
  1498 		switch (e->click.widget) {
  1483 		case 3: DeleteWindow(w); break; // Cancel
  1499 			case 2: /* Send */ SendChat(WP(w, querystr_d).text.buf); /* FALLTHROUGH */
  1484 		case 2: // Send
  1500 			case 3: /* Cancel */ DeleteWindow(w); break;
  1485 press_ok:;
  1501 		}
  1486 			if (WP(w, querystr_d).text.buf[0] == '\0') {
  1502 		break;
  1487 				DeleteWindow(w);
  1503 
  1488 			} else {
  1504 	case WE_MOUSELOOP:
  1489 				char *buf = WP(w, querystr_d).text.buf;
       
  1490 				WindowClass wnd_class = WP(w, querystr_d).wnd_class;
       
  1491 				WindowNumber wnd_num = WP(w, querystr_d).wnd_num;
       
  1492 				Window *parent;
       
  1493 
       
  1494 				DeleteWindow(w);
       
  1495 
       
  1496 				parent = FindWindowById(wnd_class, wnd_num);
       
  1497 				if (parent != NULL) {
       
  1498 					WindowEvent e;
       
  1499 					e.event = WE_ON_EDIT_TEXT;
       
  1500 					e.edittext.str = buf;
       
  1501 					parent->wndproc(parent, &e);
       
  1502 				}
       
  1503 			}
       
  1504 			break;
       
  1505 		}
       
  1506 		break;
       
  1507 
       
  1508 	case WE_MOUSELOOP: {
       
  1509 		if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) {
       
  1510 			DeleteWindow(w);
       
  1511 			return;
       
  1512 		}
       
  1513 		HandleEditBox(w, &WP(w, querystr_d), 1);
  1505 		HandleEditBox(w, &WP(w, querystr_d), 1);
  1514 	} break;
  1506 		break;
  1515 
  1507 
  1516 	case WE_KEYPRESS: {
  1508 	case WE_KEYPRESS:
  1517 		switch (HandleEditBoxKey(w, &WP(w, querystr_d), 1, e)) {
  1509 		switch (HandleEditBoxKey(w, &WP(w, querystr_d), 1, e)) {
  1518 		case 1: // Return
  1510 			case 1: /* Return */ SendChat(WP(w, querystr_d).text.buf); /* FALLTHROUGH */
  1519 			goto press_ok;
  1511 			case 2: /* Escape */ DeleteWindow(w); break;
  1520 		case 2: // Escape
  1512 		}
  1521 			DeleteWindow(w);
  1513 		break;
  1522 			break;
       
  1523 		}
       
  1524 	} break;
       
  1525 
  1514 
  1526 	case WE_DESTROY:
  1515 	case WE_DESTROY:
  1527 		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
  1516 		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
  1528 		CLRBIT(_no_scroll, SCROLL_CHAT);
  1517 		CLRBIT(_no_scroll, SCROLL_CHAT);
  1529 		break;
  1518 		break;
  1544 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
  1533 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
  1545 	_chat_window_widgets,
  1534 	_chat_window_widgets,
  1546 	ChatWindowWndProc
  1535 	ChatWindowWndProc
  1547 };
  1536 };
  1548 
  1537 
  1549 void ShowChatWindow(void)
  1538 
       
  1539 void ShowNetworkChatQueryWindow(byte desttype, byte dest)
  1550 {
  1540 {
  1551 	Window *w;
  1541 	Window *w;
       
  1542 
       
  1543 	_chat_type = desttype;
       
  1544 	_chat_dest = dest;
  1552 
  1545 
  1553 	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
  1546 	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
  1554 
  1547 
  1555 	_edit_str_buf[0] = '\0';
  1548 	_edit_str_buf[0] = '\0';
  1556 
  1549