#include "nitrito.h"
void push_console_matrix() {
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_TRANSFORM_BIT);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(viewport[0],viewport[2],viewport[1],viewport[3]);
glPopAttrib();
}
void pop_console_matrix() {
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
glPopMatrix();
}
void Console::telon()
{
if(dir == 1)
{
if(openness<1) openness+=1*world->real_step_size*5*(1.1-openness);
if(openness>1)
{
openness=1;
dir=0;
}
}
else if(dir == -1)
{
if(openness>0) openness-=1*world->real_step_size*5*(1.1-openness);
if(openness<0)
{
openness=0;
dir=0;
}
}
}
void Console::open()
{
dir=1;
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
};
void Console::close()
{
dir=-1;
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(0,0);
};
void Console::force_open()
{
dir=0;
openness = 1;
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
};
void Console::force_close()
{
dir=0;
openness = 0;
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(0,0);
};
void Console::printf(const char *fmt, ...)
{
char text[256];
// Lo que sigue es el sistema indiscutiblemente
//infalible de transformar cadenas con formato
va_list ap;
if (fmt == NULL) *text=0;
else {
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
}
string temp = text;
lines.push_back(temp); //y la ponemos al final del deque ese
//while(lines.size()>options.console_max_lines) lines.pop_front();
};
void Console::draw()
{
telon();
if(openness==0) return;
int i;
float base;
push_console_matrix();
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
//glEnable(GL_ALPHA_TEST);
glBlendFunc (GL_DST_COLOR, GL_ZERO);
base = options.screen_h-(options.screen_h-100)*openness;
glColor4f(0.5,0.5,0.5,0.4);
glBegin(GL_POLYGON);
glVertex2f(5,options.screen_h);
glVertex2f(5,base+10);
glVertex2f(15,base);
glVertex2f(options.screen_w-15,base);
glVertex2f(options.screen_w-5,base+10);
glVertex2f(options.screen_w-5,options.screen_h);
glEnd();
glColor4f(0.5,0.5,0.5,0.8);
glBegin(GL_LINES);
glVertex2f(0,base+25);
glVertex2f(options.screen_w,base+25);
glEnd();
//glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glColor4f(1,1,1,0.8);
for(i=lines.size()-1; i>=0; i--)
{
if((base+15+((int)lines.size()-i)*20)>options.screen_h-30) break;
freetype::print(console_font,10,base+15+(lines.size()-i)*20 , lines[i].c_str());
}
freetype::print(console_font,10,base+8 , command_line.c_str());
pop_console_matrix();
glEnable(GL_TEXTURE_2D);
}
void Console::draw_flat()
{
int i;
float base;
push_console_matrix();
base = options.screen_h-(options.screen_h)+20;
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
for(i=lines.size()-1; i>=0; i--)
{
if((base+15+((int)lines.size()-i)*20)>options.screen_h-30) break;
freetype::print(console_font,10,base+15+(lines.size()-i)*20 , lines[i].c_str());
}
freetype::print(console_font,10,base+8 , command_line.c_str());
glDepthMask(GL_TRUE);
pop_console_matrix();
}
bool Console::is_open()
{
if(openness==1) return TRUE;
else return FALSE;
};
void Console::send_command(string s)
{
if(s == "help")
{
this->printf("");
this->printf("Comandos disponibles:");
this->printf(" reset : resetea las variables del juego");
this->printf(" help : esta ayuda");
this->printf(" exit : salir del juego");
this->printf(" quit : salir del juego");
this->printf(" info : informacion varia");
this->printf("");
}
else if(s == "reset")
{
this->printf("Reseteando variables...");
race.reset();
}
else if(s == "quit" || s == "exit")
{
this->printf("Ta luego.");
options.done = TRUE;
}
else if(s == "info")
{
this->printf("");
this->printf(" version : %s", NVERSION);
this->printf(" resolucion : %dx%d@",options.screen_w,options.screen_h);
this->printf(" targeta graf : %s",glGetString(GL_RENDERER));
this->printf("");
}
else if(s == "")
{
}
else if(s == "fixi studios")
{
this->printf(" .. ");
this->printf(" :mp, ");
this->printf(" <WQp. ");
this->printf(" <WT$a ");
this->printf(" nE`)mc ");
this->printf(" _amk 3h, ");
this->printf(" _sgmVY^ .<Q> ._, ");
this->printf(" _wmZ!` :W[ <yW( ");
this->printf(" __<wWV'- .X[ xmD^ ");
this->printf(" <QQQW1___swa. .d[ ___i=i,_.xWF` ");
this->printf(" =RWW#mBWBU$#. =W( _awm#BBRR$mgWF` ");
this->printf(" -~~- jE. xQwyWV!`- {$E` ");
this->printf(" :de .mQW?` ]m( ");
this->printf(" :m( .xmW!` .jW` ");
this->printf(" ]W= =VY~ .__aaaa,.3h. ");
this->printf(" :mZ` - ._summBUVYY!~ 3W; ");
this->printf(" _q@^ _<wmBT!'~- )Wc ");
this->printf(" _qW(.<wmU!^- -3m> ");
this->printf(" .qW*im#T^- -Uk, ");
this->printf(" .]QQmB?~ -f- ");
this->printf(" <mW!` ");
this->printf(" aWP' ");
this->printf(" _qW!` ");
this->printf(" =mD^ [Fixi Studios] ");
this->printf(" +!` ");
this->printf(" ");
}
else
{
this->printf("console : %s : comando no valido",s.c_str());
}
}
void Console::send_char(int c)
{
char valid[] = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTVWXYZ1234567890-=+@\?;:<>{}[]#',.~_()&!|$%*<>";
int i = 0;
if(c == SDLK_BACKSPACE)
{
command_line = command_line.substr(0,command_line.length()-1);
return;
}
if(c == SDLK_RETURN)
{
this->printf("> %s",command_line.c_str());
send_command(command_line);
command_line.clear();
return;
}
while(valid[i] != '\0')
{
if(c==valid[i])
{
command_line += c;
break;
}
i++;
};
};