From 2d57f82b254fa797a0deab0109a8567287e0bb77 Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Sat, 30 May 2015 04:33:29 +0100 Subject: [PATCH 1/4] add the base for the twitch window --- data/language/english_uk.txt | 5 +- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + src/interface/window.h | 2 + src/localisation/string_ids.h | 4 + src/windows/options.c | 3 +- src/windows/twitch.c | 148 ++++++++++++++++++++++++++++++ 7 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 src/windows/twitch.c diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index ce815fca10..3409b5461d 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3593,4 +3593,7 @@ STR_5256 :Create a new theme to make changes to STR_5257 :{SMALLFONT}{BLACK}Create a new theme based on the current one STR_5258 :{SMALLFONT}{BLACK}Delete the current theme STR_5259 :{SMALLFONT}{BLACK}Rename the current theme -STR_5260 :Giant Screenshot \ No newline at end of file +STR_5260 :Giant Screenshot +STR_5261 :Twitch Integration Options +STR_5262 :Log in with Twtich +STR_5263 :{SMALLFONT}{BLACK}Authenticate the game with your Twitch account to enable Twitch features diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 7ffaf599b9..f882581273 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -143,6 +143,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index b4708cd894..ca95f5524f 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -456,6 +456,9 @@ Source\Windows + + Source\Windows + diff --git a/src/interface/window.h b/src/interface/window.h index 9bae78e466..fd371b88ab 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -406,6 +406,7 @@ enum { WC_TITLE_OPTIONS = 117, WC_LAND_RIGHTS = 118, WC_THEMES = 119, + WC_TWITCH = 120, // Only used for colour schemes WC_STAFF = 220, @@ -513,6 +514,7 @@ void window_resize_gui_scenario_editor(int width, int height); void window_top_toolbar_open(); void window_game_bottom_toolbar_open(); void window_about_open(); +void window_twitch_open(); void window_footpath_open(); void window_save_prompt_open(); void window_title_menu_open(); diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 07a7470199..bc8207eb61 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -1426,6 +1426,10 @@ enum { STR_GIANT_SCREENSHOT = 5260, + STR_TWITCH_WINDOW_TITLE = 5261, + STR_TWITCH_AUTH = 5262, + STR_TWITCH_AUTH_TIP = 5263, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/windows/options.c b/src/windows/options.c index 3491a2816e..32099721d0 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -350,7 +350,8 @@ static void window_options_mouseup() window_shortcut_keys_open(); break; case WIDX_CHANNEL_BUTTON: - window_text_input_raw_open(w, widgetIndex, STR_TWITCH_NAME, STR_TWITCH_NAME_DESC, gConfigTwitch.channel, 32); + //window_text_input_raw_open(w, widgetIndex, STR_TWITCH_NAME, STR_TWITCH_NAME_DESC, gConfigTwitch.channel, 32); + window_twitch_open(); break; case WIDX_SCREEN_EDGE_SCROLLING: gConfigGeneral.edge_scrolling ^= 1; diff --git a/src/windows/twitch.c b/src/windows/twitch.c new file mode 100644 index 0000000000..9d5c61ebb5 --- /dev/null +++ b/src/windows/twitch.c @@ -0,0 +1,148 @@ +/***************************************************************************** +* Copyright (c) 2014 Ted John +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* This file is part of OpenRCT2. +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#include "../addresses.h" +#include "../localisation/localisation.h" +#include "../sprites.h" +#include "../interface/widget.h" +#include "../interface/window.h" + +enum window_twitch_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_TWITCH_AUTH +}; + +rct_widget window_twitch_widgets[] = { + { WWT_FRAME, 0, 0, 399, 0, 329, 0x0FFFFFFFF, STR_NONE }, // panel / background + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_TWITCH_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, // title bar + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button + { WWT_DROPDOWN_BUTTON, 1, 100, 299, 53, 64, STR_TWITCH_AUTH, STR_TWITCH_AUTH_TIP }, // twitch auth + { WIDGETS_END }, +}; + +static void window_twitch_emptysub() { } +static void window_twitch_mouseup(); +static void window_twitch_paint(); + +static void* window_twitch_events[] = { + window_twitch_emptysub, + window_twitch_mouseup, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_emptysub, + window_twitch_paint, + window_twitch_emptysub +}; + +/** +* +* rct2: 0x0066D2AC +*/ +void window_twitch_open() +{ + rct_window* window; + + // Check if window is already open + window = window_bring_to_front_by_class(WC_TWITCH); + if (window != NULL) + return; + + window = window_create_centred( + 400, + 330, + (uint32*)window_twitch_events, + WC_TWITCH, + 0 + ); + window->widgets = window_twitch_widgets; + window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_TWITCH_AUTH); + + window_init_scroll_widgets(window); + window->colours[0] = 7; + window->colours[1] = 7; + window->colours[2] = 7; +} + +/** +* +* rct2: 0x0066D4D5 +*/ +static void window_twitch_mouseup() +{ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex) { + case WIDX_CLOSE: + window_close(w); + break; + } +} + +/** +* +* rct2: 0x0066D321 +*/ +static void window_twitch_paint() +{ + int x, y; + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); + + x = w->x + 180; + y = w->y + 17; + + gfx_draw_sprite(dpi, SPR_G2_TAB_TWITCH, x, y, 0); + + x = w->x + 280; + y = w->y + 315; + + gfx_draw_string_left(dpi, STR_TWITCH_POWERDBY, NULL, 12, x, y); + +} From 6e690bdd610c50db8a2508d7e41a16a651d3cd1d Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Mon, 1 Jun 2015 12:47:06 +0100 Subject: [PATCH 2/4] add multi text input, add decorations to twitch window --- data/language/english_uk.txt | 7 +- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + resources/g2/7.png | Bin 156 -> 1131 bytes src/interface/window.h | 3 + src/sprites.h | 2 +- src/windows/multi_text_input.c | 566 ++++++++++++++++++++++++++++++ src/windows/twitch.c | 16 +- 8 files changed, 589 insertions(+), 9 deletions(-) create mode 100644 src/windows/multi_text_input.c diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 3409b5461d..0877fb3c37 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3497,7 +3497,7 @@ STR_5160 :{MONTH} {STRINGID}, Year {COMMA16} STR_5161 :{WHITE}Date Format: STR_5162 :Day/Month/Year STR_5163 :Month/Day/Year -STR_5164 :Twitch Channel name +STR_5164 :Twitch Integration Options STR_5165 :Name peeps after followers STR_5166 :{SMALLFONT}{BLACK}Will name peeps after channel's Twitch followers STR_5167 :Track follower peeps @@ -3508,7 +3508,7 @@ STR_5171 :Track chat peeps STR_5172 :{SMALLFONT}{BLACK}Will turn on tracking information for guests named after Twitch chat participants STR_5173 :Pull Twitch chat as news STR_5174 :{SMALLFONT}{BLACK}Will use Twitch chat messages preceded by !news for in game notifications -STR_5175 :Input the name of your Twitch channel +STR_5175 :Login with your Twitch account. STR_5176 :Enable Twitch integration STR_5177 :Fullscreen mode: STR_5178 :{SMALLFONT}{BLACK}Show financial cheats @@ -3587,6 +3587,7 @@ STR_5250 :Title Exit Button STR_5251 :Title Options Button STR_5252 :Title Scenario Selection STR_5253 :Park Information +<<<<<<< HEAD STR_5254 :Add nausea STR_5255 :{MEDIUMFONT}{BLACK}All peeps become nauseous STR_5256 :Create a new theme to make changes to @@ -3595,5 +3596,5 @@ STR_5258 :{SMALLFONT}{BLACK}Delete the current theme STR_5259 :{SMALLFONT}{BLACK}Rename the current theme STR_5260 :Giant Screenshot STR_5261 :Twitch Integration Options -STR_5262 :Log in with Twtich +STR_5262 :Log in with Twitch STR_5263 :{SMALLFONT}{BLACK}Authenticate the game with your Twitch account to enable Twitch features diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index f882581273..9669738e98 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -112,6 +112,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index ca95f5524f..879d0ef53c 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -459,6 +459,9 @@ Source\Windows + + Source\Windows + diff --git a/resources/g2/7.png b/resources/g2/7.png index 205d3c50a4ebcfd04d966473a5b0de733b2eb422..8b6ed467014d2618290a5f46c5a16029b626420f 100644 GIT binary patch delta 1059 zcmV+;1l;?a0qY1MiBL{Q4GJ0x0000DNk~Le0001F0001F2nGNE0C3`!RFNTAe*@e} zL_t(|UhS0)j@2*>g!dL4fcu{jNM%3Gjwb)@lBE75>m~Ns#8VJoK@bE%5ClPRFTZ~O z{$s}vDt82FF$_yDg?iVjZ=D7gTlJ&7_Jbt+o_;Z|;y>`5$lbjU>mxa?Ik`G(`Mx~7 z42GpYc|TuCL)}@g&Iwh+T!QZof9Cm|ejUCqk1yllxvL0ZjnBEegY_$6s5|EpEjhpA z3_NdxdT=f0=h80+)*aS(SouRs4(~ok^(~KjG%u68doFiRXM}S(4d(go)HJGR3vv(l zB|R+tfphAP;kl~_uqJ^yt~sT;$_4+C_!tWj|2l%T@V}85RvJRhOJU`pe}pp5!z5j( zIT$7jawyX1ejj)*`hR*f}0GrurC~C3SbHN~NW{aV! z2g78+2+B|llYK+!FiaMVpbSmnwM$e%^#+5mnH(l7GSU-dU^7Pyo$U_*Hgm+#+5P}v zGe-=a?GJ!E%;XuPb6(F~M&32&_1tOXU2|T|ohI_E*?F(yZUgV0fA>0`Fz|_)uiz=; zo|=0+Pa5~s+@pEYG@gC;{Ns4qu&3uA$4?mc6Mx1r^cbb;wVnjd_pnlc{G?Go_2+C& zk4Z|?(&xAq!%9J-#~`Iqxe}=F>3a<|gYd32Dpv!0diq{Lk2y-mIj$?Pr$zr7YQ}J$ z?}=Jnfw~s`Yp9u0f2t`;dd{KN!%FX@#gI}>(W6IgYtPZN8lv*09?a!5j@N6tS1@V@ z_vLzP^#p2a+M^jULiJ#n>_e&Mpr)ohnjRyRwiMRZ^g$A+YtbJ`j{&T032VK2?U;po zTY8S7*8rt&32Sd+rgwWrmgk<9u+}DK`?qCuan)A~Yi(k-e}7w^UVLUQ_Kwcjj+GbY zx2^WR+u32^)!%n3J1om@T=kvP?6T-C@0@0*MR$7ZFgq>CZ(aSpL#QQp3R~kG)RH@e zt#KA=(H+8`elSdjM@iDXOG(5 za|t{@&8V5eeRhv>5{jRjfqn5>7 zuI~AqHrHpzqE_8GcPzZDy4&#^p3iAjUyC-KYrV(gCMYxTt~8jd. +*****************************************************************************/ + +/** +* Text Input Window +* +* This is a new window created to replace the windows dialog box +* that is used for inputing new text for ride names and peep names. +*/ + +#include "../addresses.h" +#include "../config.h" +#include "../platform/platform.h" +#include "../interface/window.h" +#include "../interface/widget.h" +#include "../localisation/localisation.h" + +#define WW 250 +#define WH 110 + +enum WINDOW_MULTI_TEXT_INPUT_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_USERNAME, + WIDX_PASSWORD, + WIDX_CANCEL, + WIDX_OKAY +}; + +// 0x9DE4E0 +static rct_widget window_multi_text_input_widgets[] = { + { WWT_FRAME, 1, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE }, + { WWT_CAPTION, 1, 1, WW - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 1, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WWT_SPINNER, 1, WW - 240, WW - 10, WH - 60, WH - 47, STR_NONE, STR_NONE }, + { WWT_SPINNER, 1, WW - 240, WW - 10, WH - 41, WH - 30, STR_NONE, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, WW - 80, WW - 10, WH - 21, WH - 10, STR_CANCEL, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 10, 80, WH - 21, WH - 10, STR_OK, STR_NONE }, + { WIDGETS_END } +}; + +static void window_multi_text_input_emptysub(){} +static void window_multi_text_input_mouseup(); +static void window_multi_text_input_paint(); +static void window_multi_text_input_text(int key, rct_window* w); +static void window_multi_text_input_update7(); +static void window_multi_text_input_close(); +static void window_multi_text_input_invalidate(); + +//0x9A3F7C +static void* window_text_input_events[] = { + window_multi_text_input_close, + window_multi_text_input_mouseup, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_update7, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_text, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_emptysub, + window_multi_text_input_invalidate, + window_multi_text_input_paint, + window_multi_text_input_emptysub +}; + +int input_text_description; +char multi_text_input[512] = { 0 }; +char multi_text_input2[512] = { 0 }; +rct_windowclass multi_calling_class = 0; +rct_windownumber multi_calling_number = 0; +int multi_calling_widget = 0; +int _multi_maxInputLength; +int _multi_maxInputLength2; +bool _multi_isPass; +bool _multi_isPass2; +int inInput; + +void window_multi_text_input_open( + rct_window* call_w, + int call_widget, + rct_string_id title, + rct_string_id description, + rct_string_id existing_text, + uint32 existing_args, + int maxLength, + bool isPass, + rct_string_id existing_text2, + uint32 existing_args2, + int maxLength2, + bool isPass2 +) { + _multi_maxInputLength = maxLength; + _multi_maxInputLength2 = maxLength2; + _multi_isPass = isPass; + _multi_isPass2 = isPass2; + + window_close_by_class(WC_MULTI_TEXTINPUT); + + // Clear the text input buffer + memset(multi_text_input, 0, maxLength); + memset(multi_text_input2, 0, maxLength2); + + + // Enter in the the text input buffer any existing + // text. + if (existing_text != (rct_string_id)STR_NONE) + format_string(multi_text_input, existing_text, &existing_args); + + if (existing_text2 != (rct_string_id)STR_NONE) + format_string(multi_text_input2, existing_text2, &existing_args2); + + // In order to prevent strings that exceed the maxLength + // from crashing the game. + multi_text_input[maxLength - 1] = '\0'; + multi_text_input2[maxLength2 - 1] = '\0'; + + // This is the text displayed above the input box + input_text_description = description; + + // Work out the existing size of the window + char wrapped_string[512]; + char wrapped_string2[512]; + strcpy(wrapped_string, multi_text_input); + strcpy(wrapped_string2, multi_text_input2); + + int no_lines = 0, font_height = 0; + + // String length needs to add 12 either side of box + // +13 for cursor when max length. + gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string2, WW - (24 + 13), &no_lines, &font_height); + + int height = no_lines * 10 + WH; + + // Window will be in the center of the screen + rct_window* w = window_create_centred( + WW, + height, + (uint32*)window_text_input_events, + WC_MULTI_TEXTINPUT, + WF_STICK_TO_FRONT + ); + + w->widgets = window_multi_text_input_widgets; + w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_USERNAME) | (1 << WIDX_PASSWORD) | (1 << WIDX_CANCEL) | (1 << WIDX_OKAY); + + window_multi_text_input_widgets[WIDX_TITLE].image = title; + + // Save calling window details so that the information + // can be passed back to the correct window & widget + multi_calling_class = call_w->classification; + multi_calling_number = call_w->number; + multi_calling_widget = call_widget; + + platform_start_text_input(multi_text_input, maxLength); + inInput = 0; + + window_init_scroll_widgets(w); + w->colours[0] = call_w->colours[0]; + w->colours[1] = call_w->colours[1]; + w->colours[2] = call_w->colours[2]; +} + +void window_multi_text_input_raw_open( + rct_window* call_w, + int call_widget, + rct_string_id title, + rct_string_id description, + utf8string existing_text, + int maxLength, + bool isPass, + utf8string existing_text2, + int maxLength2, + bool isPass2 +) { + _multi_maxInputLength = maxLength; + _multi_maxInputLength2 = maxLength2; + _multi_isPass = isPass; + _multi_isPass2 = isPass2; + + window_close_by_class(WC_MULTI_TEXTINPUT); + + // Clear the text input buffer + memset(multi_text_input, 0, maxLength); + memset(multi_text_input2, 0, maxLength2); + + // Enter in the the text input buffer any existing + // text. + if (existing_text != NULL) + strncpy(multi_text_input, existing_text, maxLength); + if (existing_text2 != NULL) + strncpy(multi_text_input2, existing_text2, maxLength2); + + // In order to prevent strings that exceed the maxLength + // from crashing the game. + multi_text_input[maxLength - 1] = '\0'; + multi_text_input2[maxLength2 - 1] = '\0'; + + + // This is the text displayed above the input box + input_text_description = description; + + // Work out the existing size of the window + char wrapped_string[512]; + char wrapped_string2[512]; + strcpy(wrapped_string, multi_text_input); + strcpy(wrapped_string2, multi_text_input2); + + int no_lines = 0, font_height = 0; + + // String length needs to add 12 either side of box + // +13 for cursor when max length. + gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string2, WW - (24 + 13), &no_lines, &font_height); + + int height = no_lines * 10 + WH; + + // Window will be in the center of the screen + rct_window* w = window_create_centred( + WW, + height, + (uint32*)window_text_input_events, + WC_MULTI_TEXTINPUT, + WF_STICK_TO_FRONT + ); + + w->widgets = window_multi_text_input_widgets; + w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_USERNAME) | (1 << WIDX_PASSWORD) | (1 << WIDX_CANCEL) | (1 << WIDX_OKAY); + + window_multi_text_input_widgets[WIDX_TITLE].image = title; + + // Save calling window details so that the information + // can be passed back to the correct window & widget + multi_calling_class = call_w->classification; + multi_calling_number = call_w->number; + multi_calling_widget = call_widget; + + platform_start_text_input(multi_text_input, maxLength); + inInput = 0; + + window_init_scroll_widgets(w); + w->colours[0] = call_w->colours[0]; + w->colours[1] = call_w->colours[1]; + w->colours[2] = call_w->colours[2]; +} + +/** +* +*/ +static void window_multi_text_input_mouseup(){ + short widgetIndex; + rct_window *w; + rct_window *calling_w; + window_widget_get_registers(w, widgetIndex); + + calling_w = window_find_by_number(multi_calling_class, multi_calling_number); + + switch (widgetIndex){ + case WIDX_CANCEL: + case WIDX_CLOSE: + platform_stop_text_input(); + // Pass back the text that has been entered. + // ecx when zero means text input failed + if (calling_w != NULL) + window_event_textinput_call(calling_w, multi_calling_widget, NULL, NULL); + window_close(w); + break; + case WIDX_OKAY: + platform_stop_text_input(); + // Pass back the text that has been entered. + // ecx when none zero means text input success + if (calling_w != NULL) + window_event_textinput_call(calling_w, multi_calling_widget, multi_text_input, multi_text_input2); + window_close(w); + break; + case WIDX_USERNAME: + platform_stop_text_input(); + platform_start_text_input(multi_text_input, _multi_maxInputLength); + inInput = 0; + break; + case WIDX_PASSWORD: + platform_stop_text_input(); + platform_start_text_input(multi_text_input2, _multi_maxInputLength2); + inInput = 1; + break; + } +} + +/** +* +*/ +static void window_multi_text_input_paint(){ + rct_window *w; + rct_drawpixelinfo *dpi; + + window_paint_get_registers(w, dpi); + + window_draw_widgets(w, dpi); + + int y = w->y + 25; + + int no_lines = 0; + int font_height = 0; + + + gfx_draw_string_centred(dpi, input_text_description, w->x + WW / 2, y, w->colours[1], &TextInputDescriptionArgs); + + y += 25; + + char wrapped_string[512]; + char wrapped_string2[512]; + char wrapped_string_pass[512]; + char wrapped_string2_pass[512]; + strcpy(wrapped_string, multi_text_input); + strcpy(wrapped_string2, multi_text_input2); + strcpy(wrapped_string_pass, multi_text_input); + strcpy(wrapped_string2_pass, multi_text_input2); + + // String length needs to add 12 either side of box + // +13 for cursor when max length. + gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string2, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string_pass, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string2_pass, WW - (24 + 13), &no_lines, &font_height); + + //gfx_fill_rect_inset(dpi, w->x + 10, y, w->x + WW - 10, y + 10 * (no_lines + 1) + 3, w->colours[1], 0x60); + + y += 1; + + char* wrap_pointer = wrapped_string; + char* wrap_pointer2 = wrapped_string2; + char* wrap_pointer_pass = wrapped_string_pass; + char* wrap_pointer2_pass = wrapped_string2_pass; + int char_count = 0; + int char_count2 = 0; + uint8 cur_drawn = 0; + uint8 cur_drawn2 = 0; + + int wrap_point_len = strlen(wrapped_string); + int wrap_point2_len = strlen(wrapped_string2); + + if (_multi_isPass) { + for (int i = 0; i < wrap_point_len; i++) { + wrap_pointer_pass[i] = '*'; + } + } + if (_multi_isPass2) { + for (int i = 0; i < wrap_point2_len; i++) { + wrap_pointer2_pass[i] = '*'; + } + } + + for (int line = 0; line <= no_lines; ++line){ + if (_multi_isPass) { + gfx_draw_string(dpi, wrap_pointer_pass, w->colours[1], w->x + 12, y); + } + else { + gfx_draw_string(dpi, wrap_pointer, w->colours[1], w->x + 12, y); + } + + int string_length = get_string_length(wrap_pointer); + + if (inInput == 0) { + if (!cur_drawn && (gTextInputCursorPosition <= char_count + string_length)){ + // Make a copy of the string for measuring the width. + char temp_string[512] = { 0 }; + if (_multi_isPass) { + memcpy(temp_string, wrap_pointer_pass, gTextInputCursorPosition - char_count); + } else { + memcpy(temp_string, wrap_pointer, gTextInputCursorPosition - char_count); + } + + int cur_x = w->x + 13 + gfx_get_string_width(temp_string); + + int width = 6; + if ((uint32)gTextInputCursorPosition < strlen(multi_text_input)){ + // Make a new 1 character wide string for measuring the width + // of the character that the cursor is under. + temp_string[1] = '\0'; + temp_string[0] = multi_text_input[gTextInputCursorPosition]; + width = max(gfx_get_string_width(temp_string) - 2, 4); + } + + if (w->frame_no > 15){ + uint8 colour = RCT2_ADDRESS(0x0141FC48, uint8)[w->colours[1] * 8]; + gfx_fill_rect(dpi, cur_x, y + 9, cur_x + width, y + 9, colour + 5); + } + + cur_drawn++; + } + } + + wrap_pointer += string_length + 1; + + if (multi_text_input[char_count + string_length] == ' ')char_count++; + char_count += string_length; + + y += 18; + } + for (int line = 0; line <= no_lines; ++line){ + if (_multi_isPass2) { + gfx_draw_string(dpi, wrap_pointer2_pass, w->colours[1], w->x + 12, y); + } else { + gfx_draw_string(dpi, wrap_pointer2, w->colours[1], w->x + 12, y); + } + + int string_length = get_string_length(wrap_pointer2); + + if (inInput == 1) { + if (!cur_drawn2 && (gTextInputCursorPosition <= char_count2 + string_length)){ + // Make a copy of the string for measuring the width. + char temp_string[512] = { 0 }; + if (_multi_isPass2) { + memcpy(temp_string, wrap_pointer2_pass, gTextInputCursorPosition - char_count2); + } else { + memcpy(temp_string, wrap_pointer2, gTextInputCursorPosition - char_count2); + } + int cur_x = w->x + 13 + gfx_get_string_width(temp_string); + + int width = 6; + if ((uint32)gTextInputCursorPosition < strlen(multi_text_input2)){ + // Make a new 1 character wide string for measuring the width + // of the character that the cursor is under. + temp_string[1] = '\0'; + temp_string[0] = multi_text_input2[gTextInputCursorPosition]; + width = max(gfx_get_string_width(temp_string) - 2, 4); + } + + if (w->frame_no > 15){ + uint8 colour = RCT2_ADDRESS(0x0141FC48, uint8)[w->colours[1] * 8]; + gfx_fill_rect(dpi, cur_x, y + 9, cur_x + width, y + 9, colour + 5); + } + + cur_drawn2++; + } + } + + wrap_pointer2 += string_length + 1; + + if (multi_text_input2[char_count2 + string_length] == ' ')char_count2++; + char_count2 += string_length; + + y += 10; + } +} + + +static void window_multi_text_input_text(int key, rct_window* w){ + + int text = key; + char new_char = platform_scancode_to_rct_keycode(0xFF & key); + + // If the return button is pressed stop text input + if (new_char == '\r'){ + if (inInput == 0){ + platform_stop_text_input(); + inInput = 1; + platform_start_text_input(multi_text_input2, _multi_maxInputLength2); + } else { + platform_stop_text_input(); + window_close(w); + rct_window* calling_w = window_find_by_number(multi_calling_class, multi_calling_number); + // Pass back the text that has been entered. + // ecx when none zero means text input success + if (calling_w) + window_event_textinput_call(calling_w, multi_calling_widget, multi_text_input, multi_text_input2); + } + } + + window_invalidate(w); +} + +void window_multi_text_input_update7() +{ + rct_window* w; + + window_get_register(w); + + rct_window* calling_w = window_find_by_number(multi_calling_class, multi_calling_number); + // If the calling window is closed then close the text + // input window. + if (!calling_w){ + window_close(w); + } + + // Used to blink the cursor. + w->frame_no++; + if (w->frame_no > 30) w->frame_no = 0; + window_invalidate(w); +} + +static void window_multi_text_input_close() +{ + // Make sure that we take it out of the text input + // mode otherwise problems may occur. + platform_stop_text_input(); +} + +static void window_multi_text_input_invalidate(){ + rct_window* w; + + window_get_register(w); + + // Work out the existing size of the window + char wrapped_string[512]; + char wrapped_string2[512]; + strcpy(wrapped_string, multi_text_input); + strcpy(wrapped_string2, multi_text_input2); + + int no_lines = 0, font_height = 0; + + // String length needs to add 12 either side of box + // +13 for cursor when max length. + gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height); + gfx_wrap_string(wrapped_string2, WW - (24 + 13), &no_lines, &font_height); + + int height = no_lines * 10 + WH; + + // Change window size if required. + if (height != w->height) { + window_invalidate(w); + window_set_resize(w, WW, height, WW, height); + } + + window_multi_text_input_widgets[WIDX_OKAY].top = height - 21; + window_multi_text_input_widgets[WIDX_OKAY].bottom = height - 10; + + window_multi_text_input_widgets[WIDX_CANCEL].top = height - 21; + window_multi_text_input_widgets[WIDX_CANCEL].bottom = height - 10; + + window_multi_text_input_widgets[WIDX_BACKGROUND].bottom = height - 1; +} \ No newline at end of file diff --git a/src/windows/twitch.c b/src/windows/twitch.c index 9d5c61ebb5..ca7eb66d45 100644 --- a/src/windows/twitch.c +++ b/src/windows/twitch.c @@ -23,6 +23,7 @@ #include "../sprites.h" #include "../interface/widget.h" #include "../interface/window.h" +#include "../config.h" enum window_twitch_WIDGET_IDX { WIDX_BACKGROUND, @@ -63,13 +64,13 @@ static void* window_twitch_events[] = { window_twitch_emptysub, window_twitch_emptysub, window_twitch_emptysub, + window_twitch_text_input, window_twitch_emptysub, window_twitch_emptysub, window_twitch_emptysub, window_twitch_emptysub, window_twitch_emptysub, - window_twitch_emptysub, - window_twitch_emptysub, + window_twitch_invalidate, window_twitch_paint, window_twitch_emptysub }; @@ -114,10 +115,15 @@ static void window_twitch_mouseup() window_widget_get_registers(w, widgetIndex); + utf8string testString = "test"; + switch (widgetIndex) { case WIDX_CLOSE: window_close(w); break; + case WIDX_TWITCH_AUTH: + window_multi_text_input_raw_open(w, widgetIndex, STR_TWITCH_AUTH, STR_TWITCH_NAME_DESC, gConfigTwitch.channel, 32, false, testString, 32, true); + break; } } @@ -140,9 +146,9 @@ static void window_twitch_paint() gfx_draw_sprite(dpi, SPR_G2_TAB_TWITCH, x, y, 0); - x = w->x + 280; - y = w->y + 315; + x = w->x + 300; + y = w->y + 230; - gfx_draw_string_left(dpi, STR_TWITCH_POWERDBY, NULL, 12, x, y); + gfx_draw_sprite(dpi, SPR_G2_PROMO_UL, x, y, 0); } From 68d8163fc109f7846e27aa7ae5b5e2fd9cfae6ce Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Mon, 1 Jun 2015 22:57:32 +0100 Subject: [PATCH 3/4] fix character pointer and prepare to send data back to window --- src/windows/multi_text_input.c | 6 +++--- src/windows/twitch.c | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/windows/multi_text_input.c b/src/windows/multi_text_input.c index b2192d5c94..b281a7c8a6 100644 --- a/src/windows/multi_text_input.c +++ b/src/windows/multi_text_input.c @@ -61,7 +61,7 @@ static void window_multi_text_input_emptysub(){} static void window_multi_text_input_mouseup(); static void window_multi_text_input_paint(); static void window_multi_text_input_text(int key, rct_window* w); -static void window_multi_text_input_update7(); +static void window_multi_text_input_update(); static void window_multi_text_input_close(); static void window_multi_text_input_invalidate(); @@ -74,7 +74,7 @@ static void* window_text_input_events[] = { window_multi_text_input_emptysub, window_multi_text_input_emptysub, window_multi_text_input_emptysub, - window_multi_text_input_update7, + window_multi_text_input_update, window_multi_text_input_emptysub, window_multi_text_input_emptysub, window_multi_text_input_emptysub, @@ -504,7 +504,7 @@ static void window_multi_text_input_text(int key, rct_window* w){ window_invalidate(w); } -void window_multi_text_input_update7() +void window_multi_text_input_update() { rct_window* w; diff --git a/src/windows/twitch.c b/src/windows/twitch.c index ca7eb66d45..803ddfddeb 100644 --- a/src/windows/twitch.c +++ b/src/windows/twitch.c @@ -29,7 +29,8 @@ enum window_twitch_WIDGET_IDX { WIDX_BACKGROUND, WIDX_TITLE, WIDX_CLOSE, - WIDX_TWITCH_AUTH + WIDX_TWITCH_AUTH, + WINDOW_TWITCH_WIDGETS_SIZE }; rct_widget window_twitch_widgets[] = { @@ -152,3 +153,16 @@ static void window_twitch_paint() gfx_draw_sprite(dpi, SPR_G2_PROMO_UL, x, y, 0); } + +static void window_twitch_invalidate() +{ + rct_window *w; + int i; + sint32 currentSoundDevice; + + window_get_register(w); + + for (i = WIDX_TWITCH_AUTH; i < WINDOW_TWITCH_WIDGETS_SIZE; i++) { + window_twitch_widgets[i].type = WWT_EMPTY; + } +} From 63808c2599e6ebbee90ba6f361c5e5a395592766 Mon Sep 17 00:00:00 2001 From: "Miso Zmiric (Mike Squinter)" Date: Tue, 2 Jun 2015 15:46:32 +0100 Subject: [PATCH 4/4] add stubs for twitch window text input event and window invalidate --- src/windows/twitch.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/windows/twitch.c b/src/windows/twitch.c index 803ddfddeb..4be14e916a 100644 --- a/src/windows/twitch.c +++ b/src/windows/twitch.c @@ -44,6 +44,8 @@ rct_widget window_twitch_widgets[] = { static void window_twitch_emptysub() { } static void window_twitch_mouseup(); static void window_twitch_paint(); +static void window_twitch_invalidate(); +static void window_twitch_text_input(); static void* window_twitch_events[] = { window_twitch_emptysub, @@ -154,15 +156,26 @@ static void window_twitch_paint() } +static void window_twitch_text_input(){ + short widgetIndex; + rct_window *w; + char _cl; + char* text; + + //just a stub +} + static void window_twitch_invalidate() { rct_window *w; int i; sint32 currentSoundDevice; + //just a stub + window_get_register(w); - for (i = WIDX_TWITCH_AUTH; i < WINDOW_TWITCH_WIDGETS_SIZE; i++) { + /*for (i = WIDX_TWITCH_AUTH; i < WINDOW_TWITCH_WIDGETS_SIZE; i++) { window_twitch_widgets[i].type = WWT_EMPTY; - } + }*/ }