mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-11 18:40:06 +01:00
Fix ImagePickerButton.
This commit is contained in:
parent
ce637e247e
commit
b8b0294501
@ -43,11 +43,8 @@ void MatMakerFileDialog::_on_FileDialog_popup_hide() {
|
|||||||
emit_signal("return_paths", Array());
|
emit_signal("return_paths", Array());
|
||||||
}
|
}
|
||||||
|
|
||||||
Array MatMakerFileDialog::select_files() {
|
void MatMakerFileDialog::select_files() {
|
||||||
popup_centered();
|
popup_centered();
|
||||||
Variant = yield(self, "return_paths");
|
|
||||||
queue_free();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MatMakerFileDialog::add_favorite() {
|
void MatMakerFileDialog::add_favorite() {
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
void _on_FileDialog_dir_selected(const String &dir);
|
void _on_FileDialog_dir_selected(const String &dir);
|
||||||
void _on_FileDialog_popup_hide();
|
void _on_FileDialog_popup_hide();
|
||||||
|
|
||||||
Array select_files();
|
void select_files();
|
||||||
void add_favorite();
|
void add_favorite();
|
||||||
|
|
||||||
MatMakerFileDialog();
|
MatMakerFileDialog();
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
|
||||||
#include "image_picker_button.h"
|
#include "image_picker_button.h"
|
||||||
|
|
||||||
|
#include "../file_dialog/mat_maker_file_dialog.h"
|
||||||
|
#include "core/io/resource_loader.h"
|
||||||
|
#include "scene/resources/texture.h"
|
||||||
|
|
||||||
String ImagePickerButton::get_image_path() {
|
String ImagePickerButton::get_image_path() {
|
||||||
return image_path;
|
return image_path;
|
||||||
}
|
}
|
||||||
@ -16,15 +20,30 @@ void ImagePickerButton::do_set_image_path(const String &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
image_path = path;
|
image_path = path;
|
||||||
texture_normal.load(image_path);
|
|
||||||
|
Ref<Image> img = ResourceLoader::load("image_path", "Image");
|
||||||
|
Ref<ImageTexture> tex = get_normal_texture();
|
||||||
|
|
||||||
|
if (!tex.is_valid()) {
|
||||||
|
tex.instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->create_from_image(img);
|
||||||
|
|
||||||
|
set_normal_texture(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImagePickerButton::_on_ImagePicker_pressed() {
|
void ImagePickerButton::_on_ImagePicker_pressed() {
|
||||||
//var dialog = preload("res://addons/mat_maker_gd/windows/file_dialog/file_dialog.tscn").instance();
|
if (dialog) {
|
||||||
|
dialog->queue_delete();
|
||||||
|
dialog = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog = memnew(MatMakerFileDialog);
|
||||||
add_child(dialog);
|
add_child(dialog);
|
||||||
dialog->set_rect_min_size(Vector2(500, 500));
|
dialog->set_custom_minimum_size(Vector2(500, 500));
|
||||||
dialog->set_access(FileDialog.ACCESS_FILESYSTEM);
|
dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
|
||||||
dialog->set_mode(FileDialog.MODE_OPEN_FILE);
|
dialog->set_mode(FileDialog::MODE_OPEN_FILE);
|
||||||
dialog->add_filter("*.bmp;BMP Image");
|
dialog->add_filter("*.bmp;BMP Image");
|
||||||
dialog->add_filter("*.exr;EXR Image");
|
dialog->add_filter("*.exr;EXR Image");
|
||||||
dialog->add_filter("*.hdr;Radiance HDR Image");
|
dialog->add_filter("*.hdr;Radiance HDR Image");
|
||||||
@ -33,15 +52,19 @@ void ImagePickerButton::_on_ImagePicker_pressed() {
|
|||||||
dialog->add_filter("*.svg;SVG Image");
|
dialog->add_filter("*.svg;SVG Image");
|
||||||
dialog->add_filter("*.tga;TGA Image");
|
dialog->add_filter("*.tga;TGA Image");
|
||||||
dialog->add_filter("*.webp;WebP Image");
|
dialog->add_filter("*.webp;WebP Image");
|
||||||
image_path = dialog->select_files();
|
dialog->connect("return_paths", this, "on_file_selected");
|
||||||
|
dialog->select_files();
|
||||||
while (files is GDScriptFunctionState) {
|
|
||||||
files = yield(files, "completed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImagePickerButton::on_file_selected(const Array &files) {
|
||||||
if (files.size() > 0) {
|
if (files.size() > 0) {
|
||||||
set_image_path(files[0]);
|
set_image_path(files[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dialog) {
|
||||||
|
dialog->queue_delete();
|
||||||
|
dialog = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
||||||
@ -49,12 +72,14 @@ void ImagePickerButton::on_drop_image_file(const String &file_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImagePickerButton::ImagePickerButton() {
|
ImagePickerButton::ImagePickerButton() {
|
||||||
|
dialog = nullptr;
|
||||||
|
|
||||||
set_custom_minimum_size(Vector2(64, 64));
|
set_custom_minimum_size(Vector2(64, 64));
|
||||||
set_clip_contents(true);
|
set_clip_contents(true);
|
||||||
|
|
||||||
Ref<ImageTexture> imagepicker_prop_texture_normal;
|
Ref<ImageTexture> imagepicker_prop_texture_normal;
|
||||||
imagepicker_prop_texture_normal.instance();
|
imagepicker_prop_texture_normal.instance();
|
||||||
set_texture_normal(imagepicker_prop_texture_normal);
|
set_normal_texture(imagepicker_prop_texture_normal);
|
||||||
set_expand(true);
|
set_expand(true);
|
||||||
set_stretch_mode(STRETCH_KEEP_ASPECT_CENTERED);
|
set_stretch_mode(STRETCH_KEEP_ASPECT_CENTERED);
|
||||||
}
|
}
|
||||||
@ -64,7 +89,10 @@ ImagePickerButton::~ImagePickerButton() {
|
|||||||
|
|
||||||
void ImagePickerButton::_notification(int p_what) {
|
void ImagePickerButton::_notification(int p_what) {
|
||||||
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
if (p_what == NOTIFICATION_POSTINITIALIZE) {
|
||||||
texture_normal = memnew(ImageTexture);
|
Ref<ImageTexture> it;
|
||||||
|
it.instance();
|
||||||
|
|
||||||
|
set_normal_texture(it);
|
||||||
|
|
||||||
connect("pressed", this, "_on_ImagePicker_pressed");
|
connect("pressed", this, "_on_ImagePicker_pressed");
|
||||||
}
|
}
|
||||||
@ -77,9 +105,9 @@ void ImagePickerButton::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_ready"), &ImagePickerButton::_ready);
|
|
||||||
ClassDB::bind_method(D_METHOD("do_set_image_path", "path"), &ImagePickerButton::do_set_image_path);
|
ClassDB::bind_method(D_METHOD("do_set_image_path", "path"), &ImagePickerButton::do_set_image_path);
|
||||||
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
ClassDB::bind_method(D_METHOD("set_image_path", "path"), &ImagePickerButton::set_image_path);
|
||||||
ClassDB::bind_method(D_METHOD("_on_ImagePicker_pressed"), &ImagePickerButton::_on_ImagePicker_pressed);
|
ClassDB::bind_method(D_METHOD("_on_ImagePicker_pressed"), &ImagePickerButton::_on_ImagePicker_pressed);
|
||||||
ClassDB::bind_method(D_METHOD("on_drop_image_file", "file_name"), &ImagePickerButton::on_drop_image_file);
|
ClassDB::bind_method(D_METHOD("on_drop_image_file", "file_name"), &ImagePickerButton::on_drop_image_file);
|
||||||
|
ClassDB::bind_method(D_METHOD("on_file_selected", "files"), &ImagePickerButton::on_file_selected);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#ifndef IMAGE_PICKER_BUTTON_H
|
#ifndef IMAGE_PICKER_BUTTON_H
|
||||||
#define IMAGE_PICKER_BUTTON_H
|
#define IMAGE_PICKER_BUTTON_H
|
||||||
|
|
||||||
|
#include "core/array.h"
|
||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
|
|
||||||
#include "scene/gui/texture_button.h"
|
#include "scene/gui/texture_button.h"
|
||||||
|
|
||||||
|
class MatMakerFileDialog;
|
||||||
|
|
||||||
class ImagePickerButton : public TextureButton {
|
class ImagePickerButton : public TextureButton {
|
||||||
GDCLASS(ImagePickerButton, TextureButton);
|
GDCLASS(ImagePickerButton, TextureButton);
|
||||||
|
|
||||||
@ -16,6 +19,7 @@ public:
|
|||||||
|
|
||||||
void _on_ImagePicker_pressed();
|
void _on_ImagePicker_pressed();
|
||||||
void on_drop_image_file(const String &file_name);
|
void on_drop_image_file(const String &file_name);
|
||||||
|
void on_file_selected(const Array &arr);
|
||||||
|
|
||||||
ImagePickerButton();
|
ImagePickerButton();
|
||||||
~ImagePickerButton();
|
~ImagePickerButton();
|
||||||
@ -25,6 +29,8 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
String image_path;
|
String image_path;
|
||||||
|
|
||||||
|
MatMakerFileDialog *dialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user