src/network/network_gui.cpp
changeset 9660 2bc15fc4dcf6
parent 9659 187142ff9b6c
child 9690 6ce3777235e2
equal deleted inserted replaced
9659:187142ff9b6c 9660:2bc15fc4dcf6
    95 	NGWW_CONN_BTN,      ///< 'Connection' droplist button
    95 	NGWW_CONN_BTN,      ///< 'Connection' droplist button
    96 	NGWW_PLAYER,        ///< Panel with editbox to set player name
    96 	NGWW_PLAYER,        ///< Panel with editbox to set player name
    97 
    97 
    98 	NGWW_NAME,          ///< 'Name' button
    98 	NGWW_NAME,          ///< 'Name' button
    99 	NGWW_CLIENTS,       ///< 'Clients' button
    99 	NGWW_CLIENTS,       ///< 'Clients' button
       
   100 	NGWW_MAPSIZE,       ///< 'Map size' button
       
   101 	NGWW_DATE,          ///< 'Date' button
       
   102 	NGWW_YEARS,         ///< 'Years' button
   100 	NGWW_INFO,          ///< Third button in the game list panel
   103 	NGWW_INFO,          ///< Third button in the game list panel
   101 
   104 
   102 	NGWW_MATRIX,        ///< Panel with list of games
   105 	NGWW_MATRIX,        ///< Panel with list of games
   103 	NGWW_SCROLLBAR,     ///< Scrollbar of matrix
   106 	NGWW_SCROLLBAR,     ///< Scrollbar of matrix
   104 
   107 
   165 
   168 
   166 		if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max;
   169 		if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max;
   167 		if (r == 0) r = NGameNameSorter(a, b);
   170 		if (r == 0) r = NGameNameSorter(a, b);
   168 
   171 
   169 		return r;
   172 		return r;
       
   173 	}
       
   174 
       
   175 	/** Sort servers by map size */
       
   176 	static int CDECL NGameMapSizeSorter(NetworkGameList* const *a, NetworkGameList* const *b)
       
   177 	{
       
   178 		/* Sort by the area of the map. */
       
   179 		int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width);
       
   180 
       
   181 		if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width;
       
   182 		return (r != 0) ? r : NGameClientSorter(a, b);
       
   183 	}
       
   184 
       
   185 	/** Sort servers by current date */
       
   186 	static int CDECL NGameDateSorter(NetworkGameList* const *a, NetworkGameList* const *b)
       
   187 	{
       
   188 		int r = (*a)->info.game_date - (*b)->info.game_date;
       
   189 		return (r != 0) ? r : NGameClientSorter(a, b);
       
   190 	}
       
   191 
       
   192 	/** Sort servers by the number of days the game is running */
       
   193 	static int CDECL NGameYearsSorter(NetworkGameList* const *a, NetworkGameList* const *b)
       
   194 	{
       
   195 		int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
       
   196 		return (r != 0) ? r : NGameDateSorter(a, b);
   170 	}
   197 	}
   171 
   198 
   172 	/** Sort servers by joinability. If both servers are the
   199 	/** Sort servers by joinability. If both servers are the
   173 	 * same, prefer the non-passworded server first. */
   200 	 * same, prefer the non-passworded server first. */
   174 	static int CDECL NGameAllowedSorter(NetworkGameList* const *a, NetworkGameList* const *b)
   201 	static int CDECL NGameAllowedSorter(NetworkGameList* const *a, NetworkGameList* const *b)
   217 		if (highlight) GfxFillRect(this->widget[NGWW_NAME].left + 1, y - 2, this->widget[NGWW_INFO].right - 1, y + 9, 10);
   244 		if (highlight) GfxFillRect(this->widget[NGWW_NAME].left + 1, y - 2, this->widget[NGWW_INFO].right - 1, y + 9, 10);
   218 
   245 
   219 		SetDParamStr(0, cur_item->info.server_name);
   246 		SetDParamStr(0, cur_item->info.server_name);
   220 		DrawStringTruncated(this->widget[NGWW_NAME].left + 5, y, STR_JUST_RAW_STRING, TC_BLACK, this->widget[NGWW_NAME].right - this->widget[NGWW_NAME].left - 5);
   247 		DrawStringTruncated(this->widget[NGWW_NAME].left + 5, y, STR_JUST_RAW_STRING, TC_BLACK, this->widget[NGWW_NAME].right - this->widget[NGWW_NAME].left - 5);
   221 
   248 
   222 		SetDParam(0, cur_item->info.clients_on);
   249 		/* only draw details if the server is online */
   223 		SetDParam(1, cur_item->info.clients_max);
       
   224 		SetDParam(2, cur_item->info.companies_on);
       
   225 		SetDParam(3, cur_item->info.companies_max);
       
   226 		DrawStringCentered(this->widget[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
       
   227 
       
   228 		/* only draw icons if the server is online */
       
   229 		if (cur_item->online) {
   250 		if (cur_item->online) {
       
   251 			SetDParam(0, cur_item->info.clients_on);
       
   252 			SetDParam(1, cur_item->info.clients_max);
       
   253 			SetDParam(2, cur_item->info.companies_on);
       
   254 			SetDParam(3, cur_item->info.companies_max);
       
   255 			DrawStringCentered(this->widget[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
       
   256 
       
   257 			/* map size */
       
   258 			if (!this->IsWidgetHidden(NGWW_MAPSIZE)) {
       
   259 				SetDParam(0, cur_item->info.map_width);
       
   260 				SetDParam(1, cur_item->info.map_height);
       
   261 				DrawStringCentered(this->widget[NGWW_MAPSIZE].left + 39, y, STR_NETWORK_MAP_SIZE_SHORT, TC_BLACK);
       
   262 			}
       
   263 
       
   264 			/* current date */
       
   265 			if (!this->IsWidgetHidden(NGWW_DATE)) {
       
   266 				YearMonthDay ymd;
       
   267 				ConvertDateToYMD(cur_item->info.game_date, &ymd);
       
   268 				SetDParam(0, ymd.year);
       
   269 				DrawStringCentered(this->widget[NGWW_DATE].left + 29, y, STR_JUST_INT, TC_BLACK);
       
   270 			}
       
   271 
       
   272 			/* number of years the game is running */
       
   273 			if (!this->IsWidgetHidden(NGWW_YEARS)) {
       
   274 				YearMonthDay ymd_cur, ymd_start;
       
   275 				ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
       
   276 				ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
       
   277 				SetDParam(0, ymd_cur.year - ymd_start.year);
       
   278 				DrawStringCentered(this->widget[NGWW_YEARS].left + 29, y, STR_JUST_INT, TC_BLACK);
       
   279 			}
       
   280 
   230 			/* draw a lock if the server is password protected */
   281 			/* draw a lock if the server is password protected */
   231 			if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[NGWW_INFO].left + 5, y - 1);
   282 			if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[NGWW_INFO].left + 5, y - 1);
   232 
   283 
   233 			/* draw red or green icon, depending on compatibility with server */
   284 			/* draw red or green icon, depending on compatibility with server */
   234 			DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), this->widget[NGWW_INFO].left + 15, y);
   285 			DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), this->widget[NGWW_INFO].left + 15, y);
   301 
   352 
   302 		/* Sort based on widgets: name, clients, compatibility */
   353 		/* Sort based on widgets: name, clients, compatibility */
   303 		switch (this->servers.SortType()) {
   354 		switch (this->servers.SortType()) {
   304 			case NGWW_NAME    - NGWW_NAME: this->DrawSortButtonState(NGWW_NAME,    arrow); break;
   355 			case NGWW_NAME    - NGWW_NAME: this->DrawSortButtonState(NGWW_NAME,    arrow); break;
   305 			case NGWW_CLIENTS - NGWW_NAME: this->DrawSortButtonState(NGWW_CLIENTS, arrow); break;
   356 			case NGWW_CLIENTS - NGWW_NAME: this->DrawSortButtonState(NGWW_CLIENTS, arrow); break;
       
   357 			case NGWW_MAPSIZE - NGWW_NAME: if (!this->IsWidgetHidden(NGWW_MAPSIZE)) this->DrawSortButtonState(NGWW_MAPSIZE, arrow); break;
       
   358 			case NGWW_DATE    - NGWW_NAME: if (!this->IsWidgetHidden(NGWW_DATE))    this->DrawSortButtonState(NGWW_DATE,    arrow); break;
       
   359 			case NGWW_YEARS   - NGWW_NAME: if (!this->IsWidgetHidden(NGWW_YEARS))   this->DrawSortButtonState(NGWW_YEARS,   arrow); break;
   306 			case NGWW_INFO    - NGWW_NAME: this->DrawSortButtonState(NGWW_INFO,    arrow); break;
   360 			case NGWW_INFO    - NGWW_NAME: this->DrawSortButtonState(NGWW_INFO,    arrow); break;
   307 		}
   361 		}
   308 
   362 
   309 		uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
   363 		uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
   310 
   364 
   408 
   462 
   409 			case NGWW_CONN_BTN: // 'Connection' droplist
   463 			case NGWW_CONN_BTN: // 'Connection' droplist
   410 				ShowDropDownMenu(this, _lan_internet_types_dropdown, _settings_client.network.lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
   464 				ShowDropDownMenu(this, _lan_internet_types_dropdown, _settings_client.network.lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
   411 				break;
   465 				break;
   412 
   466 
   413 			case NGWW_NAME: // Sort by name
   467 			case NGWW_NAME:    // Sort by name
   414 			case NGWW_CLIENTS: // Sort by connected clients
   468 			case NGWW_CLIENTS: // Sort by connected clients
   415 			case NGWW_INFO: // Connectivity (green dot)
   469 			case NGWW_MAPSIZE: // Sort by map size
       
   470 			case NGWW_DATE:    // Sort by date
       
   471 			case NGWW_YEARS:   // Sort by years
       
   472 			case NGWW_INFO:    // Connectivity (green dot)
   416 				if (this->servers.SortType() == widget - NGWW_NAME) {
   473 				if (this->servers.SortType() == widget - NGWW_NAME) {
   417 					this->servers.ToggleSortOrder();
   474 					this->servers.ToggleSortOrder();
   418 				} else {
   475 				} else {
   419 					this->servers.SetSortType(widget - NGWW_NAME);
   476 					this->servers.SetSortType(widget - NGWW_NAME);
   420 					this->servers.ForceResort();
   477 					this->servers.ForceResort();
   544 
   601 
   545 		this->widget[NGWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
   602 		this->widget[NGWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
   546 
   603 
   547 		SetVScrollCount(this, this->servers.Length());
   604 		SetVScrollCount(this, this->servers.Length());
   548 
   605 
       
   606 		/* Additional colums in server list */
       
   607 		if (this->width > NetworkGameWindow::MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth(NGWW_MAPSIZE)
       
   608 				+ GetWidgetWidth(NGWW_DATE) + GetWidgetWidth(NGWW_YEARS)) {
       
   609 			/* show columns 'Map size', 'Date' and 'Years' */
       
   610 			this->SetWidgetsHiddenState(false, NGWW_MAPSIZE, NGWW_DATE, NGWW_YEARS, WIDGET_LIST_END);
       
   611 			AlignWidgetRight(NGWW_YEARS,   NGWW_INFO);
       
   612 			AlignWidgetRight(NGWW_DATE,    NGWW_YEARS);
       
   613 			AlignWidgetRight(NGWW_MAPSIZE, NGWW_DATE);
       
   614 			AlignWidgetRight(NGWW_CLIENTS, NGWW_MAPSIZE);
       
   615 		} else if (this->width > NetworkGameWindow::MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth(NGWW_MAPSIZE) + GetWidgetWidth(NGWW_DATE)) {
       
   616 			/* show columns 'Map size' and 'Date' */
       
   617 			this->SetWidgetsHiddenState(false, NGWW_MAPSIZE, NGWW_DATE, WIDGET_LIST_END);
       
   618 			this->HideWidget(NGWW_YEARS);
       
   619 			AlignWidgetRight(NGWW_DATE,    NGWW_INFO);
       
   620 			AlignWidgetRight(NGWW_MAPSIZE, NGWW_DATE);
       
   621 			AlignWidgetRight(NGWW_CLIENTS, NGWW_MAPSIZE);
       
   622 		} else if (this->width > NetworkGameWindow::MIN_EXTRA_COLUMNS_WIDTH + GetWidgetWidth(NGWW_MAPSIZE)) {
       
   623 			/* show column 'Map size' */
       
   624 			this->ShowWidget(NGWW_MAPSIZE);
       
   625 			this->SetWidgetsHiddenState(true, NGWW_DATE, NGWW_YEARS, WIDGET_LIST_END);
       
   626 			AlignWidgetRight(NGWW_MAPSIZE, NGWW_INFO);
       
   627 			AlignWidgetRight(NGWW_CLIENTS, NGWW_MAPSIZE);
       
   628 		} else {
       
   629 			/* hide columns 'Map size', 'Date' and 'Years' */
       
   630 			this->SetWidgetsHiddenState(true, NGWW_MAPSIZE, NGWW_DATE, NGWW_YEARS, WIDGET_LIST_END);
       
   631 			AlignWidgetRight(NGWW_CLIENTS, NGWW_INFO);
       
   632 		}
       
   633 		this->widget[NGWW_NAME].right = this->widget[NGWW_CLIENTS].left - 1;
       
   634 
       
   635 		/* BOTTOM */
   549 		int widget_width = this->widget[NGWW_FIND].right - this->widget[NGWW_FIND].left;
   636 		int widget_width = this->widget[NGWW_FIND].right - this->widget[NGWW_FIND].left;
   550 		int space = (this->width - 4 * widget_width - 25) / 3;
   637 		int space = (this->width - 4 * widget_width - 25) / 3;
   551 
   638 
   552 		int offset = 10;
   639 		int offset = 10;
   553 		for (uint i = 0; i < 4; i++) {
   640 		for (uint i = 0; i < 4; i++) {
   555 			offset += widget_width;
   642 			offset += widget_width;
   556 			this->widget[NGWW_FIND + i].right = offset;
   643 			this->widget[NGWW_FIND + i].right = offset;
   557 			offset += space;
   644 			offset += space;
   558 		}
   645 		}
   559 	}
   646 	}
   560 };
   647 
   561 
   648 	static const int MIN_EXTRA_COLUMNS_WIDTH = 550;   ///< default width of the window
   562 Listing NetworkGameWindow::last_sorting = {false, 2};
   649 };
       
   650 
       
   651 Listing NetworkGameWindow::last_sorting = {false, 5};
   563 GUIGameServerList::SortFunction *const NetworkGameWindow::sorter_funcs[] = {
   652 GUIGameServerList::SortFunction *const NetworkGameWindow::sorter_funcs[] = {
   564 	&NGameNameSorter,
   653 	&NGameNameSorter,
   565 	&NGameClientSorter,
   654 	&NGameClientSorter,
       
   655 	&NGameMapSizeSorter,
       
   656 	&NGameDateSorter,
       
   657 	&NGameYearsSorter,
   566 	&NGameAllowedSorter
   658 	&NGameAllowedSorter
   567 };
   659 };
   568 
   660 
   569 
   661 
   570 static const Widget _network_game_window_widgets[] = {
   662 static const Widget _network_game_window_widgets[] = {
   577 { WWT_DROPDOWNIN,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_LAN_INTERNET_COMBO,   STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_BTN
   669 { WWT_DROPDOWNIN,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_LAN_INTERNET_COMBO,   STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_BTN
   578 
   670 
   579 {    WWT_EDITBOX,   RESIZE_LR,     BGC,   290,   440,    22,    33, STR_NETWORK_PLAYER_NAME_OSKTITLE, STR_NETWORK_ENTER_NAME_TIP},       // NGWW_PLAYER
   671 {    WWT_EDITBOX,   RESIZE_LR,     BGC,   290,   440,    22,    33, STR_NETWORK_PLAYER_NAME_OSKTITLE, STR_NETWORK_ENTER_NAME_TIP},       // NGWW_PLAYER
   580 
   672 
   581 /* LEFT SIDE */
   673 /* LEFT SIDE */
   582 { WWT_PUSHTXTBTN,   RESIZE_RIGHT,  BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,            STR_NETWORK_GAME_NAME_TIP},        // NGWW_NAME
   674 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,            STR_NETWORK_GAME_NAME_TIP},        // NGWW_NAME
   583 { WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION,      STR_NETWORK_CLIENTS_CAPTION_TIP},  // NGWW_CLIENTS
   675 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION,      STR_NETWORK_CLIENTS_CAPTION_TIP},  // NGWW_CLIENTS
       
   676 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    71,   150,    42,    53, STR_NETWORK_MAP_SIZE_CAPTION,     STR_NETWORK_MAP_SIZE_CAPTION_TIP}, // NGWW_MAPSIZE
       
   677 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    71,   130,    42,    53, STR_NETWORK_DATE_CAPTION,         STR_NETWORK_DATE_CAPTION_TIP},     // NGWW_DATE
       
   678 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    71,   130,    42,    53, STR_NETWORK_YEARS_CAPTION,        STR_NETWORK_YEARS_CAPTION_TIP},    // NGWW_YEARS
   584 { WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                        STR_NETWORK_INFO_ICONS_TIP},       // NGWW_INFO
   679 { WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                        STR_NETWORK_INFO_ICONS_TIP},       // NGWW_INFO
   585 
   680 
   586 {     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   208, (11 << 8) + 1,                    STR_NETWORK_CLICK_GAME_TO_SELECT}, // NGWW_MATRIX
   681 {     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   208, (11 << 8) + 1,                    STR_NETWORK_CLICK_GAME_TO_SELECT}, // NGWW_MATRIX
   587 {  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   208, 0x0,                              STR_0190_SCROLL_BAR_SCROLLS_LIST}, // NGWW_SCROLLBAR
   682 {  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   208, 0x0,                              STR_0190_SCROLL_BAR_SCROLLS_LIST}, // NGWW_SCROLLBAR
   588 {       WWT_TEXT,   RESIZE_RTB,    BGC,    10,   190,   211,   222, STR_NETWORK_LAST_JOINED_SERVER,   STR_NULL},                         // NGWW_LASTJOINED_LABEL
   683 {       WWT_TEXT,   RESIZE_RTB,    BGC,    10,   190,   211,   222, STR_NETWORK_LAST_JOINED_SERVER,   STR_NULL},                         // NGWW_LASTJOINED_LABEL
   606 
   701 
   607 {   WIDGETS_END},
   702 {   WIDGETS_END},
   608 };
   703 };
   609 
   704 
   610 static const WindowDesc _network_game_window_desc = {
   705 static const WindowDesc _network_game_window_desc = {
   611 	WDP_CENTER, WDP_CENTER, 450, 264, 550, 264,
   706 	WDP_CENTER, WDP_CENTER, 450, 264, 780, 264,
   612 	WC_NETWORK_WINDOW, WC_NONE,
   707 	WC_NETWORK_WINDOW, WC_NONE,
   613 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
   708 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
   614 	_network_game_window_widgets,
   709 	_network_game_window_widgets,
   615 };
   710 };
   616 
   711