You've already forked OpenRCT2-Unity
mirror of
https://github.com/izzy2lost/OpenRCT2-Unity.git
synced 2026-03-10 12:38:22 -07:00
Trying out a new technique for text input
This commit is contained in:
@@ -128,6 +128,7 @@
|
||||
<ClCompile Include="..\src\windows\staff_fire_prompt.c" />
|
||||
<ClCompile Include="..\src\windows\staff_list.c" />
|
||||
<ClCompile Include="..\src\windows\staff.c" />
|
||||
<ClCompile Include="..\src\windows\text_input.c" />
|
||||
<ClCompile Include="..\src\windows\title_exit.c" />
|
||||
<ClCompile Include="..\src\windows\title_logo.c" />
|
||||
<ClCompile Include="..\src\windows\title_menu.c" />
|
||||
|
||||
@@ -425,6 +425,9 @@
|
||||
<ClCompile Include="..\src\windows\viewport.c">
|
||||
<Filter>Source\Windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\windows\text_input.c">
|
||||
<Filter>Source\Windows</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\management\award.h">
|
||||
|
||||
13
src/input.c
13
src/input.c
@@ -1623,8 +1623,17 @@ void game_handle_keyboard_input()
|
||||
set_shortcut(key);
|
||||
else if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) == 1)
|
||||
tutorial_stop();
|
||||
else
|
||||
handle_shortcut(key);
|
||||
else{
|
||||
w = window_find_by_id(113, 0);
|
||||
if (w != NULL){
|
||||
void(*fp)(int, rct_window*) = (void*)(int)w->event_handlers[WE_TEXT_INPUT];
|
||||
(*fp)(key,w);
|
||||
}
|
||||
else{
|
||||
handle_shortcut(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) == 0)
|
||||
|
||||
@@ -509,6 +509,7 @@ void window_music_credits_open();
|
||||
void window_publisher_credits_open();
|
||||
void window_track_manage_open();
|
||||
void window_viewport_open();
|
||||
void window_text_input_open();
|
||||
|
||||
void window_guest_list_init_vars_a();
|
||||
void window_guest_list_init_vars_b();
|
||||
|
||||
@@ -469,6 +469,8 @@ void window_staff_overview_mouseup()
|
||||
window_staff_fire_prompt_open(peep);
|
||||
break;
|
||||
case WIDX_RENAME:
|
||||
window_text_input_open();
|
||||
break;
|
||||
window_show_textinput(w, (int)widgetIndex, 2977, 2978, peep->name_string_idx);
|
||||
break;
|
||||
}
|
||||
|
||||
150
src/windows/text_input.c
Normal file
150
src/windows/text_input.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014 Ted John, Duncan Frost
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../addresses.h"
|
||||
#include "../config.h"
|
||||
#include "../platform/osinterface.h"
|
||||
#include "../interface/window.h"
|
||||
#include "../interface/widget.h"
|
||||
#include "../localisation/localisation.h"
|
||||
|
||||
#define WW 250
|
||||
#define WH 60
|
||||
|
||||
enum WINDOW_TEXT_INPUT_WIDGET_IDX {
|
||||
WIDX_BACKGROUND,
|
||||
WIDX_TITLE,
|
||||
WIDX_CLOSE,
|
||||
};
|
||||
|
||||
// 0x9DE4E0
|
||||
static rct_widget window_text_input_widgets[] = {
|
||||
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE },
|
||||
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_OPTIONS, STR_WINDOW_TITLE_TIP },
|
||||
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP },
|
||||
{ WIDGETS_END }
|
||||
};
|
||||
|
||||
static void window_text_input_emptysub(){}
|
||||
static void window_text_input_mouseup();
|
||||
static void window_text_input_paint();
|
||||
static void window_text_input_text(int key);
|
||||
|
||||
//0x9A3F7C
|
||||
static void* window_text_input_events[] = {
|
||||
window_text_input_emptysub,
|
||||
window_text_input_mouseup,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_text,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_emptysub,
|
||||
window_text_input_paint,
|
||||
window_text_input_emptysub
|
||||
};
|
||||
|
||||
void window_text_input_open(){
|
||||
window_close_by_id(113, 0);
|
||||
|
||||
rct_window* w = window_create_auto_pos(WW, WH, (uint32*)window_text_input_events, 113, 0);
|
||||
w->frame_no = 0;
|
||||
w->widgets = window_text_input_widgets;
|
||||
w->enabled_widgets = (1 << 2);
|
||||
window_init_scroll_widgets(w);
|
||||
w->colours[0] = 7;
|
||||
w->colours[1] = 7;
|
||||
w->colours[2] = 7;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006E3AE0
|
||||
*/
|
||||
static void window_text_input_mouseup(){
|
||||
short widgetIndex;
|
||||
rct_window *w;
|
||||
|
||||
window_widget_get_registers(w, widgetIndex);
|
||||
|
||||
switch (widgetIndex){
|
||||
case WIDX_CLOSE:
|
||||
window_close(w);
|
||||
}
|
||||
}
|
||||
char test_text[100] = { 0 };
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006E3A9F
|
||||
*/
|
||||
static void window_text_input_paint(){
|
||||
rct_window *w;
|
||||
rct_drawpixelinfo *dpi;
|
||||
|
||||
window_paint_get_registers(w, dpi);
|
||||
|
||||
window_draw_widgets(w, dpi);
|
||||
|
||||
int x = w->x + 4;
|
||||
int y = w->y + 30;
|
||||
|
||||
gfx_draw_string(dpi, test_text, w->colours[1], x, y);
|
||||
}
|
||||
|
||||
|
||||
static void window_text_input_text(int key, rct_window* w){
|
||||
|
||||
int text = key;
|
||||
char new_char = osinterface_scancode_to_rct_keycode(0xFF&key);
|
||||
// If the shift key is held
|
||||
if (!(key & 0x100)) new_char = tolower(new_char);
|
||||
|
||||
if (new_char == '\b'){
|
||||
if (w->frame_no != 0)
|
||||
test_text[--w->frame_no] = '\0';
|
||||
}
|
||||
else if (new_char == '\r'){
|
||||
window_close(w);
|
||||
}
|
||||
else if (isprint(new_char)){
|
||||
if (w->frame_no != 100)
|
||||
test_text[w->frame_no++] = new_char;
|
||||
}
|
||||
|
||||
window_invalidate(w);
|
||||
}
|
||||
Reference in New Issue
Block a user