Loading

Paste #pbq4jucs7

  1.     virtual void OnClick(Point pt, int widget, int click_count)
  2.     {
  3.         if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
  4.             if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return;
  5.  
  6.             ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
  7.             return;
  8.         }
  9.  
  10.         switch (widget) {
  11.             case WID_AIC_DECREASE:
  12.             case WID_AIC_INCREASE: {
  13.                 int new_value;
  14.                 if (widget == WID_AIC_DECREASE) {
  15.                     new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
  16.                 } else {
  17.                     new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
  18.                 }
  19.                 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
  20.                 this->InvalidateData();
  21.                 break;
  22.             }
  23.  
  24.             case WID_AIC_GAMELIST: {
  25.                 this->selected_slot = OWNER_DEITY;
  26.                 this->InvalidateData();
  27.                 if (click_count > 1 && this->selected_slot != INVALID_COMPANY && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)this->selected_slot);
  28.                 break;
  29.             }
  30.  
  31.             case WID_AIC_LIST: { // Select a slot
  32.                 this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
  33.                 this->InvalidateData();
  34.                 if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
  35.                 break;
  36.             }
  37.  
  38.             case WID_AIC_MOVE_UP: {
  39.                 bool is_orange_slot = IsEditable((CompanyID)(this->selected_slot)) && !Company::IsValidID(this->selected_slot);
  40.                 bool is_red_slot = IsEditable((CompanyID)(this->selected_slot)) && Company::IsValidID(this->selected_slot) && Company::IsValidAiID(this->selected_slot) && Company::Get(this->selected_slot)->ai_instance->IsDead();
  41.                 bool is_orange_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && !Company::IsValidID(this->selected_slot - 1);
  42.                 bool is_orange_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && !Company::IsValidID(this->selected_slot + 1);
  43.                 bool is_red_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && Company::IsValidID(this->selected_slot - 1) && Company::IsValidAiID(this->selected_slot - 1) && Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
  44.                 bool is_red_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && Company::IsValidID(this->selected_slot + 1) && Company::IsValidAiID(this->selected_slot + 1) && Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
  45.                 if ((is_orange_slot || is_red_slot) && (is_orange_slot_above || is_red_slot_above)) {
  46.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
  47.                     this->selected_slot--;
  48.                     this->vscroll->ScrollTowards(this->selected_slot);
  49.                     this->InvalidateData();
  50.                 }
  51.                 break;
  52.  
  53.             case WID_AIC_MOVE_DOWN:
  54.                 if ((is_orange_slot || is_red_slot) && (is_orange_slot_below || is_red_slot_below)) {
  55.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
  56.                     this->selected_slot++;
  57.                     this->vscroll->ScrollTowards(this->selected_slot);
  58.                     this->InvalidateData();
  59.                 }
  60.                 break;
  61.             }
  62.  
  63.             case WID_AIC_CHANGE:  // choose other AI
  64.                 ShowAIListWindow((CompanyID)this->selected_slot);
  65.                 break;
  66.  
  67.             case WID_AIC_CONFIGURE: // change the settings for an AI
  68.                 ShowAISettingsWindow((CompanyID)this->selected_slot);
  69.                 break;
  70.  
  71.             case WID_AIC_CLOSE:
  72.                 delete this;
  73.                 break;
  74.  
  75.             case WID_AIC_CONTENT_DOWNLOAD:
  76.                 if (!_network_available) {
  77.                     ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
  78.                 } else {
  79. #if defined(ENABLE_NETWORK)
  80.                     ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
  81. #endif
  82.                 }
  83.                 break;
  84.         }
  85.     }

Comments