-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds create/delete of ItemsPool resources
- Loading branch information
Showing
7 changed files
with
204 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[gd_resource type="ItemsPool" format=3 uid="uid://bu65750smiusn"] | ||
|
||
[resource] | ||
pool_name = &"items_pool_000" | ||
resource_name = "items_pool_000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/editor_plugin/main_scene/item/ggs_item_pool_scene.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include "ggs_item_pool_scene.h" | ||
|
||
#include "resource_manager/resource_manager.h" | ||
#include "system/item/items_pool.h" | ||
|
||
#include <godot_cpp/classes/h_box_container.hpp> | ||
#include <godot_cpp/classes/button.hpp> | ||
#include <godot_cpp/classes/label.hpp> | ||
#include <godot_cpp/classes/scroll_container.hpp> | ||
|
||
using namespace ggs; | ||
using namespace ggs::editor_plugin; | ||
|
||
void ItemPoolScene::_handle_add_button_pressed() | ||
{ | ||
new_resource_modal->set_size(get_size() / 2); | ||
new_resource_modal->popup_centered(); | ||
} | ||
|
||
void ItemPoolScene::_handle_create_requested(String p_resource_name) | ||
{ | ||
GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); | ||
|
||
resource_manager->create_items_pool_resource(p_resource_name); | ||
resource_manager->save_resource(resource_manager->create_items_pool_resource(p_resource_name)); | ||
|
||
render_tree(); | ||
|
||
new_resource_modal->hide(); | ||
} | ||
|
||
void ItemPoolScene::_handle_tree_button_pressed(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) | ||
{ | ||
if (p_id == TreeButtonId::DELETE) | ||
{ | ||
GGSResourceManager *resource_manager = GGSResourceManager::get_singleton(); | ||
TypedArray<ItemsPool> pools = resource_manager->get_items_pool_resources(); | ||
|
||
ItemsPool *pool = nullptr; | ||
|
||
for (int i = 0; i < pools.size(); i++) | ||
{ | ||
Variant pool_variant = pools[i]; | ||
ItemsPool *pool_ptr = cast_to<ItemsPool>(pool_variant); | ||
|
||
if (pool_ptr && pool_ptr->get_pool_name() == p_item->get_text(0)) | ||
{ | ||
pool = pool_ptr; | ||
break; | ||
} | ||
} | ||
|
||
if (pool) | ||
{ | ||
resource_manager->remove_resource(pool); | ||
render_tree(); | ||
} | ||
} | ||
} | ||
|
||
void ItemPoolScene::_bind_methods() | ||
{ | ||
ClassDB::bind_method(D_METHOD("_handle_add_button_pressed"), &ItemPoolScene::_handle_add_button_pressed); | ||
ClassDB::bind_method(D_METHOD("_handle_create_requested", "p_resource_name"), &ItemPoolScene::_handle_create_requested); | ||
ClassDB::bind_method(D_METHOD("_handle_tree_button_pressed", "p_item", "p_column", "p_id", "p_mouse_button_index"), &ItemPoolScene::_handle_tree_button_pressed); | ||
} | ||
|
||
void ItemPoolScene::render_tree() | ||
{ | ||
item_pool_tree->clear(); | ||
|
||
TypedArray<ItemsPool> pools = GGSResourceManager::get_singleton()->get_items_pool_resources(); | ||
TreeItem *root = item_pool_tree->create_item(); | ||
|
||
for (int i = 0; i < pools.size(); i++) | ||
{ | ||
Variant pool = pools[i]; | ||
ItemsPool *pool_ptr = cast_to<ItemsPool>(pool); | ||
TreeItem *item = root->create_child(); | ||
|
||
item->set_text(0, pool_ptr->get_pool_name()); | ||
item->set_text(1, String::num_int64(pool_ptr->get_items().size())); | ||
item->set_text_alignment(1, HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); | ||
item->add_button(2, get_theme_icon("Remove", "EditorIcons"), TreeButtonId::DELETE); | ||
} | ||
} | ||
|
||
void ItemPoolScene::_ready() | ||
{ | ||
set_anchors_and_offsets_preset(PRESET_FULL_RECT); | ||
set_h_size_flags(SIZE_EXPAND_FILL); | ||
set_v_size_flags(SIZE_EXPAND_FILL); | ||
|
||
item_pool_tree = memnew(Tree); | ||
item_pool_tree->connect("button_clicked", Callable(this, "_handle_tree_button_pressed")); | ||
item_pool_tree->set_anchors_and_offsets_preset(PRESET_FULL_RECT); | ||
item_pool_tree->set_columns(3); | ||
item_pool_tree->set_column_title(0, "Name"); | ||
item_pool_tree->set_column_title(1, "Items stored"); | ||
item_pool_tree->set_column_title_alignment(1, HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); | ||
item_pool_tree->set_column_title(2, "Actions"); | ||
item_pool_tree->set_column_titles_visible(true); | ||
item_pool_tree->set_hide_root(true); | ||
item_pool_tree->set_h_size_flags(SIZE_EXPAND_FILL); | ||
item_pool_tree->set_v_size_flags(SIZE_EXPAND_FILL); | ||
|
||
Label *item_pool_label = memnew(Label); | ||
item_pool_label->set_anchors_and_offsets_preset(PRESET_FULL_RECT); | ||
item_pool_label->set_h_size_flags(SIZE_EXPAND_FILL); | ||
item_pool_label->set_text("Items pools"); | ||
|
||
Button *add_button = memnew(Button); | ||
add_button->connect("pressed", Callable(this, "_handle_add_button_pressed")); | ||
add_button->set_button_icon(get_theme_icon("Add", "EditorIcons")); | ||
add_button->set_text("Add items pool"); | ||
|
||
HBoxContainer *header = memnew(HBoxContainer); | ||
header->add_child(item_pool_label); | ||
header->add_child(add_button); | ||
header->set_anchors_and_offsets_preset(PRESET_FULL_RECT); | ||
header->set_h_size_flags(SIZE_EXPAND_FILL); | ||
|
||
add_child(header); | ||
|
||
ScrollContainer *scroll_container = memnew(ScrollContainer); | ||
scroll_container->set_anchors_and_offsets_preset(PRESET_FULL_RECT); | ||
scroll_container->set_h_size_flags(SIZE_EXPAND_FILL); | ||
scroll_container->set_v_size_flags(SIZE_EXPAND_FILL); | ||
scroll_container->add_child(item_pool_tree); | ||
|
||
add_child(scroll_container); | ||
|
||
render_tree(); | ||
|
||
new_resource_modal = memnew(NewResourceModal); | ||
new_resource_modal->connect("create_requested", Callable(this, "_handle_create_requested")); | ||
|
||
add_child(new_resource_modal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef GGS_ITEM_POOL_SCENE_H | ||
#define GGS_ITEM_POOL_SCENE_H | ||
|
||
#include <godot_cpp/classes/v_box_container.hpp> | ||
#include <godot_cpp/classes/tree.hpp> | ||
|
||
#include "editor_plugin/main_scene/ggs_new_resource_modal.h" | ||
#include "system/item/items_pool.h" | ||
|
||
using namespace godot; | ||
|
||
namespace ggs::editor_plugin | ||
{ | ||
class ItemPoolScene : public VBoxContainer | ||
{ | ||
GDCLASS(ItemPoolScene, VBoxContainer); | ||
|
||
private: | ||
enum TreeButtonId | ||
{ | ||
DELETE = 0, | ||
}; | ||
|
||
void _handle_add_button_pressed(); | ||
void _handle_create_requested(String p_resource_name); | ||
void _handle_tree_button_pressed(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
NewResourceModal *new_resource_modal; | ||
Tree *item_pool_tree; | ||
|
||
void render_tree(); | ||
|
||
public: | ||
void _ready() override; | ||
}; | ||
} | ||
|
||
#endif // GGS_ITEM_POOL_SCENE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters