21
21
#include " Music.h"
22
22
#include " Screen.h"
23
23
#include " Script.h"
24
+ #include " TextInput.h"
24
25
#include " UTF8.h"
25
26
#include " UtilityClass.h"
26
27
#include " VFormat.h"
@@ -103,8 +104,6 @@ void editorclass::reset(void)
103
104
104
105
clear_script_buffer ();
105
106
106
- script_cursor_x = 0 ;
107
- script_cursor_y = 0 ;
108
107
script_offset = 0 ;
109
108
lines_visible = 25 ;
110
109
current_script = " null" ;
@@ -1509,6 +1508,7 @@ void editorrender(void)
1509
1508
1510
1509
// Draw text
1511
1510
int font_height = font::height (PR_FONT_LEVEL);
1511
+
1512
1512
for (int i = 0 ; i < ed.lines_visible ; i++)
1513
1513
{
1514
1514
if (i + ed.script_offset < (int ) ed.script_buffer .size ())
@@ -1517,10 +1517,77 @@ void editorrender(void)
1517
1517
}
1518
1518
}
1519
1519
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
+
1520
1574
// Draw cursor
1521
- if (ed. entframe < 2 )
1575
+ if (TextInput::flash_timer < 15 )
1522
1576
{
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);
1524
1591
}
1525
1592
break ;
1526
1593
}
@@ -1832,6 +1899,8 @@ void editorlogic(void)
1832
1899
ed.entframedelay = 8 ;
1833
1900
}
1834
1901
1902
+ TextInput::flash_timer = (TextInput::flash_timer + 1 ) % 30 ;
1903
+
1835
1904
ed.old_note_timer = ed.note_timer ;
1836
1905
ed.note_timer = SDL_max (ed.note_timer - 1 , 0 );
1837
1906
@@ -2301,8 +2370,6 @@ static void editormenuactionpress(void)
2301
2370
ed.script_list_offset = 0 ;
2302
2371
ed.selected_script = 0 ;
2303
2372
2304
- ed.script_cursor_y = 0 ;
2305
- ed.script_cursor_x = 0 ;
2306
2373
ed.script_offset = 0 ;
2307
2374
ed.lines_visible = 200 / font::height (PR_FONT_LEVEL);
2308
2375
break ;
@@ -3217,17 +3284,13 @@ void editorinput(void)
3217
3284
{
3218
3285
game.mapheld = true ;
3219
3286
ed.substate = EditorSubState_SCRIPTS_EDIT;
3220
- key.enabletextentry ();
3221
- key.keybuffer = " " ;
3222
- ed.current_text_ptr = &(key.keybuffer );
3287
+
3223
3288
ed.current_script = script.customscripts [(script.customscripts .size () - 1 ) - ed.selected_script ].name ;
3224
3289
ed.load_script_in_editor (ed.current_script );
3225
3290
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 ;
3228
3292
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 );
3231
3294
3232
3295
music.playef (11 );
3233
3296
}
@@ -3244,41 +3307,11 @@ void editorinput(void)
3244
3307
3245
3308
// Alright, now re-add the script.
3246
3309
ed.create_script (ed.current_script , ed.script_buffer );
3310
+ TextInput::detach_input ();
3247
3311
}
3248
3312
3249
3313
if (ed.keydelay > 0 ) ed.keydelay --;
3250
3314
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
-
3282
3315
/* Remove all pipes, they are the line separator in the XML
3283
3316
* When this loop reaches the end, it wraps to SIZE_MAX; SIZE_MAX + 1 is 0 */
3284
3317
{size_t i; for (i = key.keybuffer .length () - 1 ; i + 1 > 0 ; --i)
@@ -3289,38 +3322,14 @@ void editorinput(void)
3289
3322
}
3290
3323
}}
3291
3324
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)
3317
3326
{
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);
3319
3328
}
3320
3329
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)
3322
3331
{
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);
3324
3333
}
3325
3334
3326
3335
break ;
0 commit comments