Lua scripts can have individual keyboard shortcuts (Issue 344)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1532 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
a2eade7203
commit
061eba29de
11
src/const.h
11
src/const.h
@ -255,6 +255,7 @@ enum CHUNKS_CFG
|
||||
CHUNK_QUICK_SHADE = 8, ///< QShade effect settings
|
||||
CHUNK_GRID = 9, ///< Grid settings
|
||||
CHUNK_BRUSH =10, ///< Paintbrushes
|
||||
CHUNK_SCRIPTS =11, ///< Callable scripts
|
||||
CHUNK_MAX
|
||||
};
|
||||
|
||||
@ -469,6 +470,16 @@ enum SPECIAL_ACTIONS
|
||||
SPECIAL_LAYER8_SELECT,
|
||||
SPECIAL_LAYER8_TOGGLE,
|
||||
SPECIAL_REPEAT_SCRIPT,
|
||||
SPECIAL_RUN_SCRIPT_1,
|
||||
SPECIAL_RUN_SCRIPT_2,
|
||||
SPECIAL_RUN_SCRIPT_3,
|
||||
SPECIAL_RUN_SCRIPT_4,
|
||||
SPECIAL_RUN_SCRIPT_5,
|
||||
SPECIAL_RUN_SCRIPT_6,
|
||||
SPECIAL_RUN_SCRIPT_7,
|
||||
SPECIAL_RUN_SCRIPT_8,
|
||||
SPECIAL_RUN_SCRIPT_9,
|
||||
SPECIAL_RUN_SCRIPT_10,
|
||||
NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts
|
||||
};
|
||||
|
||||
|
||||
13
src/engine.c
13
src/engine.c
@ -1238,6 +1238,19 @@ void Main_handler(void)
|
||||
Repeat_script();
|
||||
action++;
|
||||
break;
|
||||
case SPECIAL_RUN_SCRIPT_1:
|
||||
case SPECIAL_RUN_SCRIPT_2:
|
||||
case SPECIAL_RUN_SCRIPT_3:
|
||||
case SPECIAL_RUN_SCRIPT_4:
|
||||
case SPECIAL_RUN_SCRIPT_5:
|
||||
case SPECIAL_RUN_SCRIPT_6:
|
||||
case SPECIAL_RUN_SCRIPT_7:
|
||||
case SPECIAL_RUN_SCRIPT_8:
|
||||
case SPECIAL_RUN_SCRIPT_9:
|
||||
case SPECIAL_RUN_SCRIPT_10:
|
||||
Run_numbered_script(key_index-SPECIAL_RUN_SCRIPT_1);
|
||||
action++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // End of special keys
|
||||
|
||||
125
src/factory.c
125
src/factory.c
@ -43,6 +43,9 @@
|
||||
#include "input.h" // Is_shortcut()
|
||||
#include "help.h" // Window_help()
|
||||
|
||||
/// Lua scripts bound to shortcut keys.
|
||||
char * Bound_script[10];
|
||||
|
||||
#ifdef __ENABLE_LUA__
|
||||
|
||||
#include <lua.h>
|
||||
@ -55,6 +58,8 @@
|
||||
/// Number of characters for name in fileselector.
|
||||
/// Window is adjusted according to it.
|
||||
#define NAME_WIDTH 34
|
||||
/// Number of characters for the description block
|
||||
#define DESC_WIDTH ((NAME_WIDTH+2)*8/6)
|
||||
/// Position of fileselector top, in window space
|
||||
#define FILESEL_Y 18
|
||||
|
||||
@ -826,11 +831,12 @@ void Draw_script_information(T_Fileselector_item * script_item)
|
||||
{
|
||||
FILE *script_file;
|
||||
char full_name[MAX_PATH_CHARACTERS];
|
||||
char text_block[3][NAME_WIDTH+3];
|
||||
char text_block[3][DESC_WIDTH+1];
|
||||
int x, y;
|
||||
int i;
|
||||
|
||||
// Blank the target area
|
||||
Window_rectangle(7, FILESEL_Y + 89, (NAME_WIDTH+2)*8+2, 3*8, MC_Black);
|
||||
Window_rectangle(7, FILESEL_Y + 89, DESC_WIDTH*6+2, 4*8, MC_Black);
|
||||
|
||||
if (script_item && script_item->Full_name && script_item->Full_name[0]!='\0')
|
||||
{
|
||||
@ -865,7 +871,7 @@ void Draw_script_information(T_Fileselector_item * script_item)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x < NAME_WIDTH+4)
|
||||
if (x < DESC_WIDTH+2)
|
||||
{
|
||||
// Adding character
|
||||
text_block[y][x-2] = (c<32 || c>255) ? ' ' : c;
|
||||
@ -879,12 +885,31 @@ void Draw_script_information(T_Fileselector_item * script_item)
|
||||
fclose(script_file);
|
||||
}
|
||||
|
||||
Print_in_window(7, FILESEL_Y + 89 , text_block[0], MC_Light, MC_Black);
|
||||
Print_in_window(7, FILESEL_Y + 89+ 8, text_block[1], MC_Light, MC_Black);
|
||||
Print_in_window(7, FILESEL_Y + 89+16, text_block[2], MC_Light, MC_Black);
|
||||
Print_help(8, FILESEL_Y + 89 , text_block[0], 'N', 0, 0);
|
||||
Print_help(8, FILESEL_Y + 89+ 8, text_block[1], 'N', 0, 0);
|
||||
Print_help(8, FILESEL_Y + 89+16, text_block[2], 'N', 0, 0);
|
||||
|
||||
// Display a line with the keyboard shortcut
|
||||
Print_help(8, FILESEL_Y + 89+24, "Key:", 'N', 0, 0);
|
||||
for (i=0; i<10; i++)
|
||||
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], script_item->Full_name))
|
||||
break;
|
||||
|
||||
if (i<10)
|
||||
{
|
||||
const char *shortcut;
|
||||
shortcut=Keyboard_shortcut_value(SPECIAL_RUN_SCRIPT_1+i);
|
||||
Print_help(8+4*6, FILESEL_Y + 89+24, shortcut, 'K', 0, strlen(shortcut));
|
||||
}
|
||||
else
|
||||
{
|
||||
Print_help(8+4*6, FILESEL_Y + 89+24, "None", 'K', 0, 4);
|
||||
}
|
||||
}
|
||||
Update_window_area(7, FILESEL_Y + 89, (NAME_WIDTH+2)*8+2, 3*8);
|
||||
|
||||
|
||||
|
||||
Update_window_area(8, FILESEL_Y + 89, DESC_WIDTH*6+2, 4*8);
|
||||
|
||||
}
|
||||
|
||||
@ -1044,6 +1069,23 @@ void Run_script(char *scriptdir)
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Run_numbered_script(byte index)
|
||||
{
|
||||
char scriptdir[MAX_PATH_CHARACTERS];
|
||||
|
||||
if (index>=10)
|
||||
return;
|
||||
if (Bound_script[index]==NULL)
|
||||
return;
|
||||
|
||||
strcpy(scriptdir, Data_directory);
|
||||
strcat(scriptdir, "scripts/");
|
||||
|
||||
strcpy(selected_script, Bound_script[index]);
|
||||
|
||||
Run_script(scriptdir);
|
||||
}
|
||||
|
||||
void Repeat_script(void)
|
||||
{
|
||||
char scriptdir[MAX_PATH_CHARACTERS];
|
||||
@ -1061,6 +1103,58 @@ void Repeat_script(void)
|
||||
Run_script(scriptdir);
|
||||
}
|
||||
|
||||
void Set_script_shortcut(T_Fileselector_item * script_item)
|
||||
{
|
||||
int i;
|
||||
char full_name[MAX_PATH_CHARACTERS];
|
||||
|
||||
if (script_item && script_item->Full_name && script_item->Full_name[0]!='\0')
|
||||
{
|
||||
strcpy(full_name, Data_directory);
|
||||
strcat(full_name, "scripts/");
|
||||
strcat(full_name, script_item->Full_name);
|
||||
|
||||
// Find if it already has a shortcut
|
||||
for (i=0; i<10; i++)
|
||||
if (Bound_script[i]!=NULL && !strcmp(Bound_script[i], script_item->Full_name))
|
||||
break;
|
||||
if (i<10)
|
||||
{
|
||||
// Existing shortcut
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to find a "free" one.
|
||||
for (i=0; i<10; i++)
|
||||
if (Bound_script[i]==NULL
|
||||
|| !Has_shortcut(SPECIAL_RUN_SCRIPT_1+i)
|
||||
|| !File_exists(full_name))
|
||||
break;
|
||||
if (i<10)
|
||||
{
|
||||
free(Bound_script[i]);
|
||||
Bound_script[i]=strdup(script_item->Full_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning_message("Already 10 scripts have shortcuts.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Window_set_shortcut(SPECIAL_RUN_SCRIPT_1+i);
|
||||
if (!Has_shortcut(SPECIAL_RUN_SCRIPT_1+i))
|
||||
{
|
||||
// User cancelled or deleted all shortcuts
|
||||
free(Bound_script[i]);
|
||||
Bound_script[i]=NULL;
|
||||
}
|
||||
// Refresh display
|
||||
Hide_cursor();
|
||||
Draw_script_information(script_item);
|
||||
Display_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
void Button_Brush_Factory(void)
|
||||
{
|
||||
short clicked_button;
|
||||
@ -1068,7 +1162,7 @@ void Button_Brush_Factory(void)
|
||||
T_Scroller_button* scriptscroll;
|
||||
char scriptdir[MAX_PATH_CHARACTERS];
|
||||
|
||||
Open_window(33+8*NAME_WIDTH, 162, "Brush Factory");
|
||||
Open_window(33+8*NAME_WIDTH, 180, "Brush Factory");
|
||||
|
||||
// Here we use the same data container as the fileselectors.
|
||||
// Reinitialize the list
|
||||
@ -1080,7 +1174,7 @@ void Button_Brush_Factory(void)
|
||||
// Sort it
|
||||
Sort_list_of_files(&Scripts_list);
|
||||
|
||||
Window_set_normal_button(85, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
|
||||
Window_set_normal_button(85, 149, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
|
||||
|
||||
Window_display_frame_in(6, FILESEL_Y - 2, NAME_WIDTH*8+4, 84); // File selector
|
||||
scriptlist = Window_set_list_button(
|
||||
@ -1091,10 +1185,11 @@ void Button_Brush_Factory(void)
|
||||
Scripts_list.Nb_elements,10, 0)), // 3
|
||||
Draw_script_name); // 4
|
||||
|
||||
Window_set_normal_button(10, 141, 67, 14, "Run", 0, Scripts_list.Nb_elements!=0, SDLK_RETURN); // 5
|
||||
Window_set_normal_button(10, 149, 67, 14, "Run", 0, Scripts_list.Nb_elements!=0, SDLK_RETURN); // 5
|
||||
|
||||
Window_display_frame_in(6, FILESEL_Y + 88, (NAME_WIDTH+2)*8+4, 3*8+2); // Descr.
|
||||
|
||||
Window_display_frame_in(6, FILESEL_Y + 88, DESC_WIDTH*6+4, 4*8+2); // Descr.
|
||||
Window_set_special_button(7, FILESEL_Y + 89+24,DESC_WIDTH*6,8); // 6
|
||||
|
||||
// Update position
|
||||
Highlight_script(&Scripts_list, scriptlist, selected_script);
|
||||
// Update the scroller position
|
||||
@ -1125,7 +1220,11 @@ void Button_Brush_Factory(void)
|
||||
scriptlist->List_start + scriptlist->Cursor_position));
|
||||
Display_cursor();
|
||||
break;
|
||||
|
||||
|
||||
case 6:
|
||||
Set_script_shortcut(Get_item_by_index(&Scripts_list,
|
||||
scriptlist->List_start + scriptlist->Cursor_position));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -2,3 +2,12 @@
|
||||
*/
|
||||
void Button_Brush_Factory(void);
|
||||
void Repeat_script(void);
|
||||
|
||||
/// Lua scripts bound to shortcut keys.
|
||||
extern char * Bound_script[10];
|
||||
|
||||
///
|
||||
/// Run a lua script linked to a shortcut, 0-9.
|
||||
/// Before: Cursor hidden
|
||||
/// After: Cursor shown
|
||||
void Run_numbered_script(byte index);
|
||||
|
||||
189
src/help.c
189
src/help.c
@ -233,22 +233,102 @@ void Window_set_shortcut(int action_id)
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
// -- Menu d'aide -----------------------------------------------------------
|
||||
|
||||
void Display_help(void)
|
||||
///
|
||||
/// Print a line with the 'help' (6x8) font.
|
||||
short Print_help(short x_pos, short y_pos, const char *line, char line_type, short link_position, short link_size)
|
||||
{
|
||||
short width; // Largeur physique d'une ligne de texte
|
||||
short x; // Indices d'affichage d'un caractère
|
||||
short y;
|
||||
short x_position; // Parcours de remplissage du buffer de ligne
|
||||
short line_index; // 0-15 (16 lignes de textes)
|
||||
short char_index; // Parcours des caractères d'une ligne
|
||||
short start_line=Help_position;
|
||||
byte * char_pixel;
|
||||
short repeat_menu_x_factor;
|
||||
short repeat_menu_y_factor;
|
||||
short real_x_pos;
|
||||
short real_y_pos;
|
||||
byte * char_pixel;
|
||||
short width; // Largeur physique d'une ligne de texte
|
||||
|
||||
real_x_pos=ToWinX(x_pos);
|
||||
real_y_pos=ToWinY(y_pos);
|
||||
|
||||
// Calcul de la taille
|
||||
width=strlen(line);
|
||||
// Les lignes de titres prennent plus de place
|
||||
if (line_type == 'T' || line_type == '-')
|
||||
width = width*2;
|
||||
|
||||
// Pour chaque ligne dans la fenêtre:
|
||||
for (y=0;y<8;y++)
|
||||
{
|
||||
x_position=0;
|
||||
// On crée une nouvelle ligne à splotcher
|
||||
for (char_index=0;char_index<width;char_index++)
|
||||
{
|
||||
// Recherche du caractère dans les fontes de l'aide.
|
||||
// Ligne titre : Si l'indice est impair on dessine le quart de caractère
|
||||
// qui va a gauche, sinon celui qui va a droite.
|
||||
if (line_type=='T')
|
||||
{
|
||||
if (line[char_index/2]>'_' || line[char_index/2]<' ')
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Caractère pas géré
|
||||
else if (char_index & 1)
|
||||
char_pixel=&(Gfx->Help_font_t2[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_t1[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
}
|
||||
else if (line_type=='-')
|
||||
{
|
||||
if (line[char_index/2]>'_' || line[char_index/2]<' ')
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Caractère pas géré
|
||||
else if (char_index & 1)
|
||||
char_pixel=&(Gfx->Help_font_t4[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_t3[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
}
|
||||
else if (line_type=='S')
|
||||
char_pixel=&(Gfx->Bold_font[(unsigned char)(line[char_index])][0][0]);
|
||||
else if (line_type=='N' || line_type=='K')
|
||||
char_pixel=&(Gfx->Help_font_norm[(unsigned char)(line[char_index])][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Un garde-fou en cas de probleme
|
||||
|
||||
for (x=0;x<6;x++)
|
||||
for (repeat_menu_x_factor=0;repeat_menu_x_factor<Menu_factor_X;repeat_menu_x_factor++)
|
||||
{
|
||||
byte color = *(char_pixel+x+y*6);
|
||||
byte repetition = Pixel_width-1;
|
||||
// Surlignement pour liens
|
||||
if (line_type=='K' && char_index>=link_position
|
||||
&& char_index<(link_position+link_size))
|
||||
{
|
||||
if (color == MC_Light)
|
||||
color=MC_White;
|
||||
else if (color == MC_Dark)
|
||||
color=MC_Light;
|
||||
else if (y<7)
|
||||
color=MC_Dark;
|
||||
}
|
||||
Horizontal_line_buffer[x_position++]=color;
|
||||
while (repetition--)
|
||||
Horizontal_line_buffer[x_position++]=color;
|
||||
}
|
||||
}
|
||||
// On la splotche
|
||||
for (repeat_menu_y_factor=0;repeat_menu_y_factor<Menu_factor_Y;repeat_menu_y_factor++)
|
||||
Display_line_fast(real_x_pos,real_y_pos++,width*Menu_factor_X*6,Horizontal_line_buffer);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
// -- Menu d'aide -----------------------------------------------------------
|
||||
|
||||
void Display_help(void)
|
||||
{
|
||||
short line_index; // 0-15 (16 lignes de textes)
|
||||
short start_line=Help_position;
|
||||
const short x_pos=13;
|
||||
const short y_pos=19;
|
||||
char line_type; // N: Normale, T: Titre, S: Sous-titre
|
||||
// -: Ligne inférieur de sous-titre
|
||||
const char * line;
|
||||
@ -256,21 +336,19 @@ void Display_help(void)
|
||||
// raccourcis clavier
|
||||
short link_position=0; // Position du premier caractère "variable"
|
||||
short link_size=0; // Taille de la partie variable
|
||||
|
||||
real_x_pos=Window_pos_X+(13*Menu_factor_X);
|
||||
real_y_pos=Window_pos_Y+(19*Menu_factor_Y);
|
||||
|
||||
short width;
|
||||
|
||||
for (line_index=0;line_index<16;line_index++)
|
||||
{
|
||||
// Shortcut au cas ou la section fait moins de 16 lignes
|
||||
if (line_index >= Help_section[Current_help_section].Length)
|
||||
{
|
||||
Block (real_x_pos,
|
||||
real_y_pos,
|
||||
44*6*Menu_factor_X,
|
||||
Window_rectangle (x_pos,
|
||||
y_pos,
|
||||
44*6,
|
||||
// 44 = Nb max de char (+1 pour éviter les plantages en mode X
|
||||
// causés par une largeur = 0)
|
||||
(Menu_factor_Y<<3) * (16 - line_index),
|
||||
(16 - line_index)*8,
|
||||
MC_Black);
|
||||
break;
|
||||
}
|
||||
@ -309,83 +387,16 @@ void Display_help(void)
|
||||
line = buffer;
|
||||
}
|
||||
|
||||
// Calcul de la taille
|
||||
width=strlen(line);
|
||||
// Les lignes de titres prennent plus de place
|
||||
if (line_type == 'T' || line_type == '-')
|
||||
width = width*2;
|
||||
|
||||
// Pour chaque ligne dans la fenêtre:
|
||||
for (y=0;y<8;y++)
|
||||
{
|
||||
x_position=0;
|
||||
// On crée une nouvelle ligne à splotcher
|
||||
for (char_index=0;char_index<width;char_index++)
|
||||
{
|
||||
// Recherche du caractère dans les fontes de l'aide.
|
||||
// Ligne titre : Si l'indice est impair on dessine le quart de caractère
|
||||
// qui va a gauche, sinon celui qui va a droite.
|
||||
if (line_type=='T')
|
||||
{
|
||||
if (line[char_index/2]>'_' || line[char_index/2]<' ')
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Caractère pas géré
|
||||
else if (char_index & 1)
|
||||
char_pixel=&(Gfx->Help_font_t2[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_t1[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
}
|
||||
else if (line_type=='-')
|
||||
{
|
||||
if (line[char_index/2]>'_' || line[char_index/2]<' ')
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Caractère pas géré
|
||||
else if (char_index & 1)
|
||||
char_pixel=&(Gfx->Help_font_t4[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_t3[(unsigned char)(line[char_index/2])-' '][0][0]);
|
||||
}
|
||||
else if (line_type=='S')
|
||||
char_pixel=&(Gfx->Bold_font[(unsigned char)(line[char_index])][0][0]);
|
||||
else if (line_type=='N' || line_type=='K')
|
||||
char_pixel=&(Gfx->Help_font_norm[(unsigned char)(line[char_index])][0][0]);
|
||||
else
|
||||
char_pixel=&(Gfx->Help_font_norm['!'][0][0]); // Un garde-fou en cas de probleme
|
||||
|
||||
for (x=0;x<6;x++)
|
||||
for (repeat_menu_x_factor=0;repeat_menu_x_factor<Menu_factor_X;repeat_menu_x_factor++)
|
||||
{
|
||||
byte color = *(char_pixel+x+y*6);
|
||||
byte repetition = Pixel_width-1;
|
||||
// Surlignement pour liens
|
||||
if (line_type=='K' && char_index>=link_position
|
||||
&& char_index<(link_position+link_size))
|
||||
{
|
||||
if (color == MC_Light)
|
||||
color=MC_White;
|
||||
else if (color == MC_Dark)
|
||||
color=MC_Light;
|
||||
else if (y<7)
|
||||
color=MC_Dark;
|
||||
}
|
||||
Horizontal_line_buffer[x_position++]=color;
|
||||
while (repetition--)
|
||||
Horizontal_line_buffer[x_position++]=color;
|
||||
}
|
||||
}
|
||||
// On la splotche
|
||||
for (repeat_menu_y_factor=0;repeat_menu_y_factor<Menu_factor_Y;repeat_menu_y_factor++)
|
||||
Display_line_fast(real_x_pos,real_y_pos++,width*Menu_factor_X*6,Horizontal_line_buffer);
|
||||
}
|
||||
|
||||
width=Print_help(x_pos, y_pos+(line_index<<3), line, line_type, link_position, link_size);
|
||||
// On efface la fin de la ligne:
|
||||
Block (real_x_pos+width*Menu_factor_X*6,
|
||||
real_y_pos-(8*Menu_factor_Y),
|
||||
((44*6*Menu_factor_X)-width*Menu_factor_X*6)+1,
|
||||
// 44 = Nb max de char (+1 pour éviter les plantages en mode X
|
||||
// causés par une largeur = 0)
|
||||
Menu_factor_Y<<3,
|
||||
if (width<44)
|
||||
Window_rectangle (x_pos+width*6,
|
||||
y_pos+(line_index<<3),
|
||||
(44-width)*6,
|
||||
8,
|
||||
MC_Black);
|
||||
}
|
||||
Update_rect(Window_pos_X+13*Menu_factor_X,Window_pos_Y+19*Menu_factor_Y,44*6*Menu_factor_X,16*8*Menu_factor_Y);
|
||||
Update_window_area(x_pos,y_pos,44*6,16*8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
src/help.h
12
src/help.h
@ -46,5 +46,17 @@ void Button_Stats(void);
|
||||
*/
|
||||
void Window_help(int section, const char * sub_section);
|
||||
|
||||
/// Opens a window where you can change a shortcut key(s).
|
||||
void Window_set_shortcut(int action_id);
|
||||
|
||||
///
|
||||
/// Print a line with the 'help' (6x8) font.
|
||||
short Print_help(short x_pos, short y_pos, const char *line, char line_type, short link_position, short link_size);
|
||||
|
||||
// Nom de la touche actuallement assignée à un raccourci d'après son numéro
|
||||
// de type 0x100+BOUTON_* ou SPECIAL_*
|
||||
const char * Keyboard_shortcut_value(word shortcut_number);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -234,6 +234,16 @@ static const T_Help_table helptable_help[] =
|
||||
HELP_LINK ("Brush effects menu: %s", 0x100+BUTTON_BRUSH_EFFECTS)
|
||||
HELP_LINK ("Brush factory: %s", 0x200+BUTTON_BRUSH_EFFECTS)
|
||||
HELP_LINK ("Repeat last script: %s", SPECIAL_REPEAT_SCRIPT)
|
||||
HELP_LINK ("Run script #1: %s", SPECIAL_RUN_SCRIPT_1)
|
||||
HELP_LINK ("Run script #2: %s", SPECIAL_RUN_SCRIPT_2)
|
||||
HELP_LINK ("Run script #3: %s", SPECIAL_RUN_SCRIPT_3)
|
||||
HELP_LINK ("Run script #4: %s", SPECIAL_RUN_SCRIPT_4)
|
||||
HELP_LINK ("Run script #5: %s", SPECIAL_RUN_SCRIPT_5)
|
||||
HELP_LINK ("Run script #6: %s", SPECIAL_RUN_SCRIPT_6)
|
||||
HELP_LINK ("Run script #7: %s", SPECIAL_RUN_SCRIPT_7)
|
||||
HELP_LINK ("Run script #8: %s", SPECIAL_RUN_SCRIPT_8)
|
||||
HELP_LINK ("Run script #9: %s", SPECIAL_RUN_SCRIPT_9)
|
||||
HELP_LINK ("Run script #10: %s", SPECIAL_RUN_SCRIPT_10)
|
||||
HELP_LINK ("Text: %s", 0x100+BUTTON_TEXT)
|
||||
HELP_LINK ("Resolution menu: %s", 0x100+BUTTON_RESOL)
|
||||
HELP_LINK ("Safety resolution: %s", 0x200+BUTTON_RESOL)
|
||||
|
||||
@ -1525,6 +1525,86 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = {
|
||||
true,
|
||||
SDLK_h, // H
|
||||
0},
|
||||
{187,
|
||||
"Run script #1",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{188,
|
||||
"Run script #2",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{189,
|
||||
"Run script #3",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{190,
|
||||
"Run script #4",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{191,
|
||||
"Run script #5",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{192,
|
||||
"Run script #6",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{193,
|
||||
"Run script #7",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{194,
|
||||
"Run script #8",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{195,
|
||||
"Run script #9",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
{196,
|
||||
"Run script #10",
|
||||
"Runs a recorded Lua script.",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
0, // No shortcut
|
||||
0},
|
||||
};
|
||||
|
||||
word Ordering[NB_SHORTCUTS]=
|
||||
@ -1716,4 +1796,14 @@ word Ordering[NB_SHORTCUTS]=
|
||||
SPECIAL_BRUSH_DOUBLE_WIDTH,
|
||||
SPECIAL_BRUSH_DOUBLE_HEIGHT,
|
||||
SPECIAL_BRUSH_HALVE,
|
||||
SPECIAL_RUN_SCRIPT_1,
|
||||
SPECIAL_RUN_SCRIPT_2,
|
||||
SPECIAL_RUN_SCRIPT_3,
|
||||
SPECIAL_RUN_SCRIPT_4,
|
||||
SPECIAL_RUN_SCRIPT_5,
|
||||
SPECIAL_RUN_SCRIPT_6,
|
||||
SPECIAL_RUN_SCRIPT_7,
|
||||
SPECIAL_RUN_SCRIPT_8,
|
||||
SPECIAL_RUN_SCRIPT_9,
|
||||
SPECIAL_RUN_SCRIPT_10,
|
||||
};
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#endif
|
||||
#include <SDL.h>
|
||||
|
||||
#define NB_SHORTCUTS 187 ///< Number of actions that can have a key combination associated to it.
|
||||
#define NB_SHORTCUTS 197 ///< Number of actions that can have a key combination associated to it.
|
||||
|
||||
/*** Types definitions and structs ***/
|
||||
|
||||
|
||||
79
src/init.c
79
src/init.c
@ -2125,6 +2125,49 @@ int Load_CFG(int reload_all)
|
||||
goto Erreur_lecture_config;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CHUNK_SCRIPTS:
|
||||
if (reload_all)
|
||||
{
|
||||
int current_size=0;
|
||||
int current_script=0;
|
||||
|
||||
while(current_size<Chunk.Size)
|
||||
{
|
||||
byte size;
|
||||
|
||||
// Free (old) string
|
||||
free(Bound_script[current_script]);
|
||||
Bound_script[current_script]=NULL;
|
||||
|
||||
if (!Read_byte(Handle, &size))
|
||||
goto Erreur_lecture_config;
|
||||
|
||||
if (size!=0)
|
||||
{
|
||||
// Alloc string
|
||||
Bound_script[current_script]=malloc(size+1);
|
||||
if (Bound_script[current_script]==NULL)
|
||||
return ERROR_MEMORY;
|
||||
|
||||
// Init and load string
|
||||
memset(Bound_script[current_script], 0, size+1);
|
||||
if (!Read_bytes(Handle, Bound_script[current_script], size))
|
||||
goto Erreur_lecture_config;
|
||||
}
|
||||
current_size+=size+1;
|
||||
current_script++;
|
||||
|
||||
// Do not load more strings than hard-coded limit
|
||||
if (current_script>=10)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default: // Chunk inconnu
|
||||
goto Erreur_lecture_config;
|
||||
}
|
||||
@ -2348,7 +2391,7 @@ int Save_CFG(void)
|
||||
{
|
||||
long total_size=0;
|
||||
int index;
|
||||
// Compute size: normal paintbrushes
|
||||
// Compute size: monochrome paintbrushes
|
||||
for (index=0; index<NB_PAINTBRUSH_SPRITES; index++)
|
||||
{
|
||||
total_size+=9+(Paintbrush[index].Width*Paintbrush[index].Height+7)/8;
|
||||
@ -2408,6 +2451,40 @@ int Save_CFG(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Save script shortcuts
|
||||
{
|
||||
int i;
|
||||
Chunk.Number=CHUNK_SCRIPTS;
|
||||
// Compute size : Data stored as 10 pascal strings
|
||||
Chunk.Size=0;
|
||||
for (i=0; i<10; i++)
|
||||
{
|
||||
if (Bound_script[i]==NULL)
|
||||
Chunk.Size+=1;
|
||||
else
|
||||
Chunk.Size+=strlen(Bound_script[i])+1;
|
||||
}
|
||||
// Header
|
||||
if (!Write_byte(Handle, Chunk.Number) ||
|
||||
!Write_word_le(Handle, Chunk.Size) )
|
||||
goto Erreur_sauvegarde_config;
|
||||
|
||||
// Strings
|
||||
for (i=0; i<10; i++)
|
||||
{
|
||||
byte size=0;
|
||||
if (Bound_script[i]!=NULL)
|
||||
size=strlen(Bound_script[i]);
|
||||
|
||||
if (!Write_byte(Handle, size))
|
||||
goto Erreur_sauvegarde_config;
|
||||
|
||||
if (size)
|
||||
if (!Write_bytes(Handle, Bound_script[i], size))
|
||||
goto Erreur_sauvegarde_config;
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(Handle))
|
||||
return ERROR_SAVING_CFG;
|
||||
|
||||
|
||||
28
src/input.c
28
src/input.c
@ -86,6 +86,34 @@ short Joybutton_left_click=0; // Button number that serves as left click
|
||||
short Joybutton_right_click=0; // Button number that serves as right-click
|
||||
#endif
|
||||
|
||||
int Has_shortcut(word function)
|
||||
{
|
||||
if (function == 0xFFFF)
|
||||
return 0;
|
||||
|
||||
if (function & 0x100)
|
||||
{
|
||||
if (Buttons_Pool[function&0xFF].Left_shortcut[0]!=KEY_NONE)
|
||||
return 1;
|
||||
if (Buttons_Pool[function&0xFF].Left_shortcut[1]!=KEY_NONE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
if (function & 0x200)
|
||||
{
|
||||
if (Buttons_Pool[function&0xFF].Right_shortcut[0]!=KEY_NONE)
|
||||
return 1;
|
||||
if (Buttons_Pool[function&0xFF].Right_shortcut[1]!=KEY_NONE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
if(Config_Key[function][0]!=KEY_NONE)
|
||||
return 1;
|
||||
if(Config_Key[function][1]!=KEY_NONE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Is_shortcut(word key, word function)
|
||||
{
|
||||
if (key == 0 || function == 0xFFFF)
|
||||
|
||||
@ -38,6 +38,9 @@ int Get_input(void);
|
||||
/// Returns true if the keycode has been set as a keyboard shortcut for the function.
|
||||
int Is_shortcut(word key, word function);
|
||||
|
||||
/// Returns true if the function has any shortcut key.
|
||||
int Has_shortcut(word function);
|
||||
|
||||
/// Adjust mouse sensitivity (and actual mouse input mode)
|
||||
void Adjust_mouse_sensitivity(word fullscreen);
|
||||
|
||||
|
||||
@ -901,6 +901,8 @@ int Load_INI(T_Config * conf)
|
||||
{
|
||||
conf->Right_click_colorpick=(values[0]!=0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fclose(file);
|
||||
|
||||
|
||||
@ -321,7 +321,7 @@ typedef struct
|
||||
word Double_click_speed; ///< Maximum delay for double-click, in ms.
|
||||
word Double_key_speed; ///< Maximum delay for double-keypress, in ms.
|
||||
byte Grid_XOR_color; ///< XOR value to apply for grid color.
|
||||
byte Right_click_colorpick; ///< Boolean, true to enable a "tablet" mode, where RMB acts as instant colorpicker
|
||||
byte Right_click_colorpick; ///< Boolean, true to enable a "tablet" mode, where RMB acts as instant colorpicker
|
||||
} T_Config;
|
||||
|
||||
// Structures utilisées pour les descriptions de pages et de liste de pages.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user