<commit_before>unit KM_GUIMapEdMissionPlayers;
{$I KaM_Remake.inc}
interface
uses
  {$IFDEF MSWindows} Windows, {$ENDIF}
  {$IFDEF Unix} LCLIntf, LCLType, {$ENDIF}
  Classes, SysUtils,
  KM_Controls, KM_ControlsBase, KM_ControlsPopUp, KM_ControlsSwitch,
  KM_Defaults, KM_Pics;

type
  TKMMapEdPlayerType = (mptDefault, mptHuman, mptClassicAI, mptAdvancedAI);

  TKMMapEdConfirmationType = (mctNone, mctMPSetup, mctDeletePlayer);

  TKMMapEdMissionPlayers = class
  private
    fPlayerIdToConfirm: TKMHandID;
    fConfirmationType: TKMMapEdConfirmationType;

    procedure Mission_PlayerTypesChange(Sender: TObject);
    procedure Mission_PlayerTypesAllClick(Sender: TObject);
    procedure Mission_PlayerIdUpdate;
    procedure PlayerDelete_Click(Sender: TObject);
    procedure PlayerDeleteConfirm_Click(Sender: TObject);
    procedure PlayerMPSetup_Click(Sender: TObject);
    procedure ClosePlayerTypes_Click(Sender: TObject);

    procedure DoConfirm(aVisible: Boolean);
  protected
    Panel_PlayerTypes: TKMPopUpPanel;
      ChkBox_PlayerTypes: array [0..MAX_HANDS-1, TKMMapEdPlayerType] of TKMCheckBox;
      Button_PlayerMPSetup: array [0..MAX_HANDS-1] of TKMButtonFlat;
      Button_PlayerDelete: array [0..MAX_HANDS-1] of TKMButtonFlat;
      ChkBox_PlayerTypesAll: array [mptHuman..mptAdvancedAI] of TKMCheckBox;
      Label_PlayerTypesAll: TKMLabel;
      Label_PlayerId: array [0..MAX_HANDS-1] of TKMLabel;
      Button_Close: TKMButton;

    PopUp_Confirm_Player: TKMPopUpMenu;
      Image_Confirm_Player: TKMImage;
      Button_PlayerConfirm, Button_PlayerConfirmCancel: TKMButton;
      Label_PlayerConfirmTitle, Label_PlayerConfirmWarn: TKMLabel;
  public
    constructor Create(aParent: TKMPanel);

    procedure KeyDown(Key: Word; Shift: TShiftState; var aHandled: Boolean);

    procedure Show;
    function Visible: Boolean;
    procedure Hide;

    procedure UpdatePlayerTypes;
  end;


implementation
uses
  KM_Game,
  KM_HandsCollection, KM_Hand,
  KM_ResTexts, KM_ResFonts, KM_ResTypes,
  KM_RenderUI;

const
  PANEL_W  = 300;
  BTN_MPSETUP_W = 24;
  BTN_DELETE_W = 22;
  LINE_H = 26;
  ICON_SPACE_W = 25;
  ICON_SPACE_H = 32;
  CONF_W = 500;
  CONF_H = 260;
  CONF_BTN_W = 170;
  CONF_BTN_PAD = 40;

  PLAYER_TYPE_TX: array [mptHuman..mptAdvancedAI] of Integer = (TX_PLAYER_HUMAN, TX_AI_PLAYER_CLASSIC, TX_AI_PLAYER_ADVANCED);

{ TKMMapEdMissionPlayers }
constructor TKMMapEdMissionPlayers.Create(aParent: TKMPanel);
var
  I, top, panelH: Integer;
  MPT: TKMMapEdPlayerType;
begin
  inherited Create;

  fConfirmationType := mctNone;

  panelH := LINE_H * MAX_HANDS + 80;

  Panel_PlayerTypes := TKMPopUpPanel.Create(aParent.MasterParent, PANEL_W, panelH + 20, gResTexts[TX_MAPED_PLAYERS_TYPE],
                                            pubgitYellow, False, False);
  top := 0;
  TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 20, 20, '#', fntGrey, taLeft);

  with TKMLabel.Create(Panel_PlayerTypes.ItemsPanel, 33, top, 30, 20, gResTexts[TX_MAPED_PLAYERS_DEFAULT_SHORT], fntGrey, taLeft) do
    Hint := gResTexts[TX_MAPED_PLAYERS_DEFAULT];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,84, top, 60, 20, 588, rxGui) do
    Hint := gResTexts[TX_PLAYER_HUMAN];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,127, top, 20, 20,  62, rxGuiMain) do
    Hint := gResTexts[TX_AI_PLAYER_CLASSIC];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,169, top, 20, 20,  74, rxGuiMain) do
    Hint := gResTexts[TX_AI_PLAYER_ADVANCED];

  Inc(top, 25);
  for I := 0 to MAX_HANDS - 1 do
  begin

    Label_PlayerId[I] := TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 20, 20, IntToStr(I+1), fntOutline, taLeft);

    for MPT := Low(TKMMapEdPlayerType) to High(TKMMapEdPlayerType) do
    begin
      ChkBox_PlayerTypes[I,MPT] := TKMCheckBox.Create(Panel_PlayerTypes.ItemsPanel, 43 + Ord(MPT)*42, top - 2, 20, 20, '', fntMetal);
      ChkBox_PlayerTypes[I,MPT].Tag     := I;
      ChkBox_PlayerTypes[I,MPT].OnClick := Mission_PlayerTypesChange;
    end;

    Button_PlayerMPSetup[I] := TKMButtonFlat.Create(Panel_PlayerTypes.ItemsPanel,
                                                   ChkBox_PlayerTypes[I, mptAdvancedAI].Right + 20, top - 5,
                                                   BTN_MPSETUP_W, BTN_MPSETUP_W, 678);
    Button_PlayerMPSetup[I].Hint := Format(gResTexts[TX_MAPED_PLAYER_AI_MP_SETUP_HINT],  [I + 1]);
    Button_PlayerMPSetup[I].Tag := I;
    Button_PlayerMPSetup[I].OnClick := PlayerMPSetup_Click;

    Button_PlayerDelete[I] := TKMButtonFlat.Create(Panel_PlayerTypes.ItemsPanel,
                                                   Button_PlayerMPSetup[I].Right + 20, top - 4,
                                                   BTN_DELETE_W, BTN_DELETE_W, 340);
    Button_PlayerDelete[I].Hint := Format(gResTexts[TX_MAPED_PLAYER_DELETE_HINT], [I + 1]);
    Button_PlayerDelete[I].Tag := I;
    Button_PlayerDelete[I].OnClick := PlayerDelete_Click;

    Inc(top, LINE_H);
  end;

  Label_PlayerTypesAll := TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 75, 20, gResTexts[TX_MAPED_PLAYER_TYPE_ALLOW_ALL],
                                          fntOutline, taLeft);

  for MPT := Low(ChkBox_PlayerTypesAll) to High(ChkBox_PlayerTypesAll) do
  begin
    ChkBox_PlayerTypesAll[MPT] := TKMCheckBox.Create(Panel_PlayerTypes.ItemsPanel, 43 + Ord(MPT)*42, top - 2, 20, 20, '', fntMetal, True);
    ChkBox_PlayerTypesAll[MPT].Tag     := Ord(MPT);
    ChkBox_PlayerTypesAll[MPT].Hint    := Format(gResTexts[TX_MAPED_PLAYER_TYPE_ALLOW_ALL_HINT],
                                               [gResTexts[PLAYER_TYPE_TX[MPT]]]);
    ChkBox_PlayerTypesAll[MPT].OnClick := Mission_PlayerTypesAllClick;
  end;<commit_msg>Minor MapEd UI improvement<commit_after>unit KM_GUIMapEdMissionPlayers;
{$I KaM_Remake.inc}
interface
uses
  {$IFDEF MSWindows} Windows, {$ENDIF}
  {$IFDEF Unix} LCLIntf, LCLType, {$ENDIF}
  Classes, SysUtils,
  KM_Controls, KM_ControlsBase, KM_ControlsPopUp, KM_ControlsSwitch,
  KM_Defaults, KM_Pics;

type
  TKMMapEdPlayerType = (mptDefault, mptHuman, mptClassicAI, mptAdvancedAI);

  TKMMapEdConfirmationType = (mctNone, mctMPSetup, mctDeletePlayer);

  TKMMapEdMissionPlayers = class
  private
    fPlayerIdToConfirm: TKMHandID;
    fConfirmationType: TKMMapEdConfirmationType;

    procedure Mission_PlayerTypesChange(Sender: TObject);
    procedure Mission_PlayerTypesAllClick(Sender: TObject);
    procedure Mission_PlayerIdUpdate;
    procedure PlayerDelete_Click(Sender: TObject);
    procedure PlayerDeleteConfirm_Click(Sender: TObject);
    procedure PlayerMPSetup_Click(Sender: TObject);
    procedure ClosePlayerTypes_Click(Sender: TObject);

    procedure DoConfirm(aVisible: Boolean);
  protected
    Panel_PlayerTypes: TKMPopUpPanel;
      ChkBox_PlayerTypes: array [0..MAX_HANDS-1, TKMMapEdPlayerType] of TKMCheckBox;
      Button_PlayerMPSetup: array [0..MAX_HANDS-1] of TKMButtonFlat;
      Button_PlayerDelete: array [0..MAX_HANDS-1] of TKMButtonFlat;
      ChkBox_PlayerTypesAll: array [mptHuman..mptAdvancedAI] of TKMCheckBox;
      Label_PlayerTypesAll: TKMLabel;
      Label_PlayerId: array [0..MAX_HANDS-1] of TKMLabel;
      Button_Close: TKMButton;

    PopUp_Confirm_Player: TKMPopUpMenu;
      Image_Confirm_Player: TKMImage;
      Button_PlayerConfirm, Button_PlayerConfirmCancel: TKMButton;
      Label_PlayerConfirmTitle, Label_PlayerConfirmWarn: TKMLabel;
  public
    constructor Create(aParent: TKMPanel);

    procedure KeyDown(Key: Word; Shift: TShiftState; var aHandled: Boolean);

    procedure Show;
    function Visible: Boolean;
    procedure Hide;

    procedure UpdatePlayerTypes;
  end;


implementation
uses
  KM_Game,
  KM_HandsCollection, KM_Hand,
  KM_ResTexts, KM_ResFonts, KM_ResTypes,
  KM_RenderUI;

const
  PANEL_W  = 300;
  BTN_MPSETUP_W = 24;
  BTN_DELETE_W = 22;
  LINE_H = 26;
  ICON_SPACE_W = 25;
  ICON_SPACE_H = 32;
  CONF_W = 500;
  CONF_H = 260;
  CONF_BTN_W = 170;
  CONF_BTN_PAD = 40;

  PLAYER_TYPE_TX: array [mptHuman..mptAdvancedAI] of Integer = (TX_PLAYER_HUMAN, TX_AI_PLAYER_CLASSIC, TX_AI_PLAYER_ADVANCED);

{ TKMMapEdMissionPlayers }
constructor TKMMapEdMissionPlayers.Create(aParent: TKMPanel);
var
  I, top, panelH: Integer;
  MPT: TKMMapEdPlayerType;
begin
  inherited Create;

  fConfirmationType := mctNone;

  panelH := LINE_H * MAX_HANDS + 80;

  Panel_PlayerTypes := TKMPopUpPanel.Create(aParent.MasterParent, PANEL_W, panelH + 20, gResTexts[TX_MAPED_PLAYERS_TYPE],
                                            pubgitYellow, False, False);
  top := 0;
  TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 20, 20, '#', fntGrey, taLeft);

  with TKMLabel.Create(Panel_PlayerTypes.ItemsPanel, 33, top, 30, 20, gResTexts[TX_MAPED_PLAYERS_DEFAULT_SHORT], fntGrey, taLeft) do
    Hint := gResTexts[TX_MAPED_PLAYERS_DEFAULT];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,84, top, 60, 20, 588, rxGui) do
    Hint := gResTexts[TX_PLAYER_HUMAN];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,127, top, 20, 20,  62, rxGuiMain) do
    Hint := gResTexts[TX_AI_PLAYER_CLASSIC];
  with TKMImage.Create(Panel_PlayerTypes.ItemsPanel,169, top, 20, 20,  74, rxGuiMain) do
    Hint := gResTexts[TX_AI_PLAYER_ADVANCED];

  Inc(top, 25);
  for I := 0 to MAX_HANDS - 1 do
  begin

    Label_PlayerId[I] := TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 20, 20, IntToStr(I+1), fntOutline, taLeft);

    for MPT := Low(TKMMapEdPlayerType) to High(TKMMapEdPlayerType) do
    begin
      ChkBox_PlayerTypes[I,MPT] := TKMCheckBox.Create(Panel_PlayerTypes.ItemsPanel, 43 + Ord(MPT)*42, top - 2, 20, 20, '', fntMetal);
      ChkBox_PlayerTypes[I,MPT].Tag     := I;
      ChkBox_PlayerTypes[I,MPT].OnClick := Mission_PlayerTypesChange;
    end;

    Button_PlayerMPSetup[I] := TKMButtonFlat.Create(Panel_PlayerTypes.ItemsPanel,
                                                   ChkBox_PlayerTypes[I, mptAdvancedAI].Right + 20, top - 5,
                                                   BTN_MPSETUP_W, BTN_MPSETUP_W, 678);
    Button_PlayerMPSetup[I].Hint := Format(gResTexts[TX_MAPED_PLAYER_AI_MP_SETUP_HINT],  [I + 1]);
    Button_PlayerMPSetup[I].Tag := I;
    Button_PlayerMPSetup[I].OnClick := PlayerMPSetup_Click;
    Button_PlayerMPSetup[I].BackAlpha := 0.2;

    Button_PlayerDelete[I] := TKMButtonFlat.Create(Panel_PlayerTypes.ItemsPanel,
                                                   Button_PlayerMPSetup[I].Right + 20, top - 4,
                                                   BTN_DELETE_W, BTN_DELETE_W, 340);
    Button_PlayerDelete[I].Hint := Format(gResTexts[TX_MAPED_PLAYER_DELETE_HINT], [I + 1]);
    Button_PlayerDelete[I].Tag := I;
    Button_PlayerDelete[I].OnClick := PlayerDelete_Click;
    Button_PlayerDelete[I].BackAlpha := 0.2;

    Inc(top, LINE_H);
  end;

  Label_PlayerTypesAll := TKMLabel.Create(Panel_PlayerTypes.ItemsPanel,  13, top, 75, 20, gResTexts[TX_MAPED_PLAYER_TYPE_ALLOW_ALL],
                                          fntOutline, taLeft);

  for MPT := Low(ChkBox_PlayerTypesAll) to High(ChkBox_PlayerTypesAll) do
  begin
    ChkBox_PlayerTypesAll[MPT] := TKMCheckBox.Create(Panel_PlayerTypes.ItemsPanel, 43 + Ord(MPT)*42, top - 2, 20, 20, '', fntMetal, True);
    ChkBox_PlayerTypesAll[MPT].Tag     := Ord(MPT);
    ChkBox_PlayerTypesAll[MPT].Hint    := Format(gResTexts[TX_MAPED_PLAYER_TYPE_ALLOW_ALL_HINT],
                                               [gResTexts[PLAYER_TYPE_TX[MPT]]]);
    ChkBox_PlayerTypesAll[MPT].OnClick := Mission_PlayerTypesAllClick;
  end;
{'fraction_non_alphanumeric': 0.09646526205815775, 'fraction_numerical': 0.02211387776423472, 'mean_word_length': 3.7942404006677797, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6984575', 'n_tokens_mistral': 4433, 'n_tokens_neox': 4051, 'n_words': 722}