コード例 #1
0
	void gui_element::draw_tooltip_from_hover_or_world_highlight(vertex_triangle_buffer& output_buffer, const viewing_gui_context& context, const vec2i tooltip_pos) const {
		const auto& rect_world = context.get_rect_world();
		auto& step = context.get_step();
		const auto& cosmos = step.get_cosmos();

		const auto maybe_hovered_item = context._dynamic_cast<item_button_in_item>(rect_world.rect_hovered);
		const auto maybe_hovered_slot = context._dynamic_cast<slot_button_in_container>(rect_world.rect_hovered);
		const auto maybe_hovered_hotbar_button = context._dynamic_cast<hotbar_button_in_gui_element>(rect_world.rect_hovered);

		gui::text::fstr tooltip_text;

		const auto description_style = text::style(assets::font_id::GUI_FONT, vslightgray);

		if (maybe_hovered_item) {
			tooltip_text = text::simple_bbcode(describe_entity(cosmos[maybe_hovered_item.get_location().item_id]), description_style);
		}
		else if (maybe_hovered_slot) {
			tooltip_text = text::simple_bbcode(describe_slot(cosmos[maybe_hovered_slot.get_location().slot_id]), text::style());
		}
		else if (maybe_hovered_hotbar_button) {
			const auto assigned_entity = maybe_hovered_hotbar_button->get_assigned_entity(context.get_gui_element_entity());

			if (assigned_entity.alive()) {
				tooltip_text = text::simple_bbcode(describe_entity(assigned_entity), description_style);
			}
			else {
				tooltip_text = text::format(L"Empty slot", description_style);
			}
		}
		else {
			const auto hovered = cosmos[get_hovered_world_entity(cosmos, step.camera.transform.pos + rect_world.last_state.mouse.pos - step.camera.visible_world_area / 2)];

			if (hovered.alive()) {
				step.session.world_hover_highlighter.update(step.get_delta().in_milliseconds());
				step.session.world_hover_highlighter.draw(step, hovered);

				tooltip_text = text::simple_bbcode(describe_entity(hovered), text::style(assets::font_id::GUI_FONT, vslightgray));
			}
		}

		if (tooltip_text.size() > 0) {
			augs::gui::text_drawer description_drawer;
			description_drawer.set_text(tooltip_text);

			const auto tooltip_rect = ltrbi(tooltip_pos, description_drawer.get_bbox()).snap_to_bounds(ltrb(vec2(0, 0), get_screen_size()));

			augs::draw_rect_with_border(
				output_buffer,
				tooltip_rect,
				{ 0, 0, 0, 120 }, 
				slightly_visible_white
			);

			description_drawer.pos = tooltip_rect.get_position();
			description_drawer.draw(output_buffer);
		}
	}
コード例 #2
0
void slot_button::draw(const viewing_gui_context& context, const const_this_in_container& this_id, augs::gui::draw_info info) {
	if (!this_id->get_flag(augs::gui::flag::ENABLE_DRAWING)) {
		return;
	}

	const auto& step = context.get_step();
	const auto& cosmos = step.get_cosmos();

	const auto slot_id = cosmos[this_id.get_location().slot_id];
	const bool is_hand_slot = slot_id.is_hand_slot();
	const auto& detector = this_id->detector;

	rgba inside_col, border_col;
	
	if (slot_id->for_categorized_items_only) {
		inside_col = violet;
	}
	else {
		inside_col = cyan;
	}

	border_col = inside_col;
	inside_col.a = 4 * 5;
	border_col.a = 220;

	if (detector.is_hovered || detector.current_appearance == augs::gui::appearance_detector::appearance::pushed) {
		inside_col.a = 12 * 5;
		border_col.a = 255;
	}

	const auto inside_tex = assets::texture_id::ATTACHMENT_CIRCLE_FILLED;
	const auto border_tex = assets::texture_id::ATTACHMENT_CIRCLE_BORDER;

	const augs::gui::material inside_mat(inside_tex, inside_col);
	const augs::gui::material border_mat(border_tex, border_col);

	if (slot_id->always_allow_exactly_one_item) {
		draw_centered_texture(context, this_id, info, inside_mat);
		draw_centered_texture(context, this_id, info, border_mat);

		const auto slot_type = slot_id.get_id().type;

		if (slot_type == slot_function::PRIMARY_HAND) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::PRIMARY_HAND_ICON, border_col), vec2i(1, 0));
		}

		if (slot_type == slot_function::SECONDARY_HAND) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::SECONDARY_HAND_ICON, border_col));
		}

		if (slot_type == slot_function::SHOULDER_SLOT) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::SHOULDER_SLOT_ICON, border_col));
		}

		if (slot_type == slot_function::TORSO_ARMOR_SLOT) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::ARMOR_SLOT_ICON, border_col));
		}

		if (slot_type == slot_function::GUN_CHAMBER) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::CHAMBER_SLOT_ICON, border_col));
		}

		if (slot_type == slot_function::GUN_MUZZLE) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::GUN_MUZZLE_SLOT_ICON, border_col));
		}

		if (slot_type == slot_function::GUN_DETACHABLE_MAGAZINE) {
			draw_centered_texture(context, this_id, info, augs::gui::material(assets::texture_id::DETACHABLE_MAGAZINE_ICON, border_col));
		}
	}
	else {
		draw_centered_texture(context, this_id, info, inside_mat);
		draw_centered_texture(context, this_id, info, border_mat);

		const auto space_available_text = augs::gui::text::format(to_wstring(slot_id.calculate_free_space_with_parent_containers() / long double(SPACE_ATOMS_PER_UNIT), 2, true)
			, augs::gui::text::style(assets::font_id::GUI_FONT, border_col));

		augs::gui::text_drawer space_caption;
		space_caption.set_text(space_available_text);
		space_caption.center(context.get_tree_entry(this_id).get_absolute_rect());
		space_caption.draw(info);

		draw_children(context, this_id, info);
	}

	if (slot_id.get_container().get_owning_transfer_capability() != slot_id.get_container()) {
		const_dereferenced_location<item_button_in_item> child_item_button 
			= context.dereference_location(item_button_in_item{ slot_id.get_container().get_id() });

		draw_pixel_line_connector(context.get_tree_entry(this_id).get_absolute_rect(), context.get_tree_entry(child_item_button).get_absolute_rect(), info, border_col);
	}
}
コード例 #3
0
	void gui_element::draw_cursor_with_information(vertex_triangle_buffer& output_buffer, const viewing_gui_context& context) const {
		auto gui_cursor = assets::texture_id::GUI_CURSOR;
		auto gui_cursor_color = cyan;
		auto gui_cursor_position = get_gui_crosshair_position();

		auto get_tooltip_position = [&]() {
			return get_gui_crosshair_position() + (*gui_cursor).get_size();
		};

		auto draw_cursor_hint = [&output_buffer, this](const auto& hint_text, const vec2i cursor_position, const vec2i cursor_size) {
			vec2i bg_sprite_size;

			augs::gui::text_drawer drop_hint_drawer;

			drop_hint_drawer.set_text(gui::text::format(std::wstring(hint_text), gui::text::style()));

			bg_sprite_size.set(drop_hint_drawer.get_bbox());
			bg_sprite_size.y = std::max(cursor_size.y, drop_hint_drawer.get_bbox().y);
			bg_sprite_size.x += cursor_size.x;

			const auto hint_rect = ltrbi(cursor_position, bg_sprite_size).snap_to_bounds(ltrbi(vec2i(0, 0), get_screen_size()));

			augs::draw_rect_with_border(
				output_buffer, 
				hint_rect,
				{ 0, 0, 0, 120 }, 
				slightly_visible_white
			);
			
			drop_hint_drawer.pos = hint_rect.get_position() + vec2i(cursor_size.x + 2, 0);

			drop_hint_drawer.draw_stroke(output_buffer, black);
			drop_hint_drawer.draw(output_buffer);

			return hint_rect.get_position();
		};

		const auto& rect_world = context.get_rect_world();

		const bool is_dragging = rect_world.is_currently_dragging();

		if (!is_dragging) {
			if (context.alive(rect_world.rect_hovered)) {
				gui_cursor = assets::texture_id::GUI_CURSOR_HOVER;
			}

			draw_tooltip_from_hover_or_world_highlight(output_buffer, context, get_tooltip_position());
		}
		else {
			const auto drag_result = prepare_drag_and_drop_result(context, rect_world.rect_held_by_lmb, rect_world.rect_hovered);
			
			if (drag_result.is<unfinished_drag_of_item>()) {
				const auto& dragged_item_button = context.dereference_location(item_button_in_item{ drag_result.get<unfinished_drag_of_item>().item_id });
				
				dragged_item_button->draw_complete_dragged_ghost(context, dragged_item_button, output_buffer);
				dragged_item_button->draw_grid_border_ghost(context, dragged_item_button, output_buffer);

				auto& item = context.get_step().get_cosmos()[dragged_item_button.get_location().item_id].get<components::item>();

				if (item.charges > 1) {
					const auto gui_cursor_size = (*gui_cursor).get_size();

					auto charges_text = to_wstring(dragged_charges);

					augs::gui::text_drawer dragged_charges_drawer;

					dragged_charges_drawer.set_text(augs::gui::text::format(charges_text, text::style()));
					dragged_charges_drawer.pos = get_gui_crosshair_position() + vec2i(0, int(gui_cursor_size.y));

					dragged_charges_drawer.draw_stroke(output_buffer, black);
					dragged_charges_drawer.draw(output_buffer);
				}
			}
			else if (drag_result.is<drop_for_hotbar_assignment>()) {
				const auto& transfer_data = drag_result.get<drop_for_hotbar_assignment>();
				const auto& dragged_item_button = context.dereference_location(item_button_in_item{ transfer_data.item_id });
				
				dragged_item_button->draw_complete_dragged_ghost(context, dragged_item_button, output_buffer);

				gui_cursor = assets::texture_id::GUI_CURSOR_ADD;
				gui_cursor_color = green;
				
				gui_cursor_position = draw_cursor_hint(transfer_data.hint_text, get_gui_crosshair_position(), (*gui_cursor).get_size());
			}
			else if (drag_result.is<drop_for_item_slot_transfer>()) {
				const auto& transfer_data = drag_result.get<drop_for_item_slot_transfer>();
				const auto& dragged_item_button = context.dereference_location(item_button_in_item{ transfer_data.simulated_transfer.item });

				dragged_item_button->draw_complete_dragged_ghost(context, dragged_item_button, output_buffer);

				const auto& transfer_result = transfer_data.result.result;

				if (transfer_result == item_transfer_result_type::SUCCESSFUL_DROP) {
					gui_cursor = assets::texture_id::GUI_CURSOR_MINUS;
					gui_cursor_color = red;
				}
				else if (transfer_result == item_transfer_result_type::SUCCESSFUL_TRANSFER) {
					gui_cursor = assets::texture_id::GUI_CURSOR_ADD;
					gui_cursor_color = green;
				}
				else if (transfer_result != item_transfer_result_type::THE_SAME_SLOT) {
					gui_cursor = assets::texture_id::GUI_CURSOR_ERROR;
					gui_cursor_color = red;
				}

				gui_cursor_position = draw_cursor_hint(transfer_data.hint_text, get_gui_crosshair_position(), (*gui_cursor).get_size());
			}
		}

		augs::draw_rect(output_buffer, gui_cursor_position, gui_cursor, gui_cursor_color);
	}