From 71c0f51aa0d9d01b22e3da401bccfe88c41399f2 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 14 Jul 2009 19:08:03 +0000 Subject: 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 --- Lua/src/lua/ULuaScreenSing.pas | 141 ++++++++++++++++++++++++++++++++++++++++- Lua/src/lua/ULuaUtils.pas | 33 ++++++++++ 2 files changed, 171 insertions(+), 3 deletions(-) (limited to 'Lua/src/lua') 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 -- cgit v1.2.3