コード例 #1
0
ファイル: buddy.c プロジェクト: pjbroad/other-life
static int display_accept_buddy(char *name)
{
	window_info *win = NULL;
	int label_id = 101, yes_button = 102, no_button = 103;
	char string[250] = {0};
	int current_window;

	for(current_window = 0; current_window < MAX_ACCEPT_BUDDY_WINDOWS; current_window++) {
		/* Find a free slot in the array */
		if(accept_windows[current_window].window_id == -1) {
			break;
		}
	}

	if (current_window >= MAX_ACCEPT_BUDDY_WINDOWS)
	{
		// uh oh, no free window
		return -1;
	}

	safe_snprintf(accept_windows[current_window].name, sizeof (accept_windows[current_window].name), "%s", name);

	accept_windows[current_window].window_id = create_window(buddy_accept_str, buddy_win, 0,
		buddy_menu_x_len/2, buddy_menu_y_len/4, 0, 0, (ELW_USE_UISCALE|ELW_WIN_DEFAULT) ^ ELW_CLOSE_BOX);
	set_window_handler(accept_windows[current_window].window_id, ELW_HANDLER_DISPLAY, &display_accept_buddy_handler);
	set_window_handler(accept_windows[current_window].window_id, ELW_HANDLER_UI_SCALE, &ui_scale_accept_handler );
	if (accept_windows[current_window].window_id <=0 || accept_windows[current_window].window_id >= windows_list.num_windows)
		return -1;
	win = &windows_list.window[accept_windows[current_window].window_id];

	/* Add text */
	safe_snprintf(string, sizeof(string), buddy_wants_to_add_str, accept_windows[current_window].name);
	accept_windows[current_window].text = malloc((strlen(string)+5)*sizeof(*accept_windows[current_window].text));

	/* Add checkbox if we don't have him/her in our list. */
	if(!is_in_buddylist(accept_windows[current_window].name))
	{
		accept_windows[current_window].checkbox = checkbox_add(win->window_id, NULL,
			0, 0, win->small_font_len_y, win->small_font_len_y, NULL);
		label_id = label_add_extended(win->window_id, label_id, NULL,
			0, 0, 0, win->current_scale * DEFAULT_SMALL_RATIO, -1, -1, -1, buddy_add_to_list_str);
		widget_set_OnClick(win->window_id, label_id, click_accept_checkbox_label);
	}

	/* Add buttons */
	yes_button = button_add_extended(win->window_id, yes_button, NULL,
		0, 0, 0, 0, 0, 1.0f, newcol_r, newcol_g, newcol_b, yes_str);
	no_button = button_add_extended(win->window_id, no_button, NULL,
		0, 0, 0, 0, 0, 1.0f, newcol_r, newcol_g, newcol_b, no_str);
	widget_set_OnClick(win->window_id, yes_button, click_accept_yes);
	widget_set_OnClick(win->window_id, no_button, click_accept_no);

	ui_scale_accept_handler(win);

	return win->window_id;
}
コード例 #2
0
ファイル: buddy.c プロジェクト: pjbroad/other-life
int display_buddy_add(void)
{
	if(buddy_add_win < 0)
	{
		int label_id = 100, input_id = 101, button_id = 102;
		window_info *win = NULL;
		int label_width = 0;
		int win_x_len = 0;
		int win_y_len = 0;

		/* Create the window */
		buddy_add_win = create_window(buddy_add_str, buddy_win, 0, buddy_menu_x_len/2, buddy_menu_y_len/4, 0, 0, ELW_USE_UISCALE|ELW_WIN_DEFAULT);
		if (buddy_add_win <=0 || buddy_add_win >= windows_list.num_windows)
			return -1;
		win = &windows_list.window[buddy_add_win];

		/* Add name input and label */
		label_id = label_add_extended(buddy_add_win, label_id, NULL,
			buddy_border_space, buddy_border_space, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_name_str);
		label_width = widget_get_width(buddy_add_win, label_id);
		input_id = pword_field_add_extended(buddy_add_win, input_id, NULL,
			2 * buddy_border_space + label_width, buddy_border_space,
			MAX_USERNAME_LENGTH * win->default_font_len_x, win->default_font_len_y + buddy_border_space,
			P_TEXT, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_name_buffer, MAX_USERNAME_LENGTH);
		widget_set_OnMouseover(buddy_add_win, label_id, name_onmouseover_handler);
		widget_set_OnMouseover(buddy_add_win, input_id, name_onmouseover_handler);
		widget_set_OnKey(buddy_add_win, input_id, name_input_keypress_handler);

		/* Add "Add buddy" button */
		button_id = button_add_extended(buddy_add_win, button_id, NULL, 0, 0, 0, 0, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_add_str);
		widget_set_OnClick(buddy_add_win, button_id, click_add_buddy_handler);

		/* Resize window and centre button */
		win_x_len = 3 * buddy_border_space + label_width + widget_get_width(buddy_add_win, input_id) + win->box_size;
		win_y_len = 3 * buddy_border_space + widget_get_height(buddy_add_win, input_id) + widget_get_height(buddy_add_win, button_id);
		resize_window(buddy_add_win, win_x_len, win_y_len);
		widget_move(buddy_add_win, button_id, (win_x_len - widget_get_width(buddy_add_win, button_id)) / 2, 3 * buddy_border_space + win->default_font_len_y);

		return buddy_add_win;
	}
	else
	{
		toggle_window(buddy_add_win);
		return buddy_add_win;
	}
}
コード例 #3
0
ファイル: knowledge.c プロジェクト: raduprv/Eternal-Lands
void fill_knowledge_win (int window_id)
{
	set_window_handler(window_id, ELW_HANDLER_DISPLAY, &display_knowledge_handler );
	set_window_handler(window_id, ELW_HANDLER_CLICK, &click_knowledge_handler );
	set_window_handler(window_id, ELW_HANDLER_MOUSEOVER, &mouseover_knowledge_handler );
	set_window_handler(window_id, ELW_HANDLER_RESIZE, &resize_knowledge_handler );

	knowledge_scroll_id = vscrollbar_add_extended (window_id, knowledge_scroll_id, NULL, 0,  0, 0, 0, 0, 1.0, 0.77f, 0.57f, 0.39f, 0, 1, (knowledge_count+1)/2-displayed_book_rows);
	knowledge_book_image_id = add_knowledge_book_image(window_id);
	widget_set_OnClick(window_id, knowledge_book_image_id, &handle_knowledge_book);
	knowledge_book_label_id = label_add_extended(window_id, knowledge_book_image_id + 1, NULL, 0, 0, WIDGET_DISABLED, 0.8, 1.0, 1.0, 1.0, knowledge_read_book);
	widget_set_OnClick(window_id, knowledge_book_label_id, &handle_knowledge_book);

	if (cm_valid(!cm_know_id))
	{
		cm_know_id = cm_create(know_highlight_cm_str, cm_knowledge_handler);
		cm_add_window(cm_know_id, window_id);
		init_ipu(&ipu_know, -1, 1, 1, 1, NULL, NULL);
	}
}
コード例 #4
0
ファイル: buddy.c プロジェクト: pjbroad/other-life
static int display_buddy_change(_buddy *buddy)
{
	int label_id = 100, name_id = 101, type_label_id = 102, checkbox_id = 103, checkbox_label_id = 104, change_button_id = 105;
	int buddy_change_x_len = 0;
	int buddy_change_y_len = 0;
	window_info *win = NULL;
	int tmp_width = 0;

	buddy_to_change = buddy->name;
	if(buddy_change_win >= 0) {
		/* Destroy the window to make sure everything's set up. */
		destroy_window(buddy_change_win);
		buddy_change_win = -1;
		buddy_delete = 0;
	}

	/* Create the window */
	buddy_change_win = create_window(buddy_change_str, buddy_win, 0, buddy_menu_x_len/2, buddy_menu_y_len/4, 0, 0, ELW_USE_UISCALE|ELW_WIN_DEFAULT);
	if (buddy_change_win <=0 || buddy_change_win >= windows_list.num_windows)
		return -1;
	win = &windows_list.window[buddy_change_win];

	/* Add name label and name */
	label_id = label_add_extended(buddy_change_win, label_id, NULL,
		buddy_border_space, buddy_border_space, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_name_str);
	tmp_width = widget_get_width(buddy_change_win, label_id);
	name_id = label_add_extended(buddy_change_win, name_id, NULL,
		2 * buddy_border_space + tmp_width, buddy_border_space, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_to_change);

	buddy_change_x_len = 3 * buddy_border_space + tmp_width + MAX_USERNAME_LENGTH * win->default_font_len_x + win->box_size;
	buddy_change_y_len = 2 * buddy_border_space + widget_get_height(buddy_change_win, name_id);

	buddy_type_input_id = -1;
	if (buddy->type < 0xFE)
	{
		size_t i;
		const size_t num_type_labels = 5;
		char * type_labels_text[] = {buddy_white_str, buddy_red_str, buddy_green_str, buddy_blue_str, buddy_yellow_str};

		/* Add type label and input widget */
		type_label_id = label_add_extended(buddy_change_win, type_label_id, NULL,
			buddy_border_space, buddy_change_y_len, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_type_str);
		tmp_width = widget_get_width(buddy_change_win, type_label_id);

		buddy_type_input_id = multiselect_add(buddy_change_win, NULL,
			2 * buddy_border_space + tmp_width, buddy_change_y_len, buddy_change_x_len - tmp_width - 3 * buddy_border_space);
		for (i=0; i<num_type_labels; i++)
			multiselect_button_add_extended(buddy_change_win, buddy_type_input_id,
				0, i * 25 * win->current_scale, 0, type_labels_text[i], DEFAULT_SMALL_RATIO * win->current_scale, i==0);
		multiselect_set_selected(buddy_change_win, buddy_type_input_id, buddy->type);

		widget_set_OnMouseover(buddy_change_win, label_id, type_onmouseover_handler);
		widget_set_OnMouseover(buddy_change_win, buddy_type_input_id, type_onmouseover_handler);

		if ((3 * buddy_border_space + tmp_width + widget_get_width(buddy_change_win, buddy_type_input_id)) > buddy_change_x_len)
			buddy_change_x_len = 3 * buddy_border_space + tmp_width + widget_get_width(buddy_change_win, buddy_type_input_id);
		buddy_change_y_len += buddy_border_space + multiselect_get_height(buddy_change_win, buddy_type_input_id);
	}

	/* Delete buddy checkbox and label */
	checkbox_id = checkbox_add(buddy_change_win, NULL, 0, 0, win->default_font_len_y, win->default_font_len_y, &buddy_delete);
	checkbox_label_id = label_add_extended(buddy_change_win, checkbox_label_id, NULL,
		0, 0, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_delete_str);
	widget_set_OnClick(buddy_change_win, checkbox_label_id, click_delete_checkbox_label);
	widget_set_OnMouseover(buddy_change_win, checkbox_label_id, delete_onmouseover_handler);
	tmp_width = widget_get_width(buddy_change_win, checkbox_id) + buddy_border_space + widget_get_width(buddy_change_win, checkbox_label_id);
	widget_move(buddy_change_win, checkbox_id, (buddy_change_x_len - tmp_width) / 2, buddy_change_y_len);
	widget_move(buddy_change_win, checkbox_label_id,
		buddy_change_x_len - ((buddy_change_x_len - tmp_width) / 2) - widget_get_width(buddy_change_win, checkbox_label_id), buddy_change_y_len);
	buddy_change_y_len += buddy_border_space + widget_get_height(buddy_change_win, checkbox_id);

	/* Change button */
	change_button_id = button_add_extended(buddy_change_win, change_button_id, NULL,
		0, 0, 0, 0, 0, win->current_scale, newcol_r, newcol_g, newcol_b, buddy_change_str);
	widget_set_OnClick(buddy_change_win, change_button_id, click_change_buddy_handler);
	widget_move(buddy_change_win, change_button_id,
		(buddy_change_x_len - widget_get_width(buddy_change_win, change_button_id)) / 2, buddy_change_y_len);
	buddy_change_y_len += buddy_border_space + widget_get_height(buddy_change_win, change_button_id);

	resize_window(buddy_change_win, buddy_change_x_len, buddy_change_y_len);

	return buddy_change_win;
}