|
[Beta/Free] LiteConsole
#390056
12/21/11 22:54
12/21/11 22:54
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Heyo, As I needed it for my actual project and decided to release it for free, here it is: LiteConsole. Older shots, but they pretty much show it: What is it? LiteConsole is just a little console, that gives you access to vars [get/set], let's you call functions [call] and let's you define user functions[you got to parse the input string then]. It supports a marker, that can indicate something, if you want. [For example: function still running or something like this] You can also go through your last inputs [pressing up/down]. I think I will extend this, with a help function and other features, but I am not sure - maybe you want to contribute something ?. [Also, this is may not perfect, and I am not responsible for any damage on you or your computer ;)] Here it is: *.c code
//////////////////////////////////////////////////////////////////////////////////////////
// //
// Lite Console //
// //
/////////////////////////////////////////Includes/////////////////////////////////////////
//not needed at this point
//////////////////////////////////////////Defines/////////////////////////////////////////
//not needed at this point
//////////////////////////////////////////Strings/////////////////////////////////////////
//not needed at this point
//////////////////////////////////////////Structs/////////////////////////////////////////
typedef struct LCCONSOLE {
PANEL* background;
PANEL* output;
PANEL* input;
TEXT* inputText;
TEXT* outputText;
var inited;
var state;
var pos_y;
var stringnumber;
var inputactive;
} LCCONSOLE;
typedef struct LCCONSOLEFUNCTION {
STRING* callName;
function callFunc(STRING* );
struct LCCONSOLEFUNCTION* next;
} LCCONSOLEFUNCTION;
typedef struct LCPROCCESINGINDICATORS {
var line;
var active;
struct LCPROCCESINGINDICATORS* next;
} LCPROCCESINGINDICATORS;
typedef struct LCCOMMANDSTRINGS {
STRING* str;
struct LCCOMMANDSTRINGS* next;
struct LCCOMMANDSTRINGS* last;
} LCCOMMANDSTRINGS;
LCCONSOLE LCconsole;
LCCONSOLEFUNCTION* LCfirstFunction;
LCPROCCESINGINDICATORS* LCfirstProccesor;
LCCOMMANDSTRINGS* LCCommandStrings;
//////////////////////////////////////////Sounds//////////////////////////////////////////
//not needed at this point
/////////////////////////////////////////Pictures/////////////////////////////////////////
//not needed at this point
///////////////////////////////////////////Vars///////////////////////////////////////////
var LCfunctionNumber = 0;
//////////////////////////////////////////Fonts///////////////////////////////////////////
//not needed at this point
//////////////////////////////////////////Panels//////////////////////////////////////////
//not needed at this point
//////////////////////////////////////////Entity//////////////////////////////////////////
//not needed at this point
///////////////////////////////////Function Prototypes////////////////////////////////////
void _LCturnIndicator(LCPROCCESINGINDICATORS* myIndi, var line);
////////////////////////////////////////Functions/////////////////////////////////////////
void LC_removeProccesingIndicator(var line)
{
if(!LCconsole.inited)
return;
LCPROCCESINGINDICATORS* act = LCfirstProccesor;
while(act)
{
if(act.line == line)
act.active = 0;
act = act.next;
}
}
int LC_addProccesingIndicator()
{
if(!LCconsole.inited)
return;
if(!LCfirstProccesor)
{
LCfirstProccesor = sys_malloc(sizeof(LCPROCCESINGINDICATORS));
LCfirstProccesor.line = LCconsole.stringnumber-1;
LCfirstProccesor.active = 1;
LCfirstProccesor.next = NULL;
_LCturnIndicator(LCfirstProccesor, LCconsole.stringnumber-1);
}
else
{
LCPROCCESINGINDICATORS* act = LCfirstProccesor;
while(act.next)
{
act = act.next;
}
act.next = sys_malloc(sizeof(LCPROCCESINGINDICATORS));
act = act.next;
act.line = LCconsole.stringnumber-1;
act.active = 1;
act.next = NULL;
_LCturnIndicator(act, LCconsole.stringnumber-1);
}
return (LCconsole.stringnumber-1);
}
void _LCturnIndicator(LCPROCCESINGINDICATORS* myIndi, var line)
{
var i = 0;
for(i = str_len((LCconsole.outputText.pstring)[line]); i<91; i++)
str_cat((LCconsole.outputText.pstring)[line], " ");
while(myIndi.active)
{
str_setchr((LCconsole.outputText.pstring)[line], 90, '|');
wait(-0.15);
str_setchr((LCconsole.outputText.pstring)[line], 90, '/');
wait(-0.15);
str_setchr((LCconsole.outputText.pstring)[line], 90, '-');
wait(-0.15);
str_setchr((LCconsole.outputText.pstring)[line], 90, '\\');
wait(-0.15);
}
str_setchr((LCconsole.outputText.pstring)[line], 90, ' ');
LCPROCCESINGINDICATORS* act = LCfirstProccesor;
while((act.next != myIndi)&&(act.next))
{
act = act.next;
}
if(act.next == myIndi)
{
act.next = myIndi.next;
sys_free(myIndi);
}
}
void LC_addFunction(STRING* consoleName, void* fnc)
{
if(!LCconsole.inited)
return;
if(!LCfunctionNumber)
{
LCfirstFunction = sys_malloc(sizeof(LCCONSOLEFUNCTION));
LCfirstFunction.callName = str_create(_chr(consoleName));
LCfirstFunction.callFunc = fnc;
LCfirstFunction.next = sys_malloc(sizeof(LCCONSOLEFUNCTION));
}
else
{
LCCONSOLEFUNCTION* LCactFnc = LCfirstFunction;
while(LCactFnc.next)
{
LCactFnc = LCactFnc.next;
}
LCactFnc.callName = str_create(_chr(consoleName));
LCactFnc.callFunc = fnc;
LCactFnc.next = sys_malloc(sizeof(LCCONSOLEFUNCTION));
}
LCfunctionNumber++;
}
void LC_addNewLine(STRING* str)
{
if(!LCconsole.inited)
return;
txt_addstring(LCconsole.outputText, ">> ");
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], str);
LCconsole.stringnumber++;
}
void LC_addToLine(STRING* str)
{
if(!LCconsole.inited)
return;
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber-1], str);
}
void LC_getInput()
{
if(!LCconsole.inited)
return;
int realReturn = 0;
var inkeyResult = inkey((LCconsole.inputText.pstring)[0]);
STRING* cpyStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_replaceall(cpyStr, " ", "");
var acceptStill = 0;
if((inkeyResult==72)||(inkeyResult==80))
{
LCCOMMANDSTRINGS* temp = LCCommandStrings;
wait(1);
while(key_cuu) wait(1);
while(key_cud) wait(1);
while(!key_enter)
{
if(temp)
str_cpy((LCconsole.inputText.pstring)[0], temp.str);
else
str_cpy((LCconsole.inputText.pstring)[0], " ");
acceptStill = 1;
if(key_cuu)
{
while(key_cuu) wait(1);
if(temp)
{
if(temp.next)
if(temp.next.next)
temp = temp.next;
}
else
{
temp = LCCommandStrings;
}
}
if(key_cud)
{
while(key_cud) wait(1);
if(temp)
temp = temp.last;
}
var i;
for(i = str_len((LCconsole.inputText.pstring)[0]); i<32; i++)
str_cat((LCconsole.inputText.pstring)[0], " ");
inkey((LCconsole.inputText.pstring)[0]);
wait(1);
}
cpyStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_replaceall(cpyStr, " ", "");
acceptStill = 1;
}
if(str_len(cpyStr) > 0)
{
if((inkeyResult==13)||(acceptStill == 1))
{
realReturn = 1;
STRING* commandStr = str_parse(NULL, (LCconsole.inputText.pstring)[0], 1);
if(str_cmpni(commandStr, "set"))
{
STRING* tempStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_clip(tempStr, 4);
STRING* varNameStr = str_parse(NULL, tempStr, 1);
STRING* varValueStr = str_create(_chr(tempStr));
str_clip(varValueStr, str_len(varNameStr)+1);
ptr_remove(tempStr);
STRING* tempVarName = str_create(_chr(varNameStr));
var *pVar = var_for_name(tempVarName );
if(pVar)
{
(*pVar) = str_to_num(varValueStr);
STRING* tempStr = str_create(">> Setted ");
str_cat(tempStr, varNameStr);
str_cat(tempStr, " to ");
str_cat(tempStr, varValueStr);
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
else
{
STRING* tempStr = str_create(">> Unkown var \"");
str_cat(tempStr, varNameStr);
str_cat(tempStr, "\"");
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
ptr_remove(varNameStr);
ptr_remove(varValueStr);
ptr_remove(tempVarName);
var i;
for(i = str_len((LCconsole.outputText.pstring)[LCconsole.stringnumber]); i<100; i++)
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], " ");
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], "[set]");
}
else if(str_cmpni(commandStr, "get"))
{
STRING* tempStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_clip(tempStr, 4);
STRING* varNameStr = str_parse(NULL, tempStr, 1);
STRING* tempVarName = str_create(_chr(varNameStr));
var *pVar = var_for_name(tempVarName );
ptr_remove(tempStr);
if(pVar)
{
STRING* varValueStr = str_for_num(NULL, (*pVar));
STRING* tempStr = str_create(">> ");
str_cat(tempStr, varNameStr);
str_cat(tempStr, " is ");
str_cat(tempStr, varValueStr);
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
else
{
STRING* tempStr = str_create(">> Unkown var \"");
str_cat(tempStr, varNameStr);
str_cat(tempStr, "\"");
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
ptr_remove(varNameStr);
ptr_remove(tempVarName);
var i;
for(i = str_len((LCconsole.outputText.pstring)[LCconsole.stringnumber]); i<100; i++)
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], " ");
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], "[get]");
}
else if(str_cmpni(commandStr, "call"))
{
STRING* tempStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_clip(tempStr, 5);
STRING* fncNameStr = str_parse(NULL, tempStr, 1);
ptr_remove(tempStr);
void* tempVoid();
tempVoid = engine_getscript(_chr(fncNameStr));
if(tempVoid)
{
STRING* tempStr = str_create(">> Called ");
str_cat(tempStr, fncNameStr);
txt_addstring(LCconsole.outputText, tempStr);
tempVoid();
ptr_remove(tempStr);
}
else
{
STRING* tempStr = str_create(">> Unkown function \"");
str_cat(tempStr, fncNameStr);
str_cat(tempStr, "\"");
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
ptr_remove(fncNameStr);
var i;
for(i = str_len((LCconsole.outputText.pstring)[LCconsole.stringnumber]); i<100; i++)
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], " ");
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], "[call]");
}
else
{
var noFunc = 1;
LCCONSOLEFUNCTION* LCactFnc = LCfirstFunction;
var i;
for(i = 0; i<LCfunctionNumber; i++)
{
if(str_cmp(commandStr, LCactFnc.callName))
{
STRING* tempStr = str_create(_chr((LCconsole.inputText.pstring)[0]));
str_clip(tempStr, str_len(LCactFnc.callName)+1);
void* tempVoid(STRING* );
tempVoid = LCactFnc.callFunc;
tempVoid(tempStr);
noFunc = 0;
ptr_remove(tempStr);
tempStr = str_create(">> User defined function called: \"");
str_cat(tempStr, commandStr);
str_cat(tempStr, "\"");
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
var i;
for(i = str_len((LCconsole.outputText.pstring)[LCconsole.stringnumber]); i<100; i++)
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], " ");
str_cat((LCconsole.outputText.pstring)[LCconsole.stringnumber], "[user]");
}
LCactFnc = LCactFnc.next;
}
if(noFunc)
{
STRING* tempStr = str_create(">> Unkown command \"");
str_cat(tempStr, commandStr);
str_cat(tempStr, "\"");
txt_addstring(LCconsole.outputText, tempStr);
ptr_remove(tempStr);
}
}
LCCOMMANDSTRINGS* newLCCommandStrings = sys_malloc(sizeof(LCCOMMANDSTRINGS));
newLCCommandStrings.str = str_create(commandStr);
newLCCommandStrings.next = LCCommandStrings;
LCCommandStrings.last = newLCCommandStrings;
LCCommandStrings = newLCCommandStrings;
str_cpy((LCconsole.inputText.pstring)[0]," ");
LCconsole.stringnumber++;
}
}
ptr_remove(cpyStr);
str_cpy((LCconsole.inputText.pstring)[0]," ");
LCconsole.inputactive = 0;
if((realReturn == 1))
{
LCconsole.inputactive = 1;
LC_getInput();
}
}
void LC_init()
{
var _lastStringNumber = 0;
LCCommandStrings = sys_malloc(sizeof(LCCOMMANDSTRINGS));
LCCommandStrings.str = str_create("");
LCCommandStrings.next = 0;
LCCommandStrings.last = 0;
LCconsole.stringnumber = 0;
LCconsole.inputactive = 0;
LCconsole.background = pan_create(NULL, 999);
set(LCconsole.background, LIGHT|TRANSLUCENT);
vec_set(LCconsole.background.blue, COLOR_GREY);
LCconsole.background.alpha = 40;
LCconsole.output = pan_create(NULL, 999);
set(LCconsole.output, LIGHT|TRANSLUCENT);
vec_set(LCconsole.output.blue, COLOR_GREY);
LCconsole.output.alpha = 40;
LCconsole.input = pan_create(NULL, 999);
set(LCconsole.input, LIGHT|TRANSLUCENT);
vec_set(LCconsole.input.blue, COLOR_GREY);
LCconsole.input.alpha = 40;
LCconsole.outputText = txt_create(0,0);
set(LCconsole.outputText, WWRAP|UNTOUCHABLE);
LCconsole.outputText.font = font_create("Terminal#12");
LCconsole.inputText = txt_create(0,0);
set(LCconsole.inputText, UNTOUCHABLE);
LCconsole.inputText.font = font_create("Terminal#12");
txt_addstring(LCconsole.inputText, " ");
LCconsole.pos_y = -(screen_size.y/3);
LCconsole.inited = 1;
wait(1);
while(1)
{
if(LCconsole.state == LCOPEN)
{
mouse_mode = 4;
if(LCconsole.pos_y < -LCMOVESPEED*time_step)
{
LCconsole.pos_y += LCMOVESPEED*time_step;
}
else
{
LCconsole.pos_y = 0;
}
}
else
{
if(LCconsole.pos_y > -(screen_size.y/3))
{
LCconsole.pos_y -= LCMOVESPEED*time_step;
}
else
{
LCconsole.pos_y = -(screen_size.y/3);
}
}
LCconsole.background.size_x = screen_size.x;
LCconsole.background.size_y = screen_size.y/3-1;
LCconsole.background.pos_x = 0;
LCconsole.background.pos_y = LCconsole.pos_y;
LCconsole.output.size_x = screen_size.x-6;
LCconsole.output.size_y = screen_size.y/3-27;
LCconsole.output.pos_x = 3;
LCconsole.output.pos_y = LCconsole.pos_y+3;
LCconsole.input.size_x = screen_size.x-6;
LCconsole.input.size_y = 15;
LCconsole.input.pos_x = 3;
LCconsole.input.pos_y = LCconsole.pos_y+screen_size.y/3-20;
LCconsole.outputText.pos_x = 7;
LCconsole.outputText.pos_y = LCconsole.pos_y+3;
LCconsole.outputText.size_y = screen_size.y/3-30;
LCconsole.outputText.size_x = screen_size.x-14;
LCconsole.inputText.pos_x = 7;
LCconsole.inputText.pos_y = LCconsole.input.pos_y+2;
LCconsole.inputText.size_y = 15;
LCconsole.inputText.size_x = screen_size.x-14;
if(_lastStringNumber != LCconsole.stringnumber)
{
if(LCconsole.stringnumber * 12 > screen_size.y/3-30)
LCconsole.outputText.offset_y = ((LCconsole.stringnumber * 12) - (screen_size.y/3-30));
_lastStringNumber = LCconsole.stringnumber;
}
else
{
if((mouse_pos.x > LCconsole.output.pos_x)&&(mouse_pos.y > LCconsole.output.pos_y)&&(mouse_pos.x < LCconsole.output.pos_x+LCconsole.output.size_x)&&(mouse_pos.y < LCconsole.output.pos_y+LCconsole.output.size_y))
{
LCconsole.outputText.offset_y -= mickey.z/10;
LCconsole.outputText.offset_y = clamp(LCconsole.outputText.offset_y, 0, ((LCconsole.stringnumber * 12) - (screen_size.y/3-30)));
}
}
if((mouse_pos.x > LCconsole.input.pos_x)&&(mouse_pos.y > LCconsole.input.pos_y)&&(mouse_pos.x < LCconsole.input.pos_x+LCconsole.input.size_x)&&(mouse_pos.y < LCconsole.input.pos_y+LCconsole.input.size_y))
{
if((LCconsole.inputactive == 0)&&(mouse_left))
{
while(mouse_left)
{
draw_obj(LCconsole.background);
draw_obj(LCconsole.output);
draw_obj(LCconsole.input);
draw_obj(LCconsole.outputText);
draw_obj(LCconsole.inputText);
proc_mode = PROC_LATE;
wait(1);
}
LCconsole.inputactive = 1;
LC_getInput();
}
else if(mouse_left)
{
LCconsole.inputactive = 0;
inkey_active = 0;
}
}
else if(mouse_left)
{
LCconsole.inputactive = 0;
inkey_active = 0;
}
draw_obj(LCconsole.background);
draw_obj(LCconsole.output);
draw_obj(LCconsole.input);
draw_obj(LCconsole.outputText);
draw_obj(LCconsole.inputText);
proc_mode = PROC_LATE;
wait(1);
}
}
*.h header
/*********************************************************************************/
/* */
/* Lite Console */
/* */
/* Marian Frische - 21.12.11 */
/* */
/*********************************************************************************/
#ifndef LITECONSOLE_H
#define LITECONSOLE_H
//Defines
#define LCCLOSED 0
#define LCOPEN 1
#define LCMOVESPEED 30
//Voids
/*
Inits the Console.
Needed to work with it.
*/
void LC_init(void);
/*
Adds a new line and writes the content of the String into it
*/
void LC_addNewLine(STRING* );
/*
Adds the content of the string to the current line.
*/
void LC_addToLine(STRING* );
/*
Adds a function, that can be called by the user.
The String is the keyword/identifier, and the void is the function, that will be called if the keyword was used.
The function needs to accept a String.
*/
void LC_addFunction(STRING* , void* );
/*
Adds a Proccing Indicator (a ascii-line that "turns") to the current line
*/
int LC_addProccesingIndicator(void);
/*
Removes the Indicator at the given line.
*/
void LC_removeProccesingIndicator(var );
#include "liteConsole.c"
#endif
The header pretty much describes it Things to know: At the moment you need to include <strio.c> before including lite console. You must call LC_init() to make it work. The console shows if you set its state to 1: LCconsole.state = 1; (maybe you want such a function: function on_f1_event() { LCconsole.state = 1-LCconsole.state; } )
Critics, comments and questions are welcome! Best regards, Marian Frische
|
|
|
Re: [Beta/Free] LiteConsole
[Re: darkinferno]
#397614
03/21/12 12:30
03/21/12 12:30
|
Joined: Feb 2009
Posts: 3,207 Germany, Magdeburg
Rei_Ayanami
OP
Expert
|
OP
Expert
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
|
Ah, I see, yeah, strio.c is needed - I should have cleaned up my test script Does it work for you on A7 btw? [I am not sure what of the things I used are new in A8] I am working on a new version anyway [which will be included in my "standardincludes" library, with linkedlists, stacks, queues, maps(sort of), and some more things]
|
|
|
|