Ejemplo n.º 1
0
bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* buf, int max_size, Lumix::uint32 type)
{
	float item_w = ImGui::CalcItemWidth();
	auto& style = ImGui::GetStyle();
	float text_width = Lumix::Math::maximum(
		50.0f, item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 - style.ItemSpacing.x * 2);

	char* c = buf + Lumix::stringLength(buf);
	while (c > buf && *c != '/' && *c != '\\') --c;
	if (*c == '/' || *c == '\\') ++c;
	
	auto pos = ImGui::GetCursorPos();
	pos.x += text_width;
	ImGui::AlignFirstTextHeightToWidgets();
	ImGui::PushTextWrapPos(text_width);
	ImGui::Text("%s", c);
	ImGui::PopTextWrapPos();
	ImGui::SameLine();
	ImGui::SetCursorPos(pos);
	Lumix::StaticString<50> popup_name("pu", str_id);
	if (ImGui::Button(Lumix::StaticString<30>("...###browse", str_id)))
	{
		ImGui::OpenPopup(popup_name);
	}
	ImGui::SameLine();
	if (ImGui::Button(Lumix::StaticString<30>("View###go", str_id)))
	{
		m_is_focus_requested = true;
		m_is_opened = true;
		m_wanted_resource = buf;
	}
	ImGui::SameLine();
	ImGui::Text("%s", label);

	if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300)))
	{
		static char filter[128] = "";
		ImGui::InputText("Filter", filter, sizeof(filter));

		ImGui::BeginChild("Resources", ImVec2(0, 0));
		for (auto unv : getResources(getTypeIndexFromManagerType(type)))
		{
			if (filter[0] != '\0' && strstr(unv.c_str(), filter) == nullptr) continue;

			if (ImGui::Selectable(unv.c_str(), false))
			{
				Lumix::copyString(buf, max_size, unv.c_str());
				ImGui::EndChild();
				ImGui::EndPopup();
				return true;
			}
		}

		ImGui::EndChild();
		ImGui::EndPopup();
	}

	return false;
}
Ejemplo n.º 2
0
void AssetBrowser::update()
{
	PROFILE_FUNCTION();
	if (!m_is_update_enabled) return;
	bool is_empty;
	{
		Lumix::MT::SpinLock lock(m_changed_files_mutex);
		is_empty = m_changed_files.empty();
	}

	while (!is_empty)
	{
		Lumix::Path path;
		{
			Lumix::MT::SpinLock lock(m_changed_files_mutex);
			
			path = m_changed_files.back();
			m_changed_files.pop();
			is_empty = m_changed_files.empty();
		}

		char ext[10];
		Lumix::PathUtils::getExtension(ext, Lumix::lengthOf(ext), path.c_str());
		m_on_resource_changed.invoke(path, ext);

		Lumix::uint32 resource_type = getResourceType(path.c_str());
		if (resource_type == 0) continue;

		if (m_autoreload_changed_resource) m_editor.getEngine().getResourceManager().reload(path);

		char tmp_path[Lumix::MAX_PATH_LENGTH];
		if (m_editor.getEngine().getPatchFileDevice())
		{
			Lumix::copyString(tmp_path, m_editor.getEngine().getPatchFileDevice()->getBasePath());
			Lumix::catString(tmp_path, path.c_str());
		}

		if (!m_editor.getEngine().getPatchFileDevice() || !PlatformInterface::fileExists(tmp_path))
		{
			Lumix::copyString(tmp_path, m_editor.getEngine().getDiskFileDevice()->getBasePath());
			Lumix::catString(tmp_path, path.c_str());

			if (!PlatformInterface::fileExists(tmp_path))
			{
				int index = getTypeIndexFromManagerType(resource_type);
				m_resources[index].eraseItemFast(path);
				continue;
			}
		}

		char dir[Lumix::MAX_PATH_LENGTH];
		char filename[Lumix::MAX_PATH_LENGTH];
		Lumix::PathUtils::getDir(dir, sizeof(dir), path.c_str());
		Lumix::PathUtils::getFilename(filename, sizeof(filename), path.c_str());
		addResource(dir, filename);
	}
	m_changed_files.clear();
}
Ejemplo n.º 3
0
bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* buf, int max_size, Lumix::uint32 type)
{
	float item_w = ImGui::CalcItemWidth();
	auto& style = ImGui::GetStyle();
	ImGui::PushItemWidth(item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 -
						 style.ItemSpacing.x * 2);

	if (ImGui::InputText(Lumix::StaticString<30>("###", str_id), buf, max_size)) return true;

	ImGui::SameLine();
	Lumix::StaticString<50> popup_name("pu", str_id);
	if (ImGui::Button(Lumix::StaticString<30>("...###browse", str_id)))
	{
		ImGui::OpenPopup(popup_name);
	}
	ImGui::SameLine();
	if (ImGui::Button(Lumix::StaticString<30>("View###go", str_id)))
	{
		m_is_focus_requested = true;
		m_is_opened = true;
		m_wanted_resource = buf;
	}
	ImGui::SameLine();
	ImGui::Text("%s", label);
	ImGui::PopItemWidth();

	if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300)))
	{
		static char filter[128] = "";
		ImGui::InputText("Filter", filter, sizeof(filter));

		ImGui::BeginChild("Resources", ImVec2(0, 0));
		for (auto unv : getResources(getTypeIndexFromManagerType(type)))
		{
			if (filter[0] != '\0' && strstr(unv.c_str(), filter) == nullptr) continue;

			if (ImGui::Selectable(unv.c_str(), false))
			{
				Lumix::copyString(buf, max_size, unv.c_str());
				ImGui::EndChild();
				ImGui::EndPopup();
				return true;
			}
		}

		ImGui::EndChild();
		ImGui::EndPopup();
	}

	return false;
}
Ejemplo n.º 4
0
bool AssetBrowser::resourceList(char* buf, int max_size, Lumix::uint32 type, float height)
{
	static char filter[128] = "";
	ImGui::FilterInput("Filter", filter, sizeof(filter));

	ImGui::BeginChild("Resources", ImVec2(0, height));
	for (auto& unv : getResources(getTypeIndexFromManagerType(type)))
	{
		if (filter[0] != '\0' && strstr(unv.c_str(), filter) == nullptr) continue;

		if (ImGui::Selectable(unv.c_str(), false))
		{
			Lumix::copyString(buf, max_size, unv.c_str());
			ImGui::EndChild();
			return true;
		}
	}
	ImGui::EndChild();
	return false;
}