1467 w = AllocateWindowDesc(&_network_join_status_window_desc); |
1467 w = AllocateWindowDesc(&_network_join_status_window_desc); |
1468 /* Parent the status window to the lobby */ |
1468 /* Parent the status window to the lobby */ |
1469 if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0); |
1469 if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0); |
1470 } |
1470 } |
1471 |
1471 |
1472 static void SendChat(const char *buf, DestType type, byte dest) |
1472 static void SendChat(const char *buf, DestType type, int dest) |
1473 { |
1473 { |
1474 if (buf[0] == '\0') return; |
1474 if (buf[0] == '\0') return; |
1475 if (!_network_server) { |
1475 if (!_network_server) { |
1476 SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf); |
1476 SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf); |
1477 } else { |
1477 } else { |
1531 * See if we can auto-complete the current text of the user. |
1531 * See if we can auto-complete the current text of the user. |
1532 */ |
1532 */ |
1533 static void ChatTabCompletion(Window *w) |
1533 static void ChatTabCompletion(Window *w) |
1534 { |
1534 { |
1535 static char _chat_tab_completion_buf[lengthof(_edit_str_buf)]; |
1535 static char _chat_tab_completion_buf[lengthof(_edit_str_buf)]; |
1536 Textbuf *tb = &WP(w, querystr_d).text; |
1536 Textbuf *tb = &WP(w, chatquerystr_d).text; |
1537 uint len, tb_len; |
1537 uint len, tb_len; |
1538 uint item; |
1538 uint item; |
1539 char *tb_buf, *pre_buf; |
1539 char *tb_buf, *pre_buf; |
1540 const char *cur_name; |
1540 const char *cur_name; |
1541 bool second_scan = false; |
1541 bool second_scan = false; |
1603 /* We walked all posibilities, and the user presses tab again.. revert to original text */ |
1603 /* We walked all posibilities, and the user presses tab again.. revert to original text */ |
1604 strcpy(tb->buf, _chat_tab_completion_buf); |
1604 strcpy(tb->buf, _chat_tab_completion_buf); |
1605 _chat_tab_completion_active = false; |
1605 _chat_tab_completion_active = false; |
1606 |
1606 |
1607 /* Update the textbuffer */ |
1607 /* Update the textbuffer */ |
1608 UpdateTextBufferSize(&WP(w, querystr_d).text); |
1608 UpdateTextBufferSize(&WP(w, chatquerystr_d).text); |
1609 |
1609 |
1610 SetWindowDirty(w); |
1610 SetWindowDirty(w); |
1611 } |
1611 } |
1612 free(pre_buf); |
1612 free(pre_buf); |
1613 } |
1613 } |
1614 |
1614 |
1615 /* uses querystr_d WP macro |
1615 /* |
1616 * uses querystr_d->caption to store |
1616 * uses chatquerystr_d WP macro |
1617 * - type of chat message (Private/Team/All) in bytes 0-7 |
1617 * uses chatquerystr_d->caption to store type of chat message (Private/Team/All) |
1618 * - destination of chat message in the case of Team/Private in bytes 8-15 */ |
1618 */ |
1619 static void ChatWindowWndProc(Window *w, WindowEvent *e) |
1619 static void ChatWindowWndProc(Window *w, WindowEvent *e) |
1620 { |
1620 { |
1621 switch (e->event) { |
1621 switch (e->event) { |
1622 case WE_CREATE: |
1622 case WE_CREATE: |
1623 SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0); |
1623 SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0); |
1632 }; |
1632 }; |
1633 StringID msg; |
1633 StringID msg; |
1634 |
1634 |
1635 DrawWindowWidgets(w); |
1635 DrawWindowWidgets(w); |
1636 |
1636 |
1637 assert(GB(WP(w, querystr_d).caption, 0, 8) < lengthof(chat_captions)); |
1637 assert(WP(w, chatquerystr_d).caption < lengthof(chat_captions)); |
1638 msg = chat_captions[GB(WP(w, querystr_d).caption, 0, 8)]; |
1638 msg = chat_captions[WP(w, chatquerystr_d).caption]; |
1639 DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, 16); |
1639 DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, 16); |
1640 DrawEditBox(w, &WP(w, querystr_d), 2); |
1640 DrawEditBox(w, &WP(w, chatquerystr_d), 2); |
1641 } break; |
1641 } break; |
1642 |
1642 |
1643 case WE_CLICK: |
1643 case WE_CLICK: |
1644 switch (e->we.click.widget) { |
1644 switch (e->we.click.widget) { |
1645 case 3: { /* Send */ |
1645 case 3: { /* Send */ |
1646 DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8); |
1646 DestType type = (DestType)WP(w, chatquerystr_d).caption; |
1647 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1647 int dest = WP(w, chatquerystr_d).dest; |
1648 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1648 SendChat(WP(w, chatquerystr_d).text.buf, type, dest); |
1649 } /* FALLTHROUGH */ |
1649 } /* FALLTHROUGH */ |
1650 case 0: /* Cancel */ DeleteWindow(w); break; |
1650 case 0: /* Cancel */ DeleteWindow(w); break; |
1651 } |
1651 } |
1652 break; |
1652 break; |
1653 |
1653 |
1654 case WE_MOUSELOOP: |
1654 case WE_MOUSELOOP: |
1655 HandleEditBox(w, &WP(w, querystr_d), 2); |
1655 HandleEditBox(w, &WP(w, chatquerystr_d), 2); |
1656 break; |
1656 break; |
1657 |
1657 |
1658 case WE_KEYPRESS: |
1658 case WE_KEYPRESS: |
1659 if (e->we.keypress.keycode == WKC_TAB) { |
1659 if (e->we.keypress.keycode == WKC_TAB) { |
1660 ChatTabCompletion(w); |
1660 ChatTabCompletion(w); |
1661 } else { |
1661 } else { |
1662 _chat_tab_completion_active = false; |
1662 _chat_tab_completion_active = false; |
1663 switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) { |
1663 switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 2, e)) { |
1664 case 1: { /* Return */ |
1664 case 1: { /* Return */ |
1665 DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8); |
1665 DestType type = (DestType)WP(w, chatquerystr_d).caption; |
1666 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1666 int dest = WP(w, chatquerystr_d).dest; |
1667 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1667 SendChat(WP(w, chatquerystr_d).text.buf, type, dest); |
1668 } /* FALLTHROUGH */ |
1668 } /* FALLTHROUGH */ |
1669 case 2: /* Escape */ DeleteWindow(w); break; |
1669 case 2: /* Escape */ DeleteWindow(w); break; |
1670 } |
1670 } |
1671 } |
1671 } |
1672 break; |
1672 break; |
1704 _chat_tab_completion_active = false; |
1704 _chat_tab_completion_active = false; |
1705 |
1705 |
1706 w = AllocateWindowDesc(&_chat_window_desc); |
1706 w = AllocateWindowDesc(&_chat_window_desc); |
1707 |
1707 |
1708 LowerWindowWidget(w, 2); |
1708 LowerWindowWidget(w, 2); |
1709 WP(w, querystr_d).caption = GB(type, 0, 8) | (dest << 8); // Misuse of caption |
1709 WP(w, chatquerystr_d).caption = type; // Misuse of caption |
1710 WP(w, querystr_d).afilter = CS_ALPHANUMERAL; |
1710 WP(w, chatquerystr_d).dest = dest; |
1711 InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0); |
1711 WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL; |
|
1712 InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0); |
1712 } |
1713 } |
1713 |
1714 |
1714 #endif /* ENABLE_NETWORK */ |
1715 #endif /* ENABLE_NETWORK */ |