Skip to content

Commit

Permalink
feat(wip): starts building item editor panels
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Jan 21, 2024
1 parent f73ef63 commit 03b752b
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 1 deletion.
125 changes: 125 additions & 0 deletions src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "ggs_equipment_slot_scene.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/line_edit.hpp>

#include "system/attribute/attribute_manager.h"
#include "system/item/equipment_manager.h"
#include "system/tag/tag_manager.h"
#include "system/tag/tag_tree.h"

using namespace ggs;
using namespace ggs::editor_plugin;

void EquipmentSlotScene::_handle_add_button_pressed()
{
}

void EquipmentSlotScene::_handle_slot_item_selected()
{
TreeItem *selected = slots_tree->get_selected();

if (selected == nullptr)
{
return;
}
}

void EquipmentSlotScene::_handle_slot_item_name_edited(String p_new_text)
{
selected_equipment_slot->set_slot_name(p_new_text);

TreeItem *selected = slots_tree->get_selected();

if (selected == nullptr)
{
return;
}

selected->set_text(0, p_new_text);
}

void EquipmentSlotScene::_render_slots_tree()
{
slots_tree->clear();

TypedArray<EquipmentSlot> slots = EquipmentManager::get_singleton()->slots;

for (int i = 0; i < slots.size(); i++)
{
TreeItem *slot_item = slots_tree->create_item();
Variant slot_variant = slots[i];
EquipmentSlot *slot = cast_to<EquipmentSlot>(slot_variant);

slot_item->set_text(0, slot->get_slot_name());
slot_item->set_text(1, String("").join(slot->get_accepts_items_with_tags()));
slot_item->set_text(2, String("").join(slot->get_denies_items_with_tags()));
}
}

void EquipmentSlotScene::_bind_methods()
{
ClassDB::bind_method(D_METHOD("_handle_add_button_pressed"), &EquipmentSlotScene::_handle_add_button_pressed);
ClassDB::bind_method(D_METHOD("_handle_slot_item_selected"), &EquipmentSlotScene::_handle_slot_item_selected);
ClassDB::bind_method(D_METHOD("_handle_slot_item_name_edited"), &EquipmentSlotScene::_handle_slot_item_name_edited);
}

void EquipmentSlotScene::render_single_slot(EquipmentSlot *p_slot)
{
VBoxContainer *slot_container = memnew(VBoxContainer);
Label *slot_name_label = memnew(Label);
Label *accepts_items_with_tags_label = memnew(Label);
Label *denies_items_with_tags_label = memnew(Label);
TagTree *accepts_items_with_tags = memnew(TagTree);
TagTree *denies_items_with_tags = memnew(TagTree);
LineEdit *slot_name = memnew(LineEdit);

slot_name_label->set_text(tr("Slot name: "));
accepts_items_with_tags_label->set_text(tr("Accepts items with tags: "));
denies_items_with_tags_label->set_text(tr("Denies items with tags: "));

slot_name->set_text(p_slot->get_slot_name());
slot_name->connect("text_changed", Callable(this, "_handle_slot_item_name_edited"));

slot_container->add_child(slot_name_label);
slot_container->add_child(slot_name);
slot_container->add_child(accepts_items_with_tags_label);
slot_container->add_child(accepts_items_with_tags);
slot_container->add_child(denies_items_with_tags_label);
slot_container->add_child(denies_items_with_tags);

for (int i = 0; i < selected_slot->get_child_count(); i++)
{
selected_slot->get_child(i)->queue_free();
}

selected_slot->add_child(slot_container);
}

void EquipmentSlotScene::_ready()
{
HBoxContainer *header = memnew(HBoxContainer);
HBoxContainer *content = memnew(HBoxContainer);
Button *add_button = memnew(Button);
Label *name_label = memnew(Label);
selected_slot = memnew(VBoxContainer);
slots_tree = memnew(Tree);

add_button->connect("pressed", Callable(this, "_handle_add_button_pressed"));
add_button->set_text(tr("Add slot"));
name_label->set_text(tr("Equipment Slots"));

slots_tree->connect("item_selected", Callable(this, "_handle_slot_item_selected"));
slots_tree->set_columns(4);
slots_tree->set_column_title(0, tr("Slot name"));
slots_tree->set_column_title(1, tr("Accepts items with tags"));
slots_tree->set_column_title(2, tr("Denies items with tags"));

content->add_child(slots_tree);
content->add_child(selected_slot);

add_child(header);
add_child(content);
}
44 changes: 44 additions & 0 deletions src/editor_plugin/main_scene/item/ggs_equipment_slot_scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef GGS_EQUIPMENT_SLOT_SCENE_H
#define GGS_EQUIPMENT_SLOT_SCENE_H

#include <godot_cpp/classes/v_box_container.hpp>
#include <godot_cpp/classes/tree.hpp>
#include "system/item/equipment_slot.h"

using namespace godot;

namespace ggs::editor_plugin
{
class EquipmentSlotScene : public VBoxContainer
{
GDCLASS(EquipmentSlotScene, VBoxContainer);

private:
/// @brief Handles the add button pressed event.
void _handle_add_button_pressed();
/// @brief Handles the slot item selected event.
void _handle_slot_item_selected();
/// @brief handles the slot item name edited event.
/// @param p_new_text the new text.
void _handle_slot_item_name_edited(String p_new_text);
/// @brief Renders the slots tree.
void _render_slots_tree();

protected:
static void _bind_methods();
/// @brief The selected equipment slot.
EquipmentSlot *selected_equipment_slot;
/// @brief The selected slot.
VBoxContainer *selected_slot;
/// @brief The tree that contains the slots.
Tree *slots_tree;
/// @brief Renders a single slot.
/// @param p_slot The slot to render.
void render_single_slot(EquipmentSlot *p_slot);

public:
void _ready() override;
};
}

#endif
7 changes: 7 additions & 0 deletions src/system/item/equipment_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ using namespace godot;

namespace ggs
{
namespace editor_plugin
{
class EquipmentSlotScene;
}

class EquipmentManager : public Node
{
GDCLASS(EquipmentManager, Node)

protected:
friend class ggs::editor_plugin::EquipmentSlotScene;

/// @brief The singleton instance.
static EquipmentManager *singleton;
/// @brief Binds methods to Godot.
Expand Down
4 changes: 3 additions & 1 deletion src/system/tag/tag_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace ggs
{
namespace editor_plugin
{
class AttributeMainScene;
class AbilityInspectorPluginEditor;
class AttributeMainScene;
class EquipmentSlotScene;
class TagDocks;
class TagMainScene;
}
Expand Down Expand Up @@ -101,6 +102,7 @@ namespace ggs
protected:
friend class editor_plugin::AttributeMainScene;
friend class editor_plugin::AbilityInspectorPluginEditor;
friend class editor_plugin::EquipmentSlotScene;
friend class editor_plugin::TagDocks;
friend class editor_plugin::TagMainScene;

Expand Down

0 comments on commit 03b752b

Please sign in to comment.