From 678cc132f942ff4d84a803550eedf96acc543bca Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 23 May 2010 09:07:15 +0000 Subject: update to trunk rev. 2391 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2401 b956fd51-792f-4845-bead-9b4dfca2ff2c --- cmake/src/screens/UScreenCredits.pas | 97 ++-- cmake/src/screens/UScreenEdit.pas | 15 +- cmake/src/screens/UScreenEditConvert.pas | 678 +++++++++++++--------- cmake/src/screens/UScreenEditHeader.pas | 110 ++-- cmake/src/screens/UScreenEditSub.pas | 579 ++++++++++++++----- cmake/src/screens/UScreenLevel.pas | 25 +- cmake/src/screens/UScreenLoading.pas | 11 +- cmake/src/screens/UScreenMain.pas | 68 ++- cmake/src/screens/UScreenName.pas | 20 +- cmake/src/screens/UScreenOpen.pas | 99 ++-- cmake/src/screens/UScreenOptions.pas | 19 +- cmake/src/screens/UScreenOptionsAdvanced.pas | 22 +- cmake/src/screens/UScreenOptionsGame.pas | 31 +- cmake/src/screens/UScreenOptionsGraphics.pas | 28 +- cmake/src/screens/UScreenOptionsLyrics.pas | 18 +- cmake/src/screens/UScreenOptionsRecord.pas | 57 +- cmake/src/screens/UScreenOptionsSound.pas | 19 +- cmake/src/screens/UScreenOptionsThemes.pas | 46 +- cmake/src/screens/UScreenPartyNewRound.pas | 318 ++++------- cmake/src/screens/UScreenPartyOptions.pas | 113 ++-- cmake/src/screens/UScreenPartyPlayer.pas | 306 ++++++---- cmake/src/screens/UScreenPartyRounds.pas | 233 ++++++++ cmake/src/screens/UScreenPartyScore.pas | 193 ++++--- cmake/src/screens/UScreenPartyWin.pas | 155 +++-- cmake/src/screens/UScreenPopup.pas | 148 +++-- cmake/src/screens/UScreenScore.pas | 807 ++++++++++++++++++--------- cmake/src/screens/UScreenSing.pas | 339 +++++++---- cmake/src/screens/UScreenSingModi.pas | 580 ------------------- cmake/src/screens/UScreenSong.pas | 568 +++++++++++-------- cmake/src/screens/UScreenSongJumpto.pas | 97 ++-- cmake/src/screens/UScreenSongMenu.pas | 58 +- cmake/src/screens/UScreenStatDetail.pas | 21 +- cmake/src/screens/UScreenStatMain.pas | 42 +- cmake/src/screens/UScreenTop5.pas | 114 +++- cmake/src/screens/UScreenWelcome.pas | 164 ------ 35 files changed, 3317 insertions(+), 2881 deletions(-) create mode 100644 cmake/src/screens/UScreenPartyRounds.pas delete mode 100644 cmake/src/screens/UScreenSingModi.pas delete mode 100644 cmake/src/screens/UScreenWelcome.pas (limited to 'cmake/src/screens') diff --git a/cmake/src/screens/UScreenCredits.pas b/cmake/src/screens/UScreenCredits.pas index def6b7de..b1333b4a 100644 --- a/cmake/src/screens/UScreenCredits.pas +++ b/cmake/src/screens/UScreenCredits.pas @@ -35,15 +35,16 @@ interface uses SysUtils, - UMenu, SDL, SDL_Image, + gl, + UMenu, UDisplay, UTexture, - gl, UMusic, UFiles, UThemes, + UPath, UGraphicClasses; type @@ -98,10 +99,10 @@ type Fadeout: boolean; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; function Draw: boolean; override; - procedure onShow; override; - procedure onHide; override; + procedure OnShow; override; + procedure OnHide; override; procedure DrawCredits; procedure Draw_FunkyText; end; @@ -138,17 +139,17 @@ const OUTRO_EXD_FILE = 'outro-exit-dark.png'; Timings: array[0..21] of cardinal=( - 20, // 0 Delay vor Start + 20, // 0 Delay before Start - 149, // 1 Ende erster Intro Zoom - 155, // 2 Start 2. Action im Intro - 170, // 3 Ende Separation im Intro - 271, // 4 Anfang Zoomout im Intro + 149, // 1 End first Intro Zoom + 155, // 2 Start 2. Action in Intro + 170, // 3 End Separation in Intro + 271, // 4 beginning Zoomout in Intro 0, // 5 unused - 261, // 6 Start fade-to-white im Intro + 261, // 6 Start fade-to-white in Intro 271, // 7 Start Main Part - 280, // 8 Start On-Beat-Sternchen Main Part + 280, // 8 Start On-Beat-Star Main Part 396, // 9 Start BlindGuard 666, // 10 Start blindy @@ -162,7 +163,7 @@ const 2826, // 18 Ende Whiteshark 3096, // 19 Start FadeOut Mainscreen 3366, // 20 Ende Credits Tune - 60); // 21 start flare im intro + 60); // 21 start flare in intro implementation @@ -176,9 +177,9 @@ uses Textgl, ULanguage, UCommon, - UPath; + UPathUtils; -function TScreenCredits.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenCredits.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then @@ -204,38 +205,38 @@ end; constructor TScreenCredits.Create; var - CreditsPath: string; + CreditsPath: IPath; begin inherited Create; - CreditsPath := ResourcesPath + 'credits/'; - - credits_bg_tex := Texture.LoadTexture(CreditsPath + CRDTS_BG_FILE, TEXTURE_TYPE_PLAIN, 0); - credits_bg_ovl := Texture.LoadTexture(CreditsPath + CRDTS_OVL_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - - credits_blindguard := Texture.LoadTexture(CreditsPath + CRDTS_blindguard_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_blindy := Texture.LoadTexture(CreditsPath + CRDTS_blindy_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_canni := Texture.LoadTexture(CreditsPath + CRDTS_canni_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_commandio := Texture.LoadTexture(CreditsPath + CRDTS_commandio_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_lazyjoker := Texture.LoadTexture(CreditsPath + CRDTS_lazyjoker_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_mog := Texture.LoadTexture(CreditsPath + CRDTS_mog_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_mota := Texture.LoadTexture(CreditsPath + CRDTS_mota_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_skillmaster := Texture.LoadTexture(CreditsPath + CRDTS_skillmaster_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - credits_whiteshark := Texture.LoadTexture(CreditsPath + CRDTS_whiteshark_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - - intro_layer01 := Texture.LoadTexture(CreditsPath + INTRO_L01_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer02 := Texture.LoadTexture(CreditsPath + INTRO_L02_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer03 := Texture.LoadTexture(CreditsPath + INTRO_L03_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer04 := Texture.LoadTexture(CreditsPath + INTRO_L04_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer05 := Texture.LoadTexture(CreditsPath + INTRO_L05_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer06 := Texture.LoadTexture(CreditsPath + INTRO_L06_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer07 := Texture.LoadTexture(CreditsPath + INTRO_L07_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer08 := Texture.LoadTexture(CreditsPath + INTRO_L08_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - intro_layer09 := Texture.LoadTexture(CreditsPath + INTRO_L09_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - - outro_bg := Texture.LoadTexture(CreditsPath + OUTRO_BG_FILE, TEXTURE_TYPE_PLAIN, 0); - outro_esc := Texture.LoadTexture(CreditsPath + OUTRO_ESC_FILE, TEXTURE_TYPE_TRANSPARENT, 0); - outro_exd := Texture.LoadTexture(CreditsPath + OUTRO_EXD_FILE, TEXTURE_TYPE_TRANSPARENT, 0); + CreditsPath := ResourcesPath.Append('credits', pdAppend); + + credits_bg_tex := Texture.LoadTexture(CreditsPath.Append(CRDTS_BG_FILE), TEXTURE_TYPE_PLAIN, 0); + credits_bg_ovl := Texture.LoadTexture(CreditsPath.Append(CRDTS_OVL_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + + credits_blindguard := Texture.LoadTexture(CreditsPath.Append(CRDTS_blindguard_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_blindy := Texture.LoadTexture(CreditsPath.Append(CRDTS_blindy_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_canni := Texture.LoadTexture(CreditsPath.Append(CRDTS_canni_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_commandio := Texture.LoadTexture(CreditsPath.Append(CRDTS_commandio_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_lazyjoker := Texture.LoadTexture(CreditsPath.Append(CRDTS_lazyjoker_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_mog := Texture.LoadTexture(CreditsPath.Append(CRDTS_mog_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_mota := Texture.LoadTexture(CreditsPath.Append(CRDTS_mota_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_skillmaster := Texture.LoadTexture(CreditsPath.Append(CRDTS_skillmaster_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + credits_whiteshark := Texture.LoadTexture(CreditsPath.Append(CRDTS_whiteshark_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + + intro_layer01 := Texture.LoadTexture(CreditsPath.Append(INTRO_L01_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer02 := Texture.LoadTexture(CreditsPath.Append(INTRO_L02_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer03 := Texture.LoadTexture(CreditsPath.Append(INTRO_L03_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer04 := Texture.LoadTexture(CreditsPath.Append(INTRO_L04_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer05 := Texture.LoadTexture(CreditsPath.Append(INTRO_L05_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer06 := Texture.LoadTexture(CreditsPath.Append(INTRO_L06_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer07 := Texture.LoadTexture(CreditsPath.Append(INTRO_L07_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer08 := Texture.LoadTexture(CreditsPath.Append(INTRO_L08_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + intro_layer09 := Texture.LoadTexture(CreditsPath.Append(INTRO_L09_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + + outro_bg := Texture.LoadTexture(CreditsPath.Append(OUTRO_BG_FILE), TEXTURE_TYPE_PLAIN, 0); + outro_esc := Texture.LoadTexture(CreditsPath.Append(OUTRO_ESC_FILE), TEXTURE_TYPE_TRANSPARENT, 0); + outro_exd := Texture.LoadTexture(CreditsPath.Append(OUTRO_EXD_FILE), TEXTURE_TYPE_TRANSPARENT, 0); CRDTS_Stage:=InitialDelay; end; @@ -246,7 +247,7 @@ begin Draw := true; end; -procedure TScreenCredits.onShow; +procedure TScreenCredits.OnShow; begin inherited; @@ -255,13 +256,13 @@ begin deluxe_slidein := 0; Credits_Alpha := 0; // Music.SetLoop(true); loop loops not, shit - AudioPlayback.Open(soundpath + 'wome-credits-tune.mp3'); // thank you wetue + AudioPlayback.Open(soundpath.Append('wome-credits-tune.mp3')); // thank you wetue // Music.Play; CTime := 0; // setlength(CTime_hold,0); end; -procedure TScreenCredits.onHide; +procedure TScreenCredits.OnHide; begin AudioPlayback.Stop; end; @@ -1386,7 +1387,7 @@ begin begin CTime_hold := 0; AudioPlayback.Stop; - AudioPlayback.Open(soundpath + 'credits-outro-tune.mp3'); + AudioPlayback.Open(SoundPath.Append('credits-outro-tune.mp3')); AudioPlayback.SetVolume(0.2); AudioPlayback.SetLoop(true); AudioPlayback.Play; diff --git a/cmake/src/screens/UScreenEdit.pas b/cmake/src/screens/UScreenEdit.pas index 5112e17a..12e2948c 100644 --- a/cmake/src/screens/UScreenEdit.pas +++ b/cmake/src/screens/UScreenEdit.pas @@ -45,8 +45,7 @@ type TextDescriptionLong: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; - PressedDown: boolean): boolean; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; procedure InteractNext; override; procedure InteractPrev; override; procedure InteractInc; override; @@ -60,10 +59,10 @@ uses UGraphic, UMusic, USkins, + UUnicodeUtils, SysUtils; -function TScreenEdit.ParseInput(PressedKey: cardinal; CharCode: WideChar; - PressedDown: boolean): boolean; +function TScreenEdit.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var SDL_ModState: word; begin @@ -75,8 +74,8 @@ begin if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -158,8 +157,8 @@ end; procedure TScreenEdit.SetAnimationProgress(Progress: real); begin - Static[0].Texture.ScaleW := Progress; - Static[0].Texture.ScaleH := Progress; + Statics[0].Texture.ScaleW := Progress; + Statics[0].Texture.ScaleH := Progress; end; end. diff --git a/cmake/src/screens/UScreenEditConvert.pas b/cmake/src/screens/UScreenEditConvert.pas index e4a691cf..8b13d410 100644 --- a/cmake/src/screens/UScreenEditConvert.pas +++ b/cmake/src/screens/UScreenEditConvert.pas @@ -25,6 +25,29 @@ unit UScreenEditConvert; +{* + * See + * MIDI Recommended Practice (RP-017): SMF Lyric Meta Event Definition + * http://www.midi.org/techspecs/rp17.php + * MIDI Recommended Practice (RP-026): SMF Language and Display Extensions + * http://www.midi.org/techspecs/rp26.php + * MIDI File Format + * http://www.sonicspot.com/guide/midifiles.html + * KMIDI File Format + * http://gnese.free.fr/Projects/KaraokeTime/Fichiers/karfaq.html + * http://journals.rpungin.fotki.com/karaoke/category/midi + * + * There are two widely spread karaoke formats: + * - KMIDI (.kar), an inofficial midi extension by Tune 1000 + * - Standard Midi files with lyric meta-tags (SMF with lyrics, .mid). + * + * KMIDI uses two tracks, the first just contains a header (mostly track 2) and + * the second the lyrics (track 3). It uses text meta tags for the lyrics. + * SMF uses just one track (normally track 1) and uses lyric meta tags for storage. + * + * Most files are in the KMIDI format. Some Midi files contain both lyric types. + *} + interface {$IFDEF FPC} @@ -45,10 +68,11 @@ uses USongs, USong, UMusic, - UThemes; + UThemes, + UPath; type - TNote = record + TMidiNote = record Event: integer; EventType: integer; Channel: integer; @@ -56,70 +80,65 @@ type Len: real; Data1: integer; Data2: integer; - Str: string; + Str: UTF8String; // normally ASCII end; + TLyricType = (ltKMIDI, ltSMFLyric); + TTrack = record - Note: array of TNote; - Name: string; - Hear: boolean; - Status: set of (notes, lyrics); + Note: array of TMidiNote; + Name: UTF8String; // normally ASCII + Status: set of (tsNotes, tsLyrics); //< track contains notes, lyrics or both + LyricType: set of TLyricType; + NoteType: (ntNone, ntAvail); end; - TNuta = record + TNote = record Start: integer; Len: integer; Tone: integer; - Lyric: string; + Lyric: UTF8String; NewSentence: boolean; end; TArrayTrack = array of TTrack; TScreenEditConvert = class(TMenu) - public - ATrack: TArrayTrack; // actual track -// Track: TArrayTrack; - Channel: TArrayTrack; + private + Tracks: TArrayTrack; // current track ColR: array[0..100] of real; ColG: array[0..100] of real; ColB: array[0..100] of real; Len: real; - Sel: integer; - Selected: boolean; -// FileName: string; + SelTrack: integer; // index of selected track + fFileName: IPath; {$IFDEF UseMIDIPort} MidiFile: TMidiFile; - MidiTrack: TMidiTrack; - MidiEvent: pMidiEvent; MidiOut: TMidiOutput; {$ENDIF} - - Song: TSong; - Lines: TLines; + BPM: real; Ticks: real; - Note: array of TNuta; + Note: array of TNote; - procedure AddLyric(Start: integer; Text: string); - procedure Extract; + procedure AddLyric(Start: integer; LyricType: TLyricType; Text: UTF8String); + procedure Extract(out Song: TSong; out Lines: TLines); {$IFDEF UseMIDIPort} procedure MidiFile1MidiEvent(event: PMidiEvent); {$ENDIF} - - function SelectedNumber: integer; + + function CountSelectedTracks: integer; + + public constructor Create; override; - procedure onShow; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + procedure OnShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; function Draw: boolean; override; - procedure onHide; override; + procedure OnHide; override; end; -var - ConversionFileName: string; - implementation uses @@ -131,17 +150,42 @@ uses UGraphic, UIni, UMain, - UPath, - USkins; - -function TScreenEditConvert.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + UPathUtils, + USkins, + ULanguage, + UTextEncoding, + UUnicodeUtils; + +const + // MIDI/KAR lyrics are specified to be ASCII only. + // Assume backward compatible CP1252 encoding. + DEFAULT_ENCODING = encCP1252; + +const + MIDI_EVENTTYPE_NOTEOFF = $8; + MIDI_EVENTTYPE_NOTEON = $9; + MIDI_EVENTTYPE_META_SYSEX = $F; + + MIDI_EVENT_META = $FF; + MIDI_META_TEXT = $1; + MIDI_META_LYRICS = $5; + +function TScreenEditConvert.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; +{$IFDEF UseMIDIPort} +var + SResult: TSaveSongResult; + Playing: boolean; + MidiTrack: TMidiTrack; + Song: TSong; + Lines: TLines; +{$ENDIF} begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -153,9 +197,10 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE : begin - {$IFDEF UseMIDIPort} - MidiFile.StopPlaying; - {$ENDIF} + {$IFDEF UseMIDIPort} + if (MidiFile <> nil) then + MidiFile.StopPlaying; + {$ENDIF} AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenEdit); end; @@ -165,70 +210,97 @@ begin if Interaction = 0 then begin AudioPlayback.PlaySound(SoundLib.Start); + ScreenOpen.Filename := GamePath.Append('file.mid'); ScreenOpen.BackScreen := @ScreenEditConvert; FadeTo(@ScreenOpen); - end; - - if Interaction = 1 then + end + else if Interaction = 1 then begin - Selected := false; - {$IFDEF UseMIDIPort} - MidiFile.OnMidiEvent := MidiFile1MidiEvent; -// MidiFile.GoToTime(MidiFile.GetTrackLength div 2); - MidiFile.StartPlaying; + {$IFDEF UseMIDIPort} + if (MidiFile <> nil) then + begin + MidiFile.OnMidiEvent := MidiFile1MidiEvent; + //MidiFile.GoToTime(MidiFile.GetTrackLength div 2); + MidiFile.StartPlaying; + end; {$ENDIF} - end; - - if Interaction = 2 then + end + else if Interaction = 2 then begin - Selected := true; {$IFDEF UseMIDIPort} - MidiFile.OnMidiEvent := nil; - {$ENDIF} - {for T := 0 to High(ATrack) do + if (MidiFile <> nil) then begin - if ATrack[T].Hear then - begin - MidiTrack := MidiFile.GetTrack(T); - MidiTrack.OnMidiEvent := MidiFile1MidiEvent; - end; + MidiFile.OnMidiEvent := nil; + MidiFile.StartPlaying; end; - MidiFile.StartPlaying;//} - end; - - if Interaction = 3 then + {$ENDIF} + end + else if Interaction = 3 then begin - if SelectedNumber > 0 then + {$IFDEF UseMIDIPort} + if CountSelectedTracks > 0 then + begin + Extract(Song, Lines); + SResult := SaveSong(Song, Lines, fFileName.SetExtension('.txt'), + false); + FreeAndNil(Song); + if (SResult = ssrOK) then + ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED')) + else + ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED')); + end + else begin - Extract; - SaveSong(Song, Lines, ChangeFileExt(ConversionFileName, '.txt'), false); + ScreenPopupError.ShowPopup(Language.Translate('EDITOR_ERROR_NO_TRACK_SELECTED')); end; + {$ENDIF} end; end; SDLK_SPACE: begin -// ATrack[Sel].Hear := not ATrack[Sel].Hear; - if Notes in ATrack[Sel].Status then + {$IFDEF UseMIDIPort} + if (MidiFile <> nil) then begin - ATrack[Sel].Status := ATrack[Sel].Status - [Notes]; - if Lyrics in ATrack[Sel].Status then - ATrack[Sel].Status := ATrack[Sel].Status - [Lyrics] - else - ATrack[Sel].Status := ATrack[Sel].Status + [Lyrics]; - end - else - ATrack[Sel].Status := ATrack[Sel].Status + [Notes]; + if (Tracks[SelTrack].NoteType = ntAvail) and + (Tracks[SelTrack].LyricType <> []) then + begin + if (Tracks[SelTrack].Status = []) then + Tracks[SelTrack].Status := [tsNotes] + else if (Tracks[SelTrack].Status = [tsNotes]) then + Tracks[SelTrack].Status := [tsLyrics] + else if (Tracks[SelTrack].Status = [tsLyrics]) then + Tracks[SelTrack].Status := [tsNotes, tsLyrics] + else if (Tracks[SelTrack].Status = [tsNotes, tsLyrics]) then + Tracks[SelTrack].Status := []; + end + else if (Tracks[SelTrack].NoteType = ntAvail) then + begin + if (Tracks[SelTrack].Status = []) then + Tracks[SelTrack].Status := [tsNotes] + else + Tracks[SelTrack].Status := []; + end + else if (Tracks[SelTrack].LyricType <> []) then + begin + if (Tracks[SelTrack].Status = []) then + Tracks[SelTrack].Status := [tsLyrics] + else + Tracks[SelTrack].Status := []; + end; -{ if Selected then - begin - MidiTrack := MidiFile.GetTrack(Sel); - if Track[Sel].Hear then + Playing := (MidiFile.GetCurrentTime > 0); + MidiFile.StopPlaying(); + MidiTrack := MidiFile.GetTrack(SelTrack); + if tsNotes in Tracks[SelTrack].Status then MidiTrack.OnMidiEvent := MidiFile1MidiEvent else MidiTrack.OnMidiEvent := nil; - end;} + if (Playing) then + MidiFile.ContinuePlaying(); + end; + {$ENDIF} end; SDLK_RIGHT: @@ -243,102 +315,161 @@ begin SDLK_DOWN: begin - Inc(Sel); - if Sel > High(ATrack) then - Sel := 0; + Inc(SelTrack); + if SelTrack > High(Tracks) then + SelTrack := 0; end; SDLK_UP: begin - Dec(Sel); - if Sel < 0 then - Sel := High(ATrack); + Dec(SelTrack); + if SelTrack < 0 then + SelTrack := High(Tracks); end; end; end; end; -procedure TScreenEditConvert.AddLyric(Start: integer; Text: string); +procedure TScreenEditConvert.AddLyric(Start: integer; LyricType: TLyricType; Text: UTF8String); var N: integer; begin - for N := 0 to High(Note) do + // find corresponding note + N := 0; + while (N <= High(Note)) do begin if Note[N].Start = Start then - begin - // check for new sentece - if Copy(Text, 1, 1) = '\' then - Delete(Text, 1, 1); - if Copy(Text, 1, 1) = '/' then - begin - Delete(Text, 1, 1); - Note[N].NewSentence := true; - end; + Break; + Inc(N); + end; - // overwrite lyric od append - if Note[N].Lyric = '-' then - Note[N].Lyric := Text - else - Note[N].Lyric := Note[N].Lyric + Text; + // check if note was found + if (N > High(Note)) then + Exit; + + // set text + if (LyricType = ltKMIDI) then + begin + // end of paragraph + if Copy(Text, 1, 1) = '\' then + begin + Delete(Text, 1, 1); + end + // end of line + else if Copy(Text, 1, 1) = '/' then + begin + Delete(Text, 1, 1); + Note[N].NewSentence := true; + end; + end + else // SMFLyric + begin + // Line Feed -> end of paragraph + if Copy(Text, 1, 1) = #$0A then + begin + Delete(Text, 1, 1); + end + // Carriage Return -> end of line + else if Copy(Text, 1, 1) = #$0D then + begin + Delete(Text, 1, 1); + Note[N].NewSentence := true; end; end; + + // overwrite lyric or append + if Note[N].Lyric = '-' then + Note[N].Lyric := Text + else + Note[N].Lyric := Note[N].Lyric + Text; end; -procedure TScreenEditConvert.Extract; +procedure TScreenEditConvert.Extract(out Song: TSong; out Lines: TLines); + var T: integer; C: integer; N: integer; Nu: integer; - NoteTemp: TNuta; + NoteTemp: TNote; Move: integer; Max, Min: integer; + LyricType: TLyricType; + Text: UTF8String; begin // song info - Song.Title := ''; - Song.Artist := ''; - Song.Mp3 := ''; + Song := TSong.Create(); + Song.Clear(); Song.Resolution := 4; SetLength(Song.BPM, 1); Song.BPM[0].BPM := BPM*4; - SetLength(Note, 0); // extract notes - for T := 0 to High(ATrack) do + for T := 0 to High(Tracks) do begin -// if ATrack[T].Hear then -// begin - if Notes in ATrack[T].Status then + if tsNotes in Tracks[T].Status then begin - for N := 0 to High(ATrack[T].Note) do + for N := 0 to High(Tracks[T].Note) do begin - if (ATrack[T].Note[N].EventType = 9) and (ATrack[T].Note[N].Data2 > 0) then + if (Tracks[T].Note[N].EventType = MIDI_EVENTTYPE_NOTEON) and + (Tracks[T].Note[N].Data2 > 0) then begin Nu := Length(Note); SetLength(Note, Nu + 1); - Note[Nu].Start := Round(ATrack[T].Note[N].Start / Ticks); - Note[Nu].Len := Round(ATrack[T].Note[N].Len / Ticks); - Note[Nu].Tone := ATrack[T].Note[N].Data1 - 12*5; + Note[Nu].Start := Round(Tracks[T].Note[N].Start / Ticks); + Note[Nu].Len := Round(Tracks[T].Note[N].Len / Ticks); + Note[Nu].Tone := Tracks[T].Note[N].Data1 - 12*5; Note[Nu].Lyric := '-'; end; end; end; end; - // extract lyrics - for T := 0 to High(ATrack) do + // extract lyrics (and artist + title info) + for T := 0 to High(Tracks) do begin -// if ATrack[T].Hear then -// begin - if Lyrics in ATrack[T].Status then + if not (tsLyrics in Tracks[T].Status) then + Continue; + + for N := 0 to High(Tracks[T].Note) do begin - for N := 0 to High(ATrack[T].Note) do + if (Tracks[T].Note[N].Event = MIDI_EVENT_META) then begin - if (ATrack[T].Note[N].EventType = 15) then + // determine and validate lyric meta tag + if (ltKMIDI in Tracks[T].LyricType) and + (Tracks[T].Note[N].Data1 = MIDI_META_TEXT) then begin -// Log.LogStatus('<' + Track[T].Note[N].Str + '>', 'MIDI'); - AddLyric(Round(ATrack[T].Note[N].Start / Ticks), ATrack[T].Note[N].Str); + Text := Tracks[T].Note[N].Str; + + // check for meta info + if (Length(Text) > 2) and (Text[1] = '@') then + begin + case Text[2] of + 'L': Song.Language := Copy(Text, 3, Length(Text)); // language + 'T': begin // title info + if (Song.Artist = '') then + Song.Artist := Copy(Text, 3, Length(Text)) + else if (Song.Title = '') then + Song.Title := Copy(Text, 3, Length(Text)); + end; + end; + Continue; + end; + + LyricType := ltKMIDI; + end + else if (ltSMFLyric in Tracks[T].LyricType) and + (Tracks[T].Note[N].Data1 = MIDI_META_LYRICS) then + begin + LyricType := ltSMFLyric; + end + else + begin + // unknown meta event + Continue; end; + + AddLyric(Round(Tracks[T].Note[N].Start / Ticks), LyricType, Tracks[T].Note[N].Str); end; end; end; @@ -360,8 +491,12 @@ begin // copy notes SetLength(Lines.Line, 1); - Lines.Number := 1; - Lines.High := 0; + Lines.Number := 1; + Lines.High := 0; + Lines.Current := 0; + Lines.Resolution := 0; + Lines.NotesGAP := 0; + Lines.ScoreValue := 0; C := 0; N := 0; @@ -403,35 +538,37 @@ begin // create space for new note SetLength(Lines.Line[C].Note, Length(Lines.Line[C].Note)+1); + Inc(Lines.Line[C].HighNote); // initialize note Lines.Line[C].Note[N].Start := Note[Nu].Start; Lines.Line[C].Note[N].Length := Note[Nu].Len; Lines.Line[C].Note[N].Tone := Note[Nu].Tone; - Lines.Line[C].Note[N].Text := Note[Nu].Lyric; - //All Notes are Freestyle when Converted Fix: + Lines.Line[C].Note[N].Text := DecodeStringUTF8(Note[Nu].Lyric, DEFAULT_ENCODING); Lines.Line[C].Note[N].NoteType := ntNormal; Inc(N); end; end; -function TScreenEditConvert.SelectedNumber: integer; +function TScreenEditConvert.CountSelectedTracks: integer; var T: integer; // track begin Result := 0; - for T := 0 to High(ATrack) do -// if ATrack[T].Hear then -// Inc(Result); - if Notes in ATrack[T].Status then + for T := 0 to High(Tracks) do + if tsNotes in Tracks[T].Status then Inc(Result); end; {$IFDEF UseMIDIPort} procedure TScreenEditConvert.MidiFile1MidiEvent(event: PMidiEvent); begin -// Log.LogStatus(IntToStr(event.event), 'MIDI'); - MidiOut.PutShort(event.event, event.data1, event.data2); + //Log.LogStatus(IntToStr(event.event), 'MIDI'); + try + MidiOut.PutShort(event.event, event.data1, event.data2); + except + MidiFile.StopPlaying(); + end; end; {$ENDIF} @@ -442,7 +579,7 @@ begin inherited Create; AddButton(40, 20, 100, 40, Skin.GetTextureFileName('ButtonF')); AddButtonText(15, 5, 0, 0, 0, 'Open'); -// Button[High(Button)].Text[0].Size := 11; + //Button[High(Button)].Text[0].Size := 11; AddButton(160, 20, 100, 40, Skin.GetTextureFileName('ButtonF')); AddButtonText(25, 5, 0, 0, 0, 'Play'); @@ -453,19 +590,7 @@ begin AddButton(500, 20, 100, 40, Skin.GetTextureFileName('ButtonF')); AddButtonText(20, 5, 0, 0, 0, 'Save'); -{ MidiOut := TMidiOutput.Create(nil); -// MidiOut.Close; -// MidiOut.DeviceID := 0; - if Ini.Debug = 1 then - MidiOut.ProductName := 'Microsoft GS Wavetable SW Synth'; // for my kxproject without midi table - Log.LogStatus(MidiOut.ProductName, 'MIDI'); - MidiOut.Open; -// MidiOut.SetVolume(100, 100); // temporary} - - ConversionFileName := GamePath + 'file.mid'; - {$IFDEF UseMIDIPort} - MidiFile := TMidiFile.Create(nil); - {$ENDIF} + fFileName := PATH_NONE; for P := 0 to 100 do begin @@ -476,96 +601,124 @@ begin end; -procedure TScreenEditConvert.onShow; +procedure TScreenEditConvert.OnShow; +{$IFDEF UseMIDIPort} var T: integer; // track N: integer; // note - C: integer; // channel - CN: integer; // channel note + MidiTrack: TMidiTrack; + MidiEvent: PMidiEvent; + FileOpened: boolean; + KMIDITrackIndex, SMFTrackIndex: integer; +{$ENDIF} begin inherited; + Interaction := 0; + {$IFDEF UseMIDIPort} MidiOut := TMidiOutput.Create(nil); - if Ini.Debug = 1 then - MidiOut.ProductName := 'Microsoft GS Wavetable SW Synth'; // for my kxproject without midi table - Log.LogStatus(MidiOut.ProductName, 'MIDI'); + Log.LogInfo(MidiOut.ProductName, 'MIDI'); MidiOut.Open; + MidiFile := nil; + SetLength(Tracks, 0); + + // Filename is only <> PATH_NONE if we called the OpenScreen before + fFilename := ScreenOpen.Filename; + if (fFilename = PATH_NONE) then + Exit; + ScreenOpen.Filename := PATH_NONE; - if FileExists(ConversionFileName) then + FileOpened := false; + if fFileName.Exists then begin - MidiFile.Filename := ConversionFileName; - MidiFile.ReadFile; + MidiFile := TMidiFile.Create(nil); + MidiFile.Filename := fFileName; + try + MidiFile.ReadFile; + FileOpened := true; + except + MidiFile.Free; + end; + end; - Len := 0; - Sel := 0; - BPM := MidiFile.Bpm; - Ticks := MidiFile.TicksPerQuarter / 4; + if (not FileOpened) then + begin + ScreenPopupError.ShowPopup(Language.Translate('ERROR_FILE_NOT_FOUND')); + Exit; + end; -{ for T := 0 to MidiFile.NumberOfTracks-1 do - begin - SetLength(Track, Length(Track)+1); - MidiTrack := MidiFile.GetTrack(T); - MidiTrack.OnMidiEvent := MidiFile1MidiEvent; - Track[T].Name := MidiTrack.getName; + Len := 0; + SelTrack := 0; + BPM := MidiFile.Bpm; + Ticks := MidiFile.TicksPerQuarter / 4; - for N := 0 to MidiTrack.getEventCount-1 do - begin - SetLength(Track[T].Note, Length(Track[T].Note)+1); - MidiEvent := MidiTrack.GetEvent(N); - Track[T].Note[N].Start := MidiEvent.time; - Track[T].Note[N].Len := MidiEvent.len; - Track[T].Note[N].Event := MidiEvent.event; - Track[T].Note[N].EventType := MidiEvent.event div 16; - Track[T].Note[N].Channel := MidiEvent.event and 15; - Track[T].Note[N].Data1 := MidiEvent.data1; - Track[T].Note[N].Data2 := MidiEvent.data2; - Track[T].Note[N].Str := MidiEvent.str; - - if Track[T].Note[N].Start + Track[T].Note[N].Len > Len then - Len := Track[T].Note[N].Start + Track[T].Note[N].Len; - end; - end;} + KMIDITrackIndex := -1; + SMFTrackIndex := -1; - SetLength(Channel, 16); - for T := 0 to 15 do - begin - Channel[T].Name := IntToStr(T+1); - SetLength(Channel[T].Note, 0); - Channel[T].Status := []; - end; + SetLength(Tracks, MidiFile.NumberOfTracks); + for T := 0 to MidiFile.NumberOfTracks-1 do + Tracks[T].LyricType := []; - for T := 0 to MidiFile.NumberOfTracks-1 do + for T := 0 to MidiFile.NumberOfTracks-1 do + begin + MidiTrack := MidiFile.GetTrack(T); + MidiTrack.OnMidiEvent := nil; + Tracks[T].Name := DecodeStringUTF8(MidiTrack.getName, DEFAULT_ENCODING); + Tracks[T].NoteType := ntNone; + Tracks[T].Status := []; + + SetLength(Tracks[T].Note, MidiTrack.getEventCount()); + for N := 0 to MidiTrack.getEventCount-1 do begin - MidiTrack := MidiFile.GetTrack(T); - MidiTrack.OnMidiEvent := MidiFile1MidiEvent; - - for N := 0 to MidiTrack.getEventCount-1 do + MidiEvent := MidiTrack.GetEvent(N); + + Tracks[T].Note[N].Start := MidiEvent.time; + Tracks[T].Note[N].Len := MidiEvent.len; + Tracks[T].Note[N].Event := MidiEvent.event; + Tracks[T].Note[N].EventType := MidiEvent.event shr 4; + Tracks[T].Note[N].Channel := MidiEvent.event and $0F; + Tracks[T].Note[N].Data1 := MidiEvent.data1; + Tracks[T].Note[N].Data2 := MidiEvent.data2; + Tracks[T].Note[N].Str := DecodeStringUTF8(MidiEvent.str, DEFAULT_ENCODING); + + if (Tracks[T].Note[N].Event = MIDI_EVENT_META) then + begin + case (Tracks[T].Note[N].Data1) of + MIDI_META_TEXT: begin + // KMIDI lyrics (uses MIDI_META_TEXT events) + if (StrLComp(PAnsiChar(Tracks[T].Note[N].Str), '@KMIDI KARAOKE FILE', 19) = 0) and + (High(Tracks) >= T+1) then + begin + // The '@KMIDI ...' mark is in the first track (mostly named 'Soft Karaoke') + // but the lyrics are in the second track (named 'Words') + Tracks[T+1].LyricType := Tracks[T+1].LyricType + [ltKMIDI]; + KMIDITrackIndex := T+1; + end; + end; + MIDI_META_LYRICS: begin + // lyrics in Standard Midi File format found (uses MIDI_META_LYRICS events) + Tracks[T].LyricType := Tracks[T].LyricType + [ltSMFLyric]; + SMFTrackIndex := T; + end; + end; + end + else if (Tracks[T].Note[N].EventType = MIDI_EVENTTYPE_NOTEON) then begin - MidiEvent := MidiTrack.GetEvent(N); - C := MidiEvent.event and 15; - - CN := Length(Channel[C].Note); - SetLength(Channel[C].Note, CN+1); - - Channel[C].Note[CN].Start := MidiEvent.time; - Channel[C].Note[CN].Len := MidiEvent.len; - Channel[C].Note[CN].Event := MidiEvent.event; - Channel[C].Note[CN].EventType := MidiEvent.event div 16; - Channel[C].Note[CN].Channel := MidiEvent.event and 15; - Channel[C].Note[CN].Data1 := MidiEvent.data1; - Channel[C].Note[CN].Data2 := MidiEvent.data2; - Channel[C].Note[CN].Str := MidiEvent.str; - - if Channel[C].Note[CN].Start + Channel[C].Note[CN].Len > Len then - Len := Channel[C].Note[CN].Start + Channel[C].Note[CN].Len; + // notes available + Tracks[T].NoteType := ntAvail; end; - end; - ATrack := Channel; + if Tracks[T].Note[N].Start + Tracks[T].Note[N].Len > Len then + Len := Tracks[T].Note[N].Start + Tracks[T].Note[N].Len; + end; end; - Interaction := 0; + // set default lyric track. Prefer KMIDI. + if (KMIDITrackIndex > -1) then + Tracks[KMIDITrackIndex].Status := Tracks[KMIDITrackIndex].Status + [tsLyrics] + else if (SMFTrackIndex > -1) then + Tracks[SMFTrackIndex].Status := Tracks[SMFTrackIndex].Status + [tsLyrics]; {$ENDIF} end; @@ -584,35 +737,37 @@ begin Y := 100; - Height := min(480, 40 * Length(ATrack)); + Height := min(480, 40 * Length(Tracks)); Bottom := Y + Height; - if Length(ATrack) = 0 then // prevent crash with uncomplete code. - begin - Log.LogDebug ('UScreenEditConvert -> TScreenEditConvert.Draw:', 'Length(ATrack) = 0'); - YSkip := 40; - end - else - YSkip := Height / Length(ATrack); + YSkip := Height / Length(Tracks); - // select - DrawQuad(10, Y + Sel*YSkip, 780, YSkip, 0.8, 0.8, 0.8); + // highlight selected track + DrawQuad(10, Y+SelTrack*YSkip, 780, YSkip, 0.8, 0.8, 0.8); - // selected - now me use Status System - for Count := 0 to High(ATrack) do - if ATrack[Count].Hear then + // track-selection info + for Count := 0 to High(Tracks) do + if Tracks[Count].Status <> [] then DrawQuad(10, Y + Count*YSkip, 50, YSkip, 0.8, 0.3, 0.3); glColor3f(0, 0, 0); - for Count := 0 to High(ATrack) do + for Count := 0 to High(Tracks) do begin - if Notes in ATrack[Count].Status then + if Tracks[Count].NoteType = ntAvail then begin + if tsNotes in Tracks[Count].Status then + glColor3f(0, 0, 0) + else + glColor3f(0.7, 0.7, 0.7); SetFontPos(25, Y + Count*YSkip + 10); SetFontSize(15); glPrint('N'); end; - if Lyrics in ATrack[Count].Status then + if Tracks[Count].LyricType <> [] then begin + if tsLyrics in Tracks[Count].Status then + glColor3f(0, 0, 0) + else + glColor3f(0.7, 0.7, 0.7); SetFontPos(40, Y + Count*YSkip + 10); SetFontSize(15); glPrint('L'); @@ -623,51 +778,48 @@ begin DrawLine( 60, Y, 60, Bottom, 0, 0, 0); DrawLine(790, Y, 790, Bottom, 0, 0, 0); - for Count := 0 to Length(ATrack) do + for Count := 0 to Length(Tracks) do DrawLine(10, Y + Count*YSkip, 790, Y + Count*YSkip, 0, 0, 0); - for Count := 0 to High(ATrack) do + for Count := 0 to High(Tracks) do begin - SetFontPos(11, Y + 10 + Count*YSkip); + SetFontPos(65, Y + Count*YSkip); SetFontSize(15); - glPrint(ATrack[Count].Name); + glPrint(Tracks[Count].Name); end; - for Count := 0 to High(ATrack) do - for Count2 := 0 to High(ATrack[Count].Note) do + for Count := 0 to High(Tracks) do + begin + for Count2 := 0 to High(Tracks[Count].Note) do begin - if ATrack[Count].Note[Count2].EventType = 9 then - DrawQuad(60 + ATrack[Count].Note[Count2].Start/Len*725, - Y + (Count+1)*YSkip - ATrack[Count].Note[Count2].Data1*35/127, - 3, - 3, - ColR[Count], - ColG[Count], - ColB[Count]); - if ATrack[Count].Note[Count2].EventType = 15 then - DrawLine(60 + ATrack[Count].Note[Count2].Start/Len*725, - Y + 0.75*YSkip + Count*YSkip, - 60 + ATrack[Count].Note[Count2].Start/Len*725, - Y + YSkip + Count*YSkip, - ColR[Count], - ColG[Count], - ColB[Count]); + if Tracks[Count].Note[Count2].EventType = MIDI_EVENTTYPE_NOTEON then + DrawQuad(60 + Tracks[Count].Note[Count2].Start/Len * 725, + Y + (Count+1)*YSkip - Tracks[Count].Note[Count2].Data1*35/127, + 3, 3, + ColR[Count], ColG[Count], ColB[Count]); + if Tracks[Count].Note[Count2].EventType = 15 then + DrawLine(60 + Tracks[Count].Note[Count2].Start/Len * 725, Y + 0.75 * YSkip + Count*YSkip, + 60 + Tracks[Count].Note[Count2].Start/Len * 725, Y + YSkip + Count*YSkip, + ColR[Count], ColG[Count], ColB[Count]); end; + end; // playing line {$IFDEF UseMIDIPort} - X := 60 + MidiFile.GetCurrentTime/MidiFile.GetTrackLength*730; + if (MidiFile <> nil) then + X := 60 + MidiFile.GetCurrentTime/MidiFile.GetTrackLength*730; {$ENDIF} DrawLine(X, Y, X, Bottom, 0.3, 0.3, 0.3); Result := true; end; -procedure TScreenEditConvert.onHide; +procedure TScreenEditConvert.OnHide; begin {$IFDEF UseMIDIPort} + FreeAndNil(MidiFile); MidiOut.Close; - MidiOut.Free; + FreeAndNil(MidiOut); {$ENDIF} end; diff --git a/cmake/src/screens/UScreenEditHeader.pas b/cmake/src/screens/UScreenEditHeader.pas index ad0fc40a..1d697bc9 100644 --- a/cmake/src/screens/UScreenEditHeader.pas +++ b/cmake/src/screens/UScreenEditHeader.pas @@ -38,6 +38,7 @@ uses SDL, USongs, USong, + UPath, UThemes; type @@ -72,8 +73,8 @@ type procedure SetRoundButtons; constructor Create; override; - procedure onShow; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + procedure OnShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; { function Draw: boolean; override; procedure Finish;} end; @@ -86,17 +87,18 @@ uses SysUtils, UFiles, USkins, - UTexture; + UTexture, + UUnicodeUtils; -function TScreenEditHeader.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenEditHeader.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var T: integer; begin Result := true; if (PressedDown) then // Key Down begin // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -105,10 +107,10 @@ begin // check special keys case PressedKey of - SDLK_ESCAPE : + SDLK_ESCAPE: begin -// Music.PlayBack; -// FadeTo(@MainScreen); + //Music.PlayBack; + //FadeTo(@MainScreen); Result := false; end; @@ -116,7 +118,7 @@ begin begin if Interaction = 1 then begin -// Save; + //Save; end; end; @@ -159,19 +161,19 @@ begin T := Interaction - 2 + TextTitle; if (Interaction >= 2) and (Interaction <= 13) and (Length(Text[T].Text) >= 1) then begin - Text[T].DeleteLastL; + Text[T].DeleteLastLetter; SetRoundButtons; end; end; end; case CharCode of - #32..#255: + 32..255: begin if (Interaction >= 2) and (Interaction <= 13) then begin Text[Interaction - 2 + TextTitle].Text := - Text[Interaction - 2 + TextTitle].Text + CharCode; + Text[Interaction - 2 + TextTitle].Text + UCS4ToUTF8String(CharCode); SetRoundButtons; end; end; @@ -223,18 +225,18 @@ begin TextGAP := AddText(340, 110 + 13*30, 0, 30, 0, 0, 0, ''); TextBPM := AddText(340, 110 + 14*30, 0, 30, 0, 0, 0, ''); - StaticTitle := AddStatic(130, 115 + 0*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticArtist := AddStatic(130, 115 + 1*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticMp3 := AddStatic(130, 115 + 2*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticBackground := AddStatic(130, 115 + 4*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticVideo := AddStatic(130, 115 + 5*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticVideoGAP := AddStatic(130, 115 + 6*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticRelative := AddStatic(130, 115 + 8*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticResolution := AddStatic(130, 115 + 9*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticNotesGAP := AddStatic(130, 115 + 10*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticStart := AddStatic(130, 115 + 12*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticGAP := AddStatic(130, 115 + 13*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); - StaticBPM := AddStatic(130, 115 + 14*30, 20, 20, 1, 1, 1, 'RoundButton', TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticTitle := AddStatic(130, 115 + 0*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticArtist := AddStatic(130, 115 + 1*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticMp3 := AddStatic(130, 115 + 2*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticBackground := AddStatic(130, 115 + 4*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticVideo := AddStatic(130, 115 + 5*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticVideoGAP := AddStatic(130, 115 + 6*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticRelative := AddStatic(130, 115 + 8*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticResolution := AddStatic(130, 115 + 9*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticNotesGAP := AddStatic(130, 115 + 10*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticStart := AddStatic(130, 115 + 12*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticGAP := AddStatic(130, 115 + 13*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + StaticBPM := AddStatic(130, 115 + 14*30, 20, 20, 1, 1, 1, Path('RoundButton'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); AddInteraction(iText, TextTitle); AddInteraction(iText, TextArtist); @@ -250,7 +252,7 @@ begin AddInteraction(iText, TextBPM); end; -procedure TScreenEditHeader.onShow; +procedure TScreenEditHeader.OnShow; begin inherited; @@ -347,90 +349,90 @@ end;*) procedure TScreenEditHeader.SetRoundButtons; begin if Length(Text[TextTitle].Text) > 0 then - Static[StaticTitle].Visible := true + Statics[StaticTitle].Visible := true else - Static[StaticTitle].Visible := false; + Statics[StaticTitle].Visible := false; if Length(Text[TextArtist].Text) > 0 then - Static[StaticArtist].Visible := true + Statics[StaticArtist].Visible := true else - Static[StaticArtist].Visible := false; + Statics[StaticArtist].Visible := false; if Length(Text[TextMp3].Text) > 0 then - Static[StaticMp3].Visible := true + Statics[StaticMp3].Visible := true else - Static[StaticMp3].Visible := false; + Statics[StaticMp3].Visible := false; if Length(Text[TextBackground].Text) > 0 then - Static[StaticBackground].Visible := true + Statics[StaticBackground].Visible := true else - Static[StaticBackground].Visible := false; + Statics[StaticBackground].Visible := false; if Length(Text[TextVideo].Text) > 0 then - Static[StaticVideo].Visible := true + Statics[StaticVideo].Visible := true else - Static[StaticVideo].Visible := false; + Statics[StaticVideo].Visible := false; try StrToFloat(Text[TextVideoGAP].Text); if StrToFloat(Text[TextVideoGAP].Text)<> 0 then - Static[StaticVideoGAP].Visible := true + Statics[StaticVideoGAP].Visible := true else - Static[StaticVideoGAP].Visible := false; + Statics[StaticVideoGAP].Visible := false; except - Static[StaticVideoGAP].Visible := false; + Statics[StaticVideoGAP].Visible := false; end; if LowerCase(Text[TextRelative].Text) = 'yes' then - Static[StaticRelative].Visible := true + Statics[StaticRelative].Visible := true else - Static[StaticRelative].Visible := false; + Statics[StaticRelative].Visible := false; try StrToInt(Text[TextResolution].Text); if (StrToInt(Text[TextResolution].Text) <> 0) and (StrToInt(Text[TextResolution].Text) >= 1) then - Static[StaticResolution].Visible := true + Statics[StaticResolution].Visible := true else - Static[StaticResolution].Visible := false; + Statics[StaticResolution].Visible := false; except - Static[StaticResolution].Visible := false; + Statics[StaticResolution].Visible := false; end; try StrToInt(Text[TextNotesGAP].Text); - Static[StaticNotesGAP].Visible := true; + Statics[StaticNotesGAP].Visible := true; except - Static[StaticNotesGAP].Visible := false; + Statics[StaticNotesGAP].Visible := false; end; // start try StrToFloat(Text[TextStart].Text); if (StrToFloat(Text[TextStart].Text) > 0) then - Static[StaticStart].Visible := true + Statics[StaticStart].Visible := true else - Static[StaticStart].Visible := false; + Statics[StaticStart].Visible := false; except - Static[StaticStart].Visible := false; + Statics[StaticStart].Visible := false; end; // GAP try StrToFloat(Text[TextGAP].Text); - Static[StaticGAP].Visible := true; + Statics[StaticGAP].Visible := true; except - Static[StaticGAP].Visible := false; + Statics[StaticGAP].Visible := false; end; // BPM try StrToFloat(Text[TextBPM].Text); if (StrToFloat(Text[TextBPM].Text) > 0) then - Static[StaticBPM].Visible := true + Statics[StaticBPM].Visible := true else - Static[StaticBPM].Visible := false; + Statics[StaticBPM].Visible := false; except - Static[StaticBPM].Visible := false; + Statics[StaticBPM].Visible := false; end; end; diff --git a/cmake/src/screens/UScreenEditSub.pas b/cmake/src/screens/UScreenEditSub.pas index 3e1f3c1c..7956b127 100644 --- a/cmake/src/screens/UScreenEditSub.pas +++ b/cmake/src/screens/UScreenEditSub.pas @@ -56,6 +56,7 @@ uses type TScreenEditSub = class(TMenu) private + AktBeat: integer; //Variable is True if no Song is loaded Error: boolean; @@ -90,6 +91,7 @@ type MidiLastNote: integer; TextEditMode: boolean; + editText: UTF8String; //backup of current text in text-edit-mode Lyric: TEditorLyrics; @@ -110,17 +112,19 @@ type procedure PasteText; procedure CopySentence(Src, Dst: integer); procedure CopySentences(Src, Dst, Num: integer); + procedure DrawStatics; + procedure DrawInfoBar(x, y, w, h: integer); //Note Name Mod function GetNoteName(Note: integer): string; public Tex_Background: TTexture; FadeOut: boolean; constructor Create; override; - procedure onShow; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - function ParseInputEditText(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + procedure OnShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + function ParseInputEditText(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; function Draw: boolean; override; - procedure onHide; override; + procedure OnHide; override; end; implementation @@ -130,14 +134,44 @@ uses UDraw, UNote, USkins, - ULanguage; + ULanguage, + UTextEncoding, + UUnicodeUtils, + UPath; + + +procedure OnSaveEncodingError(Value: boolean; Data: Pointer); +var + SResult: TSaveSongResult; + FilePath: IPath; + Success: boolean; +begin + Success := false; + if (Value) then + begin + CurrentSong.Encoding := encUTF8; + FilePath := CurrentSong.Path.Append(CurrentSong.FileName); + // create backup file + FilePath.CopyFile(Path(FilePath.ToUTF8 + '.ansi.bak'), false); + // store in UTF-8 encoding + SResult := SaveSong(CurrentSong, Lines[0], FilePath, + boolean(Data)); + Success := (SResult = ssrOK); + end; + + if (Success) then + ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED')) + else + ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED')); +end; // Method for input parsing. If false is returned, GetNextWindow // should be checked to know the next window to load; -function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var SDL_ModState: word; R: real; + SResult: TSaveSongResult; begin Result := true; @@ -152,40 +186,68 @@ begin + KMOD_LCTRL + KMOD_RCTRL + KMOD_LALT + KMOD_RALT {+ KMOD_CAPS}); if (PressedDown) then // Key Down - begin // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + begin + // check normal keys + case PressedKey of + SDLK_Q: begin Result := false; Exit; end; - 'S': + SDLK_S: begin // Save Song - if SDL_ModState = KMOD_LSHIFT then - SaveSong(CurrentSong, Lines[0], CurrentSong.Path + CurrentSong.FileName, true) + SResult := SaveSong(CurrentSong, Lines[0], CurrentSong.Path.Append(CurrentSong.FileName), + (SDL_ModState = KMOD_LSHIFT)); + if (SResult = ssrOK) then + begin + //ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED')); + Text[TextDebug].Text := Language.Translate('INFO_FILE_SAVED'); + end + else if (SResult = ssrEncodingError) then + begin + ScreenPopupCheck.ShowPopup(Language.Translate('ENCODING_ERROR_ASK_FOR_UTF8'), OnSaveEncodingError, + Pointer(SDL_ModState = KMOD_LSHIFT), true); + end else - SaveSong(CurrentSong, Lines[0], CurrentSong.Path + CurrentSong.FileName, false); + begin + ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED')); + end; + Exit; + end; - {if SDL_ModState = KMOD_LSHIFT or KMOD_LCTRL + KMOD_LALT then - // Save Song - SaveSongDebug(CurrentSong, Lines[0], 'C:\song.asm', false);} + SDLK_R: //reload + begin + AudioPlayback.Stop; + {$IFDEF UseMIDIPort} + MidiOut.Close; + MidiOut.Free; + {$ENDIF} + Lyric.Free; - Exit; + onShow; + Text[TextDebug].Text := 'song reloaded'; //TODO: Language.Translate('SONG_RELOADED'); end; - 'D': + + SDLK_D: begin // Divide lengths by 2 - DivideBPM; - Exit; + if (SDL_ModState = KMOD_LSHIFT) then + begin + DivideBPM; + Exit; + end; end; - 'M': + SDLK_M: begin // Multiply lengths by 2 - MultiplyBPM; - Exit; + if (SDL_ModState = KMOD_LSHIFT) then + begin + MultiplyBPM; + Exit; + end; end; - 'C': + SDLK_C: begin // Capitalize letter at the beginning of line if SDL_ModState = 0 then @@ -201,7 +263,7 @@ begin Exit; end; - 'V': + SDLK_V: begin // Paste text if SDL_ModState = KMOD_LCTRL then @@ -217,13 +279,13 @@ begin CopySentence(CopySrc, Lines[0].Current); end; end; - 'T': + SDLK_T: begin // Fixes timings between sentences FixTimings; Exit; end; - 'P': + SDLK_P: begin if SDL_ModState = 0 then begin @@ -269,8 +331,8 @@ begin Exit; end; - // Golden Note Patch - 'G': + // Golden Note + SDLK_G: begin if (Lines[0].Line[Lines[0].Current].Note[CurrentNote].NoteType = ntGolden) then Lines[0].Line[Lines[0].Current].Note[CurrentNote].NoteType := ntNormal @@ -280,8 +342,8 @@ begin Exit; end; - // Freestyle Note Patch - 'F': + // Freestyle Note + SDLK_F: begin if (Lines[0].Line[Lines[0].Current].Note[CurrentNote].NoteType = ntFreestyle) then Lines[0].Line[Lines[0].Current].Note[CurrentNote].NoteType := ntNormal @@ -424,22 +486,40 @@ begin SDLK_F4: begin // Enter Text Edit Mode + editText := Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text; TextEditMode := true; end; SDLK_SPACE: begin - // Play Sentence - PlaySentenceMidi := false; // stop midi - PlaySentence := true; - Click := false; - AudioPlayback.Stop; - AudioPlayback.Position := GetTimeFromBeat(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start); - PlayStopTime := (GetTimeFromBeat( - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start + - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Length)); - AudioPlayback.Play; - LastClick := -100; + if (SDL_ModState = 0) or (SDL_ModState = KMOD_LSHIFT or KMOD_LCTRL) then + begin + // Play Sentence + PlaySentenceMidi := false; // stop midi + PlaySentence := true; + Click := false; + AudioPlayback.Stop; + AudioPlayback.Position := GetTimeFromBeat(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start); + PlayStopTime := (GetTimeFromBeat( + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start + + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Length)); + AudioPlayback.Play; + LastClick := -100; + end; + + if (SDL_ModState = KMOD_LSHIFT) or (SDL_ModState = KMOD_LSHIFT or KMOD_LCTRL) then + begin + // Play Midi + PlaySentenceMidi := true; + + MidiTime := USTime.GetTime; + MidiStart := GetTimeFromBeat(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start); + MidiStop := GetTimeFromBeat( + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start + + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Length); + + LastClick := -100; + end; end; SDLK_RETURN: @@ -466,11 +546,11 @@ begin // right if SDL_ModState = 0 then begin - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Inc(CurrentNote); if CurrentNote > Lines[0].Line[Lines[0].Current].HighNote then CurrentNote := 0; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.Selected := CurrentNote; end; @@ -521,11 +601,11 @@ begin // left if SDL_ModState = 0 then begin - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Dec(CurrentNote); if CurrentNote = -1 then CurrentNote := Lines[0].Line[Lines[0].Current].HighNote; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.Selected := CurrentNote; end; @@ -580,17 +660,18 @@ begin // skip to next sentence if SDL_ModState = 0 then - begin {$IFDEF UseMIDIPort} + begin + {$IFDEF UseMIDIPort} MidiOut.PutShort($81, Lines[0].Line[Lines[0].Current].Note[MidiLastNote].Tone + 60, 127); PlaySentenceMidi := false; - {$endif} + {$ENDIF} - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Inc(Lines[0].Current); CurrentNote := 0; if Lines[0].Current > Lines[0].High then Lines[0].Current := 0; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.AddLine(Lines[0].Current); Lyric.Selected := 0; @@ -617,12 +698,12 @@ begin PlaySentenceMidi := false; {$endif} - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Dec(Lines[0].Current); CurrentNote := 0; if Lines[0].Current = -1 then Lines[0].Current := Lines[0].High; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.AddLine(Lines[0].Current); Lyric.Selected := 0; @@ -642,7 +723,7 @@ begin end; // if end; -function TScreenEditSub.ParseInputEditText(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenEditSub.ParseInputEditText(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var SDL_ModState: word; begin @@ -653,39 +734,51 @@ begin + KMOD_LCTRL + KMOD_RCTRL + KMOD_LALT + KMOD_RALT {+ KMOD_CAPS}); if (PressedDown) then - begin // Key Down - case PressedKey of + begin + // check normal keys + if (IsPrintableChar(CharCode)) then + begin + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text := + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text + UCS4ToUTF8String(CharCode); + + Lyric.AddLine(Lines[0].Current); + Lyric.Selected := CurrentNote; + Exit; + end; + // check special keys + case PressedKey of SDLK_ESCAPE: begin - FadeTo(@ScreenSong); + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text := editText; + Lyric.AddLine(Lines[0].Current); + Lyric.Selected := CurrentNote; + TextEditMode := false; end; SDLK_F4, SDLK_RETURN: begin // Exit Text Edit Mode TextEditMode := false; end; - SDLK_0..SDLK_9, SDLK_A..SDLK_Z, SDLK_SPACE, SDLK_MINUS, SDLK_EXCLAIM, SDLK_COMMA, SDLK_SLASH, SDLK_ASTERISK, SDLK_QUESTION, SDLK_QUOTE, SDLK_QUOTEDBL: - begin - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text := - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text + CharCode; - end; SDLK_BACKSPACE: begin - Delete(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text, - Length(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text), 1); + UTF8Delete(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text, + LengthUTF8(Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text), 1); + Lyric.AddLine(Lines[0].Current); + Lyric.Selected := CurrentNote; end; SDLK_RIGHT: begin // right if SDL_ModState = 0 then begin - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Inc(CurrentNote); if CurrentNote > Lines[0].Line[Lines[0].Current].HighNote then CurrentNote := 0; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.Selected := CurrentNote; + editText := Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text; end; end; SDLK_LEFT: @@ -693,12 +786,13 @@ begin // left if SDL_ModState = 0 then begin - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 0; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; Dec(CurrentNote); if CurrentNote = -1 then CurrentNote := Lines[0].Line[Lines[0].Current].HighNote; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.Selected := CurrentNote; + editText := Lines[0].Line[Lines[0].Current].Note[CurrentNote].Text; end; end; end; @@ -719,15 +813,17 @@ procedure TScreenEditSub.DivideBPM; var C: integer; N: integer; -begin + +begin CurrentSong.BPM[0].BPM := CurrentSong.BPM[0].BPM / 2; + for C := 0 to Lines[0].High do begin Lines[0].Line[C].Start := Lines[0].Line[C].Start div 2; Lines[0].Line[C].End_ := Lines[0].Line[C].End_ div 2; for N := 0 to Lines[0].Line[C].HighNote do begin - Lines[0].Line[C].Note[N].Start := Lines[0].Line[C].Note[N].Start div 2; + Lines[0].Line[C].Note[N].Start := Lines[0].Line[C].Note[N].Start div 2; Lines[0].Line[C].Note[N].Length := Round(Lines[0].Line[C].Note[N].Length / 2); end; // N end; // C @@ -758,9 +854,11 @@ var S: string; begin // temporary -{ for C := 0 to Lines[0].High do + { + for C := 0 to Lines[0].High do for N := 0 to Lines[0].Line[C].HighNut do - Lines[0].Line[C].Note[N].Text := AnsiLowerCase(Lines[0].Line[C].Note[N].Text);} + Lines[0].Line[C].Note[N].Text := UTF8LowerCase(Lines[0].Line[C].Note[N].Text); + } for C := 0 to Lines[0].High do begin @@ -890,7 +988,7 @@ begin begin Inc(HighNote); SetLength(Note, HighNote + 1); - Note[HighNote] := Note[N]; + Note[HighNote] := Lines[0].Line[CStart].Note[N]; End_ := Note[HighNote].Start + Note[HighNote].Length; if Note[HighNote].Tone < BaseNote then @@ -916,7 +1014,7 @@ begin Lines[0].Current := Lines[0].Current + 1; CurrentNote := 0; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; Lyric.AddLine(Lines[0].Current); end; @@ -979,7 +1077,7 @@ begin Inc(Note[CurrentNote+1].Start); Dec(Note[CurrentNote+1].Length); Note[CurrentNote+1].Text := '- '; - Note[CurrentNote+1].Color := 0; + Note[CurrentNote+1].Color := 1; end; end; @@ -1009,7 +1107,7 @@ begin if CurrentNote > Lines[0].Line[C].HighNote then Dec(CurrentNote); - Lines[0].Line[C].Note[CurrentNote].Color := 1; + Lines[0].Line[C].Note[CurrentNote].Color := 2; end //Last Note of current Sentence Deleted - > Delete Sentence else @@ -1029,7 +1127,7 @@ begin else Lines[0].Current := 0; - Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 1; + Lines[0].Line[Lines[0].Current].Note[CurrentNote].Color := 2; end; end; end; @@ -1085,14 +1183,16 @@ var N: integer; NHigh: integer; begin -{ C := Lines[0].Current; + { + C := Lines[0].Current; for N := Lines[0].Line[C].HighNut downto 1 do begin Lines[0].Line[C].Note[N].Text := Lines[0].Line[C].Note[N-1].Text; end; // for - Lines[0].Line[C].Note[0].Text := '- ';} + Lines[0].Line[C].Note[0].Text := '- '; + } C := Lines[0].Current; NHigh := Lines[0].Line[C].HighNote; @@ -1181,73 +1281,288 @@ begin CopySentence(Src + C, Dst + C); end; +procedure TScreenEditSub.DrawStatics; +var + x, y, w, h: Integer; +begin + //Theme: + //bg + glDisable(GL_BLEND); + + x := 0; + y := 0; + w := 800; + h := 600; + glColor4f(0.3, 0.5, 0.6, 1); + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + // Line + glColor4f(0.9, 0.9, 0.9, 1); + x := 20; + y := 5; + w := 200; + h := 40; + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + // Note + x := 260; + y := 5; + w := 200; + h := 40; + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + // some borders + x := 20; + y := 55; + w := 760; + h := 236; + glColor4f(0.9, 0.9, 0.9, 1); + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + glColor4f(0, 0, 0, 1); + glLineWidth(2); + glBegin(GL_LINE_LOOP); + glVertex2f(x-1, y-1); + glVertex2f(x+w+1, y-1); + glVertex2f(x+w+1, y+h+1); + glVertex2f(x-1, y+h+1); + glEnd; + + x := 20; + y := 305; + w := 760; + h := 135; + glColor4f(0.9, 0.9, 0.9, 1); + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + glColor4f(0, 0, 0, 1); + glLineWidth(2); + glBegin(GL_LINE_LOOP); + glVertex2f(x-1, y-1); + glVertex2f(x+w+1, y-1); + glVertex2f(x+w+1, y+h+1); + glVertex2f(x-1, y+h+1); + glEnd; + + x := 20; + y := 500; + w := 760; + h := 40; + glColor4f(0.9, 0.9, 0.9, 1); + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + glColor4f(0, 0, 0, 1); + glLineWidth(2); + glBegin(GL_LINE_LOOP); + glVertex2f(x-1, y-1); + glVertex2f(x+w+1, y-1); + glVertex2f(x+w+1, y+h+1); + glVertex2f(x-1, y+h+1); + glEnd; + + glLineWidth(1); +end; + +procedure TScreenEditSub.DrawInfoBar(x, y, w, h: integer); +var + start, end_: integer; + ww: integer; + + pos: real; + br: real; + + line, note: integer; + numLines, numNotes: integer; + +begin + numLines := Length(Lines[0].Line); + + if(numLines=0) then + Exit; + + start := Lines[0].Line[0].Start; + end_ := Lines[0].Line[numLines-1].End_; + ww := end_ - start; + + glColor4f(0, 0, 0, 1); + glDisable(GL_BLEND); + glLineWidth(2); + glBegin(GL_LINE_LOOP); + glVertex2f(x-1, y-1); + glVertex2f(x+w+1, y-1); + glVertex2f(x+w+1, y+h+1); + glVertex2f(x-1, y+h+1); + glEnd; + + glColor4f(0.9, 0.9, 0.9, 1); + glbegin(gl_quads); + glVertex2f(x, y); + glVertex2f(x, y+h); + glVertex2f(x+w, y+h); + glVertex2f(x+w, y); + glEnd; + + + for line := 0 to numLines - 1 do + begin + if (line = Lines[0].Current) and not (PlaySentence or PlaySentenceMidi) then + glColor4f(0.4, 0.4, 0, 1) + else + glColor4f(1, 0.6, 0, 1); + + + start := Lines[0].Line[line].Note[0].Start; + end_ := Lines[0].Line[line].Note[Lines[0].Line[line].HighNote].Start+ + Lines[0].Line[line].Note[Lines[0].Line[line].HighNote].Length; + + pos := start/ww*w; + br := (end_-start)/ww*w; + + glbegin(gl_quads); + glVertex2f(x+pos, y); + glVertex2f(x+pos, y+h); + glVertex2f(x+pos+br, y+h); + glVertex2f(x+pos+br, y); + glEnd; + { + numNotes := Length(Lines[0].Line[line].Nuta); + + for note := 0 to numNotes - 1 do + begin + + end; } + end; + + if(PlaySentence or PlaySentenceMidi) then + begin + glColor4f(0, 0, 0, 0.5); + pos := 0; + br := AktBeat/ww*w; + if (br>w) then + br := w; + end else + begin + glColor4f(1, 0, 0, 1); + pos := Lines[0].Line[Lines[0].Current].Note[CurrentNote].Start/ww*w; + br := Lines[0].Line[Lines[0].Current].Note[CurrentNote].Length/ww*w; + if (br<1) then + br := 1; + end; + + glEnable(GL_BLEND); + glbegin(gl_quads); + glVertex2f(x+pos, y); + glVertex2f(x+pos, y+h); + glVertex2f(x+pos+br, y+h); + glVertex2f(x+pos+br, y); + glEnd; + glDisable(GL_BLEND); + + glLineWidth(1); +end; + constructor TScreenEditSub.Create; begin inherited Create; SetLength(Player, 1); // line - AddStatic(20, 10, 80, 30, 0, 0, 0, Skin.GetTextureFileName('ButtonF'), TEXTURE_TYPE_COLORIZED); - AddText(40, 17, 1, 18, 1, 1, 1, 'Line'); - TextSentence := AddText(120, 14, 1, 24, 0, 0, 0, '0 / 0'); + AddText(40, 11, 1, 30, 0, 0, 0, 'Line:'); + TextSentence := AddText(110, 11, 1, 30, 0, 0, 0, '0 / 0'); + // Note - AddStatic(220, 10, 80, 30, 0, 0, 0, Skin.GetTextureFileName('ButtonF'), TEXTURE_TYPE_COLORIZED); - AddText(242, 17, 1, 18, 1, 1, 1, 'Note'); - TextNote := AddText(320, 14, 1, 24, 0, 0, 0, '0 / 0'); + AddText(282, 11, 1, 30, 0, 0, 0, 'Note:'); + TextNote := AddText(360, 11, 1, 30, 0, 0, 0, '0 / 0'); // file info - AddStatic(150, 50, 500, 150, 0, 0, 0, Skin.GetTextureFileName('MainBar'), TEXTURE_TYPE_COLORIZED); - AddStatic(151, 52, 498, 146, 1, 1, 1, Skin.GetTextureFileName('MainBar'), TEXTURE_TYPE_COLORIZED); - AddText(180, 65, 0, 24, 0, 0, 0, 'Title:'); - AddText(180, 90, 0, 24, 0, 0, 0, 'Artist:'); - AddText(180, 115, 0, 24, 0, 0, 0, 'Mp3:'); - AddText(180, 140, 0, 24, 0, 0, 0, 'BPM:'); - AddText(180, 165, 0, 24, 0, 0, 0, 'GAP:'); - - TextTitle := AddText(250, 65, 0, 24, 0, 0, 0, 'a'); - TextArtist := AddText(250, 90, 0, 24, 0, 0, 0, 'b'); - TextMp3 := AddText(250, 115, 0, 24, 0, 0, 0, 'c'); - TextBPM := AddText(250, 140, 0, 24, 0, 0, 0, 'd'); - TextGAP := AddText(250, 165, 0, 24, 0, 0, 0, 'e'); - -{ AddInteraction(2, TextTitle); - AddInteraction(2, TextArtist); - AddInteraction(2, TextMp3); - AddInteraction(2, TextBPM); - AddInteraction(2, TextGAP);} + AddText(30, 65, 0, 24, 0, 0, 0, 'Title:'); + AddText(30, 90, 0, 24, 0, 0, 0, 'Artist:'); + AddText(30, 115, 0, 24, 0, 0, 0, 'Mp3:'); + AddText(30, 140, 0, 24, 0, 0, 0, 'BPM:'); + AddText(30, 165, 0, 24, 0, 0, 0, 'GAP:'); + + TextTitle := AddText(180, 65, 0, 24, 0, 0, 0, 'a'); + TextArtist := AddText(180, 90, 0, 24, 0, 0, 0, 'b'); + TextMp3 := AddText(180, 115, 0, 24, 0, 0, 0, 'c'); + TextBPM := AddText(180, 140, 0, 24, 0, 0, 0, 'd'); + TextGAP := AddText(180, 165, 0, 24, 0, 0, 0, 'e'); // note info - AddText(20, 190, 0, 24, 0, 0, 0, 'Start:'); - AddText(20, 215, 0, 24, 0, 0, 0, 'Duration:'); - AddText(20, 240, 0, 24, 0, 0, 0, 'Tone:'); - AddText(20, 265, 0, 24, 0, 0, 0, 'Text:'); + AddText(30, 190, 0, 24, 0, 0, 0, 'Start:'); + AddText(30, 215, 0, 24, 0, 0, 0, 'Duration:'); + AddText(30, 240, 0, 24, 0, 0, 0, 'Tone:'); + AddText(30, 265, 0, 24, 0, 0, 0, 'Text:'); //AddText(500, 265, 0, 8, 0, 0, 0, 'VideoGap:'); + + TextNStart := AddText(180, 190, 0, 24, 0, 0, 0, 'a'); + TextNLength := AddText(180, 215, 0, 24, 0, 0, 0, 'b'); + TextNTon := AddText(180, 240, 0, 24, 0, 0, 0, 'c'); + TextNText := AddText(180, 265, 0, 24, 0, 0, 0, 'd'); - TextNStart := AddText(120, 190, 0, 24, 0, 0, 0, 'a'); - TextNLength := AddText(120, 215, 0, 24, 0, 0, 0, 'b'); - TextNTon := AddText(120, 240, 0, 24, 0, 0, 0, 'c'); - TextNText := AddText(120, 265, 0, 24, 0, 0, 0, 'd'); + //TextVideoGap := AddText(600, 265, 0, 24, 0, 0, 0, 'e'); // debug - TextDebug := AddText(30, 550, 0, 8, 0, 0, 0, ''); + TextDebug := AddText(30, 550, 0, 27, 0, 0, 0, ''); end; -procedure TScreenEditSub.onShow; +procedure TScreenEditSub.OnShow; +var + FileExt: IPath; begin inherited; - Log.LogStatus('Initializing', 'TEditScreen.onShow'); + AudioPlayback.Stop; + PlaySentence := false; + PlaySentenceMidi := false; + + Log.LogStatus('Initializing', 'TEditScreen.OnShow'); Lyric := TEditorLyrics.Create; ResetSingTemp; try - //Check if File is XML - if copy(CurrentSong.FileName,length(CurrentSong.FileName)-3,4) = '.xml' then - Error := not CurrentSong.LoadXMLSong() - else - Error := not CurrentSong.LoadSong(); + //Check if File is XML + FileExt := CurrentSong.FileName.GetExtension; + if FileExt.ToUTF8 = '.xml' then + Error := not CurrentSong.LoadXMLSong() + else + begin + // reread header with custom tags + Error := not CurrentSong.Analyse(true); + if not Error then + Error := not CurrentSong.LoadSong; + end; except Error := true; end; @@ -1263,18 +1578,16 @@ begin begin {$IFDEF UseMIDIPort} MidiOut := TMidiOutput.Create(nil); - if Ini.Debug = 1 then - MidiOut.ProductName := 'Microsoft GS Wavetable SW Synth'; // for my kxproject without midi table MidiOut.Open; {$ENDIF} Text[TextTitle].Text := CurrentSong.Title; Text[TextArtist].Text := CurrentSong.Artist; - Text[TextMp3].Text := CurrentSong.Mp3; + Text[TextMp3].Text := CurrentSong.Mp3.ToUTF8; Lines[0].Current := 0; CurrentNote := 0; - Lines[0].Line[0].Note[0].Color := 1; - AudioPlayback.Open(CurrentSong.Path + CurrentSong.Mp3); + Lines[0].Line[0].Note[0].Color := 2; + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); //Set Down Music Volume for Better hearability of Midi Sounds //Music.SetVolume(0.4); @@ -1304,8 +1617,8 @@ end; function TScreenEditSub.Draw: boolean; var Pet: integer; - AktBeat: integer; begin + glClearColor(1,1,1,1); // midi music @@ -1395,15 +1708,17 @@ begin Text[TextNText].Text := Text[TextNText].Text + '|'; // draw static menu - inherited Draw; - + DrawStatics; + DrawInfoBar(20, 460, 760, 20); + //inherited Draw; + DrawFG; // draw notes - SingDrawNoteLines(20, 300, 780, 15); + SingDrawNoteLines(20, 305, 780, 15); //Error Drawing when no Song is loaded if not Error then begin - SingDrawBeatDelimeters(40, 300, 760, 0); - EditDrawLine(40, 405, 760, 0, 15); + SingDrawBeatDelimeters(40, 305, 760, 0); + EditDrawLine(40, 410, 760, 0, 15); end; // draw text @@ -1412,7 +1727,7 @@ begin Result := true; end; -procedure TScreenEditSub.onHide; +procedure TScreenEditSub.OnHide; begin {$IFDEF UseMIDIPort} MidiOut.Close; @@ -1463,4 +1778,4 @@ begin end; end; -end. +end. \ No newline at end of file diff --git a/cmake/src/screens/UScreenLevel.pas b/cmake/src/screens/UScreenLevel.pas index b41a8535..1ead9773 100644 --- a/cmake/src/screens/UScreenLevel.pas +++ b/cmake/src/screens/UScreenLevel.pas @@ -46,8 +46,8 @@ type TScreenLevel = class(TMenu) public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; @@ -58,29 +58,34 @@ uses UMain, UIni, USong, - UTexture; + UTexture, + UUnicodeUtils; -function TScreenLevel.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenLevel.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; end; end; - + // check special keys case PressedKey of SDLK_ESCAPE, SDLK_BACKSPACE : begin AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(@ScreenName); + + if Ini.OnSongClick = sSelectPlayer then + FadeTo(@ScreenMain) + else + FadeTo(@ScreenName); end; SDLK_RETURN: @@ -105,8 +110,6 @@ begin end; constructor TScreenLevel.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; @@ -119,7 +122,7 @@ begin Interaction := 0; end; -procedure TScreenLevel.onShow; +procedure TScreenLevel.OnShow; begin inherited; diff --git a/cmake/src/screens/UScreenLoading.pas b/cmake/src/screens/UScreenLoading.pas index ea639ba3..e368f181 100644 --- a/cmake/src/screens/UScreenLoading.pas +++ b/cmake/src/screens/UScreenLoading.pas @@ -43,10 +43,11 @@ uses type TScreenLoading = class(TMenu) public - Fadeout: boolean; + Fadeout: boolean; + constructor Create; override; - procedure onShow; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + procedure OnShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; end; implementation @@ -55,7 +56,7 @@ uses UGraphic, UTime; -function TScreenLoading.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenLoading.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; end; @@ -69,7 +70,7 @@ begin Fadeout := false; end; -procedure TScreenLoading.onShow; +procedure TScreenLoading.OnShow; begin inherited; end; diff --git a/cmake/src/screens/UScreenMain.pas b/cmake/src/screens/UScreenMain.pas index a4e6009f..8bb9365b 100644 --- a/cmake/src/screens/UScreenMain.pas +++ b/cmake/src/screens/UScreenMain.pas @@ -49,9 +49,9 @@ type TextDescriptionLong: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: widechar; + function ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; - procedure onShow; override; + procedure OnShow; override; procedure SetInteraction(Num: integer); override; procedure SetAnimationProgress(Progress: real); override; end; @@ -67,11 +67,11 @@ uses Textgl, ULanguage, UParty, - UDLLManager, UScreenCredits, - USkins; + USkins, + UUnicodeUtils; -function TScreenMain.ParseInput(PressedKey: cardinal; CharCode: widechar; +function TScreenMain.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var SDL_ModState: word; @@ -84,37 +84,32 @@ begin if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': - begin + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; end; - 'C': - begin + Ord('C'): begin if (SDL_ModState = KMOD_LALT) then begin FadeTo(@ScreenCredits, SoundLib.Start); Exit; end; end; - 'M': - begin - if (Ini.Players >= 1) and (Length(DLLMan.Plugins) >= 1) then + Ord('M'): begin + if (Ini.Players >= 1) and (Party.ModesAvailable) then begin FadeTo(@ScreenPartyOptions, SoundLib.Start); Exit; end; end; - 'S': - begin + Ord('S'): begin FadeTo(@ScreenStatMain, SoundLib.Start); Exit; end; - 'E': - begin + Ord('E'): begin FadeTo(@ScreenEdit, SoundLib.Start); Exit; end; @@ -140,8 +135,13 @@ begin if (Ini.Players = 4) then PlayersPlay := 6; - ScreenName.Goto_SingScreen := false; - FadeTo(@ScreenName, SoundLib.Start); + if Ini.OnSongClick = sSelectPlayer then + FadeTo(@ScreenLevel) + else + begin + ScreenName.Goto_SingScreen := false; + FadeTo(@ScreenName, SoundLib.Start); + end; end else //show error message ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_SONGS')); @@ -152,12 +152,7 @@ begin begin if (Songs.SongList.Count >= 1) then begin - if (Length(DLLMan.Plugins) >= 1) then - begin - FadeTo(@ScreenPartyOptions, SoundLib.Start); - end - else //show error message, No Plugins Loaded - ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_PLUGINS')); + FadeTo(@ScreenPartyOptions, SoundLib.Start); end else //show error message, No Songs Loaded ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_SONGS')); @@ -172,7 +167,11 @@ begin //Editor if Interaction = 3 then begin + {$IFDEF UseMIDIPort} FadeTo(@ScreenEdit, SoundLib.Start); + {$ELSE} + ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_EDITOR')); + {$ENDIF} end; //Options @@ -232,17 +231,14 @@ begin Interaction := 0; end; -procedure TScreenMain.onShow; +procedure TScreenMain.OnShow; begin inherited; - - { display cursor (on moved) } - Display.SetCursor; - -{** - * Start background music - *} - SoundLib.StartBgMusic; + {** + * Clean up TPartyGame here + * at the moment there is no better place for this + *} + Party.Clear; end; procedure TScreenMain.SetInteraction(Num: integer); @@ -254,8 +250,8 @@ end; procedure TScreenMain.SetAnimationProgress(Progress: real); begin - Static[0].Texture.ScaleW := Progress; - Static[0].Texture.ScaleH := Progress; + Statics[0].Texture.ScaleW := Progress; + Statics[0].Texture.ScaleH := Progress; end; end. diff --git a/cmake/src/screens/UScreenName.pas b/cmake/src/screens/UScreenName.pas index d13db170..42af50d7 100644 --- a/cmake/src/screens/UScreenName.pas +++ b/cmake/src/screens/UScreenName.pas @@ -47,8 +47,8 @@ type public Goto_SingScreen: boolean; //If true then next Screen in SingScreen constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; @@ -59,9 +59,11 @@ uses UGraphic, UIni, UNote, - UTexture; + UTexture, + UUnicodeUtils; -function TScreenName.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + +function TScreenName.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var I: integer; SDL_ModState: word; @@ -74,10 +76,10 @@ begin + KMOD_LCTRL + KMOD_RCTRL + KMOD_LALT + KMOD_RALT); // check normal keys - if (IsAlphaNumericChar(CharCode) or - {(CharCode in [' ','-','_','!',',','<','/','*','?','''','"']))} IsPunctuationChar(CharCode)) then + if (IsPrintableChar(CharCode)) then begin - Button[Interaction].Text[0].Text := Button[Interaction].Text[0].Text + CharCode; + Button[Interaction].Text[0].Text := Button[Interaction].Text[0].Text + + UCS4ToUTF8String(CharCode); Exit; end; @@ -195,7 +197,7 @@ begin SDLK_BACKSPACE: begin - Button[Interaction].Text[0].DeleteLastL; + Button[Interaction].Text[0].DeleteLastLetter(); end; SDLK_ESCAPE : @@ -248,7 +250,7 @@ begin Interaction := 0; end; -procedure TScreenName.onShow; +procedure TScreenName.OnShow; var I: integer; begin diff --git a/cmake/src/screens/UScreenOpen.pas b/cmake/src/screens/UScreenOpen.pas index a854e81b..70b883c4 100644 --- a/cmake/src/screens/UScreenOpen.pas +++ b/cmake/src/screens/UScreenOpen.pas @@ -34,10 +34,13 @@ interface {$I switches.inc} uses + Math, + SysUtils, + gl, + SDL, + UPath, UMenu, UMusic, - SDL, - SysUtils, UFiles, UTime, USongs, @@ -46,26 +49,31 @@ uses UTexture, UMenuText, ULyrics, - Math, - gl, UThemes; type TScreenOpen = class(TMenu) private - TextF: array[0..1] of integer; - TextN: integer; - public - Tex_Background: TTexture; - FadeOut: boolean; - Path: string; - BackScreen: pointer; + //fTextF: array[0..1] of integer; + fTextN: integer; // text-box ID of filename + fFilename: IPath; + fBackScreen: PMenu; + procedure AddBox(X, Y, W, H: real); + public constructor Create; override; - procedure onShow; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; -// function Draw: boolean; override; -// procedure Finish; + procedure OnShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + + {** + * Set by the caller to provide a default filename. + * Set to the selected filename after calling this screen or to PATH_NONE + * if the screen was aborted. + * TODO: maybe pass this value with a callback OnValueChanged() + *} + property Filename: IPath READ fFilename WRITE fFilename; + {** The screen that is shown after this screen is closed (set by the caller) *} + property BackScreen: PMenu READ fBackScreen WRITE fBackScreen; end; implementation @@ -75,45 +83,41 @@ uses UDraw, UMain, UScreenEditConvert, - USkins; + USkins, + UUnicodeUtils; -function TScreenOpen.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOpen.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then // Key Down begin // check normal keys - case CharCode of - '0'..'9', 'a'..'z', 'A'..'Z', ' ', '-', '.', ':', '\': - begin - if Interaction = 0 then - begin - Text[TextN].Text := Text[TextN].Text + CharCode; - end; - end; + if (IsPrintableChar(CharCode)) then + begin + if (Interaction = 0) then + begin + Text[fTextN].Text := Text[fTextN].Text + UCS4ToUTF8String(CharCode); + Exit; + end; end; // check special keys case PressedKey of - SDLK_Q: - begin - Result := false; - end; - 8: // del + SDLK_BACKSPACE: // del begin if Interaction = 0 then begin - Text[TextN].DeleteLastL; + Text[fTextN].DeleteLastLetter; end; end; SDLK_ESCAPE: begin //Empty Filename and go to last Screen - ConversionFileName := ''; + fFileName := PATH_NONE; AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(BackScreen); + FadeTo(fBackScreen); end; SDLK_RETURN: @@ -121,16 +125,16 @@ begin if (Interaction = 2) then begin //Update Filename and go to last Screen - ConversionFileName := Text[TextN].Text; + fFileName := Path(Text[fTextN].Text); AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(BackScreen); + FadeTo(fBackScreen); end else if (Interaction = 1) then begin //Empty Filename and go to last Screen - ConversionFileName := ''; + fFileName := PATH_NONE; AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(BackScreen); + FadeTo(fBackScreen); end; end; @@ -165,21 +169,25 @@ constructor TScreenOpen.Create; begin inherited Create; + fFilename := PATH_NONE; + // line -{ AddStatic(20, 10, 80, 30, 0, 0, 0, 'MainBar', 'JPG', TEXTURE_TYPE_COLORIZED); + { + AddStatic(20, 10, 80, 30, 0, 0, 0, 'MainBar', 'JPG', TEXTURE_TYPE_COLORIZED); AddText(35, 17, 1, 18, 1, 1, 1, 'line'); - TextSentence := AddText(120, 14, 1, 24, 0, 0, 0, '0 / 0');} + TextSentence := AddText(120, 14, 1, 24, 0, 0, 0, '0 / 0'); + } // file list -// AddBox(400, 100, 350, 450); + //AddBox(400, 100, 350, 450); -// TextF[0] := AddText(430, 155, 0, 24, 0, 0, 0, 'a'); -// TextF[1] := AddText(430, 180, 0, 24, 0, 0, 0, 'a'); + //TextF[0] := AddText(430, 155, 0, 24, 0, 0, 0, 'a'); + //TextF[1] := AddText(430, 180, 0, 24, 0, 0, 0, 'a'); // file name AddBox(20, 540, 500, 40); - TextN := AddText(50, 548, 0, 24, 0, 0, 0, ConversionFileName); - AddInteraction(iText, TextN); + fTextN := AddText(50, 548, 0, 24, 0, 0, 0, fFileName.ToUTF8); + AddInteraction(iText, fTextN); // buttons {AddButton(540, 540, 100, 40, Skin.SkinPath + Skin.ButtonF); @@ -196,11 +204,12 @@ begin end; -procedure TScreenOpen.onShow; +procedure TScreenOpen.OnShow; begin inherited; Interaction := 0; + Text[fTextN].Text := fFilename.ToUTF8(); end; (* diff --git a/cmake/src/screens/UScreenOptions.pas b/cmake/src/screens/UScreenOptions.pas index a6486075..bdb37701 100644 --- a/cmake/src/screens/UScreenOptions.pas +++ b/cmake/src/screens/UScreenOptions.pas @@ -34,9 +34,9 @@ interface {$I switches.inc} uses - UMenu, SDL, SysUtils, + UMenu, UDisplay, UMusic, UFiles, @@ -48,8 +48,8 @@ type public TextDescription: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure InteractNext; override; procedure InteractPrev; override; procedure InteractNextRow; override; @@ -60,16 +60,17 @@ type implementation uses - UGraphic; + UGraphic, + UUnicodeUtils; -function TScreenOptions.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptions.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -145,8 +146,6 @@ begin end; constructor TScreenOptions.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; @@ -189,7 +188,7 @@ begin Interaction := 0; end; -procedure TScreenOptions.onShow; +procedure TScreenOptions.OnShow; begin inherited; end; diff --git a/cmake/src/screens/UScreenOptionsAdvanced.pas b/cmake/src/screens/UScreenOptionsAdvanced.pas index 0fb8153c..dd727dd8 100644 --- a/cmake/src/screens/UScreenOptionsAdvanced.pas +++ b/cmake/src/screens/UScreenOptionsAdvanced.pas @@ -34,8 +34,8 @@ interface {$I switches.inc} uses - UMenu, SDL, + UMenu, UDisplay, UMusic, UFiles, @@ -46,24 +46,25 @@ type TScreenOptionsAdvanced = class(TMenu) public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; end; implementation uses UGraphic, + UUnicodeUtils, SysUtils; -function TScreenOptionsAdvanced.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptionsAdvanced.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -75,8 +76,7 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE : begin - // Escape -> save nothing - just leave this screen - + Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenOptions); end; @@ -120,8 +120,6 @@ begin end; constructor TScreenOptionsAdvanced.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; @@ -155,12 +153,12 @@ begin AddButton(Theme.OptionsAdvanced.ButtonExit); if (Length(Button[0].Text)=0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); Interaction := 0; end; -procedure TScreenOptionsAdvanced.onShow; +procedure TScreenOptionsAdvanced.OnShow; begin inherited; diff --git a/cmake/src/screens/UScreenOptionsGame.pas b/cmake/src/screens/UScreenOptionsGame.pas index 1d741d25..39de61e4 100644 --- a/cmake/src/screens/UScreenOptionsGame.pas +++ b/cmake/src/screens/UScreenOptionsGame.pas @@ -35,40 +35,39 @@ interface uses SDL, + UMenu, UDisplay, + UMusic, UFiles, UIni, - UMenu, - UMusic, - USongs, - UThemes; + UThemes, + USongs; type TScreenOptionsGame = class(TMenu) public old_Tabs, old_Sorting: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure RefreshSongs; end; implementation uses - SysUtils, - UGraphic; + UGraphic, + UUnicodeUtils, + SysUtils; -function TScreenOptionsGame.ParseInput(PressedKey: cardinal; - CharCode: WideChar; - PressedDown: boolean): boolean; +function TScreenOptionsGame.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if PressedDown then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -137,7 +136,7 @@ begin Theme.OptionsGame.SelectLanguage.showArrows := true; Theme.OptionsGame.SelectLanguage.oneItemOnly := true; - AddSelectSlide(Theme.OptionsGame.SelectLanguage, Ini.Language, ILanguage); + AddSelectSlide(Theme.OptionsGame.SelectLanguage, Ini.Language, ILanguageTranslated); Theme.OptionsGame.SelectTabs.showArrows := true; Theme.OptionsGame.SelectTabs.oneItemOnly := true; @@ -155,7 +154,7 @@ begin AddButton(Theme.OptionsGame.ButtonExit); if (Length(Button[0].Text) = 0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); end; @@ -166,7 +165,7 @@ begin ScreenSong.Refresh; end; -procedure TScreenOptionsGame.onShow; +procedure TScreenOptionsGame.OnShow; begin inherited; diff --git a/cmake/src/screens/UScreenOptionsGraphics.pas b/cmake/src/screens/UScreenOptionsGraphics.pas index ba1465b2..e2aacccd 100644 --- a/cmake/src/screens/UScreenOptionsGraphics.pas +++ b/cmake/src/screens/UScreenOptionsGraphics.pas @@ -46,26 +46,25 @@ type TScreenOptionsGraphics = class(TMenu) public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; end; implementation uses UGraphic, - UMain, - SysUtils, - TypInfo; + UUnicodeUtils, + SysUtils; -function TScreenOptionsGraphics.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptionsGraphics.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -77,17 +76,12 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE : begin - // Escape -> save nothing - just leave this screen - + Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenOptions); end; SDLK_RETURN: begin -{ if SelInteraction <= 1 then - begin - Restart := true; - end;} if SelInteraction = 6 then begin Ini.Save; @@ -126,8 +120,6 @@ begin end; constructor TScreenOptionsGraphics.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; LoadFromTheme(Theme.OptionsGraphics); @@ -158,11 +150,11 @@ begin AddButton(Theme.OptionsGraphics.ButtonExit); if (Length(Button[0].Text)=0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); end; -procedure TScreenOptionsGraphics.onShow; +procedure TScreenOptionsGraphics.OnShow; begin inherited; diff --git a/cmake/src/screens/UScreenOptionsLyrics.pas b/cmake/src/screens/UScreenOptionsLyrics.pas index 035b0089..468082de 100644 --- a/cmake/src/screens/UScreenOptionsLyrics.pas +++ b/cmake/src/screens/UScreenOptionsLyrics.pas @@ -46,24 +46,25 @@ type TScreenOptionsLyrics = class(TMenu) public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; end; implementation uses UGraphic, + UUnicodeUtils, SysUtils; -function TScreenOptionsLyrics.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptionsLyrics.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -75,8 +76,7 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE : begin - // Escape -> save nothing - just leave this screen - + Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenOptions); end; @@ -133,11 +133,11 @@ begin AddButton(Theme.OptionsLyrics.ButtonExit); if (Length(Button[0].Text)=0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); end; -procedure TScreenOptionsLyrics.onShow; +procedure TScreenOptionsLyrics.OnShow; begin inherited; diff --git a/cmake/src/screens/UScreenOptionsRecord.pas b/cmake/src/screens/UScreenOptionsRecord.pas index cf799204..0f9cd49a 100644 --- a/cmake/src/screens/UScreenOptionsRecord.pas +++ b/cmake/src/screens/UScreenOptionsRecord.pas @@ -61,8 +61,8 @@ type PreviewDeviceIndex: integer; // string arrays for select-slide options - InputSourceNames: array of string; - InputDeviceNames: array of string; + InputSourceNames: array of UTF8String; + InputDeviceNames: array of UTF8String; // dynamic generated themes for channel select-sliders SelectSlideChannelTheme: array of TThemeSelectSlide; @@ -95,9 +95,9 @@ type public constructor Create; override; function Draw: boolean; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; - procedure onHide; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; + procedure OnHide; override; end; const @@ -126,33 +126,34 @@ uses UFiles, UDisplay, UIni, + UUnicodeUtils, ULog; -function TScreenOptionsRecord.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptionsRecord.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; end; - '+': + Ord('+'): begin // FIXME: add a nice volume-slider instead // or at least provide visualization and acceleration if the user holds the key pressed. ChangeVolume(0.02); end; - '-': + Ord('-'): begin // FIXME: add a nice volume-slider instead // or at least provide visualization and acceleration if the user holds the key pressed. ChangeVolume(-0.02); end; - 'T': + Ord('T'): begin if ((SDL_GetModState() and KMOD_SHIFT) <> 0) then Ini.ThresholdIndex := (Ini.ThresholdIndex + Length(IThresholdVals) - 1) mod Length(IThresholdVals) @@ -167,17 +168,23 @@ begin SDLK_BACKSPACE: begin // TODO: Show Save/Abort screen - Ini.Save; - AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(@ScreenOptions); + if (AudioInputProcessor.ValidateSettings()) then + begin + Ini.Save; + AudioPlayback.PlaySound(SoundLib.Back); + FadeTo(@ScreenOptions); + end; end; SDLK_RETURN: begin if (SelInteraction = ExitButtonIID) then begin - Ini.Save; - AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(@ScreenOptions); + if (AudioInputProcessor.ValidateSettings()) then + begin + Ini.Save; + AudioPlayback.PlaySound(SoundLib.Back); + FadeTo(@ScreenOptions); + end; end; end; SDLK_DOWN: @@ -299,7 +306,7 @@ begin // add slider SelectSlideChannelID[ChannelIndex] := AddSelectSlide(ChannelTheme^, - InputDeviceCfg.ChannelToPlayerMap[ChannelIndex], IChannelPlayer); + InputDeviceCfg.ChannelToPlayerMap[ChannelIndex], IChannelPlayerTranslated); end else begin @@ -307,7 +314,7 @@ begin // add slider but hide it and assign a dummy variable to it SelectSlideChannelID[ChannelIndex] := AddSelectSlide(ChannelTheme^, - ChannelToPlayerMapDummy, IChannelPlayer); + ChannelToPlayerMapDummy, IChannelPlayerTranslated); SelectsS[SelectSlideChannelID[ChannelIndex]].Visible := false; end; end; @@ -322,7 +329,7 @@ begin // I uncommented the stuff above, because it's not skinable :X AddButton(Theme.OptionsRecord.ButtonExit); if (Length(Button[0].Text) = 0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); // store InteractionID if (Length(AudioInputProcessor.DeviceList) > 0) then ExitButtonIID := MaxChannelCount + 2 @@ -373,7 +380,7 @@ begin // show slider UpdateSelectSlideOptions(SelectSlideChannelTheme[ChannelIndex], - SelectSlideChannelID[ChannelIndex], IChannelPlayer, + SelectSlideChannelID[ChannelIndex], IChannelPlayerTranslated, InputDeviceCfg.ChannelToPlayerMap[ChannelIndex]); SelectsS[SelectSlideChannelID[ChannelIndex]].Visible := true; end @@ -383,7 +390,7 @@ begin // hide slider and assign a dummy variable to it UpdateSelectSlideOptions(SelectSlideChannelTheme[ChannelIndex], - SelectSlideChannelID[ChannelIndex], IChannelPlayer, + SelectSlideChannelID[ChannelIndex], IChannelPlayerTranslated, ChannelToPlayerMapDummy); SelectsS[SelectSlideChannelID[ChannelIndex]].Visible := false; end; @@ -418,7 +425,7 @@ begin NextVolumePollTime := 0; end; -procedure TScreenOptionsRecord.onShow; +procedure TScreenOptionsRecord.OnShow; var ChannelIndex: integer; begin @@ -433,10 +440,10 @@ begin SetLength(ChannelPeak, MaxChannelCount); - StartPreview(); + UpdateInputDevice(); end; -procedure TScreenOptionsRecord.onHide; +procedure TScreenOptionsRecord.OnHide; var ChannelIndex: integer; begin diff --git a/cmake/src/screens/UScreenOptionsSound.pas b/cmake/src/screens/UScreenOptionsSound.pas index aa87ceb4..c0efa4d8 100644 --- a/cmake/src/screens/UScreenOptionsSound.pas +++ b/cmake/src/screens/UScreenOptionsSound.pas @@ -34,8 +34,8 @@ interface {$I switches.inc} uses - UMenu, SDL, + UMenu, UDisplay, UMusic, UFiles, @@ -46,26 +46,27 @@ type TScreenOptionsSound = class(TMenu) public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: widechar; + function ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; - procedure onShow; override; + procedure OnShow; override; end; implementation uses UGraphic, + UUnicodeUtils, SysUtils; function TScreenOptionsSound.ParseInput(PressedKey: cardinal; - CharCode: widechar; PressedDown: boolean): boolean; + CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -77,7 +78,7 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE: begin - // Escape -> save nothing - just leave this screen + Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenOptions); end; @@ -172,12 +173,12 @@ begin AddButton(Theme.OptionsSound.ButtonExit); if (Length(Button[0].Text) = 0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); Interaction := 0; end; -procedure TScreenOptionsSound.onShow; +procedure TScreenOptionsSound.OnShow; begin inherited; Interaction := 0; diff --git a/cmake/src/screens/UScreenOptionsThemes.pas b/cmake/src/screens/UScreenOptionsThemes.pas index 1e7407f1..94475cc7 100644 --- a/cmake/src/screens/UScreenOptionsThemes.pas +++ b/cmake/src/screens/UScreenOptionsThemes.pas @@ -49,8 +49,8 @@ type public SkinSelect: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure InteractInc; override; procedure InteractDec; override; end; @@ -61,17 +61,18 @@ uses SysUtils, UGraphic, UMain, - UPath, + UPathUtils, + UUnicodeUtils, USkins; -function TScreenOptionsThemes.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenOptionsThemes.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -83,7 +84,12 @@ begin SDLK_ESCAPE, SDLK_BACKSPACE : begin - // Escape -> save nothing - just leave this screen + Ini.Save; + + // Reload all screens, after Theme changed + // Todo : JB - Check if theme was actually changed + UGraphic.UnLoadScreens(); + UGraphic.LoadScreens(); AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenOptions); @@ -135,7 +141,16 @@ begin if (SelInteraction = 0) then begin Skin.OnThemeChange; - UpdateSelectSlideOptions (Theme.OptionsThemes.SelectSkin, SkinSelect, ISkin, Ini.SkinNo); + UpdateSelectSlideOptions(Theme.OptionsThemes.SelectSkin, SkinSelect, ISkin, Ini.SkinNo); + + // set skin to themes default skin + Ini.SkinNo := Theme.Themes[Ini.Theme].DefaultSkin; + end; + + { set skins default color } + if (SelInteraction = 0) or (SelInteraction = 1) then + begin + Ini.Color := Skin.GetDefaultColor(Ini.SkinNo); end; ReloadTheme(); @@ -150,6 +165,15 @@ begin begin Skin.OnThemeChange; UpdateSelectSlideOptions (Theme.OptionsThemes.SelectSkin, SkinSelect, ISkin, Ini.SkinNo); + + // set skin to themes default skin + Ini.SkinNo := Theme.Themes[Ini.Theme].DefaultSkin; + end; + + { set skins default color } + if (SelInteraction = 0) or (SelInteraction = 1) then + begin + Ini.Color := Skin.GetDefaultColor(Ini.SkinNo); end; ReloadTheme(); @@ -175,10 +199,10 @@ begin AddButton(Theme.OptionsThemes.ButtonExit); if (Length(Button[0].Text)=0) then - AddButtonText(14, 20, Theme.Options.Description[7]); + AddButtonText(20, 5, Theme.Options.Description[7]); end; -procedure TScreenOptionsThemes.onShow; +procedure TScreenOptionsThemes.OnShow; begin inherited; @@ -187,7 +211,7 @@ end; procedure TScreenOptionsThemes.ReloadTheme; begin - Theme.LoadTheme(ThemePath + ITheme[Ini.Theme] + '.ini', Ini.Color); + Theme.LoadTheme(Ini.Theme, Ini.Color); ScreenOptionsThemes := TScreenOptionsThemes.create(); ScreenOptionsThemes.onshow; diff --git a/cmake/src/screens/UScreenPartyNewRound.pas b/cmake/src/screens/UScreenPartyNewRound.pas index 03a72fa9..8024108c 100644 --- a/cmake/src/screens/UScreenPartyNewRound.pas +++ b/cmake/src/screens/UScreenPartyNewRound.pas @@ -34,33 +34,21 @@ interface {$I switches.inc} uses - UMenu, SDL, + SysUtils, + UMenu, UDisplay, UMusic, UFiles, - SysUtils, UThemes; type TScreenPartyNewRound = class(TMenu) public //Texts: - TextRound1: cardinal; - TextRound2: cardinal; - TextRound3: cardinal; - TextRound4: cardinal; - TextRound5: cardinal; - TextRound6: cardinal; - TextRound7: cardinal; - - TextWinner1: cardinal; - TextWinner2: cardinal; - TextWinner3: cardinal; - TextWinner4: cardinal; - TextWinner5: cardinal; - TextWinner6: cardinal; - TextWinner7: cardinal; + TextRound: array [0..6] of cardinal; + + TextWinner: array [0..6] of cardinal; TextNextRound: cardinal; TextNextRoundNo: cardinal; @@ -69,13 +57,7 @@ type TextNextPlayer3: cardinal; //Statics - StaticRound1: cardinal; - StaticRound2: cardinal; - StaticRound3: cardinal; - StaticRound4: cardinal; - StaticRound5: cardinal; - StaticRound6: cardinal; - StaticRound7: cardinal; + StaticRound: array [0..6] of cardinal; //Scores TextScoreTeam1: cardinal; @@ -99,8 +81,8 @@ type constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; @@ -112,19 +94,19 @@ uses UIni, UTexture, UParty, - UDLLManager, ULanguage, USong, - ULog; + ULog, + UUnicodeUtils; -function TScreenPartyNewRound.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenPartyNewRound.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -143,16 +125,7 @@ begin SDLK_RETURN: begin AudioPlayback.PlaySound(SoundLib.Start); - if DLLMan.Selected.LoadSong then - begin - //Select PartyMode ScreenSong - ScreenSong.Mode := smPartyMode; - FadeTo(@ScreenSong); - end - else - begin - FadeTo(@ScreenSingModi); - end; + Party.CallBeforeSongSelect; end; end; end; @@ -162,21 +135,21 @@ constructor TScreenPartyNewRound.Create; begin inherited Create; - TextRound1 := AddText (Theme.PartyNewRound.TextRound1); - TextRound2 := AddText (Theme.PartyNewRound.TextRound2); - TextRound3 := AddText (Theme.PartyNewRound.TextRound3); - TextRound4 := AddText (Theme.PartyNewRound.TextRound4); - TextRound5 := AddText (Theme.PartyNewRound.TextRound5); - TextRound6 := AddText (Theme.PartyNewRound.TextRound6); - TextRound7 := AddText (Theme.PartyNewRound.TextRound7); - - TextWinner1 := AddText (Theme.PartyNewRound.TextWinner1); - TextWinner2 := AddText (Theme.PartyNewRound.TextWinner2); - TextWinner3 := AddText (Theme.PartyNewRound.TextWinner3); - TextWinner4 := AddText (Theme.PartyNewRound.TextWinner4); - TextWinner5 := AddText (Theme.PartyNewRound.TextWinner5); - TextWinner6 := AddText (Theme.PartyNewRound.TextWinner6); - TextWinner7 := AddText (Theme.PartyNewRound.TextWinner7); + TextRound[0] := AddText (Theme.PartyNewRound.TextRound1); + TextRound[1] := AddText (Theme.PartyNewRound.TextRound2); + TextRound[2] := AddText (Theme.PartyNewRound.TextRound3); + TextRound[3] := AddText (Theme.PartyNewRound.TextRound4); + TextRound[4] := AddText (Theme.PartyNewRound.TextRound5); + TextRound[5] := AddText (Theme.PartyNewRound.TextRound6); + TextRound[6] := AddText (Theme.PartyNewRound.TextRound7); + + TextWinner[0] := AddText (Theme.PartyNewRound.TextWinner1); + TextWinner[1] := AddText (Theme.PartyNewRound.TextWinner2); + TextWinner[2] := AddText (Theme.PartyNewRound.TextWinner3); + TextWinner[3] := AddText (Theme.PartyNewRound.TextWinner4); + TextWinner[4] := AddText (Theme.PartyNewRound.TextWinner5); + TextWinner[5] := AddText (Theme.PartyNewRound.TextWinner6); + TextWinner[6] := AddText (Theme.PartyNewRound.TextWinner7); TextNextRound := AddText (Theme.PartyNewRound.TextNextRound); TextNextRoundNo := AddText (Theme.PartyNewRound.TextNextRoundNo); @@ -184,13 +157,13 @@ begin TextNextPlayer2 := AddText (Theme.PartyNewRound.TextNextPlayer2); TextNextPlayer3 := AddText (Theme.PartyNewRound.TextNextPlayer3); - StaticRound1 := AddStatic (Theme.PartyNewRound.StaticRound1); - StaticRound2 := AddStatic (Theme.PartyNewRound.StaticRound2); - StaticRound3 := AddStatic (Theme.PartyNewRound.StaticRound3); - StaticRound4 := AddStatic (Theme.PartyNewRound.StaticRound4); - StaticRound5 := AddStatic (Theme.PartyNewRound.StaticRound5); - StaticRound6 := AddStatic (Theme.PartyNewRound.StaticRound6); - StaticRound7 := AddStatic (Theme.PartyNewRound.StaticRound7); + StaticRound[0] := AddStatic (Theme.PartyNewRound.StaticRound1); + StaticRound[1] := AddStatic (Theme.PartyNewRound.StaticRound2); + StaticRound[2] := AddStatic (Theme.PartyNewRound.StaticRound3); + StaticRound[3] := AddStatic (Theme.PartyNewRound.StaticRound4); + StaticRound[4] := AddStatic (Theme.PartyNewRound.StaticRound5); + StaticRound[5] := AddStatic (Theme.PartyNewRound.StaticRound6); + StaticRound[6] := AddStatic (Theme.PartyNewRound.StaticRound7); //Scores TextScoreTeam1 := AddText (Theme.PartyNewRound.TextScoreTeam1); @@ -215,21 +188,21 @@ begin LoadFromTheme(Theme.PartyNewRound); end; -procedure TScreenPartyNewRound.onShow; +procedure TScreenPartyNewRound.OnShow; var I: integer; - function GetTeamPlayers(const Num: byte): string; + function GetTeamPlayers(const Num: integer): UTF8String; var - Players: array of string; - J: byte; + Players: array of UTF8String; + J: integer; begin - if (Num-1 >= PartySession.Teams.NumTeams) then + if (Num > High(Party.Teams)) or (Num < 0) then exit; //Create Players array - SetLength(Players, PartySession.Teams.TeamInfo[Num-1].NumPlayers); - for J := 0 to PartySession.Teams.TeamInfo[Num-1].NumPlayers-1 do - Players[J] := string(PartySession.Teams.TeamInfo[Num-1].PlayerInfo[J].Name); + SetLength(Players, Length(Party.Teams[Num].Players)); + For J := 0 to High(Party.Teams[Num].Players) do + Players[J] := UTF8String(Party.Teams[Num].Players[J].Name); //Implode and Return Result := Language.Implode(Players); @@ -237,215 +210,114 @@ var begin inherited; - PartySession.StartRound; - //Set Visibility of Round Infos - I := Length(PartySession.Rounds); - if (I >= 1) then - begin - Static[StaticRound1].Visible := true; - Text[TextRound1].Visible := true; - Text[TextWinner1].Visible := true; - - //Texts: - Text[TextRound1].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[0].Plugin].Name); - Text[TextWinner1].Text := PartySession.GetWinnerString(0); - end - else - begin - Static[StaticRound1].Visible := false; - Text[TextRound1].Visible := false; - Text[TextWinner1].Visible := false; - end; - - if (I >= 2) then - begin - Static[StaticRound2].Visible := true; - Text[TextRound2].Visible := true; - Text[TextWinner2].Visible := true; - - //Texts: - Text[TextRound2].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[1].Plugin].Name); - Text[TextWinner2].Text := PartySession.GetWinnerString(1); - end - else - begin - Static[StaticRound2].Visible := false; - Text[TextRound2].Visible := false; - Text[TextWinner2].Visible := false; - end; - - if (I >= 3) then - begin - Static[StaticRound3].Visible := true; - Text[TextRound3].Visible := true; - Text[TextWinner3].Visible := true; - - //Texts: - Text[TextRound3].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[2].Plugin].Name); - Text[TextWinner3].Text := PartySession.GetWinnerString(2); - end - else - begin - Static[StaticRound3].Visible := false; - Text[TextRound3].Visible := false; - Text[TextWinner3].Visible := false; - end; - - if (I >= 4) then + for I := 0 to 6 do begin - Static[StaticRound4].Visible := true; - Text[TextRound4].Visible := true; - Text[TextWinner4].Visible := true; - - //Texts: - Text[TextRound4].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[3].Plugin].Name); - Text[TextWinner4].Text := PartySession.GetWinnerString(3); - end - else - begin - Static[StaticRound4].Visible := false; - Text[TextRound4].Visible := false; - Text[TextWinner4].Visible := false; - end; - - if (I >= 5) then - begin - Static[StaticRound5].Visible := true; - Text[TextRound5].Visible := true; - Text[TextWinner5].Visible := true; - - //Texts: - Text[TextRound5].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[4].Plugin].Name); - Text[TextWinner5].Text := PartySession.GetWinnerString(4); - end - else - begin - Static[StaticRound5].Visible := false; - Text[TextRound5].Visible := false; - Text[TextWinner5].Visible := false; - end; - - if (I >= 6) then - begin - Static[StaticRound6].Visible := true; - Text[TextRound6].Visible := true; - Text[TextWinner6].Visible := true; - - //Texts: - Text[TextRound6].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[5].Plugin].Name); - Text[TextWinner6].Text := PartySession.GetWinnerString(5); - end - else - begin - Static[StaticRound6].Visible := false; - Text[TextRound6].Visible := false; - Text[TextWinner6].Visible := false; + if (I <= High(Party.Rounds)) then + begin + Statics[StaticRound[I]].Visible := True; + Text[TextRound[I]].Visible := True; + Text[TextWinner[I]].Visible := True; + + // update texts: + Text[TextRound[I]].Text := Language.Translate('MODE_' + uppercase(Party.Modes[Party.Rounds[I].Mode].Name) + '_NAME'); + Text[TextWinner[I]].Text := Party.GetWinnerString(I); + end + else + begin + Statics[StaticRound[I]].Visible := False; + Text[TextRound[I]].Visible := False; + Text[TextWinner[I]].Visible := False; + end; end; - if (I >= 7) then - begin - Static[StaticRound7].Visible := true; - Text[TextRound7].Visible := true; - Text[TextWinner7].Visible := true; - - //Texts: - Text[TextRound7].Text := Language.Translate(DllMan.Plugins[PartySession.Rounds[6].Plugin].Name); - Text[TextWinner7].Text := PartySession.GetWinnerString(6); - end - else - begin - Static[StaticRound7].Visible := false; - Text[TextRound7].Visible := false; - Text[TextWinner7].Visible := false; - end; //Display Scores - if (PartySession.Teams.NumTeams >= 1) then + if (Length(Party.Teams) >= 1) then begin - Text[TextScoreTeam1].Text := InttoStr(PartySession.Teams.TeamInfo[0].Score); - Text[TextNameTeam1].Text := string(PartySession.Teams.TeamInfo[0].Name); - Text[TextTeam1Players].Text := GetTeamPlayers(1); + Text[TextScoreTeam1].Text := InttoStr(Party.Teams[0].Score); + Text[TextNameTeam1].Text := UTF8String(Party.Teams[0].Name); + Text[TextTeam1Players].Text := GetTeamPlayers(0); Text[TextScoreTeam1].Visible := true; Text[TextNameTeam1].Visible := true; Text[TextTeam1Players].Visible := true; - Static[StaticTeam1].Visible := true; - Static[StaticNextPlayer1].Visible := true; + Statics[StaticTeam1].Visible := true; + Statics[StaticNextPlayer1].Visible := true; end else begin Text[TextScoreTeam1].Visible := false; Text[TextNameTeam1].Visible := false; Text[TextTeam1Players].Visible := false; - Static[StaticTeam1].Visible := false; - Static[StaticNextPlayer1].Visible := false; + Statics[StaticTeam1].Visible := false; + Statics[StaticNextPlayer1].Visible := false; end; - if (PartySession.Teams.NumTeams >= 2) then + if (Length(Party.Teams) >= 2) then begin - Text[TextScoreTeam2].Text := InttoStr(PartySession.Teams.TeamInfo[1].Score); - Text[TextNameTeam2].Text := string(PartySession.Teams.TeamInfo[1].Name); - Text[TextTeam2Players].Text := GetTeamPlayers(2); + Text[TextScoreTeam2].Text := InttoStr(Party.Teams[1].Score); + Text[TextNameTeam2].Text := UTF8String(Party.Teams[1].Name); + Text[TextTeam2Players].Text := GetTeamPlayers(1); Text[TextScoreTeam2].Visible := true; Text[TextNameTeam2].Visible := true; Text[TextTeam2Players].Visible := true; - Static[StaticTeam2].Visible := true; - Static[StaticNextPlayer2].Visible := true; + Statics[StaticTeam2].Visible := true; + Statics[StaticNextPlayer2].Visible := true; end else begin Text[TextScoreTeam2].Visible := false; Text[TextNameTeam2].Visible := false; Text[TextTeam2Players].Visible := false; - Static[StaticTeam2].Visible := false; - Static[StaticNextPlayer2].Visible := false; + Statics[StaticTeam2].Visible := false; + Statics[StaticNextPlayer2].Visible := false; end; - if (PartySession.Teams.NumTeams >= 3) then + if (Length(Party.Teams) >= 3) then begin - Text[TextScoreTeam3].Text := InttoStr(PartySession.Teams.TeamInfo[2].Score); - Text[TextNameTeam3].Text := string(PartySession.Teams.TeamInfo[2].Name); - Text[TextTeam3Players].Text := GetTeamPlayers(3); + Text[TextScoreTeam3].Text := InttoStr(Party.Teams[2].Score); + Text[TextNameTeam3].Text := UTF8String(Party.Teams[2].Name); + Text[TextTeam3Players].Text := GetTeamPlayers(2); Text[TextScoreTeam3].Visible := true; Text[TextNameTeam3].Visible := true; Text[TextTeam3Players].Visible := true; - Static[StaticTeam3].Visible := true; - Static[StaticNextPlayer3].Visible := true; + Statics[StaticTeam3].Visible := true; + Statics[StaticNextPlayer3].Visible := true; end else begin Text[TextScoreTeam3].Visible := false; Text[TextNameTeam3].Visible := false; Text[TextTeam3Players].Visible := false; - Static[StaticTeam3].Visible := false; - Static[StaticNextPlayer3].Visible := false; - end; + Statics[StaticTeam3].Visible := false; + Statics[StaticNextPlayer3].Visible := false; + end; //nextRound Texts - Text[TextNextRound].Text := Language.Translate(DllMan.Selected.PluginDesc); - Text[TextNextRoundNo].Text := InttoStr(PartySession.CurRound + 1); - if (PartySession.Teams.NumTeams >= 1) then + Text[TextNextRound].Text := Language.Translate('MODE_' + uppercase(Party.Modes[Party.Rounds[Party.CurrentRound].Mode].Name) + '_DESC'); + Text[TextNextRoundNo].Text := InttoStr(Party.CurrentRound + 1); + if (Length(Party.Teams) >= 1) then begin - Text[TextNextPlayer1].Text := PartySession.Teams.Teaminfo[0].Playerinfo[PartySession.Teams.Teaminfo[0].CurPlayer].Name; + Text[TextNextPlayer1].Text := Party.Teams[0].Players[Party.Teams[0].NextPlayer].Name; Text[TextNextPlayer1].Visible := true; end else Text[TextNextPlayer1].Visible := false; - - if (PartySession.Teams.NumTeams >= 2) then + + if (Length(Party.Teams) >= 2) then begin - Text[TextNextPlayer2].Text := PartySession.Teams.Teaminfo[1].Playerinfo[PartySession.Teams.Teaminfo[1].CurPlayer].Name; + Text[TextNextPlayer2].Text := Party.Teams[1].Players[Party.Teams[1].NextPlayer].Name; Text[TextNextPlayer2].Visible := true; end else Text[TextNextPlayer2].Visible := false; - if (PartySession.Teams.NumTeams >= 3) then + if (Length(Party.Teams) >= 3) then begin - Text[TextNextPlayer3].Text := PartySession.Teams.Teaminfo[2].Playerinfo[PartySession.Teams.Teaminfo[2].CurPlayer].Name; + Text[TextNextPlayer3].Text := Party.Teams[2].Players[Party.Teams[2].NextPlayer].Name; Text[TextNextPlayer3].Visible := true; end else diff --git a/cmake/src/screens/UScreenPartyOptions.pas b/cmake/src/screens/UScreenPartyOptions.pas index 5f7f1d9e..f63b37fb 100644 --- a/cmake/src/screens/UScreenPartyOptions.pas +++ b/cmake/src/screens/UScreenPartyOptions.pas @@ -44,38 +44,26 @@ uses type TScreenPartyOptions = class(TMenu) - public + private SelectLevel: cardinal; SelectPlayList: cardinal; SelectPlayList2: cardinal; SelectRounds: cardinal; - SelectTeams: cardinal; - SelectPlayers1: cardinal; - SelectPlayers2: cardinal; - SelectPlayers3: cardinal; + + IPlaylist: array[0..2] of UTF8String; + IPlaylist2: array of UTF8String; PlayList: integer; PlayList2: integer; - Rounds: integer; - NumTeams: integer; - NumPlayer1, NumPlayer2, NumPlayer3: integer; - + + procedure SetPlaylist2; + public constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; - procedure SetPlaylist2; end; -var - IPlaylist: array[0..2] of string; - IPlaylist2: array of string; - - const - ITeams: array[0..1] of string = ('2', '3'); - IPlayers: array[0..3] of string = ('1', '2', '3', '4'); - IRounds: array[0..5] of string = ('2', '3', '4', '5', '6', '7'); - implementation uses @@ -86,21 +74,20 @@ uses ULanguage, UParty, USong, - UDLLManager, UPlaylist, - USongs; + USongs, + UUnicodeUtils; -function TScreenPartyOptions.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenPartyOptions.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var I, J: integer; - OnlyMultiPlayer: boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -121,27 +108,11 @@ begin //Don'T start when Playlist is Selected and there are no Playlists if (Playlist = 2) and (Length(PlaylistMan.Playlists) = 0) then Exit; - // Don't start when SinglePlayer Teams but only Multiplayer Plugins available - OnlyMultiPlayer := true; - for I := 0 to High(DLLMan.Plugins) do - begin - OnlyMultiPlayer := (OnlyMultiPlayer and DLLMan.Plugins[I].TeamModeOnly); - end; - if (OnlyMultiPlayer) and ((NumPlayer1 = 0) or (NumPlayer2 = 0) or ((NumPlayer3 = 0) and (NumTeams = 1))) then - begin - ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_PLUGINS')); - Exit; - end; + //Save Difficulty Ini.Difficulty := SelectsS[SelectLevel].SelectedOption; Ini.SaveLevel; - //Save Num Teams: - PartySession.Teams.NumTeams := NumTeams + 2; - PartySession.Teams.Teaminfo[0].NumPlayers := NumPlayer1+1; - PartySession.Teams.Teaminfo[1].NumPlayers := NumPlayer2+1; - PartySession.Teams.Teaminfo[2].NumPlayers := NumPlayer3+1; - //Save Playlist PlaylistMan.Mode := TSingMode( Playlist ); PlaylistMan.CurPlayList := High(cardinal); @@ -168,9 +139,6 @@ begin else PlaylistMan.CurPlayList := Playlist2; - //Start Party - PartySession.StartNewParty(Rounds + 2); - AudioPlayback.PlaySound(SoundLib.Start); //Go to Player Screen FadeTo(@ScreenPartyPlayer); @@ -190,10 +158,6 @@ begin if (Interaction = 1) then begin SetPlaylist2; - end //Change Team3 Players visibility - else if (Interaction = 4) then - begin - SelectsS[7].Visible := (NumTeams = 1); end; end; SDLK_LEFT: @@ -205,10 +169,6 @@ begin if (Interaction = 1) then begin SetPlaylist2; - end //Change Team3 Players visibility - else if (Interaction = 4) then - begin - SelectsS[7].Visible := (NumTeams = 1); end; end; end; @@ -228,30 +188,25 @@ begin IPlaylist2[0] := '---'; //Clear all Selects - NumTeams := 0; - NumPlayer1 := 0; - NumPlayer2 := 0; - NumPlayer3 := 0; - Rounds := 5; PlayList := 0; PlayList2 := 0; //Load Screen From Theme LoadFromTheme(Theme.PartyOptions); - SelectLevel := AddSelectSlide (Theme.PartyOptions.SelectLevel, Ini.Difficulty, Theme.ILevel); - SelectPlayList := AddSelectSlide (Theme.PartyOptions.SelectPlayList, PlayList, IPlaylist); - SelectPlayList2 := AddSelectSlide (Theme.PartyOptions.SelectPlayList2, PlayList2, IPlaylist2); - SelectRounds := AddSelectSlide (Theme.PartyOptions.SelectRounds, Rounds, IRounds); - SelectTeams := AddSelectSlide (Theme.PartyOptions.SelectTeams, NumTeams, ITeams); - SelectPlayers1 := AddSelectSlide (Theme.PartyOptions.SelectPlayers1, NumPlayer1, IPlayers); - SelectPlayers2 := AddSelectSlide (Theme.PartyOptions.SelectPlayers2, NumPlayer2, IPlayers); - SelectPlayers3 := AddSelectSlide (Theme.PartyOptions.SelectPlayers3, NumPlayer3, IPlayers); + Theme.PartyOptions.SelectLevel.oneItemOnly := true; + Theme.PartyOptions.SelectLevel.showArrows := true; + SelectLevel := AddSelectSlide(Theme.PartyOptions.SelectLevel, Ini.Difficulty, Theme.ILevel); - Interaction := 0; + Theme.PartyOptions.SelectPlayList.oneItemOnly := true; + Theme.PartyOptions.SelectPlayList.showArrows := true; + SelectPlayList := AddSelectSlide(Theme.PartyOptions.SelectPlayList, PlayList, IPlaylist); + + Theme.PartyOptions.SelectPlayList2.oneItemOnly := true; + Theme.PartyOptions.SelectPlayList2.showArrows := true; + SelectPlayList2 := AddSelectSlide(Theme.PartyOptions.SelectPlayList2, PlayList2, IPlaylist2); - //Hide Team3 Players - SelectsS[7].Visible := false; + Interaction := 0; end; procedure TScreenPartyOptions.SetPlaylist2; @@ -301,11 +256,23 @@ begin UpdateSelectSlideOptions(Theme.PartyOptions.SelectPlayList2, 2, IPlaylist2, Playlist2); end; -procedure TScreenPartyOptions.onShow; +procedure TScreenPartyOptions.OnShow; begin inherited; - Randomize; + Party.Clear; + + // check if there are loaded modes + if Party.ModesAvailable then + begin + // modes are loaded + Randomize; + end + else + begin // no modes found + ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_PLUGINS')); + Display.AbortScreenChange; + end; end; procedure TScreenPartyOptions.SetAnimationProgress(Progress: real); diff --git a/cmake/src/screens/UScreenPartyPlayer.pas b/cmake/src/screens/UScreenPartyPlayer.pas index c2070fce..a7f4d627 100644 --- a/cmake/src/screens/UScreenPartyPlayer.pas +++ b/cmake/src/screens/UScreenPartyPlayer.pas @@ -44,6 +44,14 @@ uses type TScreenPartyPlayer = class(TMenu) + private + CountTeams: integer; + CountPlayer: array [0..2] of integer; + + SelectTeams: cardinal; + SelectPlayers: array [0..2] of cardinal; + procedure UpdateInterface; + procedure UpdateParty; public Team1Name: cardinal; Player1Name: cardinal; @@ -64,11 +72,15 @@ type Player12Name: cardinal; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; +const + ITeams: array[0..1] of UTF8String = ('2', '3'); + IPlayers: array[0..3] of UTF8String = ('1', '2', '3', '4'); + implementation uses @@ -76,24 +88,96 @@ uses UMain, UIni, UTexture, - UParty; + UParty, + UUnicodeUtils, + UScreenPartyOptions, + ULanguage; + +procedure TScreenPartyPlayer.UpdateInterface; + var + I: integer; + Btn: integer; +begin + SelectsS[SelectPlayers[2]].Visible := (CountTeams = 1); + + Btn := 0; + for I := 0 to 2 do + begin + if (CountTeams + 1 >= I) then + begin + Button[Btn + 0].Visible := true; + Button[Btn + 1].Visible := (CountPlayer[I] + 1 >= 1); + Button[Btn + 2].Visible := (CountPlayer[I] + 1 >= 2); + Button[Btn + 3].Visible := (CountPlayer[I] + 1 >= 3); + Button[Btn + 4].Visible := (CountPlayer[I] + 1 >= 4); + end + else + begin + Button[Btn + 0].Visible := false; + Button[Btn + 1].Visible := false; + Button[Btn + 2].Visible := false; + Button[Btn + 3].Visible := false; + Button[Btn + 4].Visible := false; + end; + Inc(Btn, 5); + end; +end; + +procedure TScreenPartyPlayer.UpdateParty; + var + I, J: integer; +begin + {//Save PlayerNames + for I := 0 to PartySession.Teams.NumTeams-1 do + begin + PartySession.Teams.Teaminfo[I].Name := PChar(Button[I*5].Text[0].Text); + for J := 0 to PartySession.Teams.Teaminfo[I].NumPlayers-1 do + begin + PartySession.Teams.Teaminfo[I].Playerinfo[J].Name := PChar(Button[I*5 + J+1].Text[0].Text); + PartySession.Teams.Teaminfo[I].Playerinfo[J].TimesPlayed := 0; + end; + end; } + + // add teams to party + + for I := 0 to CountTeams + 1 do + begin + Party.AddTeam(Button[I * 5].Text[0].Text); -function TScreenPartyPlayer.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + for J := 0 to CountPlayer[I] do + Party.AddPlayer(I, Button[I * 5 + 1 + J].Text[0].Text); + end; + + if (Party.ModesAvailable) then + begin //mode for current playersetup available + FadeTo(@ScreenPartyRounds, SoundLib.Start); + end + else + begin + // no mode available for current player setup + ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_MODES_FOR_CURRENT_SETUP')); + Party.Clear; + end; +end; + +function TScreenPartyPlayer.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var SDL_ModState: word; - I, J: integer; - procedure IntNext; begin repeat InteractNext; - until Button[Interaction].Visible; + until ((Interactions[Interaction].Typ = iSelectS) and + SelectsS[Interactions[Interaction].Num].Visible) or + (Button[Interactions[Interaction].Num].Visible); end; procedure IntPrev; begin repeat InteractPrev; - until Button[Interaction].Visible; + until ((Interactions[Interaction].Typ = iSelectS) and + SelectsS[Interactions[Interaction].Num].Visible) or + (Button[Interactions[Interaction].Num].Visible); end; begin Result := true; @@ -104,166 +188,178 @@ begin else SDL_ModState := 0; - begin // Key Down - // check normal keys + // Key Down + // check normal keys + if (Interactions[Interaction].Typ = iButton) then + begin case CharCode of - '0'..'9', 'a'..'z', 'A'..'Z', ' ', '-', '_', '!', ',', '<', '/', '*', '?', '''', '"': + Ord('0')..Ord('9'), + Ord('a')..Ord('z'), + Ord('A')..Ord('Z'), + Ord(' '), Ord('-'), Ord('_'), Ord('!'), Ord(','), Ord('<'), Ord('/'), + Ord('*'), Ord('?'), Ord(''''), Ord('"'): begin - Button[Interaction].Text[0].Text := Button[Interaction].Text[0].Text + CharCode; + Button[Interactions[Interaction].Num].Text[0].Text := + Button[Interactions[Interaction].Num].Text[0].Text + UCS4ToUTF8String(CharCode); Exit; end; end; + // check special keys case PressedKey of // Templates for Names Mod SDLK_F1: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[0] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[0] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[0]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[0]; end; SDLK_F2: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[1] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[1] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[1]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[1]; end; SDLK_F3: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[2] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[2] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[2]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[2]; end; SDLK_F4: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[3] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[3] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[3]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[3]; end; SDLK_F5: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[4] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[4] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[4]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[4]; end; SDLK_F6: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[5] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[5] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[5]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[5]; end; SDLK_F7: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[6] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[6] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[6]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[6]; end; SDLK_F8: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[7] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[7] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[7]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[7]; end; SDLK_F9: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[8] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[8] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[8]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[8]; end; SDLK_F10: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[9] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[9] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[9]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[9]; end; SDLK_F11: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[10] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[10] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[10]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[10]; end; SDLK_F12: if (SDL_ModState = KMOD_LALT) then begin - Ini.NameTemplate[11] := Button[Interaction].Text[0].Text; + Ini.NameTemplate[11] := Button[Interactions[Interaction].Num].Text[0].Text; end else begin - Button[Interaction].Text[0].Text := Ini.NameTemplate[11]; + Button[Interactions[Interaction].Num].Text[0].Text := Ini.NameTemplate[11]; end; SDLK_BACKSPACE: begin - Button[Interaction].Text[0].DeleteLastL; + Button[Interactions[Interaction].Num].Text[0].DeleteLastLetter; end; + end; + end; - SDLK_ESCAPE: + case PressedKey of + SDLK_ESCAPE: + begin + Ini.SaveNames; + AudioPlayback.PlaySound(SoundLib.Back); + FadeTo(@ScreenPartyOptions); + end; + + SDLK_RETURN: UpdateParty; + + // Up and Down could be done at the same time, + // but I don't want to declare variables inside + // functions like this one, called so many times + SDLK_DOWN: IntNext; + SDLK_UP: IntPrev; + SDLK_RIGHT: + begin + if (Interaction in [0,2,8,14]) then begin - Ini.SaveNames; - AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(@ScreenPartyOptions); - end; + AudioPlayback.PlaySound(SoundLib.Option); + InteractInc; - SDLK_RETURN: + UpdateInterface; + end; + end; + SDLK_LEFT: + begin + if (Interaction in [0,2,8,14]) then begin + AudioPlayback.PlaySound(SoundLib.Option); + InteractDec; - //Save PlayerNames - for I := 0 to PartySession.Teams.NumTeams-1 do - begin - PartySession.Teams.Teaminfo[I].Name := PChar(Button[I*5].Text[0].Text); - for J := 0 to PartySession.Teams.Teaminfo[I].NumPlayers-1 do - begin - PartySession.Teams.Teaminfo[I].Playerinfo[J].Name := PChar(Button[I*5 + J+1].Text[0].Text); - PartySession.Teams.Teaminfo[I].Playerinfo[J].TimesPlayed := 0; - end; - end; - - AudioPlayback.PlaySound(SoundLib.Start); - FadeTo(@ScreenPartyNewRound); + UpdateInterface; end; - - // Up and Down could be done at the same time, - // but I don't want to declare variables inside - // functions like this one, called so many times - SDLK_DOWN: IntNext; - SDLK_UP: IntPrev; - SDLK_RIGHT: IntNext; - SDLK_LEFT: IntPrev; - end; + end; end; end; @@ -273,28 +369,50 @@ begin LoadFromTheme(Theme.PartyPlayer); + Theme.PartyPlayer.SelectTeams.oneItemOnly := true; + Theme.PartyPlayer.SelectTeams.showArrows := true; + SelectTeams := AddSelectSlide(Theme.PartyPlayer.SelectTeams, CountTeams, ITeams); + Team1Name := AddButton(Theme.PartyPlayer.Team1Name); + Theme.PartyPlayer.SelectPlayers1.oneItemOnly := true; + Theme.PartyPlayer.SelectPlayers1.showArrows := true; + SelectPlayers[0] := AddSelectSlide(Theme.PartyPlayer.SelectPlayers1, CountPlayer[0], IPlayers); + AddButton(Theme.PartyPlayer.Player1Name); AddButton(Theme.PartyPlayer.Player2Name); AddButton(Theme.PartyPlayer.Player3Name); AddButton(Theme.PartyPlayer.Player4Name); Team2Name := AddButton(Theme.PartyPlayer.Team2Name); + Theme.PartyPlayer.SelectPlayers2.oneItemOnly := true; + Theme.PartyPlayer.SelectPlayers2.showArrows := true; + SelectPlayers[1] := AddSelectSlide(Theme.PartyPlayer.SelectPlayers2, CountPlayer[1], IPlayers); + AddButton(Theme.PartyPlayer.Player5Name); AddButton(Theme.PartyPlayer.Player6Name); AddButton(Theme.PartyPlayer.Player7Name); AddButton(Theme.PartyPlayer.Player8Name); Team3Name := AddButton(Theme.PartyPlayer.Team3Name); + Theme.PartyPlayer.SelectPlayers3.oneItemOnly := true; + Theme.PartyPlayer.SelectPlayers3.showArrows := true; + SelectPlayers[2] := AddSelectSlide(Theme.PartyPlayer.SelectPlayers3, CountPlayer[2], IPlayers); + AddButton(Theme.PartyPlayer.Player9Name); AddButton(Theme.PartyPlayer.Player10Name); AddButton(Theme.PartyPlayer.Player11Name); AddButton(Theme.PartyPlayer.Player12Name); Interaction := 0; + + //Clear Selects + CountTeams := 0; + CountPlayer[0] := 0; + CountPlayer[1] := 0; + CountPlayer[2] := 0; end; -procedure TScreenPartyPlayer.onShow; +procedure TScreenPartyPlayer.OnShow; var I: integer; begin @@ -314,66 +432,18 @@ begin Button[5].Text[0].Text := Ini.NameTeam[1]; Button[10].Text[0].Text := Ini.NameTeam[2]; // Templates for Names Mod end - - if (PartySession.Teams.NumTeams>=1) then - begin - Button[0].Visible := true; - Button[1].Visible := (PartySession.Teams.Teaminfo[0].NumPlayers >=1); - Button[2].Visible := (PartySession.Teams.Teaminfo[0].NumPlayers >=2); - Button[3].Visible := (PartySession.Teams.Teaminfo[0].NumPlayers >=3); - Button[4].Visible := (PartySession.Teams.Teaminfo[0].NumPlayers >=4); - end - else - begin - Button[0].Visible := false; - Button[1].Visible := false; - Button[2].Visible := false; - Button[3].Visible := false; - Button[4].Visible := false; - end; - if (PartySession.Teams.NumTeams>=2) then - begin - Button[5].Visible := true; - Button[6].Visible := (PartySession.Teams.Teaminfo[1].NumPlayers >=1); - Button[7].Visible := (PartySession.Teams.Teaminfo[1].NumPlayers >=2); - Button[8].Visible := (PartySession.Teams.Teaminfo[1].NumPlayers >=3); - Button[9].Visible := (PartySession.Teams.Teaminfo[1].NumPlayers >=4); - end - else - begin - Button[5].Visible := false; - Button[6].Visible := false; - Button[7].Visible := false; - Button[8].Visible := false; - Button[9].Visible := false; - end; - - if (PartySession.Teams.NumTeams>=3) then - begin - Button[10].Visible := true; - Button[11].Visible := (PartySession.Teams.Teaminfo[2].NumPlayers >=1); - Button[12].Visible := (PartySession.Teams.Teaminfo[2].NumPlayers >=2); - Button[13].Visible := (PartySession.Teams.Teaminfo[2].NumPlayers >=3); - Button[14].Visible := (PartySession.Teams.Teaminfo[2].NumPlayers >=4); - end - else - begin - Button[10].Visible := false; - Button[11].Visible := false; - Button[12].Visible := false; - Button[13].Visible := false; - Button[14].Visible := false; - end; + Party.Clear; + UpdateInterface; end; procedure TScreenPartyPlayer.SetAnimationProgress(Progress: real); var I: integer; begin - for I := 0 to high(Button) do - Button[I].Texture.ScaleW := Progress; + {for I := 0 to high(Button) do + Button[I].Texture.ScaleW := Progress; } end; end. diff --git a/cmake/src/screens/UScreenPartyRounds.pas b/cmake/src/screens/UScreenPartyRounds.pas new file mode 100644 index 00000000..070c9eb8 --- /dev/null +++ b/cmake/src/screens/UScreenPartyRounds.pas @@ -0,0 +1,233 @@ +{* UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL: https://ultrastardx.svn.sourceforge.net/svnroot/ultrastardx/branches/experimental/Lua/src/screens/UScreenPartyOptions.pas $ + * $Id: UScreenPartyOptions.pas 2036 2009-12-14 20:59:44Z whiteshark0 $ + *} + +unit UScreenPartyRounds; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses + UMenu, + SDL, + UDisplay, + UMusic, + UFiles, + SysUtils, + UThemes; + +type + TScreenPartyRounds = class(TMenu) + private + SelectRoundCount: cardinal; + SelectRound: array [0..6] of cardinal; + + RoundCount: integer; + Round: array [0..6] of integer; + + IModeNames: array of UTF8String; + IModeIDs: array of integer; + + procedure UpdateInterface; + procedure StartParty; + public + constructor Create; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; + procedure SetAnimationProgress(Progress: real); override; + end; + +const + IRoundCount: array[0..5] of UTF8String = ('2', '3', '4', '5', '6', '7'); + +implementation + +uses + UGraphic, + UMain, + UIni, + UTexture, + ULanguage, + UParty, + USong, + UPlaylist, + USongs, + UUnicodeUtils; + +procedure TScreenPartyRounds.UpdateInterface; + var + I: integer; + ActualRounds: integer; +begin + ActualRounds := RoundCount + 2; + + for I := 0 to High(SelectRound) do + SelectsS[SelectRound[I]].Visible := (I < ActualRounds); +end; + +procedure TScreenPartyRounds.StartParty; + var + GameRounds: ARounds; + I: integer; +begin + SetLength(GameRounds, RoundCount + 2); + + for I := 0 to High(GameRounds) do + GameRounds[I] := IModeIds[Round[I]]; + + // start party game + if (Party.StartGame(GameRounds)) then + begin + FadeTo(@ScreenPartyNewRound, SoundLib.Start); + end + else + begin + //error starting party game + ScreenPopupError.ShowPopup(Language.Translate('ERROR_CAN_NOT_START_PARTY')); + end; +end; + +function TScreenPartyRounds.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; +begin + Result := true; + if (PressedDown) then + begin // Key Down + // check normal keys + case UCS4UpperCase(CharCode) of + Ord('Q'): + begin + Result := false; + Exit; + end; + end; + + // check special keys + case PressedKey of + SDLK_ESCAPE, + SDLK_BACKSPACE : + begin + AudioPlayback.PlaySound(SoundLib.Back); + FadeTo(@ScreenPartyPlayer); + end; + + SDLK_RETURN: StartParty; + + // Up and Down could be done at the same time, + // but I don't want to declare variables inside + // functions like this one, called so many times + SDLK_DOWN: InteractNext; + SDLK_UP: InteractPrev; + SDLK_RIGHT: + begin + AudioPlayback.PlaySound(SoundLib.Option); + InteractInc; + + if Interaction = 0 then + UpdateInterface; + end; + SDLK_LEFT: + begin + AudioPlayback.PlaySound(SoundLib.Option); + InteractDec; + + if Interaction = 0 then + UpdateInterface; + end; + end; + end; +end; + +constructor TScreenPartyRounds.Create; + var + I: integer; +begin + inherited Create; + RoundCount := 5; + + //Load Screen From Theme + LoadFromTheme(Theme.PartyRounds); + + Theme.PartyRounds.SelectRoundCount.oneItemOnly := true; + Theme.PartyRounds.SelectRoundCount.showArrows := true; + SelectRoundCount := AddSelectSlide(Theme.PartyRounds.SelectRoundCount, RoundCount, IRoundCount); + + SetLength(IModeNames, 1); + IModeNames[0] := '---'; + for I := 0 to high(Theme.PartyRounds.SelectRound) do + begin + Round[I] := 0; + Theme.PartyRounds.SelectRound[I].oneItemOnly := true; + Theme.PartyRounds.SelectRound[I].showArrows := true; + SelectRound[I] := AddSelectSlide(Theme.PartyRounds.SelectRound[I], Round[I], IModeNames); + end; + + + Interaction := 0; +end; + +procedure TScreenPartyRounds.OnShow; + var + ModeList: AParty_ModeList; + I: integer; +begin + inherited; + + // check if there are loaded modes + if Party.ModesAvailable then + begin + UpdateInterface; + + ModeList := Party.GetAvailableModes; + SetLength(IModeNames, Length(ModeList)); + SetLength(IModeIds, Length(ModeList)); + for I := 0 to High(ModeList) do + begin + IModeNames[I] := ModeList[I].Name; + IModeIds[I] := ModeList[I].Index; + end; + + for I := 0 to High(SelectRound) do + UpdateSelectSlideOptions(Theme.PartyRounds.SelectRound[I] , SelectRound[I], IModeNames, Round[I]); + end + else + begin + // no mode available for current player setup + ScreenPopupError.ShowPopup(Language.Translate('ERROR_NO_MODES_FOR_CURRENT_SETUP')); + Party.Clear; + Display.AbortScreenChange; + end; +end; + +procedure TScreenPartyRounds.SetAnimationProgress(Progress: real); +begin + {for I := 0 to 6 do + SelectS[I].Texture.ScaleW := Progress;} +end; + +end. diff --git a/cmake/src/screens/UScreenPartyScore.pas b/cmake/src/screens/UScreenPartyScore.pas index 23cf666d..32ca5db2 100644 --- a/cmake/src/screens/UScreenPartyScore.pas +++ b/cmake/src/screens/UScreenPartyScore.pas @@ -34,11 +34,11 @@ interface {$I switches.inc} uses - UMenu, SDL, + SysUtils, + UMenu, UDisplay, UMusic, - SysUtils, UThemes; type @@ -69,8 +69,8 @@ type MaxScore: word; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; @@ -80,19 +80,19 @@ uses UGraphic, UMain, UParty, - UScreenSingModi, ULanguage, UTexture, - USkins; + USkins, + UUnicodeUtils; -function TScreenPartyScore.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenPartyScore.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -102,33 +102,28 @@ begin // check special keys case PressedKey of SDLK_ESCAPE, - SDLK_BACKSPACE : + SDLK_BACKSPACE, + SDLK_RETURN : begin AudioPlayback.PlaySound(SoundLib.Start); - if (PartySession.CurRound < High(PartySession.Rounds)) then - FadeTo(@ScreenPartyNewRound) + + Party.NextRound; //< go to next round + + if (not Party.GameFinished) then + begin + FadeTo(@ScreenPartyNewRound); + end else begin - PartySession.EndRound; FadeTo(@ScreenPartyWin); end; end; - - SDLK_RETURN: - begin - AudioPlayback.PlaySound(SoundLib.Start); - if (PartySession.CurRound < High(PartySession.Rounds)) then - FadeTo(@ScreenPartyNewRound) - else - FadeTo(@ScreenPartyWin); - end; end; end; end; constructor TScreenPartyScore.Create; var -// I: integer; // Auto Removed, Unused Variable Tex: TTexture; R, G, B: real; Color: integer; @@ -165,7 +160,9 @@ begin DecoColor[0].B := B; //Load Texture - Tex := Texture.LoadTexture(pchar(Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.FirstTexture)), Theme.PartyScore.DecoTextures.FirstTyp, Color); + Tex := Texture.LoadTexture( + Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.FirstTexture), + Theme.PartyScore.DecoTextures.FirstTyp, Color); DecoTex[0] := Tex.TexNum; //Get Second Color @@ -176,7 +173,9 @@ begin DecoColor[1].B := B; //Load Second Texture - Tex := Texture.LoadTexture(pchar(Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.SecondTexture)), Theme.PartyScore.DecoTextures.SecondTyp, Color); + Tex := Texture.LoadTexture( + Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.SecondTexture), + Theme.PartyScore.DecoTextures.SecondTyp, Color); DecoTex[1] := Tex.TexNum; //Get Third Color @@ -187,150 +186,146 @@ begin DecoColor[2].B := B; //Load Third Texture - Tex := Texture.LoadTexture(pchar(Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.ThirdTexture)), Theme.PartyScore.DecoTextures.ThirdTyp, Color); + Tex := Texture.LoadTexture( + Skin.GetTextureFileName(Theme.PartyScore.DecoTextures.ThirdTexture), + Theme.PartyScore.DecoTextures.ThirdTyp, Color); DecoTex[2] := Tex.TexNum; end; LoadFromTheme(Theme.PartyScore); end; -procedure TScreenPartyScore.onShow; +procedure TScreenPartyScore.OnShow; var - I, J: integer; - Placings: array [0..5] of byte; + Ranking: AParty_TeamRanking; begin inherited; - //Get Maxscore - - MaxScore := 0; - for I := 0 to ScreenSingModi.PlayerInfo.NumPlayers - 1 do - begin - if (ScreenSingModi.PlayerInfo.Playerinfo[I].Score > MaxScore) then - MaxScore := ScreenSingModi.PlayerInfo.Playerinfo[I].Score; - end; + // indicate that round is finished + Party.RoundPlayed; - //Get Placings - for I := 0 to ScreenSingModi.PlayerInfo.NumPlayers - 1 do - begin - Placings[I] := 0; - for J := 0 to ScreenSingModi.PlayerInfo.NumPlayers - 1 do - if (ScreenSingModi.PlayerInfo.Playerinfo[J].Score > ScreenSingModi.PlayerInfo.Playerinfo[I].Score) then - Inc(Placings[I]); - end; + // get rankings for current round + Ranking := Party.Rounds[Party.CurrentRound].Ranking; - //Set Static Length - Static[StaticTeam1].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[0].Percentage / 100; - Static[StaticTeam2].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[1].Percentage / 100; - Static[StaticTeam3].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[2].Percentage / 100; - //fix: prevents static from drawn out of bounds. - if Static[StaticTeam1].Texture.ScaleW > 99 then Static[StaticTeam1].Texture.ScaleW := 99; - if Static[StaticTeam2].Texture.ScaleW > 99 then Static[StaticTeam2].Texture.ScaleW := 99; - if Static[StaticTeam3].Texture.ScaleW > 99 then Static[StaticTeam3].Texture.ScaleW := 99; + {//Set Statics Length + Statics[StaticTeam1].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[0].Percentage / 100; + Statics[StaticTeam2].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[1].Percentage / 100; + Statics[StaticTeam3].Texture.ScaleW := ScreenSingModi.PlayerInfo.Playerinfo[2].Percentage / 100; - //End Last Round - PartySession.EndRound; + //fix: prevents statics from drawn out of bounds. + if Statics[StaticTeam1].Texture.ScaleW > 99 then Statics[StaticTeam1].Texture.ScaleW := 99; + if Statics[StaticTeam2].Texture.ScaleW > 99 then Statics[StaticTeam2].Texture.ScaleW := 99; + if Statics[StaticTeam3].Texture.ScaleW > 99 then Statics[StaticTeam3].Texture.ScaleW := 99; } //Set Winnertext - Text[TextWinner].Text := Format(Language.Translate('PARTY_SCORE_WINS'), [PartySession.GetWinnerString(PartySession.CurRound)]); + Text[TextWinner].Text := Format(Language.Translate('PARTY_SCORE_WINS'), [Party.GetWinnerString(Party.CurrentRound)]); - if (ScreenSingModi.PlayerInfo.NumPlayers >= 1) then + if (Length(Party.Teams) >= 1) then begin - Text[TextScoreTeam1].Text := InttoStr(ScreenSingModi.PlayerInfo.Playerinfo[0].Score); - Text[TextNameTeam1].Text := string(ScreenSingModi.TeamInfo.Teaminfo[0].Name); + Text[TextScoreTeam1].Text := InttoStr(Party.Teams[0].Score); + Text[TextNameTeam1].Text := Utf8String(Party.Teams[0].Name); //Set Deco Texture if Theme.PartyScore.DecoTextures.ChangeTextures then begin - Static[StaticTeam1Deco].Texture.TexNum := DecoTex[Placings[0]]; - Static[StaticTeam1Deco].Texture.ColR := DecoColor[Placings[0]].R; - Static[StaticTeam1Deco].Texture.ColG := DecoColor[Placings[0]].G; - Static[StaticTeam1Deco].Texture.ColB := DecoColor[Placings[0]].B; + if (Length(Ranking) >= 1) and (Ranking[0].Rank >= 1) and (Ranking[0].Rank <= Length(DecoTex)) then + begin + Statics[StaticTeam1Deco].Texture.TexNum := DecoTex[Ranking[0].Rank-1]; + Statics[StaticTeam1Deco].Texture.ColR := DecoColor[Ranking[0].Rank-1].R; + Statics[StaticTeam1Deco].Texture.ColG := DecoColor[Ranking[0].Rank-1].G; + Statics[StaticTeam1Deco].Texture.ColB := DecoColor[Ranking[0].Rank-1].B; + end; end; Text[TextScoreTeam1].Visible := true; Text[TextNameTeam1].Visible := true; - Static[StaticTeam1].Visible := true; - Static[StaticTeam1BG].Visible := true; - Static[StaticTeam1Deco].Visible := true; + Statics[StaticTeam1].Visible := true; + Statics[StaticTeam1BG].Visible := true; + Statics[StaticTeam1Deco].Visible := true; end else begin Text[TextScoreTeam1].Visible := false; Text[TextNameTeam1].Visible := false; - Static[StaticTeam1].Visible := false; - Static[StaticTeam1BG].Visible := false; - Static[StaticTeam1Deco].Visible := false; + Statics[StaticTeam1].Visible := false; + Statics[StaticTeam1BG].Visible := false; + Statics[StaticTeam1Deco].Visible := false; end; - if (ScreenSingModi.PlayerInfo.NumPlayers >= 2) then + if (Length(Party.Teams) >= 2) then begin - Text[TextScoreTeam2].Text := InttoStr(ScreenSingModi.PlayerInfo.Playerinfo[1].Score); - Text[TextNameTeam2].Text := string(ScreenSingModi.TeamInfo.Teaminfo[1].Name); + Text[TextScoreTeam2].Text := InttoStr(Party.Teams[1].Score); + Text[TextNameTeam2].Text := UTF8String(Party.Teams[1].Name); //Set Deco Texture if Theme.PartyScore.DecoTextures.ChangeTextures then begin - Static[StaticTeam2Deco].Texture.TexNum := DecoTex[Placings[1]]; - Static[StaticTeam2Deco].Texture.ColR := DecoColor[Placings[1]].R; - Static[StaticTeam2Deco].Texture.ColG := DecoColor[Placings[1]].G; - Static[StaticTeam2Deco].Texture.ColB := DecoColor[Placings[1]].B; + if (Length(Ranking) >= 2) and (Ranking[1].Rank >= 1) and (Ranking[1].Rank <= Length(DecoTex)) then + begin + Statics[StaticTeam2Deco].Texture.TexNum := DecoTex[Ranking[1].Rank-1]; + Statics[StaticTeam2Deco].Texture.ColR := DecoColor[Ranking[1].Rank-1].R; + Statics[StaticTeam2Deco].Texture.ColG := DecoColor[Ranking[1].Rank-1].G; + Statics[StaticTeam2Deco].Texture.ColB := DecoColor[Ranking[1].Rank-1].B; + end; end; Text[TextScoreTeam2].Visible := true; Text[TextNameTeam2].Visible := true; - Static[StaticTeam2].Visible := true; - Static[StaticTeam2BG].Visible := true; - Static[StaticTeam2Deco].Visible := true; + Statics[StaticTeam2].Visible := true; + Statics[StaticTeam2BG].Visible := true; + Statics[StaticTeam2Deco].Visible := true; end else begin Text[TextScoreTeam2].Visible := false; Text[TextNameTeam2].Visible := false; - Static[StaticTeam2].Visible := false; - Static[StaticTeam2BG].Visible := false; - Static[StaticTeam2Deco].Visible := false; + Statics[StaticTeam2].Visible := false; + Statics[StaticTeam2BG].Visible := false; + Statics[StaticTeam2Deco].Visible := false; end; - if (ScreenSingModi.PlayerInfo.NumPlayers >= 3) then + if (Length(Party.Teams) >= 3) then begin - Text[TextScoreTeam3].Text := InttoStr(ScreenSingModi.PlayerInfo.Playerinfo[2].Score); - Text[TextNameTeam3].Text := string(ScreenSingModi.TeamInfo.Teaminfo[2].Name); + Text[TextScoreTeam3].Text := InttoStr(Party.Teams[2].Score); + Text[TextNameTeam3].Text := UTF8String(Party.Teams[2].Name); //Set Deco Texture if Theme.PartyScore.DecoTextures.ChangeTextures then begin - Static[StaticTeam3Deco].Texture.TexNum := DecoTex[Placings[2]]; - Static[StaticTeam3Deco].Texture.ColR := DecoColor[Placings[2]].R; - Static[StaticTeam3Deco].Texture.ColG := DecoColor[Placings[2]].G; - Static[StaticTeam3Deco].Texture.ColB := DecoColor[Placings[2]].B; + if (Length(Ranking) >= 3) and (Ranking[2].Rank >= 1) and (Ranking[2].Rank <= Length(DecoTex)) then + begin + Statics[StaticTeam3Deco].Texture.TexNum := DecoTex[Ranking[2].Rank-1]; + Statics[StaticTeam3Deco].Texture.ColR := DecoColor[Ranking[2].Rank-1].R; + Statics[StaticTeam3Deco].Texture.ColG := DecoColor[Ranking[2].Rank-1].G; + Statics[StaticTeam3Deco].Texture.ColB := DecoColor[Ranking[2].Rank-1].B; + end; end; Text[TextScoreTeam3].Visible := true; Text[TextNameTeam3].Visible := true; - Static[StaticTeam3].Visible := true; - Static[StaticTeam3BG].Visible := true; - Static[StaticTeam3Deco].Visible := true; + Statics[StaticTeam3].Visible := true; + Statics[StaticTeam3BG].Visible := true; + Statics[StaticTeam3Deco].Visible := true; end else begin Text[TextScoreTeam3].Visible := false; Text[TextNameTeam3].Visible := false; - Static[StaticTeam3].Visible := false; - Static[StaticTeam3BG].Visible := false; - Static[StaticTeam3Deco].Visible := false; + Statics[StaticTeam3].Visible := false; + Statics[StaticTeam3BG].Visible := false; + Statics[StaticTeam3Deco].Visible := false; end; end; procedure TScreenPartyScore.SetAnimationProgress(Progress: real); begin - if (ScreenSingModi.PlayerInfo.NumPlayers >= 1) then - Static[StaticTeam1].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[0].Percentage / 100; + {if (ScreenSingModi.PlayerInfo.NumPlayers >= 1) then + Statics[StaticTeam1].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[0].Percentage / 100; if (ScreenSingModi.PlayerInfo.NumPlayers >= 2) then - Static[StaticTeam2].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[1].Percentage / 100; + Statics[StaticTeam2].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[1].Percentage / 100; if (ScreenSingModi.PlayerInfo.NumPlayers >= 3) then - Static[StaticTeam3].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[2].Percentage / 100; + Statics[StaticTeam3].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[2].Percentage / 100;} end; end. diff --git a/cmake/src/screens/UScreenPartyWin.pas b/cmake/src/screens/UScreenPartyWin.pas index 3c105c7d..ed8d017c 100644 --- a/cmake/src/screens/UScreenPartyWin.pas +++ b/cmake/src/screens/UScreenPartyWin.pas @@ -34,10 +34,11 @@ interface {$I switches.inc} uses + SDL, + SysUtils, UMenu, - SDL, UDisplay, + UDisplay, UMusic, - SysUtils, UThemes; type @@ -61,28 +62,28 @@ type TextWinner: cardinal; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; end; implementation -uses +uses UGraphic, UMain, UParty, - UScreenSingModi, - ULanguage; + ULanguage, + UUnicodeUtils; -function TScreenPartyWin.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenPartyWin.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -92,13 +93,8 @@ begin // check special keys case PressedKey of SDLK_ESCAPE, - SDLK_BACKSPACE : - begin - AudioPlayback.PlaySound(SoundLib.Start); - FadeTo(@ScreenMain); - end; - - SDLK_RETURN: + SDLK_BACKSPACE, + SDLK_RETURN : begin AudioPlayback.PlaySound(SoundLib.Start); FadeTo(@ScreenMain); @@ -108,8 +104,6 @@ begin end; constructor TScreenPartyWin.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; @@ -135,12 +129,12 @@ begin LoadFromTheme(Theme.PartyWin); end; -procedure TScreenPartyWin.onShow; +procedure TScreenPartyWin.OnShow; var - I: integer; - Placing: TeamOrderArray; + I: integer; + Ranking: AParty_TeamRanking; - Function GetTeamColor(Team: byte): cardinal; + Function GetTeamColor(Team: integer): cardinal; var NameString: string; begin @@ -152,42 +146,43 @@ var begin inherited; - //Get Team Placing - Placing := PartySession.GetTeamOrder; + // get team ranking + // Ranking is sorted by score + Ranking := Party.GetTeamRanking; //Set Winnertext - Text[TextWinner].Text := Format(Language.Translate('PARTY_SCORE_WINS'), [PartySession.Teams.Teaminfo[Placing[0]].Name]); - if (PartySession.Teams.NumTeams >= 1) then + Text[TextWinner].Text := Format(Language.Translate('PARTY_SCORE_WINS'), [Party.GetWinnerString(-1)]); + if (Length(Party.Teams) >= 1) then begin - Text[TextScoreTeam1].Text := InttoStr(PartySession.Teams.TeamInfo[Placing[0]].Score); - Text[TextNameTeam1].Text := string(PartySession.Teams.TeamInfo[Placing[0]].Name); + Text[TextScoreTeam1].Text := IntToStr(Party.Teams[Ranking[0].Team].Score); + Text[TextNameTeam1].Text := Party.Teams[Ranking[0].Team].Name; Text[TextScoreTeam1].Visible := true; Text[TextNameTeam1].Visible := true; - Static[StaticTeam1].Visible := true; - Static[StaticTeam1BG].Visible := true; - Static[StaticTeam1Deco].Visible := true; + Statics[StaticTeam1].Visible := true; + Statics[StaticTeam1BG].Visible := true; + Statics[StaticTeam1Deco].Visible := true; //Set Static Color to Team Color if (Theme.PartyWin.StaticTeam1BG.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[0]); + I := GetTeamColor(Ranking[0].Team); if (I <> -1) then begin - Static[StaticTeam1BG].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam1BG].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam1BG].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam1BG].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam1BG].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam1BG].Texture.ColB := Color[I].RGB.B; end; end; if (Theme.PartyWin.StaticTeam1.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[0]); + I := GetTeamColor(Ranking[0].Team); if (I <> -1) then begin - Static[StaticTeam1].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam1].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam1].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam1].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam1].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam1].Texture.ColB := Color[I].RGB.B; end; end; end @@ -195,42 +190,42 @@ begin begin Text[TextScoreTeam1].Visible := false; Text[TextNameTeam1].Visible := false; - Static[StaticTeam1].Visible := false; - Static[StaticTeam1BG].Visible := false; - Static[StaticTeam1Deco].Visible := false; + Statics[StaticTeam1].Visible := false; + Statics[StaticTeam1BG].Visible := false; + Statics[StaticTeam1Deco].Visible := false; end; - if (PartySession.Teams.NumTeams >= 2) then + if (Length(Party.Teams) >= 2) then begin - Text[TextScoreTeam2].Text := InttoStr(PartySession.Teams.TeamInfo[Placing[1]].Score); - Text[TextNameTeam2].Text := string(PartySession.Teams.TeamInfo[Placing[1]].Name); + Text[TextScoreTeam2].Text := IntToStr(Party.Teams[Ranking[1].Team].Score); + Text[TextNameTeam2].Text := Party.Teams[Ranking[1].Team].Name; Text[TextScoreTeam2].Visible := true; Text[TextNameTeam2].Visible := true; - Static[StaticTeam2].Visible := true; - Static[StaticTeam2BG].Visible := true; - Static[StaticTeam2Deco].Visible := true; + Statics[StaticTeam2].Visible := true; + Statics[StaticTeam2BG].Visible := true; + Statics[StaticTeam2Deco].Visible := true; //Set Static Color to Team Color if (Theme.PartyWin.StaticTeam2BG.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[1]); + I := GetTeamColor(Ranking[1].Team); if (I <> -1) then begin - Static[StaticTeam2BG].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam2BG].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam2BG].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam2BG].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam2BG].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam2BG].Texture.ColB := Color[I].RGB.B; end; end; if (Theme.PartyWin.StaticTeam2.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[1]); + I := GetTeamColor(Ranking[1].Team); if (I <> -1) then begin - Static[StaticTeam2].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam2].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam2].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam2].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam2].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam2].Texture.ColB := Color[I].RGB.B; end; end; end @@ -238,42 +233,42 @@ begin begin Text[TextScoreTeam2].Visible := false; Text[TextNameTeam2].Visible := false; - Static[StaticTeam2].Visible := false; - Static[StaticTeam2BG].Visible := false; - Static[StaticTeam2Deco].Visible := false; + Statics[StaticTeam2].Visible := false; + Statics[StaticTeam2BG].Visible := false; + Statics[StaticTeam2Deco].Visible := false; end; - if (PartySession.Teams.NumTeams >= 3) then + if (Length(Party.Teams) >= 3) then begin - Text[TextScoreTeam3].Text := InttoStr(PartySession.Teams.TeamInfo[Placing[2]].Score); - Text[TextNameTeam3].Text := string(PartySession.Teams.TeamInfo[Placing[2]].Name); + Text[TextScoreTeam3].Text := IntToStr(Party.Teams[Ranking[2].Team].Score); + Text[TextNameTeam3].Text := Party.Teams[Ranking[2].Team].Name; Text[TextScoreTeam3].Visible := true; Text[TextNameTeam3].Visible := true; - Static[StaticTeam3].Visible := true; - Static[StaticTeam3BG].Visible := true; - Static[StaticTeam3Deco].Visible := true; + Statics[StaticTeam3].Visible := true; + Statics[StaticTeam3BG].Visible := true; + Statics[StaticTeam3Deco].Visible := true; //Set Static Color to Team Color if (Theme.PartyWin.StaticTeam3BG.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[2]); + I := GetTeamColor(Ranking[2].Team); if (I <> -1) then begin - Static[StaticTeam3BG].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam3BG].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam3BG].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam3BG].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam3BG].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam3BG].Texture.ColB := Color[I].RGB.B; end; end; if (Theme.PartyWin.StaticTeam3.Color = 'TeamColor') then begin - I := GetTeamColor(Placing[2]); + I := GetTeamColor(Ranking[2].Team); if (I <> -1) then begin - Static[StaticTeam3].Texture.ColR := Color[I].RGB.R; - Static[StaticTeam3].Texture.ColG := Color[I].RGB.G; - Static[StaticTeam3].Texture.ColB := Color[I].RGB.B; + Statics[StaticTeam3].Texture.ColR := Color[I].RGB.R; + Statics[StaticTeam3].Texture.ColG := Color[I].RGB.G; + Statics[StaticTeam3].Texture.ColB := Color[I].RGB.B; end; end; end @@ -281,20 +276,20 @@ begin begin Text[TextScoreTeam3].Visible := false; Text[TextNameTeam3].Visible := false; - Static[StaticTeam3].Visible := false; - Static[StaticTeam3BG].Visible := false; - Static[StaticTeam3Deco].Visible := false; + Statics[StaticTeam3].Visible := false; + Statics[StaticTeam3BG].Visible := false; + Statics[StaticTeam3Deco].Visible := false; end; end; procedure TScreenPartyWin.SetAnimationProgress(Progress: real); begin {if (ScreenSingModi.PlayerInfo.NumPlayers >= 1) then - Static[StaticTeam1].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[0].Score / maxScore; + Statics[StaticTeam1].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[0].Score / maxScore; if (ScreenSingModi.PlayerInfo.NumPlayers >= 2) then - Static[StaticTeam2].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[1].Score / maxScore; + Statics[StaticTeam2].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[1].Score / maxScore; if (ScreenSingModi.PlayerInfo.NumPlayers >= 3) then - Static[StaticTeam3].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[2].Score / maxScore;} + Statics[StaticTeam3].Texture.ScaleW := Progress * ScreenSingModi.PlayerInfo.Playerinfo[2].Score / maxScore;} end; end. diff --git a/cmake/src/screens/UScreenPopup.pas b/cmake/src/screens/UScreenPopup.pas index 7e4671d6..fdf4a69c 100644 --- a/cmake/src/screens/UScreenPopup.pas +++ b/cmake/src/screens/UScreenPopup.pas @@ -34,42 +34,61 @@ interface {$I switches.inc} uses - UMenu, SDL, + SysUtils, + UMenu, UMusic, UFiles, - SysUtils, UThemes; type + TPopupCheckHandler = procedure(Value: boolean; Data: Pointer); + TScreenPopupCheck = class(TMenu) + private + fHandler: TPopupCheckHandler; + fHandlerData: Pointer; + public - Visible: boolean; //Whether the Menu should be Drawn + Visible: boolean; // whether the menu should be drawn constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; - procedure ShowPopup(msg: string); + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; + procedure ShowPopup(const Msg: UTF8String; Handler: TPopupCheckHandler; + HandlerData: Pointer; DefaultValue: boolean = false); function Draw: boolean; override; end; type - TScreenPopupError = class(TMenu) -{ private - CurMenu: byte; //Num of the cur. Shown Menu} + TScreenPopup = class(TMenu) + { + private + CurMenu: byte; //Num of the cur. Shown Menu + } public Visible: boolean; //Whether the Menu should be Drawn constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; - procedure onHide; override; - procedure ShowPopup(msg: string); + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; + procedure OnHide; override; + procedure ShowPopup(const Msg: UTF8String); function Draw: boolean; override; end; + TScreenPopupError = class(TScreenPopup) + public + constructor Create; + end; + + TScreenPopupInfo = class(TScreenPopup) + public + constructor Create; + end; + var -// ISelections: array of string; + //ISelections: array of string; SelectValue: integer; implementation @@ -82,70 +101,57 @@ uses ULanguage, UParty, UPlaylist, - UDisplay; + UDisplay, + UUnicodeUtils; -function TScreenPopupCheck.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +{ TScreenPopupCheck } + +function TScreenPopupCheck.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; +var + Value: 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 - Display.CheckOK := false; - Display.NextScreenWithCheck := NIL; + Value := false; Visible := false; Result := false; end; SDLK_RETURN: begin - case Interaction of - 0: begin - //Hack to Finish Singscreen correct on Exit with Q Shortcut - if (Display.NextScreenWithCheck = NIL) then - begin - if (Display.CurrentScreen = @ScreenSing) then - ScreenSing.Finish - else if (Display.CurrentScreen = @ScreenSingModi) then - ScreenSingModi.Finish; - end; - - Display.CheckOK := true; - end; - 1: begin - Display.CheckOK := false; - Display.NextScreenWithCheck := NIL; - end; - end; + Value := (Interaction = 0); Visible := false; Result := false; end; - SDLK_DOWN: InteractNext; - SDLK_UP: InteractPrev; - + SDLK_DOWN: InteractNext; + SDLK_UP: InteractPrev; + SDLK_RIGHT: InteractNext; - SDLK_LEFT: InteractPrev; + SDLK_LEFT: InteractPrev; end; end; + + if (not Result) then + begin + if (@fHandler <> nil) then + fHandler(Value, fHandlerData); + end; end; constructor TScreenPopupCheck.Create; begin inherited Create; + fHandler := nil; + fHandlerData := nil; + AddText(Theme.CheckPopup.TextCheck); LoadFromTheme(Theme.CheckPopup); @@ -163,18 +169,24 @@ end; function TScreenPopupCheck.Draw: boolean; begin - Draw:=inherited Draw; + Result := inherited Draw; end; -procedure TScreenPopupCheck.onShow; +procedure TScreenPopupCheck.OnShow; begin inherited; end; -procedure TScreenPopupCheck.ShowPopup(msg: string); +procedure TScreenPopupCheck.ShowPopup(const Msg: UTF8String; Handler: TPopupCheckHandler; + HandlerData: Pointer; DefaultValue: boolean); begin - Interaction := 0; //Reset Interaction + if (DefaultValue) then + Interaction := 0 + else + Interaction := 1; Visible := true; //Set Visible + fHandler := Handler; + fHandlerData := HandlerData; Text[0].Text := Language.Translate(msg); @@ -187,9 +199,9 @@ begin Background.OnShow end; -// error popup +{ TScreenPopup } -function TScreenPopupError.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenPopup.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then @@ -223,7 +235,7 @@ begin end; end; -constructor TScreenPopupError.Create; +constructor TScreenPopup.Create; begin inherited Create; @@ -238,22 +250,22 @@ begin Interaction := 0; end; -function TScreenPopupError.Draw: boolean; +function TScreenPopup.Draw: boolean; begin Draw := inherited Draw; end; -procedure TScreenPopupError.onShow; +procedure TScreenPopup.OnShow; begin inherited; end; -procedure TScreenPopupError.onHide; +procedure TScreenPopup.OnHide; begin end; -procedure TScreenPopupError.ShowPopup(msg: string); +procedure TScreenPopup.ShowPopup(const Msg: UTF8String); begin Interaction := 0; //Reset Interaction Visible := true; //Set Visible @@ -277,4 +289,20 @@ begin Button[0].Text[0].Text := 'OK'; end; +{ TScreenPopupError } + +constructor TScreenPopupError.Create; +begin + inherited; + Text[1].Text := Language.Translate('MSG_ERROR_TITLE'); +end; + +{ TScreenPopupInfo } + +constructor TScreenPopupInfo.Create; +begin + inherited; + Text[1].Text := Language.Translate('MSG_INFO_TITLE'); +end; + end. diff --git a/cmake/src/screens/UScreenScore.pas b/cmake/src/screens/UScreenScore.pas index a01c7691..de7675bf 100644 --- a/cmake/src/screens/UScreenScore.pas +++ b/cmake/src/screens/UScreenScore.pas @@ -51,9 +51,10 @@ const EaseOut_MaxSteps: real = 10; // that's the speed of the bars (10 is fast | 100 is slower) - BarRaiseSpeed: cardinal = 0; // Time for raising the bar one step higher (in ms) + BarRaiseSpeed: cardinal = 14; // Time for raising the bar one step higher (in ms) type + TScoreBarType = (sbtScore, sbtLine, sbtGolden); TPlayerScoreScreenTexture = record // holds all colorized textures for up to 6 players //Bar textures Score_NoteBarLevel_Dark: TTexture; // Note @@ -64,6 +65,8 @@ type Score_NoteBarLevel_Lightest: TTexture; // GoldenNotes Score_NoteBarRound_Lightest: TTexture; + + Player_Id_Box: TTexture; // boxes with player numbers end; TPlayerScoreScreenData = record // holds the positions and other data @@ -79,11 +82,27 @@ type RateEaseValue: real; end; + { hold maps of players to the different positions } + TPlayerPositionMap = record + Position: byte; // 1..6: Position of Player; 0: no position (e.g. too little screens) + Screen: byte; // 0 - Screen 1; 1 - Screen 2 + BothScreens: boolean; // true if player is drawn on both screens + end; + APlayerPositionMap = array of TPlayerPositionMap; + + { textures for playerstatics of seconds screen players } + TPlayerStaticTexture = record + Tex: TTexture; + end; + TScreenScore = class(TMenu) private + { holds position and screen of players(index) + set by calling MapPlayerstoPosition() } + PlayerPositionMap: APlayerPositionMap; + BarTime: cardinal; - ArrayStartModifier: integer; - public + aPlayerScoreScreenTextures: array[1..6] of TPlayerScoreScreenTexture; aPlayerScoreScreenDatas: array[1..6] of TPlayerScoreScreenData; aPlayerScoreScreenRatings: array[1..6] of TPlayerScoreRatingPics; @@ -110,42 +129,77 @@ type TextTotalScore: array[1..6] of integer; PlayerStatic: array[1..6] of array of integer; + { texture pairs for swapping when screens = 2 + first array level: index of player ( actually this is a position + 1 - Player 1 if PlayersPlay = 1 <- we don't need swapping here + 2..3 - Player 1 and 2 or 3 and 4 if PlayersPlay = 2 or 4 + 4..6 - Player 1 - 3 or 4 - 6 if PlayersPlay = 3 or 6 ) + second array level: different playerstatics for positions + third array level: texture for screen 1 or 2 } + PlayerStaticTextures: array[1..6] of array of array [1..2] of TPlayerStaticTexture; PlayerTexts: array[1..6] of array of integer; StaticBoxLightest: array[1..6] of integer; StaticBoxLight: array[1..6] of integer; StaticBoxDark: array[1..6] of integer; + { texture pairs for swapping when screens = 2 + for boxes + first array level: index of player ( actually this is a position + 1 - Player 1 if PlayersPlay = 1 <- we don't need swapping here + 2..3 - Player 1 and 2 or 3 and 4 if PlayersPlay = 2 or 4 + 4..6 - Player 1 - 3 or 4 - 6 if PlayersPlay = 3 or 6 ) + second array level: different boxes for positions (0: lightest; 1: light; 2: dark) + third array level: texture for screen 1 or 2 } + PlayerBoxTextures: array[1..6] of array[0..2] of array [1..2] of TPlayerStaticTexture; StaticBackLevel: array[1..6] of integer; StaticBackLevelRound: array[1..6] of integer; StaticLevel: array[1..6] of integer; StaticLevelRound: array[1..6] of integer; + { statics with players ids } + StaticPlayerIdBox: array[1..6] of integer; + TexturePlayerIdBox: array[1..6] of TTexture; + Animation: real; TextScore_ActualValue: array[1..6] of integer; TextPhrase_ActualValue: array[1..6] of integer; TextGolden_ActualValue: array[1..6] of integer; - constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - function ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; override; - procedure onShow; override; - procedure onShowFinish; override; - function Draw: boolean; override; + procedure MapPlayersToPosition; + procedure FillPlayer(Item, P: integer); + procedure FillPlayerItems(PlayerNumber: integer); - procedure EaseBarIn(PlayerNumber: integer; BarType: string); - procedure EaseScoreIn(PlayerNumber: integer; ScoreType: string); + procedure UpdateAnimation; + {**** + * helpers for bar easing + *} + procedure EaseBarIn(PlayerNumber: integer; BarType: TScoreBarType); + procedure EaseScoreIn(PlayerNumber: integer; ScoreType: TScoreBarType); - procedure FillPlayerItems(PlayerNumber: integer; ScoreType: string); + procedure DrawPlayerBars; - procedure DrawBar(BarType: string; PlayerNumber: integer; BarStartPosY: single; NewHeight: real); + procedure DrawBar(BarType: TScoreBarType; PlayerNumber: integer; BarStartPosY: single; NewHeight: real); - //Rating Picture + {**** + * helpers for rating picture + *} procedure ShowRating(PlayerNumber: integer); function CalculateBouncing(PlayerNumber: integer): real; procedure DrawRating(PlayerNumber: integer; Rating: integer); + + { for player static texture swapping } + procedure LoadSwapTextures; + procedure SwapToScreen(Screen: integer); + public + constructor Create; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + function ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; override; + procedure OnShow; override; + procedure OnShowFinish; override; + function Draw: boolean; override; end; implementation @@ -156,18 +210,21 @@ uses UMenuStatic, UTime, UIni, + USkins, ULog, ULanguage, - UNote; + UNote, + UUnicodeUtils; -function TScreenScore.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + +function TScreenScore.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -197,7 +254,189 @@ begin Result := True; if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then begin //left-click anywhere sends return - ParseInput(SDLK_RETURN, #0, true); + ParseInput(SDLK_RETURN, 0, true); + end; +end; + +procedure TScreenScore.LoadSwapTextures; + var + P, I: integer; + PlayerNum, PlayerNum2: integer; + Color: string; + R, G, B: real; + StaticNum: integer; + ThemeStatic: TThemeStatic; +begin + { we only need to load swapping textures if in dualscreen mode } + if Screens = 2 then + begin + { load swapping textures for custom statics } + for P := low(PlayerStatic) to High(PlayerStatic) do + begin + SetLength(PlayerStaticTextures[P], Length(PlayerStatic[P])); + + { get the players that actually are on this position } + case P of + 1: begin + PlayerNum := 1; + PlayerNum2 := 1; + end; + + 2, 3: begin + PlayerNum := P - 1; + PlayerNum2 := PlayerNum + 2; + end; + + 4..6: begin + PlayerNum := P - 3; + PlayerNum2 := PlayerNum + 3; + end; + end; + + for I := 0 to High(PlayerStatic[P]) do + begin + // copy current statics texture to texture for screen 1 + PlayerStaticTextures[P, I, 1].Tex := Statics[PlayerStatic[P, I]].Texture; + + // fallback to first screen texture for 2nd screen + PlayerStaticTextures[P, I, 2].Tex := PlayerStaticTextures[P, I, 1].Tex; + + { texture for second screen } + { we only change color for statics with playercolor + and with Texture type colorized + also we don't need to swap for one player position } + if (P <> 1) and + (Theme.Score.PlayerStatic[P, I].Typ = Texture_Type_Colorized) and + (Length(Theme.Score.PlayerStatic[P, I].Color) >= 2) and + (copy(Theme.Score.PlayerStatic[P, I].Color, 1, 2) = 'P' + IntToStr(PlayerNum)) then + begin + // get the color + Color := Theme.Score.PlayerStatic[P, I].Color; + Color[2] := IntToStr(PlayerNum2)[1]; + LoadColor(R, G, B, Color); + + with Theme.Score.PlayerStatic[P, I] do + PlayerStaticTextures[P, I, 2].Tex := Texture.GetTexture(Skin.GetTextureFileName(Tex), Typ, RGBFloatToInt(R, G, B)); + + PlayerStaticTextures[P, I, 2].Tex.X := Statics[PlayerStatic[P, I]].Texture.X; + PlayerStaticTextures[P, I, 2].Tex.Y := Statics[PlayerStatic[P, I]].Texture.Y; + PlayerStaticTextures[P, I, 2].Tex.W := Statics[PlayerStatic[P, I]].Texture.W; + PlayerStaticTextures[P, I, 2].Tex.H := Statics[PlayerStatic[P, I]].Texture.H; + end; + end; + end; + + { load swap textures for boxes } + for P := low(PlayerBoxTextures) to High(PlayerBoxTextures) do + begin + { get the players that actually are on this position } + case P of + 1: begin + PlayerNum := 1; + PlayerNum2 := 1; + end; + + 2, 3: begin + PlayerNum := P - 1; + PlayerNum2 := PlayerNum + 2; + end; + + 4..6: begin + PlayerNum := P - 3; + PlayerNum2 := PlayerNum + 3; + end; + end; + + for I := 0 to High(PlayerBoxTextures[P]) do + begin + case I of + 0: begin + StaticNum := StaticBoxLightest[P]; + ThemeStatic := Theme.Score.StaticBoxLightest[P]; + end; + 1: begin + StaticNum := StaticBoxLight[P]; + ThemeStatic := Theme.Score.StaticBoxLight[P]; + end; + 2: begin + StaticNum := StaticBoxDark[P]; + ThemeStatic := Theme.Score.StaticBoxDark[P]; + end; + end; + // copy current statics texture to texture for screen 1 + PlayerBoxTextures[P, I, 1].Tex := Statics[StaticNum].Texture; + + // fallback to first screen texture for 2nd screen + PlayerBoxTextures[P, I, 2].Tex := PlayerBoxTextures[P, I, 1].Tex; + + { texture for second screen } + { we only change color for statics with playercolor + and with Texture type colorized + also we don't need to swap for one player position } + if (P <> 1) and + (ThemeStatic.Typ = Texture_Type_Colorized) and + (Length(ThemeStatic.Color) >= 2) and + (copy(ThemeStatic.Color, 1, 2) = 'P' + IntToStr(PlayerNum)) then + begin + // get the color + Color := ThemeStatic.Color; + Color[2] := IntToStr(PlayerNum2)[1]; + LoadColor(R, G, B, Color); + + with ThemeStatic do + PlayerBoxTextures[P, I, 2].Tex := Texture.GetTexture(Skin.GetTextureFileName(Tex), Typ, RGBFloatToInt(R, G, B)); + + PlayerBoxTextures[P, I, 2].Tex.X := Statics[StaticNum].Texture.X; + PlayerBoxTextures[P, I, 2].Tex.Y := Statics[StaticNum].Texture.Y; + PlayerBoxTextures[P, I, 2].Tex.W := Statics[StaticNum].Texture.W; + PlayerBoxTextures[P, I, 2].Tex.H := Statics[StaticNum].Texture.H; + end; + end; + end; + end; +end; + +procedure TScreenScore.SwapToScreen(Screen: integer); + var + P, I: integer; +begin + { if screens = 2 and playerplay <= 3 the 2nd screen shows the + textures of screen 1 } + if (PlayersPlay <= 3) and (Screen = 2) then + Screen := 1; + + { set correct box textures } + for I := 0 to High(PlayerPositionMap) do + begin + if (PlayerPositionMap[I].Position > 0) and ((ScreenAct = PlayerPositionMap[I].Screen) or (PlayerPositionMap[I].BothScreens)) then + begin + // we just set the texture specific stuff + // so we don't overwrite e.g. width and height + with Statics[StaticPlayerIdBox[PlayerPositionMap[I].Position]].Texture do + begin + TexNum := aPlayerScoreScreenTextures[I+1].Player_Id_Box.TexNum; + TexW := aPlayerScoreScreenTextures[I+1].Player_Id_Box.TexW; + TexH := aPlayerScoreScreenTextures[I+1].Player_Id_Box.TexH; + end; + end; + end; + + if (Screens = 2) then + begin + { to keep it simple we just swap all statics, not just the shown ones } + for P := Low(PlayerStatic) to High(PlayerStatic) do + for I := 0 to High(PlayerStatic[P]) do + begin + Statics[PlayerStatic[P, I]].Texture := PlayerStaticTextures[P, I, Screen].Tex; + end; + + { box statics } + for P := Low(PlayerStatic) to High(PlayerStatic) do + begin + Statics[StaticBoxLightest[P]].Texture := PlayerBoxTextures[P, 0, Screen].Tex; + Statics[StaticBoxLight[P]].Texture := PlayerBoxTextures[P, 1, Screen].Tex; + Statics[StaticBoxDark[P]].Texture := PlayerBoxTextures[P, 2, Screen].Tex; + end; end; end; @@ -224,6 +463,8 @@ begin for Counter := 0 to High(Theme.Score.PlayerStatic[Player]) do PlayerStatic[Player, Counter] := AddStatic(Theme.Score.PlayerStatic[Player, Counter]); + + for Counter := 0 to High(Theme.Score.PlayerTexts[Player]) do PlayerTexts[Player, Counter] := AddText(Theme.Score.PlayerTexts[Player, Counter]); @@ -247,6 +488,7 @@ begin StaticBackLevelRound[Player] := AddStatic(Theme.Score.StaticBackLevelRound[Player]); StaticLevel[Player] := AddStatic(Theme.Score.StaticLevel[Player]); StaticLevelRound[Player] := AddStatic(Theme.Score.StaticLevelRound[Player]); + StaticPlayerIdBox[Player] := AddStatic(Theme.Score.StaticPlayerIdBox[Player]); //textures aPlayerScoreScreenTextures[Player].Score_NoteBarLevel_Dark := Tex_Score_NoteBarLevel_Dark[Player]; @@ -257,25 +499,18 @@ begin aPlayerScoreScreenTextures[Player].Score_NoteBarLevel_Lightest := Tex_Score_NoteBarLevel_Lightest[Player]; aPlayerScoreScreenTextures[Player].Score_NoteBarRound_Lightest := Tex_Score_NoteBarRound_Lightest[Player]; + aPlayerScoreScreenTextures[Player].Player_Id_Box := Texture.GetTexture(Skin.GetTextureFileName('PlayerIDBox0' + IntToStr(Player)), Texture_Type_Transparent); end; + LoadSwapTextures; end; -procedure TScreenScore.onShow; -var - P: integer; // player - I: integer; - V: array[1..6] of boolean; // visibility array - +procedure TScreenScore.MapPlayersToPosition; + var + ArrayStartModifier: integer; + PlayersPerScreen: integer; + I: integer; begin - -{** - * Turn backgroundmusic on - *} - SoundLib.StartBgMusic; - - inherited; - // all statics / texts are loaded at start - so that we have them all even if we change the amount of players // To show the corrects statics / text from the them, we simply modify the start of the according arrays // 1 Player -> Player[0].Score (The score for one player starts at 0) @@ -285,21 +520,122 @@ begin // 3 Player -> Player[0..5].Score // -> Statics[4..6] case PlayersPlay of - 1: ArrayStartModifier := 0; - 2, 4: ArrayStartModifier := 1; - 3, 6: ArrayStartModifier := 3; + 1: ArrayStartModifier := 1; + 2, 4: ArrayStartModifier := 2; + 3, 6: ArrayStartModifier := 4; else ArrayStartModifier := 0; //this should never happen end; + if (PlayersPlay <= 3) then + PlayersPerScreen := PlayersPlay + else + PlayersPerScreen := PlayersPlay div 2; + + SetLength(PlayerPositionMap, PlayersPlay); + + // actually map players to positions + for I := 0 to PlayersPlay - 1 do + begin + PlayerPositionMap[I].Screen := (I div PlayersPerScreen) + 1; + if (PlayerPositionMap[I].Screen > Screens) then + PlayerPositionMap[I].Position := 0 + else + PlayerPositionMap[I].Position := ArrayStartModifier + (I mod PlayersPerScreen); + PlayerPositionMap[I].BothScreens := (PlayersPlay <= 3) and (Screens > 1); + end; +end; + +procedure TScreenScore.UpdateAnimation; +var + CurrentTime: integer; + I: integer; +begin + CurrentTime := SDL_GetTicks(); + + if (ScreenAct = 1) and ShowFinish then + while (CurrentTime >= BarTime) do + begin + Inc(BarTime, BarRaiseSpeed); + + // We actually arise them in the right order, but we have to draw them in reverse order (golden -> phrase -> mainscore) + if (BarScore_EaseOut_Step < EaseOut_MaxSteps * 10) then + BarScore_EaseOut_Step:= BarScore_EaseOut_Step + 1 + + // PhrasenBonus + else if (BarPhrase_EaseOut_Step < EaseOut_MaxSteps * 10) then + BarPhrase_EaseOut_Step := BarPhrase_EaseOut_Step + 1 + + // GoldenNotebonus + else if (BarGolden_EaseOut_Step < EaseOut_MaxSteps * 10) then + BarGolden_EaseOut_Step := BarGolden_EaseOut_Step + 1 + + // rating icon + else + for I := 1 to PlayersPlay do + CalculateBouncing(I); + end; +end; + +procedure TScreenScore.DrawPlayerBars; + var + I: integer; +begin + for I := 0 to PlayersPlay-1 do + begin + if (PlayerPositionMap[I].Position > 0) and ((ScreenAct = PlayerPositionMap[I].Screen) or (PlayerPositionMap[I].BothScreens)) then + begin + if (BarScore_EaseOut_Step >= (EaseOut_MaxSteps * 10)) then + begin + if (BarPhrase_EaseOut_Step >= (EaseOut_MaxSteps * 10)) then + begin + // Draw golden score bar # + EaseBarIn(I + 1, sbtGolden); + EaseScoreIn(I + 1, sbtGolden); + end; + + // Draw phrase score bar # + EaseBarIn(I + 1, sbtLine); + EaseScoreIn(I + 1, sbtLine); + end; + + // Draw plain score bar # + EaseBarIn(I + 1, sbtScore); + EaseScoreIn(I + 1, sbtScore); + end; + end; +end; + +procedure TScreenScore.OnShow; +var + P: integer; // player + I: integer; + V: array[1..6] of boolean; // visibility array + +begin + + {** + * Turn backgroundmusic on + *} + SoundLib.StartBgMusic; + + inherited; + + MapPlayersToPosition; + for P := 1 to PlayersPlay do begin // data - aPlayerScoreScreenDatas[P].Bar_Y := Theme.Score.StaticBackLevel[P + ArrayStartModifier].Y; + aPlayerScoreScreenDatas[P].Bar_Y := Theme.Score.StaticBackLevel[PlayerPositionMap[P-1].Position].Y; // ratings aPlayerScoreScreenRatings[P].RateEaseStep := 1; aPlayerScoreScreenRatings[P].RateEaseValue := 20; + + // actual values + TextScore_ActualValue[P] := 0; + TextPhrase_ActualValue[P] := 0; + TextGolden_ActualValue[P] := 0; end; Text[TextArtist].Text := CurrentSong.Artist; @@ -349,9 +685,9 @@ begin Text[TextGoldenNotesScore[P]].Alpha := 0; Text[TextTotal[P]].Alpha := 0; Text[TextTotalScore[P]].Alpha := 0; - Static[StaticBoxLightest[P]].Texture.Alpha := 0; - Static[StaticBoxLight[P]].Texture.Alpha := 0; - Static[StaticBoxDark[P]].Texture.Alpha := 0; + Statics[StaticBoxLightest[P]].Texture.Alpha := 0; + Statics[StaticBoxLight[P]].Texture.Alpha := 0; + Statics[StaticBoxDark[P]].Texture.Alpha := 0; Text[TextNotes[P]].Visible := V[P]; Text[TextNotesScore[P]].Visible := V[P]; @@ -363,21 +699,27 @@ begin Text[TextTotalScore[P]].Visible := V[P]; for I := 0 to high(PlayerStatic[P]) do - Static[PlayerStatic[P, I]].Visible := V[P]; + Statics[PlayerStatic[P, I]].Visible := V[P]; for I := 0 to high(PlayerTexts[P]) do Text[PlayerTexts[P, I]].Visible := V[P]; - Static[StaticBoxLightest[P]].Visible := V[P]; - Static[StaticBoxLight[P]].Visible := V[P]; - Static[StaticBoxDark[P]].Visible := V[P]; + Statics[StaticBoxLightest[P]].Visible := V[P]; + Statics[StaticBoxLight[P]].Visible := V[P]; + Statics[StaticBoxDark[P]].Visible := V[P]; + + Statics[StaticPlayerIdBox[P]].Visible := V[P]; // we draw that on our own - Static[StaticBackLevel[P]].Visible := false; - Static[StaticBackLevelRound[P]].Visible := false; - Static[StaticLevel[P]].Visible := false; - Static[StaticLevelRound[P]].Visible := false; + Statics[StaticBackLevel[P]].Visible := false; + Statics[StaticBackLevelRound[P]].Visible := false; + Statics[StaticLevel[P]].Visible := false; + Statics[StaticLevelRound[P]].Visible := false; end; + + BarScore_EaseOut_Step := 1; + BarPhrase_EaseOut_Step := 1; + BarGolden_EaseOut_Step := 1; end; procedure TScreenScore.onShowFinish; @@ -391,17 +733,12 @@ begin TextGolden_ActualValue[index] := 0; end; - BarScore_EaseOut_Step := 1; - BarPhrase_EaseOut_Step := 1; - BarGolden_EaseOut_Step := 1; + BarTime := SDL_GetTicks(); end; function TScreenScore.Draw: boolean; var - CurrentTime: cardinal; PlayerCounter: integer; - PStart: integer; - PHigh: integer; begin {* player[0].ScoreInt := 7000; @@ -413,94 +750,33 @@ begin player[1].ScoreLineInt := 1100; player[1].ScoreGoldenInt := 900; player[1].ScoreTotalInt := 4500; -*} +//*} + // swap static textures to current screen ones + SwapToScreen(ScreenAct); //Draw the Background DrawBG; - //Calculate first and last Player on this Screen - if (PlayersPlay > 3) then - begin - case PlayersPlay of - 4: begin - PStart := 1 + ((ScreenAct-1) * 2); - PHigh := 2 + ((ScreenAct-1) * 2); - end; - - 6: begin - PStart := 1 + ((ScreenAct-1) * 3); - PHigh := 3 + ((ScreenAct-1) * 3); - end; - end; - end - else - begin - PStart := 1; - PHigh := PlayersPlay; - end; - // Let's start to arise the bars - CurrentTime := SDL_GetTicks(); - if((CurrentTime >= BarTime) and ShowFinish) then - begin - BarTime := CurrentTime + BarRaiseSpeed; - - for PlayerCounter := PStart to PHigh do - begin - // We actually arise them in the right order, but we have to draw them in reverse order (golden -> phrase -> mainscore) - if (BarScore_EaseOut_Step < EaseOut_MaxSteps * 10) then - BarScore_EaseOut_Step:= BarScore_EaseOut_Step + 1; - - // PhrasenBonus - if (BarScore_EaseOut_Step >= (EaseOut_MaxSteps * 10)) then - begin - if (BarPhrase_EaseOut_Step < EaseOut_MaxSteps * 10) then - BarPhrase_EaseOut_Step := BarPhrase_EaseOut_Step + 1; - - // GoldenNotebonus - if (BarPhrase_EaseOut_Step >= (EaseOut_MaxSteps * 10)) then - begin - if (BarGolden_EaseOut_Step < EaseOut_MaxSteps * 10) then - BarGolden_EaseOut_Step := BarGolden_EaseOut_Step + 1; - - // Draw golden score bar # - EaseBarIn(PlayerCounter, 'Golden'); - EaseScoreIn(PlayerCounter,'Golden'); - end; - - // Draw phrase score bar # - EaseBarIn(PlayerCounter, 'Line'); - EaseScoreIn(PlayerCounter,'Line'); - end; - - // Draw plain score bar # - EaseBarIn(PlayerCounter, 'Note'); - EaseScoreIn(PlayerCounter,'Note'); + UpdateAnimation; - if (PlayersPlay <= 3) then - //If we play w/ 3 or less players they fit in one screen - //so we don't have to swap the values of themeobjects - //on every draw - FillPlayerItems(PlayerCounter,'Funky'); - - end; + // we have to swap the themeobjects values on every draw + // to support dual screen + for PlayerCounter := 1 to PlayersPlay do + begin + FillPlayerItems(PlayerCounter); end; - if (PlayersPlay > 3) then - //more then 3 players don't fit the screen - //so we have to swap the themeobjects values on every draw - for PlayerCounter := PStart to PHigh do - begin - FillPlayerItems(PlayerCounter,'Funky'); - end; + if (ShowFinish) then + DrawPlayerBars; //Draw Theme Objects DrawFG; (* //todo: i need a clever method to draw statics with their z value - for I := 0 to Length(Static) - 1 do - Static[I].Draw; + for I := 0 to Length(Statics) - 1 do + Statics[I].Draw; for I := 0 to Length(Text) - 1 do Text[I].Draw; *) @@ -508,54 +784,48 @@ begin Result := true; end; -procedure TscreenScore.FillPlayerItems(PlayerNumber: integer; ScoreType: string); +procedure TscreenScore.FillPlayerItems(PlayerNumber: integer); var ThemeIndex: integer; begin - // todo: take the name from player[PlayerNumber].Name instead of the ini when this is done (mog) - Text[TextName[PlayerNumber + ArrayStartModifier]].Text := Ini.Name[PlayerNumber - 1]; - // end todo - - // We have to do this here because we use the same Theme Object - // for players on the first and second screen - case PlayersPlay of - 1, 2, 3: ThemeIndex := PlayerNumber + ArrayStartModifier; - 4: ThemeIndex := ((PlayerNumber-1) mod 2) + 1 + ArrayStartModifier; - 6: ThemeIndex := ((PlayerNumber-1) mod 3) + 1 + ArrayStartModifier; - end; - - //golden - Text[TextGoldenNotesScore[ThemeIndex]].Text := IntToStr(TextGolden_ActualValue[PlayerNumber]); - Text[TextGoldenNotesScore[ThemeIndex]].Alpha := (BarGolden_EaseOut_Step / 100); + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; + if (ThemeIndex > 0) and ((ScreenAct = PlayerPositionMap[PlayerNumber-1].Screen) or (PlayerPositionMap[PlayerNumber-1].BothScreens)) then + begin + // todo: take the name from player[PlayerNumber].Name instead of the ini when this is done (mog) + Text[TextName[ThemeIndex]].Text := Ini.Name[PlayerNumber-1]; + // end todo - Static[StaticBoxLightest[ThemeIndex]].Texture.Alpha := (BarGolden_EaseOut_Step / 100); - Text[TextGoldenNotes[ThemeIndex]].Alpha := (BarGolden_EaseOut_Step / 100); + //golden + Text[TextGoldenNotesScore[ThemeIndex]].Text := IntToStr(TextGolden_ActualValue[PlayerNumber]); + Text[TextGoldenNotesScore[ThemeIndex]].Alpha := (BarGolden_EaseOut_Step / 100); - // line bonus - Text[TextLineBonusScore[ThemeIndex]].Text := IntToStr(TextPhrase_ActualValue[PlayerNumber]); - Text[TextLineBonusScore[ThemeIndex]].Alpha := (BarPhrase_EaseOut_Step / 100); + Statics[StaticBoxLightest[ThemeIndex]].Texture.Alpha := (BarGolden_EaseOut_Step / 100); + Text[TextGoldenNotes[ThemeIndex]].Alpha := (BarGolden_EaseOut_Step / 100); - Static[StaticBoxLight[ThemeIndex]].Texture.Alpha := (BarPhrase_EaseOut_Step / 100); - Text[TextLineBonus[ThemeIndex]].Alpha := (BarPhrase_EaseOut_Step / 100); + // line bonus + Text[TextLineBonusScore[ThemeIndex]].Text := IntToStr(TextPhrase_ActualValue[PlayerNumber]); + Text[TextLineBonusScore[ThemeIndex]].Alpha := (BarPhrase_EaseOut_Step / 100); - // plain score - Text[TextNotesScore[ThemeIndex]].Text := IntToStr(TextScore_ActualValue[PlayerNumber]); - Text[TextNotes[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); + Statics[StaticBoxLight[ThemeIndex]].Texture.Alpha := (BarPhrase_EaseOut_Step / 100); + Text[TextLineBonus[ThemeIndex]].Alpha := (BarPhrase_EaseOut_Step / 100); - Static[StaticBoxDark[ThemeIndex]].Texture.Alpha := (BarScore_EaseOut_Step / 100); - Text[TextNotesScore[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); + // plain score + Text[TextNotesScore[ThemeIndex]].Text := IntToStr(TextScore_ActualValue[PlayerNumber]); + Text[TextNotes[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); - // total score - Text[TextTotalScore[ThemeIndex]].Text := IntToStr(TextScore_ActualValue[PlayerNumber] + TextPhrase_ActualValue[PlayerNumber] + TextGolden_ActualValue[PlayerNumber]); - Text[TextTotalScore[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); + Statics[StaticBoxDark[ThemeIndex]].Texture.Alpha := (BarScore_EaseOut_Step / 100); + Text[TextNotesScore[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); - Text[TextTotal[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); + // total score + Text[TextTotalScore[ThemeIndex]].Text := IntToStr(TextScore_ActualValue[PlayerNumber] + TextPhrase_ActualValue[PlayerNumber] + TextGolden_ActualValue[PlayerNumber]); + Text[TextTotalScore[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); - Text[TextTotal[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); + Text[TextTotal[ThemeIndex]].Alpha := (BarScore_EaseOut_Step / 100); - if(BarGolden_EaseOut_Step = 100) then - begin - ShowRating(PlayerNumber); + if(BarGolden_EaseOut_Step = 100) then + begin + ShowRating(PlayerNumber); + end; end; end; @@ -564,68 +834,63 @@ var Rating: integer; ThemeIndex: integer; begin + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; + if (ThemeIndex > 0) and ((ScreenAct = PlayerPositionMap[PlayerNumber-1].Screen) or (PlayerPositionMap[PlayerNumber-1].BothScreens)) then + begin + case (Player[PlayerNumber-1].ScoreTotalInt) of + 0..2009: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_TONE_DEAF'); + Rating := 0; + end; + 2010..4009: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_AMATEUR'); + Rating := 1; + end; + 4010..5009: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_WANNABE'); + Rating := 2; + end; + 5010..6009: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_HOPEFUL'); + Rating := 3; + end; + 6010..7509: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_RISING_STAR'); + Rating := 4; + end; + 7510..8509: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_LEAD_SINGER'); + Rating := 5; + end; + 8510..9009: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_SUPERSTAR'); + Rating := 6; + end; + 9010..10000: + begin + Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_ULTRASTAR'); + Rating := 7; + end; + else + Rating := 0; // Cheata :P + end; - // We have to do this here because we use the same Theme Object - // for players on the first and second screen - case PlayersPlay of - 1, 2, 3: ThemeIndex := PlayerNumber + ArrayStartModifier; - 4: ThemeIndex := ((PlayerNumber-1) mod 2) + 1 + ArrayStartModifier; - 6: ThemeIndex := ((PlayerNumber-1) mod 3) + 1 + ArrayStartModifier; - end; - - case (Player[PlayerNumber-1].ScoreTotalInt) of - 0..2009: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_TONE_DEAF'); - Rating := 0; - end; - 2010..4009: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_AMATEUR'); - Rating := 1; - end; - 4010..5009: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_WANNABE'); - Rating := 2; - end; - 5010..6009: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_HOPEFUL'); - Rating := 3; - end; - 6010..7509: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_RISING_STAR'); - Rating := 4; - end; - 7510..8509: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_LEAD_SINGER'); - Rating := 5; - end; - 8510..9009: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_SUPERSTAR'); - Rating := 6; - end; - 9010..10000: - begin - Text[TextScore[ThemeIndex]].Text := Language.Translate('SING_SCORE_ULTRASTAR'); - Rating := 7; - end; - else - Rating := 0; // Cheata :P - end; + //todo: this could break if the width is not given, for instance when there's a skin with no picture for ratings + if ( Theme.Score.StaticRatings[ThemeIndex].W > 0 ) and ( aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue > 0 ) then + begin + Text[TextScore[ThemeIndex]].Alpha := aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue / Theme.Score.StaticRatings[ThemeIndex].W; + end; + // end todo - //todo: this could break if the width is not given, for instance when there's a skin with no picture for ratings - if ( Theme.Score.StaticRatings[ThemeIndex].W > 0 ) and ( aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue > 0 ) then - begin - Text[TextScore[ThemeIndex]].Alpha := aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue / Theme.Score.StaticRatings[ThemeIndex].W; + DrawRating(PlayerNumber, Rating); end; - // end todo - - DrawRating(PlayerNumber, Rating); end; procedure TscreenScore.DrawRating(PlayerNumber: integer; Rating: integer); @@ -633,12 +898,12 @@ var Posx: real; Posy: real; Width: real; + ThemeIndex: integer; begin + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; - CalculateBouncing(PlayerNumber); - - PosX := Theme.Score.StaticRatings[PlayerNumber + ArrayStartModifier].X + (Theme.Score.StaticRatings[PlayerNumber + ArrayStartModifier].W * 0.5); - PosY := Theme.Score.StaticRatings[PlayerNumber + ArrayStartModifier].Y + (Theme.Score.StaticRatings[PlayerNumber + ArrayStartModifier].H * 0.5); ; + PosX := Theme.Score.StaticRatings[ThemeIndex].X + (Theme.Score.StaticRatings[ThemeIndex].W * 0.5); + PosY := Theme.Score.StaticRatings[ThemeIndex].Y + (Theme.Score.StaticRatings[ThemeIndex].H * 0.5); ; Width := aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue/2; @@ -661,14 +926,16 @@ end; function TscreenScore.CalculateBouncing(PlayerNumber: integer): real; var - ReturnValue: real; p, s: real; RaiseStep, MaxVal: real; EaseOut_Step: integer; + ThemeIndex: integer; begin + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; + EaseOut_Step := aPlayerScoreScreenRatings[PlayerNumber].RateEaseStep; - MaxVal := Theme.Score.StaticRatings[PlayerNumber + ArrayStartModifier].W; + MaxVal := Theme.Score.StaticRatings[ThemeIndex].W; RaiseStep := EaseOut_Step; @@ -677,23 +944,21 @@ begin if (RaiseStep = 1) then begin - ReturnValue := MaxVal; + Result := MaxVal; end else begin p := MaxVal * 0.4; s := p/(2*PI) * arcsin (1); - ReturnValue := MaxVal * power(2,-5 * RaiseStep) * sin( (RaiseStep * MaxVal - s) * (2 * PI) / p) + MaxVal; + Result := MaxVal * power(2,-5 * RaiseStep) * sin( (RaiseStep * MaxVal - s) * (2 * PI) / p) + MaxVal; inc(aPlayerScoreScreenRatings[PlayerNumber].RateEaseStep); - aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue := ReturnValue; + aPlayerScoreScreenRatings[PlayerNumber].RateEaseValue := Result; end; - - Result := ReturnValue; end; -procedure TscreenScore.EaseBarIn(PlayerNumber: integer; BarType: string); +procedure TscreenScore.EaseBarIn(PlayerNumber: integer; BarType: TScoreBarType); const RaiseSmoothness: integer = 100; var @@ -706,34 +971,31 @@ var lTmp: real; Score: integer; + ThemeIndex: integer; begin - MaxHeight := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].H; + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; + MaxHeight := Theme.Score.StaticBackLevel[ThemeIndex].H; // let's get the points according to the bar we draw // score array starts at 0, which means the score for player 1 is in score[0] // EaseOut_Step is the actual step in the raising process, like the 20iest step of EaseOut_MaxSteps - if (BarType = 'Note') then + if (BarType = sbtScore) then begin Score := Player[PlayerNumber - 1].ScoreInt; RaiseStep := BarScore_EaseOut_Step; - BarStartPosY := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].Y + MaxHeight; + BarStartPosY := Theme.Score.StaticBackLevel[ThemeIndex].Y + MaxHeight; end - else if (BarType = 'Line') then + else if (BarType = sbtLine) then begin Score := Player[PlayerNumber - 1].ScoreLineInt; RaiseStep := BarPhrase_EaseOut_Step; - BarStartPosY := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].Y - aPlayerScoreScreenDatas[PlayerNumber].BarScore_ActualHeight + MaxHeight; + BarStartPosY := Theme.Score.StaticBackLevel[ThemeIndex].Y - aPlayerScoreScreenDatas[PlayerNumber].BarScore_ActualHeight + MaxHeight; end - else if (BarType = 'Golden') then + else if (BarType = sbtGolden) then begin Score := Player[PlayerNumber - 1].ScoreGoldenInt; RaiseStep := BarGolden_EaseOut_Step; - BarStartPosY := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].Y - aPlayerScoreScreenDatas[PlayerNumber].BarScore_ActualHeight - aPlayerScoreScreenDatas[PlayerNumber].BarLine_ActualHeight + MaxHeight; - end - else - begin - Log.LogCritical('Unknown bar-type: ' + BarType, 'TScreenScore.EaseBarIn'); - Exit; // suppress warnings + BarStartPosY := Theme.Score.StaticBackLevel[ThemeIndex].Y - aPlayerScoreScreenDatas[PlayerNumber].BarScore_ActualHeight - aPlayerScoreScreenDatas[PlayerNumber].BarLine_ActualHeight + MaxHeight; end; // the height dependend of the score @@ -758,31 +1020,34 @@ begin DrawBar(BarType, PlayerNumber, BarStartPosY, NewHeight); - if (BarType = 'Note') then + if (BarType = sbtScore) then aPlayerScoreScreenDatas[PlayerNumber].BarScore_ActualHeight := NewHeight - else if (BarType = 'Line') then + else if (BarType = sbtLine) then aPlayerScoreScreenDatas[PlayerNumber].BarLine_ActualHeight := NewHeight - else if (BarType = 'Golden') then + else if (BarType = sbtGolden) then aPlayerScoreScreenDatas[PlayerNumber].BarGolden_ActualHeight := NewHeight; end; -procedure TscreenScore.DrawBar(BarType: string; PlayerNumber: integer; BarStartPosY: single; NewHeight: real); +procedure TscreenScore.DrawBar(BarType: TScoreBarType; PlayerNumber: integer; BarStartPosY: single; NewHeight: real); var Width: real; BarStartPosX: real; + ThemeIndex: integer; begin + ThemeIndex := PlayerPositionMap[PlayerNumber-1].Position; + // this is solely for better readability of the drawing - Width := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].W; - BarStartPosX := Theme.Score.StaticBackLevel[PlayerNumber + ArrayStartModifier].X; + Width := Theme.Score.StaticBackLevel[ThemeIndex].W; + BarStartPosX := Theme.Score.StaticBackLevel[ThemeIndex].X; glColor4f(1, 1, 1, 1); // set the texture for the bar - if (BarType = 'Note') then + if (BarType = sbtScore) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarLevel_Dark.TexNum); - if (BarType = 'Line') then + if (BarType = sbtLine) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarLevel_Light.TexNum); - if (BarType = 'Golden') then + if (BarType = sbtGolden) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarLevel_Lightest.TexNum); //draw it @@ -801,11 +1066,11 @@ begin glDisable(GL_TEXTURE_2d); //the round thing on top - if (BarType = 'Note') then + if (BarType = sbtScore) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarRound_Dark.TexNum); - if (BarType = 'Line') then + if (BarType = sbtLine) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarRound_Light.TexNum); - if (BarType = 'Golden') then + if (BarType = sbtGolden) then glBindTexture(GL_TEXTURE_2D, aPlayerScoreScreenTextures[PlayerNumber].Score_NoteBarRound_Lightest.TexNum); glEnable(GL_TEXTURE_2D); @@ -813,8 +1078,8 @@ begin glEnable(GL_BLEND); glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex3f(BarStartPosX, (BarStartPosY - Static[StaticLevelRound[PlayerNumber + ArrayStartModifier]].Texture.h) - NewHeight, ZBars); - glTexCoord2f(1, 0); glVertex3f(BarStartPosX + Width, (BarStartPosY - Static[StaticLevelRound[PlayerNumber + ArrayStartModifier]].Texture.h) - NewHeight, ZBars); + glTexCoord2f(0, 0); glVertex3f(BarStartPosX, (BarStartPosY - Statics[StaticLevelRound[ThemeIndex]].Texture.h) - NewHeight, ZBars); + glTexCoord2f(1, 0); glVertex3f(BarStartPosX + Width, (BarStartPosY - Statics[StaticLevelRound[ThemeIndex]].Texture.h) - NewHeight, ZBars); glTexCoord2f(1, 1); glVertex3f(BarStartPosX + Width, BarStartPosY - NewHeight, ZBars); glTexCoord2f(0, 1); glVertex3f(BarStartPosX, BarStartPosY - NewHeight, ZBars); glEnd; @@ -823,7 +1088,7 @@ begin glDisable(GL_TEXTURE_2d); end; -procedure TScreenScore.EaseScoreIn(PlayerNumber: integer; ScoreType: string); +procedure TScreenScore.EaseScoreIn(PlayerNumber: integer; ScoreType: TScoreBarType); const RaiseSmoothness: integer = 100; var @@ -833,19 +1098,19 @@ var EaseOut_Step: real; ActualScoreValue: integer; begin - if (ScoreType = 'Note') then + if (ScoreType = sbtScore) then begin EaseOut_Step := BarScore_EaseOut_Step; ActualScoreValue := TextScore_ActualValue[PlayerNumber]; ScoreReached := Player[PlayerNumber-1].ScoreInt; end; - if (ScoreType = 'Line') then + if (ScoreType = sbtLine) then begin EaseOut_Step := BarPhrase_EaseOut_Step; ActualScoreValue := TextPhrase_ActualValue[PlayerNumber]; ScoreReached := Player[PlayerNumber-1].ScoreLineInt; end; - if (ScoreType = 'Golden') then + if (ScoreType = sbtGolden) then begin EaseOut_Step := BarGolden_EaseOut_Step; ActualScoreValue := TextGolden_ActualValue[PlayerNumber]; @@ -866,21 +1131,21 @@ begin if ( lTmpA > 0 ) and ( RaiseSmoothness > 0 ) then begin - if (ScoreType = 'Note') then + if (ScoreType = sbtScore) then TextScore_ActualValue[PlayerNumber] := floor( lTmpA / RaiseSmoothness); - if (ScoreType = 'Line') then + if (ScoreType = sbtLine) then TextPhrase_ActualValue[PlayerNumber] := floor( lTmpA / RaiseSmoothness); - if (ScoreType = 'Golden') then + if (ScoreType = sbtGolden) then TextGolden_ActualValue[PlayerNumber] := floor( lTmpA / RaiseSmoothness); end; end else begin - if (ScoreType = 'Note') then + if (ScoreType = sbtScore) then TextScore_ActualValue[PlayerNumber] := ScoreReached; - if (ScoreType = 'Line') then + if (ScoreType = sbtLine) then TextPhrase_ActualValue[PlayerNumber] := ScoreReached; - if (ScoreType = 'Golden') then + if (ScoreType = sbtGolden) then TextGolden_ActualValue[PlayerNumber] := ScoreReached; end; end; diff --git a/cmake/src/screens/UScreenSing.pas b/cmake/src/screens/UScreenSing.pas index ae75c74d..233f1e38 100644 --- a/cmake/src/screens/UScreenSing.pas +++ b/cmake/src/screens/UScreenSing.pas @@ -35,9 +35,9 @@ interface uses SysUtils, - gl, SDL, TextGL, + gl, UFiles, UGraphicClasses, UIni, @@ -49,19 +49,30 @@ uses USongs, UTexture, UThemes, - UTime; + UPath, + UTime, + UHookableEvent; type TLyricsSyncSource = class(TSyncSource) function GetClock(): real; override; end; + TMusicSyncSource = class(TSyncSource) + function GetClock(): real; override; + end; + type TScreenSing = class(TMenu) + private + fShowVisualization: boolean; + fCurrentVideo: IVideo; + fVideoClip: IVideo; + fLyricsSync: TLyricsSyncSource; + fMusicSync: TMusicSyncSource; protected - VideoLoaded: boolean; - Paused: boolean; // pause mod - LyricsSync: TLyricsSyncSource; + eSongLoaded: THookableEvent; //< event is called after lyrics of a song are loaded on OnShow + Paused: boolean; //pause Mod NumEmptySentences: integer; public // timebar fields @@ -97,15 +108,28 @@ type // score manager: Scores: TSingScores; - fShowVisualization: boolean; - fCurrentVideoPlaybackEngine: IVideoPlayback; + //the song was sung to the end + SungToEnd: boolean; + + // some settings to be set by plugins + Settings: record + Finish: Boolean; //< if true, screen will finish on next draw + + LyricsVisible: Boolean; //< shows or hides lyrics + NotesVisible: Integer; //< if bit[playernum] is set the notes for the specified player are visible. By default all players notes are visible + + PlayerEnabled: Integer; //< defines whether a player can score atm + end; + procedure ClearSettings; + procedure ApplySettings; //< applies changes of settings record + procedure EndSong; constructor Create; override; - procedure onShow; override; - procedure onShowFinish; override; - procedure onHide; override; + procedure OnShow; override; + procedure OnShowFinish; override; + procedure OnHide; override; - function ParseInput(PressedKey: cardinal; CharCode: widechar; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; function Draw: boolean; override; @@ -127,20 +151,22 @@ uses UNote, URecord, USong, - UDisplay; + UDisplay, + UParty, + UUnicodeUtils; // method for input parsing. if false is returned, getnextwindow // should be checked to know the next window to load; -function TScreenSing.ParseInput(PressedKey: cardinal; CharCode: widechar; +function TScreenSing.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // key down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin // when not ask before exit then finish now if (Ini.AskbeforeDel <> 1) then @@ -152,21 +178,22 @@ begin Result := false; Exit; end; - 'V': // show visualization + Ord('V'): // show visualization begin fShowVisualization := not fShowVisualization; if fShowVisualization then - fCurrentVideoPlaybackEngine := Visualization + begin + fCurrentVideo := Visualization.Open(PATH_NONE); + fCurrentVideo.play; + end else - fCurrentVideoPlaybackEngine := VideoPlayback; - - if fShowVisualization then - fCurrentVideoPlaybackEngine.play; - + begin + fCurrentVideo := fVideoClip; + end; Exit; end; - 'P': + Ord('P'): begin Pause; Exit; @@ -194,7 +221,7 @@ begin SDLK_TAB: // change visualization preset begin if fShowVisualization then - fCurrentVideoPlaybackEngine.Position := now; // move to a random position + fCurrentVideo.Position := now; // move to a random position end; SDLK_RETURN: @@ -228,22 +255,20 @@ begin AudioPlayback.Pause; // pause video - if (CurrentSong.Video <> '') and FileExists(CurrentSong.Path + - CurrentSong.Video) then - fCurrentVideoPlaybackEngine.Pause; + if (fCurrentVideo <> nil) then + fCurrentVideo.Pause; end else // disable pause begin - LyricsState.Resume(); + LyricsState.Start(); // play music AudioPlayback.Play; // video - if (CurrentSong.Video <> '') and FileExists(CurrentSong.Path + - CurrentSong.Video) then - fCurrentVideoPlaybackEngine.Pause; + if (fCurrentVideo <> nil) then + fCurrentVideo.Pause; Paused := false; end; @@ -259,7 +284,7 @@ begin fShowVisualization := false; - fCurrentVideoPlaybackEngine := VideoPlayback; + fCurrentVideo := nil; // create score class Scores := TSingScores.Create; @@ -298,16 +323,21 @@ begin StaticPausePopup := AddStatic(Theme.Sing.PausePopUp); // pausepopup is not visibile at the beginning - Static[StaticPausePopup].Visible := false; + Statics[StaticPausePopup].Visible := false; Lyrics := TLyricEngine.Create( Theme.LyricBar.UpperX, Theme.LyricBar.UpperY, Theme.LyricBar.UpperW, Theme.LyricBar.UpperH, Theme.LyricBar.LowerX, Theme.LyricBar.LowerY, Theme.LyricBar.LowerW, Theme.LyricBar.LowerH); - LyricsSync := TLyricsSyncSource.Create(); + fLyricsSync := TLyricsSyncSource.Create(); + fMusicSync := TMusicSyncSource.Create(); + + eSongLoaded := THookableEvent.Create('ScreenSing.SongLoaded'); + + ClearSettings; end; -procedure TScreenSing.onShow; +procedure TScreenSing.OnShow; var Index: integer; V1: boolean; @@ -317,16 +347,21 @@ var V2M: boolean; V3R: boolean; Color: TRGB; - + VideoFile, BgFile: IPath; success: boolean; begin inherited; - Log.LogStatus('Begin', 'onShow'); + Log.LogStatus('Begin', 'OnShow'); FadeOut := false; - // reset video playback engine, to play video clip ... - fCurrentVideoPlaybackEngine := VideoPlayback; + //the song was sung to the end + SungToEnd := false; + ClearSettings; + Party.CallBeforeSing; + + // reset video playback engine + fCurrentVideo := nil; // setup score manager Scores.ClearPlayers; // clear old player values @@ -395,24 +430,24 @@ begin end; // this one is shown in 1P mode - Static[StaticP1].Visible := V1; + Statics[StaticP1].Visible := V1; Text[TextP1].Visible := V1; // this one is shown in 2/4P mode - Static[StaticP1TwoP].Visible := V1TwoP; + Statics[StaticP1TwoP].Visible := V1TwoP; Text[TextP1TwoP].Visible := V1TwoP; - Static[StaticP2R].Visible := V2R; + Statics[StaticP2R].Visible := V2R; Text[TextP2R].Visible := V2R; // this one is shown in 3/6P mode - Static[StaticP1ThreeP].Visible := V1ThreeP; + Statics[StaticP1ThreeP].Visible := V1ThreeP; Text[TextP1ThreeP].Visible := V1ThreeP; - Static[StaticP2M].Visible := V2M; + Statics[StaticP2M].Visible := V2M; Text[TextP2M].Visible := V2M; - Static[StaticP3R].Visible := V3R; + Statics[StaticP3R].Visible := V3R; Text[TextP3R].Visible := V3R; // FIXME: sets path and filename to '' @@ -423,7 +458,7 @@ begin // FIXME: bad style, put the try-except into loadsong() and not here try // check if file is xml - if copy(CurrentSong.FileName, length(CurrentSong.FileName) - 3, 4) = '.xml' then + if CurrentSong.FileName.GetExtension.ToUTF8 = '.xml' then success := CurrentSong.LoadXMLSong() else success := CurrentSong.LoadSong(); @@ -433,8 +468,8 @@ begin if (not success) then begin - // error loading song -> go back to song screen and show some error message - FadeTo(@ScreenSong); + // error loading song -> go back to previous screen and show some error message + Display.AbortScreenChange; // select new song in party mode if ScreenSong.Mode = smPartyMode then ScreenSong.SelectRandomSong(); @@ -447,10 +482,6 @@ begin Exit; end; - // reset video playback engine, to play video clip ... - fCurrentVideoPlaybackEngine.Close; - fCurrentVideoPlaybackEngine := VideoPlayback; - {* * == Background == * We have four types of backgrounds: @@ -465,32 +496,34 @@ begin {* * set background to: video *} - VideoLoaded := false; fShowVisualization := false; - if (CurrentSong.Video <> '') and FileExists(CurrentSong.Path + CurrentSong.Video) then + VideoFile := CurrentSong.Path.Append(CurrentSong.Video); + if (CurrentSong.Video.IsSet) and VideoFile.IsFile then begin - if (fCurrentVideoPlaybackEngine.Open(CurrentSong.Path + CurrentSong.Video)) then + fVideoClip := VideoPlayback.Open(VideoFile); + fCurrentVideo := fVideoClip; + if (fVideoClip <> nil) then begin fShowVisualization := false; - fCurrentVideoPlaybackEngine := VideoPlayback; - fCurrentVideoPlaybackEngine.Position := CurrentSong.VideoGAP + CurrentSong.Start; - fCurrentVideoPlaybackEngine.Play; - VideoLoaded := true; + fCurrentVideo.Position := CurrentSong.VideoGAP + CurrentSong.Start; + fCurrentVideo.Play; end; end; {* * set background to: picture *} - if (CurrentSong.Background <> '') and (VideoLoaded = false) + if (CurrentSong.Background.IsSet) and (fVideoClip = nil) and (TVisualizerOption(Ini.VisualizerOption) = voOff) then + begin + BgFile := CurrentSong.Path.Append(CurrentSong.Background); try - Tex_Background := Texture.LoadTexture(CurrentSong.Path + CurrentSong.Background); + Tex_Background := Texture.LoadTexture(BgFile); except - Log.LogError('Background could not be loaded: ' + CurrentSong.Path + - CurrentSong.Background); + Log.LogError('Background could not be loaded: ' + BgFile.ToNative); Tex_Background.TexNum := 0; end + end else begin Tex_Background.TexNum := 0; @@ -502,21 +535,21 @@ begin if (TVisualizerOption(Ini.VisualizerOption) in [voOn]) then begin fShowVisualization := true; - fCurrentVideoPlaybackEngine := Visualization; - if (fCurrentVideoPlaybackEngine <> nil) then - fCurrentVideoPlaybackEngine.Play; + fCurrentVideo := Visualization.Open(PATH_NONE); + if (fCurrentVideo <> nil) then + fCurrentVideo.Play; end; {* * set background to: visualization (Videos are still shown) *} if ((TVisualizerOption(Ini.VisualizerOption) in [voWhenNoVideo]) and - (VideoLoaded = false)) then + (fVideoClip = nil)) then begin fShowVisualization := true; - fCurrentVideoPlaybackEngine := Visualization; - if (fCurrentVideoPlaybackEngine <> nil) then - fCurrentVideoPlaybackEngine.Play; + fCurrentVideo := Visualization.Open(PATH_NONE); + if (fCurrentVideo <> nil) then + fCurrentVideo.Play; end; // prepare lyrics timer @@ -529,12 +562,6 @@ begin LyricsState.TotalTime := AudioPlayback.Length; LyricsState.UpdateBeats(); - // prepare music - AudioPlayback.Stop(); - AudioPlayback.Position := CurrentSong.Start; - // synchronize music to the lyrics - AudioPlayback.SetSyncSource(LyricsSync); - // prepare and start voice-capture AudioInput.CaptureStart; @@ -564,7 +591,7 @@ begin case Ini.LyricsFont of 0: // normal fonts begin - Lyrics.FontStyle := 0; + Lyrics.FontStyle := ftNormal; Lyrics.LineColor_en.R := Skin_FontR; Lyrics.LineColor_en.G := Skin_FontG; @@ -581,9 +608,12 @@ begin Lyrics.LineColor_act.B := 0.8; Lyrics.LineColor_act.A := 1; end; - 1, 2: // outline fonts (is TScalableOutlineFont) + 1, 2: // outline fonts begin - Lyrics.FontStyle := Ini.LyricsFont + 1; + if (Ini.LyricsFont = 1) then + Lyrics.FontStyle := ftOutline1 + else + Lyrics.FontStyle := ftOutline2; Lyrics.LineColor_en.R := 0.75; Lyrics.LineColor_en.G := 0.75; @@ -622,16 +652,37 @@ begin if Lines[0].Line[Index].TotalNotes = 0 then Inc(NumEmptySentences); - Log.LogStatus('End', 'onShow'); + eSongLoaded.CallHookChain(False); + + Log.LogStatus('End', 'OnShow'); end; procedure TScreenSing.onShowFinish; begin // hide cursor on singscreen show Display.SetCursor; - + + // prepare music + // Important: AudioPlayback must not be initialized in onShow() as TScreenSong + // uses stops AudioPlayback in onHide() which interferes with TScreenSings onShow. + AudioPlayback.Open(CurrentSong.Path.Append(CurrentSong.Mp3)); + AudioPlayback.SetVolume(1.0); + AudioPlayback.Position := CurrentSong.Start; + + // synchronize music + if (Ini.SyncTo = Ord(stLyrics)) then + AudioPlayback.SetSyncSource(fLyricsSync) + else + AudioPlayback.SetSyncSource(nil); + + // synchronize lyrics (do not set this before AudioPlayback is initialized) + if (Ini.SyncTo = Ord(stMusic)) then + LyricsState.SetSyncSource(fMusicSync) + else + LyricsState.SetSyncSource(nil); + // start lyrics - LyricsState.Resume(); + LyricsState.Start(true); // start music AudioPlayback.Play(); @@ -640,7 +691,26 @@ begin CountSkipTimeSet; end; -procedure TScreenSing.onHide; +procedure TScreenSing.ClearSettings; +begin + Settings.Finish := False; + Settings.LyricsVisible := True; + Settings.NotesVisible := high(Integer); + Settings.PlayerEnabled := high(Integer); +end; + +{ applies changes of settings record } +procedure TScreenSing.ApplySettings; +begin + // +end; + +procedure TScreenSing.EndSong; +begin + Settings.Finish := True; +end; + +procedure TScreenSing.OnHide; begin // background texture if (Tex_Background.TexNum > 0) then @@ -659,6 +729,9 @@ var Sec: integer; T: integer; CurLyricsTime: real; + VideoFrameTime: Extended; + Line: TLyricLine; + LastWord: TLyricWord; begin Background.Draw; @@ -704,23 +777,23 @@ begin // will move the statics and texts to the correct screen here. // FIXME: clean up this weird stuff. Commenting this stuff out, nothing // was missing on screen w/ 6 players - so do we even need this stuff? - {Static[StaticP1].Texture.X := Static[StaticP1].Texture.X + 10 * ScreenX; + {Statics[StaticP1].Texture.X := Statics[StaticP1].Texture.X + 10 * ScreenX; Text[TextP1].X := Text[TextP1].X + 10 * ScreenX; } - {Static[StaticP1ScoreBG].Texture.X := Static[StaticP1ScoreBG].Texture.X + 10*ScreenX; + {Statics[StaticP1ScoreBG].Texture.X := Statics[StaticP1ScoreBG].Texture.X + 10*ScreenX; Text[TextP1Score].X := Text[TextP1Score].X + 10*ScreenX;} - {Static[StaticP2R].Texture.X := Static[StaticP2R].Texture.X + 10 * ScreenX; + {Statics[StaticP2R].Texture.X := Statics[StaticP2R].Texture.X + 10 * ScreenX; Text[TextP2R].X := Text[TextP2R].X + 10 * ScreenX; } - {Static[StaticP2RScoreBG].Texture.X := Static[StaticP2RScoreBG].Texture.X + 10*ScreenX; + {Statics[StaticP2RScoreBG].Texture.X := Statics[StaticP2RScoreBG].Texture.X + 10*ScreenX; Text[TextP2RScore].X := Text[TextP2RScore].X + 10*ScreenX;} // end of weird stuff { - Static[1].Texture.X := Static[1].Texture.X + 10 * ScreenX; } + Statics[1].Texture.X := Statics[1].Texture.X + 10 * ScreenX; } { for T := 0 to 1 do Text[T].X := Text[T].X + 10 * ScreenX; } @@ -744,18 +817,37 @@ begin // Note: there is no menu and the animated background brakes the video playback //DrawBG; + //the song was sung to the end? + Line := Lyrics.GetUpperLine(); + if Line.LastLine then + begin + LastWord := Line.Words[Length(Line.Words)-1]; + if CurLyricsTime >= GetTimeFromBeat(LastWord.Start+LastWord.Length) then + SungToEnd := true; + end; + // update and draw movie - if (ShowFinish and (VideoLoaded or fShowVisualization)) then + if Assigned(fCurrentVideo) then begin - if assigned(fCurrentVideoPlaybackEngine) then + // Just call this once + // when Screens = 2 + if (ScreenAct = 1) then begin - // Just call this once - // when Screens = 2 - if (ScreenAct = 1) then - fCurrentVideoPlaybackEngine.GetFrame(CurrentSong.VideoGAP + LyricsState.GetCurrentTime()); - - fCurrentVideoPlaybackEngine.DrawGL(ScreenAct); + if (ShowFinish) then + begin + // everything is setup, determine the current position + VideoFrameTime := CurrentSong.VideoGAP + LyricsState.GetCurrentTime(); + end + else + begin + // Important: do not yet start the triggered timer by a call to + // LyricsState.GetCurrentTime() + VideoFrameTime := CurrentSong.VideoGAP; + end; + fCurrentVideo.GetFrame(VideoFrameTime); end; + + fCurrentVideo.DrawGL(ScreenAct); end; // draw static menu (FG) @@ -766,11 +858,14 @@ begin if ShowFinish then begin if (not AudioPlayback.Finished) and ((CurrentSong.Finish = 0) or - (LyricsState.GetCurrentTime() * 1000 <= CurrentSong.Finish)) then + (LyricsState.GetCurrentTime() * 1000 <= CurrentSong.Finish)) and (not Settings.Finish) then begin // analyze song if not paused if (not Paused) then + begin Sing(Self); + Party.CallOnSing; + end; end else begin @@ -778,7 +873,6 @@ begin begin Finish; FadeOut := true; - FadeTo(@ScreenScore); end; end; end; @@ -800,15 +894,15 @@ begin // will move the statics and texts to the correct screen here. // FIXME: clean up this weird stuff - {Static[StaticP1].Texture.X := Static[StaticP1].Texture.X - 10 * ScreenX; + {Statics[StaticP1].Texture.X := Statics[StaticP1].Texture.X - 10 * ScreenX; Text[TextP1].X := Text[TextP1].X - 10 * ScreenX; - Static[StaticP2R].Texture.X := Static[StaticP2R].Texture.X - 10 * ScreenX; + Statics[StaticP2R].Texture.X := Statics[StaticP2R].Texture.X - 10 * ScreenX; Text[TextP2R].X := Text[TextP2R].X - 10 * ScreenX; // end of weird - Static[1].Texture.X := Static[1].Texture.X - 10 * ScreenX; + Statics[1].Texture.X := Statics[1].Texture.X - 10 * ScreenX; for T := 0 to 1 do Text[T].X := Text[T].X - 10 * ScreenX; } @@ -818,9 +912,9 @@ begin // maybe someone could find a better solution if Paused then begin - Static[StaticPausePopup].Visible := true; - Static[StaticPausePopup].Draw; - Static[StaticPausePopup].Visible := false; + Statics[StaticPausePopup].Visible := true; + Statics[StaticPausePopup].Draw; + Statics[StaticPausePopup].Visible := false; end; Result := true; @@ -832,14 +926,12 @@ begin AudioPlayback.Stop; AudioPlayback.SetSyncSource(nil); - if (VideoPlayback <> nil) then - VideoPlayback.Close; + LyricsState.Stop(); + LyricsState.SetSyncSource(nil); - if (Visualization <> nil) then - Visualization.Close; - - // to prevent drawing closed video - VideoLoaded := false; + // close video files + fVideoClip := nil; + fCurrentVideo := nil; // kill all stars and effects GoldenRec.KillAll; @@ -855,11 +947,13 @@ begin end; SetFontItalic(false); + + Party.CallAfterSing; end; procedure TScreenSing.OnSentenceEnd(SentenceIndex: cardinal); var - PlayerIndex: integer; + PlayerIndex: byte; CurrentPlayer: PPLayer; CurrentScore: real; Line: PLine; @@ -898,10 +992,14 @@ begin // points for this line LineScore := CurrentScore - CurrentPlayer.ScoreLast; - // determine LinePerfection - // Note: the "+2" extra points are a little bonus so the player does not - // have to be that perfect to reach the bonus steps. - LinePerfection := (LineScore + 2) / MaxLineScore; + // check for lines with low points + if (MaxLineScore <= 2) then + LinePerfection := 1 + else + // determine LinePerfection + // Note: the "+2" extra points are a little bonus so the player does not + // have to be that perfect to reach the bonus steps. + LinePerfection := LineScore / (MaxLineScore - 2); // clamp LinePerfection to range [0..1] if (LinePerfection < 0) then @@ -928,7 +1026,9 @@ begin // spawn rating pop-up Rating := Round(LinePerfection * MAX_LINE_RATING); Scores.SpawnPopUp(PlayerIndex, Rating, CurrentPlayer.ScoreTotalInt); - end; + end + else + Scores.RaiseScore(PlayerIndex, CurrentPlayer.ScoreTotalInt); // PerfectLineTwinkle (effect), part 1 if (Ini.EffectSing = 1) then @@ -967,5 +1067,10 @@ begin Result := LyricsState.GetCurrentTime(); end; +function TMusicSyncSource.GetClock(): real; +begin + Result := AudioPlayback.Position; +end; + end. diff --git a/cmake/src/screens/UScreenSingModi.pas b/cmake/src/screens/UScreenSingModi.pas deleted file mode 100644 index eeb06004..00000000 --- a/cmake/src/screens/UScreenSingModi.pas +++ /dev/null @@ -1,580 +0,0 @@ -{* UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - *} - -unit UScreenSingModi; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -{$I switches.inc} - -uses - UMenu, - UMusic, - SDL, - SysUtils, - UFiles, - UTime, - USongs, - UIni, - ULog, - UTexture, - ULyrics, - TextGL, - gl, - - UThemes, - UScreenSing, - ModiSDK; - -type - TScreenSingModi = class(TScreenSing) - protected - - public - Winner: byte; //Who Wins - PlayerInfo: TPlayerInfo; - TeamInfo: TTeamInfo; - - constructor Create; override; - procedure onShow; override; - //procedure onShowFinish; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - function Draw: boolean; override; - procedure Finish; override; - end; - -type - TCustomSoundEntry = record - Filename : string; - Stream : TAudioPlaybackStream; - end; - -var - //Custom Sounds - CustomSounds: array of TCustomSoundEntry; - -//Procedured for Plugin -function LoadTex(const Name: PChar; Typ: TTextureType): TsmallTexture; - {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} -//function Translate (const Name: PChar): PChar; -// {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} -//Procedure to Print Text -procedure Print(const Style, Size: byte; const X, Y: real; const Text: PChar); - {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} -//Procedure that loads a Custom Sound -function LoadSound(const Name: PChar): cardinal; - {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} -//Plays a Custom Sound -procedure PlaySound(const Index: cardinal); - {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} - -//Utilys -function ToSentences(Const Lines: TLines): TSentences; - -implementation - -uses - Classes, - Math, - UDLLManager, - UDraw, - UGraphic, - UGraphicClasses, - ULanguage, - UNote, - UPath, - URecord, - USkins; - -// Method for input parsing. If false is returned, GetNextWindow -// should be checked to know the next window to load; -function TScreenSingModi.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; -begin - Result := true; - if (PressedDown) then - begin // Key Down - case PressedKey of - - SDLK_ESCAPE, - SDLK_BACKSPACE : - begin - Finish; - AudioPlayback.PlaySound(SoundLib.Back); - FadeTo(@ScreenPartyScore); - end; - - else - Result := inherited ParseInput(PressedKey, CharCode, PressedDown); - end; - end; -end; - -constructor TScreenSingModi.Create; -begin - inherited Create; - -end; - -function ToSentences(Const Lines: TLines): TSentences; -var - I, J: integer; -begin - Result.Current := Lines.Current; - Result.High := Lines.High; - Result.Number := Lines.Number; - Result.Resolution := Lines.Resolution; - Result.NotesGAP := Lines.NotesGAP; - Result.TotalLength := Lines.ScoreValue; - - SetLength(Result.Sentence, Length(Lines.Line)); - for I := low(Result.Sentence) to high(Result.Sentence) do - begin - Result.Sentence[I].Start := Lines.Line[I].Start; - Result.Sentence[I].StartNote := Lines.Line[I].Note[0].Start; - Result.Sentence[I].Lyric := Lines.Line[I].Lyric; - Result.Sentence[I].End_ := Lines.Line[I].End_; - Result.Sentence[I].BaseNote := Lines.Line[I].BaseNote; - Result.Sentence[I].HighNote := Lines.Line[I].HighNote; - Result.Sentence[I].TotalNotes := Lines.Line[I].TotalNotes; - - SetLength(Result.Sentence[I].Note, Length(Lines.Line[I].Note)); - for J := low(Result.Sentence[I].Note) to high(Result.Sentence[I].Note) do - begin - Result.Sentence[I].Note[J].Color := Lines.Line[I].Note[J].Color; - Result.Sentence[I].Note[J].Start := Lines.Line[I].Note[J].Start; - Result.Sentence[I].Note[J].Length := Lines.Line[I].Note[J].Length; - Result.Sentence[I].Note[J].Tone := Lines.Line[I].Note[J].Tone; - //Result.Sentence[I].Note[J].Text := Lines.Line[I].Note[J].Text; - Result.Sentence[I].Note[J].FreeStyle := (Lines.Line[I].Note[J].NoteType = ntFreestyle); - end; - end; -end; - -procedure TScreenSingModi.onShow; -var - I: integer; -begin - inherited; - - PlayersPlay := TeamInfo.NumTeams; - - if DLLMan.Selected.LoadSong then //Start with Song - begin - inherited; - end - else //Start Without Song - begin - AudioInput.CaptureStart; - end; - -//Set Playerinfo - PlayerInfo.NumPlayers := PlayersPlay; - for I := 0 to PlayerInfo.NumPlayers-1 do - begin - PlayerInfo.Playerinfo[I].Name := PChar(Ini.Name[I]); - PlayerInfo.Playerinfo[I].Score := 0; - PlayerInfo.Playerinfo[I].Bar := 50; - PlayerInfo.Playerinfo[I].Enabled := true; - end; - - for I := PlayerInfo.NumPlayers to high(PlayerInfo.Playerinfo) do - begin - PlayerInfo.Playerinfo[I].Score:= 0; - PlayerInfo.Playerinfo[I].Bar := 0; - PlayerInfo.Playerinfo[I].Enabled := false; - end; - - {Case PlayersPlay of - 1: begin - PlayerInfo.Playerinfo[0].PosX := Static[StaticP1ScoreBG].Texture.X; - PlayerInfo.Playerinfo[0].PosY := Static[StaticP1ScoreBG].Texture.Y + Static[StaticP1ScoreBG].Texture.H; - end; - 2,4: begin - PlayerInfo.Playerinfo[0].PosX := Static[StaticP1TwoPScoreBG].Texture.X; - PlayerInfo.Playerinfo[0].PosY := Static[StaticP1TwoPScoreBG].Texture.Y + Static[StaticP1TwoPScoreBG].Texture.H; - PlayerInfo.Playerinfo[2].PosX := Static[StaticP1TwoPScoreBG].Texture.X; - PlayerInfo.Playerinfo[2].PosY := Static[StaticP1TwoPScoreBG].Texture.Y + Static[StaticP1TwoPScoreBG].Texture.H; - PlayerInfo.Playerinfo[1].PosX := Static[StaticP2RScoreBG].Texture.X; - PlayerInfo.Playerinfo[1].PosY := Static[StaticP2RScoreBG].Texture.Y + Static[StaticP2RScoreBG].Texture.H; - PlayerInfo.Playerinfo[3].PosX := Static[StaticP2RScoreBG].Texture.X; - PlayerInfo.Playerinfo[3].PosY := Static[StaticP2RScoreBG].Texture.Y + Static[StaticP2RScoreBG].Texture.H; - end; - 3,6: begin - PlayerInfo.Playerinfo[0].PosX := Static[StaticP1ThreePScoreBG].Texture.X; - PlayerInfo.Playerinfo[0].PosY := Static[StaticP1ThreePScoreBG].Texture.Y + Static[StaticP1ThreePScoreBG].Texture.H; - PlayerInfo.Playerinfo[3].PosX := Static[StaticP1ThreePScoreBG].Texture.X; - PlayerInfo.Playerinfo[3].PosY := Static[StaticP1ThreePScoreBG].Texture.Y + Static[StaticP1ThreePScoreBG].Texture.H; - PlayerInfo.Playerinfo[1].PosX := Static[StaticP2MScoreBG].Texture.X; - PlayerInfo.Playerinfo[1].PosY := Static[StaticP2MScoreBG].Texture.Y + Static[StaticP2MScoreBG].Texture.H; - PlayerInfo.Playerinfo[4].PosX := Static[StaticP2MScoreBG].Texture.X; - PlayerInfo.Playerinfo[4].PosY := Static[StaticP2MScoreBG].Texture.Y + Static[StaticP2MScoreBG].Texture.H; - PlayerInfo.Playerinfo[2].PosX := Static[StaticP3RScoreBG].Texture.X; - PlayerInfo.Playerinfo[2].PosY := Static[StaticP3RScoreBG].Texture.Y + Static[StaticP3RScoreBG].Texture.H; - PlayerInfo.Playerinfo[5].PosX := Static[StaticP3RScoreBG].Texture.X; - PlayerInfo.Playerinfo[5].PosY := Static[StaticP3RScoreBG].Texture.Y + Static[StaticP3RScoreBG].Texture.H; - end; - end; } - - // play music (I) - //Music.CaptureStart; - //Music.MoveTo(AktSong.Start); - - //Init Plugin - if not DLLMan.PluginInit(TeamInfo, PlayerInfo, ToSentences(Lines[0]), LoadTex, Print, LoadSound, PlaySound) then - begin - //Fehler - Log.LogError('Could not Init Plugin'); - Halt; - end; - - // Set Background (Little Workaround, maybe change sometime) - if (DLLMan.Selected.LoadBack) and (DLLMan.Selected.LoadSong) then - ScreenSing.Tex_Background := Tex_Background; - - Winner := 0; - - //Set Score Visibility - Scores.Visible := DLLMan.Selected.ShowScore; - - {if PlayersPlay = 1 then - begin - Text[TextP1Score].Visible := DLLMan.Selected.ShowScore; - Static[StaticP1ScoreBG].Visible := DLLMan.Selected.ShowScore; - end; - - if (PlayersPlay = 2) or (PlayersPlay = 4) then - begin - Text[TextP1TwoPScore].Visible := DLLMan.Selected.ShowScore; - Static[StaticP1TwoPScoreBG].Visible := DLLMan.Selected.ShowScore; - - Text[TextP2RScore].Visible := DLLMan.Selected.ShowScore; - Static[StaticP2RScoreBG].Visible := DLLMan.Selected.ShowScore; - end; - - if (PlayersPlay = 3) or (PlayersPlay = 6) then - begin - Text[TextP1ThreePScore].Visible := DLLMan.Selected.ShowScore; - Static[StaticP1ThreePScoreBG].Visible := DLLMan.Selected.ShowScore; - - Text[TextP2MScore].Visible := DLLMan.Selected.ShowScore; - Static[StaticP2MScoreBG].Visible := DLLMan.Selected.ShowScore; - - Text[TextP3RScore].Visible := DLLMan.Selected.ShowScore; - Static[StaticP3RScoreBG].Visible := DLLMan.Selected.ShowScore; - end; } -end; - -function TScreenSingModi.Draw: boolean; -var - Min: integer; - Sec: integer; - TextStr: string; - S, I: integer; - T: integer; - CurLyricsTime: real; -begin - Result := false; - - //Set Playerinfo - PlayerInfo.NumPlayers := PlayersPlay; - for I := 0 to PlayerInfo.NumPlayers-1 do - begin - PlayerInfo.Playerinfo[I].Name := PChar(Player[I].Name); - if PlayerInfo.Playerinfo[I].Enabled then - begin - if (Player[I].ScoreTotalInt <= MAX_SONG_SCORE) then - PlayerInfo.Playerinfo[I].Score:= Player[I].ScoreTotalInt; - PlayerInfo.Playerinfo[I].Bar := Round(Scores.Players[I].RBPos * 100); - end; - end; - - Background.Draw; - - // draw background picture (if any, and if no visualizations) - // when we don't check for visualizations the visualizations would - // be overdrawn by the picture when {UNDEFINED UseTexture} in UVisualizer - if (DllMan.Selected.LoadSong) and (DllMan.Selected.LoadBack) and (not fShowVisualization) then - SingDrawBackground; - - // set player names (for 2 screens and only Singstar skin) - if ScreenAct = 1 then - begin - Text[TextP1].Text := 'P1'; - Text[TextP1TwoP].Text := 'P1'; // added for ps3 skin - Text[TextP1ThreeP].Text := 'P1'; // added for ps3 skin - Text[TextP2R].Text := 'P2'; - Text[TextP2M].Text := 'P2'; - Text[TextP3R].Text := 'P3'; - end - - Else if ScreenAct = 2 then - begin - case PlayersPlay of - 4: begin - Text[TextP1TwoP].Text := 'P3'; - Text[TextP2R].Text := 'P4'; - end; - 6: begin - Text[TextP1ThreeP].Text := 'P4'; - Text[TextP2M].Text := 'P5'; - Text[TextP3R].Text := 'P6'; - end; - end; // case - end; // if - - // stereo <- and where iss P2M? or P3? - Static[StaticP1].Texture.X := Static[StaticP1].Texture.X + 10*ScreenX; - Text[TextP1].X := Text[TextP1].X + 10*ScreenX; - - {Static[StaticP1ScoreBG].Texture.X := Static[StaticP1ScoreBG].Texture.X + 10*ScreenX; - Text[TextP1Score].X := Text[TextP1Score].X + 10*ScreenX;} - - Static[StaticP2R].Texture.X := Static[StaticP2R].Texture.X + 10*ScreenX; - Text[TextP2R].X := Text[TextP2R].X + 10*ScreenX; - - for S := 1 to 1 do - Static[S].Texture.X := Static[S].Texture.X + 10*ScreenX; - - for T := 0 to 1 do - Text[T].X := Text[T].X + 10*ScreenX; - - if DLLMan.Selected.LoadSong then - begin - // update static menu with time ... - CurLyricsTime := LyricsState.GetCurrentTime(); - Min := Round(CurLyricsTime) div 60; - Sec := Round(CurLyricsTime) mod 60; - - Text[TextTimeText].Text := ''; - if Min < 10 then Text[TextTimeText].Text := '0'; - Text[TextTimeText].Text := Text[TextTimeText].Text + IntToStr(Min) + ':'; - if Sec < 10 then Text[TextTimeText].Text := Text[TextTimeText].Text + '0'; - Text[TextTimeText].Text := Text[TextTimeText].Text + IntToStr(Sec); - end; - - // update and draw movie -{ if ShowFinish and CurrentSong.VideoLoaded and DllMan.Selected.LoadVideo then - begin - UpdateSmpeg; // this only draws - end;} - - // update and draw movie - if (ShowFinish and (VideoLoaded or fShowVisualization) and DllMan.Selected.LoadVideo) then - begin - if assigned(fCurrentVideoPlaybackEngine) then - begin - // Just call this once - // when Screens = 2 - if (ScreenAct = 1) then - fCurrentVideoPlaybackEngine.GetFrame(CurrentSong.VideoGAP + LyricsState.GetCurrentTime()); - - fCurrentVideoPlaybackEngine.DrawGL(ScreenAct); - end; - end; - - // draw static menu (FG) - DrawFG; - - if ShowFinish then - begin - if DllMan.Selected.LoadSong then - begin - if (not AudioPlayback.Finished) and ((CurrentSong.Finish = 0) or (LyricsState.GetCurrentTime*1000 <= CurrentSong.Finish)) then - begin - //Pause Mod: - if not Paused then - Sing(Self); // analyze song - end - else - begin - if not FadeOut then - begin - Finish; - FadeOut := true; - FadeTo(@ScreenPartyScore); - end; - end; - end; - end; - - // draw custom items - SingModiDraw(PlayerInfo); // always draw - - //GoldenNoteStarsTwinkle Mod - GoldenRec.SpawnRec; - //GoldenNoteStarsTwinkle Mod - - //Draw Score - Scores.Draw; - - //Update PlayerInfo - for I := 0 to PlayerInfo.NumPlayers-1 do - begin - if PlayerInfo.Playerinfo[I].Enabled then - begin - //PlayerInfo.Playerinfo[I].Bar := Player[I].ScorePercent; - PlayerInfo.Playerinfo[I].Score := Player[I].ScoreTotalInt; - end; - end; - - if ((ShowFinish) and (not Paused)) then - begin - if not DLLMan.PluginDraw(Playerinfo, Lines[0].Current) then - begin - if not FadeOut then - begin - Finish; - FadeOut := true; - FadeTo(@ScreenPartyScore); - end; - end; - end; - - //Change PlayerInfo/Changeables - for I := 0 to PlayerInfo.NumPlayers-1 do - begin - if (Player[I].ScoreTotalInt <> PlayerInfo.Playerinfo[I].Score) then - begin - //Player[I].ScoreTotal := Player[I].ScoreTotal + (PlayerInfo.Playerinfo[I].Score - Player[I].ScoreTotalI); - Player[I].ScoreTotalInt := PlayerInfo.Playerinfo[I].Score; - end; - {if (PlayerInfo.Playerinfo[I].Bar <> Player[I].ScorePercent) then - Player[I].ScorePercentTarget := PlayerInfo.Playerinfo[I].Bar; } - end; - - // back stereo - Static[StaticP1].Texture.X := Static[StaticP1].Texture.X - 10*ScreenX; - Text[TextP1].X := Text[TextP1].X - 10*ScreenX; - - {Static[StaticP1ScoreBG].Texture.X := Static[StaticP1ScoreBG].Texture.X - 10*ScreenX; - Text[TextP1Score].X := Text[TextP1Score].X - 10*ScreenX;} - - Static[StaticP2R].Texture.X := Static[StaticP2R].Texture.X - 10*ScreenX; - Text[TextP2R].X := Text[TextP2R].X - 10*ScreenX; - - {Static[StaticP2RScoreBG].Texture.X := Static[StaticP2RScoreBG].Texture.X - 10*ScreenX; - Text[TextP2RScore].X := Text[TextP2RScore].X - 10*ScreenX;} - - for S := 1 to 1 do - Static[S].Texture.X := Static[S].Texture.X - 10*ScreenX; - - for T := 0 to 1 do - Text[T].X := Text[T].X - 10*ScreenX; - - Result := true; -end; - -procedure TScreenSingModi.Finish; -begin -inherited Finish; - -Winner := DllMan.PluginFinish(PlayerInfo); - -//Log.LogError('Winner: ' + InttoStr(Winner)); - -//DLLMan.UnLoadPlugin; -end; - -function LoadTex(const Name: PChar; Typ: TTextureType): TsmallTexture; -var - Texname, EXT: string; - Tex: TTexture; -begin - //Get texture Name - TexName := Skin.GetTextureFileName(string(Name)); - //Get File Typ - Ext := ExtractFileExt(TexName); - if (uppercase(Ext) = '.JPG') then - Ext := 'JPG' - else - Ext := 'BMP'; - - Tex := Texture.LoadTexture(false, PChar(TexName), UTEXTURE.TTextureType(Typ), 0); - - Result.TexNum := Tex.TexNum; - Result.W := Tex.W; - Result.H := Tex.H; -end; -{ -function Translate (const Name: PChar): PChar; stdcall; -begin - Result := PChar(Language.Translate(string(Name))); -end; } - -//Procedure to Print Text -procedure Print(const Style, Size: byte; const X, Y: real; const Text: PChar); -begin - SetFontItalic ((Style and 128) = 128); - SetFontStyle(Style and 7); - // FIXME: FONTSIZE - // used by Hold_The_Line / TeamDuell - SetFontSize(Size); - SetFontPos (X, Y); - glPrint (Language.Translate(string(Text))); -end; - -//Procedure that loads a Custom Sound -function LoadSound(const Name: PChar): cardinal; -var - Stream: TAudioPlaybackStream; - i: integer; - Filename: string; -begin - //Search for Sound in already loaded Sounds - Filename := UpperCase(SoundPath + Name); - for i := 0 to High(CustomSounds) do - begin - if (UpperCase(CustomSounds[i].Filename) = Filename) then - begin - Result := i; - Exit; - end; - end; - - Stream := AudioPlayback.OpenSound(SoundPath + string(Name)); - if (Stream = nil) then - begin - Result := 0; - Exit; - end; - - SetLength(CustomSounds, Length(CustomSounds)+1); - CustomSounds[High(CustomSounds)].Stream := Stream; - Result := High(CustomSounds); -end; - -//Plays a Custom Sound -procedure PlaySound(const Index: cardinal); -begin - if (Index <= High(CustomSounds)) then - AudioPlayback.PlaySound(CustomSounds[Index].Stream); -end; - -end. - diff --git a/cmake/src/screens/UScreenSong.pas b/cmake/src/screens/UScreenSong.pas index fa3c836e..6b83d522 100644 --- a/cmake/src/screens/UScreenSong.pas +++ b/cmake/src/screens/UScreenSong.pas @@ -38,6 +38,7 @@ uses SDL, UCommon, UDisplay, + UPath, UFiles, UIni, ULanguage, @@ -56,6 +57,11 @@ type private Equalizer: Tms_Equalizer; + PreviewOpened: Integer; // interaction of the Song that is loaded for preview music + // -1 if nothing is opened + + isScrolling: boolean; // true if song flow is about to move + procedure StartMusicPreview(); procedure StopMusicPreview(); public @@ -75,7 +81,6 @@ type HighSpeed: boolean; CoverFull: boolean; CoverTime: real; - MusicPreviewTimer: PSDL_TimerID; CoverX: integer; CoverY: integer; @@ -118,19 +123,19 @@ type procedure SetScroll4; procedure SetScroll5; procedure SetScroll6; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; function ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; override; function Draw: boolean; override; procedure GenerateThumbnails(); - procedure onShow; override; - procedure onHide; override; + procedure OnShow; override; + procedure OnHide; override; procedure SelectNext; procedure SelectPrev; procedure SkipTo(Target: cardinal); procedure FixSelected; //Show Wrong Song when Tabs on Fix procedure FixSelected2; //Show Wrong Song when Tabs on Fix procedure ShowCatTL(Cat: integer);// Show Cat in Top left - procedure ShowCatTLCustom(Caption: string);// Show Custom Text in Top left + procedure ShowCatTLCustom(Caption: UTF8String);// Show Custom Text in Top left procedure HideCatTL;// Show Cat in Tob left procedure Refresh; //Refresh Song Sorting procedure ChangeMusic; @@ -141,9 +146,12 @@ type //procedures for Menu procedure StartSong; procedure OpenEditor; - procedure DoJoker(Team: byte); + procedure DoJoker(Team: integer); procedure SelectPlayers; + procedure OnSongSelect; // called when song flows movement stops at a song + procedure OnSongDeSelect; // called before current song is deselected + procedure UnloadDetailedCover; //Extensions @@ -156,7 +164,6 @@ uses Math, gl, UCovers, - UDLLManager, UGraphic, UMain, UMenuButton, @@ -164,7 +171,8 @@ uses UParty, UPlaylist, UScreenSongMenu, - USkins; + USkins, + UUnicodeUtils; // ***** Public methods ****** // @@ -211,11 +219,11 @@ begin end; //Show Wrong Song when Tabs on Fix End -procedure TScreenSong.ShowCatTLCustom(Caption: string);// Show Custom Text in Top left +procedure TScreenSong.ShowCatTLCustom(Caption: UTF8String);// Show Custom Text in Top left begin Text[TextCat].Text := Caption; Text[TextCat].Visible := true; - Static[StaticCat].Visible := false; + Statics[StaticCat].Visible := false; end; //Show Cat in Top Left Mod @@ -223,18 +231,18 @@ procedure TScreenSong.ShowCatTL(Cat: integer); begin //Change Text[TextCat].Text := CatSongs.Song[Cat].Artist; - Static[StaticCat].Texture := Texture.GetTexture(Button[Cat].Texture.Name, TEXTURE_TYPE_PLAIN, true); + //Statics[StaticCat].Texture := Texture.GetTexture(Button[Cat].Texture.Name, TEXTURE_TYPE_PLAIN, true); //Show Text[TextCat].Visible := true; - Static[StaticCat].Visible := true; + Statics[StaticCat].Visible := true; end; procedure TScreenSong.HideCatTL; begin //Hide //Text[TextCat].Visible := false; - Static[StaticCat].Visible := false; + Statics[StaticCat].Visible := false; //New -> Show Text specified in Theme Text[TextCat].Visible := true; Text[TextCat].Text := Theme.Song.TextCat.Text; @@ -243,12 +251,13 @@ end; // Method for input parsing. If false is returned, GetNextWindow // should be checked to know the next window to load; -function TScreenSong.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenSong.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; var I: integer; I2: integer; SDL_ModState: word; - Letter: WideChar; + UpperLetter: UCS4Char; + TempStr: UTF8String; begin Result := true; @@ -273,9 +282,10 @@ begin //Jump to Artist/Titel if ((SDL_ModState and KMOD_LALT <> 0) and (Mode = smNormal)) then begin - if (WideCharUpperCase(CharCode)[1] in ([WideChar('A')..WideChar('Z'), WideChar('0') .. WideChar('9')]) ) then + UpperLetter := UCS4UpperCase(CharCode); + + if (UpperLetter in ([Ord('A')..Ord('Z'), Ord('0') .. Ord('9')]) ) then begin - Letter := WideCharUpperCase(CharCode)[1]; I2 := Length(CatSongs.Song); //Jump To Titel @@ -283,18 +293,20 @@ begin begin for I := 1 to High(CatSongs.Song) do begin - if (CatSongs.Song[(I + Interaction) mod I2].Visible) and - (Length(CatSongs.Song[(I + Interaction) mod I2].Title)>0) and - (WideStringUpperCase(CatSongs.Song[(I + Interaction) mod I2].Title)[1] = Letter) then + if (CatSongs.Song[(I + Interaction) mod I2].Visible) then begin - SkipTo(CatSongs.VisibleIndex((I + Interaction) mod I2)); + TempStr := CatSongs.Song[(I + Interaction) mod I2].Title; + if (Length(TempStr) > 0) and + (UCS4UpperCase(UTF8ToUCS4String(TempStr)[0]) = UpperLetter) then + begin + SkipTo(CatSongs.VisibleIndex((I + Interaction) mod I2)); - AudioPlayback.PlaySound(SoundLib.Change); + AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; - SetScroll4; - //Break and Exit - Exit; + SetScroll4; + //Break and Exit + Exit; + end; end; end; end @@ -303,19 +315,21 @@ begin begin for I := 1 to High(CatSongs.Song) do begin - if (CatSongs.Song[(I + Interaction) mod I2].Visible) and - (Length(CatSongs.Song[(I + Interaction) mod I2].Artist)>0) and - (WideStringUpperCase(CatSongs.Song[(I + Interaction) mod I2].Artist)[1] = Letter) then + if (CatSongs.Song[(I + Interaction) mod I2].Visible) then begin - SkipTo(CatSongs.VisibleIndex((I + Interaction) mod I2)); + TempStr := CatSongs.Song[(I + Interaction) mod I2].Artist; + if (Length(TempStr) > 0) and + (UCS4UpperCase(UTF8ToUCS4String(TempStr)[0]) = UpperLetter) then + begin + SkipTo(CatSongs.VisibleIndex((I + Interaction) mod I2)); - AudioPlayback.PlaySound(SoundLib.Change); + AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; - SetScroll4; + SetScroll4; - //Break and Exit - Exit; + //Break and Exit + Exit; + end; end; end; end; @@ -324,15 +338,22 @@ begin Exit; end; + // ********************** + // * workaround for LCTRL+R: it should be changed when we have a solution for the + // * CTRL+'A'..'Z' problem + if (SDL_ModState = KMOD_LCTRL) and (PressedKey = SDLK_R) then + CharCode := UCS4Char('R'); + // ********************** + // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; end; - 'M': //Show SongMenu + Ord('M'): //Show SongMenu begin if (Songs.SongList.Count > 0) then begin @@ -342,41 +363,41 @@ begin begin if CatSongs.CatNumShow = -3 then begin - ScreenSongMenu.onShow; + ScreenSongMenu.OnShow; ScreenSongMenu.MenuShow(SM_Playlist); end else begin - ScreenSongMenu.onShow; + ScreenSongMenu.OnShow; ScreenSongMenu.MenuShow(SM_Main); end; end else begin - ScreenSongMenu.onShow; + ScreenSongMenu.OnShow; ScreenSongMenu.MenuShow(SM_Playlist_Load); end; end //Party Mode -> Show Party Menu else begin - ScreenSongMenu.onShow; + ScreenSongMenu.OnShow; ScreenSongMenu.MenuShow(SM_Party_Main); end; end; Exit; end; - 'P': //Show Playlist Menu + Ord('P'): //Show Playlist Menu begin if (Songs.SongList.Count > 0) and (Mode = smNormal) then begin - ScreenSongMenu.onShow; + ScreenSongMenu.OnShow; ScreenSongMenu.MenuShow(SM_Playlist_Load); end; Exit; end; - 'J': //Show Jumpto Menu + Ord('J'): //Show Jumpto Menu begin if (Songs.SongList.Count > 0) and (Mode = smNormal) then begin @@ -385,13 +406,13 @@ begin Exit; end; - 'E': + Ord('E'): begin OpenEditor; Exit; end; - 'R': + Ord('R'): begin if (Songs.SongList.Count > 0) and (Mode = smNormal) then @@ -464,7 +485,6 @@ begin end; AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; SetScroll4; end; Exit; @@ -505,7 +525,7 @@ begin //Show Wrong Song when Tabs on Fix SelectNext; FixSelected; - //SelectPrev; + //SelectPrev(true); //CatSongs.Song[0].Visible := false; end else @@ -515,7 +535,7 @@ begin if (CatSongs.CatNumShow < -1) then begin //Atm: Set Empty Filter - CatSongs.SetFilter('', 0); + CatSongs.SetFilter('', fltAll); //Show Cat in Top Left Mod HideCatTL; @@ -524,8 +544,6 @@ begin //Show Wrong Song when Tabs on Fix SelectNext; FixSelected; - - ChangeMusic; end else begin @@ -564,9 +582,6 @@ begin //Show Wrong Song when Tabs on Fix SelectNext; FixSelected; - - //Play Music: - ChangeMusic; end else begin // clicked on song @@ -589,7 +604,7 @@ begin if (Ini.PartyPopup = 1) then ScreenSongMenu.MenuShow(SM_Party_Main) else - ScreenSong.StartSong; + Party.CallAfterSongSelect; end; end; end; @@ -627,8 +642,6 @@ begin //Play Music: AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; - end; // @@ -671,7 +684,6 @@ begin //Play Music: AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; end; end; //Cat Change Hack End} @@ -684,9 +696,6 @@ begin begin AudioPlayback.PlaySound(SoundLib.Change); SelectNext; - //InteractNext; - //SongTarget := Interaction; - ChangeMusic; SetScroll4; end; end; @@ -697,65 +706,116 @@ begin begin AudioPlayback.PlaySound(SoundLib.Change); SelectPrev; - ChangeMusic; SetScroll4; end; end; SDLK_1: begin //Joker - if (Mode = smPartyMode) and (PartySession.Teams.NumTeams >= 1) and (PartySession.Teams.Teaminfo[0].Joker > 0) then - begin - //Use Joker - Dec(PartySession.Teams.Teaminfo[0].Joker); - SelectRandomSong; - SetJoker; - end; + DoJoker(0); end; SDLK_2: begin //Joker - if (Mode = smPartyMode) and (PartySession.Teams.NumTeams >= 2) and (PartySession.Teams.Teaminfo[1].Joker > 0) then - begin - //Use Joker - Dec(PartySession.Teams.Teaminfo[1].Joker); - SelectRandomSong; - SetJoker; - end; + DoJoker(1); end; SDLK_3: begin //Joker - if (Mode = smPartyMode) and (PartySession.Teams.NumTeams >= 3) and (PartySession.Teams.Teaminfo[2].Joker > 0) then - begin - //Use Joker - Dec(PartySession.Teams.Teaminfo[2].Joker); - SelectRandomSong; - SetJoker; - end; + DoJoker(2); end; end; end; // if (PressedDown) end; function TScreenSong.ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; + var + I, J: Integer; + Btn: Integer; begin Result := true; - if RightMbESC and (MouseButton = SDL_BUTTON_RIGHT) and BtnDown then - //if RightMbESC is set, send ESC keypress - Result:=ParseInput(SDLK_ESCAPE, #0, true); + if (ScreenSongMenu.Visible) then + begin + Result := ScreenSongMenu.ParseMouse(MouseButton, BtnDown, X, Y); + exit; + end + else if (ScreenSongJumpTo.Visible) then + begin + Result := ScreenSongJumpTo.ParseMouse(MouseButton, BtnDown, X, Y); + exit; + end + else // no extension visible + begin + if (BtnDown) then + begin + //if RightMbESC is set, send ESC keypress + if RightMbESC and (MouseButton = SDL_BUTTON_RIGHT) then + Result:=ParseInput(SDLK_ESCAPE, 0, true) + + //song scrolling with mousewheel + else if (MouseButton = SDL_BUTTON_WHEELDOWN) then + ParseInput(SDLK_RIGHT, 0, true) - //song scrolling with mousewheel - if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then - ParseInput(SDLK_RIGHT, #0, true); + else if (MouseButton = SDL_BUTTON_WHEELUP) then + ParseInput(SDLK_LEFT, 0, true) - if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then - ParseInput(SDLK_LEFT, #0, true); + //LMB anywhere starts + else if (MouseButton = SDL_BUTTON_LEFT) then + begin + if (CatSongs.VisibleSongs > 4) then + begin + // select the second visible button left from selected + I := 0; + Btn := Interaction; + while (I < 2) do + begin + Dec(Btn); + if (Btn < 0) then + Btn := High(CatSongs.Song); - //LMB anywhere starts - if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then - ParseInput(SDLK_RETURN, #0, true); + if (CatSongs.Song[Btn].Visible) then + Inc(I); + end; + + // test the 5 front buttons for click + for I := 0 to 4 do + begin + if InRegion(X, Y, Button[Btn].GetMouseOverArea) then + begin + // song cover clicked + if (I = 2) then + begin // Selected Song clicked -> start singing + ParseInput(SDLK_RETURN, 0, true); + end + else + begin // one of the other 4 covers in the front clicked -> select it + J := I - 2; + while (J < 0) do + begin + ParseInput(SDLK_LEFT, 0, true); + Inc(J); + end; + + while (J > 0) do + begin + ParseInput(SDLK_RIGHT, 0, true); + Dec(J); + end; + end; + Break; + end; + + Btn := CatSongs.FindNextVisible(Btn); + if (Btn = -1) then + Break; + end; + end + else + ParseInput(SDLK_RETURN, 0, true); + end; + end; + end; end; constructor TScreenSong.Create; @@ -824,8 +884,8 @@ begin Equalizer := Tms_Equalizer.Create(AudioPlayback, Theme.Song.Equalizer); - if (Length(CatSongs.Song) > 0) then - Interaction := 0; + PreviewOpened := -1; + isScrolling := false; end; procedure TScreenSong.GenerateThumbnails(); @@ -833,9 +893,9 @@ var I: integer; CoverButtonIndex: integer; CoverButton: TButton; - CoverName: string; CoverTexture: TTexture; Cover: TCover; + CoverFile: IPath; Song: TSong; begin if (Length(CatSongs.Song) <= 0) then @@ -850,7 +910,7 @@ begin CoverButton := nil; // create a clickable cover - CoverButtonIndex := AddButton(300 + I*250, 140, 200, 200, '', TEXTURE_TYPE_PLAIN, Theme.Song.Cover.Reflections); + CoverButtonIndex := AddButton(300 + I*250, 140, 200, 200, PATH_NONE, TEXTURE_TYPE_PLAIN, Theme.Song.Cover.Reflections); if (CoverButtonIndex > -1) then CoverButton := Button[CoverButtonIndex]; if (CoverButton = nil) then @@ -858,19 +918,17 @@ begin Song := CatSongs.Song[I]; - // if cover-image is not found then show 'no cover' - if (not FileExists(Song.Path + Song.Cover)) then - Song.Cover := ''; + CoverFile := Song.Path.Append(Song.Cover); + if (not CoverFile.IsFile()) then + Song.Cover := PATH_NONE; - if (Song.Cover = '') then - CoverName := Skin.GetTextureFileName('SongCover') - else - CoverName := Song.Path + Song.Cover; + if (Song.Cover.IsUnset) then + CoverFile := Skin.GetTextureFileName('SongCover'); // load cover and cache its texture - Cover := Covers.FindCover(CoverName); + Cover := Covers.FindCover(CoverFile); if (Cover = nil) then - Cover := Covers.AddCover(CoverName); + Cover := Covers.AddCover(CoverFile); // use the cached texture // TODO: this is a workaround until the new song-loading works. @@ -883,10 +941,39 @@ begin CoverTexture := Cover.GetPreviewTexture(); Texture.AddTexture(CoverTexture, TEXTURE_TYPE_PLAIN, true); CoverButton.Texture := CoverTexture; + + // set selected to false -> the right texture will be displayed + CoverButton.Selected := False; end; Cover.Free; end; + + // reset selection + if (Length(CatSongs.Song) > 0) then + Interaction := 0; +end; + +{ called when song flows movement stops at a song } +procedure TScreenSong.OnSongSelect; +begin + if (Ini.PreviewVolume <> 0) then + begin + StartMusicPreview; + end; + + // fade in detailed cover + CoverTime := 0; +end; + +{ called before current song is deselected } +procedure TScreenSong.OnSongDeSelect; +begin + CoverTime := 10; + UnLoadDetailedCover; + + StopMusicPreview(); + PreviewOpened := -1; end; procedure TScreenSong.SetScroll; @@ -899,18 +986,13 @@ begin // Set Positions case Theme.Song.Cover.Style of 3: SetScroll3; - 5:begin - if VS > 5 then - SetScroll5 - else - SetScroll4; - end; + 5: SetScroll5; 6: SetScroll6; else SetScroll4; end; // Set visibility of video icon - Static[VideoIcon].Visible := (CatSongs.Song[Interaction].Video <> ''); + Statics[VideoIcon].Visible := CatSongs.Song[Interaction].Video.IsSet; // Set texts Text[TextArtist].Text := CatSongs.Song[Interaction].Artist; @@ -944,8 +1026,6 @@ end; procedure TScreenSong.SetScroll1; var B: integer; // button - //BMin: integer; // button min // Auto Removed, Unused Variable - //BMax: integer; // button max // Auto Removed, Unused Variable Src: integer; //Dst: integer; Count: integer; // Dst is not used. Count is used. @@ -1097,7 +1177,7 @@ begin end; if Length(Button) > 0 then - Static[1].Texture.Y := Button[Interaction].Y - 5; // selection texture + Statics[1].Texture.Y := Button[Interaction].Y - 5; // selection texture end; procedure TScreenSong.SetScroll2; @@ -1251,7 +1331,7 @@ begin // Use an alternate position for the five front covers. if (Abs(Pos) < 2.5) then begin - Angle := Pi * (Pos / 5); // Range: (-1/4*Pi .. +1/4*Pi) + Angle := Pi * (Pos / Min(VS, 5)); // Range: (-1/4*Pi .. +1/4*Pi) Button[B].H := Abs(Theme.Song.Cover.H * cos(Angle*0.8)); Button[B].W := Button[B].H; @@ -1265,14 +1345,25 @@ begin Button[B].X := Theme.Song.Cover.X + Theme.Song.Cover.W * X - Padding; Button[B].Y := (Theme.Song.Cover.Y + (Theme.Song.Cover.H - Abs(Theme.Song.Cover.H * cos(Angle))) * 0.5); Button[B].Z := 0.95 - Abs(Pos) * 0.01; + + if VS < 5 then + Button[B].Texture.Alpha := 1 - Abs(Pos) / VS * 2 + else + Button[B].Texture.Alpha := 1; end - else + { only draw 3 visible covers in the background + (the 3 that are on the opposite of the front covers} + else if (VS > 7) and (Abs(Pos) > floor(VS/2) - 1.5) then begin - // Transform Pos to range [-1..-1/2, +1/2..+1] + // Transform Pos to range [-1..-3/4, +3/4..+1] + { the 3 covers at the back will show up in the gap between the + front cover and its neighbors + one cover will be hiddenbehind the front cover, + but this will not be a lack of performance ;) } if Pos < 0 then - Pos := Pos/VS - 0.5 + Pos := (Pos - 2 + ceil(VS/2))/8 - 0.75 else - Pos := Pos/VS + 0.5; + Pos := (Pos + 2 - floor(VS/2))/8 + 0.75; // angle in radians [-2Pi..-Pi, +Pi..+2Pi] Angle := 2*Pi * Pos; @@ -1286,9 +1377,14 @@ begin Button[B].Y := Theme.Song.Cover.Y - (Button[B].H - Theme.Song.Cover.H)*0.75; Button[B].Z := (0.4 - Abs(Pos/4)) -0.00001; //z < 0.49999 is behind the cover 1 is in front of the covers + Button[B].Texture.Alpha := 1; + //Button[B].Reflectionspacing := 15 * Button[B].H/Theme.Song.Cover.H; Button[B].DeSelectReflectionspacing := 15 * Button[B].H/Theme.Song.Cover.H; - end; + end + { all other covers are not visible } + else + Button[B].Visible := false; end; end; end; @@ -1399,7 +1495,7 @@ begin end; end; -procedure TScreenSong.onShow; +procedure TScreenSong.OnShow; begin inherited; {** @@ -1408,6 +1504,7 @@ begin SoundLib.PauseBgMusic; AudioPlayback.Stop; + PreviewOpened := -1; if Ini.Players <= 3 then PlayersPlay := Ini.Players + 1; if Ini.Players = 4 then PlayersPlay := 6; @@ -1423,10 +1520,6 @@ begin if Length(CatSongs.Song) > 0 then begin - //Load Music only when Song Preview is activated - if ( Ini.PreviewVolume <> 0 ) then - StartMusicPreview(); - SetScroll; end; @@ -1437,7 +1530,6 @@ begin if (CatSongs.CatNumShow = -3) then begin SelectNext; - ChangeMusic; end; end //Party Mode @@ -1452,25 +1544,18 @@ begin end; end; + isScrolling := true; SetJoker; SetStatics; end; -procedure TScreenSong.onHide; +procedure TScreenSong.OnHide; begin // turn music volume to 100% AudioPlayback.SetVolume(1.0); - // if preview is deactivated: load musicfile now - if (IPreviewVolumeVals[Ini.PreviewVolume] = 0) then - AudioPlayback.Open(CatSongs.Song[Interaction].Path + CatSongs.Song[Interaction].Mp3); - - // if hide then stop music (for party mode popup on exit) - if (Display.NextScreen <> @ScreenSing) and - (Display.NextScreen <> @ScreenSingModi) then - begin - StopMusicPreview(); - end; + // stop preview + StopMusicPreview(); end; procedure TScreenSong.DrawExtensions; @@ -1492,13 +1577,23 @@ var dt: real; I: integer; begin - dx := SongTarget-SongCurrent; - dt := TimeSkip * 7; + if isScrolling then + begin + dx := SongTarget-SongCurrent; + dt := TimeSkip * 7; - if dt > 1 then - dt := 1; - - SongCurrent := SongCurrent + dx*dt; + if dt > 1 then + dt := 1; + + SongCurrent := SongCurrent + dx*dt; + + if SameValue(SongCurrent, SongTarget, 0.002) and (CatSongs.VisibleSongs > 0) then + begin + isScrolling := false; + SongCurrent := SongTarget; + OnSongSelect; + end; + end; { if SongCurrent > Catsongs.VisibleSongs then @@ -1552,8 +1647,8 @@ begin Button[I].Draw; // Statics - for I := 0 to Length(Static) - 1 do - Static[I].Draw; + for I := 0 to Length(Statics) - 1 do + Statics[I].Draw; // and texts for I := 0 to Length(Text) - 1 do @@ -1575,7 +1670,11 @@ begin if VS > 0 then begin - UnLoadDetailedCover; + if (not isScrolling) and (VS > 0) then + begin + isScrolling := true; + OnSongDeselect; + end; Skip := 1; @@ -1610,7 +1709,11 @@ begin if VS > 0 then begin - UnLoadDetailedCover; + if (not isScrolling) and (VS > 0) then + begin + isScrolling := true; + OnSongDeselect; + end; Skip := 1; @@ -1638,12 +1741,21 @@ var begin AudioPlayback.Close(); + if CatSongs.VisibleSongs = 0 then + Exit; + Song := CatSongs.Song[Interaction]; if not assigned(Song) then Exit; - if AudioPlayback.Open(Song.Path + Song.Mp3) then + //fix: if main cat than there is nothing to play + if Song.main then + Exit; + + if AudioPlayback.Open(Song.Path.Append(Song.Mp3)) then begin + PreviewOpened := Interaction; + AudioPlayback.Position := AudioPlayback.Length / 4; // set preview volume if (Ini.PreviewFading = 0) then @@ -1663,51 +1775,22 @@ end; procedure TScreenSong.StopMusicPreview(); begin - // Cancel pending preview requests - SDL_RemoveTimer(MusicPreviewTimer); - // Stop preview of previous song AudioPlayback.Stop; end; -procedure StartMusicPreview(data: Pointer); -var - ScreenSong: TScreenSong; -begin - ScreenSong := TScreenSong(data); - if (ScreenSong <> nil) then - ScreenSong.StartMusicPreview(); -end; - -function MusicPreviewTimerCallback(interval: UInt32; param: Pointer): UInt32; cdecl; -begin - // delegate execution to main-thread - MainThreadExec(@StartMusicPreview, param); - // stop timer - Result := 0; -end; - // Changes previewed song procedure TScreenSong.ChangeMusic; begin StopMusicPreview(); - - // Preview song if activated and current selection is not a category cover - if (CatSongs.VisibleSongs > 0) and - (not CatSongs.Song[Interaction].Main) and - (Ini.PreviewVolume <> 0) then - begin - // Delay song fading to prevent the song from being played while scrolling - MusicPreviewTimer := SDL_AddTimer(200, MusicPreviewTimerCallback, Self); - end; + PreviewOpened := -1; + StartMusicPreview(); end; procedure TScreenSong.SkipTo(Target: cardinal); var i: integer; begin - UnLoadDetailedCover; - Interaction := High(CatSongs.Song); SongTarget := 0; @@ -1776,7 +1859,6 @@ begin end; AudioPlayback.PlaySound(SoundLib.Change); - ChangeMusic; SetScroll; end; @@ -1785,76 +1867,76 @@ begin // If Party Mode if Mode = smPartyMode then //Show Joker that are available begin - if (PartySession.Teams.NumTeams >= 1) then + if (Length(Party.Teams) >= 1) then begin - Static[StaticTeam1Joker1].Visible := (PartySession.Teams.Teaminfo[0].Joker >= 1); - Static[StaticTeam1Joker2].Visible := (PartySession.Teams.Teaminfo[0].Joker >= 2); - Static[StaticTeam1Joker3].Visible := (PartySession.Teams.Teaminfo[0].Joker >= 3); - Static[StaticTeam1Joker4].Visible := (PartySession.Teams.Teaminfo[0].Joker >= 4); - Static[StaticTeam1Joker5].Visible := (PartySession.Teams.Teaminfo[0].Joker >= 5); + Statics[StaticTeam1Joker1].Visible := (Party.Teams[0].JokersLeft >= 1); + Statics[StaticTeam1Joker2].Visible := (Party.Teams[0].JokersLeft >= 2); + Statics[StaticTeam1Joker3].Visible := (Party.Teams[0].JokersLeft >= 3); + Statics[StaticTeam1Joker4].Visible := (Party.Teams[0].JokersLeft >= 4); + Statics[StaticTeam1Joker5].Visible := (Party.Teams[0].JokersLeft >= 5); end else begin - Static[StaticTeam1Joker1].Visible := false; - Static[StaticTeam1Joker2].Visible := false; - Static[StaticTeam1Joker3].Visible := false; - Static[StaticTeam1Joker4].Visible := false; - Static[StaticTeam1Joker5].Visible := false; + Statics[StaticTeam1Joker1].Visible := false; + Statics[StaticTeam1Joker2].Visible := false; + Statics[StaticTeam1Joker3].Visible := false; + Statics[StaticTeam1Joker4].Visible := false; + Statics[StaticTeam1Joker5].Visible := false; end; - if (PartySession.Teams.NumTeams >= 2) then + if (Length(Party.Teams) >= 2) then begin - Static[StaticTeam2Joker1].Visible := (PartySession.Teams.Teaminfo[1].Joker >= 1); - Static[StaticTeam2Joker2].Visible := (PartySession.Teams.Teaminfo[1].Joker >= 2); - Static[StaticTeam2Joker3].Visible := (PartySession.Teams.Teaminfo[1].Joker >= 3); - Static[StaticTeam2Joker4].Visible := (PartySession.Teams.Teaminfo[1].Joker >= 4); - Static[StaticTeam2Joker5].Visible := (PartySession.Teams.Teaminfo[1].Joker >= 5); + Statics[StaticTeam2Joker1].Visible := (Party.Teams[1].JokersLeft >= 1); + Statics[StaticTeam2Joker2].Visible := (Party.Teams[1].JokersLeft >= 2); + Statics[StaticTeam2Joker3].Visible := (Party.Teams[1].JokersLeft >= 3); + Statics[StaticTeam2Joker4].Visible := (Party.Teams[1].JokersLeft >= 4); + Statics[StaticTeam2Joker5].Visible := (Party.Teams[1].JokersLeft >= 5); end else begin - Static[StaticTeam2Joker1].Visible := false; - Static[StaticTeam2Joker2].Visible := false; - Static[StaticTeam2Joker3].Visible := false; - Static[StaticTeam2Joker4].Visible := false; - Static[StaticTeam2Joker5].Visible := false; + Statics[StaticTeam2Joker1].Visible := false; + Statics[StaticTeam2Joker2].Visible := false; + Statics[StaticTeam2Joker3].Visible := false; + Statics[StaticTeam2Joker4].Visible := false; + Statics[StaticTeam2Joker5].Visible := false; end; - if (PartySession.Teams.NumTeams >= 3) then + if (Length(Party.Teams) >= 3) then begin - Static[StaticTeam3Joker1].Visible := (PartySession.Teams.Teaminfo[2].Joker >= 1); - Static[StaticTeam3Joker2].Visible := (PartySession.Teams.Teaminfo[2].Joker >= 2); - Static[StaticTeam3Joker3].Visible := (PartySession.Teams.Teaminfo[2].Joker >= 3); - Static[StaticTeam3Joker4].Visible := (PartySession.Teams.Teaminfo[2].Joker >= 4); - Static[StaticTeam3Joker5].Visible := (PartySession.Teams.Teaminfo[2].Joker >= 5); + Statics[StaticTeam3Joker1].Visible := (Party.Teams[2].JokersLeft >= 1); + Statics[StaticTeam3Joker2].Visible := (Party.Teams[2].JokersLeft >= 2); + Statics[StaticTeam3Joker3].Visible := (Party.Teams[2].JokersLeft >= 3); + Statics[StaticTeam3Joker4].Visible := (Party.Teams[2].JokersLeft >= 4); + Statics[StaticTeam3Joker5].Visible := (Party.Teams[2].JokersLeft >= 5); end else begin - Static[StaticTeam3Joker1].Visible := false; - Static[StaticTeam3Joker2].Visible := false; - Static[StaticTeam3Joker3].Visible := false; - Static[StaticTeam3Joker4].Visible := false; - Static[StaticTeam3Joker5].Visible := false; + Statics[StaticTeam3Joker1].Visible := false; + Statics[StaticTeam3Joker2].Visible := false; + Statics[StaticTeam3Joker3].Visible := false; + Statics[StaticTeam3Joker4].Visible := false; + Statics[StaticTeam3Joker5].Visible := false; end; end else begin //Hide all - Static[StaticTeam1Joker1].Visible := false; - Static[StaticTeam1Joker2].Visible := false; - Static[StaticTeam1Joker3].Visible := false; - Static[StaticTeam1Joker4].Visible := false; - Static[StaticTeam1Joker5].Visible := false; - - Static[StaticTeam2Joker1].Visible := false; - Static[StaticTeam2Joker2].Visible := false; - Static[StaticTeam2Joker3].Visible := false; - Static[StaticTeam2Joker4].Visible := false; - Static[StaticTeam2Joker5].Visible := false; - - Static[StaticTeam3Joker1].Visible := false; - Static[StaticTeam3Joker2].Visible := false; - Static[StaticTeam3Joker3].Visible := false; - Static[StaticTeam3Joker4].Visible := false; - Static[StaticTeam3Joker5].Visible := false; + Statics[StaticTeam1Joker1].Visible := false; + Statics[StaticTeam1Joker2].Visible := false; + Statics[StaticTeam1Joker3].Visible := false; + Statics[StaticTeam1Joker4].Visible := false; + Statics[StaticTeam1Joker5].Visible := false; + + Statics[StaticTeam2Joker1].Visible := false; + Statics[StaticTeam2Joker2].Visible := false; + Statics[StaticTeam2Joker3].Visible := false; + Statics[StaticTeam2Joker4].Visible := false; + Statics[StaticTeam2Joker5].Visible := false; + + Statics[StaticTeam3Joker1].Visible := false; + Statics[StaticTeam3Joker2].Visible := false; + Statics[StaticTeam3Joker3].Visible := false; + Statics[StaticTeam3Joker4].Visible := false; + Statics[StaticTeam3Joker5].Visible := false; end; end; @@ -1867,7 +1949,7 @@ begin Visible := (Mode = smPartyMode); for I := 0 to High(StaticParty) do - Static[StaticParty[I]].Visible := Visible; + Statics[StaticParty[I]].Visible := Visible; for I := 0 to High(TextParty) do Text[TextParty[I]].Visible := Visible; @@ -1876,7 +1958,7 @@ begin Visible := not Visible; for I := 0 to High(StaticNonParty) do - Static[StaticNonParty[I]].Visible := Visible; + Statics[StaticNonParty[I]].Visible := Visible; for I := 0 to High(TextNonParty) do Text[TextNonParty[I]].Visible := Visible; @@ -1892,7 +1974,7 @@ begin //Party Mode if (Mode = smPartyMode) then begin - FadeTo(@ScreenSingModi); + FadeTo(@ScreenSing); end else begin @@ -1923,14 +2005,14 @@ begin end; //Team No of Team (0-5) -procedure TScreenSong.DoJoker (Team: byte); +procedure TScreenSong.DoJoker (Team: integer); begin if (Mode = smPartyMode) and - (PartySession.Teams.NumTeams >= Team + 1) and - (PartySession.Teams.Teaminfo[Team].Joker > 0) then + (High(Party.Teams) >= Team) and + (Party.Teams[Team].JokersLeft > 0) then begin //Use Joker - Dec(PartySession.Teams.Teaminfo[Team].Joker); + Dec(Party.Teams[Team].JokersLeft); SelectRandomSong; SetJoker; end; @@ -1939,8 +2021,6 @@ end; //Detailed Cover Unloading. Unloads the Detailed, uncached Cover of the cur. Song procedure TScreenSong.UnloadDetailedCover; begin - CoverTime := 0; - // show cached texture Button[Interaction].Texture := Texture.GetTexture(Button[Interaction].Texture.Name, TEXTURE_TYPE_PLAIN, true); Button[Interaction].Texture2.Alpha := 0; @@ -1955,7 +2035,7 @@ begin CatSongs.Refresh; CatSongs.ShowCategoryList; Interaction := 0; - SelectNext; + SelectNext(true); FixSelected; } end; diff --git a/cmake/src/screens/UScreenSongJumpto.pas b/cmake/src/screens/UScreenSongJumpto.pas index e55a6276..b3d48679 100644 --- a/cmake/src/screens/UScreenSongJumpto.pas +++ b/cmake/src/screens/UScreenSongJumpto.pas @@ -34,42 +34,39 @@ interface {$I switches.inc} uses - UMenu, SDL, + SysUtils, + UMenu, UDisplay, UMusic, UFiles, - SysUtils, + USongs, UThemes; type TScreenSongJumpto = class(TMenu) private //For ChangeMusic - LastPlayed: integer; - VisibleBool: boolean; - public - VisSongs: integer; + fLastPlayed: integer; + fVisible: boolean; + fSelectType: TSongFilter; + fVisSongs: integer; - constructor Create; override; + procedure SetTextFound(Count: Cardinal); //Visible //Whether the Menu should be Drawn //Whether the Menu should be Drawn procedure SetVisible(Value: boolean); - property Visible: boolean read VisibleBool write SetVisible; + public + constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; function Draw: boolean; override; - procedure SetTextFound(const Count: cardinal); + property Visible: boolean read fVisible write SetVisible; end; -var - IType: array [0..2] of string; - SelectType: integer; - - implementation uses @@ -79,26 +76,24 @@ uses UTexture, ULanguage, UParty, - USongs, UScreenSong, - ULog; + ULog, + UUnicodeUtils; -function TScreenSongJumpto.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenSongJumpto.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case CharCode of - '0'..'9', 'a'..'z', 'A'..'Z', ' ', '-', '_', '!', ',', '<', '/', '*', '?', '''', '"', - '[', '{', ';', ':': - begin - if Interaction = 0 then - begin - Button[0].Text[0].Text := Button[0].Text[0].Text + CharCode; - SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, SelectType)); - end; - end; + if (IsAlphaNumericChar(CharCode) or + IsPunctuationChar(CharCode)) then + begin + if (Interaction = 0) then + begin + Button[0].Text[0].Text := Button[0].Text[0].Text + UCS4ToUTF8String(CharCode); + SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, fSelectType)); + end; end; // check special keys @@ -107,8 +102,8 @@ begin begin if (Interaction = 0) and (Length(Button[0].Text[0].Text) > 0) then begin - Button[0].Text[0].DeleteLastL; - SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, SelectType)); + Button[0].Text[0].DeleteLastLetter(); + SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, fSelectType)); end; end; @@ -117,18 +112,15 @@ begin begin Visible := false; AudioPlayback.PlaySound(SoundLib.Back); - if (VisSongs = 0) and (Length(Button[0].Text[0].Text) > 0) then + if (fVisSongs = 0) and (Length(Button[0].Text[0].Text) > 0) then begin ScreenSong.UnLoadDetailedCover; Button[0].Text[0].Text := ''; - CatSongs.SetFilter('', 0); + CatSongs.SetFilter('', fltAll); SetTextFound(0); end; end; - // Up and Down could be done at the same time, - // but I don't want to declare variables inside - // functions like this one, called so many times SDLK_DOWN: begin {SelectNext; @@ -146,7 +138,7 @@ begin Interaction := 1; InteractInc; if (Length(Button[0].Text[0].Text) > 0) then - SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, SelectType)); + SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, fSelectType)); Interaction := 0; end; SDLK_LEFT: @@ -154,7 +146,7 @@ begin Interaction := 1; InteractDec; if (Length(Button[0].Text[0].Text) > 0) then - SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, SelectType)); + SetTextFound(CatSongs.SetFilter(Button[0].Text[0].Text, fSelectType)); Interaction := 0; end; end; @@ -162,8 +154,6 @@ begin end; constructor TScreenSongJumpto.Create; -//var -// I: integer; // Auto Removed, Unused Variable begin inherited Create; @@ -175,23 +165,23 @@ begin if (Length(Button[0].Text) = 0) then AddButtonText(14, 20, ''); - SelectType := 0; - AddSelectSlide(Theme.SongJumpto.SelectSlideType, SelectType, Theme.SongJumpto.IType); + fSelectType := fltAll; + AddSelectSlide(Theme.SongJumpto.SelectSlideType, PInteger(@fSelectType)^, Theme.SongJumpto.IType); Interaction := 0; - LastPlayed := 0; + fLastPlayed := 0; end; procedure TScreenSongJumpto.SetVisible(Value: boolean); begin -//If change from unvisible to Visible then OnShow - if (VisibleBool = false) and (Value = true) then +//If change from invisible to Visible then OnShow + if (fVisible = false) and (Value = true) then OnShow; - VisibleBool := Value; + fVisible := Value; end; -procedure TScreenSongJumpto.onShow; +procedure TScreenSongJumpto.OnShow; begin inherited; @@ -208,7 +198,7 @@ begin Interaction := 0; Button[0].Text[0].Selected := true; - LastPlayed := ScreenSong.Interaction; + fLastPlayed := ScreenSong.Interaction; end; function TScreenSongJumpto.Draw: boolean; @@ -216,7 +206,7 @@ begin Result := inherited Draw; end; -procedure TScreenSongJumpto.SetTextFound(const Count: cardinal); +procedure TScreenSongJumpto.SetTextFound(Count: cardinal); begin if (Count = 0) then begin @@ -235,7 +225,7 @@ begin end; //Set visSongs - VisSongs := Count; + fVisSongs := Count; //Fix SongSelection ScreenSong.Interaction := high(CatSongs.Song); @@ -243,9 +233,12 @@ begin ScreenSong.FixSelected; //Play Correct Music - if (ScreenSong.Interaction <> LastPlayed) then + if (ScreenSong.Interaction <> fLastPlayed) or (CatSongs.VisibleSongs = 0) then begin - LastPlayed := ScreenSong.Interaction; + if (CatSongs.VisibleSongs > 0) then + fLastPlayed := ScreenSong.Interaction + else + fLastPlayed := -1; ScreenSong.ChangeMusic; end; diff --git a/cmake/src/screens/UScreenSongMenu.pas b/cmake/src/screens/UScreenSongMenu.pas index 0af94a8f..173ac2c8 100644 --- a/cmake/src/screens/UScreenSongMenu.pas +++ b/cmake/src/screens/UScreenSongMenu.pas @@ -50,8 +50,8 @@ type Visible: boolean; // whether the menu should be drawn constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; function Draw: boolean; override; procedure MenuShow(sMenu: byte); procedure HandleReturn; @@ -73,7 +73,7 @@ const SM_Party_Joker = 128 or 2; var - ISelections: array of string; + ISelections: array of UTF8String; SelectValue: integer; implementation @@ -86,9 +86,10 @@ uses ULanguage, UParty, UPlaylist, - USongs; + USongs, + UUnicodeUtils; -function TScreenSongMenu.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenSongMenu.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then @@ -96,27 +97,29 @@ begin if (CurMenu = SM_Playlist_New) and (Interaction=0) then begin // check normal keys - case WideCharUpperCase(CharCode)[1] of - '0'..'9', 'A'..'Z', ' ', '-', '_', '!', ',', '<', '/', '*', '?', '''', '"': - begin - Button[Interaction].Text[0].Text := Button[Interaction].Text[0].Text + CharCode; - exit; - end; + if IsAlphaNumericChar(CharCode) or + (CharCode in [Ord(' '), Ord('-'), Ord('_'), Ord('!'), + Ord(','), Ord('<'), Ord('/'), Ord('*'), + Ord('?'), Ord(''''), Ord('"')]) then + begin + Button[Interaction].Text[0].Text := Button[Interaction].Text[0].Text + + UCS4ToUTF8String(CharCode); + exit; end; // check special keys case PressedKey of SDLK_BACKSPACE: begin - Button[Interaction].Text[0].DeleteLastL; + Button[Interaction].Text[0].DeleteLastLetter; exit; end; end; end; // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -223,7 +226,7 @@ begin Result := inherited Draw; end; -procedure TScreenSongMenu.onShow; +procedure TScreenSongMenu.OnShow; begin inherited; end; @@ -398,16 +401,19 @@ begin begin CurMenu := sMenu; Text[0].Text := Language.Translate('SONG_MENU_NAME_PARTY_JOKER'); - - Button[0].Visible := (PartySession.Teams.NumTeams >= 1) and (PartySession.Teams.Teaminfo[0].Joker > 0); - Button[1].Visible := (PartySession.Teams.NumTeams >= 2) and (PartySession.Teams.Teaminfo[1].Joker > 0); - Button[2].Visible := (PartySession.Teams.NumTeams >= 3) and (PartySession.Teams.Teaminfo[2].Joker > 0); - Button[3].Visible := true; - SelectsS[0].Visible := false; - - Button[0].Text[0].Text := string(PartySession.Teams.Teaminfo[0].Name); - Button[1].Text[0].Text := string(PartySession.Teams.Teaminfo[1].Name); - Button[2].Text[0].Text := string(PartySession.Teams.Teaminfo[2].Name); + // to-do : Party + Button[0].Visible := (Length(Party.Teams) >= 1) AND (Party.Teams[0].JokersLeft > 0); + Button[1].Visible := (Length(Party.Teams) >= 2) AND (Party.Teams[1].JokersLeft > 0); + Button[2].Visible := (Length(Party.Teams) >= 3) AND (Party.Teams[2].JokersLeft > 0); + Button[3].Visible := True; + SelectsS[0].Visible := False; + + if (Button[0].Visible) then + Button[0].Text[0].Text := UTF8String(Party.Teams[0].Name); + if (Button[1].Visible) then + Button[1].Text[0].Text := UTF8String(Party.Teams[1].Name); + if (Button[2].Visible) then + Button[2].Text[0].Text := UTF8String(Party.Teams[2].Name); Button[3].Text[0].Text := Language.Translate('SONG_MENU_CANCEL'); // set right interaction @@ -611,7 +617,7 @@ begin 0: // button 1 begin // start singing - ScreenSong.StartSong; + Party.CallAfterSongSelect; Visible := false; end; diff --git a/cmake/src/screens/UScreenStatDetail.pas b/cmake/src/screens/UScreenStatDetail.pas index bbbb4a1b..1638cd85 100644 --- a/cmake/src/screens/UScreenStatDetail.pas +++ b/cmake/src/screens/UScreenStatDetail.pas @@ -55,8 +55,8 @@ type TotPages: cardinal; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; procedure SetTitle; @@ -66,20 +66,21 @@ type implementation uses - UGraphic, - ULanguage, Math, Classes, - ULog; + UGraphic, + ULanguage, + ULog, + UUnicodeUtils; -function TScreenStatDetail.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TScreenStatDetail.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -178,7 +179,7 @@ begin Typ := TStatType(0); end; -procedure TScreenStatDetail.onShow; +procedure TScreenStatDetail.OnShow; begin inherited; @@ -233,7 +234,7 @@ begin if (Score > 0) then begin Text[I].Text := Format(FormatStr, - [Singer, Score, Theme.ILevel[Difficulty], SongArtist, SongTitle]); + [Singer, Score, Theme.ILevel[Difficulty], SongArtist, SongTitle, Date]); end; end; end; diff --git a/cmake/src/screens/UScreenStatMain.pas b/cmake/src/screens/UScreenStatMain.pas index 2fd91288..204f40cd 100644 --- a/cmake/src/screens/UScreenStatMain.pas +++ b/cmake/src/screens/UScreenStatMain.pas @@ -47,14 +47,14 @@ type private //Some Stat Value that don't need to be calculated 2 times SongsWithVid: cardinal; - function FormatOverviewIntro(FormatStr: string): string; - function FormatSongOverview(FormatStr: string): string; - function FormatPlayerOverview(FormatStr: string): string; + function FormatOverviewIntro(FormatStr: UTF8String): UTF8String; + function FormatSongOverview(FormatStr: UTF8String): UTF8String; + function FormatPlayerOverview(FormatStr: UTF8String): UTF8String; public TextOverview: integer; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - procedure onShow; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; + procedure OnShow; override; procedure SetAnimationProgress(Progress: real); override; procedure SetOverview; @@ -70,21 +70,17 @@ uses ULanguage, UCommon, Classes, - {$IFDEF win32} - windows, - {$ELSE} - sysconst, - {$ENDIF} - ULog; - -function TScreenStatMain.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; + ULog, + UUnicodeUtils; + +function TScreenStatMain.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if (PressedDown) then begin // Key Down // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -170,11 +166,11 @@ begin //Set Songs with Vid SongsWithVid := 0; for I := 0 to Songs.SongList.Count -1 do - if (TSong(Songs.SongList[I]).Video <> '') then + if (TSong(Songs.SongList[I]).Video.IsSet) then Inc(SongsWithVid); end; -procedure TScreenStatMain.onShow; +procedure TScreenStatMain.OnShow; begin inherited; @@ -182,7 +178,7 @@ begin SetOverview; end; -function TScreenStatMain.FormatOverviewIntro(FormatStr: string): string; +function TScreenStatMain.FormatOverviewIntro(FormatStr: UTF8String): UTF8String; var Year, Month, Day: word; begin @@ -203,10 +199,10 @@ begin end; end; -function TScreenStatMain.FormatSongOverview(FormatStr: string): string; +function TScreenStatMain.FormatSongOverview(FormatStr: UTF8String): UTF8String; var CntSongs, CntSungSongs, CntVidSongs: integer; - MostPopSongArtist, MostPopSongTitle: string; + MostPopSongArtist, MostPopSongTitle: UTF8String; StatList: TList; MostSungSong: TStatResultMostSungSong; begin @@ -247,12 +243,12 @@ begin end; end; -function TScreenStatMain.FormatPlayerOverview(FormatStr: string): string; +function TScreenStatMain.FormatPlayerOverview(FormatStr: UTF8String): UTF8String; var CntPlayers: integer; BestScoreStat: TStatResultBestScores; BestSingerStat: TStatResultBestSingers; - BestPlayer, BestScorePlayer: string; + BestPlayer, BestScorePlayer: UTF8String; BestPlayerScore, BestScore: integer; SingerStats, ScoreStats: TList; begin @@ -307,7 +303,7 @@ end; procedure TScreenStatMain.SetOverview; var - Overview: string; + Overview: UTF8String; begin // Format overview Overview := FormatOverviewIntro(Language.Translate('STAT_OVERVIEW_INTRO')) + '\n \n' + diff --git a/cmake/src/screens/UScreenTop5.pas b/cmake/src/screens/UScreenTop5.pas index 1013a9b5..705d1e35 100644 --- a/cmake/src/screens/UScreenTop5.pas +++ b/cmake/src/screens/UScreenTop5.pas @@ -47,18 +47,21 @@ type public TextLevel: integer; TextArtistTitle: integer; + DifficultyShow: integer; StaticNumber: array[1..5] of integer; TextNumber: array[1..5] of integer; TextName: array[1..5] of integer; TextScore: array[1..5] of integer; + TextDate: array[1..5] of integer; Fadeout: boolean; constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; + function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; function ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; override; - procedure onShow; override; + procedure OnShow; override; + procedure DrawScores(difficulty: integer); function Draw: boolean; override; end; @@ -67,19 +70,19 @@ implementation uses UDataBase, UGraphic, + UMain, UIni, - UNote; + UNote, + UUnicodeUtils; -function TScreenTop5.ParseInput(PressedKey: cardinal; - CharCode: WideChar; - PressedDown: boolean): boolean; +function TScreenTop5.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin Result := true; if PressedDown then begin // check normal keys - case WideCharUpperCase(CharCode)[1] of - 'Q': + case UCS4UpperCase(CharCode) of + Ord('Q'): begin Result := false; Exit; @@ -98,6 +101,34 @@ begin Fadeout := true; end; end; + SDLK_RIGHT: + begin + inc(DifficultyShow); + if (DifficultyShow>2) then + DifficultyShow:=0; + DrawScores(DifficultyShow); + end; + SDLK_LEFT: + begin + dec(DifficultyShow); + if (DifficultyShow<0) then + DifficultyShow:=2; + DrawScores(DifficultyShow); + end; + SDLK_UP: + begin + inc(DifficultyShow); + if (DifficultyShow>2) then + DifficultyShow:=0; + DrawScores(DifficultyShow); + end; + SDLK_DOWN: + begin + dec(DifficultyShow); + if (DifficultyShow<0) then + DifficultyShow:=2; + DrawScores(DifficultyShow); + end; SDLK_SYSREQ: begin Display.SaveScreenShot; @@ -113,7 +144,7 @@ begin Result := true; if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then //left-click anywhere sends return - ParseInput(SDLK_RETURN, #0, true); + ParseInput(SDLK_RETURN, 0, true); end; constructor TScreenTop5.Create; @@ -133,18 +164,22 @@ begin TextNumber[I+1] := AddText (Theme.Top5.TextNumber[I]); TextName[I+1] := AddText (Theme.Top5.TextName[I]); TextScore[I+1] := AddText (Theme.Top5.TextScore[I]); + TextDate[I+1] := AddText (Theme.Top5.TextDate[I]); end; end; -procedure TScreenTop5.onShow; +procedure TScreenTop5.OnShow; var I: integer; PMax: integer; + sung: boolean; //score added? otherwise in wasn't sung! begin inherited; + sung := false; Fadeout := false; + DifficultyShow := Ini.Difficulty; //ReadScore(CurrentSong); @@ -152,35 +187,74 @@ begin if PMax = 4 then PMax := 5; for I := 0 to PMax do - DataBase.AddScore(CurrentSong, Ini.Difficulty, Ini.Name[I], Round(Player[I].ScoreTotalInt)); + begin + if (Round(Player[I].ScoreTotalInt) > 0) and (ScreenSing.SungToEnd) then + begin + DataBase.AddScore(CurrentSong, Ini.Difficulty, Ini.Name[I], Round(Player[I].ScoreTotalInt)); + sung:=true; + end; + end; - DataBase.WriteScore(CurrentSong); + if sung then + DataBase.WriteScore(CurrentSong); DataBase.ReadScore(CurrentSong); Text[TextArtistTitle].Text := CurrentSong.Artist + ' - ' + CurrentSong.Title; for I := 1 to Length(CurrentSong.Score[Ini.Difficulty]) do begin - Static[StaticNumber[I]].Visible := true; + Statics[StaticNumber[I]].Visible := true; Text[TextNumber[I]].Visible := true; Text[TextName[I]].Visible := true; Text[TextScore[I]].Visible := true; + Text[TextDate[I]].Visible := true; Text[TextName[I]].Text := CurrentSong.Score[Ini.Difficulty, I-1].Name; Text[TextScore[I]].Text := IntToStr(CurrentSong.Score[Ini.Difficulty, I-1].Score); + Text[TextDate[I]].Text := CurrentSong.Score[Ini.Difficulty, I-1].Date; end; for I := Length(CurrentSong.Score[Ini.Difficulty]) + 1 to 5 do begin - Static[StaticNumber[I]].Visible := false; + Statics[StaticNumber[I]].Visible := false; Text[TextNumber[I]].Visible := false; Text[TextName[I]].Visible := false; Text[TextScore[I]].Visible := false; + Text[TextDate[I]].Visible := false; end; Text[TextLevel].Text := IDifficulty[Ini.Difficulty]; end; +procedure TScreenTop5.DrawScores(difficulty: integer); +var + I: integer; +begin + for I := 1 to Length(CurrentSong.Score[difficulty]) do + begin + Statics[StaticNumber[I]].Visible := true; + Text[TextNumber[I]].Visible := true; + Text[TextName[I]].Visible := true; + Text[TextScore[I]].Visible := true; + Text[TextDate[I]].Visible := true; + + Text[TextName[I]].Text := CurrentSong.Score[difficulty, I-1].Name; + Text[TextScore[I]].Text := IntToStr(CurrentSong.Score[difficulty, I-1].Score); + Text[TextDate[I]].Text := CurrentSong.Score[difficulty, I-1].Date; + end; + + for I := Length(CurrentSong.Score[difficulty]) + 1 to 5 do + begin + Statics[StaticNumber[I]].Visible := false; + Text[TextNumber[I]].Visible := false; + Text[TextName[I]].Visible := false; + Text[TextScore[I]].Visible := false; + Text[TextDate[I]].Visible := false; + end; + + Text[TextLevel].Text := IDifficulty[difficulty]; +end; + function TScreenTop5.Draw: boolean; //var { @@ -208,18 +282,18 @@ begin if ScreenAct = 1 then begin LoadColor( - Static[StaticBoxLightest[Item]].Texture.ColR, - Static[StaticBoxLightest[Item]].Texture.ColG, - Static[StaticBoxLightest[Item]].Texture.ColB, + Statics[StaticBoxLightest[Item]].Texture.ColR, + Statics[StaticBoxLightest[Item]].Texture.ColG, + Statics[StaticBoxLightest[Item]].Texture.ColB, 'P1Dark'); end; if ScreenAct = 2 then begin LoadColor( - Static[StaticBoxLightest[Item]].Texture.ColR, - Static[StaticBoxLightest[Item]].Texture.ColG, - Static[StaticBoxLightest[Item]].Texture.ColB, + Statics[StaticBoxLightest[Item]].Texture.ColR, + Statics[StaticBoxLightest[Item]].Texture.ColG, + Statics[StaticBoxLightest[Item]].Texture.ColB, 'P4Dark'); end; } diff --git a/cmake/src/screens/UScreenWelcome.pas b/cmake/src/screens/UScreenWelcome.pas deleted file mode 100644 index a00a84e2..00000000 --- a/cmake/src/screens/UScreenWelcome.pas +++ /dev/null @@ -1,164 +0,0 @@ -{* UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - *} - -unit UScreenWelcome; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -{$I switches.inc} - -uses - UMenu, - SDL, - SysUtils, - UThemes; - -type - TScreenWelcome = class(TMenu) - public - Animation: real; - Fadeout: boolean; - constructor Create; override; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; override; - function Draw: boolean; override; - procedure onShow; override; - end; - -implementation - -uses - UGraphic, - UTime, - USkins, - UTexture; - -function TScreenWelcome.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; -begin - Result := true; - if (PressedDown) then - begin - case PressedKey of - SDLK_ESCAPE, - SDLK_BACKSPACE : - begin - Result := false; - end; - SDLK_RETURN: - begin - FadeTo(@ScreenMain); - Fadeout := true; - end; - end; - end; -end; - -constructor TScreenWelcome.Create; -begin - inherited Create; - AddStatic(-10, -10, 0, 0, 1, 1, 1, Skin.GetTextureFileName('ButtonAlt'), TEXTURE_TYPE_TRANSPARENT); - AddStatic(-500, 440, 200, 5, 0, 0, 0, Skin.GetTextureFileName('Rectangle'), TEXTURE_TYPE_COLORIZED); - AddStatic(-500, 472, 200, 5, 0, 0, 0, Skin.GetTextureFileName('Rectangle'), TEXTURE_TYPE_COLORIZED); - AddStatic(-500, 504, 200, 5, 0, 0, 0, Skin.GetTextureFileName('Rectangle'), TEXTURE_TYPE_COLORIZED); - AddStatic(-500, 536, 200, 5, 0, 0, 0, Skin.GetTextureFileName('Rectangle'), TEXTURE_TYPE_COLORIZED); - AddStatic(-500, 568, 200, 5, 0, 0, 0, Skin.GetTextureFileName('Rectangle'), TEXTURE_TYPE_COLORIZED); - Animation := 0; - Fadeout := false; -end; - -procedure TScreenWelcome.onShow; -begin - inherited; - - CountSkipTimeSet; -end; - -function TScreenWelcome.Draw: boolean; -var - Min: real; - Max: real; - Factor: real; - Count: integer; -begin - // star animation - Animation := Animation + TimeSkip*1000; - - // draw nothing - Min := 0; Max := 1000; - if (Animation >= Min) and (Animation < Max) then - begin - end; - - // popup - Min := 1000; Max := 1120; - if (Animation >= Min) and (Animation < Max) then - begin - Factor := (Animation - Min) / (Max - Min); - Static[0].Texture.X := 600; - Static[0].Texture.Y := 600 - Factor * 230; - Static[0].Texture.W := 200; - Static[0].Texture.H := Factor * 230; - end; - - // bounce - Min := 1120; Max := 1200; - if (Animation >= Min) and (Animation < Max) then - begin - Factor := (Animation - Min) / (Max - Min); - Static[0].Texture.Y := 370 + Factor * 50; - Static[0].Texture.H := 230 - Factor * 50; - end; - - // run - Min := 1500; Max := 3500; - if (Animation >= Min) and (Animation < Max) then - begin - Factor := (Animation - Min) / (Max - Min); - - Static[0].Texture.X := 600 - Factor * 1400; - Static[0].Texture.H := 180; - - for Count := 1 to 5 do - begin - Static[Count].Texture.X := 770 - Factor * 1400; - Static[Count].Texture.W := 150 + Factor * 200; - Static[Count].Texture.Alpha := Factor * 0.5; - end; - end; - - Min := 3500; - if (Animation >= Min) and (not Fadeout) then - begin - FadeTo(@ScreenMain); - Fadeout := true; - end; - - Result := inherited Draw; -end; - -end. -- cgit v1.2.3