aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Screens/UScreenStatMain.pas
blob: 4f46bec2a2bd4c27cee4ee843933116710dd7907 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
unit UScreenStatMain;

interface

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}


uses
  UMenu,
  SDL,
  SysUtils,
  UDisplay,
  UMusic,
  UIni,
  UThemes;

type
  TScreenStatMain = class(TMenu)
    private
      //Some Stat Value that don't need to be calculated 2 times
      SongswithVid: Cardinal;
    public
      TextOverview:    integer;
      constructor Create; override;
      function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
      procedure onShow; override;
      procedure SetAnimationProgress(Progress: real); override;

      procedure SetOverview;
  end;

implementation

uses UGraphic,
     UDataBase,
     USongs,
     ULanguage,
     UCommon,
     {$IFDEF win32}
     windows,
     {$ELSE}
     sysconst,
     {$ENDIF}
     ULog;

function TScreenStatMain.ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean;
begin
  Result := true;
  If (PressedDown) Then
  begin // Key Down
    case PressedKey of
      SDLK_Q:
        begin
          Result := false;
        end;

      SDLK_ESCAPE,
      SDLK_BACKSPACE :
        begin
          Ini.Save;
          AudioPlayback.PlayBack;
          FadeTo(@ScreenMain);
        end;
      SDLK_RETURN:
        begin
          //Exit Button Pressed
          if Interaction = 4 then
          begin
            AudioPlayback.PlayBack;
            FadeTo(@ScreenMain);
          end
          else //One of the Stats Buttons Pressed
          begin
            AudioPlayback.PlayBack;
            ScreenStatDetail.Typ := Interaction;
            FadeTo(@ScreenStatDetail);
          end;
        end;
      SDLK_LEFT:
      begin
          InteractPrev;
      end;
      SDLK_RIGHT:
      begin
          InteractNext;
      end;
      SDLK_UP:
      begin
          InteractPrev;
      end;
      SDLK_DOWN:
      begin
          InteractNext;
      end;
    end;
  end;
end;

constructor TScreenStatMain.Create;
var
  I:    integer;
begin
  inherited Create;

  TextOverview := AddText(Theme.StatMain.TextOverview);

  LoadFromTheme(Theme.StatMain);

  AddButton(Theme.StatMain.ButtonScores);
  if (Length(Button[0].Text)=0) then
    AddButtonText(14, 20, Theme.StatDetail.Description[0]);

  AddButton(Theme.StatMain.ButtonSingers);
  if (Length(Button[1].Text)=0) then
    AddButtonText(14, 20, Theme.StatDetail.Description[1]);

  AddButton(Theme.StatMain.ButtonSongs);
  if (Length(Button[2].Text)=0) then
    AddButtonText(14, 20, Theme.StatDetail.Description[2]);

  AddButton(Theme.StatMain.ButtonBands);
  if (Length(Button[3].Text)=0) then
    AddButtonText(14, 20, Theme.StatDetail.Description[3]);

  AddButton(Theme.StatMain.ButtonExit);
  if (Length(Button[4].Text)=0) then
    AddButtonText(14, 20, Theme.Options.Description[4]);

  Interaction := 0;

  //Set Songs with Vid
  SongswithVid := 0;
  For I := 0 to high(Songs.Song) do
    if (Songs.Song[I].Video <> '') then
      Inc(SongswithVid);
end;

procedure TScreenStatMain.onShow;
begin
  //Set Overview Text:
  SetOverview;
end;

procedure TScreenStatMain.SetOverview;
type
  TwSystemTime = record
    wYear,
    wMonth,
    wDayOfWeek,
    wDay,
    wHour,
    wMinute,
    wSecond,
    wMilliseconds: Word;
  end;
var
  Overview, Formatstr: String;
  I: Integer;
  //Some Vars to Save Attributes to
  A1, A2, A3: Integer;
  A4, A5: String;
  Result1, Result2: AStatResult;
  ResetTime: TSystemTime;
  
  {$IFDEF win32}
  function GetFileCreation(Filename: String): TSystemTime;
  var
    FindData: TWin32FindData;
    Handle: THandle;
  begin
    Handle := FindFirstFile(PChar(Filename), FindData);
    if Handle <> INVALID_HANDLE_VALUE then
    begin
      FileTimeToSystemTime(FindData.ftCreationTime, Result);
      windows.FindClose(Handle);
    end;
  end;

  {$ELSE}
  
  function GetFileCreation(Filename: String): TSystemTime;
  Var
    F,D : Longint;
  Begin
    F:=FileCreate( Filename );
    try
      D:=FileGetDate(F);
      DateTimeToSystemTime( FileDateToDateTime(D) , result);
    finally
      FileClose(F);
    end;
  end;
  {$ENDIF}
  
begin
  //Song Overview

  //Introduction
  Formatstr := Language.Translate ('STAT_OVERVIEW_INTRO');
  (*Format:
    %0:d Ultrastar Version
    %1:d Day of Reset (A1)
    %2:d Month of Reset (A2)
    %3:d Year of Reset (A3)*)

  ResetTime := GetFileCreation(Database.Filename);

  {$IFDEF win32}
    A1 := ResetTime.wDay;
    A2 := ResetTime.wMonth;
    A3 := ResetTime.wYear;
  {$ELSE}
    A1 := ResetTime.Day;
    A2 := ResetTime.Month;
    A3 := ResetTime.Year;
  {$ENDIF}
  
  
  try
    Overview := Format(Formatstr, [Language.Translate('US_VERSION'), A1, A2, A3]);
  except
    on E: EConvertError do
      Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_INTRO": ' + E.Message);
  end;

  Formatstr := Language.Translate ('STAT_OVERVIEW_SONG');
  {Format:
    %0:d Count Songs (A1)
    %1:d Count of Sung Songs (A2)
    %2:d Count of UnSung Songs
    %3:d Count of Songs with Video (A3)
    %4:s Name of the most popular Song}
  A1 := Length(Songs.Song);
  A2 := Database.GetTotalEntrys(2);

  A3 := SongswithVid;

  SetLength(Result1, 1);
  Database.GetStats(Result1, 2, 1, 0, False);
  A4 := Result1[0].Artist;
  A5 := Result1[0].Title;

  try
    Overview := Overview + '\n \n' + Format(Formatstr, [A1, A2, A1-A2, A3, A4, A5]);
  except
    on E: EConvertError do
      Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_SONG": ' + E.Message);
  end;

  //Player Overview
  Formatstr := Language.Translate ('STAT_OVERVIEW_PLAYER');
  {Format:
    %0:d Count Players (A1)
    %1:s Best Player (Result)
    %2:d Best Players Score
    %3:s Best Score Player (Result2)
    %4:d Best Score}
  A1 := Database.GetTotalEntrys(1);

  SetLength(Result1, 1);
  Database.GetStats(Result1, 1, 1, 0, False);

  SetLength(Result2, 1);
  Database.GetStats(Result2, 0, 1, 0, False);

  try
    Overview := Overview + '\n \n' + Format(Formatstr, [A1, Result1[0].Player, Result1[0].AverageScore, Result2[0].Singer, Result2[0].Score]);
  except
    on E: EConvertError do
      Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_PLAYER": ' + E.Message);
  end;

  Text[0].Text := Overview;
end;


procedure TScreenStatMain.SetAnimationProgress(Progress: real);
var I: Integer;
begin
  For I := 0 to high(Button) do
    Button[I].Texture.ScaleW := Progress;
end;

end.