Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
497 changes: 409 additions & 88 deletions src/base/UAvatars.pas

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/base/UCommon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ procedure FreeAlignedMem(P: pointer);
function Equals(A, B: string; CaseSensitive: boolean = false): Boolean; overload;

function GetArrayIndex(const SearchArray: array of UTF8String; Value: string; CaseInsensitiv: boolean = false): integer; overload;
function GetArrayIndex(const SearchArray: array of string; Value: string; CaseInsensitiv: boolean = false): integer; overload;
function GetArrayIndex(const SearchArray: array of integer; Value: integer): integer; overload;

function ParseResolutionString(const ResolutionString: string; out x, y: integer): boolean;
Expand Down Expand Up @@ -635,11 +634,6 @@ function GetArrayIndex(const SearchArray: array of UTF8String; Value: string;
end;
end;

function GetArrayIndex(const SearchArray: array of string; Value: string; CaseInsensitiv: boolean = false): integer;
begin
Result := GetArrayIndex(SearchArray, Value, CaseInsensitiv);
end;

(**
* Returns the index of Value in SearchArray
* or -1 if Value is not in SearchArray.
Expand Down
104 changes: 67 additions & 37 deletions src/base/UIni.pas
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TInputDeviceConfig = record
DEFAULT_RESOLUTION = '800x600';
IMaxPlayerCount = 6;
IPlayers: array[0..4] of UTF8String = ('1', '2', '3', '4', '6');
IPlayersVals: array[0..4] of integer = (1, 2, 3, 4, 6);

type

Expand Down Expand Up @@ -101,13 +102,13 @@ TIni = class
procedure LoadWebcamSettings(IniFile: TCustomIniFile);
public
// Players or Teams colors
SingColor: array[0..(IMaxPlayerCount-1)] of integer; //FIXME remove this variable in all files
SingColor: array[0..(IMaxPlayerCount-1)] of integer;

Name: array[0..(IMaxPlayerCount-1)] of UTF8String;
PlayerColor: array[0..(IMaxPlayerCount-1)] of integer;
TeamColor: array[0..2] of integer;

PlayerAvatar: array[0..(IMaxPlayerCount-1)] of string;
PlayerAvatar: array[0..(IMaxPlayerCount-1)] of UTF8String;
PlayerLevel: array[0..(IMaxPlayerCount-1)] of integer;

// Templates for Names Mod
Expand Down Expand Up @@ -229,19 +230,15 @@ TIni = class
procedure Save();
procedure SaveNames();
procedure SaveLevel();
procedure SavePlayers(
TotalNumber: integer;
Names: array of UTF8String;
Colors: array of integer;
Levels: array of integer;
AvatarButtonsMd5: array of string;
Avatars: array of integer
);
procedure SavePlayerColors();
procedure SavePlayerAvatars();
procedure SavePlayerLevels();
procedure SaveTeamColors();
procedure SaveShowWebScore();
procedure SaveJukeboxSongMenu();
procedure SaveSoundFont(Name: string);
procedure SaveWebcamSettings();
procedure SaveNumberOfPlayers();
procedure SaveSingTimebarMode();
procedure SaveJukeboxTimebarMode();
procedure SaveJukeboxRepeatSongList();
Expand Down Expand Up @@ -846,10 +843,13 @@ procedure TIni.Load();

for I := 0 to IMaxPlayerCount-1 do
begin
// Name
Name[I] := IniFile.ReadString('Name', 'P'+IntToStr(I+1), 'Player'+IntToStr(I+1));
// Color Player
PlayerColor[I] := IniFile.ReadInteger('PlayerColor', 'P'+IntToStr(I+1), I + 1);
Self.SingColor[I] := Self.PlayerColor[I];
// Avatar Player
PlayerAvatar[I] := IniFile.ReadString('PlayerAvatar', 'P'+IntToStr(I+1), '');
// Level Player
PlayerLevel[I] := IniFile.ReadInteger('PlayerLevel', 'P'+IntToStr(I+1), 0);
end;

Expand Down Expand Up @@ -1317,39 +1317,54 @@ procedure TIni.SaveShowWebScore;
end;


procedure TIni.SavePlayers(
TotalNumber: integer;
Names: array of UTF8String;
Colors: array of integer;
Levels: array of integer;
AvatarButtonsMd5: array of string;
Avatars: array of integer
);
procedure TIni.SavePlayerColors;

var
IniFile: TIniFile;
I, J: integer;
PlayerNumber: string;
I: integer;
begin
if not Filename.IsReadOnly() then
begin
Self.Players := TotalNumber;
IniFile := TIniFile.Create(Filename.ToNative);
IniFile.WriteString('Game', 'Players', IPlayers[Players]);

//Colors for Names Mod
for I := 1 to IMaxPlayerCount do
begin
J := I - 1;
Self.Name[J] := Names[J];
Self.PlayerAvatar[J] := AvatarButtonsMd5[Avatars[J]];
Self.PlayerColor[J] := Colors[J];
Self.PlayerLevel[J] := Levels[J];
Self.SingColor[J] := Colors[J];
PlayerNumber := 'P' + IntToStr(I);
IniFile.WriteString('Name', PlayerNumber, Self.Name[J]);
IniFile.WriteString('PlayerAvatar', PlayerNumber, Self.PlayerAvatar[J]);
IniFile.WriteString('PlayerColor', PlayerNumber, IntToStr(Self.PlayerColor[J]));
IniFile.WriteInteger('PlayerLevel', PlayerNumber, Levels[J]);
end;
IniFile.Free();
IniFile.WriteString('PlayerColor', 'P' + IntToStr(I), IntToStr(PlayerColor[I-1]));

IniFile.Free;
end;
end;

procedure TIni.SavePlayerAvatars;
var
IniFile: TIniFile;
I: integer;
begin
if not Filename.IsReadOnly() then
begin
IniFile := TIniFile.Create(Filename.ToNative);

//Colors for Names Mod
for I := 1 to IMaxPlayerCount do
IniFile.WriteString('PlayerAvatar', 'P' + IntToStr(I), PlayerAvatar[I-1]);

IniFile.Free;
end;
end;

procedure TIni.SavePlayerLevels;
var
IniFile: TIniFile;
I: integer;
begin
if not Filename.IsReadOnly() then
begin
IniFile := TIniFile.Create(Filename.ToNative);

for I := 1 to IMaxPlayerCount do
IniFile.WriteInteger('PlayerLevel', 'P' + IntToStr(I), PlayerLevel[I-1]);

IniFile.Free;
end;
end;

Expand Down Expand Up @@ -1401,6 +1416,21 @@ procedure TIni.SaveWebcamSettings;

end;

procedure TIni.SaveNumberOfPlayers;
var
IniFile: TIniFile;
begin
if not Filename.IsReadOnly() then
begin
IniFile := TIniFile.Create(Filename.ToNative);

// Players
IniFile.WriteString('Game', 'Players', IPlayers[Players]);

IniFile.Free;
end;
end;

procedure TIni.SaveSingTimebarMode;
var
IniFile: TIniFile;
Expand Down
7 changes: 6 additions & 1 deletion src/base/UMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,14 @@ procedure Main;
USongs.CatSongs := TCatSongs.Create();
USongs.Songs := TSongs.Create(); //in a new thread

// Theme
UThemes.Theme.LoadTheme(Ini.Theme, Ini.Color);

//avatars cache
UAvatars.Avatars := TAvatarDatabase.Create();

// Graphics
UGraphic.Initialize3D(WindowTitle);
UAvatars.SetAvatarsList();

UMusic.InitializeSound();
UMusic.InitializeVideo();
Expand Down
1 change: 1 addition & 0 deletions src/base/UMusic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ TAudioOutputDevice = class
function Length: real;

function Open(const Filename: IPath): boolean; // true if succeed
function OpenWithInstrum(const Filename: IPath; const InstrumFilename: IPath): boolean; // true if succeed
procedure Close;

procedure Play;
Expand Down
13 changes: 12 additions & 1 deletion src/base/USong.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ TSong = class
// filenames
Cover: IPath;
Mp3: IPath;
Instrum: IPath;
Background: IPath;
Video: IPath;

Expand Down Expand Up @@ -215,6 +216,7 @@ constructor TSong.Create();
Self.FileName := PATH_NONE();
Self.Cover := PATH_NONE();
Self.Mp3 := PATH_NONE();
Self.Instrum := PATH_NONE();
Self.Background:= PATH_NONE();
Self.Video := PATH_NONE();
end;
Expand Down Expand Up @@ -277,12 +279,13 @@ constructor TSong.Create(const aFileName: IPath);
Self.Year := 0;
if (not FileSystem.FileAge(aFileName, Self.FileDate)) then
Self.FileDate := 0;

// set to default encoding
Self.Encoding := Ini.DefaultEncoding;

//Required Information
Self.Mp3 := PATH_NONE;
Self.Instrum := PATH_NONE;
Self.BPM := 0;
Self.GAP := 0;
Self.Start := 0;
Expand Down Expand Up @@ -672,6 +675,14 @@ function TSong.ReadTxtHeader(): boolean;
else
Log.LogError('Can''t find audio file in song: '+Self.FullPath);
end;
'INSTRUM': //sound source file
begin
EncFile := DecodeFilename(Value);
if (Self.Path.Append(EncFile).IsFile()) then
begin
Self.Instrum := EncFile;
end
end;
'BPM': //beats per minute
begin
Self.BPM := StrToFloatI18n(Value)*4;
Expand Down
36 changes: 32 additions & 4 deletions src/media/UAudioPlaybackBase.pas
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{*
UltraStar WorldParty - Karaoke Game
UltraStar WorldParty is the legal property of its developers,
whose names are too numerous to list here. Please refer to the

UltraStar WorldParty 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
Expand All @@ -16,7 +16,7 @@
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. Check "LICENSE" file. If not, see
along with this program. Check "LICENSE" file. If not, see
<http://www.gnu.org/licenses/>.
*}

Expand Down Expand Up @@ -61,6 +61,7 @@ TAudioPlaybackBase = class(TInterfacedObject, IAudioPlayback)
function GetName: string; virtual; abstract;

function Open(const Filename: IPath): boolean; // true if succeed
function OpenWithInstrum(const Filename: IPath; const InstrumFilename: IPath): boolean; // true if succeed
procedure Close;

procedure Play;
Expand Down Expand Up @@ -169,6 +170,33 @@ function TAudioPlaybackBase.Open(const Filename: IPath): boolean;
Result := true;
end;

function TAudioPlaybackBase.OpenWithInstrum(const Filename: IPath; const InstrumFilename: IPath): boolean;
var
customInstrum: boolean;
begin
// free old MusicStream
MusicStream.Free;

customInstrum := doVoiceRemoval and InstrumFilename.IsSet();
if customInstrum then
MusicStream := OpenStream(InstrumFilename);
if not customInstrum or not assigned(MusicStream) then
begin
MusicStream := OpenStream(Filename);
customInstrum := false;
end;
if not assigned(MusicStream) then
begin
Result := false;
Exit;
end;

if doVoiceRemoval and not customInstrum then MusicStream.AddSoundEffect(TVoiceRemoval.Create());
if assigned(IReplayGain) and IReplayGain.CanEnable then MusicStream.AddSoundFX(IReplayGain.Create());

Result := true;
end;

procedure TAudioPlaybackBase.Close;
begin
FreeAndNil(MusicStream);
Expand Down
8 changes: 7 additions & 1 deletion src/screens/UScreenPartyPlayer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ procedure TScreenPartyPlayer.UpdateParty;
Party.AddPlayer(I, Button[I * 5 + 1 + J].Text[0].Text);

// no avatar on Party
UAvatars.GetAvatarsList().LoadConfig(true);
AvatarPlayerTextures[I + 1] := NoAvatarTexture[I + 1];

Col := GetPlayerColor(Num[I]);

AvatarPlayerTextures[I + 1].ColR := Col.R;
AvatarPlayerTextures[I + 1].ColG := Col.G;
AvatarPlayerTextures[I + 1].ColB := Col.B;
end;


Expand Down
Loading