Fix TPTScript 'set' function
This commit is contained in:
parent
f75a3c2642
commit
622f2246ef
@ -310,6 +310,11 @@ int LuaScriptInterface::Command(std::string command)
|
|||||||
|
|
||||||
std::string LuaScriptInterface::FormatCommand(std::string command)
|
std::string LuaScriptInterface::FormatCommand(std::string command)
|
||||||
{
|
{
|
||||||
|
if(command[0] == '!')
|
||||||
|
{
|
||||||
|
return "!"+legacy->FormatCommand(command.substr(1));
|
||||||
|
}
|
||||||
|
else
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
AnyType value = eval(words);
|
AnyType value = eval(words);
|
||||||
|
|
||||||
Simulation * sim = m->GetSimulation();
|
Simulation * sim = m->GetSimulation();
|
||||||
|
unsigned char * partsBlock = (unsigned char*)&sim->parts[0];
|
||||||
|
|
||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
|
|
||||||
@ -205,10 +206,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
|
|
||||||
//Selector
|
//Selector
|
||||||
int newValue;
|
int newValue;
|
||||||
if(selector.GetType() == TypeNumber)
|
if(value.GetType() == TypeNumber)
|
||||||
newValue = ((NumberType)selector).Value();
|
newValue = ((NumberType)value).Value();
|
||||||
else if(selector.GetType() == TypeString)
|
else if(value.GetType() == TypeString)
|
||||||
newValue = GetParticleType(((StringType)selector).Value());
|
newValue = GetParticleType(((StringType)value).Value());
|
||||||
else
|
else
|
||||||
throw GeneralException("Invalid value for assignment");
|
throw GeneralException("Invalid value for assignment");
|
||||||
|
|
||||||
@ -230,10 +231,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
switch(propertyFormat)
|
switch(propertyFormat)
|
||||||
{
|
{
|
||||||
case FormatInt:
|
case FormatInt:
|
||||||
*((int*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
break;
|
break;
|
||||||
case FormatFloat:
|
case FormatFloat:
|
||||||
*((float*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
returnValue = 1;
|
returnValue = 1;
|
||||||
@ -248,7 +249,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type)
|
if(sim->parts[j].type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -258,7 +259,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type)
|
if(sim->parts[j].type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -274,6 +275,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
|
|
||||||
if(type<0 || type>=PT_NUM)
|
if(type<0 || type>=PT_NUM)
|
||||||
throw GeneralException("Invalid particle type");
|
throw GeneralException("Invalid particle type");
|
||||||
|
std::cout << propertyOffset << std::endl;
|
||||||
switch(propertyFormat)
|
switch(propertyFormat)
|
||||||
{
|
{
|
||||||
case FormatInt:
|
case FormatInt:
|
||||||
@ -282,7 +284,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type == type)
|
if(sim->parts[j].type == type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -292,7 +294,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type == type)
|
if(sim->parts[j].type == type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -17,7 +17,7 @@ ConsoleView::ConsoleView():
|
|||||||
ConsoleView * v;
|
ConsoleView * v;
|
||||||
public:
|
public:
|
||||||
CommandHighlighter(ConsoleView * v_) { v = v_; }
|
CommandHighlighter(ConsoleView * v_) { v = v_; }
|
||||||
void TextChangedCallback(ui::Textbox * sender)
|
virtual void TextChangedCallback(ui::Textbox * sender)
|
||||||
{
|
{
|
||||||
sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
|
sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
|
||||||
}
|
}
|
||||||
@ -43,6 +43,7 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
|
|||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
c->EvaluateCommand(commandField->GetText());
|
c->EvaluateCommand(commandField->GetText());
|
||||||
commandField->SetText("");
|
commandField->SetText("");
|
||||||
|
commandField->SetDisplayText("");
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
c->NextCommand();
|
c->NextCommand();
|
||||||
@ -88,6 +89,7 @@ void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
|
|||||||
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
|
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
|
||||||
{
|
{
|
||||||
commandField->SetText(sender->GetCurrentCommand().Command);
|
commandField->SetText(sender->GetCurrentCommand().Command);
|
||||||
|
commandField->SetDisplayText(c->FormatCommand(commandField->GetText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,6 +266,11 @@ void Label::updateSelection()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::SetDisplayText(std::string newText)
|
||||||
|
{
|
||||||
|
displayText = newText;
|
||||||
|
}
|
||||||
|
|
||||||
void Label::Draw(const Point& screenPos)
|
void Label::Draw(const Point& screenPos)
|
||||||
{
|
{
|
||||||
if(!drawn)
|
if(!drawn)
|
||||||
@ -282,6 +287,23 @@ void Label::Draw(const Point& screenPos)
|
|||||||
}
|
}
|
||||||
Graphics * g = Engine::Ref().g;
|
Graphics * g = Engine::Ref().g;
|
||||||
|
|
||||||
|
std::string cDisplayText = displayText;
|
||||||
|
|
||||||
|
if(!cDisplayText.length())
|
||||||
|
{
|
||||||
|
if(selectionXL != -1 && selectionXH != -1)
|
||||||
|
{
|
||||||
|
cDisplayText = textFragments;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(multiline)
|
||||||
|
cDisplayText = textLines;
|
||||||
|
else
|
||||||
|
cDisplayText = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(multiline)
|
if(multiline)
|
||||||
{
|
{
|
||||||
if(selectionXL != -1 && selectionXH != -1)
|
if(selectionXL != -1 && selectionXH != -1)
|
||||||
@ -298,21 +320,21 @@ void Label::Draw(const Point& screenPos)
|
|||||||
} else {
|
} else {
|
||||||
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+selectionYL+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+selectionYL+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
||||||
}
|
}
|
||||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textFragments, textColour.Red, textColour.Green, textColour.Blue, 255);
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, cDisplayText, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textLines, textColour.Red, textColour.Green, textColour.Blue, 255);
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, cDisplayText, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(selectionXL != -1 && selectionXH != -1)
|
if(selectionXL != -1 && selectionXH != -1)
|
||||||
{
|
{
|
||||||
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
g->fillrect(screenPos.X+textPosition.X+selectionXL, screenPos.Y+textPosition.Y-1, selectionXH-(selectionXL), 10, 255, 255, 255, 255);
|
||||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, textFragments, textColour.Red, textColour.Green, textColour.Blue, 255);
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, cDisplayText, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, textColour.Red, textColour.Green, textColour.Blue, 255);
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, cDisplayText, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace ui
|
|||||||
protected:
|
protected:
|
||||||
std::string textFragments;
|
std::string textFragments;
|
||||||
std::string textLines;
|
std::string textLines;
|
||||||
|
std::string displayText;
|
||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
Colour textColour;
|
Colour textColour;
|
||||||
@ -48,6 +49,7 @@ namespace ui
|
|||||||
virtual void SetMultiline(bool status);
|
virtual void SetMultiline(bool status);
|
||||||
|
|
||||||
virtual void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
|
virtual void SetDisplayText(std::string newText);
|
||||||
virtual std::string GetText();
|
virtual std::string GetText();
|
||||||
|
|
||||||
virtual bool HasSelection();
|
virtual bool HasSelection();
|
||||||
|
@ -99,11 +99,6 @@ size_t Textbox::GetLimit()
|
|||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::SetDisplayText(std::string newText)
|
|
||||||
{
|
|
||||||
Label::SetText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Textbox::GetText()
|
std::string Textbox::GetText()
|
||||||
{
|
{
|
||||||
return backingText;
|
return backingText;
|
||||||
|
@ -24,7 +24,6 @@ public:
|
|||||||
Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = "");
|
Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = "");
|
||||||
virtual ~Textbox();
|
virtual ~Textbox();
|
||||||
|
|
||||||
virtual void SetDisplayText(std::string text);
|
|
||||||
virtual void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
virtual std::string GetText();
|
virtual std::string GetText();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user