<commit_before>unit KM_GUIMenuReplays;
{$I KaM_Remake.inc}
interface
uses
  SysUtils, Controls, Math,
  KM_Utils, KM_Controls, KM_Saves, KM_InterfaceDefaults, KM_Minimap, KM_Pics;


type
  TKMMenuReplays = class
  private
    fOnPageChange: TGUIEventText;

    fSaves: TKMSavesCollection;
    fMinimap: TKMMinimap;

    fLastSaveCRC: Cardinal; //CRC of selected save

    procedure Replays_ListClick(Sender: TObject);
    procedure Replay_TypeChange(Sender: TObject);
    procedure Replays_ScanUpdate(Sender: TObject);
    procedure Replays_SortUpdate(Sender: TObject);
    procedure Replays_RefreshList(aJumpToSelected:Boolean);
    procedure Replays_Sort(aIndex: Integer);
    procedure Replays_Play(Sender: TObject);
    procedure BackClick(Sender: TObject);
    procedure DeleteClick(Sender: TObject);
    procedure DeleteConfirm(aVisible: Boolean);
    procedure RenameClick(Sender: TObject);
    procedure RenameConfirm(aVisible: Boolean);

  protected
    Panel_Replays:TKMPanel;
      Radio_Replays_Type:TKMRadioGroup;
      ColumnBox_Replays: TKMColumnBox;
      Button_ReplaysPlay: TKMButton;
      Button_ReplaysBack:TKMButton;
      MinimapView_Replay: TKMMinimapView;
      Button_Delete, Button_DeleteConfirm, Button_DeleteCancel: TKMButton;
      Label_DeleteConfirm: TKMLabel;
      Button_Rename, Button_RenameConfirm, Button_RenameCancel: TKMButton;
      PopUp_Rename: TKMPopUpMenu;
      Image_Rename: TKMImage;
      Edit_Rename: TKMEdit;
      Label_RenameInfo, Label_RenameName: TKMLabel;
  public
    constructor Create(aParent: TKMPanel; aOnPageChange: TGUIEventText);
    destructor Destroy; override;

    procedure Show;
    procedure UpdateState;
  end;


implementation
uses
  KM_ResTexts, KM_GameApp, KM_RenderUI, KM_ResFonts;


{ TKMGUIMenuReplays }
constructor TKMMenuReplays.Create(aParent: TKMPanel; aOnPageChange: TGUIEventText);
begin
  inherited Create;

  fOnPageChange := aOnPageChange;

  fSaves := TKMSavesCollection.Create;
  fMinimap := TKMMinimap.Create(False, True);

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

  TKMLabel.Create(Panel_Replays, aParent.Width div 2, 50, gResTexts[TX_MENU_LOAD_LIST], fnt_Outline, taCenter);

  TKMBevel.Create(Panel_Replays, 22, 86, 770, 50);
  Radio_Replays_Type := TKMRadioGroup.Create(Panel_Replays,30,94,300,40,fnt_Grey);
  Radio_Replays_Type.ItemIndex := 0;
  Radio_Replays_Type.Add(gResTexts[TX_MENU_MAPED_SPMAPS]);
  Radio_Replays_Type.Add(gResTexts[TX_MENU_MAPED_MPMAPS]);
  Radio_Replays_Type.OnChange := Replay_TypeChange;

  ColumnBox_Replays := TKMColumnBox.Create(Panel_Replays, 22, 150, 770, 425, fnt_Metal, bsMenu);
  ColumnBox_Replays.SetColumns(fnt_Outline, [gResTexts[TX_MENU_LOAD_FILE], gResTexts[TX_MENU_LOAD_DATE], gResTexts[TX_MENU_LOAD_DESCRIPTION]], [0, 250, 430]);
  ColumnBox_Replays.Anchors := [anLeft,anTop,anBottom];
  ColumnBox_Replays.SearchColumn := 0;
  ColumnBox_Replays.OnChange := Replays_ListClick;
  ColumnBox_Replays.OnColumnClick := Replays_Sort;
  ColumnBox_Replays.OnDoubleClick := Replays_Play;

  with TKMBevel.Create(Panel_Replays, 805, 290, 199, 199) do Anchors := [anLeft];
  MinimapView_Replay := TKMMinimapView.Create(Panel_Replays,809,294,191,191);
  MinimapView_Replay.Anchors := [anLeft];

  Button_ReplaysBack := TKMButton.Create(Panel_Replays, 337, 700, 350, 30, gResTexts[TX_MENU_BACK], bsMenu);
  Button_ReplaysBack.Anchors := [anLeft,anBottom];
  Button_ReplaysBack.OnClick := BackClick;

  Button_ReplaysPlay := TKMButton.Create(Panel_Replays, 337, 590, 350, 30, gResTexts[TX_MENU_VIEW_REPLAY], bsMenu);
  Button_ReplaysPlay.Anchors := [anLeft,anBottom];
  Button_ReplaysPlay.OnClick := Replays_Play;

  Button_Delete := TKMButton.Create(Panel_Replays, 337, 624, 350, 30, gResTexts[TX_MENU_REPLAY_DELETE], bsMenu);
  Button_Delete.Anchors := [anLeft,anBottom];
  Button_Delete.OnClick := DeleteClick;

  Label_DeleteConfirm := TKMLabel.Create(Panel_Replays, aParent.Width div 2, 634, gResTexts[TX_MENU_REPLAY_DELETE_CONFIRM], fnt_Outline, taCenter);
  Label_DeleteConfirm.Anchors := [anLeft,anBottom];
  Label_DeleteConfirm.Hide;

  Button_DeleteConfirm := TKMButton.Create(Panel_Replays, 337, 660, 170, 30, gResTexts[TX_MENU_LOAD_DELETE_DELETE], bsMenu);
  Button_DeleteConfirm.Anchors := [anLeft,anBottom];
  Button_DeleteConfirm.OnClick := DeleteClick;
  Button_DeleteConfirm.Hide;

  Button_DeleteCancel  := TKMButton.Create(Panel_Replays, 517, 660, 170, 30, gResTexts[TX_MENU_LOAD_DELETE_CANCEL], bsMenu);
  Button_DeleteCancel.Anchors := [anLeft,anBottom];
  Button_DeleteCancel.OnClick := DeleteClick;
  Button_DeleteCancel.Hide;

  Button_Rename := TKMButton.Create(Panel_Replays, 805, 499, 199, 30, 'Rename Replay', bsMenu);
  Button_Rename.Anchors := [anLeft,anBottom];
  Button_Rename.OnClick := RenameClick;

  PopUp_Rename := TKMPopUpMenu.Create(Panel_Replays, 400);
  PopUp_Rename.Height := 180;
  // Keep the pop-up centered
  PopUp_Rename.Left := (Panel_Replays.Width Div 2) - 200;
  PopUp_Rename.Top := (Panel_Replays.Height Div 2) - 90;

  Image_Rename := TKMImage.Create(PopUp_Rename,0,0, 400, 180, 3, rxGuiMain);
  Image_Rename.ImageStretch;

  Label_RenameInfo := TKMLabel.Create(PopUp_Rename, 20, 25, 360, 30, 'Rename this Replay', fnt_Outline, taCenter);
  Label_RenameInfo.Anchors := [anLeft,anBottom];

  Label_RenameName := TKMLabel.Create(PopUp_Rename, 20, 75, 60, 20, 'Name:', fnt_Metal, taLeft);
  Label_RenameName.Anchors := [anLeft,anBottom];

  Edit_Rename := TKMEdit.Create(PopUp_Rename, 80, 72, 290, 20, fnt_Metal);
  Edit_Rename.Anchors := [anLeft,anBottom];
  Edit_Rename.AllowedChars := acFileName;

  Button_RenameConfirm := TKMButton.Create(PopUp_Rename, 20, 125, 170, 30, 'Confirm', bsMenu);
  Button_RenameConfirm.Anchors := [anLeft,anBottom];
  Button_RenameConfirm.OnClick := RenameClick;

  Button_RenameCancel := TKMButton.Create(PopUp_Rename, 200, 125, 170, 30, 'Cancel', bsMenu);
  Button_RenameCancel.Anchors := [anLeft,anBottom];
  Button_RenameCancel.OnClick := RenameClick;
end;


destructor TKMMenuReplays.Destroy;
begin
  fSaves.Free;
  fMinimap.Free;

  inherited;
end;


procedure TKMMenuReplays.Replays_ListClick(Sender: TObject);
var ID: Integer;
begin<commit_msg>Tiny clean up * Label_RenameTitle sounds more natural then Label_RenameInfo. * For order's sake, move the labels up one spot.<commit_after>unit KM_GUIMenuReplays;
{$I KaM_Remake.inc}
interface
uses
  SysUtils, Controls, Math,
  KM_Utils, KM_Controls, KM_Saves, KM_InterfaceDefaults, KM_Minimap, KM_Pics;


type
  TKMMenuReplays = class
  private
    fOnPageChange: TGUIEventText;

    fSaves: TKMSavesCollection;
    fMinimap: TKMMinimap;

    fLastSaveCRC: Cardinal; //CRC of selected save

    procedure Replays_ListClick(Sender: TObject);
    procedure Replay_TypeChange(Sender: TObject);
    procedure Replays_ScanUpdate(Sender: TObject);
    procedure Replays_SortUpdate(Sender: TObject);
    procedure Replays_RefreshList(aJumpToSelected:Boolean);
    procedure Replays_Sort(aIndex: Integer);
    procedure Replays_Play(Sender: TObject);
    procedure BackClick(Sender: TObject);
    procedure DeleteClick(Sender: TObject);
    procedure DeleteConfirm(aVisible: Boolean);
    procedure RenameClick(Sender: TObject);
    procedure RenameConfirm(aVisible: Boolean);

  protected
    Panel_Replays:TKMPanel;
      Radio_Replays_Type:TKMRadioGroup;
      ColumnBox_Replays: TKMColumnBox;
      Button_ReplaysPlay: TKMButton;
      Button_ReplaysBack:TKMButton;
      MinimapView_Replay: TKMMinimapView;
      Button_Delete, Button_DeleteConfirm, Button_DeleteCancel: TKMButton;
      Label_DeleteConfirm: TKMLabel;
      Button_Rename, Button_RenameConfirm, Button_RenameCancel: TKMButton;
      PopUp_Rename: TKMPopUpMenu;
      Image_Rename: TKMImage;
      Label_RenameTitle, Label_RenameName: TKMLabel;
      Edit_Rename: TKMEdit;
  public
    constructor Create(aParent: TKMPanel; aOnPageChange: TGUIEventText);
    destructor Destroy; override;

    procedure Show;
    procedure UpdateState;
  end;


implementation
uses
  KM_ResTexts, KM_GameApp, KM_RenderUI, KM_ResFonts;


{ TKMGUIMenuReplays }
constructor TKMMenuReplays.Create(aParent: TKMPanel; aOnPageChange: TGUIEventText);
begin
  inherited Create;

  fOnPageChange := aOnPageChange;

  fSaves := TKMSavesCollection.Create;
  fMinimap := TKMMinimap.Create(False, True);

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

  TKMLabel.Create(Panel_Replays, aParent.Width div 2, 50, gResTexts[TX_MENU_LOAD_LIST], fnt_Outline, taCenter);

  TKMBevel.Create(Panel_Replays, 22, 86, 770, 50);
  Radio_Replays_Type := TKMRadioGroup.Create(Panel_Replays,30,94,300,40,fnt_Grey);
  Radio_Replays_Type.ItemIndex := 0;
  Radio_Replays_Type.Add(gResTexts[TX_MENU_MAPED_SPMAPS]);
  Radio_Replays_Type.Add(gResTexts[TX_MENU_MAPED_MPMAPS]);
  Radio_Replays_Type.OnChange := Replay_TypeChange;

  ColumnBox_Replays := TKMColumnBox.Create(Panel_Replays, 22, 150, 770, 425, fnt_Metal, bsMenu);
  ColumnBox_Replays.SetColumns(fnt_Outline, [gResTexts[TX_MENU_LOAD_FILE], gResTexts[TX_MENU_LOAD_DATE], gResTexts[TX_MENU_LOAD_DESCRIPTION]], [0, 250, 430]);
  ColumnBox_Replays.Anchors := [anLeft,anTop,anBottom];
  ColumnBox_Replays.SearchColumn := 0;
  ColumnBox_Replays.OnChange := Replays_ListClick;
  ColumnBox_Replays.OnColumnClick := Replays_Sort;
  ColumnBox_Replays.OnDoubleClick := Replays_Play;

  with TKMBevel.Create(Panel_Replays, 805, 290, 199, 199) do Anchors := [anLeft];
  MinimapView_Replay := TKMMinimapView.Create(Panel_Replays,809,294,191,191);
  MinimapView_Replay.Anchors := [anLeft];

  Button_ReplaysBack := TKMButton.Create(Panel_Replays, 337, 700, 350, 30, gResTexts[TX_MENU_BACK], bsMenu);
  Button_ReplaysBack.Anchors := [anLeft,anBottom];
  Button_ReplaysBack.OnClick := BackClick;

  Button_ReplaysPlay := TKMButton.Create(Panel_Replays, 337, 590, 350, 30, gResTexts[TX_MENU_VIEW_REPLAY], bsMenu);
  Button_ReplaysPlay.Anchors := [anLeft,anBottom];
  Button_ReplaysPlay.OnClick := Replays_Play;

  Button_Delete := TKMButton.Create(Panel_Replays, 337, 624, 350, 30, gResTexts[TX_MENU_REPLAY_DELETE], bsMenu);
  Button_Delete.Anchors := [anLeft,anBottom];
  Button_Delete.OnClick := DeleteClick;

  Label_DeleteConfirm := TKMLabel.Create(Panel_Replays, aParent.Width div 2, 634, gResTexts[TX_MENU_REPLAY_DELETE_CONFIRM], fnt_Outline, taCenter);
  Label_DeleteConfirm.Anchors := [anLeft,anBottom];
  Label_DeleteConfirm.Hide;

  Button_DeleteConfirm := TKMButton.Create(Panel_Replays, 337, 660, 170, 30, gResTexts[TX_MENU_LOAD_DELETE_DELETE], bsMenu);
  Button_DeleteConfirm.Anchors := [anLeft,anBottom];
  Button_DeleteConfirm.OnClick := DeleteClick;
  Button_DeleteConfirm.Hide;

  Button_DeleteCancel  := TKMButton.Create(Panel_Replays, 517, 660, 170, 30, gResTexts[TX_MENU_LOAD_DELETE_CANCEL], bsMenu);
  Button_DeleteCancel.Anchors := [anLeft,anBottom];
  Button_DeleteCancel.OnClick := DeleteClick;
  Button_DeleteCancel.Hide;

  Button_Rename := TKMButton.Create(Panel_Replays, 805, 499, 199, 30, 'Rename Replay', bsMenu);
  Button_Rename.Anchors := [anLeft,anBottom];
  Button_Rename.OnClick := RenameClick;

  PopUp_Rename := TKMPopUpMenu.Create(Panel_Replays, 400);
  PopUp_Rename.Height := 180;
  // Keep the pop-up centered
  PopUp_Rename.Left := (Panel_Replays.Width Div 2) - 200;
  PopUp_Rename.Top := (Panel_Replays.Height Div 2) - 90;

  Image_Rename := TKMImage.Create(PopUp_Rename,0,0, 400, 180, 3, rxGuiMain);
  Image_Rename.ImageStretch;

  Label_RenameTitle := TKMLabel.Create(PopUp_Rename, 20, 25, 360, 30, 'Rename this Replay', fnt_Outline, taCenter);
  Label_RenameTitle.Anchors := [anLeft,anBottom];

  Label_RenameName := TKMLabel.Create(PopUp_Rename, 20, 75, 60, 20, 'Name:', fnt_Metal, taLeft);
  Label_RenameName.Anchors := [anLeft,anBottom];

  Edit_Rename := TKMEdit.Create(PopUp_Rename, 80, 72, 290, 20, fnt_Metal);
  Edit_Rename.Anchors := [anLeft,anBottom];
  Edit_Rename.AllowedChars := acFileName;

  Button_RenameConfirm := TKMButton.Create(PopUp_Rename, 20, 125, 170, 30, 'Confirm', bsMenu);
  Button_RenameConfirm.Anchors := [anLeft,anBottom];
  Button_RenameConfirm.OnClick := RenameClick;

  Button_RenameCancel := TKMButton.Create(PopUp_Rename, 200, 125, 170, 30, 'Cancel', bsMenu);
  Button_RenameCancel.Anchors := [anLeft,anBottom];
  Button_RenameCancel.OnClick := RenameClick;
end;


destructor TKMMenuReplays.Destroy;
begin
  fSaves.Free;
  fMinimap.Free;

  inherited;
end;


procedure TKMMenuReplays.Replays_ListClick(Sender: TObject);
var ID: Integer;
begin
{'fraction_non_alphanumeric': 0.10371430843871789, 'fraction_numerical': 0.03276863119382804, 'mean_word_length': 6.111990950226244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4913010', 'n_tokens_mistral': 5243, 'n_tokens_neox': 4539, 'n_words': 784}