From 1bcf5d3ab366002e8000656b566340c3efd756af Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 23 May 2009 14:08:58 +0000 Subject: new ULuaUtils procedure: lua_PushBinInt new functions in ScreenSing lua module ScreenSing.GetSettings ScreenSing.SetSettings 3 new settings in UScreenSing that needs to be implemented LyrcsVisible, NotesVisible and PlayerEnabled git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1769 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Lua/src/lua/ULuaScreenSing.pas | 78 +++++++++++++++++++++++++++++++++++++++-- Lua/src/lua/ULuaUtils.pas | 31 ++++++++++++++++ Lua/src/screens/UScreenSing.pas | 10 ++++++ 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/Lua/src/lua/ULuaScreenSing.pas b/Lua/src/lua/ULuaScreenSing.pas index 75ed6277..09d83403 100644 --- a/Lua/src/lua/ULuaScreenSing.pas +++ b/Lua/src/lua/ULuaScreenSing.pas @@ -44,14 +44,25 @@ function ULuaScreenSing_GetScores(L: Plua_State): Integer; cdecl; an error } function ULuaScreenSing_Finish(L: Plua_State): Integer; cdecl; +{ ScreenSing.GetSettings - no arguments + returns a table filled with the data of TScreenSing } +function ULuaScreenSing_GetSettings(L: Plua_State): Integer; cdecl; + +{ ScreenSing.SetSettings - arguments: Table + sets all attributes of TScreenSing.Settings that are + unequal to nil in Table } +function ULuaScreenSing_SetSettings(L: Plua_State): Integer; cdecl; + const - ULuaScreenSing_Lib_f: array [0..1] of lual_reg = ( + ULuaScreenSing_Lib_f: array [0..3] of lual_reg = ( (name:'GetScores';func:ULuaScreenSing_GetScores), - (name:'Finish';func:ULuaScreenSing_Finish) + (name:'Finish';func:ULuaScreenSing_Finish), + (name:'GetSettings';func:ULuaScreenSing_GetSettings), + (name:'SetSettings';func:ULuaScreenSing_SetSettings) ); implementation -uses UScreenSing, UMain, UDisplay, UGraphic; +uses UScreenSing, UMain, UDisplay, UGraphic, ULuaUtils, SysUtils; { returns a table with following structure: t[1..playercount] = score of player i } @@ -102,4 +113,65 @@ begin LuaL_error(L, 'Usdx.ScreenSing.Finish is called, but sing screen is not shown.'); end; +{ ScreenSing.GetSettings - no arguments + returns a table filled with the data of TScreenSing } +function ULuaScreenSing_GetSettings(L: Plua_State): Integer; cdecl; + var Top: Integer; +begin + // pop arguments + Top := lua_getTop(L); + if (Top > 0) then + lua_pop(L, Top); + + lua_createtable(L, 0, 3); + + //fill table w/ info + lua_pushBoolean(L, ScreenSing.Settings.LyricsVisible); + lua_setField(L, -2, 'LyricsVisible'); + + lua_pushBinInt(L, ScreenSing.Settings.NotesVisible); + lua_setField(L, -2, 'NotesVisible'); + + lua_pushBinInt(L, ScreenSing.Settings.PlayerEnabled); + lua_setField(L, -2, 'PlayerEnabled'); + + + Result := 1; +end; + +{ ScreenSing.SetSettings - arguments: Table + sets all attributes of TScreenSing.Settings that are + unequal to nil in Table } +function ULuaScreenSing_SetSettings(L: Plua_State): Integer; cdecl; + var + Key: String; +begin + Result := 0; + + // check for table on stack + luaL_checkType(L, 1, LUA_TTABLE); + + // go through table elements + lua_pushNil(L); + while (lua_Next(L, 1) <> 0) do + begin + Key := lowercase(lua_ToString(L, -2)); + + if (Key = 'lyricsvisible') and (lua_isBoolean(L, -1)) then + ScreenSing.settings.LyricsVisible := lua_toBoolean(L, -1) + else if (Key = 'notesvisible') and (lua_isTable(L, -1)) then + ScreenSing.settings.NotesVisible := lua_toBinInt(L, -1) + else if (Key = 'playerenabled') and (lua_isTable(L, -1)) then + ScreenSing.settings.PlayerEnabled := lua_toBinInt(L, -1); + + // pop value from stack so key is on top + lua_pop(L, 1); + end; + + // clear stack from table + lua_pop(L, lua_gettop(L)); + + ScreenSing.ApplySettings; +end; + end. \ No newline at end of file diff --git a/Lua/src/lua/ULuaUtils.pas b/Lua/src/lua/ULuaUtils.pas index de3bd15f..4ac1d80a 100644 --- a/Lua/src/lua/ULuaUtils.pas +++ b/Lua/src/lua/ULuaUtils.pas @@ -42,6 +42,13 @@ uses ULua, ULuaCore; does not pop anything } function Lua_ToBinInt(L: PLua_State; idx: Integer): Integer; +{ converts an integer with the value: + 0b11001 + to a lua table with a structure like: + * = 1 , * = 4 , * = 5 + and pushed the table onto the stack } +procedure Lua_PushBinInt(L: PLua_State; BinInt: Integer); + { 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 @@ -88,6 +95,30 @@ begin end; end; +{ converts an integer with the value: + 0b11001 + to a lua table with a structure like: + * = 1 , * = 4 , * = 5 + and pushed the table onto the stack } +procedure Lua_PushBinInt(L: PLua_State; BinInt: Integer); +var + I, Index: Integer; +begin + lua_newTable(L); + + + Index := 1; //< lua starts w/ index 1 + for I := 0 to 31 do + if (BinInt and (1 shl I) <> 0) then + begin + lua_pushInteger(L, Index); + lua_pushInteger(L, I); + lua_settable(L, -3); + + Inc(Index); + end; +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 diff --git a/Lua/src/screens/UScreenSing.pas b/Lua/src/screens/UScreenSing.pas index bbdd1ecd..375ec3e3 100644 --- a/Lua/src/screens/UScreenSing.pas +++ b/Lua/src/screens/UScreenSing.pas @@ -105,9 +105,13 @@ type settings: record Finish: Boolean; //< if true, screen will finish on next draw + LyricsVisible: Boolean; //< shows or hides lyrics + NotesVisible: Integer; //< if bit[playernum] is set the notes for the specified player are visible. By default all players notes are visible + PlayerEnabled: Integer; //< defines whether a player can score atm end; procedure ClearSettings; + procedure ApplySettings; //< applies changes of settings record procedure EndSong; constructor Create; override; @@ -640,6 +644,12 @@ begin Settings.Finish := False; end; +{ applies changes of settings record } +procedure TScreenSing.ApplySettings; +begin + // +end; + procedure TScreenSing.EndSong; begin Settings.Finish := True; -- cgit v1.2.3