Exemple #1
0
static void window_player_list_scrollmousedown(rct_window *w, int scrollIndex, int x, int y)
{
	if (network_get_mode() != NETWORK_MODE_SERVER) {
		return;
	}

	int index;

	index = y / 10;
	if (index >= w->no_list_items)
		return;

	w->selected_list_item = index;
	window_invalidate(w);

	rct_widget *listWidget = &w->widgets[WIDX_LIST];
	int ddx = w->x + listWidget->left + x;
	int ddy = w->y + listWidget->top + y;

	if (index == 0) {
		return;
	}
	_dropdownPlayerId = network_get_player_id(index);
	if (_dropdownPlayerId == network_get_current_player_id()) {
		return;
	}

	gDropdownItemsFormat[0] = STR_KICK_PLAYER;
	window_dropdown_show_text(ddx, ddy, 0, 7, 0, 1);
}
Exemple #2
0
void network_attach_image(unsigned int unit, const char *filename)
{
    unsigned int control = NETWORK_CONTROL_DEVC;

    if (network_get_mode() == NETWORK_CLIENT)
        control <<= NETWORK_CONTROL_CLIENTOFFSET;

    if ((control & network_control) == 0)
        return;

    event_record_attach_in_list(&(frame_event_list[current_frame]), unit, filename, 1);
}
Exemple #3
0
static void netplay_update_status(void)
{
    gchar *text = NULL;
    const char *server_name;
    const char *server_bind_address;
    int port;
    char st[256];

    switch(network_get_mode()) {
        case NETWORK_IDLE:
            gtk_widget_set_sensitive(GTK_WIDGET(dcb), FALSE);
            gtk_widget_set_sensitive(GTK_WIDGET(ctrls), TRUE);
            text = _("Idle");
            break;
        case NETWORK_SERVER:
            gtk_widget_set_sensitive(GTK_WIDGET(dcb), TRUE);
            gtk_widget_set_sensitive(GTK_WIDGET(ctrls), FALSE);
            text = _("Server listening");
            break;
        case NETWORK_SERVER_CONNECTED:
            gtk_widget_set_sensitive(GTK_WIDGET(dcb), TRUE);
            gtk_widget_set_sensitive(GTK_WIDGET(ctrls), FALSE);
            text = _("Connected server");
            break;
        case NETWORK_CLIENT:
            gtk_widget_set_sensitive(GTK_WIDGET(dcb), TRUE);
            gtk_widget_set_sensitive(GTK_WIDGET(ctrls), FALSE);
            text = _("Connected client");
            break;
        default:
            break;
    }
    gtk_label_set_text(GTK_LABEL(current_mode), text);

    resources_get_int("NetworkServerPort", &port);
    resources_get_string("NetworkServerName", &server_name);
    resources_get_string("NetworkServerBindAddress", &server_bind_address);
    snprintf(st, 256, "%d", port);
    gtk_entry_set_text(GTK_ENTRY(np_port), st);
    gtk_entry_set_text(GTK_ENTRY(np_server), server_name);
    gtk_entry_set_text(GTK_ENTRY(np_server_bind), server_bind_address);
    log_message(np_log, "Status: %s, Server: %s, Port: %d; server bind address: %s", text, server_name, port, server_bind_address);
    netplay_update_control_gui();
}
Exemple #4
0
void chat_draw()
{
	if (network_get_mode() == NETWORK_MODE_NONE || network_get_status() != NETWORK_STATUS_CONNECTED || network_get_authstatus() != NETWORK_AUTH_OK) {
		gChatOpen = false;
		return;
	}
	rct_drawpixelinfo *dpi = (rct_drawpixelinfo*)RCT2_ADDRESS_SCREEN_DPI;
	_chatLeft = 10;
	_chatTop = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 40 - ((CHAT_HISTORY_SIZE + 1) * 10);
	_chatRight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - 10;
	_chatBottom = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 45;
	char lineBuffer[CHAT_INPUT_SIZE + 10];
	char* lineCh = lineBuffer;
	int x = _chatLeft;
	int y = _chatBottom - (15 * 2);
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0;
	for (int i = 0; i < CHAT_HISTORY_SIZE; i++, y -= 15) {
		if (!gChatOpen && SDL_TICKS_PASSED(SDL_GetTicks(), chat_history_get_time(i) + 10000)) {
			break;
		}
		safe_strcpy(lineBuffer, chat_history_get(i), CHAT_INPUT_SIZE + 10);
		gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer), y + 12);
		gfx_draw_string(dpi, lineBuffer, 255, x, y);
	}
	if (gChatOpen) {
		lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
		lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
		safe_strcpy(lineCh, _chatCurrentLine, CHAT_INPUT_SIZE);
		y = _chatBottom - 15;
		gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer) + 7, y + 12);
		gfx_draw_string(dpi, lineBuffer, 255, x, y);
		if (_chatCaretTicks < 15) {
			memcpy(lineBuffer, _chatCurrentLine, gTextInput.selection_offset);
			lineBuffer[gTextInput.selection_offset] = 0;
			int caretX = x + gfx_get_string_width(lineBuffer);
			int caretY = y + 15;

			gfx_fill_rect(dpi, caretX, caretY, caretX + 6, caretY + 1, 0x38);
		}
	}
}
Exemple #5
0
void network_event_record(unsigned int type, void *data, unsigned int size)
{
    unsigned int control = 0;
    BYTE joyport;

    switch (type) {
      case EVENT_KEYBOARD_MATRIX:
      case EVENT_KEYBOARD_RESTORE:
      case EVENT_KEYBOARD_DELAY:
      case EVENT_KEYBOARD_CLEAR:
        control = NETWORK_CONTROL_KEYB;
        break;
      case EVENT_ATTACHDISK:
      case EVENT_ATTACHTAPE:
      case EVENT_DATASETTE:
        control = NETWORK_CONTROL_DEVC;
        break;
      case EVENT_RESOURCE:
      case EVENT_RESETCPU:
        control = NETWORK_CONTROL_RSRC;
        break;
      case EVENT_JOYSTICK_VALUE:
        joyport = ((BYTE*)data)[0];
        if (joyport == 1) 
            control = NETWORK_CONTROL_JOY1;
        if (joyport == 2) 
            control = NETWORK_CONTROL_JOY2;
        break;
      default:
        control = 0;
    }

    if (network_get_mode() == NETWORK_CLIENT)
        control <<= NETWORK_CONTROL_CLIENTOFFSET;

    if (control != 0 && (control & network_control) == 0)
        return;

    event_record_in_list(&(frame_event_list[current_frame]), type, data, size);
}
Exemple #6
0
static APTR build_gui(void)
{
    APTR app, ui, mode, start_server, connect_to, disconnect, cancel, bind_server;

    app = mui_get_app();

    ui = GroupObject,
           Child, mode = StringObject,
             MUIA_Frame, MUIV_Frame_String,
             MUIA_FrameTitle, translate_text(IDS_CURRENT_MODE),
           End,
           Child, GroupObject,
             MUIA_Frame, MUIV_Frame_Group,
             MUIA_Group_Horiz, TRUE,
             Child, ui_to_from[0].object = StringObject,
               MUIA_Frame, MUIV_Frame_String,
               MUIA_FrameTitle, translate_text(IDS_TCP_PORT),
               MUIA_String_Accept, "0123456789",
               MUIA_String_MaxLen, 5+1,
             End,
             Child, start_server = TextObject,
               ButtonFrame,
               MUIA_Background, MUII_ButtonBack,
               MUIA_Text_Contents, translate_text(IDS_START_SERVER),
               MUIA_Text_PreParse, "\033c",
               MUIA_InputMode, MUIV_InputMode_RelVerify,
             End,
           End,
           Child, GroupObject,
             MUIA_Frame, MUIV_Frame_Group,
             MUIA_Group_Horiz, TRUE,
             Child, bind_server = TextObject,
               ButtonFrame,
               MUIA_Background, MUII_ButtonBack,
               MUIA_Text_Contents, translate_text(IDS_SERVER_BIND),
               MUIA_Text_PreParse, "\033c",
               MUIA_InputMode, MUIV_InputMode_RelVerify,
             End,
             Child, ui_to_from[1].object = StringObject,
               MUIA_Frame, MUIV_Frame_String,
               MUIA_String_Accept, ".0123456789",
               MUIA_String_MaxLen, 15+1,
             End,
           End,
           Child, GroupObject,
             MUIA_Frame, MUIV_Frame_Group,
             MUIA_Group_Horiz, TRUE,
             Child, connect_to = TextObject,
               ButtonFrame,
               MUIA_Background, MUII_ButtonBack,
               MUIA_Text_Contents, translate_text(IDS_CONNECT_TO),
               MUIA_Text_PreParse, "\033c",
               MUIA_InputMode, MUIV_InputMode_RelVerify,
             End,
             Child, ui_to_from[2].object = StringObject,
               MUIA_Frame, MUIV_Frame_String,
               MUIA_String_Accept, ".0123456789",
               MUIA_String_MaxLen, 15+1,
             End,
           End,
           Child, GroupObject,
             MUIA_Frame, MUIV_Frame_Group,
             MUIA_Group_Horiz, TRUE,
             Child, disconnect = TextObject,
               ButtonFrame,
               MUIA_Background, MUII_ButtonBack,
               MUIA_Text_Contents, translate_text(IDS_DISCONNECT),
               MUIA_Text_PreParse, "\033c",
               MUIA_InputMode, MUIV_InputMode_RelVerify,
             End,
             Child, cancel = TextObject,
               ButtonFrame,
               MUIA_Background, MUII_ButtonBack,
               MUIA_Text_Contents, translate_text(IDS_CANCEL),
               MUIA_Text_PreParse, "\033c",
               MUIA_InputMode, MUIV_InputMode_RelVerify,
             End,
           End,
         End;

    if (ui != NULL) {
        DoMethod(start_server, MUIM_Notify, MUIA_Pressed, FALSE,
                 app, 2, MUIM_Application_ReturnID, BTN_START_SERVER);

        DoMethod(connect_to, MUIM_Notify, MUIA_Pressed, FALSE,
                 app, 2, MUIM_Application_ReturnID, BTN_CONNECT_TO);

        DoMethod(disconnect, MUIM_Notify, MUIA_Pressed, FALSE,
                 app, 2, MUIM_Application_ReturnID, BTN_DISCONNECT);

        DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE,
                 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

        switch(network_get_mode()) {
            case NETWORK_IDLE:
                set(mode, MUIA_String_Contents, translate_text(IDS_IDLE));
                break;
            case NETWORK_SERVER:
                set(mode, MUIA_String_Contents, translate_text(IDS_SERVER_LISTENING));
                break;
            case NETWORK_SERVER_CONNECTED:
                set(mode, MUIA_String_Contents, translate_text(IDS_CONNECTED_SERVER));
                break;
            case NETWORK_CLIENT:
                set(mode, MUIA_String_Contents, translate_text(IDS_CONNECTED_CLIENT));
                break;
        }
    }

    return ui;
}
Exemple #7
0
bool chat_available()
{
    return network_get_mode() != NETWORK_MODE_NONE && network_get_status() == NETWORK_STATUS_CONNECTED
        && network_get_authstatus() == NETWORK_AUTH_OK;
}
Exemple #8
0
void chat_draw(rct_drawpixelinfo * dpi)
{
    if (network_get_mode() == NETWORK_MODE_NONE || network_get_status() != NETWORK_STATUS_CONNECTED || network_get_authstatus() != NETWORK_AUTH_OK) {
        gChatOpen = false;
        return;
    }

    _chatLeft = 10;
    _chatRight = std::min((context_get_width() - 10), CHAT_MAX_WINDOW_WIDTH);
    _chatWidth = _chatRight - _chatLeft;
    _chatBottom = context_get_height() - 45;
    _chatTop = _chatBottom - 10;

    char lineBuffer[CHAT_INPUT_SIZE + 10];
    char* lineCh = lineBuffer;
    char* inputLine = _chatCurrentLine;
    sint32 inputLineHeight = 10;
    uint8 chatBackgroundColor = theme_get_colour(WC_CHAT, 0);

    // Draw chat window
    if (gChatOpen) {
        inputLineHeight = chat_string_wrapped_get_height((void*)&inputLine, _chatWidth - 10);
        _chatTop -= inputLineHeight;

        for (sint32 i = 0; i < CHAT_HISTORY_SIZE; i++) {
            if (strlen(chat_history_get(i)) == 0) {
                continue;
            }

            safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer));

            sint32 lineHeight = chat_string_wrapped_get_height((void*)&lineCh, _chatWidth - 10);
            _chatTop -= (lineHeight + 5);
        }

        _chatHeight = _chatBottom - _chatTop;

        if (_chatTop < 50) {
            _chatTop = 50;
        } else if (_chatHeight < 150) { // Min height
            _chatTop = _chatBottom - 150;
            _chatHeight = 150;
        }

        gfx_set_dirty_blocks(_chatLeft, _chatTop - 5, _chatRight, _chatBottom + 5); // Background area + Textbox
        gfx_filter_rect(dpi, _chatLeft, _chatTop - 5, _chatRight, _chatBottom + 5, PALETTE_51); // Opaque gray background
        gfx_fill_rect_inset(dpi, _chatLeft, _chatTop - 5, _chatRight, _chatBottom + 5, chatBackgroundColor, INSET_RECT_FLAG_FILL_NONE);
        gfx_fill_rect_inset(dpi, _chatLeft + 1, _chatTop - 4, _chatRight - 1, _chatBottom - inputLineHeight - 6, chatBackgroundColor, INSET_RECT_FLAG_BORDER_INSET);
        gfx_fill_rect_inset(dpi, _chatLeft + 1, _chatBottom - inputLineHeight - 5, _chatRight - 1, _chatBottom + 4, chatBackgroundColor, INSET_RECT_FLAG_BORDER_INSET); // Textbox
    }

    sint32 x = _chatLeft + 5;
    sint32 y = _chatBottom - inputLineHeight - 20;
    sint32 stringHeight = 0;

    // Draw chat history
    for (sint32 i = 0; i < CHAT_HISTORY_SIZE; i++, y -= stringHeight) {
        uint32 expireTime = chat_history_get_time(i) + 10000;
        if (!gChatOpen && platform_get_ticks() > expireTime) {
            break;
        }

        safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer));

        stringHeight = chat_history_draw_string(dpi, (void*) &lineCh, x, y, _chatWidth - 10) + 5;
        gfx_set_dirty_blocks(x, y - stringHeight, x + _chatWidth, y + 20);

        if ((y - stringHeight) < 50) {
            break;
        }
    }

    // Draw current chat input
    if (gChatOpen) {
        lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
        lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);

        safe_strcpy(lineCh, _chatCurrentLine, sizeof(_chatCurrentLine));
        y = _chatBottom - inputLineHeight - 5;

        lineCh = lineBuffer;
        inputLineHeight = gfx_draw_string_left_wrapped(dpi, (void*)&lineCh, x, y + 3, _chatWidth - 10, STR_STRING, TEXT_COLOUR_255);
        gfx_set_dirty_blocks(x, y, x + _chatWidth, y + inputLineHeight + 15);

        // TODO: Show caret if the input text has multiple lines
        if (_chatCaretTicks < 15 && gfx_get_string_width(lineBuffer) < (_chatWidth - 10)) {
            memcpy(lineBuffer, _chatCurrentLine, _chatTextInputSession->SelectionStart);
            lineBuffer[_chatTextInputSession->SelectionStart] = 0;
            sint32 caretX = x + gfx_get_string_width(lineBuffer);
            sint32 caretY = y + 14;

            gfx_fill_rect(dpi, caretX, caretY, caretX + 6, caretY + 1, PALETTE_INDEX_56);
        }
    }
}