From 66a80011ceaadbbc2a835b60c68f60415eaeed96 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Fri, 31 Jan 2020 16:25:55 +0100 Subject: work --- src/assets.c | 1 + src/config.h | 2 + src/input.c | 2 + src/mo_edit.c | 168 ++++++++++++++++++++++++++++++++++++++++------------- src/string_utils.c | 8 ++- src/ui.c | 2 +- 6 files changed, 140 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/assets.c b/src/assets.c index 37334dd..4b8bd3e 100644 --- a/src/assets.c +++ b/src/assets.c @@ -131,6 +131,7 @@ bool assets_queue_worker_load_font(font *font) if (i == 'M') font->px_h = -yoff; if (i == ' ') new_glyph.xoff = font->size/3; + if (i == 'g') new_glyph.xoff += 1; // stupid font or stupid me? font->glyphs[i-TEXT_CHARSET_START] = new_glyph; } diff --git a/src/config.h b/src/config.h index 3bfb3c3..51b6563 100644 --- a/src/config.h +++ b/src/config.h @@ -16,5 +16,7 @@ #define MAX_STATUS_TEXT_LENGTH 120 #define MAX_TERM_NAME_LENGTH 100 +#define UNSAVED_CHANGES_COLOR rgb(255, 102, 102) +#define MISSING_TRANSLATION_COLOR rgb(255, 179, 102) #endif \ No newline at end of file diff --git a/src/input.c b/src/input.c index 40f7b74..4ee795b 100644 --- a/src/input.c +++ b/src/input.c @@ -201,6 +201,8 @@ void keyboard_handle_input_string(platform_window *window, keyboard_input *keybo if (keyboard_is_key_down(keyboard, KEY_BACKSPACE)) { + current_keyboard_to_handle->keys[KEY_BACKSPACE] = false; + bool is_lctrl_down = keyboard->keys[KEY_LEFT_CONTROL]; if (keyboard->has_selection) diff --git a/src/mo_edit.c b/src/mo_edit.c index fe511ac..abbad3f 100644 --- a/src/mo_edit.c +++ b/src/mo_edit.c @@ -10,6 +10,7 @@ #include "languages.h" // TODO(Aldrik): option to disable menu item +// TODO(Aldrik): move the delete button for term to edit panel on the topright and put a exclamation mark at the old spot to indicate a missing translation typedef struct t_translation { @@ -159,8 +160,39 @@ void add_country_to_project() void set_term_name(s32 index, char *name) { - term *t = array_at(¤t_project->terms, index); - string_copyn(t->name, name, MAX_TERM_NAME_LENGTH); + if (strlen(name) > 0) + { + term *t = array_at(¤t_project->terms, index); + string_copyn(t->name, name, MAX_TERM_NAME_LENGTH); + } + else + { + // TODO(Aldrik): translate + platform_show_message(main_window, "Term name cannot be empty", "Invalid input"); + } +} + +void remove_country_from_project(s32 index) +{ + for (s32 i = 0; i < current_project->languages.length; i++) + { + s32 ind = *(s32*)array_at(¤t_project->languages, i); + + if (ind == index) + array_remove_at(¤t_project->languages, i); + } + + for (s32 x = 0; x < current_project->terms.length; x++) + { + term *tr = array_at(¤t_project->terms, x); + + tr->translations[index].valid = false; + if (tr->translations[index].value) + { + mem_free(tr->translations[index].value); + tr->translations[index].value = 0; + } + } } void select_term(s32 index) @@ -186,6 +218,9 @@ void select_term(s32 index) s32 add_term_to_project() { + tb_filter.state = 0; + ui_set_textbox_text(&tb_filter, ""); + term t; t.name = mem_alloc(MAX_TERM_NAME_LENGTH); @@ -217,6 +252,28 @@ s32 add_term_to_project() return array_push(¤t_project->terms, &t); } +void save_term_changes() +{ + set_term_name(current_project->selected_term_index, tb_new_term.buffer); + + term *t = array_at(¤t_project->terms, current_project->selected_term_index); + + for (s32 x = 0; x < COUNTRY_CODE_COUNT; x++) + { + textbox_state *tb = &tb_translation_list[x]; + + if (t->translations[x].valid && strlen(tb->buffer)) + { + if (!t->translations[x].value) + { + t->translations[x].value = mem_alloc(MAX_INPUT_LENGTH); + } + + string_copyn(t->translations[x].value, tb->buffer, MAX_INPUT_LENGTH); + } + } +} + void start_new_project() { current_project = mem_alloc(sizeof(translation_project)); @@ -418,24 +475,27 @@ int main(int argc, char **argv) { term *t = array_at(¤t_project->terms, i); - ui_push_button_image(&btn_summary, "", delete_img); - //ui_push_image(exclaim_img, 14, 14, 1, rgb(255,255,255)); - - if (i == current_project->selected_term_index) - { - ui_push_rect(10, global_ui_context.style.textbox_active_border); - } - else - { - ui_push_rect(10, global_ui_context.style.background); - } - - if (ui_push_text_width(t->name, global_ui_context.layout.width-100, true)) + if (!strlen(tb_filter.buffer) || string_contains(t->name, tb_filter.buffer)) { - select_term(i); + ui_push_button_image(&btn_summary, "", delete_img); + //ui_push_image(exclaim_img, 14, 14, 1, rgb(255,255,255)); + + if (i == current_project->selected_term_index) + { + ui_push_rect(10, global_ui_context.style.textbox_active_border); + } + else + { + ui_push_rect(10, global_ui_context.style.background); + } + + if (ui_push_text_width(t->name, global_ui_context.layout.width-100, true)) + { + select_term(i); + } + + ui_block_end(); } - - ui_block_end(); } } ui_scroll_end(); @@ -456,20 +516,29 @@ int main(int argc, char **argv) if (current_project && current_project->selected_term_index >= 0) { - bool set_name = keyboard_is_key_pressed(&keyboard, KEY_ENTER) && - tb_new_term.state; + if (keyboard_is_key_down(&keyboard, KEY_LEFT_CONTROL) && keyboard_is_key_pressed(&keyboard, KEY_S)) + { + save_term_changes(); + } + + term *t = array_at(¤t_project->terms, + current_project->selected_term_index); ui_block_begin(LAYOUT_HORIZONTAL); { // editor - ui_push_textbox(&tb_new_term, "Term name"); - if (set_name) - set_term_name(current_project->selected_term_index, tb_new_term.buffer); + if (string_equals(tb_new_term.buffer, t->name)) + ui_push_rect(10, global_ui_context.style.background); + else + ui_push_rect(10, UNSAVED_CHANGES_COLOR); + + // TODO(Aldrik): localize + ui_push_textbox(&tb_new_term, "Term name"); if (ui_push_button_image(&btn_set_term_name, "", set_img)) { - set_term_name(current_project->selected_term_index, tb_new_term.buffer); + save_term_changes(); } } ui_block_end(); @@ -477,29 +546,46 @@ int main(int argc, char **argv) global_ui_context.layout.offset_x = 310; ui_push_separator(); - term *t = array_at(¤t_project->terms, - current_project->selected_term_index); - trans_scroll.height = main_window->height-global_ui_context.layout.offset_y; ui_scroll_begin(&trans_scroll); { - for (s32 i = 0; i < COUNTRY_CODE_COUNT; i++) + if (!current_project->languages.length) { - translation *tr = &t->translations[i]; - - if (tr->valid) + ui_push_text("No languages added to project yet."); + } + else + { + for (s32 i = 0; i < COUNTRY_CODE_COUNT; i++) { - TEXTBOX_WIDTH = global_ui_context.layout.width - 100; + translation *tr = &t->translations[i]; - ui_push_textbox(&tb_translation_list[i], ""); - ui_push_image(list_img, TEXTBOX_HEIGHT,TEXTBOX_HEIGHT,1,rgb(255,255,255)); - ui_push_text_width(global_langues[i].code, 25, false); - - global_ui_context.layout.offset_y += TEXTBOX_HEIGHT + WIDGET_PADDING; - global_ui_context.layout.offset_x = 310; + if (tr->valid) + { + TEXTBOX_WIDTH = global_ui_context.layout.width - 130; + + if (!tr->value && !strlen(tb_translation_list[i].buffer)) + { + ui_push_rect(10, MISSING_TRANSLATION_COLOR); + } + else if (tr->value && string_equals(tb_translation_list[i].buffer, + tr->value)) + { + ui_push_rect(10, global_ui_context.style.background); + } + else + { + ui_push_rect(10, UNSAVED_CHANGES_COLOR); + } + + ui_push_textbox(&tb_translation_list[i], ""); + ui_push_image(list_img, TEXTBOX_HEIGHT,TEXTBOX_HEIGHT,1,rgb(255,255,255)); + ui_push_text_width(global_langues[i].code, 25, false); + + global_ui_context.layout.offset_y += TEXTBOX_HEIGHT + WIDGET_PADDING; + global_ui_context.layout.offset_x = 310; + } } - } } ui_scroll_end(); @@ -586,7 +672,7 @@ int main(int argc, char **argv) if (pressed) { - array_remove_at(¤t_project->languages, i); + remove_country_from_project(index); i--; } @@ -616,7 +702,7 @@ int main(int argc, char **argv) double time_to_wait = (TARGET_FRAMERATE) - diff_ms; thread_sleep(time_to_wait*1000); } - } + } settings_page_hide_without_save(); diff --git a/src/string_utils.c b/src/string_utils.c index 5c8aac9..2ad2f0d 100644 --- a/src/string_utils.c +++ b/src/string_utils.c @@ -70,8 +70,10 @@ bool string_contains_ex(char *text_to_search, char *text_to_find, array *text_ma s32 word_match_len_val = 0; char* line_start_ptr = text_to_search; + //printf("%s %s\n", text_to_search, text_to_find); s32 index = 0; - while((text_to_search = utf8codepoint(text_to_search, &text_to_search_ch)) + char *text_to_ss = text_to_search; + while((text_to_ss = utf8codepoint(text_to_search, &text_to_search_ch)) && text_to_search_ch) { if (cancel_search && *cancel_search) goto set_info_and_return_failure; @@ -93,6 +95,7 @@ bool string_contains_ex(char *text_to_search, char *text_to_find, array *text_ma text_to_search_current_attempt = utf8codepoint(text_to_search_current_attempt, &text_to_search_current_attempt_ch); + text_to_search = text_to_ss; word_match_len_val = 0; while(text_to_search_current_attempt_ch) { @@ -116,6 +119,7 @@ bool string_contains_ex(char *text_to_search, char *text_to_find, array *text_ma // text to find has reached 0byte, word has been found if (text_to_find_ch == 0) { + done: if (save_info) { text_match new_match; @@ -149,6 +153,8 @@ bool string_contains_ex(char *text_to_search, char *text_to_find, array *text_ma text_to_search_current_attempt, &text_to_search_current_attempt_ch); + if (!text_to_search_current_attempt_ch && !text_to_find_ch) goto done; + word_match_len_val++; } diff --git a/src/ui.c b/src/ui.c index 536eef6..6c9783b 100644 --- a/src/ui.c +++ b/src/ui.c @@ -180,7 +180,7 @@ static void ui_pop_scissor() s32 y = global_ui_context.layout.offset_y + global_ui_context.camera->y - WIDGET_PADDING; render_set_scissor(global_ui_context.layout.active_window, - x,y,w,h); + 0,y,global_ui_context.layout.active_window->width,h); } else { -- cgit v1.2.3-70-g09d2