From e281ca418b99f54746fd1705e1143e05ecdbbd57 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Tue, 5 Jul 2011 19:10:07 -0400 Subject: [PATCH] New lua function CHARMAN:GetCharacterCount. How the Characters mod won't display by default if there are no characters to play with at all. --- Docs/Changelog_sm5.txt | 3 +++ Docs/Luadoc/Lua.xml | 1 + Docs/Luadoc/LuaDocumentation.xml | 3 +++ Themes/default/Scripts/03 ThemePrefs.lua | 27 +++++++++++++++--------- src/CharacterManager.cpp | 8 +++++++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index 5c8753740a..e4c5a6d79e 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -14,6 +14,9 @@ StepMania 5.0 ????????? | 20110??? Saving should still work, but this was never tested yet. [Wolfman2000] * [ScreenOptions] Mini is now ITG Mini, and Tiny is now Pump Pro Mini. This will prevent many prior courses from breaking. [sharksoda, Wolfman2000] +* [CharacterManager] Add a lua function to check how many characters you have. + For an example of how this is used, check the default theme's scripts + folder, specifically 03 ThemePrefs.lua. [Wolfman2000] 2011/07/04 ---------- diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index 4f56b8b1a2..a3bf6efb82 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -580,6 +580,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index d1d6f53eda..3163e5b0da 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -1540,6 +1540,9 @@ Returns a random character. + + Returns the number of characters available. + diff --git a/Themes/default/Scripts/03 ThemePrefs.lua b/Themes/default/Scripts/03 ThemePrefs.lua index d7c1555728..221ced5288 100644 --- a/Themes/default/Scripts/03 ThemePrefs.lua +++ b/Themes/default/Scripts/03 ThemePrefs.lua @@ -231,9 +231,9 @@ function UserPrefShowLotsaOptions() end function GetDefaultOptionLines() - local LineSets = { - "1,8,14,2,3,4,5,6,R,7,9,10,11,12,13,16,17,18", -- All - "1,8,14,2,7,13,16,17,18", -- DDR Essentials ( no turns, fx ) + local LineSets = { -- none of these include characters yet. + "1,8,14,2,3,4,5,6,R,7,9,10,11,12,13,16,17", -- All + "1,8,14,2,7,13,16,17", -- DDR Essentials ( no turns, fx ) }; local function IsExtra() if GAMESTATE:IsExtraStage() or GAMESTATE:IsExtraStage2() then @@ -242,15 +242,22 @@ function GetDefaultOptionLines() return false end end - if not IsExtra() then - if GetUserPrefB("UserPrefShowLotsaOptions") then - return GetUserPrefB("UserPrefShowLotsaOptions") and LineSets[1] or LineSets[2]; - else - return LineSets[2]; -- Just make sure! + + local function CheckCharacters(mods) + if CHARMAN:GetCharacterCount() > 0 then + return mods .. ",18"; --TODO: Better line name. end - else - return "1,8,14,2,7,13,16,17,18" -- "failsafe" list + return mods; end + + modLines = LineSets[2]; + + if not IsExtra() then + modLines = GetUserPrefB("UserPrefShowLotsaOptions") + and LineSets[1] or LineSets[2]; + end + + return CheckCharacters(modLines); end; function UserPrefAutoSetStyle() diff --git a/src/CharacterManager.cpp b/src/CharacterManager.cpp index 10cf6a26d6..30fc1ab6ac 100644 --- a/src/CharacterManager.cpp +++ b/src/CharacterManager.cpp @@ -152,6 +152,13 @@ public: LuaHelpers::CreateTableFromArray(vChars, L); return 1; } + static int GetCharacterCount(T* p, lua_State *L) + { + vector chars; + p->GetCharacters(chars); + lua_pushnumber(L, chars.size()); + return 1; + } LunaCharacterManager() { @@ -159,6 +166,7 @@ public: // sm-ssc adds: ADD_METHOD( GetRandomCharacter ); ADD_METHOD( GetAllCharacters ); + ADD_METHOD( GetCharacterCount ); } };