2121#include " Music.h"
2222#include " Screen.h"
2323#include " Script.h"
24+ #include " TextInput.h"
2425#include " UTF8.h"
2526#include " UtilityClass.h"
2627#include " VFormat.h"
@@ -103,8 +104,6 @@ void editorclass::reset(void)
103104
104105 clear_script_buffer ();
105106
106- script_cursor_x = 0 ;
107- script_cursor_y = 0 ;
108107 script_offset = 0 ;
109108 lines_visible = 25 ;
110109 current_script = " null" ;
@@ -1509,6 +1508,7 @@ void editorrender(void)
15091508
15101509 // Draw text
15111510 int font_height = font::height (PR_FONT_LEVEL);
1511+
15121512 for (int i = 0 ; i < ed.lines_visible ; i++)
15131513 {
15141514 if (i + ed.script_offset < (int ) ed.script_buffer .size ())
@@ -1517,10 +1517,77 @@ void editorrender(void)
15171517 }
15181518 }
15191519
1520+ // Draw selection
1521+
1522+ if (TextInput::selecting) {
1523+ int x = TextInput::cursor_select_pos.x ;
1524+ int y = TextInput::cursor_select_pos.y ;
1525+ int w = TextInput::cursor_pos.x - x;
1526+ int h = TextInput::cursor_pos.y - y;
1527+
1528+ if (h == 0 )
1529+ {
1530+ Selection_Rect rect = TextInput::reorder_selection_positions ();
1531+ char * offset_x = UTF8_substr (ed.script_buffer [rect.y ].c_str (), 0 , rect.x );
1532+ char * cut_string = UTF8_substr (ed.script_buffer [rect.y ].c_str (), rect.x , rect.x2 );
1533+
1534+ graphics.fill_rect (16 + font::len (PR_FONT_LEVEL, offset_x), 20 + (y - ed.script_offset ) * font_height, font::len (PR_FONT_LEVEL,cut_string), font_height, graphics.getRGB (123 , 111 , 218 ));
1535+ font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 + font::len (PR_FONT_LEVEL, offset_x), 20 + (rect.y2 - ed.script_offset ) * font_height, cut_string, 61 , 48 , 162 );
1536+
1537+ SDL_free (offset_x);
1538+ SDL_free (cut_string);
1539+ }
1540+ else
1541+ {
1542+ Selection_Rect rect = TextInput::reorder_selection_positions ();
1543+
1544+ const char * line = ed.script_buffer [rect.y ].c_str ();
1545+
1546+ char * offset_x = UTF8_substr (line, 0 , rect.x );
1547+ char * selection_w = UTF8_substr (line, rect.x , UTF8_total_codepoints (line));
1548+ graphics.fill_rect (16 + font::len (PR_FONT_LEVEL, offset_x), 20 + (rect.y - ed.script_offset ) * font_height, SDL_max (font::len (PR_FONT_LEVEL, selection_w), 1 ), font_height, graphics.getRGB (123 , 111 , 218 ));
1549+ font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 + font::len (PR_FONT_LEVEL, offset_x), 20 + (rect.y - ed.script_offset ) * font_height, selection_w, 61 , 48 , 162 );
1550+ SDL_free (offset_x);
1551+ SDL_free (selection_w);
1552+ for (int i = 1 ; i < rect.y2 - rect.y ; i++)
1553+ {
1554+ if (rect.y + i - ed.script_offset < ed.lines_visible )
1555+ {
1556+ graphics.fill_rect (16 , 20 + (rect.y + i - ed.script_offset ) * font_height, SDL_max (font::len (PR_FONT_LEVEL, ed.script_buffer [rect.y + i].c_str ()), 1 ), font_height, graphics.getRGB (123 , 111 , 218 ));
1557+ font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 , 20 + (rect.y + i - ed.script_offset ) * font_height, ed.script_buffer [rect.y + i].c_str (), 61 , 48 , 162 );
1558+ }
1559+ }
1560+
1561+ if (rect.y2 - ed.script_offset < ed.lines_visible )
1562+ {
1563+ const char * line_2 = ed.script_buffer [rect.y2 ].c_str ();
1564+
1565+ selection_w = UTF8_substr (line_2, 0 , rect.x2 );
1566+ graphics.fill_rect (16 , 20 + (rect.y2 - ed.script_offset ) * font_height, SDL_max (font::len (PR_FONT_LEVEL, selection_w), 1 ), font_height, graphics.getRGB (123 , 111 , 218 ));
1567+ font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 , 20 + (rect.y2 - ed.script_offset ) * font_height, selection_w, 61 , 48 , 162 );
1568+ SDL_free (offset_x);
1569+ SDL_free (selection_w);
1570+ }
1571+ }
1572+ }
1573+
15201574 // Draw cursor
1521- if (ed. entframe < 2 )
1575+ if (TextInput::flash_timer < 15 )
15221576 {
1523- font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 + font::len (PR_FONT_LEVEL, ed.script_buffer [ed.script_cursor_y ].c_str ()), 20 + ((ed.script_cursor_y - ed.script_offset ) * font_height), " _" , 123 , 111 , 218 );
1577+ char * substr = UTF8_substr (ed.script_buffer [TextInput::cursor_pos.y ].c_str (), 0 , TextInput::cursor_pos.x );
1578+
1579+ if (TextInput::cursor_pos.x < (int )ed.script_buffer [TextInput::cursor_pos.y ].size () || TextInput::selecting)
1580+ {
1581+ graphics.set_color (123 , 111 , 218 );
1582+ int x = 16 + font::len (PR_FONT_LEVEL, substr);
1583+ int y = 20 + ((TextInput::cursor_pos.y - ed.script_offset ) * font_height);
1584+ SDL_RenderDrawLine (gameScreen.m_renderer , x, y, x, y + font_height - 1 );
1585+ }
1586+ else
1587+ {
1588+ font::print (PR_FONT_LEVEL | PR_CJK_LOW, 16 + font::len (PR_FONT_LEVEL, substr), 20 + ((TextInput::cursor_pos.y - ed.script_offset ) * font_height), " _" , 123 , 111 , 218 );
1589+ }
1590+ SDL_free (substr);
15241591 }
15251592 break ;
15261593 }
@@ -1832,6 +1899,8 @@ void editorlogic(void)
18321899 ed.entframedelay = 8 ;
18331900 }
18341901
1902+ TextInput::flash_timer = (TextInput::flash_timer + 1 ) % 30 ;
1903+
18351904 ed.old_note_timer = ed.note_timer ;
18361905 ed.note_timer = SDL_max (ed.note_timer - 1 , 0 );
18371906
@@ -2301,8 +2370,6 @@ static void editormenuactionpress(void)
23012370 ed.script_list_offset = 0 ;
23022371 ed.selected_script = 0 ;
23032372
2304- ed.script_cursor_y = 0 ;
2305- ed.script_cursor_x = 0 ;
23062373 ed.script_offset = 0 ;
23072374 ed.lines_visible = 200 / font::height (PR_FONT_LEVEL);
23082375 break ;
@@ -3217,17 +3284,13 @@ void editorinput(void)
32173284 {
32183285 game.mapheld = true ;
32193286 ed.substate = EditorSubState_SCRIPTS_EDIT;
3220- key.enabletextentry ();
3221- key.keybuffer = " " ;
3222- ed.current_text_ptr = &(key.keybuffer );
3287+
32233288 ed.current_script = script.customscripts [(script.customscripts .size () - 1 ) - ed.selected_script ].name ;
32243289 ed.load_script_in_editor (ed.current_script );
32253290
3226- ed.script_cursor_y = ed.script_buffer .size () - 1 ;
3227- ed.script_offset = SDL_max (ed.script_cursor_y - (ed.lines_visible - SCRIPT_LINE_PADDING), 0 );
3291+ ed.script_offset = 0 ;
32283292
3229- key.keybuffer = ed.script_buffer [ed.script_cursor_y ];
3230- ed.script_cursor_x = UTF8_total_codepoints (ed.script_buffer [ed.script_cursor_y ].c_str ());
3293+ TextInput::attach_input (&ed.script_buffer );
32313294
32323295 music.playef (11 );
32333296 }
@@ -3244,41 +3307,11 @@ void editorinput(void)
32443307
32453308 // Alright, now re-add the script.
32463309 ed.create_script (ed.current_script , ed.script_buffer );
3310+ TextInput::detach_input ();
32473311 }
32483312
32493313 if (ed.keydelay > 0 ) ed.keydelay --;
32503314
3251- if (up_pressed && ed.keydelay <= 0 )
3252- {
3253- ed.keydelay = 3 ;
3254- ed.script_cursor_y = SDL_max (0 , ed.script_cursor_y - 1 );
3255-
3256- key.keybuffer = ed.script_buffer [ed.script_cursor_y ];
3257- }
3258-
3259- if (down_pressed && ed.keydelay <= 0 )
3260- {
3261- ed.keydelay = 3 ;
3262- ed.script_cursor_y = SDL_min ((int ) ed.script_buffer .size () - 1 , ed.script_cursor_y + 1 );
3263-
3264- key.keybuffer = ed.script_buffer [ed.script_cursor_y ];
3265- }
3266-
3267- if (key.linealreadyemptykludge )
3268- {
3269- ed.keydelay = 6 ;
3270- key.linealreadyemptykludge = false ;
3271- }
3272-
3273- if (key.pressedbackspace && ed.script_buffer [ed.script_cursor_y ] == " " && ed.keydelay <= 0 )
3274- {
3275- // Remove this line completely
3276- ed.remove_line (ed.script_cursor_y );
3277- ed.script_cursor_y = SDL_max (0 , ed.script_cursor_y - 1 );
3278- key.keybuffer = ed.script_buffer [ed.script_cursor_y ];
3279- ed.keydelay = 6 ;
3280- }
3281-
32823315 /* Remove all pipes, they are the line separator in the XML
32833316 * When this loop reaches the end, it wraps to SIZE_MAX; SIZE_MAX + 1 is 0 */
32843317 {size_t i; for (i = key.keybuffer .length () - 1 ; i + 1 > 0 ; --i)
@@ -3289,38 +3322,14 @@ void editorinput(void)
32893322 }
32903323 }}
32913324
3292- ed.script_buffer [ed.script_cursor_y ] = key.keybuffer ;
3293- ed.script_cursor_x = UTF8_total_codepoints (ed.script_buffer [ed.script_cursor_y ].c_str ());
3294-
3295- if (enter_pressed)
3296- {
3297- // Continue to next line
3298- if (ed.script_cursor_y >= (int )ed.script_buffer .size ()) // we're on the last line
3299- {
3300- ed.script_cursor_y ++;
3301-
3302- key.keybuffer = ed.script_buffer [ed.script_cursor_y ];
3303- ed.script_cursor_x = UTF8_total_codepoints (ed.script_buffer [ed.script_cursor_y ].c_str ());
3304- }
3305- else
3306- {
3307- // We're not, insert a line instead
3308- ed.script_cursor_y ++;
3309-
3310- ed.insert_line (ed.script_cursor_y );
3311- key.keybuffer = " " ;
3312- ed.script_cursor_x = 0 ;
3313- }
3314- }
3315-
3316- if (ed.script_cursor_y < ed.script_offset + SCRIPT_LINE_PADDING)
3325+ if (TextInput::cursor_pos.y < ed.script_offset + SCRIPT_LINE_PADDING)
33173326 {
3318- ed.script_offset = SDL_max (0 , ed. script_cursor_y - SCRIPT_LINE_PADDING);
3327+ ed.script_offset = SDL_max (0 , TextInput::cursor_pos. y - SCRIPT_LINE_PADDING);
33193328 }
33203329
3321- if (ed. script_cursor_y > ed.script_offset + ed.lines_visible - SCRIPT_LINE_PADDING)
3330+ if (TextInput::cursor_pos. y > ed.script_offset + ed.lines_visible - SCRIPT_LINE_PADDING)
33223331 {
3323- ed.script_offset = SDL_min ((int ) ed.script_buffer .size () - ed.lines_visible + SCRIPT_LINE_PADDING, ed. script_cursor_y - ed.lines_visible + SCRIPT_LINE_PADDING);
3332+ ed.script_offset = SDL_min ((int ) ed.script_buffer .size () - ed.lines_visible + SCRIPT_LINE_PADDING, TextInput::cursor_pos. y - ed.lines_visible + SCRIPT_LINE_PADDING);
33243333 }
33253334
33263335 break ;
0 commit comments