<commit_before>unit KM_GUIMenuCampaigns;
{$I KaM_Remake.inc}
interface
uses
  {$IFDEF MSWindows} Windows, {$ENDIF}
  {$IFDEF Unix} LCLType, {$ENDIF}
  Classes, SysUtils, Math,
  KM_Controls, KM_ControlsBase, KM_ControlsList, KM_ControlsMemo,
  KM_Pics,
  KM_Campaigns, KM_InterfaceDefaults, KM_InterfaceTypes;


type
  TKMMenuCampaigns = class(TKMMenuPageCommon)
  private
    fOnPageChange: TKMMenuChangeEventText; //will be in ancestor class

    fCampaigns: TKMCampaignsCollection;

    procedure ListChange(Sender: TObject);
    procedure StartClick(Sender: TObject);
    procedure BackClick(Sender: TObject);
  protected
    Panel_CampSelect: TKMPanel;
      ColumnBox_Camps: TKMColumnBox;
      Image_CampsPreview: TKMImage;
      Memo_CampDesc: TKMMemo;
      Button_Camp_Start, Button_Camp_Back: TKMButton;
  public
    constructor Create(aParent: TKMPanel; aCampaigns: TKMCampaignsCollection; aOnPageChange: TKMMenuChangeEventText);
    procedure RefreshList;
    procedure Show;
  end;


implementation
uses
  KM_ResTexts, KM_ResFonts, KM_ResTypes,
  KM_RenderUI,
  KM_GameSettings,
  KM_CampaignTypes;


{ TKMMainMenuInterface }
constructor TKMMenuCampaigns.Create(aParent: TKMPanel; aCampaigns: TKMCampaignsCollection; aOnPageChange: TKMMenuChangeEventText);
var
  L: TKMLabel;
begin
  inherited Create(gpCampSelect);

  fCampaigns := aCampaigns;
  fOnPageChange := aOnPageChange;
  OnEscKeyDown := BackClick;

  Panel_CampSelect := TKMPanel.Create(aParent, 0, 0, aParent.Width, aParent.Height);
  Panel_CampSelect.AnchorsStretch;

    TKMLabel.Create(Panel_CampSelect, 80, 140, 575, 20, gResTexts[TX_MENU_CAMP_HEADER], fntOutline, taCenter).AnchorsCenter;
    ColumnBox_Camps := TKMColumnBox.Create(Panel_CampSelect, 80, 170, 575, 360, fntGrey, bsMenu);
    ColumnBox_Camps.SetColumns(fntOutline, [gResTexts[TX_MENU_CAMPAIGNS_TITLE],
                                             gResTexts[TX_MENU_CAMPAIGNS_MAPS_COUNT],
                                             gResTexts[TX_MENU_CAMPAIGNS_MAPS_UNLOCKED]],
                                             [0, 305, 440]);
    ColumnBox_Camps.AnchorsCenter;
    ColumnBox_Camps.SearchColumn := 0;
    ColumnBox_Camps.OnChange := ListChange;
    ColumnBox_Camps.OnDoubleClick := StartClick;

    TKMBevel.Create(Panel_CampSelect, 669, 170, 275, 208).AnchorsCenter;
    Image_CampsPreview := TKMImage.Create(Panel_CampSelect, 673, 174, 267, 200, 0, rxGuiMain);
    Image_CampsPreview.ImageStretch;
    Image_CampsPreview.AnchorsCenter;

    Memo_CampDesc := TKMMemo.Create(Panel_CampSelect, 669, 390, 275, 140, fntGame, bsMenu);
    Memo_CampDesc.AnchorsCenter;
    Memo_CampDesc.WordWrap := True;
    Memo_CampDesc.ItemHeight := 16;

    L := TKMLabel.Create(Panel_CampSelect, 80, 540, 864, 40, gResTexts[TX_MENU_CAMP_HINT], fntGrey, taCenter);
    L.AnchorsCenter;
    L.WordWrap := True;

    Button_Camp_Start := TKMButton.Create(Panel_CampSelect, 362, 580, 300, 30, gResTexts[TX_MENU_CAMP_START], bsMenu);
    Button_Camp_Start.AnchorsCenter;
    Button_Camp_Start.OnClick := StartClick;

    Button_Camp_Back := TKMButton.Create(Panel_CampSelect, 362, 625, 300, 30, gResTexts[TX_MENU_BACK], bsMenu);
    Button_Camp_Back.AnchorsCenter;
    Button_Camp_Back.OnClick := BackClick;
end;


procedure TKMMenuCampaigns.RefreshList;
var
  I: Integer;
begin
  Image_CampsPreview.TexID := 0; //Clear preview image
  ColumnBox_Camps.Clear;
  Memo_CampDesc.Clear;
  for I := 0 to fCampaigns.Count - 1 do
  begin
    ColumnBox_Camps.AddItem(MakeListRow(
                        [fCampaigns[I].GetCampaignTitle, IntToStr(fCampaigns[I].MapCount), IntToStr(fCampaigns[I].UnlockedMap + 1)],
                        [$FFFFFFFF, $FFFFFFFF, $FFFFFFFF], I));
    if fCampaigns[I].ShortName = gGameSettings.MenuCampaignName then
    begin
      ColumnBox_Camps.ItemIndex := I;
      ListChange(nil);
    end;

  end;

  if ColumnBox_Camps.ItemIndex = -1 then
    Button_Camp_Start.Disable
  else
    Button_Camp_Start.Enable;
end;<commit_msg>Refactor UI of Campaigns list menu<commit_after>unit KM_GUIMenuCampaigns;
{$I KaM_Remake.inc}
interface
uses
  {$IFDEF MSWindows} Windows, {$ENDIF}
  {$IFDEF Unix} LCLType, {$ENDIF}
  Classes, SysUtils, Math,
  KM_Controls, KM_ControlsBase, KM_ControlsList, KM_ControlsMemo,
  KM_Pics,
  KM_Campaigns, KM_InterfaceDefaults, KM_InterfaceTypes;


type
  TKMMenuCampaigns = class(TKMMenuPageCommon)
  private
    fOnPageChange: TKMMenuChangeEventText; //will be in ancestor class

    fCampaigns: TKMCampaignsCollection;

    procedure ListChange(Sender: TObject);
    procedure StartClick(Sender: TObject);
    procedure BackClick(Sender: TObject);
  protected
    Panel_CampSelect: TKMPanel;
      Panel_Campaigns: TKMPanel;
        ColumnBox_Camps: TKMColumnBox;
        Image_CampsPreview: TKMImage;
        Memo_CampDesc: TKMMemo;
        Button_Camp_Start, Button_Camp_Back: TKMButton;
  public
    constructor Create(aParent: TKMPanel; aCampaigns: TKMCampaignsCollection; aOnPageChange: TKMMenuChangeEventText);
    procedure RefreshList;
    procedure Show;
  end;


implementation
uses
  KM_ResTexts, KM_ResFonts, KM_ResTypes,
  KM_RenderUI,
  KM_GameSettings,
  KM_CampaignTypes;


{ TKMMainMenuInterface }
constructor TKMMenuCampaigns.Create(aParent: TKMPanel; aCampaigns: TKMCampaignsCollection; aOnPageChange: TKMMenuChangeEventText);
const
  PAD_W = 80;
  PAN_W = 1024 - PAD_W * 2;
  BTN_W = 300;
  BTN_PAD_W = 40;
  LIST_TOP = 30;
  LIST_W = 505;
  LIST_H = 540;
  COL_PAD = 14;
  RIGHT_W = PAN_W - LIST_W - COL_PAD;
  MAP_IMG_W = 337;
  MAP_IMG_H = 252;
  MAP_PAD = 4;
  DESC_PAD_H = 12;
  DESC_TOP = LIST_TOP + MAP_IMG_H + DESC_PAD_H;
  DESC_H = LIST_H - MAP_IMG_H - DESC_PAD_H;
  DESC_W = MAP_IMG_W + 2*MAP_PAD;
begin
  inherited Create(gpCampSelect);

  fCampaigns := aCampaigns;
  fOnPageChange := aOnPageChange;
  OnEscKeyDown := BackClick;

  Panel_CampSelect := TKMPanel.Create(aParent, 0, 0, aParent.Width, aParent.Height);
  Panel_CampSelect.AnchorsStretch;
    Panel_Campaigns := TKMPanel.Create(Panel_CampSelect, PAD_W, 60, PAN_W, aParent.Height - 100);
    Panel_Campaigns.AnchorsStretch;

    TKMLabel.Create(Panel_Campaigns, 0, 0, Panel_Campaigns.Width, 20, gResTexts[TX_MENU_CAMP_HEADER], fntOutline, taCenter).AnchorsCenter;
    ColumnBox_Camps := TKMColumnBox.Create(Panel_Campaigns, 0, LIST_TOP, LIST_W, LIST_H, fntGrey, bsMenu);
    ColumnBox_Camps.SetColumns(fntOutline, [gResTexts[TX_MENU_CAMPAIGNS_TITLE],
                                             gResTexts[TX_MENU_CAMPAIGNS_MAPS_COUNT],
                                             gResTexts[TX_MENU_CAMPAIGNS_MAPS_UNLOCKED]],
                                             [0, 305, 405]);
    ColumnBox_Camps.AnchorsCenter;
    ColumnBox_Camps.SearchColumn := 0;
    ColumnBox_Camps.OnChange := ListChange;
    ColumnBox_Camps.OnDoubleClick := StartClick;

    TKMBevel.Create(Panel_Campaigns, LIST_W + COL_PAD, 30, MAP_IMG_W + 2*MAP_PAD, MAP_IMG_H + 2*MAP_PAD).AnchorsCenter;
    Image_CampsPreview := TKMImage.Create(Panel_Campaigns, LIST_W + COL_PAD + MAP_PAD, 34, MAP_IMG_W, MAP_IMG_H, 0, rxGuiMain);
    Image_CampsPreview.ImageStretch;
    Image_CampsPreview.AnchorsCenter;

    Memo_CampDesc := TKMMemo.Create(Panel_Campaigns, LIST_W + COL_PAD, DESC_TOP, DESC_W, DESC_H, fntGame, bsMenu);
    Memo_CampDesc.AnchorsCenter;
    Memo_CampDesc.WordWrap := True;
    Memo_CampDesc.ItemHeight := 16;

    with TKMLabel.Create(Panel_Campaigns, 0, ColumnBox_Camps.Bottom + 15, 864, 40, gResTexts[TX_MENU_CAMP_HINT], fntGrey, taCenter) do
    begin
      AnchorsCenter;
      WordWrap := True;
    end;

    Button_Camp_Back := TKMButton.Create(Panel_Campaigns, BTN_PAD_W, 620, BTN_W, 30, gResTexts[TX_MENU_BACK], bsMenu);
    Button_Camp_Back.AnchorsCenter;
    Button_Camp_Back.OnClick := BackClick;

    Button_Camp_Start := TKMButton.Create(Panel_Campaigns, PAN_W - BTN_W - BTN_PAD_W, 620, BTN_W, 30, gResTexts[TX_MENU_CAMP_START], bsMenu);
    Button_Camp_Start.AnchorsCenter;
    Button_Camp_Start.OnClick := StartClick;
end;


procedure TKMMenuCampaigns.RefreshList;
var
  I: Integer;
begin
  Image_CampsPreview.TexID := 0; //Clear preview image
  ColumnBox_Camps.Clear;
  Memo_CampDesc.Clear;
  for I := 0 to fCampaigns.Count - 1 do
  begin
    ColumnBox_Camps.AddItem(MakeListRow(
                        [fCampaigns[I].GetCampaignTitle, IntToStr(fCampaigns[I].MapCount), IntToStr(fCampaigns[I].UnlockedMap + 1)],
                        [$FFFFFFFF, $FFFFFFFF, $FFFFFFFF], I));
    if fCampaigns[I].ShortName = gGameSettings.MenuCampaignName then
    begin
      ColumnBox_Camps.ItemIndex := I;
      ListChange(nil);
    end;

  end;

  if ColumnBox_Camps.ItemIndex = -1 then
    Button_Camp_Start.Disable
  else
    Button_Camp_Start.Enable;
end;
{'fraction_non_alphanumeric': 0.09037800687285223, 'fraction_numerical': 0.021878579610538372, 'mean_word_length': 3.9977103606182025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821534', 'n_tokens_mistral': 3542, 'n_tokens_neox': 3157, 'n_words': 561}