aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UDataBase.pas
diff options
context:
space:
mode:
authorGogolNr1 <GogolNr1@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-12 11:19:31 +0000
committerGogolNr1 <GogolNr1@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-07-12 11:19:31 +0000
commit215f80b357450ff0b0c52a3aac017a0998acc0b7 (patch)
treee34c4a54b0c51fbbb661504047a944be08d6066e /Game/Code/Classes/UDataBase.pas
parentbe2e6581b4708d5f05e450e7c3d1f8e100a77bc8 (diff)
downloadusdx-215f80b357450ff0b0c52a3aac017a0998acc0b7.tar.gz
usdx-215f80b357450ff0b0c52a3aac017a0998acc0b7.tar.xz
usdx-215f80b357450ff0b0c52a3aac017a0998acc0b7.zip
unit UScreenStatMain;
interface {$IFDEF FPC} {$MODE Delphi} {$ENDIF} {$I switches.inc} 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; CharCode: WideChar; PressedDown: Boolean): Boolean; override; procedure onShow; override; procedure SetAnimationProgress(Progress: real); override; procedure SetOverview; end; implementation uses UGraphic, UDataBase, USongs, USong, ULanguage, UCommon, {$IFDEF win32} windows, {$ELSE} sysconst, {$ENDIF} ULog; function TScreenStatMain.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; begin Result := true; If (PressedDown) Then begin // Key Down // check normal keys case WideCharUpperCase(CharCode)[1] of 'Q': begin Result := false; Exit; end; end; // check special keys case PressedKey of SDLK_ESCAPE, SDLK_BACKSPACE : begin Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenMain); end; SDLK_RETURN: begin //Exit Button Pressed if Interaction = 4 then begin AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenMain); end else //One of the Stats Buttons Pressed begin AudioPlayback.PlaySound(SoundLib.Back); 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 Songs.SongList.Count -1 do if (TSong(Songs.SongList[I]).Video <> '') then Inc(SongswithVid); end; procedure TScreenStatMain.onShow; begin inherited; //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; 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)*) DateTimeToSystemTime(Database.GetStatReset, ResetTime); // ResetTime := GetFileCreation(Database.Filename); {$IFDEF MSWINDOWS} 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 := Songs.SongList.Count; 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. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1186 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UDataBase.pas')
-rw-r--r--Game/Code/Classes/UDataBase.pas34
1 files changed, 29 insertions, 5 deletions
diff --git a/Game/Code/Classes/UDataBase.pas b/Game/Code/Classes/UDataBase.pas
index 8f5ebf50..bbdce9ec 100644
--- a/Game/Code/Classes/UDataBase.pas
+++ b/Game/Code/Classes/UDataBase.pas
@@ -55,6 +55,7 @@ type
Function GetStats(var Stats: AStatResult; const Typ, Count: Byte; const Page: Cardinal; const Reversed: Boolean): Boolean;
Function GetTotalEntrys(const Typ: Byte): Cardinal;
+ Function GetStatReset: TDateTime;
end;
var
@@ -71,6 +72,7 @@ uses
const
cUS_Scores = 'us_scores';
cUS_Songs = 'us_songs';
+ cUS_Statistics_Info = 'us_statistics_info';
//--------------------
//Create - Opens Database and Create Tables if not Exist
@@ -97,7 +99,14 @@ begin
ScoreDB.execsql('CREATE TABLE `'+cUS_Songs+'` (`ID` INTEGER PRIMARY KEY, `Artist` VARCHAR( 255 ) NOT NULL , `Title` VARCHAR( 255 ) NOT NULL , `TimesPlayed` int(5) NOT NULL );');
debugWriteln( 'TDataBaseSystem.Init - CREATED US_Songs' );
end;
-
+
+ if not ScoreDB.TableExists( cUS_Statistics_Info ) then
+ begin
+ ScoreDB.execsql('CREATE TABLE `'+cUS_Statistics_Info+'` (`ResetTime` VARCHAR(17) );');
+ ScoreDB.execsql('INSERT INTO `'+cUS_Statistics_Info+'` (`ResetTime`) VALUES ("'+datetimetostr(now)+'");');
+ debugWriteln( 'TDataBaseSystem.Init - CREATED US_Statistics_Info' );
+ end;
+
//Not possible because of String Limitation to 255 Chars //Need to rewrite Wrapper
{if not ScoreDB.TableExists('US_SongCache') then
ScoreDB.ExecSQL('CREATE TABLE `US_SongCache` (`Path` VARCHAR( 255 ) NOT NULL , `Filename` VARCHAR( 255 ) NOT NULL , `Title` VARCHAR( 255 ) NOT NULL , `Artist` VARCHAR( 255 ) NOT NULL , `Folder` VARCHAR( 255 ) NOT NULL , `Genre` VARCHAR( 255 ) NOT NULL , `Edition` VARCHAR( 255 ) NOT NULL , `Language` VARCHAR( 255 ) NOT NULL , `Creator` VARCHAR( 255 ) NOT NULL , `Cover` VARCHAR( 255 ) NOT NULL , `Background` VARCHAR( 255 ) NOT NULL , `Video` VARCHAR( 255 ) NOT NULL , `VideoGap` FLOAT NOT NULL , `Gap` FLOAT NOT NULL , `Start` FLOAT NOT NULL , `Finish` INT( 11 ) NOT NULL , `BPM` INT( 5 ) NOT NULL , `Relative` BOOLEAN NOT NULL , `NotesGap` INT( 11 ) NOT NULL);');}
@@ -148,7 +157,7 @@ begin
while not TableData.Eof do //Go through all Entrys
begin //Add one Entry to Array
- Difficulty := StrToIntDef(TableData.FieldAsString(TableData.FieldIndex['Difficulty']), -1);
+ Difficulty := StrToIntDef(TableData.FieldAsString(TableData.FieldIndex['Difficulty']), -1);
if (Difficulty >= 0) AND (Difficulty <= 2) then
begin
SetLength(Song.Score[Difficulty], Length(Song.Score[Difficulty]) + 1);
@@ -362,9 +371,8 @@ begin
Result := ScoreDB.GetTableValue(Query);
except
- // TODO : JB_Linux - Why do we get these exceptions on linux !!
- on E:ESQLiteException DO // used to handle : Could not retrieve data "SELECT COUNT(`ID`) FROM `US_Songs`;" : SQL logic error or missing database
- // however, we should pre-empt this error... and make sure the database DOES exist.
+ // TODO : JB_Linux - Why do we get these exceptions on linux !! -> should be solved!
+ on E:ESQLiteException DO
begin
exit;
end;
@@ -372,4 +380,20 @@ begin
end;
+//--------------------
+//GetStatReset - Get reset date of statistic data
+//--------------------
+Function TDataBaseSystem.GetStatReset: TDateTime;
+var
+ Query: String;
+ TableData: TSqliteTable;
+begin
+ if not assigned( ScoreDB ) then
+ exit;
+
+ Query := 'SELECT `ResetTime` FROM `'+cUS_Statistics_Info+'`;';
+ TableData := ScoreDB.GetTable(Query);
+ result:=StrToDateTime(TableData.Fields[0]);
+end;
+
end.