Skip to content

Commit

Permalink
feat(wip): initial work on item/inventory/equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Jan 20, 2024
1 parent 81e82c8 commit f2156e5
Show file tree
Hide file tree
Showing 31 changed files with 2,396 additions and 240 deletions.
6 changes: 6 additions & 0 deletions project/demos/item_test_ui/items/test_item_000.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="Item" load_steps=2 format=3 uid="uid://cmuoe6r8lr7g"]

[ext_resource type="ItemSettings" uid="uid://bcdwpcf5776td" path="res://demos/item_test_ui/items/test_item_settings.tres" id="1_xmfv7"]

[resource]
item_settings = ExtResource("1_xmfv7")
6 changes: 6 additions & 0 deletions project/demos/item_test_ui/items/test_item_001.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="Item" load_steps=2 format=3 uid="uid://d27wbmd1lsxtp"]

[ext_resource type="ItemSettings" uid="uid://bcdwpcf5776td" path="res://demos/item_test_ui/items/test_item_settings.tres" id="1_n6u0y"]

[resource]
item_settings = ExtResource("1_n6u0y")
6 changes: 6 additions & 0 deletions project/demos/item_test_ui/items/test_item_settings.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_resource type="ItemSettings" format=3 uid="uid://bcdwpcf5776td"]

[resource]
decrease_quantity_on_use = true
is_stackable = true
max_quantity = 10
8 changes: 8 additions & 0 deletions project/demos/item_test_ui/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends Control


func _ready() -> void:
print(ItemManager.get_items())
print(EquipmentManager.get_slots())
pass

12 changes: 12 additions & 0 deletions project/demos/item_test_ui/main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://c7kl1lpd5o5ps"]

[ext_resource type="Script" path="res://demos/item_test_ui/main.gd" id="1_poj3d"]

[node name="Main" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_poj3d")
2 changes: 1 addition & 1 deletion project/new_tag_dictionary.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="TagDictionary" format=3 uid="uid://dh8udsjb5navh"]

[resource]
tags = PackedStringArray("enemy.ai.idle", "enemy.ai.roam", "enemy.ai.roam.end", "enemy.ai.roam.start", "enemy.ai.roam.idle", "enemy.ai.combat.chasing", "enemy.ai.combat.low_health", "enemy.ai.combat.panic", "enemy.factions", "enemy.factions.000", "enemy.factions.001", "enemy.factions.002")
tags = PackedStringArray("enemy.ai.idle", "enemy.ai.roam", "enemy.ai.roam.end", "enemy.ai.roam.start", "enemy.ai.roam.idle", "enemy.ai.combat.chasing", "enemy.ai.combat.low_health", "enemy.ai.combat.panic", "enemy.factions", "enemy.factions.enemies", "enemy.factions.neutrals", "enemy.factions.friends")
21 changes: 16 additions & 5 deletions src/editor_plugin/main_scene/ggs_main_scene.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "ggs_main_scene.h"

#include "attribute/ggs_attribute_main_scene.h"
#include "tag/ggs_tag_main_scene.h"
#include "ggs_main_scene.h"
#include "item/ggs_item_main_scene.h"

#include <godot_cpp/classes/panel.hpp>
#include <godot_cpp/classes/tab_container.hpp>

using namespace ggs;
using namespace ggs::editor_plugin;
Expand All @@ -15,32 +20,38 @@ MainScene::~MainScene()

void MainScene::_ready()
{
ability_panel = memnew(Panel);
attributes_panel = memnew(Panel);
tab_container = memnew(TabContainer);
tag_manager_panel = memnew(Panel);
Panel *ability_panel = memnew(Panel);
Panel *attributes_panel = memnew(Panel);
Panel *item_panel = memnew(Panel);
TabContainer *tab_container = memnew(TabContainer);
Panel *tag_manager_panel = memnew(Panel);

tab_container->set_anchors_and_offsets_preset(LayoutPreset::PRESET_FULL_RECT);

add_child(tab_container);

tab_container->add_child(tag_manager_panel);
tab_container->add_child(attributes_panel);
tab_container->add_child(item_panel);
// commented. Will come with a visual ability designer in the future.
// tab_container->add_child(ability_panel);

tag_manager_panel->set_name(tag_manager_panel->tr("Tag Manager"));
attributes_panel->set_name(attributes_panel->tr("Attributes"));
item_panel->set_name(item_panel->tr("Items & Equipment"));
// commented. Will come with a visual ability designer in the future.
// ability_panel->set_name(ability_panel->tr("Ability"));

AttributeMainScene *attribute_main_scene = memnew(AttributeMainScene);
TagMainScene *tag_main_scene = memnew(TagMainScene);
ItemMainScene *item_main_scene = memnew(ItemMainScene);

attributes_panel->add_child(attribute_main_scene);
tag_manager_panel->add_child(tag_main_scene);
item_panel->add_child(item_main_scene);
}

void MainScene::_bind_methods()
{
/// BANANA SPLITS HERE
}
6 changes: 0 additions & 6 deletions src/editor_plugin/main_scene/ggs_main_scene.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef GGS_MAIN_SCENE_H
#define GGS_MAIN_SCENE_H

#include <godot_cpp/classes/panel.hpp>
#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/tab_container.hpp>

using namespace godot;

Expand All @@ -28,10 +26,6 @@ namespace ggs::editor_plugin

protected:
static void _bind_methods();
TabContainer *tab_container;
Panel *ability_panel;
Panel *attributes_panel;
Panel *tag_manager_panel;
};
}

Expand Down
47 changes: 47 additions & 0 deletions src/editor_plugin/main_scene/item/ggs_item_main_scene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "ggs_item_main_scene.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/v_box_container.hpp>
#include <godot_cpp/classes/panel.hpp>

using namespace ggs;
using namespace ggs::editor_plugin;

void ItemMainScene::_handle_tab_pressed(int tab_id)
{
}

void ItemMainScene::_bind_methods()
{
}

void ItemMainScene::_ready()
{
Button *equipment_button = memnew(Button);
Button *items_button = memnew(Button);
VBoxContainer *tab_buttons = memnew(VBoxContainer);
VBoxContainer *tabs_container = memnew(VBoxContainer);
Panel *tabs_panel = memnew(Panel);
Panel *items_panel = memnew(Panel);
Panel *equipment_panel = memnew(Panel);

equipment_button->set_text(tr("Equipment"));
items_button->set_text(tr("Items"));

tab_buttons->set_name("GGS_ITEMS_TabButtons");

tab_buttons->add_child(equipment_button);
tab_buttons->add_child(items_button);

tabs_container->add_child(equipment_panel);
tabs_container->add_child(items_panel);
tabs_container->set_anchors_and_offsets_preset(PRESET_FULL_RECT);

tabs_panel->add_child(tabs_container);

add_child(tab_buttons);
add_child(tabs_panel);

set_anchors_and_offsets_preset(PRESET_FULL_RECT);
}
26 changes: 26 additions & 0 deletions src/editor_plugin/main_scene/item/ggs_item_main_scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GGS_ITEM_MAIN_SCENE_H
#define GGS_ITEM_MAIN_SCENE_H

#include <godot_cpp/classes/h_box_container.hpp>

using namespace godot;

namespace ggs::editor_plugin
{
class ItemMainScene : public HBoxContainer
{
GDCLASS(ItemMainScene, HBoxContainer);
/// @brief Handles the tab button being pressed.
/// @param tab_id The tab id of the button that was pressed.
void _handle_tab_pressed(int tab_id);

protected:
/// @brief Bind methods to Godot.
static void _bind_methods();
/// @brief Called when the node enters the scene tree for the first time.
public:
void _ready() override;
};
}

#endif
44 changes: 37 additions & 7 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
#include "system/attribute/attribute_project_settings.h"
#include "system/attribute/gameplay_effect.h"
#include "system/attribute/gameplay_effect_stacking_behavior.h"
#include "system/item/equipment.h"
#include "system/item/equipment_manager.h"
#include "system/item/equipment_project_settings.h"
#include "system/item/item.h"
#include "system/item/item_manager.h"
#include "system/item/item_project_settings.h"
#include "system/item/items_pool.h"
#include "system/item/inventory.h"
#include "system/tag/tag_dictionary.h"
#include "system/tag/tag_manager.h"
#include "system/tag/tag_project_settings.h"
Expand All @@ -35,6 +43,7 @@
#include "editor_plugin/ggs_editor_plugin.h"
#include "editor_plugin/main_scene/ggs_main_scene.h"
#include "editor_plugin/main_scene/attribute/ggs_attribute_main_scene.h"
#include "editor_plugin/main_scene/item/ggs_item_main_scene.h"
#include "editor_plugin/main_scene/tag/ggs_tag_dictionary_item.h"
#include "editor_plugin/main_scene/tag/ggs_tag_main_scene.h"

Expand All @@ -53,36 +62,55 @@ void initialize_ggs_module(ModuleInitializationLevel p_level)
ClassDB::register_class<ggs::Ability>();
ClassDB::register_class<ggs::AbilityContainer>();
ClassDB::register_class<ggs::AbilityGrant>();
ClassDB::register_class<ggs::AttributeManager>();
ClassDB::register_class<ggs::Attribute>();
ClassDB::register_class<ggs::AttributeContainer>();
ClassDB::register_class<ggs::AttributeEffect>();
ClassDB::register_class<ggs::AttributeEffectCondition>();
ClassDB::register_class<ggs::AttributeProjectSettings>();
ClassDB::register_class<ggs::AttributeManager>();
ClassDB::register_class<ggs::Equipment>();
ClassDB::register_class<ggs::EquipmentManager>();
ClassDB::register_class<ggs::EquipmentSlot>();
ClassDB::register_class<ggs::GameplayEffect>();
ClassDB::register_class<ggs::GameplayEffectStackingBehavior>();
ClassDB::register_class<ggs::Inventory>();
ClassDB::register_class<ggs::InventoryItem>();
ClassDB::register_class<ggs::Item>();
ClassDB::register_class<ggs::ItemManager>();
ClassDB::register_class<ggs::ItemSettings>();
ClassDB::register_class<ggs::ItemTags>();
ClassDB::register_class<ggs::ItemsPool>();
ClassDB::register_class<ggs::TagDictionary>();
ClassDB::register_class<ggs::TagManager>();
ClassDB::register_class<ggs::TagTree>();
ClassDB::register_internal_class<ggs::AbilityQueueItem>();

/// registering internal classes
ClassDB::register_internal_class<ggs::AbilityQueue>();
ClassDB::register_internal_class<ggs::AbilityQueueItem>();
ClassDB::register_internal_class<ggs::AttributeProjectSettings>();
ClassDB::register_internal_class<ggs::EquipmentProjectSettings>();
ClassDB::register_internal_class<ggs::ItemProjectSettings>();

/// registering settings
ggs::AttributeProjectSettings::setup();
ggs::EquipmentProjectSettings::setup();
ggs::ItemProjectSettings::setup();
ggs::TagProjectSettings::setup();

/// enabling autoloads
Engine::get_singleton()->register_singleton("AttributeManager", memnew(ggs::AttributeManager));
Engine::get_singleton()->register_singleton("TagManager", memnew(ggs::TagManager));
Engine::get_singleton()->register_singleton("AttributeManager", ggs::AttributeManager::get_singleton());
Engine::get_singleton()->register_singleton("EquipmentManager", ggs::EquipmentManager::get_singleton());
Engine::get_singleton()->register_singleton("ItemManager", ggs::ItemManager::get_singleton());
Engine::get_singleton()->register_singleton("TagManager", ggs::TagManager::get_singleton());
}
else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR)
{
ClassDB::register_internal_class<ggs::editor_plugin::AbilityInspectorPluginEditor>();
ClassDB::register_internal_class<ggs::editor_plugin::AbilityInspectorPlugin>();
ClassDB::register_internal_class<ggs::editor_plugin::AttributeContainerInspectorEditor>();
ClassDB::register_internal_class<ggs::editor_plugin::AbilityInspectorPluginEditor>();
ClassDB::register_internal_class<ggs::editor_plugin::AttributeContainerInspector>();
ClassDB::register_internal_class<ggs::editor_plugin::AttributeContainerInspectorEditor>();
ClassDB::register_internal_class<ggs::editor_plugin::AttributeMainScene>();
ClassDB::register_internal_class<ggs::editor_plugin::GGSEditorPlugin>();
ClassDB::register_internal_class<ggs::editor_plugin::ItemMainScene>();
ClassDB::register_internal_class<ggs::editor_plugin::MainScene>();
ClassDB::register_internal_class<ggs::editor_plugin::TagDictionaryItem>();
ClassDB::register_internal_class<ggs::editor_plugin::TagDocks>();
Expand All @@ -96,6 +124,8 @@ void uninitialize_ggs_module(ModuleInitializationLevel p_level)
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
{
Engine::get_singleton()->unregister_singleton("AttributeManager");
Engine::get_singleton()->unregister_singleton("EquipmentManager");
Engine::get_singleton()->unregister_singleton("ItemManager");
Engine::get_singleton()->unregister_singleton("TagManager");
}
else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR)
Expand Down
Loading

0 comments on commit f2156e5

Please sign in to comment.