<commit_before>﻿unit KM_GUIGameStats;
{$I KaM_Remake.inc}
interface
uses
  Classes, Math, StrUtils, SysUtils,
  KM_Controls, KM_Defaults, KM_Houses,
  KM_InterfaceGame, KM_ResHouses, KM_CommonTypes;


type
  TKMGUIGameStats = class
  private
    fOnShowStats: TNotifyEvent;
    fHouseSketch: TKMHouseSketchEdit;
    fLastHouseUIDs: array [HOUSE_MIN..HOUSE_MAX] of Cardinal;
    fSetViewportEvent: TPointFEvent;
    procedure House_Stat_Clicked(Sender: TObject);
    procedure ResetUIDs;
  protected
    Panel_Stats: TKMPanel;
      Panel_StatBlock: array [0..STATS_LINES_CNT-1] of TKMPanel;
        Stat_HousePic: array [HOUSE_MIN..HOUSE_MAX] of TKMImage;
        Stat_UnitPic: array [CITIZEN_MIN..CITIZEN_MAX] of TKMImage;
        Stat_HouseQty, Stat_HouseWip: array [HOUSE_MIN..HOUSE_MAX] of TKMLabel;
        Stat_UnitQty, Stat_UnitWip: array [CITIZEN_MIN..CITIZEN_MAX] of TKMLabel;
      Button_ShowStats: TKMButtonFlat;
  public
    constructor Create(aParent: TKMPanel; aOnShowStats: TNotifyEvent; aSetViewportEvent: TPointFEvent);
    destructor Destroy; override;

    procedure Show;
    procedure Hide;
    procedure Resize;
    procedure UpdateState;
    function Visible: Boolean;
  end;


implementation
uses
  KM_RenderUI, KM_HandsCollection, KM_ResTexts, KM_Resource, KM_ResFonts, KM_ResUnits,
  KM_Hand, KM_Pics, KM_Points;


{ TKMGUIGameStats }
constructor TKMGUIGameStats.Create(aParent: TKMPanel; aOnShowStats: TNotifyEvent; aSetViewportEvent: TPointFEvent);
const
  HOUSE_W = 30;
  UNIT_W = 26;
  BEVEL_LAYER = 1;
  IMAGE_LAYER = 2;
  TEXT_LAYER = 3;
var
  I, K: Integer;
  HT: TKMHouseType;
  UT: TKMUnitType;
  OffX: Integer;
begin
  inherited Create;

  fOnShowStats := aOnShowStats;
  fSetViewportEvent := aSetViewportEvent;
  fHouseSketch := TKMHouseSketchEdit.Create;
  ResetUIDs;

  Panel_Stats := TKMPanel.Create(aParent, TB_PAD, 44, TB_WIDTH, 332);
  Panel_Stats.Anchors := [anLeft, anTop, anBottom];

    for I := 0 to High(StatPlan) do
    begin
      //Houses block
      Panel_StatBlock[I] := TKMPanel.Create(Panel_Stats, 0, 0, 30, 30);
      with TKMBevel.Create(Panel_StatBlock[I], 0, 0, 30, 30, BEVEL_LAYER) do
        AnchorsStretch;

      OffX := 0;
      for K := Low(StatPlan[I].HouseType) to High(StatPlan[I].HouseType) do
        if StatPlan[I].HouseType[K] <> htNone then
        begin
          HT := StatPlan[I].HouseType[K];
          Stat_HousePic[HT] := TKMImage.Create(Panel_StatBlock[I], OffX, 0, HOUSE_W, 30, 41, rxGui, IMAGE_LAYER); //Filled with [?] at start
          Stat_HousePic[HT].Hint := gRes.Houses[HT].HouseName;
          Stat_HousePic[HT].ImageCenter;
          Stat_HousePic[HT].Tag := Byte(HT);
          Stat_HouseWip[HT] := TKMLabel.Create(Panel_StatBlock[I], OffX + HOUSE_W  ,  0,  '', fntGrey, taRight, TEXT_LAYER);
          Stat_HouseWip[HT].Hitable := False;
          Stat_HouseQty[HT] := TKMLabel.Create(Panel_StatBlock[I], OffX + HOUSE_W-2, 16, '-', fntGrey, taRight, TEXT_LAYER);
          Stat_HouseQty[HT].Hitable := False;
          Inc(OffX, HOUSE_W);
        end;

      for K := Low(StatPlan[I].UnitType) to High(StatPlan[I].UnitType) do
        if StatPlan[I].UnitType[K] <> utNone then
        begin
          UT := StatPlan[I].UnitType[K];
          Stat_UnitPic[UT] := TKMImage.Create(Panel_StatBlock[I], OffX, 0, UNIT_W, 30, gRes.Units[UT].GUIIcon, rxGui, IMAGE_LAYER);
          Stat_UnitPic[UT].Hint := gRes.Units[UT].GUIName;
          Stat_UnitPic[UT].ImageCenter;
          Stat_UnitWip[UT] := TKMLabel.Create(Panel_StatBlock[I], OffX + UNIT_W  ,  0,  '', fntGrey, taRight, TEXT_LAYER);
          Stat_UnitWip[UT].Hitable := False;
          Stat_UnitQty[UT] := TKMLabel.Create(Panel_StatBlock[I], OffX + UNIT_W-2, 16, '-', fntGrey, taRight, TEXT_LAYER);
          Stat_UnitQty[UT].Hitable := False;
          Inc(OffX, UNIT_W);
        end;
      Panel_StatBlock[I].Width := OffX;
    end;
    Button_ShowStats  := TKMButtonFlat.Create(Panel_Stats, TB_WIDTH - 30, 0, 30, 30, 669, rxGui);
    Button_ShowStats.OnClick := fOnShowStats;
    Button_ShowStats.Hint := gResTexts[TX_GAME_MENU_SHOW_STATS_HINT];
end;


destructor TKMGUIGameStats.Destroy;
begin
  FreeAndNil(fHouseSketch);

  inherited
end;


//Resize stats page in a way to display data in more readable form
//Try to keep items in corresponding pairs and stack them when dont fit otherwise
procedure TKMGUIGameStats.Resize;
const
  PAD_X = 4;
  PAD_Y = 4;<commit_msg>do not use paint layers for Stats F3 window for now<commit_after>﻿unit KM_GUIGameStats;
{$I KaM_Remake.inc}
interface
uses
  Classes, Math, StrUtils, SysUtils,
  KM_Controls, KM_Defaults, KM_Houses,
  KM_InterfaceGame, KM_ResHouses, KM_CommonTypes;


type
  TKMGUIGameStats = class
  private
    fOnShowStats: TNotifyEvent;
    fHouseSketch: TKMHouseSketchEdit;
    fLastHouseUIDs: array [HOUSE_MIN..HOUSE_MAX] of Cardinal;
    fSetViewportEvent: TPointFEvent;
    procedure House_Stat_Clicked(Sender: TObject);
    procedure ResetUIDs;
  protected
    Panel_Stats: TKMPanel;
      Panel_StatBlock: array [0..STATS_LINES_CNT-1] of TKMPanel;
        Stat_HousePic: array [HOUSE_MIN..HOUSE_MAX] of TKMImage;
        Stat_UnitPic: array [CITIZEN_MIN..CITIZEN_MAX] of TKMImage;
        Stat_HouseQty, Stat_HouseWip: array [HOUSE_MIN..HOUSE_MAX] of TKMLabel;
        Stat_UnitQty, Stat_UnitWip: array [CITIZEN_MIN..CITIZEN_MAX] of TKMLabel;
      Button_ShowStats: TKMButtonFlat;
  public
    constructor Create(aParent: TKMPanel; aOnShowStats: TNotifyEvent; aSetViewportEvent: TPointFEvent);
    destructor Destroy; override;

    procedure Show;
    procedure Hide;
    procedure Resize;
    procedure UpdateState;
    function Visible: Boolean;
  end;


implementation
uses
  KM_RenderUI, KM_HandsCollection, KM_ResTexts, KM_Resource, KM_ResFonts, KM_ResUnits,
  KM_Hand, KM_Pics, KM_Points;


{ TKMGUIGameStats }
constructor TKMGUIGameStats.Create(aParent: TKMPanel; aOnShowStats: TNotifyEvent; aSetViewportEvent: TPointFEvent);
const
  HOUSE_W = 30;
  UNIT_W = 26;
var
  I, K: Integer;
  HT: TKMHouseType;
  UT: TKMUnitType;
  OffX: Integer;
begin
  inherited Create;

  fOnShowStats := aOnShowStats;
  fSetViewportEvent := aSetViewportEvent;
  fHouseSketch := TKMHouseSketchEdit.Create;
  ResetUIDs;

  Panel_Stats := TKMPanel.Create(aParent, TB_PAD, 44, TB_WIDTH, 332);
  Panel_Stats.Anchors := [anLeft, anTop, anBottom];

    for I := 0 to High(StatPlan) do
    begin
      //Houses block
      Panel_StatBlock[I] := TKMPanel.Create(Panel_Stats, 0, 0, 30, 30);
      with TKMBevel.Create(Panel_StatBlock[I], 0, 0, 30, 30) do
        AnchorsStretch;

      OffX := 0;
      for K := Low(StatPlan[I].HouseType) to High(StatPlan[I].HouseType) do
        if StatPlan[I].HouseType[K] <> htNone then
        begin
          HT := StatPlan[I].HouseType[K];
          Stat_HousePic[HT] := TKMImage.Create(Panel_StatBlock[I], OffX, 0, HOUSE_W, 30, 41, rxGui); //Filled with [?] at start
          Stat_HousePic[HT].Hint := gRes.Houses[HT].HouseName;
          Stat_HousePic[HT].ImageCenter;
          Stat_HousePic[HT].Tag := Byte(HT);
          Stat_HouseWip[HT] := TKMLabel.Create(Panel_StatBlock[I], OffX + HOUSE_W  ,  0,  '', fntGrey, taRight);
          Stat_HouseWip[HT].Hitable := False;
          Stat_HouseQty[HT] := TKMLabel.Create(Panel_StatBlock[I], OffX + HOUSE_W-2, 16, '-', fntGrey, taRight);
          Stat_HouseQty[HT].Hitable := False;
          Inc(OffX, HOUSE_W);
        end;

      for K := Low(StatPlan[I].UnitType) to High(StatPlan[I].UnitType) do
        if StatPlan[I].UnitType[K] <> utNone then
        begin
          UT := StatPlan[I].UnitType[K];
          Stat_UnitPic[UT] := TKMImage.Create(Panel_StatBlock[I], OffX, 0, UNIT_W, 30, gRes.Units[UT].GUIIcon, rxGui);
          Stat_UnitPic[UT].Hint := gRes.Units[UT].GUIName;
          Stat_UnitPic[UT].ImageCenter;
          Stat_UnitWip[UT] := TKMLabel.Create(Panel_StatBlock[I], OffX + UNIT_W  ,  0,  '', fntGrey, taRight);
          Stat_UnitWip[UT].Hitable := False;
          Stat_UnitQty[UT] := TKMLabel.Create(Panel_StatBlock[I], OffX + UNIT_W-2, 16, '-', fntGrey, taRight);
          Stat_UnitQty[UT].Hitable := False;
          Inc(OffX, UNIT_W);
        end;
      Panel_StatBlock[I].Width := OffX;
    end;
    Button_ShowStats  := TKMButtonFlat.Create(Panel_Stats, TB_WIDTH - 30, 0, 30, 30, 669, rxGui);
    Button_ShowStats.OnClick := fOnShowStats;
    Button_ShowStats.Hint := gResTexts[TX_GAME_MENU_SHOW_STATS_HINT];
end;


destructor TKMGUIGameStats.Destroy;
begin
  FreeAndNil(fHouseSketch);

  inherited
end;


//Resize stats page in a way to display data in more readable form
//Try to keep items in corresponding pairs and stack them when dont fit otherwise
procedure TKMGUIGameStats.Resize;
const
  PAD_X = 4;
  PAD_Y = 4;
{'fraction_non_alphanumeric': 0.1097379562879048, 'fraction_numerical': 0.012587252546057902, 'mean_word_length': 3.6170100369783413, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4654540', 'n_tokens_mistral': 3499, 'n_tokens_neox': 3226, 'n_words': 668}