diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml
index 27c291591a..bc4e99d244 100644
--- a/Docs/Luadoc/Lua.xml
+++ b/Docs/Luadoc/Lua.xml
@@ -925,6 +925,7 @@
+
@@ -1821,6 +1822,7 @@
+
diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml
index 77370ffcf2..61886525d3 100644
--- a/Docs/Luadoc/LuaDocumentation.xml
+++ b/Docs/Luadoc/LuaDocumentation.xml
@@ -749,6 +749,10 @@ save yourself some time, copy this for undocumented things:
Tries to read the file at sPath. If successful, it returns the file's contents.
If unsuccessful, it returns two values: nil and "error".
+
+ Reports the error through the error reporting system. error_type is the type used for the dialog that is presented, a dialog will not appear for a type the user has chosen to ignore.
+ error is optional an defaults to "Script error occurred.". error_type is optional and defaults to "LUA_ERROR".
+
Calls func(...) with two LuaThreadVariables set, and returns the return values of func().
@@ -2769,6 +2773,9 @@ save yourself some time, copy this for undocumented things:
second argument is an optional table of parameters. It may be omitted or explicitly
set to nil.
+
+ Sets whether logging of messages is enabled. If log is true, all messages that pass through Broadcast (from the engine for from the theme or from anywhere else), will be logged with Trace.
+
diff --git a/Docs/Themerdocs/Examples/Example_Screens/ScreenOptionsExample.ini b/Docs/Themerdocs/Examples/Example_Screens/ScreenOptionsExample.ini
new file mode 100644
index 0000000000..39e4a0032e
--- /dev/null
+++ b/Docs/Themerdocs/Examples/Example_Screens/ScreenOptionsExample.ini
@@ -0,0 +1,129 @@
+# Try out this examply by copying these metrics into your metrics.ini.
+
+# Some elements will require entries to be added to the language file. Read Examples/LanguageFile.ini for instructions on adding entries to a language file.
+
+# Setting InitialScreen in the Common section just makes the theme start up in this screen.
+# This is only done for ease of seeing this example in action, and is not part of making an options screen.
+[Common]
+InitialScreen="ScreenOptionsExample"
+
+# The screen must have a metrics section with its name.
+[ScreenOptionsExample]
+# The Fallback metric for the screen should be "ScreenOptionsMaster", to pull in necessary fallback metrics from that section.
+Fallback="ScreenOptionsMaster"
+
+# The ForceAllPlayers metric will force join all players if set.
+# This example sets it because the example runs when players would not otherwise be joined.
+# An options screen that is meant to set song options between song select and gameplay should not set ForceAllPlayers to true.
+ForceAllPlayers=true
+
+# NavigationMode controls how the cursor is used to navigate the screen.
+# If it's not set by the theme, it defaults to the setting in Preferences.ini.
+# "toggle" sets navigation to the preferred toggle style mode. In toggle mode, all options on all rows are treated as on/off toggled options.
+# "menu" sets navigation to the menu style mode. In menu mode, each should have only a single option which sets a new screen when chosen.
+# This example does not set NavigationMode because the default is what it wants.
+# NavigationMode=
+
+# InputMode sets the input mode. This controls whether the players have separate cursors.
+# "individual" means the players' cursors can be separated and move to different options.
+# "together" means both players control the same cursor.
+InputMode="individual"
+
+# LineNames sets the names of the rows on the screen.
+# Names are separated by commas and can be anything that doesn't contain a comma.
+# Each name will be appended to "Line" to find the metric that defines that line. So a line name of "a" will be defined by the metric "Linea".
+LineNames="a,b,c,d,e,f,g,h,j,k,l,m,n"
+
+# Each line is defined by a metric that sets its type and arguments for that type.
+# This example is going to include a simple example of each type.
+# The types of option rows are: "list", "lua", "conf", "stepstype", "steps", "gamecommand".
+
+# The "list" row type takes a single argument: The subtype, or the metric that defines the elements of the list.
+# The subtypes of list are: "NoteSkins", "Steps", "StepsLocked", "Characters", "Styles", "Groups", "Difficulties", "SongsInCurrentSongGroup".
+# If the subtype is not one of the above, it is the name of the metric that defines the list.
+
+# This list example will create a list defined by a metric.
+# A list that is defined by a metric requires entries in the language file for the option title and the option explanation.
+# "list,Examples" requires an "Examples" entry in the "OptionTitles" and "OptionExplanations" sections of the language file.
+# When looking for the metric that defines the list, the ScreenOptionsMaster section is searched. See the ScreenOptionsMaster section of this file for an explanation of the body of the list.
+Linea="list,Examples"
+
+# The other list subtypes construct lists of GameCommands that execute specific actions.
+
+# The "NoteSkins" subtype constructs a list out of all noteskins available.
+Lineb="list,NoteSkins"
+
+# The "Steps" subtype constructs a list out of the playable steps for the current song or course. Because this is an example screen and there is no current song set, no steps are in the list when this screen is used.
+Linec="list,Steps"
+# The "StepsLocked" subtype is identical to the "Steps" subtype, but forces all players to make the same choice.
+Lined="list,StepsLocked"
+
+# The "Characters" subtype constructs a list out of the selectable dancers.
+Linee="list,Characters"
+
+# The "Styles" subtype constructs a list ouf of all styles for the current game type.
+Linef="list,Styles"
+
+# The "Groups" subtype constructs a list out of all the song groups.
+Lineg="list,Groups"
+
+# The "Difficulties" subtype constructs a list of the difficulties in the "DifficultiesToShow" metric from the "Common" section.
+Lineh="list,Difficulties"
+
+# The "SongsInCurrentSongGroup" subtype
+# This option row type is not actually usable because it requires language file entries for every song, which is impractical.
+#Linei="list,SongsInCurrentSongGroup"
+
+# This is the end of the list subtype examples.
+
+# The "lua" row type takes a single argument, a chunk of lua to run which must return a table defining the row. Full explanation of the lua option row type can be found in Examples/OptionRowHandlerLua.lua.
+# This example uses the "ArbitrarySpeedMods()" function just because I like it.
+Linej="lua,ArbitrarySpeedMods()"
+
+# The "steps" row type creates choices for the different charts for the current song. It takes a single argument, "EditSteps" or "EditSourceSteps". Its purpose is currently unknown.
+Linek="steps,EditSteps"
+
+# The "stepstype" row type is related to the "steps" row type. It takes a single argument, "EditStepsType" or "EditSourceStepsType". Its purpose is also unknown.
+Linel="stepstype,EditStepsType"
+
+# The "conf" row type constructs a row for changing a conf option. conf options are the options in Preferences.ini and the argument is the name of the option to edit.
+Linem="conf,AllowW1"
+
+# The "gamecommand" row type constructs a row with a single choice from a GameCommand and applies that GameCommand when the choice is chosen.
+# Everything after the "gamecommand;" part of the row command is used to construct the GameCommand.
+# Full documention on GameCommands can be found in gamecommands.txt.
+# This example just makes a GameCommand that does nothing, but has a name.
+Linen="gamecommand;name,ExampleCommand"
+
+
+[ScreenOptionsMaster]
+# The main metric defining the list is a command that sets the number of elements and some flags. All flags are optional, and most commonly will not be used.
+# The number of elements must come first.
+# Flags are separated by semicolons.
+# Arguments to flags are separated by commas.
+# Flags are:
+# "together": Any choice chosen is applied to both players.
+# "selectmultiple": Multiple choices on the row can be chosen.
+# "selectone": One choice on the row can be chosen.
+# "selectnone": No choice on the row can be chosen.
+# selectmultiple, selectone, and selectnone are mutually exclusive. If more than one is set, only the last one applies.
+# "showoneinrow": Only show one choice in the row.
+# "default": Sets the default choice. Takes one argument, the number of the choice. "default,2" makes the second choice the default.
+# "reloadrowmessages": Sets the messages that will cause the row to be reloaded. Arguments are the messages.
+# "enabledforplayers": Sets which players are allowed to use the row. Arguments are numbers.
+# "exportonchange": Sets whether the option is exported every time it changes.
+# "broadcastonexport": Sets the messages that are broadcast when the row is exported. Arguments are the messages.
+# Example line using all flags:
+#Examples="4;together;selectmultiple;showoneinrow;default,3;reloadrowmessages,ExampleReload;enabledforplayers,1,2;exportonchange;broadcastonexport,ExampleExport"
+Examples="4"
+
+# Each choice in the list is defined by a metric. The name of the metric is the name of the list with a comma and the id of the choice.
+# So the first choice in our "Examples" list is defined by the metric "Examples,1".
+# The metric defining a choice is a GameCommand. Full explanation of GameCommands is beyond the scope of this example. This example will only use the "name" part of a GameCommand. See gamecommands.txt for full documentation on GameCommands.
+# The "name" part of a GameCommand sets the name for that GameCommand. There must be an entry for this name in the "OptionNames" section of the language file.
+# A list also needs a Default entry, a command to apply if the none of the choices are selected. It can be empty, and it does not need a name.
+ExamplesDefault=""
+Examples,1="name,Ex1"
+Examples,2="name,Ex2"
+Examples,3="name,Ex3"
+Examples,4="name,Ex4"
diff --git a/Docs/Themerdocs/actordef.txt b/Docs/Themerdocs/actordef.txt
index 3257511314..551600a5cd 100644
--- a/Docs/Themerdocs/actordef.txt
+++ b/Docs/Themerdocs/actordef.txt
@@ -26,6 +26,7 @@ GrooveRadar
HelpDisplay
HoldJudgment
InputList
+LogDisplay
MemoryCardDisplay
MeterDisplay
Model
@@ -43,4 +44,4 @@ Sprite
StepsDisplay
StepsDisplayList
TextBanner
-WorkoutGraph
\ No newline at end of file
+WorkoutGraph
diff --git a/Docs/Themerdocs/gamecommands.txt b/Docs/Themerdocs/gamecommands.txt
index 8b2f11a277..bed2c60725 100644
--- a/Docs/Themerdocs/gamecommands.txt
+++ b/Docs/Themerdocs/gamecommands.txt
@@ -1,62 +1,123 @@
-all the known gamecommands (pre-sm-ssc)
+GameCommands are constructed from subcommands separated by semicolons.
+Subcommands are constructed from a command name and its arguments, separated by commas.
+Each command takes its arguments and interprets them to set a property of the GameCommand.
+
+Most of the things that can be done through GameCommands can be done better through other means. GameCommand is kept around for compatibility with older versions and because ScreenOptionsMaster based screens often don't have the ability to use the better ways of doing things for their choices.
+
+Example command:
+"name,Example;screen,ScreenInit"
+This example creates a GameCommand with the name "Example" and its screen property set to "ScreenInit".
+
+When a GameCommand is applied, its properties are used to change things about the game.
+
+The various properties that can be set for a GameCommand are listed below, with their effects when applied.
+
+"announcer"
+Sets the name of the announcer. The argument must be the name of the directoory of the announcer.
+
+"applydefaultoptions"
+Applies the default options to the player. No argument.
+
+"clearcredits"
+Clears any credits that have been inserted. No argument.
+
+"course"
+Sets the current course to the argument.
-"style"
-"playmode"
"difficulty"
+Sets the difficulty property of this GameCommand.
+Acceptable args are:
+Beginner, Easy, Medium, Hard, Challenge, Edit
-"announcer" {m_sAnnouncer = sValue;}
+"fademusic"
+Must have 2 args: The volume to fade out to and the seconds to spread the fade over.
-"name" {m_sName = sValue;}
+"goalcalories"
+Sets the calorie goal of the player.
-"text" {m_sText = sValue;}
+"goaltype"
+Sets the goal type of the player. Types are: Calories, Time, None.
-"mod" {m_sPreferredModifiers += sValue;}
-
-"stagemod" {m_sStageModifiers += sValue;}
+"insertcredit"
+Inserts a credit. No arguments.
"lua"
+Sets a lua function to be run when this GameCommand is applied.
-"screen" {m_sScreen = sValue;}
+"mod"
+Sets a modifier to be applied to the player(s).
+
+"name"
+Sets the name of this GameCommand. For GameCommands used in option rows as choices, this is used to set the text that is shown on screen for the choice.
+
+"playmode"
+The "playmode" game command controls what mode of play the game is in. This is a choice between the normal play mode and the various course or battle modes. The noral effects of the different playmodes are described in playmods.txt, though a theme can check the current playmode and do anything it pleases with that information.
+Acceptable args are:
+Regular, Nonstop, Oni, Endless, Battle, Rave
+
+"preparescreen"
+Prepares the screen named by the argument when the command is applied. PrepareScreen takes time and blocks graphics, so this should not be used for screens that load a lot of data.
+
+"profileid"
+Sets the default local profile ID of the player.
+
+"screen"
+Sets the screen that will be transitioned to when this GameCommand is applied.
+
+"setenv"
+Arguments are "key,value" pairs of environment variables to be set. Only capable of setting string values.
+
+"setpref"
+Must have 2 args: The preference and the value to set it to. Preferences are listed in Preferences.ini.
"song"
-"steps"
-"course"
-"trail"
+Sets the current song. The argument should be of the form "Group/SongName".
-"setenv" {
- if( cmd.m_vsArgs.size() == 3 )
- m_SetEnv[ cmd.m_vsArgs[1] ] = cmd.m_vsArgs[2]; }
-
-"songgroup" {m_sSongGroup = sValue;}
+"songgroup"
+Sets the preferred song group. Does not immediately change the group on the music wheel, but the preferred group is the group that will be open when ScreenSelectMusic starts.
"sort"
-{
- m_SortOrder = StringToSortOrder( sValue );
- if( m_SortOrder == SortOrder_Invalid )
- {
- m_sInvalidReason = ssprintf( "SortOrder \"%s\" is not valid.", sValue.c_str() );
- m_bInvalid |= true;
- }
-}
+Sets the sort order. Does not immediately change the sort on the music wheel, but the sort is the sort that will be used when ScreenSelectMusic starts.
+Sort names are:
+Preferred, Group, Title, BPM, Popularity, TopGrades, Artist, Genre, BeginnerMeter, EasyMeter, MediumMeter, HardMeter, ChallengeMeter, DoubleBeginnerMeter, DoubleEasyMeter, DoubleMediumMeter, DoubleHardMeter, DoubleChallengeMeter, ModeMenu, AllCourses, Nonstop, Oni, Endless, Length, Roulette, Recent.
-"weight" {m_iWeightPounds = atoi( sValue );}
+"sound"
+Plays the sound at the path once.
-"goalcalories" {m_iGoalCalories = atoi( sValue );}
+"stagemod"
+Sets a modifier to be applied to the stagemods.
-"goaltype" {m_GoalType = StringToGoalType( sValue );}
+"steps"
+Sets the current steps to the steps at the specified difficulty for the current song. Emits an error if the song or the style is not already set when the GameCommand is parsed.
-"profileid" {m_sProfileID = sValue;}
+"stopmusic"
+Stops the music that is currently playing. No argument.
-"url" {m_sUrl = sValue;}
+"style"
+The "style" command is used to set the style of the game. The style of the game controls how many pads/players are used. Acceptable args depend on the game type.
+For dance: single, versus, double, couple, solo, couple-edit, threepanel, routine
+For pump: single, versus, halfdouble, double, couple, couple-edit, routine
+For kb7: single, versus
+For ez2: single, real, versus, versusReal, double
+For para: single, versus
+For ds3ddx: single
+For beat: single5, versus5, double5, single7, versus7, double7
+For maniax: single, versus, double
+For techno: single4, single5, single8, versus4, versus5, versus8, double4, double5, double8
+For popn: popn-five, popn-nine
+For lights: cabinet
-"sound" {m_sSoundPath = sValue;}
+"text"
+Sets the text property of the GameCommand. This is an alternative to the name field used by some screens.
-"preparescreen" {m_vsScreensToPrepare.push_back( sValue );}
+"trail"
+Sets the current trail to the trail at the specified difficulty for the current course. Emits an error if the course or the style is not already set when the GameCommand is parsed.
-"insertcredit" {m_bInsertCredit = true;}
+"url"
+Exits the game and launches a browser to visit the url.
-"clearcredits" {m_bClearCredits = true;}
+"urlnoexit"
+Launches a browser to visit the url.
-"stopmusic" {m_bStopMusic = true;}
-
-"applydefaultoptions" {m_bApplyDefaultOptions = true;}
\ No newline at end of file
+"weight"
+Sets the weight of the player.
diff --git a/Themes/_fallback/BGAnimations/ScreenSystemLayer error.lua b/Themes/_fallback/BGAnimations/ScreenSystemLayer error.lua
new file mode 100644
index 0000000000..b7b932cb04
--- /dev/null
+++ b/Themes/_fallback/BGAnimations/ScreenSystemLayer error.lua
@@ -0,0 +1,57 @@
+-- If you are a common themer, DO NOT INCLUDE THIS FILE IN YOUR THEME.
+-- This layer is purely for error reporting, so that you can see errors on screen easily while running stepmania.
+-- If you include this file in your theme, you will not benefit from any improvements in error reporting.
+-- If you want to adjust how long errors stay on screen for, call the "SetErrorMessageTime" function. (see usage notes in comments above that function)
+
+local line_height= 12 -- A good line height for Common Normal at .5 zoom.
+
+local min_message_time= {show= 1, hide= .03125}
+local default_message_time= {show= 4, hide= .125}
+local message_time= {}
+for k, v in pairs(default_message_time) do
+ message_time[k]= v
+end
+
+-- Example usage:
+-- "SetErrorMessageTime('show' 5)" sets errors to show for 5 seconds before beginning to hide.
+-- "SetErrorMessageTime('hide' .5)" sets errors to hide one error every .5 seconds after the show time has passed.
+function SetErrorMessageTime(which, t)
+ if not min_message_time[which] then
+ MESSAGEMAN:Broadcast(
+ "ScriptError", {
+ Message= "Attempted to set invalid overlay message time field: " ..
+ tostring(which)})
+ return
+ end
+ if t < min_message_time[which] then
+ MESSAGEMAN:Broadcast(
+ "ScriptError", {
+ Message= "Attempted to set overlay message " .. which ..
+ " time to below minimum of " .. min_message_time[which] .. "."})
+ return
+ end
+ message_time[which]= t
+end
+
+function GetErrorMessageTime(which)
+ return message_time[which]
+end
+
+function GetErrorMessageTimeMin(which)
+ return min_message_time[which]
+end
+
+function GetErrorMessageTimeDefault(which)
+ return default_message_time[which]
+end
+
+local log_args= {
+ Name= "ScriptError",
+ ReplaceLinesWhenHidden= true,
+ Times= message_time,
+ Font= "Common Error",
+}
+
+Trace("Loaded error layer.")
+
+return Def.LogDisplay(log_args)
diff --git a/Themes/_fallback/Fonts/Common Error.redir b/Themes/_fallback/Fonts/Common Error.redir
new file mode 100644
index 0000000000..dde05763a4
--- /dev/null
+++ b/Themes/_fallback/Fonts/Common Error.redir
@@ -0,0 +1 @@
+_open sans book 24px
diff --git a/Themes/_fallback/Languages/en.ini b/Themes/_fallback/Languages/en.ini
index 237922b3cd..0eb3886c49 100644
--- a/Themes/_fallback/Languages/en.ini
+++ b/Themes/_fallback/Languages/en.ini
@@ -1301,6 +1301,7 @@ Assist=Assist
AutoPlay=AutoPlay
Autosync=Autosync
CPU=CPU
+Clear Errors=Clear Errors
Clear Profile Stats=Clear Profile Scores
CoinMode=CoinMode
Debug Menu=Debug Menu
@@ -1317,6 +1318,7 @@ Profile=Profile
Pull Back Camera=Pull Back Camera
Restart=Restart
Reload=Reload
+Reload Overlay Screens=Reload Overlay Screens
Reload Theme and Textures=Reload Theme and Textures
Rendering Stats=Rendering Stats
Screen Test Mode=Screen Test Mode
@@ -1327,6 +1329,7 @@ Show Masks=Show Masks
Slow=Slow
Song=Song
Tempo=Tempo
+Toggle Errors=Toggle Show Errors
Uptime=Uptime
Visual Delay Down=Visual Delay Down
Visual Delay Up=Visual Delay Up
diff --git a/Themes/_fallback/Scripts/02 Utilities.lua b/Themes/_fallback/Scripts/02 Utilities.lua
index aa99ec0767..2d456e770b 100644
--- a/Themes/_fallback/Scripts/02 Utilities.lua
+++ b/Themes/_fallback/Scripts/02 Utilities.lua
@@ -371,6 +371,78 @@ function IsUsingWideScreen()
end;
end;
+-- Minor text formatting functions from Kyzentun.
+-- TODO: Figure out why BitmapText:maxwidth doesn't do what I want.
+-- Intentionally undocumented because they should be moved to BitmapText ASAP
+function width_limit_text(text, limit, natural_zoom)
+ natural_zoom= natural_zoom or 1
+ if text:GetWidth() * natural_zoom > limit then
+ text:zoomx(limit / text:GetWidth())
+ else
+ text:zoomx(natural_zoom)
+ end
+end
+
+function width_clip_text(text, limit)
+ local full_text= text:GetText()
+ local fits= text:GetZoomedWidth() <= limit
+ local prev_max= #full_text - 1
+ local prev_min= 0
+ if not fits then
+ while prev_max - prev_min > 1 do
+ local new_max= math.round((prev_max + prev_min) / 2)
+ text:settext(full_text:sub(1, 1+new_max))
+ if text:GetZoomedWidth() <= limit then
+ prev_min= new_max
+ else
+ prev_max= new_max
+ end
+ end
+ text:settext(full_text:sub(1, 1+prev_min))
+ end
+end
+
+function width_clip_limit_text(text, limit, natural_zoom)
+ natural_zoom= natural_zoom or text:GetZoomY()
+ local text_width= text:GetWidth() * natural_zoom
+ if text_width > limit * 2 then
+ text:zoomx(natural_zoom * .5)
+ width_clip_text(text, limit)
+ else
+ width_limit_text(text, limit, natural_zoom)
+ end
+end
+
+function convert_text_to_indented_lines(text, indent, width, text_zoom)
+ local text_as_lines= split("\n", text:GetText())
+ local indented_lines= {}
+ for i, line in ipairs(text_as_lines) do
+ local remain= line
+ local sub_lines= 0
+ repeat
+ text:settext(remain)
+ local clipped= false
+ local indent_mult= 0
+ if i > 1 then
+ indent_mult= indent_mult + 1
+ end
+ if sub_lines > 0 then
+ indent_mult= 2
+ end
+ local usable_width= width - (indent * indent_mult)
+ if text:GetWidth() * text_zoom > usable_width * 2 then
+ clipped= true
+ width_clip_text(text, usable_width * 2)
+ end
+ indented_lines[#indented_lines+1]= {
+ indent_mult, text:GetText()}
+ remain= remain:sub(#text:GetText()+1)
+ sub_lines= sub_lines + 1
+ until not clipped
+ end
+ return indented_lines
+end
+
-- (c) 2005-2011 Glenn Maynard, Chris Danford, SSC
-- All rights reserved.
--
diff --git a/Themes/_fallback/Scripts/04 LogDisplay.lua b/Themes/_fallback/Scripts/04 LogDisplay.lua
new file mode 100644
index 0000000000..4bfb50564b
--- /dev/null
+++ b/Themes/_fallback/Scripts/04 LogDisplay.lua
@@ -0,0 +1,313 @@
+-- This is a little fake actor class meant for displaying lines of a log.
+-- It's placed inside Def, but it's actually just an ActorFrame with some
+-- children and special commands.
+
+-- LogDisplay listens for several messages that control its behavior.
+-- The name given to the LogDisplay is added to the name of the message to
+-- make the messages unique to this LogDisplay. So to issue a command to
+-- the LogDisplay, broadcast the message "".
+-- For a LogDisplay named "Foo", you would broadcase "Foo" to add to the
+-- log, "ToggleFoo" to toggle whether it's shown or hidden, and so on.
+
+-- Some of the control messages take tables of args.
+-- Arg elements of the form "name= type" are named, and must be a value of
+-- the given type.
+-- Arg elements of the form "name" are unnamed.
+
+-- The messages are:
+-- : params= {message= string, dont_show= bool}
+-- Adds message to the log to be shown when revealing.
+-- If dont_show is false, then Show will be automatically executed with
+-- auto_hide= true.
+-- Messages with line breaks will take up multiple lines.
+-- The newest message in the log has index 1.
+-- Toggle: No params
+-- Executes either Show or Hide, depending on the current state.
+-- Show: params= {range= {last_message, lines}, auto_hide= bool}
+-- Shows the messages currently in the log.
+-- range[1] is the index of the last message to show.
+-- range[2] is the max number of lines to show.
+-- range[1] defaults to a cleavage shot.
+-- range[2] defaults to MaxDisplayLines.
+-- If auto_hide is non-nil, Hide will be execuated after a short time.
+-- If auto_hide is a number, it will be used as the time to wait before
+-- hiding. Otherwise, the Times.show will be used.
+-- Query: No params
+-- Broadcasts "Response" message with a table containing:
+-- {log_len= number, hidden= bool}
+-- log_len is the number of messages currently in the log.
+-- hidden is whether the LogDisplay is currently hidden.
+-- Hide: No params
+-- Hides the LogDisplay.
+-- Clear: params= {messages}
+-- Clears the messages in the log. If messages is a number, only clears
+-- that many messages, oldest first.
+
+-- params to Def.LogDisplay():
+-- {
+-- Name= string
+-- The name will be used as the name of the main ActorFrame and to
+-- control what messages the LogDisplay listens for.
+-- MaxLogLen= number
+-- The maximum number of messages to store in the log.
+-- MaxDisplayLines= number
+-- The maximum number of lines that can be displayed at a time.
+-- ReplaceLinesWhenHidden= bool
+-- If this is true, any messages recieved while the LogDisplay is hidden
+-- will replace the message currently at the front of the log.
+-- If this is false, messages recieved while the LogDisplay is hidden
+-- will push other messages back. Messages pushed past MaxLines will be
+-- removed.
+-- Font= font name
+-- The name of the font to use. This will be passed to THEME:GetPathF,
+-- so it should not be a path.
+-- LineHeight= number
+-- The height in pixels to use between lines.
+-- LineWidth= number
+-- The width that lines should be limited to.
+-- TextZoom= number
+-- The zoom factor to apply to the text.
+-- TextColor= color
+-- The color to use for the text.
+-- Times= {show= number, hide= number}
+-- show is the amount of time to wait before automatically hiding when
+-- Show is executed with AutoHide == true. It's passed as a table, so
+-- if you keep a copy of the table, you should be able to modify it to
+-- change the time.
+-- hide is used as the time for the default hide command to hide.
+-- Indent= number
+-- The amount in pixels to indent lines that were part of a multi-line
+-- message.
+-- Hide= function(self)
+-- This command will be executed when the LogDisplay needs to be hidden.
+-- Hide will also be executed during the InitCommand, so the
+-- LogDisplay will start in the hidden state.
+-- Show= function(self, Lines)
+-- This command will be executed when the LogDisplay needs to be shown.
+-- Lines is the number of lines to show.
+-- }
+-- Any actors placed in params will be used and drawn behind the text.
+-- If there are no actors in params, a quad filling the area will be used.
+-- Reasonable defaults are provided for everything except Name. If Name is
+-- blank, you get nothing. Defaults assume the LogDisplay should fill the
+-- screen when in use.
+
+-- Below is the implementation of the above features.
+
+local log_display_mt= {
+ __index= {
+ create_actors= function(self, params)
+ self.name= params.Name
+ self.font= params.Font or "Common Normal"
+ self.line_height= params.LineHeight or 12
+ self.line_width= params.LineWidth or SCREEN_WIDTH
+ self.text_zoom= params.TextZoom or .5
+ self.text_color= params.TextColor or color("#93a1a1")
+ self.max_lines= params.MaxLines or SCREEN_HEIGHT / self.line_height
+ self.max_log= params.MaxLogLen or self.max_lines
+ self.indent= params.Indent or 8
+ self.times= params.Times
+ self.param_hide= params.Hide or
+ function(subself)
+ subself:linear(params.Times.hide)
+ subself:y(-SCREEN_HEIGHT)
+ end
+ self.param_show= params.Show or
+ function(subself, lines)
+ subself:visible(true)
+ subself:linear(params.Times.hide)
+ local cover= math.min(self.line_height * (lines+.5), SCREEN_HEIGHT)
+ subself:y(-SCREEN_HEIGHT + cover)
+ end
+
+ self.text_actors= {}
+ self.message_log= {}
+ self.messes_since_update= 0
+
+ local name_mess= self.name .. "MessageCommand"
+ local args= {
+ Name= self.name,
+ InitCommand= function(subself)
+ self.container= subself; -- This semicolon ends this statement.
+ -- Without it, the next would be ambiguous syntax.
+ -- Let the InitCommand passed in params do something.
+ (params.InitCommand or function() end)(subself)
+ self:hide()
+ end,
+ OffCommand= function(subself)
+ subself:visible(false)
+ for i, actor in ipairs(self.text_actors) do
+ actor:visible(false)
+ end
+ end,
+ [name_mess]= function(subself, mess)
+ if not mess.message then return end
+ if self.messes_since_update > self.max_log then return end
+ -- Long ago, someone decided that "::" should be an alias for "\n"
+ -- and hardcoded it into BitmapText.
+ local message= tostring(mess.message):gsub("::", ":")
+ if params.ReplaceLinesWhenHidden and self.hidden then
+ self:clear()
+ self.message_log[1]= message
+ else
+ table.insert(self.message_log, 1, message)
+ if #self.message_log > self.max_log then
+ table.remove(self.message_log)
+ end
+ end
+ if not mess.dont_show or not self.hidden then
+ self.messes_since_update= self.messes_since_update + 1
+ self.hidden= false
+ subself:stoptweening()
+ subself:queuecommand("Update")
+ end
+ end,
+ ["Toggle" .. name_mess]= function(subself)
+ if self.hidden then
+ self:show()
+ else
+ self:hide()
+ end
+ end,
+ ["Hide" .. name_mess]= function(subself)
+ self:hide()
+ end,
+ ["Show" .. name_mess]= function(subself, mess)
+ self:show(mess.range, mess.auto_hide)
+ end,
+ ["Clear" .. name_mess]= function(subself, mess)
+ self:clear(mess[1])
+ end,
+ UpdateCommand= function(subself)
+ self:show(nil, true)
+ self.messes_since_update= 0
+ end,
+ LoadFont(self.font) ..
+ {
+ Name="WidthTester",
+ InitCommand= function(subself)
+ self.width_tester= subself
+ subself:zoom(self.text_zoom)
+ subself:visible(false)
+ end
+ }
+ }
+ if #params == 0 then
+ args[#args+1]= Def.Quad {
+ Name= "Logbg",
+ InitCommand= function(subself)
+ subself:setsize(self.line_width, self.line_height*self.max_lines)
+ subself:horizalign(left)
+ subself:vertalign(top)
+ subself:diffuse(color("#002b36"))
+ subself:diffusealpha(.85)
+ end,
+ }
+ else
+ -- Add bg actors passed through params.
+ for i, actor in ipairs(params) do
+ args[#args+1]= actor
+ end
+ end
+ -- Add commands passed through params.
+ for name, command in pairs(params) do
+ if type(name) == "string" and name:find("Command") and not args[name] then
+ args[name]= command
+ end
+ end
+ for i= 1, self.max_lines do
+ args[#args+1]= LoadFont(self.font) ..
+ {
+ Name="Text" .. i,
+ InitCommand= function(subself)
+ -- Put them in the list in reverse order so the ones at the
+ -- bottom of the screen are used first.
+ self.text_actors[self.max_lines-i+1]= subself
+ subself:horizalign(left)
+ subself:vertalign(top)
+ subself:y(self.line_height * (i-1))
+ subself:zoom(self.text_zoom)
+ subself:diffuse(self.text_color)
+ subself:visible(false)
+ end,
+ OffCommand= cmd(visible,false),
+ }
+ end
+ return Def.ActorFrame(args)
+ end,
+ hide= function(self)
+ self.container:stoptweening()
+ self.param_hide(self.container)
+ self.container:queuecommand("Off")
+ self.hidden= true
+ end,
+ show= function(self, range, auto_hide)
+ if not range then range= {} end
+ local start= range[1] or 1
+ local lmax= range[2] or self.max_lines
+ local indented_lines= {}
+ local next_message= start
+ local num_lines= 0
+ while num_lines < lmax and self.message_log[next_message] do
+ self.width_tester:settext(self.message_log[next_message])
+ local lines_to_add= convert_text_to_indented_lines(
+ self.width_tester, self.indent, self.line_width, self.text_zoom)
+ indented_lines[#indented_lines+1]= lines_to_add
+ num_lines= num_lines + #lines_to_add
+ next_message= next_message + 1
+ end
+ local use_next= 1
+ local used= 0
+ for i, mess in ipairs(indented_lines) do
+ for l, line in ipairs(mess) do
+ -- Start at the end of the mess because the text actors are in
+ -- reverse order.
+ local ind= use_next + (#mess - l)
+ local actor= self.text_actors[ind]
+ if actor and used <= lmax then
+ actor:settext(line[2])
+ local indent= 8 + self.indent * line[1]
+ local lw= self.line_width - (indent + 8)
+ width_limit_text(actor, lw, self.text_zoom)
+ actor:x(indent)
+ actor:visible(true)
+ used= used + 1
+ end
+ end
+ use_next= use_next + #mess
+ end
+ self.container:stoptweening()
+ self.param_show(self.container, used)
+ self.hidden= false
+ if auto_hide then
+ self.container:sleep(self.times.show)
+ self.container:queuecommand("Hide" .. self.name)
+ end
+ end,
+ clear= function(self, messes)
+ if #self.message_log < 1 then return end
+ if not messes then
+ self.message_log= {}
+ else
+ for i= 1, messes do
+ table.remove(self.message_log)
+ if #self.message_log < 1 then break end
+ end
+ end
+ end
+}}
+
+function Def.LogDisplay(params)
+ if type(params.Name) ~= "string" or params.Name == "" then
+ ReportScriptError("Cannot create a LogDisplay without a name.")
+ return nil
+ end
+
+ if not params.Times then params.Times= {show= 4, hide= .125} end
+ if not params.Times.show then params.Times.show= 4 end
+ if not params.Times.hide then params.Times.hide= .125 end
+
+ local new_log_display= setmetatable({}, log_display_mt)
+ _G[params.Name .. "LogDisplay"]= new_log_display
+ return new_log_display:create_actors(params)
+end
diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini
index 8fe8fda8da..66c3de676d 100644
--- a/Themes/_fallback/metrics.ini
+++ b/Themes/_fallback/metrics.ini
@@ -57,7 +57,7 @@ SelectMusicScreen="ScreenSelectMusic"
# Screens that show over everything else.
# Only mess with this if you know what you're doing.
-OverlayScreens="ScreenSystemLayer,ScreenSyncOverlay,ScreenStatsOverlay,ScreenDebugOverlay,ScreenConsoleOverlay,ScreenInstallOverlay"
+OverlayScreens="ScreenSystemLayer,ScreenSyncOverlay,ScreenStatsOverlay,ScreenDebugOverlay,ScreenInstallOverlay"
# Used in PlayerStageStats for formatting scores.
PercentScoreDecimalPlaces=2
@@ -1580,16 +1580,6 @@ CreditsP2ScreenChangedMessageCommand=queuecommand,"UpdateVisible";queuecommand,"
CreditsP2OnCommand=horizalign,right;vertalign,bottom;zoom,0.675;shadowlength,1;
CreditsP2OffCommand=
-[ScreenConsoleOverlay]
-Class="ScreenSystemLayer"
-Fallback="ScreenSystemLayer"
-#
-CreditsInitCommand=visible,false;zoom,0
-CreditsP1X=-9999
-CreditsP2X=-9999
-CreditsP1Y=-9999
-CreditsP2Y=-9999
-
[ScreenInstallOverlay]
Class="ScreenInstallOverlay"
Fallback="Screen"
diff --git a/src/Actor.cpp b/src/Actor.cpp
index 5ab0620f28..5d96198cf1 100644
--- a/src/Actor.cpp
+++ b/src/Actor.cpp
@@ -4,7 +4,6 @@
#include "RageUtil.h"
#include "RageMath.h"
#include "RageLog.h"
-#include "arch/Dialog/Dialog.h"
#include "Foreach.h"
#include "XmlFile.h"
#include "LuaBinding.h"
@@ -793,10 +792,7 @@ void Actor::BeginTweening( float time, ITween *pTween )
// recursing ActorCommand.
if( m_Tweens.size() > 50 )
{
- RString sError = ssprintf( "Tween overflow: \"%s\"; infinitely recursing ActorCommand?", GetLineage().c_str() );
-
- LOG->Warn( "%s", sError.c_str() );
- Dialog::OK( sError );
+ LuaHelpers::ReportScriptErrorFmt("Tween overflow: \"%s\"; infinitely recursing ActorCommand?", GetLineage().c_str());
this->FinishTweening();
}
@@ -1129,7 +1125,7 @@ void Actor::RunCommands( const LuaReference& cmds, const LuaReference *pParamTab
{
if( !cmds.IsSet() || cmds.IsNil() )
{
- LOG->Warn( "RunCommands: command is unset or nil" );
+ LuaHelpers::ReportScriptError("RunCommands: command is unset or nil");
return;
}
@@ -1139,7 +1135,7 @@ void Actor::RunCommands( const LuaReference& cmds, const LuaReference *pParamTab
cmds.PushSelf( L );
if( lua_isnil(L, -1) )
{
- LOG->Warn("Error compiling commands");
+ LuaHelpers::ReportScriptError("Error compiling commands");
LUA->Release(L);
return;
}
@@ -1154,9 +1150,8 @@ void Actor::RunCommands( const LuaReference& cmds, const LuaReference *pParamTab
pParamTable->PushSelf( L );
// call function with 2 arguments and 0 results
- RString sError;
- if( !LuaHelpers::RunScriptOnStack(L, sError, 2, 0) )
- LOG->Warn( "Error playing command: %s", sError.c_str() );
+ RString Error= "Error playing command: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 2, 0, true);
LUA->Release(L);
}
@@ -1301,7 +1296,7 @@ void Actor::AddCommand( const RString &sCmdName, apActorCommands apac )
if( HasCommand(sCmdName) )
{
RString sWarning = GetLineage()+"'s command '"+sCmdName+"' defined twice";
- Dialog::OK( sWarning, "COMMAND_DEFINED_TWICE" );
+ LuaHelpers::ReportScriptError(sWarning, "COMMAND_DEFINED_TWICE");
}
RString sMessage;
@@ -1404,7 +1399,7 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: sleep(%f): time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: sleep(%f): time must not be negative", fTime);
return 0;
}
p->Sleep(fTime);
@@ -1415,7 +1410,7 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: linear(%f): tween time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: linear(%f): tween time must not be negative", fTime);
return 0;
}
p->BeginTweening(fTime, TWEEN_LINEAR);
@@ -1426,7 +1421,7 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: accelerate(%f): tween time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: accelerate(%f): tween time must not be negative", fTime);
return 0;
}
p->BeginTweening(fTime, TWEEN_ACCELERATE);
@@ -1437,7 +1432,7 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: decelerate(%f): tween time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: decelerate(%f): tween time must not be negative", fTime);
return 0;
}
p->BeginTweening(fTime, TWEEN_DECELERATE);
@@ -1448,7 +1443,7 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: spring(%f): tween time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: spring(%f): tween time must not be negative", fTime);
return 0;
}
p->BeginTweening(fTime, TWEEN_SPRING);
@@ -1459,11 +1454,14 @@ public:
float fTime = FArg(1);
if (fTime < 0)
{
- LOG->Warn("Lua: tween(%f): tween time must not be negative", fTime);
+ LuaHelpers::ReportScriptErrorFmt("Lua: tween(%f): tween time must not be negative", fTime);
return 0;
}
ITween *pTween = ITween::CreateFromStack( L, 2 );
- p->BeginTweening(fTime, pTween);
+ if(pTween != NULL)
+ {
+ p->BeginTweening(fTime, pTween);
+ }
return 0;
}
static int stoptweening( T* p, lua_State * ) { p->StopTweening(); return 0; }
@@ -1559,7 +1557,7 @@ public:
float fPeriod = FArg(1);
if (fPeriod <= 0)
{
- LOG->Warn("Effect period (%f) must be positive; ignoring", fPeriod);
+ LuaHelpers::ReportScriptErrorFmt("Effect period (%f) must be positive; ignoring", fPeriod);
return 0;
}
p->SetEffectPeriod(FArg(1));
@@ -1570,13 +1568,13 @@ public:
float f1 = FArg(1), f2 = FArg(2), f3 = FArg(3), f4 = FArg(4);
if (f1 < 0 || f2 < 0 || f3 < 0 || f4 < 0)
{
- LOG->Warn("Effect timings (%f,%f,%f,%f) must not be negative; ignoring",
+ LuaHelpers::ReportScriptErrorFmt("Effect timings (%f,%f,%f,%f) must not be negative; ignoring",
f1, f2, f3, f4);
return 0;
}
if (f1 == 0 && f2 == 0 && f3 == 0 && f4 == 0)
{
- LOG->Warn("Effect timings (0,0,0,0) must not all be zero; ignoring");
+ LuaHelpers::ReportScriptErrorFmt("Effect timings (0,0,0,0) must not all be zero; ignoring");
return 0;
}
p->SetEffectTiming(FArg(1), FArg(2), FArg(3), FArg(4));
diff --git a/src/ActorFrame.cpp b/src/ActorFrame.cpp
index 3f17a94056..845acd41eb 100644
--- a/src/ActorFrame.cpp
+++ b/src/ActorFrame.cpp
@@ -224,7 +224,7 @@ void ActorFrame::DrawPrimitives()
{
if( m_bClearZBuffer )
{
- LOG->Warn( "ClearZBuffer not supported on ActorFrames" );
+ LuaHelpers::ReportScriptErrorFmt( "ClearZBuffer not supported on ActorFrames" );
m_bClearZBuffer = false;
}
@@ -238,13 +238,12 @@ void ActorFrame::DrawPrimitives()
m_DrawFunction.PushSelf( L );
if( lua_isnil(L, -1) )
{
- LOG->Warn( "Error compiling DrawFunction" );
+ LuaHelpers::ReportScriptErrorFmt( "Error compiling DrawFunction" );
return;
}
this->PushSelf( L );
- RString sError;
- if( !LuaHelpers::RunScriptOnStack(L, sError, 1, 0) ) // 1 arg, 0 results
- LOG->Warn( "Error running DrawFunction: %s", sError.c_str() );
+ RString Error= "Error running DrawFunction: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 1, 0, true); // 1 arg, 0 results
LUA->Release(L);
return;
}
@@ -302,6 +301,8 @@ static int IdenticalChildrenSingleApplier(lua_State* L)
lua_pushvalue(L, lua_upvalueindex(1)); // stack: table, obj, args, func
lua_insert(L, 2); // stack: table, func, obj, args
int args_count= lua_gettop(L) - 2;
+ // Not using RunScriptOnStack because we're inside a lua call already and
+ // we want an error to propagate up.
lua_call(L, args_count, LUA_MULTRET); // stack: table, return_values
return lua_gettop(L) - 1;
}
@@ -477,15 +478,13 @@ void ActorFrame::UpdateInternal( float fDeltaTime )
m_UpdateFunction.PushSelf( L );
if( lua_isnil(L, -1) )
{
- LOG->Warn( "Error compiling UpdateFunction" );
+ LuaHelpers::ReportScriptErrorFmt( "Error compiling UpdateFunction" );
return;
}
this->PushSelf( L );
lua_pushnumber( L, fDeltaTime );
- RString sError;
-
- if( !LuaHelpers::RunScriptOnStack(L, sError, 2, 0) ) // 1 args, 0 results
- LOG->Warn( "Error running m_UpdateFunction: %s", sError.c_str() );
+ RString Error= "Error running UpdateFunction: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 2, 0, true); // 1 args, 0 results
LUA->Release(L);
}
}
diff --git a/src/ActorMultiVertex.cpp b/src/ActorMultiVertex.cpp
index 879b5f7a2a..4d1f932b45 100644
--- a/src/ActorMultiVertex.cpp
+++ b/src/ActorMultiVertex.cpp
@@ -358,13 +358,13 @@ void ActorMultiVertex::AMV_TweenState::SetDrawState( DrawMode dm, int first, int
{
if(first >= (int)vertices.size() && vertices.size() > 0)
{
- LOG->Warn("ActorMultiVertex:SetDrawState: FirstToDraw > vertices.size(), %d > %u", FirstToDraw + 1, (unsigned int)vertices.size() );
+ LuaHelpers::ReportScriptErrorFmt("ActorMultiVertex:SetDrawState: FirstToDraw > vertices.size(), %d > %u", FirstToDraw + 1, (unsigned int)vertices.size() );
return;
}
int safe_num= GetSafeNumToDraw( dm, num );
if( num != safe_num && num != -1 )
{
- LOG->Warn("ActorMultiVertex:SetDrawState: NumToDraw %d is not valid for %u vertices with DrawMode %s", num, (unsigned int)vertices.size(), DrawModeNames[dm] );
+ LuaHelpers::ReportScriptErrorFmt("ActorMultiVertex:SetDrawState: NumToDraw %d is not valid for %u vertices with DrawMode %s", num, (unsigned int)vertices.size(), DrawModeNames[dm] );
return;
}
_DrawMode= dm;
@@ -416,7 +416,7 @@ public:
// Use the number of arguments to determine which property a table is for
if(lua_type(L, DataStackIndex) != LUA_TTABLE)
{
- LOG->Warn("ActorMultiVertex::SetVertex: non-table parameter supplied. Table of tables of vertex data expected.");
+ LuaHelpers::ReportScriptErrorFmt("ActorMultiVertex::SetVertex: non-table parameter supplied. Table of tables of vertex data expected.");
return;
}
size_t NumDataParts = lua_objlen(L, DataStackIndex);
@@ -428,7 +428,7 @@ public:
size_t DataPieceElements = lua_objlen(L, DataPieceIndex);
if(lua_type(L, DataPieceIndex) != LUA_TTABLE)
{
- LOG->Warn( "ActorMultiVertex::SetVertex: non-table parameter %u supplied inside table of parameters, table expected.", (unsigned int)i );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetVertex: non-table parameter %u supplied inside table of parameters, table expected.", (unsigned int)i );
return;
}
int pushes = 1;
@@ -462,7 +462,7 @@ public:
}
else
{
- LOG->Warn( "ActorMultiVertex::SetVertex: Parameter %u has %u elements supplied. 2, 3, or 4 expected.", (unsigned int)i, (unsigned int)DataPieceElements );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetVertex: Parameter %u has %u elements supplied. 2, 3, or 4 expected.", (unsigned int)i, (unsigned int)DataPieceElements );
}
// Avoid a stack underflow by only popping the amount we pushed.
@@ -477,7 +477,7 @@ public:
int Index = IArg(1)-1;
if( Index < 0 )
{
- LOG->Warn( "ActorMultiVertex::SetVertex: index %d provided, cannot set Index < 1", Index+1 );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetVertex: index %d provided, cannot set Index < 1", Index+1 );
return 0;
}
else if( Index == (int) p->GetNumVertices() )
@@ -486,7 +486,7 @@ public:
}
else if( Index > (int) p->GetNumVertices() )
{
- LOG->Warn( "ActorMultiVertex::SetVertex: Cannot set vertex %d if there is no vertex %d, only %u vertices.", Index+1 , Index, (unsigned int)p->GetNumVertices() );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetVertex: Cannot set vertex %d if there is no vertex %d, only %u vertices.", Index+1 , Index, (unsigned int)p->GetNumVertices() );
return 0;
}
SetVertexFromStack(p, L, Index, lua_gettop(L));
@@ -504,7 +504,7 @@ public:
First = IArg(1)-1;
if( First < 0 )
{
- LOG->Warn( "ActorMultiVertex::SetVertices: index %d provided, cannot set Index < 1", First+1 );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetVertices: index %d provided, cannot set Index < 1", First+1 );
return 0;
}
}
@@ -542,7 +542,7 @@ public:
float Width = FArg(1);
if( Width < 0 )
{
- LOG->Warn( "ActorMultiVertex::SetLineWidth: cannot set negative width." );
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex::SetLineWidth: cannot set negative width." );
return 0;
}
p->SetLineWidth(Width);
@@ -557,7 +557,7 @@ public:
int ArgsIndex= 1;
if( !lua_istable(L, ArgsIndex) )
{
- LOG->Warn( "ActorMultiVertex:SetDrawState: Table expected, something else recieved. Doing nothing.");
+ LuaHelpers::ReportScriptErrorFmt( "ActorMultiVertex:SetDrawState: Table expected, something else recieved. Doing nothing.");
return 0;
}
// Fetch the draw mode, if provided.
diff --git a/src/ActorUtil.cpp b/src/ActorUtil.cpp
index 29046e9f19..3d48573c6c 100644
--- a/src/ActorUtil.cpp
+++ b/src/ActorUtil.cpp
@@ -55,7 +55,7 @@ bool ActorUtil::ResolvePath( RString &sPath, const RString &sName )
if( asPaths.empty() )
{
RString sError = ssprintf( "%s: references a file \"%s\" which doesn't exist", sName.c_str(), sPath.c_str() );
- switch( Dialog::AbortRetryIgnore( sError, "BROKEN_FILE_REFERENCE" ) )
+ switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true))
{
case Dialog::abort:
RageException::Throw( "%s", sError.c_str() );
@@ -76,7 +76,7 @@ bool ActorUtil::ResolvePath( RString &sPath, const RString &sName )
{
RString sError = ssprintf( "%s: references a file \"%s\" which has multiple matches", sName.c_str(), sPath.c_str() );
sError += "\n" + join( "\n", asPaths );
- switch( Dialog::AbortRetryIgnore( sError, "BROKEN_FILE_REFERENCE" ) )
+ switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true))
{
case Dialog::abort:
RageException::Throw( "%s", sError.c_str() );
@@ -246,7 +246,7 @@ namespace
{
LUA->Release( L );
sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
- Dialog::OK( sError, "LUA_ERROR" );
+ LuaHelpers::ReportScriptError(sError);
return NULL;
}
@@ -268,12 +268,10 @@ bool ActorUtil::LoadTableFromStackShowErrors( Lua *L )
lua_pushvalue( L, -1 );
func.SetFromStack( L );
- RString sError;
- if( !LuaHelpers::RunScriptOnStack(L, sError, 0, 1) )
+ RString Error= "Lua runtime error: ";
+ if( !LuaHelpers::RunScriptOnStack(L, Error, 0, 1, true) )
{
lua_pop( L, 1 );
- sError = ssprintf( "Lua runtime error: %s", sError.c_str() );
- Dialog::OK( sError, "LUA_ERROR" );
return false;
}
@@ -285,9 +283,9 @@ bool ActorUtil::LoadTableFromStackShowErrors( Lua *L )
lua_Debug debug;
lua_getinfo( L, ">nS", &debug );
- sError = ssprintf( "%s: must return a table", debug.short_src );
+ Error = ssprintf( "%s: must return a table", debug.short_src );
- Dialog::OK( sError, "LUA_ERROR" );
+ LuaHelpers::ReportScriptError(Error, "LUA_ERROR");
return false;
}
return true;
diff --git a/src/Background.cpp b/src/Background.cpp
index deddf700f9..910d5b4284 100644
--- a/src/Background.cpp
+++ b/src/Background.cpp
@@ -328,7 +328,7 @@ bool BackgroundImpl::Layer::CreateBackground( const Song *pSong, const Backgroun
switch( ft )
{
default:
- LOG->Warn( "CreateBackground() Unknown file type '%s'", vsResolved[0].c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "CreateBackground() Unknown file type '%s'", vsResolved[0].c_str() );
// fall through
case FT_Bitmap:
case FT_Sprite:
@@ -364,12 +364,12 @@ bool BackgroundImpl::Layer::CreateBackground( const Song *pSong, const Backgroun
BackgroundUtil::GetBackgroundEffects( sEffect, vsPaths, vsThrowAway );
if( vsPaths.empty() )
{
- LOG->Warn( "BackgroundEffect '%s' is missing.",sEffect.c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "BackgroundEffect '%s' is missing.",sEffect.c_str() );
sEffect = SBE_Centered;
}
else if( vsPaths.size() > 1 )
{
- LOG->Warn( "BackgroundEffect '%s' has more than one match.",sEffect.c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "BackgroundEffect '%s' has more than one match.",sEffect.c_str() );
sEffect = SBE_Centered;
}
else
@@ -744,7 +744,7 @@ void BackgroundImpl::Layer::UpdateCurBGChange( const Song *pSong, float fLastMus
XNode *pNode = change.m_def.CreateNode();
RString xml = XmlFileUtil::GetXML( pNode );
Trim( xml );
- LOG->Warn( "Tried to switch to a background that was never loaded:\n%s", xml.c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "Tried to switch to a background that was never loaded:\n%s", xml.c_str() );
SAFE_DELETE( pNode );
return;
}
diff --git a/src/BitmapText.cpp b/src/BitmapText.cpp
index c15cf2b57a..fd55c067d2 100644
--- a/src/BitmapText.cpp
+++ b/src/BitmapText.cpp
@@ -126,17 +126,22 @@ void BitmapText::LoadFromNode( const XNode* pNode )
ThemeManager::EvaluateString( sAltText );
RString sFont;
- if( !ActorUtil::GetAttrPath(pNode, "Font", sFont) &&
- !ActorUtil::GetAttrPath(pNode, "File", sFont) )
+ // Allow the Font attribute to be either a path or simply the name of a font.
+ // If it's a path, it will have a slash in it.
+ // Also allow it to be set through either "Font" or through "File".
+ if(!pNode->GetAttrValue("Font", sFont) && !pNode->GetAttrValue("File", sFont))
{
- if( !pNode->GetAttrValue("Font", sFont) &&
- !pNode->GetAttrValue("File", sFont) ) // accept "File" for backward compatibility
- {
- LOG->Warn( "%s: BitmapText: Font or File attribute not found",
- ActorUtil::GetWhere(pNode).c_str() );
- sFont = "Common Normal";
- }
- sFont = THEME->GetPathF( "", sFont );
+ LuaHelpers::ReportScriptErrorFmt("%s: BitmapText: Font or File attribute not found",
+ ActorUtil::GetWhere(pNode).c_str());
+ sFont = "Common Normal";
+ }
+ if(sFont.find("/") == RString::npos)
+ {
+ sFont= THEME->GetPathF("", sFont);
+ }
+ else if(!ActorUtil::ResolvePath(sFont, ActorUtil::GetWhere(pNode)))
+ {
+ sFont= THEME->GetPathF("", "Common Normal");
}
LoadFromFont( sFont );
diff --git a/src/ComboGraph.cpp b/src/ComboGraph.cpp
index e582f2a9fb..e562d269b0 100644
--- a/src/ComboGraph.cpp
+++ b/src/ComboGraph.cpp
@@ -61,7 +61,7 @@ void ComboGraph::Load( RString sMetricsGroup )
if( m_pComboNumber != NULL )
this->AddChild( m_pComboNumber );
else
- LOG->Warn( "ComboGraph: \"sMetricsGroup\" \"ComboNumber\" must be a BitmapText" );
+ LuaHelpers::ReportScriptErrorFmt( "ComboGraph: \"sMetricsGroup\" \"ComboNumber\" must be a BitmapText" );
}
}
diff --git a/src/Command.cpp b/src/Command.cpp
index a0332f037b..cb004a53f2 100644
--- a/src/Command.cpp
+++ b/src/Command.cpp
@@ -83,7 +83,13 @@ RString Commands::GetOriginalCommandString() const
{
RString s;
FOREACH_CONST( Command, v, c )
+ {
+ if(s != "")
+ {
+ s += ";";
+ }
s += c->GetOriginalCommandString();
+ }
return s;
}
diff --git a/src/CommonMetrics.cpp b/src/CommonMetrics.cpp
index b699738e03..7ca1fa2569 100644
--- a/src/CommonMetrics.cpp
+++ b/src/CommonMetrics.cpp
@@ -38,14 +38,23 @@ void ThemeMetricDifficultiesToShow::Read()
vector v;
split( ThemeMetric::GetValue(), ",", v );
- ASSERT( v.size() > 0 );
+ if(v.empty())
+ {
+ LuaHelpers::ReportScriptError("DifficultiesToShow must have at least one entry.");
+ return;
+ }
FOREACH_CONST( RString, v, i )
{
Difficulty d = StringToDifficulty( *i );
if( d == Difficulty_Invalid )
- RageException::Throw( "Unknown difficulty \"%s\" in CourseDifficultiesToShow.", i->c_str() );
- m_v.push_back( d );
+ {
+ LuaHelpers::ReportScriptErrorFmt("Unknown difficulty \"%s\" in CourseDifficultiesToShow.", i->c_str());
+ }
+ else
+ {
+ m_v.push_back( d );
+ }
}
}
const vector& ThemeMetricDifficultiesToShow::GetValue() const { return m_v; }
@@ -68,14 +77,23 @@ void ThemeMetricCourseDifficultiesToShow::Read()
vector v;
split( ThemeMetric::GetValue(), ",", v );
- ASSERT( v.size() > 0 );
+ if(v.empty())
+ {
+ LuaHelpers::ReportScriptError("CourseDifficultiesToShow must have at least one entry.");
+ return;
+ }
FOREACH_CONST( RString, v, i )
{
CourseDifficulty d = StringToDifficulty( *i );
if( d == Difficulty_Invalid )
- RageException::Throw( "Unknown CourseDifficulty \"%s\" in CourseDifficultiesToShow.", i->c_str() );
- m_v.push_back( d );
+ {
+ LuaHelpers::ReportScriptErrorFmt("Unknown CourseDifficulty \"%s\" in CourseDifficultiesToShow.", i->c_str());
+ }
+ else
+ {
+ m_v.push_back( d );
+ }
}
}
const vector& ThemeMetricCourseDifficultiesToShow::GetValue() const { return m_v; }
@@ -92,7 +110,7 @@ static void RemoveStepsTypes( vector& inout, RString sStepsTypesToRem
StepsType st = GAMEMAN->StringToStepsType(*i);
if( st == StepsType_Invalid )
{
- LOG->Warn( "Invalid StepsType value '%s' in '%s'", i->c_str(), sStepsTypesToRemove.c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "Invalid StepsType value '%s' in '%s'", i->c_str(), sStepsTypesToRemove.c_str() );
continue;
}
diff --git a/src/CourseContentsList.cpp b/src/CourseContentsList.cpp
index 2566465c15..43e76e1526 100644
--- a/src/CourseContentsList.cpp
+++ b/src/CourseContentsList.cpp
@@ -26,7 +26,10 @@ void CourseContentsList::LoadFromNode( const XNode* pNode )
const XNode *pDisplayNode = pNode->GetChild( "Display" );
if( pDisplayNode == NULL )
- RageException::Throw( "%s: CourseContentsList: missing the Display child", ActorUtil::GetWhere(pNode).c_str() );
+ {
+ LuaHelpers::ReportScriptErrorFmt("%s: CourseContentsList: missing the Display child", ActorUtil::GetWhere(pNode).c_str());
+ return;
+ }
for( int i=0; iGetChild( ssprintf("CursorP%i",pn+1) );
if( pChild == NULL )
- RageException::Throw( "%s: StepsDisplayList: missing the node \"CursorP%d\"", ActorUtil::GetWhere(pNode).c_str(), pn+1 );
- m_Cursors[pn].LoadActorFromNode( pChild, this );
+ {
+ LuaHelpers::ReportScriptErrorFmt("%s: StepsDisplayList: missing the node \"CursorP%d\"", ActorUtil::GetWhere(pNode).c_str(), pn+1);
+ }
+ else
+ {
+ m_Cursors[pn].LoadActorFromNode( pChild, this );
+ }
/* Hack: we need to tween cursors both up to down (cursor motion) and visible to
* invisible (fading). Cursor motion needs to stoptweening, so multiple motions
@@ -62,10 +71,15 @@ void StepsDisplayList::LoadFromNode( const XNode* pNode )
* colors; I think we do need a diffuse color stack ... */
pChild = pNode->GetChild( ssprintf("CursorP%iFrame",pn+1) );
if( pChild == NULL )
- RageException::Throw( "%s: StepsDisplayList: missing the node \"CursorP%dFrame\"", ActorUtil::GetWhere(pNode).c_str(), pn+1 );
- m_CursorFrames[pn].LoadFromNode( pChild );
- m_CursorFrames[pn].AddChild( m_Cursors[pn] );
- this->AddChild( &m_CursorFrames[pn] );
+ {
+ LuaHelpers::ReportScriptErrorFmt("%s: StepsDisplayList: missing the node \"CursorP%dFrame\"", ActorUtil::GetWhere(pNode).c_str(), pn+1);
+ }
+ else
+ {
+ m_CursorFrames[pn].LoadFromNode( pChild );
+ m_CursorFrames[pn].AddChild( m_Cursors[pn] );
+ this->AddChild( &m_CursorFrames[pn] );
+ }
}
for( unsigned m = 0; m < m_Lines.size(); ++m )
diff --git a/src/DynamicActorScroller.cpp b/src/DynamicActorScroller.cpp
index ba877146de..b8f4cc7d86 100644
--- a/src/DynamicActorScroller.cpp
+++ b/src/DynamicActorScroller.cpp
@@ -18,7 +18,15 @@ void DynamicActorScroller::LoadFromNode( const XNode *pNode )
*
* Make one extra copy if masking is enabled. */
if( m_SubActors.size() != 1 )
- RageException::Throw( "%s: DynamicActorScroller: loaded %i nodes; require exactly one", ActorUtil::GetWhere(pNode).c_str(), (int)m_SubActors.size() );
+ {
+ LuaHelpers::ReportScriptErrorFmt("%s: DynamicActorScroller: loaded %i nodes; require exactly one", ActorUtil::GetWhere(pNode).c_str(), (int)m_SubActors.size());
+ // Remove all but one.
+ for( size_t i=1; iWarn( "Error running LoadFunction: %s", sError.c_str() );
+ RString Error= "Error running LoadFunction: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 2, 1, true); // 2 args, 1 result
m_iNumItems = (int) luaL_checknumber( L, -1 );
lua_pop( L, 1 );
@@ -119,9 +126,8 @@ void DynamicActorScroller::ConfigureActor( Actor *pActor, int iItem )
pActor->PushSelf( L );
LuaHelpers::Push( L, iItem );
- RString sError;
- if( !LuaHelpers::RunScriptOnStack(L, sError, 2, 0) ) // 2 args, 0 results
- LOG->Warn( "Error running LoadFunction: %s", sError.c_str() );
+ RString Error= "Error running LoadFunction: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 2, 0, true); // 2 args, 0 results
LUA->Release(L);
}
diff --git a/src/EnumHelper.cpp b/src/EnumHelper.cpp
index cc9d274f82..921a92a935 100644
--- a/src/EnumHelper.cpp
+++ b/src/EnumHelper.cpp
@@ -70,7 +70,7 @@ int CheckEnum( lua_State *L, LuaReference &table, int iPos, int iInvalid, const
{
RString errmsg;
LuaHelpers::Pop(L, errmsg);
- LOG->Warn(errmsg.c_str());
+ LuaHelpers::ReportScriptError(errmsg);
lua_pop(L, 2);
return iInvalid;
}
diff --git a/src/GameCommand.cpp b/src/GameCommand.cpp
index cf399ad2ef..e8ee6a1554 100644
--- a/src/GameCommand.cpp
+++ b/src/GameCommand.cpp
@@ -14,7 +14,6 @@
#include "Game.h"
#include "Style.h"
#include "Foreach.h"
-#include "arch/Dialog/Dialog.h"
#include "GameSoundManager.h"
#include "PlayerState.h"
#include "SongManager.h"
@@ -176,31 +175,40 @@ void GameCommand::LoadOne( const Command& cmd )
sValue += cmd.m_vsArgs[i];
}
+#define MAKE_INVALID(expr) \
+ m_sInvalidReason= (expr); \
+ LuaHelpers::ReportScriptError(m_sInvalidReason, "INVALID_GAME_COMMAND"); \
+ m_bInvalid= true;
+
+#define CHECK_INVALID_COND(member, value, cond, message) \
+ if(cond) \
+ { \
+ MAKE_INVALID(message); \
+ } \
+ else \
+ { \
+ member= value; \
+ }
+
+#define CHECK_INVALID_VALUE(member, value, invalid_value, value_name) \
+ CHECK_INVALID_COND(member, value, (value == invalid_value), ssprintf("Invalid "#value_name" \"%s\".", sValue.c_str()));
+
if( sName == "style" )
{
const Style* style = GAMEMAN->GameAndStringToStyle( GAMESTATE->m_pCurGame, sValue );
- if( style )
- m_pStyle = style;
- else
- m_bInvalid = true;
+ CHECK_INVALID_VALUE(m_pStyle, style, NULL, style);
}
else if( sName == "playmode" )
{
PlayMode pm = StringToPlayMode( sValue );
- if( pm != PlayMode_Invalid )
- m_pm = pm;
- else
- m_bInvalid = true;
+ CHECK_INVALID_VALUE(m_pm, pm, PlayMode_Invalid, playmode);
}
else if( sName == "difficulty" )
{
Difficulty dc = StringToDifficulty( sValue );
- if( dc != Difficulty_Invalid )
- m_dc = dc;
- else
- m_bInvalid = true;
+ CHECK_INVALID_VALUE(m_dc, dc, Difficulty_Invalid, difficulty);
}
else if( sName == "announcer" )
@@ -235,22 +243,22 @@ void GameCommand::LoadOne( const Command& cmd )
else if( sName == "lua" )
{
m_LuaFunction.SetFromExpression( sValue );
- ASSERT_M( !m_LuaFunction.IsNil(), ssprintf("\"%s\" evaluated to nil", sValue.c_str()) );
+ if(m_LuaFunction.IsNil())
+ {
+ MAKE_INVALID("Lua error in game command: \"" + sValue + "\" evaluated to nil");
+ }
}
else if( sName == "screen" )
{
- m_sScreen = sValue;
+ CHECK_INVALID_COND(m_sScreen, sValue, (!SCREENMAN->IsScreenNameValid(sValue)), ("Screen \"" + sValue + "\" has invalid class."));
}
else if( sName == "song" )
{
- m_pSong = SONGMAN->FindSong( sValue );
- if( m_pSong == NULL )
- {
- m_sInvalidReason = ssprintf( "Song \"%s\" not found", sValue.c_str() );
- m_bInvalid |= true;
- }
+ CHECK_INVALID_COND(m_pSong, SONGMAN->FindSong(sValue),
+ (SONGMAN->FindSong(sValue) == NULL),
+ (ssprintf("Song \"%s\" not found", sValue.c_str())));
}
else if( sName == "steps" )
@@ -263,29 +271,32 @@ void GameCommand::LoadOne( const Command& cmd )
Song *pSong = (m_pSong != NULL)? m_pSong:GAMESTATE->m_pCurSong;
const Style *pStyle = m_pStyle ? m_pStyle : GAMESTATE->GetCurrentStyle();
if( pSong == NULL || pStyle == NULL )
- RageException::Throw( "Must set Song and Style to set Steps." );
-
- Difficulty dc = StringToDifficulty( sSteps );
- if( dc != Difficulty_Edit )
- m_pSteps = SongUtil::GetStepsByDifficulty( pSong, pStyle->m_StepsType, dc );
- else
- m_pSteps = SongUtil::GetStepsByDescription( pSong, pStyle->m_StepsType, sSteps );
- if( m_pSteps == NULL )
{
- m_sInvalidReason = "steps not found";
- m_bInvalid |= true;
+ MAKE_INVALID("Must set Song and Style to set Steps.");
+ }
+ else
+ {
+ Difficulty dc = StringToDifficulty( sSteps );
+ Steps* st;
+ if( dc < Difficulty_Edit )
+ {
+ st = SongUtil::GetStepsByDifficulty( pSong, pStyle->m_StepsType, dc );
+ }
+ else
+ {
+ st = SongUtil::GetStepsByDescription( pSong, pStyle->m_StepsType, sSteps );
+ }
+ CHECK_INVALID_COND(m_pSteps, st, (st == NULL),
+ (ssprintf("Steps \"%s\" not found", sSteps.c_str())));
}
}
}
else if( sName == "course" )
{
- m_pCourse = SONGMAN->FindCourse( "", sValue );
- if( m_pCourse == NULL )
- {
- m_sInvalidReason = ssprintf( "Course \"%s\" not found", sValue.c_str() );
- m_bInvalid |= true;
- }
+ CHECK_INVALID_COND(m_pCourse, SONGMAN->FindCourse("", sValue),
+ (SONGMAN->FindCourse("", sValue) == NULL),
+ (ssprintf( "Course \"%s\" not found", sValue.c_str())));
}
else if( sName == "trail" )
@@ -298,39 +309,50 @@ void GameCommand::LoadOne( const Command& cmd )
Course *pCourse = (m_pCourse != NULL)? m_pCourse:GAMESTATE->m_pCurCourse;
const Style *pStyle = m_pStyle ? m_pStyle : GAMESTATE->GetCurrentStyle();
if( pCourse == NULL || pStyle == NULL )
- RageException::Throw( "Must set Course and Style to set Steps." );
-
- const CourseDifficulty cd = StringToDifficulty( sTrail );
- ASSERT_M( cd != Difficulty_Invalid, ssprintf("Invalid difficulty '%s'", sTrail.c_str()) );
-
- m_pTrail = pCourse->GetTrail( pStyle->m_StepsType, cd );
- if( m_pTrail == NULL )
{
- m_sInvalidReason = "trail not found";
- m_bInvalid |= true;
+ MAKE_INVALID("Must set Course and Style to set Trail.");
+ }
+ else
+ {
+ const CourseDifficulty cd = StringToDifficulty( sTrail );
+ if(cd == Difficulty_Invalid)
+ {
+ MAKE_INVALID(ssprintf("Invalid difficulty '%s'", sTrail.c_str()));
+ }
+ else
+ {
+ Trail* tr = pCourse->GetTrail(pStyle->m_StepsType, cd);
+ CHECK_INVALID_COND(m_pTrail, tr, (tr == NULL),
+ ("Trail \"" + sTrail + "\" not found."));
+ }
}
}
}
else if( sName == "setenv" )
{
- if( cmd.m_vsArgs.size() == 3 )
- m_SetEnv[ cmd.m_vsArgs[1] ] = cmd.m_vsArgs[2];
+ if((cmd.m_vsArgs.size() - 1) % 2 != 0)
+ {
+ MAKE_INVALID("Arguments to setenv game command must be key,value pairs.");
+ }
+ else
+ {
+ for(size_t i= 1; i < cmd.m_vsArgs.size(); i+= 2)
+ {
+ m_SetEnv[cmd.m_vsArgs[i]]= cmd.m_vsArgs[i+1];
+ }
+ }
}
else if( sName == "songgroup" )
{
- m_sSongGroup = sValue;
+ CHECK_INVALID_COND(m_sSongGroup, sValue, (!SONGMAN->DoesSongGroupExist(sValue)), ("Song group \"" + sValue + "\" does not exist."));
}
else if( sName == "sort" )
{
- m_SortOrder = StringToSortOrder( sValue );
- if( m_SortOrder == SortOrder_Invalid )
- {
- m_sInvalidReason = ssprintf( "SortOrder \"%s\" is not valid.", sValue.c_str() );
- m_bInvalid |= true;
- }
+ SortOrder so= StringToSortOrder(sValue);
+ CHECK_INVALID_VALUE(m_SortOrder, so, SortOrder_Invalid, sortorder);
}
else if( sName == "weight" )
@@ -345,7 +367,8 @@ void GameCommand::LoadOne( const Command& cmd )
else if( sName == "goaltype" )
{
- m_GoalType = StringToGoalType( sValue );
+ GoalType go= StringToGoalType(sValue);
+ CHECK_INVALID_VALUE(m_GoalType, go, GoalType_Invalid, goaltype);
}
else if( sName == "profileid" )
@@ -398,15 +421,23 @@ void GameCommand::LoadOne( const Command& cmd )
else if( sName == "setpref" )
{
- if( cmd.m_vsArgs.size() == 3 )
+ if((cmd.m_vsArgs.size() - 1) % 2 != 0)
{
- IPreference *pPref = IPreference::GetPreferenceByName( cmd.m_vsArgs[1] );
- if( pPref == NULL )
+ MAKE_INVALID("Arguments to setpref game command must be key,value pairs.");
+ }
+ else
+ {
+ for(size_t i= 1; i < cmd.m_vsArgs.size(); i+= 2)
{
- m_sInvalidReason = ssprintf("unknown preference \"%s\"", cmd.m_vsArgs[1].c_str() );
- m_bInvalid |= true;
+ if(IPreference::GetPreferenceByName(cmd.m_vsArgs[i]) == NULL)
+ {
+ MAKE_INVALID("Unknown preference \"" + cmd.m_vsArgs[i] + "\".");
+ }
+ else
+ {
+ m_SetPref[cmd.m_vsArgs[i]]= cmd.m_vsArgs[i+1];
+ }
}
- pPref->FromString(cmd.m_vsArgs[2]);
}
}
@@ -418,14 +449,19 @@ void GameCommand::LoadOne( const Command& cmd )
m_fMusicFadeOutVolume = static_cast(atof( cmd.m_vsArgs[1] ));
m_fMusicFadeOutSeconds = static_cast(atof( cmd.m_vsArgs[2] ));
}
+ else
+ {
+ MAKE_INVALID("Wrong number of args to fademusic.");
+ }
}
else
{
- RString sWarning = ssprintf( "Command '%s' is not valid.", cmd.GetOriginalCommandString().c_str() );
- LOG->Warn( "%s", sWarning.c_str() );
- Dialog::OK( sWarning, "INVALID_GAME_COMMAND" );
+ MAKE_INVALID(ssprintf( "Command '%s' is not valid.", cmd.GetOriginalCommandString().c_str()));
}
+#undef CHECK_INVALID_VALUE
+#undef CHECK_INVALID_COND
+#undef MAKE_INVALID
}
int GetNumCreditsPaid()
@@ -444,8 +480,8 @@ int GetCreditsRequiredToPlayStyle( const Style *style )
{
// GameState::GetCoinsNeededToJoin returns 0 if the coin mode isn't
// CoinMode_Pay, which means the theme can't make sure that there are
- // enough credits available. GameCommand::IsPlayable will cause a crash
- // if there aren't enough credits. So we have to check the coin mode here
+ // enough credits available.
+ // So we have to check the coin mode here
// and return 0 if the player doesn't have to pay.
if( GAMESTATE->GetCoinMode() != CoinMode_Pay )
{
@@ -679,7 +715,7 @@ void GameCommand::ApplySelf( const vector &vpns ) const
}
break;
default:
- FAIL_M(ssprintf("Invalid StyleType: %i", m_pStyle->m_StyleType));
+ LuaHelpers::ReportScriptError("Invalid StyleType: " + m_pStyle->m_StyleType);
}
}
if( m_dc != Difficulty_Invalid )
@@ -693,7 +729,7 @@ void GameCommand::ApplySelf( const vector &vpns ) const
if( m_sStageModifiers != "" )
FOREACH_CONST( PlayerNumber, vpns, pn )
GAMESTATE->ApplyStageModifiers( *pn, m_sStageModifiers );
- if( m_LuaFunction.IsSet() )
+ if( m_LuaFunction.IsSet() && !m_LuaFunction.IsNil() )
{
Lua *L = LUA->Get();
FOREACH_CONST( PlayerNumber, vpns, pn )
@@ -702,7 +738,8 @@ void GameCommand::ApplySelf( const vector &vpns ) const
ASSERT( !lua_isnil(L, -1) );
lua_pushnumber( L, *pn ); // 1st parameter
- lua_call( L, 1, 0 ); // call function with 1 argument and 0 results
+ RString error= "Lua GameCommand error: ";
+ LuaHelpers::RunScriptOnStack(L, error, 1, 0, true);
}
LUA->Release(L);
}
@@ -740,6 +777,14 @@ void GameCommand::ApplySelf( const vector &vpns ) const
lua_pop( L, 1 );
LUA->Release(L);
}
+ for(map::const_iterator setting= m_SetPref.begin(); setting != m_SetPref.end(); ++setting)
+ {
+ IPreference* pref= IPreference::GetPreferenceByName(setting->first);
+ if(pref != NULL)
+ {
+ pref->FromString(setting->second);
+ }
+ }
if( !m_sSongGroup.empty() )
GAMESTATE->m_sPreferredSongGroup.Set( m_sSongGroup );
if( m_SortOrder != SortOrder_Invalid )
diff --git a/src/GameCommand.h b/src/GameCommand.h
index d0641292ba..cad1ae9c62 100644
--- a/src/GameCommand.h
+++ b/src/GameCommand.h
@@ -34,7 +34,7 @@ public:
m_sAnnouncer(""), m_sPreferredModifiers(""),
m_sStageModifiers(""), m_sScreen(""), m_LuaFunction(),
m_pSong(NULL), m_pSteps(NULL), m_pCourse(NULL),
- m_pTrail(NULL), m_pCharacter(NULL), m_SetEnv(),
+ m_pTrail(NULL), m_pCharacter(NULL), m_SetEnv(), m_SetPref(),
m_sSongGroup(""), m_SortOrder(SortOrder_Invalid),
m_sSoundPath(""), m_vsScreensToPrepare(), m_iWeightPounds(-1),
m_iGoalCalories(-1), m_GoalType(GoalType_Invalid),
@@ -92,6 +92,7 @@ public:
Trail* m_pTrail;
Character* m_pCharacter;
std::map m_SetEnv;
+ std::map m_SetPref;
RString m_sSongGroup;
SortOrder m_SortOrder;
RString m_sSoundPath; // "" for no sound
diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp
index d30cba98da..74ccdb0d6a 100644
--- a/src/GameLoop.cpp
+++ b/src/GameLoop.cpp
@@ -145,6 +145,13 @@ namespace
StepMania::ResetGame();
SCREENMAN->ThemeChanged();
+ // Not all themes use the same screen names! Check whether the new
+ // screen is valid in the new theme before setting it. Use the
+ // InitialScreen metric if it's not.
+ if(!SCREENMAN->IsScreenNameValid(g_sNewScreen))
+ {
+ g_sNewScreen= THEME->GetMetric("Common", "InitialScreen");
+ }
SCREENMAN->SetNewScreen( g_sNewScreen );
g_sNewTheme = RString();
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 57a58f8377..67a3135d87 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -222,7 +222,10 @@ void GameState::ApplyGameCommand( const RString &sCommand, PlayerNumber pn )
RString sWhy;
if( !m.IsPlayable(&sWhy) )
- RageException::Throw( "Can't apply mode \"%s\": %s", sCommand.c_str(), sWhy.c_str() );
+ {
+ LuaHelpers::ReportScriptErrorFmt("Can't apply GameCommand \"%s\": %s", sCommand.c_str(), sWhy.c_str());
+ return;
+ }
if( pn == PLAYER_INVALID )
m.ApplyToAllPlayers();
@@ -1879,7 +1882,7 @@ void GameState::StoreRankingName( PlayerNumber pn, RString sName )
{
if( file.GetLine(sLine) == -1 )
{
- LOG->Warn( "Error reading \"%s\": %s", NAME_BLACKLIST_FILE, file.GetError().c_str() );
+ LuaHelpers::ReportScriptErrorFmt( "Error reading \"%s\": %s", NAME_BLACKLIST_FILE, file.GetError().c_str() );
break;
}
@@ -2085,7 +2088,7 @@ Difficulty GameState::GetEasiestStepsDifficulty() const
{
if( m_pCurSteps[p] == NULL )
{
- LOG->Warn( "GetEasiestStepsDifficulty called but p%i hasn't chosen notes", p+1 );
+ LuaHelpers::ReportScriptErrorFmt( "GetEasiestStepsDifficulty called but p%i hasn't chosen notes", p+1 );
continue;
}
dc = min( dc, m_pCurSteps[p]->GetDifficulty() );
@@ -2100,7 +2103,7 @@ Difficulty GameState::GetHardestStepsDifficulty() const
{
if( m_pCurSteps[p] == NULL )
{
- LOG->Warn( "GetHardestStepsDifficulty called but p%i hasn't chosen notes", p+1 );
+ LuaHelpers::ReportScriptErrorFmt( "GetHardestStepsDifficulty called but p%i hasn't chosen notes", p+1 );
continue;
}
dc = max( dc, m_pCurSteps[p]->GetDifficulty() );
diff --git a/src/HoldJudgment.cpp b/src/HoldJudgment.cpp
index bfd0f04a1f..26656d8120 100644
--- a/src/HoldJudgment.cpp
+++ b/src/HoldJudgment.cpp
@@ -27,8 +27,10 @@ void HoldJudgment::Load( const RString &sPath )
void HoldJudgment::LoadFromNode( const XNode* pNode )
{
RString sFile;
- if( ActorUtil::GetAttrPath(pNode, "File", sFile) )
- RageException::Throw( "%s: HoldJudgment: missing the attribute \"File\"", ActorUtil::GetWhere(pNode).c_str() );
+ if(!ActorUtil::GetAttrPath(pNode, "File", sFile))
+ {
+ LuaHelpers::ReportScriptErrorFmt("%s: HoldJudgment: missing the attribute \"File\"", ActorUtil::GetWhere(pNode).c_str());
+ }
CollapsePath( sFile );
diff --git a/src/LuaExpressionTransform.cpp b/src/LuaExpressionTransform.cpp
index f8da8d936e..7ddeb91d56 100644
--- a/src/LuaExpressionTransform.cpp
+++ b/src/LuaExpressionTransform.cpp
@@ -26,7 +26,8 @@ void LuaExpressionTransform::TransformItemDirect( Actor &a, float fPositionOffse
LuaHelpers::Push( L, fPositionOffsetFromCenter );
LuaHelpers::Push( L, iItemIndex );
LuaHelpers::Push( L, iNumItems );
- lua_call( L, 4, 0 ); // 4 args, 0 results
+ RString error= "Lua error in Transform function: ";
+ LuaHelpers::RunScriptOnStack(L, error, 4, 0, true);
LUA->Release(L);
}
diff --git a/src/LuaManager.cpp b/src/LuaManager.cpp
index 550109848f..39eb6b452d 100644
--- a/src/LuaManager.cpp
+++ b/src/LuaManager.cpp
@@ -9,7 +9,9 @@
#include "arch/Dialog/Dialog.h"
#include "XmlFile.h"
#include "Command.h"
+#include "RageLog.h"
#include "RageTypes.h"
+#include "MessageManager.h"
#include // conversion for lua functions.
#include
@@ -45,6 +47,8 @@ namespace LuaHelpers
template<> bool FromStack( Lua *L, float &Object, int iOffset );
template<> bool FromStack( Lua *L, int &Object, int iOffset );
template<> bool FromStack( Lua *L, RString &Object, int iOffset );
+
+ bool InReportScriptError= false;
}
void LuaManager::SetGlobal( const RString &sName, int val )
@@ -787,52 +791,102 @@ bool LuaHelpers::LoadScript( Lua *L, const RString &sScript, const RString &sNam
return true;
}
-bool LuaHelpers::RunScriptOnStack( Lua *L, RString &sError, int iArgs, int iReturnValues )
+void LuaHelpers::ScriptErrorMessage(RString const& Error)
+{
+ Message msg("ScriptError");
+ msg.SetParam("message", Error);
+ MESSAGEMAN->Broadcast(msg);
+}
+
+Dialog::Result LuaHelpers::ReportScriptError(RString const& Error, RString ErrorType, bool UseAbort)
+{
+ // Protect from a recursion loop resulting from a mistake in the error reporting lua.
+ if(!InReportScriptError)
+ {
+ InReportScriptError= true;
+ ScriptErrorMessage(Error);
+ InReportScriptError= false;
+ }
+ LOG->Warn(Error.c_str());
+ if(UseAbort)
+ {
+ RString with_correct= Error + " Correct this and click Retry, or Cancel to break.";
+ return Dialog::AbortRetryIgnore(with_correct, ErrorType);
+ }
+ Dialog::OK(Error, ErrorType);
+ return Dialog::ok;
+}
+
+// For convenience when replacing uses of LOG->Warn.
+void LuaHelpers::ReportScriptErrorFmt(const char *fmt, ...)
+{
+ va_list va;
+ va_start( va, fmt );
+ RString Buff = vssprintf( fmt, va );
+ va_end( va );
+ ReportScriptError(Buff);
+}
+
+bool LuaHelpers::RunScriptOnStack( Lua *L, RString &Error, int Args, int ReturnValues, bool ReportError )
{
lua_pushcfunction( L, GetLuaStack );
// move the error function above the function and params
- int iErrFunc = lua_gettop(L) - iArgs - 1;
- lua_insert( L, iErrFunc );
+ int ErrFunc = lua_gettop(L) - Args - 1;
+ lua_insert( L, ErrFunc );
// evaluate
- int ret = lua_pcall( L, iArgs, iReturnValues, iErrFunc );
+ int ret = lua_pcall( L, Args, ReturnValues, ErrFunc );
if( ret )
{
- LuaHelpers::Pop( L, sError );
- lua_remove( L, iErrFunc );
- for( int i = 0; i < iReturnValues; ++i )
+ if(ReportError)
+ {
+ RString lerror;
+ LuaHelpers::Pop( L, lerror );
+ Error+= lerror;
+ ReportScriptError(Error);
+ }
+ else
+ {
+ LuaHelpers::Pop( L, Error );
+ }
+ lua_remove( L, ErrFunc );
+ for( int i = 0; i < ReturnValues; ++i )
lua_pushnil( L );
return false;
}
- lua_remove( L, iErrFunc );
+ lua_remove( L, ErrFunc );
return true;
}
-bool LuaHelpers::RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs, int iReturnValues )
+bool LuaHelpers::RunScript( Lua *L, const RString &Script, const RString &Name, RString &Error, int Args, int ReturnValues, bool ReportError )
{
- if( !LoadScript(L, sScript, sName, sError) )
+ RString lerror;
+ if( !LoadScript(L, Script, Name, lerror) )
{
- lua_pop( L, iArgs );
- for( int i = 0; i < iReturnValues; ++i )
+ Error+= lerror;
+ if(ReportError)
+ {
+ ReportScriptError(Error);
+ }
+ lua_pop( L, Args );
+ for( int i = 0; i < ReturnValues; ++i )
lua_pushnil( L );
return false;
}
// move the function above the params
- lua_insert( L, lua_gettop(L) - iArgs );
+ lua_insert( L, lua_gettop(L) - Args );
- return LuaHelpers::RunScriptOnStack( L, sError, iArgs, iReturnValues );
+ return LuaHelpers::RunScriptOnStack( L, Error, Args, ReturnValues, ReportError );
}
bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RString &sName )
{
- RString sError;
- if( !LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 0, 1) )
+ RString sError= ssprintf("Lua runtime error parsing \"%s\": ", sName.size()? sName.c_str():sExpression.c_str());
+ if(!LuaHelpers::RunScript(L, "return " + sExpression, sName.empty()? RString("in"):sName, sError, 0, 1, true))
{
- sError = ssprintf( "Lua runtime error parsing \"%s\": %s", sName.size()? sName.c_str():sExpression.c_str(), sError.c_str() );
- Dialog::OK( sError, "LUA_ERROR" );
return false;
}
return true;
@@ -1090,6 +1144,22 @@ namespace
return 1;
}
+ static int ReportScriptError(lua_State* L)
+ {
+ RString error= "Script error occurred.";
+ RString error_type= "LUA_ERROR";
+ if(lua_isstring(L, 1))
+ {
+ error= SArg(1);
+ }
+ if(lua_isstring(L, 2))
+ {
+ error_type= SArg(2);
+ }
+ LuaHelpers::ReportScriptError(error, error_type);
+ return 0;
+ }
+
const luaL_Reg luaTable[] =
{
LIST_METHOD( Trace ),
@@ -1099,6 +1169,7 @@ namespace
LIST_METHOD( ReadFile ),
LIST_METHOD( RunWithThreadVariables ),
LIST_METHOD( GetThreadVariable ),
+ LIST_METHOD( ReportScriptError ),
{ NULL, NULL }
};
}
diff --git a/src/LuaManager.h b/src/LuaManager.h
index 1dce0a906b..644780eb67 100644
--- a/src/LuaManager.h
+++ b/src/LuaManager.h
@@ -15,6 +15,9 @@ extern "C"
#include "../extern/lua-5.1/src/lauxlib.h"
}
+// For Dialog::Result
+#include "arch/Dialog/Dialog.h"
+
class LuaManager
{
public:
@@ -58,15 +61,30 @@ namespace LuaHelpers
* and the stack is unchanged. */
bool LoadScript( Lua *L, const RString &sScript, const RString &sName, RString &sError );
+ /* Report the error three ways: Broadcast message, Warn, and Dialog. */
+ /* If UseAbort is true, reports the error through Dialog::AbortRetryIgnore
+ and returns the result. */
+ /* If UseAbort is false, reports the error through Dialog::OK and returns
+ Dialog::ok. */
+ Dialog::Result ReportScriptError(RString const& Error, RString ErrorType= "LUA_ERROR", bool UseAbort= false);
+ // Just the broadcast message part, for things that need to do the rest differently.
+ void ScriptErrorMessage(RString const& Error);
+ // For convenience when replacing uses of LOG->Warn.
+ void ReportScriptErrorFmt(const char *fmt, ...);
+
/* Run the function with arguments at the top of the stack, with the given
* number of arguments. The specified number of return values are left on
* the Lua stack. On error, nils are left on the stack, sError is set and
- * false is returned. */
- bool RunScriptOnStack( Lua *L, RString &sError, int iArgs = 0, int iReturnValues = 0 );
+ * false is returned.
+ * If ReportError is true, Error should contain the string to prepend
+ * when reporting. The error is reported through LOG->Warn and
+ * SCREENMAN->SystemMessage.
+ */
+ bool RunScriptOnStack( Lua *L, RString &Error, int Args = 0, int ReturnValues = 0, bool ReportError = false );
/* LoadScript the given script, and RunScriptOnStack it.
* iArgs arguments are at the top of the stack. */
- bool RunScript( Lua *L, const RString &sScript, const RString &sName, RString &sError, int iArgs = 0, int iReturnValues = 0 );
+ bool RunScript( Lua *L, const RString &Script, const RString &Name, RString &Error, int Args = 0, int ReturnValues = 0, bool ReportError = false );
/* Run the given expression, returning a single value, and leave the return
* value on the stack. On error, push nil. */
diff --git a/src/LyricsLoader.cpp b/src/LyricsLoader.cpp
index 9909416cd8..d617df2144 100644
--- a/src/LyricsLoader.cpp
+++ b/src/LyricsLoader.cpp
@@ -24,7 +24,7 @@ bool LyricsLoader::LoadFromLRCFile(const RString& sPath, Song& out)
RageFile input;
if( !input.Open(sPath) )
{
- LOG->Warn("Error opening file '%s' for reading: %s", sPath.c_str(), input.GetError().c_str() );
+ LuaHelpers::ReportScriptErrorFmt("Error opening file '%s' for reading: %s", sPath.c_str(), input.GetError().c_str() );
return false;
}
@@ -40,7 +40,7 @@ bool LyricsLoader::LoadFromLRCFile(const RString& sPath, Song& out)
break;
if( ret == -1 )
{
- LOG->Warn("Error reading %s: %s", input.GetPath().c_str(), input.GetError().c_str() );
+ LuaHelpers::ReportScriptErrorFmt("Error reading %s: %s", input.GetPath().c_str(), input.GetError().c_str() );
break;
}
diff --git a/src/MenuTimer.cpp b/src/MenuTimer.cpp
index 066b593e29..5115544399 100644
--- a/src/MenuTimer.cpp
+++ b/src/MenuTimer.cpp
@@ -183,9 +183,9 @@ void MenuTimer::SetText( float fSeconds )
LuaHelpers::Push( L, fSeconds );
// call function with 1 argument and 1 result
- RString sError;
- if( !LuaHelpers::RunScriptOnStack(L, sError, 1, 1) )
- LOG->Warn( "Error running Text%iFormatFunction: %s", i+1, sError.c_str() );
+ RString Error= "Error running Text" + (i+1);
+ Error+= "FormatFunction: ";
+ LuaHelpers::RunScriptOnStack(L, Error, 1, 1, true);
RString sText;
LuaHelpers::Pop( L, sText );
diff --git a/src/MessageManager.cpp b/src/MessageManager.cpp
index 6f4ffcda29..021b3100cb 100644
--- a/src/MessageManager.cpp
+++ b/src/MessageManager.cpp
@@ -5,6 +5,7 @@
#include "RageThreads.h"
#include "EnumHelper.h"
#include "LuaManager.h"
+#include "RageLog.h"
#include
#include