Made example programs not directly runnable (#450)

master
krzys-h 2015-04-17 22:39:57 +02:00
parent 45edb29de4
commit df4cb110b5
11 changed files with 46 additions and 6 deletions

View File

@ -186,6 +186,9 @@ msgstr ""
msgid "This program is read-only, clone it to edit"
msgstr ""
msgid "This is example code that cannot be run directly"
msgstr ""
msgid "\\b;List of objects\n"
msgstr ""

View File

@ -1486,6 +1486,9 @@ msgstr "Diese Klasse gibt es schon"
msgid "This class does not exist"
msgstr "Diese Klasse existiert nicht"
msgid "This is example code that cannot be run directly"
msgstr ""
msgid "This is not a member of this class"
msgstr "Dieses Element gibt es nicht in dieser Klasse"

View File

@ -1481,6 +1481,9 @@ msgstr "Cette classe existe déjà"
msgid "This class does not exist"
msgstr "Cette classe n'existe pas"
msgid "This is example code that cannot be run directly"
msgstr ""
msgid "This is not a member of this class"
msgstr "Cet élément n'existe pas dans cette classe"

View File

@ -1484,6 +1484,9 @@ msgstr "Taka klasa już istnieje"
msgid "This class does not exist"
msgstr "Taka klasa nie istnieje"
msgid "This is example code that cannot be run directly"
msgstr "To jest przykładowy kod którego nie można uruchomić bezpośrednio"
msgid "This is not a member of this class"
msgstr "To nie jest obiekt tej klasy"

View File

@ -1482,6 +1482,9 @@ msgstr "Этот класс уже существует"
msgid "This class does not exist"
msgstr "Этот класс не существует"
msgid "This is example code that cannot be run directly"
msgstr ""
msgid "This is not a member of this class"
msgstr "Это не член этого класса"

View File

@ -122,6 +122,7 @@ void InitializeRestext()
stringsText[RT_STUDIO_CLONED] = TR("Program cloned");
stringsText[RT_PROGRAM_READONLY] = TR("This program is read-only, clone it to edit");
stringsText[RT_PROGRAM_EXAMPLE] = TR("This is example code that cannot be run directly");
stringsText[RT_SATCOM_LIST] = TR("\\b;List of objects\n");
stringsText[RT_SATCOM_BOT] = TR("\\b;Robots\n");

View File

@ -118,6 +118,7 @@ enum ResTextType
RT_STUDIO_CLONED = 123,
RT_PROGRAM_READONLY = 130,
RT_PROGRAM_EXAMPLE = 131,
RT_SATCOM_LIST = 140,
RT_SATCOM_BOT = 141,

View File

@ -2311,7 +2311,7 @@ void CBrain::UpdateInterface()
EnableInterface(pw, EVENT_OBJECT_PROGLIST, bEnable && !m_bTraceRecord);
EnableInterface(pw, EVENT_OBJECT_PROGADD, m_currentProgram == nullptr);
EnableInterface(pw, EVENT_OBJECT_PROGREMOVE, m_currentProgram == nullptr && m_selScript < m_program.size() && !m_program[m_selScript]->readOnly);
EnableInterface(pw, EVENT_OBJECT_PROGCLONE, m_currentProgram == nullptr);
EnableInterface(pw, EVENT_OBJECT_PROGCLONE, m_currentProgram == nullptr && m_selScript < m_program.size() && m_program[m_selScript]->runnable);
EnableInterface(pw, EVENT_OBJECT_PROGMOVEUP, m_currentProgram == nullptr && m_program.size() >= 2 && m_selScript > 0);
EnableInterface(pw, EVENT_OBJECT_PROGMOVEDOWN,m_currentProgram == nullptr && m_program.size() >= 2 && m_selScript < m_program.size()-1);
EnableInterface(pw, EVENT_OBJECT_LEFT, bEnable);
@ -2460,10 +2460,17 @@ void CBrain::UpdateInterface()
bRun = false;
if ( m_selScript < m_program.size() )
{
m_program[m_selScript]->script->GetTitle(title);
if ( title[0] != 0 )
if(m_program[m_selScript]->runnable)
{
bRun = true;
m_program[m_selScript]->script->GetTitle(title);
if ( title[0] != 0 )
{
bRun = true;
}
}
else
{
bRun = false;
}
}
if ( !bEnable && m_currentProgram == nullptr ) bRun = false;
@ -3127,6 +3134,7 @@ Program* CBrain::AddProgram()
Program* program = new Program();
program->script = new CScript(m_object, &m_secondaryTask);
program->readOnly = false;
program->runnable = true;
AddProgram(program);
return program;
}

View File

@ -79,6 +79,7 @@ struct Program
CScript* script;
std::string filename;
bool readOnly;
bool runnable;
};

View File

@ -3637,10 +3637,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
std::string op = "script"+boost::lexical_cast<std::string>(i+1); // script1..script10
std::string opReadOnly = "scriptReadOnly"+boost::lexical_cast<std::string>(i+1); // scriptReadOnly1..scriptReadOnly10
std::string opRunnable = "scriptRunnable"+boost::lexical_cast<std::string>(i+1); // scriptRunnable1..scriptRunnable10
if(line->GetParam(op)->IsDefined()) {
Program* program = brain->AddProgram();
program->filename = "../"+line->GetParam(op)->AsPath("ai");
program->readOnly = line->GetParam(opReadOnly)->AsBool(true);
program->runnable = line->GetParam(opRunnable)->AsBool(strcmp(base, "exercises") || i+1 != 4); // TODO: I'd rather not have it hardcoded like that
loadedPrograms[i] = program;
}

View File

@ -649,7 +649,12 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra
button = pw->CreateButton(pos, dim, 64+29, EVENT_STUDIO_STEP);
button->SetState(STATE_SHADOW);
if(m_program->readOnly)
if(!m_program->runnable)
{
GetResource(RES_TEXT, RT_PROGRAM_EXAMPLE, res);
SetInfoText(res, false);
}
else if(m_program->readOnly)
{
GetResource(RES_TEXT, RT_PROGRAM_READONLY, res);
SetInfoText(res, false);
@ -1003,13 +1008,20 @@ void CStudio::UpdateButtons()
edit->SetHighlightCap(true);
}
button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_CLONE));
if ( button == 0 ) return;
button->SetState(STATE_ENABLE, m_program->runnable && !m_bRunning);
button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_COMPILE));
if ( button == 0 ) return;
button->SetState(STATE_ENABLE, !m_bRunning);
button->SetState(STATE_ENABLE, m_program->runnable && !m_bRunning);
button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_RUN));
if ( button == 0 ) return;
button->SetIcon(m_bRunning?8:21); // stop/run
button->SetState(STATE_ENABLE, m_program->runnable || m_bRunning);
button = static_cast< CButton* >(pw->SearchControl(EVENT_STUDIO_REALTIME));
if ( button == 0 ) return;