* Draw a single server line. * @param cur_item the server to draw. * @param y from where to draw? * @param highlight does the line need to be highlighted? */
| 350 | * @param highlight does the line need to be highlighted? |
| 351 | */ |
| 352 | void DrawServerLine(const NetworkGame *cur_item, int y, bool highlight) const |
| 353 | { |
| 354 | Rect name = this->GetWidget<NWidgetBase>(WID_NG_NAME)->GetCurrentRect(); |
| 355 | Rect info = this->GetWidget<NWidgetBase>(WID_NG_INFO)->GetCurrentRect(); |
| 356 | |
| 357 | /* show highlighted item with a different colour */ |
| 358 | if (highlight) { |
| 359 | Rect r = {std::min(name.left, info.left), y, std::max(name.right, info.right), y + (int)this->resize.step_height - 1}; |
| 360 | GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_GREY); |
| 361 | } |
| 362 | |
| 363 | /* Offset to vertically position text. */ |
| 364 | int text_y_offset = WidgetDimensions::scaled.matrix.top + (this->resize.step_height - WidgetDimensions::scaled.matrix.Vertical() - GetCharacterHeight(FS_NORMAL)) / 2; |
| 365 | |
| 366 | info = info.Shrink(WidgetDimensions::scaled.framerect); |
| 367 | name = name.Shrink(WidgetDimensions::scaled.framerect); |
| 368 | DrawString(name.left, name.right, y + text_y_offset, cur_item->info.server_name, TC_BLACK); |
| 369 | |
| 370 | /* only draw details if the server is online */ |
| 371 | if (cur_item->status == NGLS_ONLINE) { |
| 372 | if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_CLIENTS); nwid->current_x != 0) { |
| 373 | Rect clients = nwid->GetCurrentRect(); |
| 374 | DrawString(clients.left, clients.right, y + text_y_offset, |
| 375 | GetString(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE, cur_item->info.clients_on, cur_item->info.clients_max, cur_item->info.companies_on, cur_item->info.companies_max), |
| 376 | TC_FROMSTRING, SA_HOR_CENTER); |
| 377 | } |
| 378 | |
| 379 | if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_MAPSIZE); nwid->current_x != 0) { |
| 380 | /* map size */ |
| 381 | Rect mapsize = nwid->GetCurrentRect(); |
| 382 | DrawString(mapsize.left, mapsize.right, y + text_y_offset, |
| 383 | GetString(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, cur_item->info.map_width, cur_item->info.map_height), |
| 384 | TC_FROMSTRING, SA_HOR_CENTER); |
| 385 | } |
| 386 | |
| 387 | if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_DATE); nwid->current_x != 0) { |
| 388 | /* current date */ |
| 389 | Rect date = nwid->GetCurrentRect(); |
| 390 | TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(cur_item->info.calendar_date); |
| 391 | DrawString(date.left, date.right, y + text_y_offset, |
| 392 | GetString(STR_JUST_INT, ymd.year), |
| 393 | TC_BLACK, SA_HOR_CENTER); |
| 394 | } |
| 395 | |
| 396 | if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_YEARS); nwid->current_x != 0) { |
| 397 | /* play time */ |
| 398 | Rect years = nwid->GetCurrentRect(); |
| 399 | const auto play_time = cur_item->info.ticks_playing / Ticks::TICKS_PER_SECOND; |
| 400 | DrawString(years.left, years.right, y + text_y_offset, |
| 401 | GetString(STR_NETWORK_SERVER_LIST_PLAY_TIME_SHORT, play_time / 60 / 60, (play_time / 60) % 60), |
| 402 | TC_BLACK, SA_HOR_CENTER); |
| 403 | } |
| 404 | |
| 405 | /* Set top and bottom of info rect to current row. */ |
| 406 | info.top = y; |
| 407 | info.bottom = y + this->resize.step_height - 1; |
| 408 | |
| 409 | bool rtl = _current_text_dir == TD_RTL; |
no test coverage detected