From 496148d48518fed72a2759c5f811d48eaba153a5 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 13 Nov 2011 23:21:59 +0000 Subject: [PATCH] Tilemap effect: Added a menu to set options. Options saved and reloaded in .INI. Added support for shortcuts (but no helpfile so far, so you can't set them) git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1870 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 12 +++++++- src/buttons_effects.c | 64 +++++++++++++++++++++++++++++++++++++++++++ src/const.h | 2 ++ src/engine.c | 10 +++++++ src/hotkeys.c | 18 ++++++++++++ src/hotkeys.h | 2 +- src/readini.c | 23 ++++++++++++++++ src/saveini.c | 13 +++++++++ src/struct.h | 6 ++++ src/tiles.c | 35 +++++++++++------------ src/tiles.h | 13 --------- src/transform.c | 2 ++ 12 files changed, 168 insertions(+), 32 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 90df77d7..5f5789df 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -4538,7 +4538,7 @@ void Button_Effects(void) Window_set_normal_button( 83,131,104,14,"Feedback: ",1,1,SDLK_f); // 13 Window_set_normal_button(177, 19, 16,16,"",0,1,Config_Key[SPECIAL_FORMAT_CHECKER_MENU][0]); // 14 - Window_set_normal_button(177, 38, 16,16,"",0,1,KEY_NONE); // 15 + Window_set_normal_button(177, 38, 16,16,"",0,1,Config_Key[SPECIAL_TILEMAP_MODE][0]); // 15 Display_feedback_state(); Display_effect_sprite(EFFECTS_SPRITE_SHADE, 8,20); @@ -4800,10 +4800,20 @@ void Button_Effects(void) } break; case 15: // Tilemap + if (Window_attribute1==LEFT_SIDE) + { Button_Tilemap_mode(); Hide_cursor(); Display_effect_state(177+23,43, "Tilemap" ,Main_tilemap_mode); Display_cursor(); + } + else + { + Close_window(); + Display_cursor(); + Button_Tilemap_menu(); + clicked_button=11; + } break; } } diff --git a/src/buttons_effects.c b/src/buttons_effects.c index e9db41e1..3a74f984 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -199,7 +199,71 @@ void Button_Tilemap_mode(void) void Button_Tilemap_menu(void) { + short clicked_button; + byte flip_x=Config.Tilemap_allow_flipped_x; + byte flip_y=Config.Tilemap_allow_flipped_y; + byte count=Config.Tilemap_show_count; + + Open_window(166,138,"Tilemap options"); + + Window_set_normal_button(6,120,51,14,"Cancel",0,1,KEY_ESC); // 1 + Window_set_normal_button(110,120,51,14,"OK" ,0,1,SDLK_RETURN); // 2 + + Print_in_window(24,21, "Detect mirrored",MC_Dark,MC_Light); + Window_display_frame(5,17,155,74); + + Print_in_window(37,37, "Horizontally",MC_Black,MC_Light); + Window_set_normal_button(18,34,13,13,flip_x?"X":"",0,1,0); // 3 + + Print_in_window(37,55, "Vertically",MC_Black,MC_Light); + Window_set_normal_button(18,52,13,13,flip_y?"X":"",0,1,0); // 4 + + Print_in_window(27,99, "Show count",MC_Black,MC_Light); + Window_set_normal_button(7,96,13,13,count?"X":"",0,1,0); // 5 + + Update_window_area(0,0,Window_width, Window_height); + + Display_cursor(); + + do + { + clicked_button=Window_clicked_button(); + + switch (clicked_button) + { + case 3 : + flip_x=!flip_x; + Hide_cursor(); + Print_in_window(21,37,flip_x?"X":" ", MC_Black, MC_Light); + Display_cursor(); + break; + case 4 : + flip_y=!flip_y; + Hide_cursor(); + Print_in_window(21,55,flip_y?"X":" ", MC_Black, MC_Light); + Display_cursor(); + break; + case 5 : + count=!count; + Hide_cursor(); + Print_in_window(10,99,count?"X":" ", MC_Black, MC_Light); + Display_cursor(); + break; + } + if (Is_shortcut(Key,0x100+BUTTON_HELP)) + Window_help(BUTTON_EFFECTS, "TILEMAP"); + } + while ( (clicked_button!=1) && (clicked_button!=2) ); + + if (clicked_button==2) // OK + { + Config.Tilemap_allow_flipped_x=flip_x; + Config.Tilemap_allow_flipped_y=flip_y; + Config.Tilemap_show_count=count; + } + Close_window(); + Display_cursor(); } //--------------------------------- Stencil ---------------------------------- diff --git a/src/const.h b/src/const.h index 600efc8a..0938f367 100644 --- a/src/const.h +++ b/src/const.h @@ -465,6 +465,8 @@ enum SPECIAL_ACTIONS SPECIAL_TRANSPARENCY_8, SPECIAL_TRANSPARENCY_9, SPECIAL_TRANSPARENCY_0, + SPECIAL_TILEMAP_MODE, + SPECIAL_TILEMAP_MENU, SPECIAL_TILING_MENU, ///< This must be the last of the "effects" family SPECIAL_ZOOM_1, SPECIAL_ZOOM_2, diff --git a/src/engine.c b/src/engine.c index 80984aa6..3483326f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1169,6 +1169,16 @@ void Main_handler(void) Button_Tiling_menu(); action++; break; + case SPECIAL_TILEMAP_MODE : + Button_Tilemap_mode(); + effect_modified = 1; + action++; + break; + case SPECIAL_TILEMAP_MENU : + effect_modified = 1; + Button_Tilemap_menu(); + action++; + break; case SPECIAL_EFFECTS_OFF : Effects_off(); effect_modified = 1; diff --git a/src/hotkeys.c b/src/hotkeys.c index 02fbdb58..8d81e7ed 100644 --- a/src/hotkeys.c +++ b/src/hotkeys.c @@ -597,6 +597,22 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { true, SDLK_b|MOD_SHIFT|MOD_ALT, // Shift + Alt + B 0}, + {206, + "Tilemap mode", + "Enables or disables the Tilemap", + "mode.", + "", + true, + 0, // No key + 0}, + {207, + "Tilemap menu", + "Opens a menu where you can configure", + "the tilemap settings.", + "", + true, + 0, // No key + 0}, {67, "Classical brush grabbing", "Allows you to pick a brush defined", @@ -1780,6 +1796,8 @@ word Ordering[NB_SHORTCUTS]= SPECIAL_SMEAR_MODE, // Smear mode SPECIAL_TILING_MODE, // Tiling mode SPECIAL_TILING_MENU, // Tiling menu + SPECIAL_TILEMAP_MODE, // Tilemap mode + SPECIAL_TILEMAP_MENU, // Tilemap menu 0x100+BUTTON_BRUSH, // Pick brush 0x100+BUTTON_POLYBRUSH, // Pick polyform brush 0x200+BUTTON_BRUSH, // Restore brush diff --git a/src/hotkeys.h b/src/hotkeys.h index 0b569bfa..eac4325f 100644 --- a/src/hotkeys.h +++ b/src/hotkeys.h @@ -33,7 +33,7 @@ #endif #include -#define NB_SHORTCUTS 206 ///< Number of actions that can have a key combination associated to it. +#define NB_SHORTCUTS 208 ///< Number of actions that can have a key combination associated to it. /*** Types definitions and structs ***/ diff --git a/src/readini.c b/src/readini.c index 0d5ae57b..9dd526fa 100644 --- a/src/readini.c +++ b/src/readini.c @@ -954,6 +954,29 @@ int Load_INI(T_Config * conf) { conf->Allow_multi_shortcuts=(values[0]!=0); } + + conf->Tilemap_allow_flipped_x=0; + // Optional, makes tilemap effect detect x-flipped tiles (>=2.4) + if (!Load_INI_get_values (file,buffer,"Tilemap_detect_mirrored_x",1,values)) + { + conf->Tilemap_allow_flipped_x=(values[0]!=0); + } + + conf->Tilemap_allow_flipped_y=0; + // Optional, makes tilemap effect detect y-flipped tiles (>=2.4) + if (!Load_INI_get_values (file,buffer,"Tilemap_detect_mirrored_y",1,values)) + { + conf->Tilemap_allow_flipped_y=(values[0]!=0); + } + + conf->Tilemap_show_count=0; + // Optional, makes tilemap effect display tile count (>=2.4) + if (!Load_INI_get_values (file,buffer,"Tilemap_count",1,values)) + { + conf->Tilemap_show_count=(values[0]!=0); + } + + // Insert new values here diff --git a/src/saveini.c b/src/saveini.c index b691965f..48f42242 100644 --- a/src/saveini.c +++ b/src/saveini.c @@ -705,6 +705,19 @@ int Save_INI(T_Config * conf) values[0]=(conf->Allow_multi_shortcuts); if ((return_code=Save_INI_set_values (old_file,new_file,buffer,"Allow_multi_shortcuts",1,values,1))) goto Erreur_Retour; + + values[0]=conf->Tilemap_allow_flipped_x; + if ((return_code=Save_INI_set_values (old_file,new_file,buffer,"Tilemap_detect_mirrored_x",1,values,1))) + goto Erreur_Retour; + + values[0]=conf->Tilemap_allow_flipped_y; + if ((return_code=Save_INI_set_values (old_file,new_file,buffer,"Tilemap_detect_mirrored_y",1,values,1))) + goto Erreur_Retour; + + values[0]=conf->Tilemap_show_count; + if ((return_code=Save_INI_set_values (old_file,new_file,buffer,"Tilemap_count",1,values,1))) + goto Erreur_Retour; + // Insert new values here diff --git a/src/struct.h b/src/struct.h index b9c0ff51..627b9c60 100644 --- a/src/struct.h +++ b/src/struct.h @@ -370,6 +370,12 @@ typedef struct word Swap_buttons; ///< Sets which key swaps mouse buttons : 0=none, or MOD_CTRL, or MOD_ALT. char Scripts_directory[MAX_PATH_CHARACTERS];///< Full pathname of directory for Lua scripts byte Allow_multi_shortcuts; ///< Boolean, true if the same key combination can trigger multiple shortcuts. + byte Tilemap_allow_flipped_x; ///< Boolean, true if the Tilemap tool should detect x-flipped tiles. + byte Tilemap_allow_flipped_y; ///< Boolean, true if the Tilemap tool should detect y-flipped tiles. + byte Tilemap_show_count; ///< Boolean, true if the Tilemap tool should display tile count after analysis. + + + } T_Config; // Structures utilisées pour les descriptions de pages et de liste de pages. diff --git a/src/tiles.c b/src/tiles.c index 0c860b14..32a0c46c 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -46,8 +46,6 @@ T_Tile * Spare_tilemap; short Spare_tilemap_width; short Spare_tilemap_height; -T_Tilemap_settings Tilemap_settings = { 0, 0, 0, 0}; - // /// Build the tile-area from the current picture @@ -313,7 +311,7 @@ void Tilemap_update(void) Main_tilemap_width=width; Main_tilemap_height=height; - if (width*height > 1000 || Tilemap_settings.Show_tile_count) + if (width*height > 1000 || Config.Tilemap_show_count) { wait_window=1; Open_window(180,36,"Creating tileset"); @@ -362,7 +360,7 @@ void Tilemap_update(void) } // Try flipped-y comparison - if (Tilemap_settings.Allow_flipped_y) + if (Config.Tilemap_allow_flipped_y) { for (ref_tile=0; ref_tile