Skip to content

Commit 14b179d

Browse files
committed
Add generic player layout theme support
1 parent 9f259d0 commit 14b179d

2 files changed

Lines changed: 682 additions & 75 deletions

File tree

src/base/UIni.pas

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ TInputDeviceConfig = record
9393
IPlayers: array[0..4] of UTF8String = ('1', '2', '3', '4', '6');
9494
IPlayersVals: array[0..4] of integer = ( 1 , 2 , 3 , 4 , 6 );
9595

96+
function TryGetMixedPlayerColorPair(ColorIndex: integer; out LeftColor, RightColor: integer): boolean;
97+
9698
type
9799

98100
//Options
@@ -616,6 +618,50 @@ TSafeIniFile = class(TIniFile)
616618

617619
const
618620
IGNORE_INDEX = -1;
621+
BASE_PLAYER_COLOR_COUNT = 16;
622+
623+
function TryGetMixedPlayerColorPair(ColorIndex: integer; out LeftColor, RightColor: integer): boolean;
624+
var
625+
Remaining: integer;
626+
Sum: integer;
627+
LeftCandidate: integer;
628+
RightCandidate: integer;
629+
begin
630+
Result := false;
631+
LeftColor := 0;
632+
RightColor := 0;
633+
634+
if ColorIndex <= BASE_PLAYER_COLOR_COUNT then
635+
Exit;
636+
637+
Remaining := ColorIndex - BASE_PLAYER_COLOR_COUNT;
638+
for Sum := BASE_PLAYER_COLOR_COUNT + 1 to BASE_PLAYER_COLOR_COUNT * 2 - 1 do
639+
begin
640+
LeftCandidate := Sum - BASE_PLAYER_COLOR_COUNT;
641+
if LeftCandidate < 1 then
642+
LeftCandidate := 1;
643+
while LeftCandidate <= ((Sum - 1) div 2) do
644+
begin
645+
RightCandidate := Sum - LeftCandidate;
646+
if LeftCandidate >= RightCandidate then
647+
begin
648+
Inc(LeftCandidate);
649+
Continue;
650+
end;
651+
652+
Dec(Remaining);
653+
if Remaining = 0 then
654+
begin
655+
LeftColor := LeftCandidate;
656+
RightColor := RightCandidate;
657+
Result := true;
658+
Exit;
659+
end;
660+
661+
Inc(LeftCandidate);
662+
end;
663+
end;
664+
end;
619665

620666
constructor TSafeIniFile.Create(const FileName, LogSource: string);
621667
begin

0 commit comments

Comments
 (0)