From 5ed6620bad808381fce94f2cd67ee911b4d45bff Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 21 Mar 2007 19:19:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 335 ++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 Game/Code/Menu/UMenuSelectSlide.pas (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas new file mode 100644 index 00000000..7850cdf6 --- /dev/null +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -0,0 +1,335 @@ +unit UMenuSelectSlide; + +interface +uses TextGL, UTexture, OpenGL12, UMenuText; + +type + PSelectSlide = ^TSelectSlide; + TSelectSlide = class + private + SelectBool: boolean; + public + // objects + Text: TText; // Main text describing option + TextOpt: array of TText; // 3 texts in the position of possible options + TextOptT: array of string; // array of names for possible options + + Texture: TTexture; // Select Texture + TextureSBG: TTexture; // Background Selections Texture +// TextureS: array of TTexture; // Selections Texture (not used) + +// TextureArrowL: TTexture; // Texture for left arrow (not used yet) +// TextureArrowR: TTexture; // Texture for right arrow (not used yet) + + SelectOptInt: integer; + PData: ^integer; + + //For automatically Setting LineCount + Lines: Byte; + + //Visibility + Visible: Boolean; + + // for selection and deselection + // main static + ColR: real; + ColG: real; + ColB: real; + Int: real; + DColR: real; + DColG: real; + DColB: real; + DInt: real; + + // main text + TColR: real; + TColG: real; + TColB: real; + TInt: real; + TDColR: real; + TDColG: real; + TDColB: real; + TDInt: real; + + // selection background static + SBGColR: real; + SBGColG: real; + SBGColB: real; + SBGInt: real; + SBGDColR: real; + SBGDColG: real; + SBGDColB: real; + SBGDInt: real; + + // selection text + STColR: real; + STColG: real; + STColB: real; + STInt: real; + STDColR: real; + STDColG: real; + STDColB: real; + STDInt: real; + + // position and size + property X: real read Texture.x write Texture.x; + property Y: real read Texture.y write Texture.y; + property W: real read Texture.w write Texture.w; + property H: real read Texture.h write Texture.h; +// property X2: real read Texture2.x write Texture2.x; +// property Y2: real read Texture2.y write Texture2.y; +// property W2: real read Texture2.w write Texture2.w; +// property H2: real read Texture2.h write Texture2.h; + + // procedures + procedure SetSelect(Value: boolean); + property Selected: Boolean read SelectBool write SetSelect; + procedure SetSelectOpt(Value: integer); + property SelectedOption: integer read SelectOptInt write SetSelectOpt; + procedure Draw; + constructor Create; + + //Automatically Generate Lines (Texts) + procedure genLines; + end; + +implementation +uses UDrawTexture, math, ULog, SysUtils; + +// ------------ Select +constructor TSelectSlide.Create; +begin + inherited Create; + Text := TText.Create; + SetLength(TextOpt, 1); + TextOpt[0] := TText.Create; + + Visible := True; + {SetLength(TextOpt, 3); + TextOpt[0] := TText.Create; + TextOpt[1] := TText.Create; + TextOpt[2] := TText.Create;} +end; + +procedure TSelectSlide.SetSelect(Value: boolean); +var + SO: integer; + I: integer; +begin + SelectBool := Value; + if Value then begin + Texture.ColR := ColR; + Texture.ColG := ColG; + Texture.ColB := ColB; + Texture.Int := Int; + + Text.ColR := TColR; + Text.ColG := TColG; + Text.ColB := TColB; + Text.Int := TInt; + + TextureSBG.ColR := SBGColR; + TextureSBG.ColG := SBGColG; + TextureSBG.ColB := SBGColB; + TextureSBG.Int := SBGInt; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STColR; + TextOpt[I].ColG := STColG; + TextOpt[I].ColB := STColB; + TextOpt[I].Int := STInt; + end;} + + end else begin + Texture.ColR := DColR; + Texture.ColG := DColG; + Texture.ColB := DColB; + Texture.Int := DInt; + + Text.ColR := TDColR; + Text.ColG := TDColG; + Text.ColB := TDColB; + Text.Int := TDInt; + + TextureSBG.ColR := SBGDColR; + TextureSBG.ColG := SBGDColG; + TextureSBG.ColB := SBGDColB; + TextureSBG.Int := SBGDInt; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + end;} + end; +end; + +procedure TSelectSlide.SetSelectOpt(Value: integer); +var + SO: integer; + Sel: integer; + HalfL: integer; + HalfR: integer; + +procedure DoSelection(Sel: Cardinal); + var I: Integer; + begin + for I := low(TextOpt) to high(TextOpt) do + begin + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + end; + if (Sel <= high(TextOpt)) then + begin + TextOpt[Sel].ColR := STColR; + TextOpt[Sel].ColG := STColG; + TextOpt[Sel].ColB := STColB; + TextOpt[Sel].Int := STInt; + end; + end; +begin + SelectOptInt := Value; + PData^ := Value; +// SetSelect(true); // reset all colors + + if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then + begin + + if (Value <= 0) then + begin //First Option Selected + Value := 0; + + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(0); + end + else if (Value >= high(TextOptT)) then + begin //Last Option Selected + Value := high(TextOptT); + + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + DoSelection(Lines-1); + end + else + begin + HalfL := Ceil((Lines-1)/2); + HalfR := Lines-1-HalfL; + + if (Value <= HalfL) then + begin //Selected Option is near to the left side + {HalfL := Value; + HalfR := Lines-1-HalfL;} + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(Value); + end + else if (Value > High(TextOptT)-HalfR) then + begin //Selected is too near to the right border + HalfR := high(TextOptT) - Value; + HalfL := Lines-1-HalfR; + //Change Texts + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + + DoSelection (HalfL); + end + else + begin + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + end; + + DoSelection(HalfL); + end; + + end; + + end; + +end; + +procedure TSelectSlide.Draw; +var + SO: integer; +begin + if Visible then + begin + DrawTexture(Texture); + DrawTexture(TextureSBG); + + Text.Draw; + + for SO := low(TextOpt) to high(TextOpt) do + TextOpt[SO].Draw; + end; +end; + +procedure TSelectSlide.GenLines; +var +maxlength: Real; +I: Integer; +begin + SetFontStyle(TextOpt[0].Style); + SetFontSize(TextOpt[0].Size); + maxlength := 0; + + for I := low(TextOptT) to high (TextOptT) do + begin + if (glTextWidth(PChar(TextOptT[I])) > maxlength) then + maxlength := glTextWidth(PChar(TextOptT[I])); + end; + + Lines := floor((TextureSBG.W-40) / (maxlength+7)); + if (Lines > Length(TextOptT)) then + Lines := Length(TextOptT); + + if (Lines <= 0) then + Lines := 1; + + setLength (TextOpt, Lines); + + for I := low(TextOpt) to high(TextOpt) do + begin + + //TextOpt[I] := TextOpt[0]; + TextOpt[I] := TText.Create; + TextOpt[I].Size := 10; + //TextOpt[I].Align := 1; + TextOpt[I].Align := 0; + TextOpt[I].Visible := True; + + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + + //Generate Positions + //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I; + TextOpt[I].Y := TextureSBG.Y + 20; + + //Better Look with 2 Options + if (Lines=2) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; + end; + //TextOpt[I] := TextOpt[0]; +end; + +end. -- cgit v1.2.3 From e0e16a3b1d28cf51fecf669d42465cf2a65728f3 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 29 Mar 2007 16:54:52 +0000 Subject: Added SBGW to TSelectSlide: Defining the Width of the Selections BG Added W to TText + Pagebreaks. If Width is given the Text breaks at the given width. Breaks are not generated perfect yet, needs some tuning. Changed all affected Screens to fit the new TText Component git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@49 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index 7850cdf6..9885acc0 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -81,6 +81,8 @@ type // property W2: real read Texture2.w write Texture2.w; // property H2: real read Texture2.h write Texture2.h; + property SBGW: real read TextureSBG.w write TextureSBG.w; + // procedures procedure SetSelect(Value: boolean); property Selected: Boolean read SelectBool write SetSelect; @@ -104,6 +106,9 @@ begin SetLength(TextOpt, 1); TextOpt[0] := TText.Create; + //Set Standard Width for Selections Background + SBGW := 450; + Visible := True; {SetLength(TextOpt, 3); TextOpt[0] := TText.Create; @@ -326,7 +331,7 @@ begin TextOpt[I].Y := TextureSBG.Y + 20; //Better Look with 2 Options - if (Lines=2) then + if (Lines=2) AND (Length(TextOptT)= 2) then TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; end; //TextOpt[I] := TextOpt[0]; -- cgit v1.2.3 From 9b29c5321e423fbe6ba29f32bdcf8f2c83828e92 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 16 May 2007 18:18:37 +0000 Subject: Fixed text position of SelectSlide when High is not 70 Added ability to change Z and Textsize from SelectSlide Use new abilitys to finish SongMenu Screen in Deluxe Theme git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@196 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index 9885acc0..0149ea2b 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -315,7 +315,7 @@ begin //TextOpt[I] := TextOpt[0]; TextOpt[I] := TText.Create; - TextOpt[I].Size := 10; + TextOpt[I].Size := Text.Size; //TextOpt[I].Align := 1; TextOpt[I].Align := 0; TextOpt[I].Visible := True; @@ -328,7 +328,7 @@ begin //Generate Positions //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I; - TextOpt[I].Y := TextureSBG.Y + 20; + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; //Better Look with 2 Options if (Lines=2) AND (Length(TextOptT)= 2) then -- cgit v1.2.3 From dc72a49b4c680fe6698b831a203a9b00e476d562 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Fri, 1 Jun 2007 17:23:59 +0000 Subject: Fixed a Memory Bug in UMenuSelectSlide that causes memory that is not in use anymore is not freeed when the Attributes of a SelectSlide are Updated git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@240 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 43 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index 0149ea2b..f18b45cd 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -308,33 +308,34 @@ begin if (Lines <= 0) then Lines := 1; + //Free old Space used by Texts + For I := low(TextOpt) to high(TextOpt) do + TextOpt[I].Free; + setLength (TextOpt, Lines); for I := low(TextOpt) to high(TextOpt) do begin + TextOpt[I] := TText.Create; + TextOpt[I].Size := Text.Size; + //TextOpt[I].Align := 1; + TextOpt[I].Align := 0; + TextOpt[I].Visible := True; - //TextOpt[I] := TextOpt[0]; - TextOpt[I] := TText.Create; - TextOpt[I].Size := Text.Size; - //TextOpt[I].Align := 1; - TextOpt[I].Align := 0; - TextOpt[I].Visible := True; - - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - - //Generate Positions - //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I; - TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; - - //Better Look with 2 Options - if (Lines=2) AND (Length(TextOptT)= 2) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + + //Generate Positions + //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I; + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; + + //Better Look with 2 Options + if (Lines=2) AND (Length(TextOptT)= 2) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; end; - //TextOpt[I] := TextOpt[0]; end; end. -- cgit v1.2.3 From 141878175d76d013be3ec8fb9fd0a58dc9b0d3eb Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 9 Jun 2007 10:10:25 +0000 Subject: Added Preview Volume and Fading to Sound Options Changed Themes to Fit these changes Updated Language Files Some fixes in SelectSlide git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@251 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index f18b45cd..c1ccad6d 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -291,8 +291,8 @@ var maxlength: Real; I: Integer; begin - SetFontStyle(TextOpt[0].Style); - SetFontSize(TextOpt[0].Size); + SetFontStyle(0{Text.Style}); + SetFontSize(Text.Size); maxlength := 0; for I := low(TextOptT) to high (TextOptT) do @@ -329,7 +329,11 @@ begin //Generate Positions //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I; + if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I + else + TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; //Better Look with 2 Options -- cgit v1.2.3 From 247cbdca4eb8af228fa1753f1185e85077b5befa Mon Sep 17 00:00:00 2001 From: b1indy Date: Fri, 7 Sep 2007 21:09:02 +0000 Subject: UScreenSing.pas, UScreenSingModi.pas: removed Uffmpeg and USmpeg, added UVideo UGraphic.pas: prepared for possible loading animation UGraphicClasses.pas, ULCD.pas, ULight.pas, UMain.pas, USkins.pas, UDisplay.pas, UMenuButton.pas, UMenuSelect.pas, UMenuSelectSlide.pas, UMenuStatic.pas, UScreenCredits.pas, UScreenEditSub.pas, UScreenOpen.pas, UScreenPopup.pas: some fixes to get rid of some compiler infos/warnings git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@374 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index c1ccad6d..3659c00d 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -117,9 +117,9 @@ begin end; procedure TSelectSlide.SetSelect(Value: boolean); -var +{var SO: integer; - I: integer; + I: integer;} begin SelectBool := Value; if Value then begin @@ -187,7 +187,7 @@ procedure DoSelection(Sel: Cardinal); TextOpt[I].ColB := STDColB; TextOpt[I].Int := STDInt; end; - if (Sel <= high(TextOpt)) then + if (integer(Sel) <= high(TextOpt)) then begin TextOpt[Sel].ColR := STColR; TextOpt[Sel].ColG := STColG; -- cgit v1.2.3 From 433a1b7339e2bf96f3b0bb4c98b8c799c6540027 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Tue, 18 Sep 2007 13:19:20 +0000 Subject: changes in order to compile in lazarus... minor tidy ups and removal of big old comment blocks.. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@394 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index 3659c00d..bb9b5809 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -1,7 +1,15 @@ unit UMenuSelectSlide; interface -uses TextGL, UTexture, OpenGL12, UMenuText; + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +uses TextGL, + UTexture, + OpenGL12, + UMenuText; type PSelectSlide = ^TSelectSlide; -- cgit v1.2.3 From 391d30716d48dc709f6444b19c008e82311623b9 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 1 Nov 2007 19:34:40 +0000 Subject: Mac OS X version compiles and links. I hope I didn't break too many files on windows/linux. Added switches.inc to all files. Changed many IFDEFs. For Windows-only code please use MSWINDOWS instead of WIN32 now. WIN32 is also used by the Mac port. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@546 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index bb9b5809..e4c5f959 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -2,9 +2,7 @@ unit UMenuSelectSlide; interface -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} +{$I switches.inc} uses TextGL, UTexture, -- cgit v1.2.3 From 99955c78f63d1cb0d8bec666bc33953590a74c8a Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 1 Nov 2007 23:22:01 +0000 Subject: fixed failed builds build:USDX-LAZLIN-75 build:USDX-LAZLIN-76 for some reason we can not use {$MODE Delphi} in an included file. ( Probably because of the way the compier scopes this switch to each pas file ) ive had to revert this part of eddies changes. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@548 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuSelectSlide.pas | 706 ++++++++++++++++++------------------ 1 file changed, 355 insertions(+), 351 deletions(-) (limited to 'Game/Code/Menu/UMenuSelectSlide.pas') diff --git a/Game/Code/Menu/UMenuSelectSlide.pas b/Game/Code/Menu/UMenuSelectSlide.pas index e4c5f959..d52474e6 100644 --- a/Game/Code/Menu/UMenuSelectSlide.pas +++ b/Game/Code/Menu/UMenuSelectSlide.pas @@ -1,351 +1,355 @@ -unit UMenuSelectSlide; - -interface - -{$I switches.inc} - -uses TextGL, - UTexture, - OpenGL12, - UMenuText; - -type - PSelectSlide = ^TSelectSlide; - TSelectSlide = class - private - SelectBool: boolean; - public - // objects - Text: TText; // Main text describing option - TextOpt: array of TText; // 3 texts in the position of possible options - TextOptT: array of string; // array of names for possible options - - Texture: TTexture; // Select Texture - TextureSBG: TTexture; // Background Selections Texture -// TextureS: array of TTexture; // Selections Texture (not used) - -// TextureArrowL: TTexture; // Texture for left arrow (not used yet) -// TextureArrowR: TTexture; // Texture for right arrow (not used yet) - - SelectOptInt: integer; - PData: ^integer; - - //For automatically Setting LineCount - Lines: Byte; - - //Visibility - Visible: Boolean; - - // for selection and deselection - // main static - ColR: real; - ColG: real; - ColB: real; - Int: real; - DColR: real; - DColG: real; - DColB: real; - DInt: real; - - // main text - TColR: real; - TColG: real; - TColB: real; - TInt: real; - TDColR: real; - TDColG: real; - TDColB: real; - TDInt: real; - - // selection background static - SBGColR: real; - SBGColG: real; - SBGColB: real; - SBGInt: real; - SBGDColR: real; - SBGDColG: real; - SBGDColB: real; - SBGDInt: real; - - // selection text - STColR: real; - STColG: real; - STColB: real; - STInt: real; - STDColR: real; - STDColG: real; - STDColB: real; - STDInt: real; - - // position and size - property X: real read Texture.x write Texture.x; - property Y: real read Texture.y write Texture.y; - property W: real read Texture.w write Texture.w; - property H: real read Texture.h write Texture.h; -// property X2: real read Texture2.x write Texture2.x; -// property Y2: real read Texture2.y write Texture2.y; -// property W2: real read Texture2.w write Texture2.w; -// property H2: real read Texture2.h write Texture2.h; - - property SBGW: real read TextureSBG.w write TextureSBG.w; - - // procedures - procedure SetSelect(Value: boolean); - property Selected: Boolean read SelectBool write SetSelect; - procedure SetSelectOpt(Value: integer); - property SelectedOption: integer read SelectOptInt write SetSelectOpt; - procedure Draw; - constructor Create; - - //Automatically Generate Lines (Texts) - procedure genLines; - end; - -implementation -uses UDrawTexture, math, ULog, SysUtils; - -// ------------ Select -constructor TSelectSlide.Create; -begin - inherited Create; - Text := TText.Create; - SetLength(TextOpt, 1); - TextOpt[0] := TText.Create; - - //Set Standard Width for Selections Background - SBGW := 450; - - Visible := True; - {SetLength(TextOpt, 3); - TextOpt[0] := TText.Create; - TextOpt[1] := TText.Create; - TextOpt[2] := TText.Create;} -end; - -procedure TSelectSlide.SetSelect(Value: boolean); -{var - SO: integer; - I: integer;} -begin - SelectBool := Value; - if Value then begin - Texture.ColR := ColR; - Texture.ColG := ColG; - Texture.ColB := ColB; - Texture.Int := Int; - - Text.ColR := TColR; - Text.ColG := TColG; - Text.ColB := TColB; - Text.Int := TInt; - - TextureSBG.ColR := SBGColR; - TextureSBG.ColG := SBGColG; - TextureSBG.ColB := SBGColB; - TextureSBG.Int := SBGInt; - -{ for I := 0 to High(TextOpt) do begin - TextOpt[I].ColR := STColR; - TextOpt[I].ColG := STColG; - TextOpt[I].ColB := STColB; - TextOpt[I].Int := STInt; - end;} - - end else begin - Texture.ColR := DColR; - Texture.ColG := DColG; - Texture.ColB := DColB; - Texture.Int := DInt; - - Text.ColR := TDColR; - Text.ColG := TDColG; - Text.ColB := TDColB; - Text.Int := TDInt; - - TextureSBG.ColR := SBGDColR; - TextureSBG.ColG := SBGDColG; - TextureSBG.ColB := SBGDColB; - TextureSBG.Int := SBGDInt; - -{ for I := 0 to High(TextOpt) do begin - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - end;} - end; -end; - -procedure TSelectSlide.SetSelectOpt(Value: integer); -var - SO: integer; - Sel: integer; - HalfL: integer; - HalfR: integer; - -procedure DoSelection(Sel: Cardinal); - var I: Integer; - begin - for I := low(TextOpt) to high(TextOpt) do - begin - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - end; - if (integer(Sel) <= high(TextOpt)) then - begin - TextOpt[Sel].ColR := STColR; - TextOpt[Sel].ColG := STColG; - TextOpt[Sel].ColB := STColB; - TextOpt[Sel].Int := STInt; - end; - end; -begin - SelectOptInt := Value; - PData^ := Value; -// SetSelect(true); // reset all colors - - if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then - begin - - if (Value <= 0) then - begin //First Option Selected - Value := 0; - - for SO := low (TextOpt) to high(TextOpt) do - begin - TextOpt[SO].Text := TextOptT[SO]; - end; - - DoSelection(0); - end - else if (Value >= high(TextOptT)) then - begin //Last Option Selected - Value := high(TextOptT); - - for SO := high(TextOpt) downto low (TextOpt) do - begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; - end; - DoSelection(Lines-1); - end - else - begin - HalfL := Ceil((Lines-1)/2); - HalfR := Lines-1-HalfL; - - if (Value <= HalfL) then - begin //Selected Option is near to the left side - {HalfL := Value; - HalfR := Lines-1-HalfL;} - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do - begin - TextOpt[SO].Text := TextOptT[SO]; - end; - - DoSelection(Value); - end - else if (Value > High(TextOptT)-HalfR) then - begin //Selected is too near to the right border - HalfR := high(TextOptT) - Value; - HalfL := Lines-1-HalfR; - //Change Texts - for SO := high(TextOpt) downto low (TextOpt) do - begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; - end; - - DoSelection (HalfL); - end - else - begin - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do - begin - TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; - end; - - DoSelection(HalfL); - end; - - end; - - end; - -end; - -procedure TSelectSlide.Draw; -var - SO: integer; -begin - if Visible then - begin - DrawTexture(Texture); - DrawTexture(TextureSBG); - - Text.Draw; - - for SO := low(TextOpt) to high(TextOpt) do - TextOpt[SO].Draw; - end; -end; - -procedure TSelectSlide.GenLines; -var -maxlength: Real; -I: Integer; -begin - SetFontStyle(0{Text.Style}); - SetFontSize(Text.Size); - maxlength := 0; - - for I := low(TextOptT) to high (TextOptT) do - begin - if (glTextWidth(PChar(TextOptT[I])) > maxlength) then - maxlength := glTextWidth(PChar(TextOptT[I])); - end; - - Lines := floor((TextureSBG.W-40) / (maxlength+7)); - if (Lines > Length(TextOptT)) then - Lines := Length(TextOptT); - - if (Lines <= 0) then - Lines := 1; - - //Free old Space used by Texts - For I := low(TextOpt) to high(TextOpt) do - TextOpt[I].Free; - - setLength (TextOpt, Lines); - - for I := low(TextOpt) to high(TextOpt) do - begin - TextOpt[I] := TText.Create; - TextOpt[I].Size := Text.Size; - //TextOpt[I].Align := 1; - TextOpt[I].Align := 0; - TextOpt[I].Visible := True; - - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - - //Generate Positions - //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I - else - TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; - - TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; - - //Better Look with 2 Options - if (Lines=2) AND (Length(TextOptT)= 2) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; - end; -end; - -end. +unit UMenuSelectSlide; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses TextGL, + UTexture, + OpenGL12, + UMenuText; + +type + PSelectSlide = ^TSelectSlide; + TSelectSlide = class + private + SelectBool: boolean; + public + // objects + Text: TText; // Main text describing option + TextOpt: array of TText; // 3 texts in the position of possible options + TextOptT: array of string; // array of names for possible options + + Texture: TTexture; // Select Texture + TextureSBG: TTexture; // Background Selections Texture +// TextureS: array of TTexture; // Selections Texture (not used) + +// TextureArrowL: TTexture; // Texture for left arrow (not used yet) +// TextureArrowR: TTexture; // Texture for right arrow (not used yet) + + SelectOptInt: integer; + PData: ^integer; + + //For automatically Setting LineCount + Lines: Byte; + + //Visibility + Visible: Boolean; + + // for selection and deselection + // main static + ColR: real; + ColG: real; + ColB: real; + Int: real; + DColR: real; + DColG: real; + DColB: real; + DInt: real; + + // main text + TColR: real; + TColG: real; + TColB: real; + TInt: real; + TDColR: real; + TDColG: real; + TDColB: real; + TDInt: real; + + // selection background static + SBGColR: real; + SBGColG: real; + SBGColB: real; + SBGInt: real; + SBGDColR: real; + SBGDColG: real; + SBGDColB: real; + SBGDInt: real; + + // selection text + STColR: real; + STColG: real; + STColB: real; + STInt: real; + STDColR: real; + STDColG: real; + STDColB: real; + STDInt: real; + + // position and size + property X: real read Texture.x write Texture.x; + property Y: real read Texture.y write Texture.y; + property W: real read Texture.w write Texture.w; + property H: real read Texture.h write Texture.h; +// property X2: real read Texture2.x write Texture2.x; +// property Y2: real read Texture2.y write Texture2.y; +// property W2: real read Texture2.w write Texture2.w; +// property H2: real read Texture2.h write Texture2.h; + + property SBGW: real read TextureSBG.w write TextureSBG.w; + + // procedures + procedure SetSelect(Value: boolean); + property Selected: Boolean read SelectBool write SetSelect; + procedure SetSelectOpt(Value: integer); + property SelectedOption: integer read SelectOptInt write SetSelectOpt; + procedure Draw; + constructor Create; + + //Automatically Generate Lines (Texts) + procedure genLines; + end; + +implementation +uses UDrawTexture, math, ULog, SysUtils; + +// ------------ Select +constructor TSelectSlide.Create; +begin + inherited Create; + Text := TText.Create; + SetLength(TextOpt, 1); + TextOpt[0] := TText.Create; + + //Set Standard Width for Selections Background + SBGW := 450; + + Visible := True; + {SetLength(TextOpt, 3); + TextOpt[0] := TText.Create; + TextOpt[1] := TText.Create; + TextOpt[2] := TText.Create;} +end; + +procedure TSelectSlide.SetSelect(Value: boolean); +{var + SO: integer; + I: integer;} +begin + SelectBool := Value; + if Value then begin + Texture.ColR := ColR; + Texture.ColG := ColG; + Texture.ColB := ColB; + Texture.Int := Int; + + Text.ColR := TColR; + Text.ColG := TColG; + Text.ColB := TColB; + Text.Int := TInt; + + TextureSBG.ColR := SBGColR; + TextureSBG.ColG := SBGColG; + TextureSBG.ColB := SBGColB; + TextureSBG.Int := SBGInt; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STColR; + TextOpt[I].ColG := STColG; + TextOpt[I].ColB := STColB; + TextOpt[I].Int := STInt; + end;} + + end else begin + Texture.ColR := DColR; + Texture.ColG := DColG; + Texture.ColB := DColB; + Texture.Int := DInt; + + Text.ColR := TDColR; + Text.ColG := TDColG; + Text.ColB := TDColB; + Text.Int := TDInt; + + TextureSBG.ColR := SBGDColR; + TextureSBG.ColG := SBGDColG; + TextureSBG.ColB := SBGDColB; + TextureSBG.Int := SBGDInt; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + end;} + end; +end; + +procedure TSelectSlide.SetSelectOpt(Value: integer); +var + SO: integer; + Sel: integer; + HalfL: integer; + HalfR: integer; + +procedure DoSelection(Sel: Cardinal); + var I: Integer; + begin + for I := low(TextOpt) to high(TextOpt) do + begin + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + end; + if (integer(Sel) <= high(TextOpt)) then + begin + TextOpt[Sel].ColR := STColR; + TextOpt[Sel].ColG := STColG; + TextOpt[Sel].ColB := STColB; + TextOpt[Sel].Int := STInt; + end; + end; +begin + SelectOptInt := Value; + PData^ := Value; +// SetSelect(true); // reset all colors + + if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then + begin + + if (Value <= 0) then + begin //First Option Selected + Value := 0; + + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(0); + end + else if (Value >= high(TextOptT)) then + begin //Last Option Selected + Value := high(TextOptT); + + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + DoSelection(Lines-1); + end + else + begin + HalfL := Ceil((Lines-1)/2); + HalfR := Lines-1-HalfL; + + if (Value <= HalfL) then + begin //Selected Option is near to the left side + {HalfL := Value; + HalfR := Lines-1-HalfL;} + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(Value); + end + else if (Value > High(TextOptT)-HalfR) then + begin //Selected is too near to the right border + HalfR := high(TextOptT) - Value; + HalfL := Lines-1-HalfR; + //Change Texts + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + + DoSelection (HalfL); + end + else + begin + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + end; + + DoSelection(HalfL); + end; + + end; + + end; + +end; + +procedure TSelectSlide.Draw; +var + SO: integer; +begin + if Visible then + begin + DrawTexture(Texture); + DrawTexture(TextureSBG); + + Text.Draw; + + for SO := low(TextOpt) to high(TextOpt) do + TextOpt[SO].Draw; + end; +end; + +procedure TSelectSlide.GenLines; +var +maxlength: Real; +I: Integer; +begin + SetFontStyle(0{Text.Style}); + SetFontSize(Text.Size); + maxlength := 0; + + for I := low(TextOptT) to high (TextOptT) do + begin + if (glTextWidth(PChar(TextOptT[I])) > maxlength) then + maxlength := glTextWidth(PChar(TextOptT[I])); + end; + + Lines := floor((TextureSBG.W-40) / (maxlength+7)); + if (Lines > Length(TextOptT)) then + Lines := Length(TextOptT); + + if (Lines <= 0) then + Lines := 1; + + //Free old Space used by Texts + For I := low(TextOpt) to high(TextOpt) do + TextOpt[I].Free; + + setLength (TextOpt, Lines); + + for I := low(TextOpt) to high(TextOpt) do + begin + TextOpt[I] := TText.Create; + TextOpt[I].Size := Text.Size; + //TextOpt[I].Align := 1; + TextOpt[I].Align := 0; + TextOpt[I].Visible := True; + + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + + //Generate Positions + //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); + if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I + else + TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; + + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; + + //Better Look with 2 Options + if (Lines=2) AND (Length(TextOptT)= 2) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; + end; +end; + +end. -- cgit v1.2.3