From 6cdcfb402ce738dfc77b008fcb98fd1cda691eb5 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 19 Apr 2007 18:53:22 +0000 Subject: Added Statistic Screens to C0de and to Theme Moved some Translated Strings from UScreenPartyOptions to UTheme to use it with the Statistic Screens, too. Fixed use of /n Tag istead of the correct \n git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@118 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UDataBase.pas | 131 ++++++++++++++++++++++++++++++++++++++++ Game/Code/Classes/UGraphic.pas | 36 +++++++---- Game/Code/Classes/UThemes.pas | 33 +++++++++- 3 files changed, 184 insertions(+), 16 deletions(-) (limited to 'Game/Code/Classes') diff --git a/Game/Code/Classes/UDataBase.pas b/Game/Code/Classes/UDataBase.pas index 1ebc18db..0e5a4a3f 100644 --- a/Game/Code/Classes/UDataBase.pas +++ b/Game/Code/Classes/UDataBase.pas @@ -8,6 +8,26 @@ uses USongs, SQLiteTable3; //DataBaseSystem - Class including all DB Methods //-------------------- type + TStatResult = record + Case Typ: Byte of + 0: (Singer: ShortString; + Score: Word; + Difficulty: Byte; + SongArtist: ShortString; + SongTitle: ShortString); + + 1: (Player: ShortString; + AverageScore: Word); + + 2: (Artist: ShortString; + Title: ShortString; + TimesSung: Word); + + 3: (ArtistName: ShortString; + TimesSungtot: Word); + end; + AStatResult = Array of TStatResult; + TDataBaseSystem = class private ScoreDB: TSqliteDatabase; @@ -15,12 +35,17 @@ type public + property Filename: String read sFilename; + Destructor Free; Procedure Init(const Filename: string); procedure ReadScore(var Song: TSong); procedure AddScore(var Song: TSong; Level: integer; Name: string; Score: integer); procedure WriteScore(var Song: TSong); + + Function GetStats(var Stats: AStatResult; const Typ, Count: Byte; const Page: Cardinal; const Reversed: Boolean): Boolean; + Function GetTotalEntrys(const Typ: Byte): Cardinal; end; var @@ -160,4 +185,110 @@ begin end; end; +//-------------------- +//GetStats - Write some Stats to Array, Returns True if Chossen Page has Entrys +//Case Typ of +//0 - Best Scores +//1 - Best Singers +//2 - Most sung Songs +//3 - Most popular Band +//-------------------- +Function TDataBaseSystem.GetStats(var Stats: AStatResult; const Typ, Count: Byte; const Page: Cardinal; const Reversed: Boolean): Boolean; +var + Query: String; + TableData: TSqliteTable; +begin + Result := False; + + if (Length(Stats) < Count) then + Exit; + + {Todo: + Add Prevention that only Players with more than 5 Scores are Selected at Typ 2} + + //Create Query + Case Typ of + 0: Query := 'SELECT `Player` , `Difficulty` , `Score` , `Artist` , `Title` FROM `US_Scores` INNER JOIN `US_Songs` ON (`SongID` = `ID`) ORDER BY `Score`'; + 1: Query := 'SELECT `Player` , (Sum(`Score`) / COUNT(`Score`)) FROM `US_Scores` GROUP BY `Player` ORDER BY (Sum(`Score`) / COUNT(`Score`))'; + 2: Query := 'SELECT `Artist` , `Title` , `TimesPlayed` FROM `US_Songs` ORDER BY `TimesPlayed`'; + 3: Query := 'SELECT `Artist` , Sum(`TimesPlayed`) FROM `US_Songs` GROUP BY `Artist` ORDER BY Sum(`TimesPlayed`)'; + end; + + //Add Order Direction + If Reversed then + Query := Query + ' ASC' + else + Query := Query + ' DESC'; + + //Add Limit + Query := Query + ' LIMIT ' + InttoStr(Count * Page) + ', ' + InttoStr(Count) + ';'; + + //Execute Query + //try + TableData := ScoreDB.GetTable(Query); + {except + exit; + end;} + + //if Result empty -> Exit + if (TableData.RowCount < 1) then + exit; + + //Copy Result to Stats Array + while not TableData.Eof do + begin + Stats[TableData.Row].Typ := Typ; + + Case Typ of + 0:begin + Stats[TableData.Row].Singer := TableData.Fields[0]; + + Stats[TableData.Row].Difficulty := StrtoIntDef(TableData.Fields[1], 0); + + Stats[TableData.Row].Score := StrtoIntDef(TableData.Fields[2], 0){TableData.FieldAsInteger(2)}; + Stats[TableData.Row].SongArtist := TableData.Fields[3]; + Stats[TableData.Row].SongTitle := TableData.Fields[4]; + end; + + 1:begin + Stats[TableData.Row].Player := TableData.Fields[0]; + Stats[TableData.Row].AverageScore := TableData.FieldAsInteger(1); + end; + + 2:begin + Stats[TableData.Row].Artist := TableData.Fields[0]; + Stats[TableData.Row].Title := TableData.Fields[1]; + Stats[TableData.Row].TimesSung := StrtoIntDef(TableData.Fields[2], 0); + end; + + 3:begin + Stats[TableData.Row].ArtistName := TableData.Fields[0]; + Stats[TableData.Row].TimesSungtot := StrtoIntDef(TableData.Fields[1], 0); + end; + + end; + + TableData.Next; + end; + + Result := True; +end; + +//-------------------- +//GetTotalEntrys - Get Total Num of entrys for a Stats Query +//-------------------- +Function TDataBaseSystem.GetTotalEntrys(const Typ: Byte): Cardinal; +var Query: String; +begin + //Create Query + Case Typ of + 0: Query := 'SELECT COUNT(`SongID`) FROM `US_Scores`;'; + 1: Query := 'SELECT COUNT(DISTINCT `Player`) FROM `US_Scores`;'; + 2: Query := 'SELECT COUNT(`ID`) FROM `US_Songs`;'; + 3: Query := 'SELECT COUNT(DISTINCT `Artist`) FROM `US_Songs`;'; + end; + + Result := ScoreDB.GetTableValue(Query); +end; + end. diff --git a/Game/Code/Classes/UGraphic.pas b/Game/Code/Classes/UGraphic.pas index b909e49f..342efe3c 100644 --- a/Game/Code/Classes/UGraphic.pas +++ b/Game/Code/Classes/UGraphic.pas @@ -7,7 +7,8 @@ uses UScreenOptionsGraphics, UScreenOptionsSound, UScreenOptionsLyrics, UScreenOptionsThemes, UScreenOptionsRecord, UScreenOptionsAdvanced, UScreenSong, UScreenSing, UScreenScore, UScreenTop5, UScreenEditSub, UScreenEdit, UScreenEditConvert, UScreenEditHeader, UScreenOpen, UThemes, USkins, UScreenSongMenu, UScreenSongJumpto, - {Party Screens} UScreenSingModi, UScreenPartyNewRound, UScreenPartyScore, UScreenPartyOptions, UScreenPartyWin, UScreenPartyPlayer; + {Party Screens} UScreenSingModi, UScreenPartyNewRound, UScreenPartyScore, UScreenPartyOptions, UScreenPartyWin, UScreenPartyPlayer, + {Stats Screens} UScreenStatMain, UScreenStatDetail; type TRecR = record @@ -62,6 +63,10 @@ var ScreenPartyOptions: TScreenPartyOptions; ScreenPartyPlayer: TScreenPartyPlayer; + //StatsScreens + ScreenStatMain: TScreenStatMain; + ScreenStatDetail: TScreenStatDetail; + Tex_Left: array[0..6] of TTexture; Tex_Mid: array[0..6] of TTexture; @@ -221,20 +226,27 @@ var Icon: TIcon; Res: TResourceStream; ISurface: PSDL_Surface; + Pixel: PByteArray; begin Log.LogStatus('LoadOpenGL', 'Initialize3D'); Log.BenchmarkStart(2); LoadOpenGL; - {//Load Icon + Log.LogStatus('SDL_Init', 'Initialize3D'); + if ( SDL_Init(SDL_INIT_VIDEO or SDL_INIT_AUDIO)= -1 ) then begin + Log.LogError('SDL_Init Failed', 'Initialize3D'); + exit; + end; + + { //Load Icon Res := TResourceStream.CreateFromID(HInstance, 3, RT_ICON); Icon := TIcon.Create; Icon.LoadFromStream(Res); Res.Free; - + Icon. //Create icon Surface - SDL_CreateRGBSurface ( + SDL_CreateRGBSurfaceFrom ( SDL_SWSURFACE, Icon.Width, Icon.Height, @@ -243,18 +255,12 @@ begin 32 or 16, 8 or 4, 2 or 1); - SDL_BlitSurface( //} - + //SDL_BlitSurface( - SDL_WM_SetIcon(SDL_LoadBMP('us.ico'), 0); //} - Log.LogStatus('SDL_Init', 'Initialize3D'); - if ( SDL_Init(SDL_INIT_VIDEO or SDL_INIT_AUDIO)= -1 ) then begin - Log.LogError('SDL_Init Failed', 'Initialize3D'); - exit; - end; + SDL_WM_SetIcon(SDL_LoadBMP('DEFAULT_WINDOW_ICON'), 0); //} - SDL_WM_SetCaption(PChar(Title), 'WM_DEFAULT'); + SDL_WM_SetCaption(PChar(Title), nil); InitializeScreen; @@ -433,6 +439,10 @@ begin Log.BenchmarkEnd(3); Log.LogBenchmark('====> Screen PartyOptions', 3); Log.BenchmarkStart(3); ScreenPartyPlayer := TScreenPartyPlayer.Create; Log.BenchmarkEnd(3); Log.LogBenchmark('====> Screen PartyPlayer', 3); Log.BenchmarkStart(3); + ScreenStatMain := TScreenStatMain.Create; + Log.BenchmarkEnd(3); Log.LogBenchmark('====> Screen Stat Main', 3); Log.BenchmarkStart(3); + ScreenStatDetail := TScreenStatDetail.Create; + Log.BenchmarkEnd(3); Log.LogBenchmark('====> Screen Stat Detail', 3); Log.BenchmarkStart(3); end; end. diff --git a/Game/Code/Classes/UThemes.pas b/Game/Code/Classes/UThemes.pas index 5aca1401..4f4ab2b9 100644 --- a/Game/Code/Classes/UThemes.pas +++ b/Game/Code/Classes/UThemes.pas @@ -570,10 +570,15 @@ type ButtonPrev: TThemeButton; ButtonReverse: TThemeButton; ButtonExit: TThemeButton; - - Description: array[0..3] of string; + TextDescription: TThemeText; + TextPage: TThemeText; TextList: AThemeText; + + Description: array[0..3] of string; + DescriptionR: array[0..3] of string; + FormatStr: array[0..3] of string; + PageStr: String; end; //Playlist Translations @@ -620,6 +625,8 @@ type Playlist: TThemePlaylist; + ILevel: array[0..2] of String; + constructor Create(FileName: string); overload; // Initialize theme system constructor Create(FileName: string; Color: integer); overload; // Initialize theme system with color function LoadTheme(FileName: string; sColor: integer): boolean; // Load some theme settings from file @@ -1242,15 +1249,35 @@ begin ThemeLoadButton(StatDetail.ButtonExit, 'StatDetailButtonExit'); ThemeLoadText (StatDetail.TextDescription, 'StatDetailTextDescription'); + ThemeLoadText (StatDetail.TextPage, 'StatDetailTextPage'); ThemeLoadTexts(StatDetail.TextList, 'StatDetailTextList'); + //Translate Texts StatDetail.Description[0] := Language.Translate('STAT_DESC_SCORES'); StatDetail.Description[1] := Language.Translate('STAT_DESC_SINGERS'); StatDetail.Description[2] := Language.Translate('STAT_DESC_SONGS'); StatDetail.Description[3] := Language.Translate('STAT_DESC_BANDS'); + StatDetail.DescriptionR[0] := Language.Translate('STAT_DESC_SCORES_REVERSED'); + StatDetail.DescriptionR[1] := Language.Translate('STAT_DESC_SINGERS_REVERSED'); + StatDetail.DescriptionR[2] := Language.Translate('STAT_DESC_SONGS_REVERSED'); + StatDetail.DescriptionR[3] := Language.Translate('STAT_DESC_BANDS_REVERSED'); + + StatDetail.FormatStr[0] := Language.Translate('STAT_FORMAT_SCORES'); + StatDetail.FormatStr[1] := Language.Translate('STAT_FORMAT_SINGERS'); + StatDetail.FormatStr[2] := Language.Translate('STAT_FORMAT_SONGS'); + StatDetail.FormatStr[3] := Language.Translate('STAT_FORMAT_BANDS'); + + StatDetail.PageStr := Language.Translate('STAT_PAGE'); + //Playlist Translations - Playlist.CatText := Language.Translate('PLAYLIST_CATTEXT') + Playlist.CatText := Language.Translate('PLAYLIST_CATTEXT'); + + //Level Translations + //Fill ILevel + ILevel[0] := Language.Translate('SING_EASY'); + ILevel[1] := Language.Translate('SING_MEDIUM'); + ILevel[2] := Language.Translate('SING_HARD'); end; ThemeIni.Free; -- cgit v1.2.3