Loading

Paste #pn4tdn6kn

  1. --- src/ai/ai_gui.cpp
  2. +++ src/ai/ai_gui.cpp
  3. @@ -757,36 +787,76 @@
  4.     virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
  5.     {
  6.         switch (widget) {
  7. -           case WID_AIC_GAMELIST:
  8. -               this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
  9. +           case WID_AIC_GAMELIST: {
  10. +               uint highest_icon = 0;
  11. +               static const SpriteID icons[] = {SPR_AICONFIG_DEAD, SPR_AICONFIG_ELIGIBLE, SPR_AICONFIG_ALIVE};
  12. +               for (int i = 0; i < lengthof(icons); i++) {
  13. +                   highest_icon = max(highest_icon, GetSpriteSize(icons[i]).height);
  14. +               }
  15. +               this->line_height = max((uint)FONT_HEIGHT_NORMAL, highest_icon) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
  16.                 size->height = 1 * this->line_height;
  17.                 break;
  18. +           }
  19.  
  20. -           case WID_AIC_LIST:
  21. -               this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
  22. -               size->height = 8 * this->line_height;
  23. +           case WID_AIC_LIST: {
  24. +               uint highest_icon = 0;
  25. +               static const SpriteID icons[] = {SPR_AICONFIG_DEAD, SPR_AICONFIG_ELIGIBLE, SPR_AICONFIG_ALIVE, SPR_AICONFIG_HUMAN, SPR_AICONFIG_RANDOM};
  26. +               for (int i = 0; i < lengthof(icons); i++) {
  27. +                   highest_icon = max(highest_icon, GetSpriteSize(icons[i]).height);
  28. +               }
  29. +               this->line_height = max((uint)FONT_HEIGHT_NORMAL, highest_icon) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
  30. +               size->height = 15 * this->line_height;
  31.                 break;
  32. +           }
  33. +
  34. +           case WID_AIC_CHANGE: {
  35. +               uint change_width = 0;
  36. +               static const StringID params[] = {STR_AI_CONFIG_GAMESCRIPT, STR_AI_CONFIG_NONE, STR_AI_CONFIG_AI};
  37. +               for (int i = 0; i < lengthof(params); i++) {
  38. +                   SetDParam(0, params[i]);
  39. +                   change_width = max(change_width, GetStringBoundingBox(STR_AI_CONFIG_CHANGE).width);
  40. +               }
  41. +               size->width = change_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
  42. +               break;
  43. +           }
  44. +
  45. +           case WID_AIC_CONFIGURE: {
  46. +               size->width = max(GetStringBoundingBox(STR_AI_CONFIG_CONFIGURE).width, GetStringBoundingBox(STR_AI_DEBUG_SETTINGS).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
  47. +               break;
  48. +           }
  49.         }
  50.     }
  51.  
  52.     /**
  53. -    * Can the AI config in the given company slot be edited?
  54. +    * Can the AI or GS config in the given slot be selected?
  55.      * @param slot The slot to query.
  56. -    * @return True if and only if the given AI Config slot can e edited.
  57. +    * @return True if and only if the given AI or GS Config of this slot can be selected.
  58.      */
  59. -   static bool IsEditable(CompanyID slot)
  60. +   static bool IsSelectable(CompanyID slot)
  61.     {
  62. -       if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
  63. +       return slot >= COMPANY_FIRST && slot < MAX_COMPANIES || slot == OWNER_DEITY;
  64. +   }
  65.  
  66. -       if (_game_mode != GM_NORMAL) {
  67. -           return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
  68. -       }
  69. +   /**
  70. +   * Is the AI or GS config in the given slot eligible to start?
  71. +   * @param slot The slot to query.
  72. +   * @return True if and only if the given AI or GS Config of this slot can start.
  73. +   */
  74. +   static bool IsEligible(CompanyID slot)
  75. +   {
  76. +       if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL && (Game::GetInstance() == NULL || _game_mode == GM_MENU);
  77. +
  78.         if (Company::IsValidID(slot) || slot < 0) return false;
  79.  
  80. -       int max_slot = GetGameSettings().difficulty.max_no_competitors;
  81. -       for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
  82. -           if (Company::IsValidHumanID(cid)) max_slot++;
  83. +       int current_no_ais = 0;
  84. +       for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
  85. +           if (Company::IsValidAiID(cid)) current_no_ais++;
  86.         }
  87. +       int empty_slots = 0;
  88. +       CompanyID max_slot;
  89. +       for (max_slot = COMPANY_FIRST; max_slot < MAX_COMPANIES && GetGameSettings().difficulty.max_no_competitors - current_no_ais > empty_slots; max_slot++) {
  90. +           if (!Company::IsValidID(max_slot)) empty_slots++;
  91. +       }
  92.         return slot < max_slot;
  93.     }

Comments