25 #include "network_udp.h" |
25 #include "network_udp.h" |
26 #include "../settings.h" |
26 #include "../settings.h" |
27 #include "../string.h" |
27 #include "../string.h" |
28 #include "../town.h" |
28 #include "../town.h" |
29 #include "../newgrf.h" |
29 #include "../newgrf.h" |
|
30 #include "../helpers.hpp" |
30 |
31 |
31 #define BGC 5 |
32 #define BGC 5 |
32 #define BTC 15 |
33 #define BTC 15 |
33 |
34 |
34 typedef struct network_d { |
35 typedef struct network_d { |
164 for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++; |
165 for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++; |
165 if (n == 0) return; |
166 if (n == 0) return; |
166 |
167 |
167 /* Create temporary array of games to use for listing */ |
168 /* Create temporary array of games to use for listing */ |
168 free(nqld->sort_list); |
169 free(nqld->sort_list); |
169 nqld->sort_list = malloc(n * sizeof(nqld->sort_list[0])); |
170 MallocT(&nqld->sort_list, n); |
170 if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list"); |
171 if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list"); |
171 nqld->l.list_length = n; |
172 nqld->l.list_length = n; |
172 |
173 |
173 for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) { |
174 for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) { |
174 nqld->sort_list[n++] = ngl_temp; |
175 nqld->sort_list[n++] = ngl_temp; |
219 case WE_CREATE: /* Focus input box */ |
220 case WE_CREATE: /* Focus input box */ |
220 nd->field = 3; |
221 nd->field = 3; |
221 nd->server = NULL; |
222 nd->server = NULL; |
222 |
223 |
223 WP(w, network_ql_d).sort_list = NULL; |
224 WP(w, network_ql_d).sort_list = NULL; |
224 ld->flags = VL_REBUILD | (_ng_sorting.order << (VL_DESC - 1)); |
225 ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE); |
225 ld->sort_type = _ng_sorting.criteria; |
226 ld->sort_type = _ng_sorting.criteria; |
226 break; |
227 break; |
227 |
228 |
228 case WE_PAINT: { |
229 case WE_PAINT: { |
229 const NetworkGameList *sel = nd->server; |
230 const NetworkGameList *sel = nd->server; |
785 |
786 |
786 WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL; |
787 WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL; |
787 InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160); |
788 InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160); |
788 } |
789 } |
789 |
790 |
790 static byte NetworkLobbyFindCompanyIndex(byte pos) |
791 static PlayerID NetworkLobbyFindCompanyIndex(byte pos) |
791 { |
792 { |
792 byte i; |
793 PlayerID i; |
793 |
794 |
794 /* Scroll through all _network_player_info and get the 'pos' item |
795 /* Scroll through all _network_player_info and get the 'pos' item |
795 that is not empty */ |
796 that is not empty */ |
796 for (i = 0; i < MAX_PLAYERS; i++) { |
797 for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { |
797 if (_network_player_info[i].company_name[0] != '\0') { |
798 if (_network_player_info[i].company_name[0] != '\0') { |
798 if (pos-- == 0) return i; |
799 if (pos-- == 0) return i; |
799 } |
800 } |
800 } |
801 } |
801 |
802 |
802 return 0; |
803 return PLAYER_FIRST; |
803 } |
804 } |
804 |
805 |
805 /* uses network_d WP macro */ |
806 /* uses network_d WP macro */ |
806 static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) |
807 static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) |
807 { |
808 { |
808 network_d *nd = &WP(w, network_d); |
809 network_d *nd = &WP(w, network_d); |
809 |
810 |
810 switch (e->event) { |
811 switch (e->event) { |
811 case WE_CREATE: |
812 case WE_CREATE: |
812 nd->company = (byte)-1; |
813 nd->company = INVALID_PLAYER; |
813 break; |
814 break; |
814 |
815 |
815 case WE_PAINT: { |
816 case WE_PAINT: { |
816 const NetworkGameInfo *gi = &nd->server->info; |
817 const NetworkGameInfo *gi = &nd->server->info; |
817 int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos; |
818 int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos; |
917 uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW; |
918 uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW; |
918 |
919 |
919 if (id_v >= w->vscroll.cap) return; |
920 if (id_v >= w->vscroll.cap) return; |
920 |
921 |
921 id_v += w->vscroll.pos; |
922 id_v += w->vscroll.pos; |
922 nd->company = (id_v >= nd->server->info.companies_on) ? (byte)-1 : NetworkLobbyFindCompanyIndex(id_v); |
923 nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v); |
923 SetWindowDirty(w); |
924 SetWindowDirty(w); |
924 } break; |
925 } break; |
925 case 7: /* Join company */ |
926 case 7: /* Join company */ |
926 if (nd->company != (byte)-1) { |
927 if (nd->company != (byte)-1) { |
927 _network_playas = nd->company; |
928 _network_playas = nd->company; |
1409 default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */ |
1410 default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */ |
1410 progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total; |
1411 progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total; |
1411 } |
1412 } |
1412 |
1413 |
1413 /* Draw nice progress bar :) */ |
1414 /* Draw nice progress bar :) */ |
1414 DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, 0); |
1415 DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE); |
1415 } break; |
1416 } break; |
1416 |
1417 |
1417 case WE_CLICK: |
1418 case WE_CLICK: |
1418 switch (e->we.click.widget) { |
1419 switch (e->we.click.widget) { |
1419 case 2: /* Disconnect button */ |
1420 case 2: /* Disconnect button */ |
1463 |
1464 |
1464 static void SendChat(const char *buf, DestType type, byte dest) |
1465 static void SendChat(const char *buf, DestType type, byte dest) |
1465 { |
1466 { |
1466 if (buf[0] == '\0') return; |
1467 if (buf[0] == '\0') return; |
1467 if (!_network_server) { |
1468 if (!_network_server) { |
1468 SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + type, type, dest, buf); |
1469 SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf); |
1469 } else { |
1470 } else { |
1470 NetworkServer_HandleChat(NETWORK_ACTION_CHAT + type, type, dest, buf, NETWORK_SERVER_INDEX); |
1471 NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX); |
1471 } |
1472 } |
1472 } |
1473 } |
1473 |
1474 |
1474 /** |
1475 /** |
1475 * Find the next item of the list of things that can be auto-completed. |
1476 * Find the next item of the list of things that can be auto-completed. |
1633 } break; |
1634 } break; |
1634 |
1635 |
1635 case WE_CLICK: |
1636 case WE_CLICK: |
1636 switch (e->we.click.widget) { |
1637 switch (e->we.click.widget) { |
1637 case 3: { /* Send */ |
1638 case 3: { /* Send */ |
1638 DestType type = GB(WP(w, querystr_d).caption, 0, 8); |
1639 DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8); |
1639 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1640 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1640 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1641 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1641 } /* FALLTHROUGH */ |
1642 } /* FALLTHROUGH */ |
1642 case 0: /* Cancel */ DeleteWindow(w); break; |
1643 case 0: /* Cancel */ DeleteWindow(w); break; |
1643 } |
1644 } |
1652 ChatTabCompletion(w); |
1653 ChatTabCompletion(w); |
1653 } else { |
1654 } else { |
1654 _chat_tab_completion_active = false; |
1655 _chat_tab_completion_active = false; |
1655 switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) { |
1656 switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) { |
1656 case 1: { /* Return */ |
1657 case 1: { /* Return */ |
1657 DestType type = GB(WP(w, querystr_d).caption, 0, 8); |
1658 DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8); |
1658 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1659 byte dest = GB(WP(w, querystr_d).caption, 8, 8); |
1659 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1660 SendChat(WP(w, querystr_d).text.buf, type, dest); |
1660 } /* FALLTHROUGH */ |
1661 } /* FALLTHROUGH */ |
1661 case 2: /* Escape */ DeleteWindow(w); break; |
1662 case 2: /* Escape */ DeleteWindow(w); break; |
1662 } |
1663 } |