diff options
author | whiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-07-14 19:08:03 +0000 |
---|---|---|
committer | whiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-07-14 19:08:03 +0000 |
commit | 71c0f51aa0d9d01b22e3da401bccfe88c41399f2 (patch) | |
tree | d883e36e46483467c9657821791d7ad24022514c /Lua | |
parent | e86e99462f608406da825043acde9c7b8147b907 (diff) | |
download | usdx-71c0f51aa0d9d01b22e3da401bccfe88c41399f2.tar.gz usdx-71c0f51aa0d9d01b22e3da401bccfe88c41399f2.tar.xz usdx-71c0f51aa0d9d01b22e3da401bccfe88c41399f2.zip |
4 new lua interface function for module ScreenSing
new procedure in ULuaUtils lua_PushRect
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1846 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Lua')
-rw-r--r-- | Lua/src/base/USingScores.pas | 57 | ||||
-rw-r--r-- | Lua/src/lua/ULuaScreenSing.pas | 141 | ||||
-rw-r--r-- | Lua/src/lua/ULuaUtils.pas | 33 |
3 files changed, 200 insertions, 31 deletions
diff --git a/Lua/src/base/USingScores.pas b/Lua/src/base/USingScores.pas index 2d9b1e5e..9ae48548 100644 --- a/Lua/src/base/USingScores.pas +++ b/Lua/src/base/USingScores.pas @@ -129,7 +129,7 @@ type //----------- TSingScores = class private - Positions: aScorePosition; + aPositions: aScorePosition; aPlayers: aScorePlayer; oPositionCount: Byte; oPlayerCount: Byte; @@ -174,6 +174,7 @@ type property PositionCount: Byte read oPositionCount; property PlayerCount: Byte read oPlayerCount; property Players: aScorePlayer read aPlayers; + property Positions: aScorePosition read aPositions; //Constructor just sets some standard Settings constructor Create; @@ -266,7 +267,7 @@ Procedure TSingScores.AddPosition(const pPosition: PScorePosition); begin if (PositionCount < MaxPositions) then begin - Positions[PositionCount] := pPosition^; + aPositions[PositionCount] := pPosition^; Inc(oPositionCount); end; @@ -529,7 +530,7 @@ var For I := 0 to PositionCount-1 do begin - If ((Positions[I].PlayerCount AND bPlayerCount) <> 0) then + If ((aPositions[I].PlayerCount AND bPlayerCount) <> 0) then Inc(Result); end; end; @@ -542,7 +543,7 @@ var For I := 0 to PositionCount-1 do begin - If ((Positions[I].PlayerCount AND bPlayerCount) <> 0) then + If ((aPositions[I].PlayerCount AND bPlayerCount) <> 0) then begin If (bPlayer = 0) then begin @@ -699,13 +700,13 @@ begin Progress := TimeDiff / Settings.Phase1Time; - W := Positions[PIndex].PUW * Sin(Progress/2*Pi); - H := Positions[PIndex].PUH * Sin(Progress/2*Pi); + W := aPositions[PIndex].PUW * Sin(Progress/2*Pi); + H := aPositions[PIndex].PUH * Sin(Progress/2*Pi); - X := Positions[PIndex].PUStartX + (Positions[PIndex].PUW - W)/2; - Y := Positions[PIndex].PUStartY + (Positions[PIndex].PUH - H)/2; + X := aPositions[PIndex].PUStartX + (aPositions[PIndex].PUW - W)/2; + Y := aPositions[PIndex].PUStartY + (aPositions[PIndex].PUH - H)/2; - FontSize := Round(Progress * Positions[PIndex].PUFontSize); + FontSize := Round(Progress * aPositions[PIndex].PUFontSize); FontOffset := (H - FontSize) / 2; Alpha := 1; end @@ -715,20 +716,20 @@ begin //Phase 2 - The Moving Progress := (TimeDiff - Settings.Phase1Time) / Settings.Phase2Time; - W := Positions[PIndex].PUW; - H := Positions[PIndex].PUH; + W := aPositions[PIndex].PUW; + H := aPositions[PIndex].PUH; - PosDiff := Positions[PIndex].PUTargetX - Positions[PIndex].PUStartX; + PosDiff := aPositions[PIndex].PUTargetX - aPositions[PIndex].PUStartX; If PosDiff > 0 then PosDiff := PosDiff + W; - X := Positions[PIndex].PUStartX + PosDiff * sqr(Progress); + X := aPositions[PIndex].PUStartX + PosDiff * sqr(Progress); - PosDiff := Positions[PIndex].PUTargetY - Positions[PIndex].PUStartY; + PosDiff := aPositions[PIndex].PUTargetY - aPositions[PIndex].PUStartY; If PosDiff < 0 then - PosDiff := PosDiff + Positions[PIndex].BGH; - Y := Positions[PIndex].PUStartY + PosDiff * sqr(Progress); + PosDiff := PosDiff + aPositions[PIndex].BGH; + Y := aPositions[PIndex].PUStartY + PosDiff * sqr(Progress); - FontSize := Positions[PIndex].PUFontSize; + FontSize := aPositions[PIndex].PUFontSize; FontOffset := (H - FontSize) / 2; Alpha := 1 - 0.3 * Progress; end @@ -758,24 +759,24 @@ begin //Set Positions etc. Alpha := 0.7 - 0.7 * Progress; - W := Positions[PIndex].PUW; - H := Positions[PIndex].PUH; + W := aPositions[PIndex].PUW; + H := aPositions[PIndex].PUH; - PosDiff := Positions[PIndex].PUTargetX - Positions[PIndex].PUStartX; + PosDiff := aPositions[PIndex].PUTargetX - aPositions[PIndex].PUStartX; If (PosDiff > 0) then PosDiff := W else PosDiff := 0; - X := Positions[PIndex].PUTargetX + PosDiff * Progress; + X := aPositions[PIndex].PUTargetX + PosDiff * Progress; - PosDiff := Positions[PIndex].PUTargetY - Positions[PIndex].PUStartY; + PosDiff := aPositions[PIndex].PUTargetY - aPositions[PIndex].PUStartY; If (PosDiff < 0) then - PosDiff := -Positions[PIndex].BGH + PosDiff := -aPositions[PIndex].BGH else PosDiff := 0; - Y := Positions[PIndex].PUTargetY - PosDiff * (1-Progress); + Y := aPositions[PIndex].PUTargetY - PosDiff * (1-Progress); - FontSize := Positions[PIndex].PUFontSize; + FontSize := aPositions[PIndex].PUFontSize; FontOffset := (H - FontSize) / 2; end else @@ -812,7 +813,7 @@ begin glDisable(GL_BLEND); //Set FontStyle and Size - SetFontStyle(Positions[PIndex].PUFont); + SetFontStyle(aPositions[PIndex].PUFont); SetFontItalic(False); SetFontSize(FontSize); @@ -847,7 +848,7 @@ begin //Only Draw if Player is on Cur Screen If (((Players[Index].Position AND 128) = 0) = (ScreenAct = 1)) AND Players[Index].Visible then begin - Position := @Positions[Players[Index].Position and 127]; + Position := @aPositions[Players[Index].Position and 127]; //Draw ScoreBG glEnable(GL_TEXTURE_2D); @@ -898,7 +899,7 @@ begin Players[index].RBVisible and Players[index].Visible) then begin - Position := @Positions[Players[Index].Position and 127]; + Position := @aPositions[Players[Index].Position and 127]; if (Enabled AND Players[Index].Enabled) then begin diff --git a/Lua/src/lua/ULuaScreenSing.pas b/Lua/src/lua/ULuaScreenSing.pas index 09d83403..c205b65b 100644 --- a/Lua/src/lua/ULuaScreenSing.pas +++ b/Lua/src/lua/ULuaScreenSing.pas @@ -1,4 +1,4 @@ - {* UltraStar Deluxe - Karaoke Game
+{* 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
@@ -40,6 +40,21 @@ uses t[1..playercount] = score of player i }
function ULuaScreenSing_GetScores(L: Plua_State): Integer; cdecl;
+{ returns a table with following structure:
+ t[1..playercount] = rating of player i range: [0..1] }
+function ULuaScreenSing_GetRating(L: Plua_State): Integer; cdecl;
+
+{ returns a table with following structure:
+ t[1..playercount] = rect of players score background: table(x, y, w, h) }
+function ULuaScreenSing_GetScoreBGRect(L: Plua_State): Integer; cdecl;
+
+{ returns a table with following structure:
+ t[1..playercount] = rect of players rating bar: table(x, y, w, h) }
+function ULuaScreenSing_GetRBRect(L: Plua_State): Integer; cdecl;
+
+{ ScreenSing.GetBeat() - returns current beat of lyricstate }
+function ULuaScreenSing_GetBeat(L: Plua_State): Integer; cdecl;
+
{ finishes current song, if sing screen is not shown it will raise
an error }
function ULuaScreenSing_Finish(L: Plua_State): Integer; cdecl;
@@ -54,15 +69,19 @@ function ULuaScreenSing_GetSettings(L: Plua_State): Integer; cdecl; function ULuaScreenSing_SetSettings(L: Plua_State): Integer; cdecl;
const
- ULuaScreenSing_Lib_f: array [0..3] of lual_reg = (
+ ULuaScreenSing_Lib_f: array [0..7] of lual_reg = (
(name:'GetScores';func:ULuaScreenSing_GetScores),
+ (name:'GetRating';func:ULuaScreenSing_GetRating),
+ (name:'GetBeat';func:ULuaScreenSing_GetBeat),
+ (name:'GetScoreBGRect';func:ULuaScreenSing_GetScoreBGRect),
+ (name:'GetRBRect';func:ULuaScreenSing_GetRBRect),
(name:'Finish';func:ULuaScreenSing_Finish),
(name:'GetSettings';func:ULuaScreenSing_GetSettings),
(name:'SetSettings';func:ULuaScreenSing_SetSettings)
);
implementation
-uses UScreenSing, UMain, UDisplay, UGraphic, ULuaUtils, SysUtils;
+uses UScreenSing, UMain, UDisplay, UGraphic, UMusic, ULuaUtils, SysUtils;
{ returns a table with following structure:
t[1..playercount] = score of player i }
@@ -93,6 +112,107 @@ begin // leave table on stack, it is our result
end;
+{ returns a table with following structure:
+ t[1..playercount] = rating of player i range: [0..1] }
+function ULuaScreenSing_GetRating(L: Plua_State): Integer; cdecl;
+ var
+ Top: Integer;
+ I: Integer;
+begin
+ Result := 1;
+
+ // pop arguments
+ Top := lua_getTop(L);
+ if (Top > 0) then
+ lua_pop(L, Top);
+
+ // create table
+ lua_createtable(L, Length(Player), 0);
+
+ // fill w/ values
+ for I := 0 to High(ScreenSing.Scores.Players) do
+ begin
+ lua_pushInteger(L, I + 1);
+ lua_pushNumber(L, ScreenSing.Scores.Players[I].RBPos);
+
+ lua_settable(L, -3);
+ end;
+
+ // leave table on stack, it is our result
+end;
+
+{ returns a table with following structure:
+ t[1..playercount] = rect of players ScoreBG: table(x, y, w, h) }
+function ULuaScreenSing_GetScoreBGRect(L: Plua_State): Integer; cdecl;
+ var
+ Top: Integer;
+ I: Integer;
+begin
+ Result := 1;
+
+ // pop arguments
+ Top := lua_getTop(L);
+ if (Top > 0) then
+ lua_pop(L, Top);
+
+ // create table
+ lua_createtable(L, Length(ScreenSing.Scores.Players), 0);
+
+ // fill w/ values
+ for I := 0 to High(ScreenSing.Scores.Players) do
+ begin
+ lua_pushInteger(L, I + 1);
+
+ if (ScreenSing.Scores.Players[I].Position = High(Byte)) then
+ // player has no position, prevent crash by pushing nil
+ lua_pushNil(L)
+ else
+ with ScreenSing.Scores.Positions[ScreenSing.Scores.Players[I].Position] do
+ lua_PushRect(L, BGX, BGY, BGW, BGH);
+
+
+ lua_settable(L, -3);
+ end;
+
+ // leave table on stack, it is our result
+end;
+
+{ returns a table with following structure:
+ t[1..playercount] = rect of players rating bar: table(x, y, w, h) }
+function ULuaScreenSing_GetRBRect(L: Plua_State): Integer; cdecl;
+ var
+ Top: Integer;
+ I: Integer;
+begin
+ Result := 1;
+
+ // pop arguments
+ Top := lua_getTop(L);
+ if (Top > 0) then
+ lua_pop(L, Top);
+
+ // create table
+ lua_createtable(L, Length(ScreenSing.Scores.Players), 0);
+
+ // fill w/ values
+ for I := 0 to High(ScreenSing.Scores.Players) do
+ begin
+ lua_pushInteger(L, I + 1);
+
+ if (ScreenSing.Scores.Players[I].Position = High(Byte)) then
+ // player has no position, prevent crash by pushing nil
+ lua_pushNil(L)
+ else
+ with ScreenSing.Scores.Positions[ScreenSing.Scores.Players[I].Position] do
+ lua_PushRect(L, RBX, RBY, RBW, RBH);
+
+
+ lua_settable(L, -3);
+ end;
+
+ // leave table on stack, it is our result
+end;
+
{ finishes current song, if sing screen is not shown it will raise
an error }
function ULuaScreenSing_Finish(L: Plua_State): Integer; cdecl;
@@ -174,4 +294,19 @@ begin ScreenSing.ApplySettings;
end;
+{ ScreenSing.GetBeat() - returns current beat of lyricstate }
+function ULuaScreenSing_GetBeat(L: Plua_State): Integer; cdecl;
+var top: Integer;
+begin
+ //remove arguments (if any)
+ top := lua_gettop(L);
+
+ if (top > 0) then
+ lua_pop(L, top);
+
+ //push result
+ lua_pushnumber(L, LyricsState.MidBeat);
+ Result := 1; //one result
+end;
+
end.
\ No newline at end of file diff --git a/Lua/src/lua/ULuaUtils.pas b/Lua/src/lua/ULuaUtils.pas index 4ac1d80a..143b34d4 100644 --- a/Lua/src/lua/ULuaUtils.pas +++ b/Lua/src/lua/ULuaUtils.pas @@ -49,6 +49,13 @@ function Lua_ToBinInt(L: PLua_State; idx: Integer): Integer; and pushed the table onto the stack }
procedure Lua_PushBinInt(L: PLua_State; BinInt: Integer);
+{ pushes a table with position and size of a rectangle
+ t.x => position of the rectangle in pixels at x-axis
+ t.y => position of the rectangle in pixels at y-axis
+ t.w => width of the rectangle
+ t.h => height of the rectangle }
+procedure Lua_PushRect(L: PLua_State; X, Y, W, H: Double);
+
{ returns plugin that is the owner of the given state
may raise a lua error if the parent id is not found
in states registry, if state owner does not exists
@@ -119,6 +126,32 @@ begin end;
end;
+{ pushes a table with position and size of a rectangle
+ t.x => position of the rectangle in pixels at x-axis
+ t.y => position of the rectangle in pixels at y-axis
+ t.w => width of the rectangle
+ t.h => height of the rectangle }
+procedure Lua_PushRect(L: PLua_State; X, Y, W, H: Double);
+begin
+ lua_createtable(L, 0, 4); // table w/ 4 record fields
+
+ // x pos
+ lua_pushNumber(L, X);
+ lua_setField(L, -2, 'x');
+
+ // y pos
+ lua_pushNumber(L, Y);
+ lua_setField(L, -2, 'y');
+
+ // width
+ lua_pushNumber(L, W);
+ lua_setField(L, -2, 'w');
+
+ // height
+ lua_pushNumber(L, H);
+ lua_setField(L, -2, 'h');
+end;
+
{ returns plugin that is the owner of the given state
may raise a lua error if the parent id is not found
in states registry, if state owner does not exists
|