Loading

Paste #pojcblf4i

  1.     /**
  2.      * Some data on this window has become invalid.
  3.      * @param data Information about the changed data.
  4.      * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
  5.      */
  6.     virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
  7.     {
  8.         if (!IsSelectable(this->selected_slot)) {
  9.             this->selected_slot = INVALID_COMPANY;
  10.         }
  11.  
  12.         if (!gui_scope) return;
  13.  
  14.         this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
  15.         this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
  16.         this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidAiID(this->selected_slot) || GetFreeSlot(this->selected_slot, -1) == INVALID_COMPANY);
  17.         this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidAiID(this->selected_slot) || GetFreeSlot(this->selected_slot, +1) == INVALID_COMPANY);
  18.  
  19.         for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
  20.             if (!Company::IsValidAiID(cid) && AIConfig::GetConfig(cid)->IsRandom()) {
  21.                 AIConfig::GetConfig(cid)->Change(NULL);
  22.                 DeleteWindowById(WC_AI_SETTINGS, cid);
  23.                 DeleteWindowByClass(WC_TEXTFILE);
  24.                 DeleteWindowByClass(WC_QUERY_STRING);
  25.             }
  26.         }
  27.  
  28.         this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY && (_game_mode == GM_NORMAL || (_game_mode == GM_EDITOR && Game::GetInstance() != NULL)) || Company::IsValidAiID(this->selected_slot));
  29.         this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0 || _game_mode == GM_EDITOR && !IsConsideredDead(this->selected_slot));
  30.  
  31.         /* Display either Settings or Configure button */
  32.         NWidgetCore *configure_button = this->GetWidget<NWidgetCore>(WID_AIC_CONFIGURE);
  33.         if (this->selected_slot != INVALID_COMPANY && !IsConsideredDead(this->selected_slot)) {
  34.             configure_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
  35.         } else {
  36.             configure_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
  37.         }
  38.  
  39.         this->SetWidgetDisabledState(WID_AIC_START_STOP_TOGGLE, _game_mode != GM_NORMAL || this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidHumanID(this->selected_slot) || GetCurrentNoAIs() >= GetGameSettings().difficulty.max_no_competitors && !Company::IsValidID(this->selected_slot));
  40.  
  41.         /* Display either Start AI or Stop AI button */
  42.         NWidgetCore *toggle_button = this->GetWidget<NWidgetCore>(WID_AIC_START_STOP_TOGGLE);
  43.         if (this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidHumanID(this->selected_slot) || !Company::IsValidAiID(this->selected_slot)) {
  44.             toggle_button->SetDataTip(STR_AI_CONFIG_START, STR_AI_CONFIG_START_TOOLTIP);
  45.         } else {
  46.             toggle_button->SetDataTip(STR_AI_CONFIG_STOP, STR_AI_CONFIG_STOP_TOOLTIP);
  47.         }
  48.  
  49.         for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
  50.             this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
  51.         }
  52.     }
  53. };

Comments