Moved error reporting to ScreenSystemLayer error.lua. ScreenSystemLayer overlay/default.lua restored to previous. Error messages are now broadcast with the ScriptError message instead of SystemMessage. Added show/hide error messages toggle and clear error messages to debug menu. Nuked ScreenConsoleOverlay for being unfinished and duplicating ScreenSystemLayer. Changed Actor:tween and Tween::CreateFromStack to use ReportScriptError on invalid tween params. Changed some OptionRowList things to use ReportScriptError on invalid metrics.

This commit is contained in:
Kyzentun
2014-07-08 20:01:33 -06:00
parent bee284d0c7
commit 63311ab62f
13 changed files with 321 additions and 179 deletions
@@ -0,0 +1,218 @@
-- 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 a different background behind the errors, then include "ScreenSystemLayer errorbg.lua" in your theme.
-- If you want to adjust how long errors stay on screen for, call the "SetErrorMessageTime" function. (see usage notes in comments above that function)
-- Minor text formatting functions from Kyzentun.
-- TODO: Figure out why BitmapText:maxwidth doesn't do what I want.
local 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
local 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
local 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
local text_actors= {}
local line_height= 12 -- A good line height for Common Normal at .5 zoom.
local line_width= SCREEN_WIDTH - 20
local next_message_actor= 1
local show_requested= false
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
Trace("Setting error message " .. which .. " time to " .. t)
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 frame_args= {
Name="Error frame",
InitCommand= function(self)
self:y(-SCREEN_HEIGHT)
end,
ScriptErrorMessageCommand = function(self, params)
show_requested= false
self:stoptweening()
self:visible(true)
local covered_height= math.min(line_height * next_message_actor, SCREEN_HEIGHT)
self:y(-SCREEN_HEIGHT + covered_height)
self:sleep(message_time.show)
self:queuecommand("DecNextActor")
-- Shift the text on all the actors being shown up by one.
for i= next_message_actor, 1, -1 do
if text_actors[i] then
text_actors[i]:visible(true)
if i > 1 and text_actors[i-1] then
text_actors[i]:settext(text_actors[i-1]:GetText())
else
text_actors[i]:settext(params.Message)
end
width_clip_limit_text(text_actors[i], line_width)
end
end
if next_message_actor <= #text_actors then
next_message_actor= next_message_actor + 1
end
end,
ToggleErrorsMessageCommand= function(self, params)
if show_requested then
self:playcommand("HideErrors")
else
self:playcommand("ShowErrors")
end
end,
ShowErrorsMessageCommand= function(self, params)
show_requested= true
for i, mactor in ipairs(text_actors) do
if mactor:GetText() ~= "" then
mactor:visible(true)
next_message_actor= next_message_actor + 1
end
end
next_message_actor= next_message_actor - 1
local covered_height= math.min(line_height * next_message_actor, SCREEN_HEIGHT)
self:stoptweening()
self:visible(true)
self:linear(message_time.hide)
self:y(-SCREEN_HEIGHT + covered_height)
end,
HideErrorsMessageCommand= function(self, params)
if not show_requested then return end
show_requested= false
self:stoptweening()
next_message_actor= 1
self:linear(message_time.hide)
self:y(-SCREEN_HEIGHT)
self:queuecommand("HideText")
end,
ClearErrorsMessageCommand= function(self, params)
-- This is so that someone using ShowErrorsMessageCommand can clear ones
-- they've dealt with.
-- Only allow clearing errors that we have scrolled off screen.
for i, mactor in ipairs(text_actors) do
if not mactor:GetVisible() then
mactor:settext("")
end
end
end,
DecNextActorCommand= function(self)
self:linear(message_time.hide)
self:y(self:GetY()-line_height)
if text_actors[next_message_actor] then
text_actors[next_message_actor]:visible(false)
end
next_message_actor= next_message_actor - 1
if next_message_actor > 1 then
self:queuecommand("DecNextActor")
else
self:queuecommand("Off")
end
end,
HideTextCommand= function(self)
for i, mactor in ipairs(text_actors) do
mactor:visible(false)
end
end,
OffCommand= cmd(visible,false),
Def.Quad {
Name= "errorbg",
InitCommand= function(self)
self:setsize(SCREEN_WIDTH, SCREEN_HEIGHT)
self:horizalign(left)
self:vertalign(top)
self:diffuse(color("0,0,0,0"))
self:diffusealpha(.85)
end,
}
}
-- Create enough text actors that we can fill the screen.
local num_text= SCREEN_HEIGHT / line_height
for i= 1, num_text do
frame_args[#frame_args+1]= LoadFont("Common","Normal") .. {
Name="Text" .. i,
InitCommand= function(self)
-- Put them in the list in reverse order so the ones at the bottom of the screen are used first.
text_actors[num_text-i+1]= self
self:horizalign(left)
self:vertalign(top)
self:x(SCREEN_LEFT + 10)
self:y(SCREEN_TOP + (line_height * (i-1)) + 2)
self:shadowlength(1)
self:zoom(.5)
self:visible(false)
end,
OffCommand= cmd(visible,false),
}
end
Trace("Loaded error layer.")
return Def.ActorFrame(frame_args)
@@ -1,14 +0,0 @@
return Def.ActorFrame{
Def.Quad {
Name= "erp",
InitCommand= function(self)
self:setsize(SCREEN_WIDTH, SCREEN_HEIGHT)
self:horizalign(left)
self:vertalign(top)
self:diffuse(color("0,0,0,0"))
self:diffusealpha(.85)
end,
SetCoveredHeightCommand= function(self, param)
end
}
}
@@ -64,147 +64,27 @@ t[#t+1] = Def.ActorFrame {
CreditsText( PLAYER_2 );
};
-- Text
-- Minor text formatting functions from Kyzentun.
-- TODO: Figure out why BitmapText:maxwidth doesn't do what I want.
local 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
local 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
local 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
local errorbg
local err_frame
local text_actors= {}
local line_height= 12 -- A good line height for Common Normal at .5 zoom.
local line_width= SCREEN_WIDTH - 20
local next_message_actor= 1
local min_message_time= { show= 4, hide= .125}
local message_time= {
show= min_message_time.show, hide= min_message_time.hide}
function SetOverlayMessageTime(t, which)
if not min_message_time[which] then
SCREENMAN:SystemMessage("Attempted to set invalid overlay message time field: " .. tostring(which))
return
end
if t < min_message_time[which] then
SCREENMAN:SystemMessage(
"Attempted to set overlay message " .. which ..
" time to below minimum of " .. min_message_time[which] .. ".")
return
end
message_time[which]= t
end
local errbg_actor= LoadActor(THEME:GetPathB("ScreenSystemLayer", "errorbg"))
-- Force the name of the returned actor so that we can easily use playcommand on it later.
errbg_actor.Name= "errorbg"
local frame_args= {
Name="Error frame",
InitCommand= function(self)
err_frame= self
errorbg= self:GetChild("errorbg")
self:y(-SCREEN_HEIGHT)
end,
t[#t+1] = Def.ActorFrame {
Def.Quad {
InitCommand=cmd(zoomtowidth,SCREEN_WIDTH;zoomtoheight,30;horizalign,left;vertalign,top;y,SCREEN_TOP;diffuse,color("0,0,0,0"));
OnCommand=cmd(finishtweening;diffusealpha,0.85;);
OffCommand=cmd(sleep,3;linear,0.5;diffusealpha,0;);
};
LoadFont("Common","Normal") .. {
Name="Text";
InitCommand=cmd(maxwidth,750;horizalign,left;vertalign,top;y,SCREEN_TOP+10;x,SCREEN_LEFT+10;shadowlength,1;diffusealpha,0;);
OnCommand=cmd(finishtweening;diffusealpha,1;zoom,0.5);
OffCommand=cmd(sleep,3;linear,0.5;diffusealpha,0;);
};
SystemMessageMessageCommand = function(self, params)
err_frame:stoptweening()
err_frame:visible(true)
local covered_height= line_height * (next_message_actor-1)
err_frame:y(-SCREEN_HEIGHT + covered_height)
if errorbg then
errorbg:playcommand("SetCoveredHeight", {height= covered_height})
self:GetChild("Text"):settext( params.Message );
self:playcommand( "On" );
if params.NoAnimate then
self:finishtweening();
end
err_frame:sleep(message_time.show)
err_frame:queuecommand("DecNextActor")
-- Shift the text on all the actors being shown up by one.
for i= next_message_actor, 1, -1 do
if text_actors[i] then
text_actors[i]:visible(true)
if i > 1 and text_actors[i-1] then
text_actors[i]:settext(text_actors[i-1]:GetText())
else
text_actors[i]:settext(params.Message)
end
width_clip_limit_text(text_actors[i], line_width)
end
end
if next_message_actor <= #text_actors and not params.NoAnimate then
next_message_actor= next_message_actor + 1
end
end,
DecNextActorCommand= function(self)
self:linear(message_time.hide)
self:y(self:GetY()-line_height)
if text_actors[next_message_actor] then
text_actors[next_message_actor]:visible(false)
end
next_message_actor= next_message_actor - 1
if next_message_actor > 1 then
self:queuecommand("DecNextActor")
else
self:queuecommand("Off")
end
end,
OffCommand= cmd(visible,false),
HideSystemMessageMessageCommand = cmd(finishtweening),
errbg_actor,
}
-- Create enough text actors that we can fill the screen.
local num_text= SCREEN_HEIGHT / line_height
for i= 1, num_text do
frame_args[#frame_args+1]= LoadFont("Common","Normal") .. {
Name="Text" .. i,
InitCommand= function(self)
-- Put them in the list in reverse order so the ones at the bottom of the screen are used first.
text_actors[num_text-i+1]= self
self:horizalign(left)
self:vertalign(top)
self:x(SCREEN_LEFT + 10)
self:y(SCREEN_TOP + (line_height * (i-1)) + 2)
self:shadowlength(1)
self:zoom(.5)
self:visible(false)
end,
OffCommand= cmd(visible,false),
}
end
t[#t+1] = Def.ActorFrame(frame_args)
self:playcommand( "Off" );
end;
HideSystemMessageMessageCommand = cmd(finishtweening);
};
return t
return t;
+2
View File
@@ -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
@@ -1328,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
+1 -11
View File
@@ -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"
+4 -1
View File
@@ -1458,7 +1458,10 @@ public:
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; }
+9 -1
View File
@@ -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; i<m_SubActors.size(); i++ )
{
delete m_SubActors[i];
}
m_SubActors.resize(1);
}
int iNumCopies = (int) m_fNumItemsToDraw;
if( m_quadMask.GetVisible() )
+4 -2
View File
@@ -11,7 +11,7 @@
#include "Command.h"
#include "RageLog.h"
#include "RageTypes.h"
#include "ScreenManager.h"
#include "MessageManager.h"
#include <sstream> // conversion for lua functions.
#include <csetjmp>
@@ -801,7 +801,9 @@ void LuaHelpers::ReportScriptError(RString const& Error, RString ErrorType)
{
short_error= Error.substr(0, line_break_pos);
}
SCREENMAN->SystemMessage(short_error);
Message msg("ScriptError");
msg.SetParam("Message", short_error);
MESSAGEMAN->Broadcast(msg);
LOG->Warn(Error.c_str());
Dialog::OK(Error, ErrorType);
}
+21 -6
View File
@@ -153,7 +153,10 @@ public:
// Parse the basic configuration metric.
Commands lCmds = ParseCommands( ENTRY(sParam) );
if( lCmds.v.size() < 1 )
RageException::Throw( "Parse error in \"ScreenOptionsMaster::%s\".", sParam.c_str() );
{
LuaHelpers::ReportScriptErrorFmt("Parse error in \"ScreenOptionsMaster::%s\".", sParam.c_str());
lCmds= ParseCommands("0");
}
m_Def.m_bOneChoiceForAllPlayers = false;
const int NumCols = StringToInt( lCmds.v[0].m_vsArgs[0] );
@@ -195,10 +198,20 @@ public:
}
else
{
RageException::Throw( "Unkown row flag \"%s\".", sName.c_str() );
LuaHelpers::ReportScriptErrorFmt( "Unkown row flag \"%s\".", sName.c_str() );
}
}
if(NumCols < 1)
{
LuaHelpers::ReportScriptErrorFmt(sParam + " has %d choices.", NumCols);
GameCommand mc;
mc.ApplyCommitsScreens( false );
mc.Load( 0, ParseCommands("name,Error") );
m_aListEntries.push_back(mc);
RString sChoice = mc.m_sName;
m_Def.m_vsChoices.push_back( sChoice );
}
for( int col = 0; col < NumCols; ++col )
{
GameCommand mc;
@@ -209,17 +222,19 @@ public:
if( mc.m_sName == "" && NumCols == 1 )
mc.m_sName = sParam;
if( mc.m_sName == "" )
RageException::Throw( "List \"%s\", col %i has no name.", sParam.c_str(), col );
{
LuaHelpers::ReportScriptErrorFmt("List \"%s\", col %i has no name.", sParam.c_str(), col);
mc.m_sName= "";
}
if( !mc.IsPlayable() )
{
LOG->Trace( "\"%s\" is not playable.", sParam.c_str() );
LuaHelpers::ReportScriptErrorFmt("\"%s\" is not playable.", sParam.c_str());
continue;
}
m_aListEntries.push_back( mc );
RString sName = mc.m_sName;
RString sChoice = mc.m_sName;
m_Def.m_vsChoices.push_back( sChoice );
}
@@ -543,7 +558,7 @@ public:
}
else
{
RageException::Throw( "Invalid StepsType param \"%s\".", sParam.c_str() );
LuaHelpers::ReportScriptErrorFmt("Invalid StepsType param \"%s\".", sParam.c_str());
}
m_Def.m_sName = sParam;
+33 -1
View File
@@ -549,6 +549,8 @@ static LocalizedString RESTART ( "ScreenDebugOverlay", "Restart" );
static LocalizedString SCREEN_ON ( "ScreenDebugOverlay", "Send On To Screen" );
static LocalizedString SCREEN_OFF ( "ScreenDebugOverlay", "Send Off To Screen" );
static LocalizedString RELOAD_OVERLAY_SCREENS( "ScreenDebugOverlay", "Reload Overlay Screens" );
static LocalizedString TOGGLE_ERRORS( "ScreenDebugOverlay", "Toggle Errors" );
static LocalizedString CLEAR_ERRORS( "ScreenDebugOverlay", "Clear Errors" );
static LocalizedString RELOAD_THEME_AND_TEXTURES( "ScreenDebugOverlay", "Reload Theme and Textures" );
static LocalizedString WRITE_PROFILES ( "ScreenDebugOverlay", "Write Profiles" );
static LocalizedString WRITE_PREFERENCES ( "ScreenDebugOverlay", "Write Preferences" );
@@ -1039,8 +1041,36 @@ class DebugLineReloadOverlayScreens : public IDebugLine
virtual RString GetPageName() const { return "Theme"; }
virtual void DoAndLog( RString &sMessageOut )
{
IDebugLine::DoAndLog(sMessageOut);
SCREENMAN->ReloadOverlayScreensAfterInputFinishes();
IDebugLine::DoAndLog(sMessageOut);
}
};
class DebugLineToggleErrors : public IDebugLine
{
virtual RString GetDisplayTitle() { return TOGGLE_ERRORS.GetValue(); }
virtual RString GetDisplayValue() { return RString(); }
virtual bool IsEnabled() { return true; }
virtual RString GetPageName() const { return "Theme"; }
virtual void DoAndLog( RString &sMessageOut )
{
Message msg("ToggleErrors");
MESSAGEMAN->Broadcast(msg);
IDebugLine::DoAndLog(sMessageOut);
}
};
class DebugLineClearErrors : public IDebugLine
{
virtual RString GetDisplayTitle() { return CLEAR_ERRORS.GetValue(); }
virtual RString GetDisplayValue() { return RString(); }
virtual bool IsEnabled() { return true; }
virtual RString GetPageName() const { return "Theme"; }
virtual void DoAndLog( RString &sMessageOut )
{
Message msg("ClearErrors");
MESSAGEMAN->Broadcast(msg);
IDebugLine::DoAndLog(sMessageOut);
}
};
@@ -1227,6 +1257,8 @@ DECLARE_ONE( DebugLineCurrentScreenOn );
DECLARE_ONE( DebugLineCurrentScreenOff );
DECLARE_ONE( DebugLineReloadTheme );
DECLARE_ONE( DebugLineReloadOverlayScreens );
DECLARE_ONE( DebugLineToggleErrors );
DECLARE_ONE( DebugLineClearErrors );
DECLARE_ONE( DebugLineWriteProfiles );
DECLARE_ONE( DebugLineWritePreferences );
DECLARE_ONE( DebugLineMenuTimer );
+3 -1
View File
@@ -155,8 +155,10 @@ void ScreenSystemLayer::Init()
{
Screen::Init();
m_sprOverlay.Load( THEME->GetPathB("ScreenSystemLayer", "overlay") );
m_sprOverlay.Load( THEME->GetPathB(m_sName, "overlay") );
this->AddChild( m_sprOverlay );
m_errLayer.Load( THEME->GetPathB(m_sName, "error") );
this->AddChild( m_errLayer );
}
/*
+1
View File
@@ -13,6 +13,7 @@ public:
private:
AutoActor m_sprOverlay;
AutoActor m_errLayer;
};
+4 -1
View File
@@ -97,7 +97,10 @@ ITween *ITween::CreateFromStack( Lua *L, int iStackPos )
luaL_checktype( L, iStackPos+1, LUA_TTABLE );
int iArgs = lua_objlen( L, iStackPos+1 );
if( iArgs != 4 && iArgs != 8 )
RageException::Throw( "CreateFromStack: table argument must have 4 or 8 entries" );
{
LuaHelpers::ReportScriptErrorFmt("Tween::CreateFromStack: table argument must have 4 or 8 entries");
return NULL;
}
float fC[8];
for( int i = 0; i < iArgs; ++i )