Added new scripting command to set the text color:

- settextcolor / gettextcolor added to celestia object in CELX scripting
- settextcolor added to CEL scripting
ver1_6_1
Vincent Giangiulio 2009-11-01 19:17:16 +00:00
parent f140f73bd6
commit 618edb2b8b
6 changed files with 85 additions and 1 deletions

View File

@ -764,6 +764,13 @@ Command* CommandParser::parseCommand()
Color color((float) colorv.x, (float) colorv.y, (float) colorv.z);
cmd = new CommandSetLabelColor(item, color);
}
else if (commandName == "settextcolor")
{
Vec3d colorv(1.0f, 1.0f, 1.0f);
paramList->getVector("color", colorv);
Color color((float) colorv.x, (float) colorv.y, (float) colorv.z);
cmd = new CommandSetTextColor(color);
}
else
{
error("Unknown command name '" + commandName + "'");

View File

@ -923,6 +923,20 @@ void CommandSetLabelColor::process(ExecutionEnvironment& /* env */)
}
////////////////
// SetTextColor command
CommandSetTextColor::CommandSetTextColor(Color _color) :
color(_color)
{
}
void CommandSetTextColor::process(ExecutionEnvironment& env)
{
env.getCelestiaCore()->setTextColor(color);
}
///////////////
// Repeat command

View File

@ -658,6 +658,17 @@ class CommandSetLabelColor : public InstantaneousCommand
};
class CommandSetTextColor : public InstantaneousCommand
{
public:
CommandSetTextColor(Color);
void process(ExecutionEnvironment&);
private:
Color color;
};
class Execution;
class RepeatCommand : public Command

View File

@ -309,6 +309,7 @@ CelestiaCore::CelestiaCore() :
messageVOffset(0),
messageStart(0.0),
messageDuration(0.0),
textColor(Color(1.0f, 1.0f, 1.0f)),
typedText(""),
typedTextCompletionIdx(-1),
textEnterMode(KbNormal),
@ -3886,7 +3887,7 @@ void CelestiaCore::renderOverlay()
float alpha = 1.0f;
if (currentTime > messageStart + messageDuration - 0.5)
alpha = (float) ((messageStart + messageDuration - currentTime) / 0.5);
glColor4f(1.0f, 1.0f, 1.0f, alpha);
glColor4f(textColor.red(), textColor.green(), textColor.blue(), alpha);
glTranslatef((float) x, (float) y, 0.0f);
overlay->beginText();
*overlay << _(messageText.c_str());
@ -4677,6 +4678,18 @@ void CelestiaCore::setHudDetail(int newHudDetail)
notifyWatchers(VerbosityLevelChanged);
}
Color CelestiaCore::getTextColor()
{
return textColor;
}
void CelestiaCore::setTextColor(Color newTextColor)
{
textColor = newTextColor;
}
astro::Date::Format CelestiaCore::getDateFormat() const
{
return dateFormat;

View File

@ -280,6 +280,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
int getHudDetail();
void setHudDetail(int);
Color getTextColor();
void setTextColor(Color);
astro::Date::Format getDateFormat() const;
void setDateFormat(astro::Date::Format format);
int getOverlayElements() const;
@ -375,6 +377,7 @@ class CelestiaCore // : public Watchable<CelestiaCore>
int messageVOffset;
double messageStart;
double messageDuration;
Color textColor;
std::string typedText;
std::vector<std::string> typedTextCompletion;
int typedTextCompletionIdx;

View File

@ -2118,6 +2118,40 @@ static int celestia_getoverlayelements(lua_State* l)
return 1;
}
static int celestia_settextcolor(lua_State* l)
{
Celx_CheckArgs(l, 4, 4, "Three arguments expected for celestia:settextcolor()");
CelestiaCore* appCore = this_celestia(l);
Color color;
double red = Celx_SafeGetNumber(l, 2, WrongType, "settextcolor: color values must be numbers", 1.0);
double green = Celx_SafeGetNumber(l, 3, WrongType, "settextcolor: color values must be numbers", 1.0);
double blue = Celx_SafeGetNumber(l, 4, WrongType, "settextcolor: color values must be numbers", 1.0);
// opacity currently not settable
double opacity = 1.0;
color = Color((float) red, (float) green, (float) blue, (float) opacity);
appCore->setTextColor(color);
return 0;
}
static int celestia_gettextcolor(lua_State* l)
{
Celx_CheckArgs(l, 1, 1, "No arguments expected for celestia:getgalaxylightgain()");
CelestiaCore* appCore = this_celestia(l);
Color color = appCore->getTextColor();
lua_pushnumber(l, color.red());
lua_pushnumber(l, color.green());
lua_pushnumber(l, color.blue());
return 3;
}
static int celestia_setlabelcolor(lua_State* l)
{
Celx_CheckArgs(l, 5, 5, "Four arguments expected for celestia:setlabelcolor()");
@ -3392,6 +3426,8 @@ static void CreateCelestiaMetaTable(lua_State* l)
Celx_RegisterMethod(l, "getlabelcolor", celestia_getlabelcolor);
Celx_RegisterMethod(l, "setlinecolor", celestia_setlinecolor);
Celx_RegisterMethod(l, "getlinecolor", celestia_getlinecolor);
Celx_RegisterMethod(l, "settextcolor", celestia_settextcolor);
Celx_RegisterMethod(l, "gettextcolor", celestia_gettextcolor);
Celx_RegisterMethod(l, "getoverlayelements", celestia_getoverlayelements);
Celx_RegisterMethod(l, "setoverlayelements", celestia_setoverlayelements);
Celx_RegisterMethod(l, "getfaintestvisible", celestia_getfaintestvisible);