Skip to content

Commit

Permalink
Fix intel description being the same for all items (#53)
Browse files Browse the repository at this point in the history
* Ensure to get description of local intel

* Add comment

* Fix names of intel editor attributes
  • Loading branch information
Kexanone authored Oct 20, 2024
1 parent 7c89bc1 commit bc649ef
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 97 deletions.
4 changes: 2 additions & 2 deletions addons/GME/Configs/Editor/AttributeLists/Edit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ SCR_EditorAttributeList {
}
}
}
GME_IntelTitleAttribute "{59863CBA3751B77E}" {
GME_IntelTitleEditorAttribute "{59863CBA3751B77E}" {
m_UIInfo SCR_EditorAttributeUIInfo "{59863CBA35CFA591}" {
Name "#GME-Editor_Attribute_IntelTitel_Name"
}
m_CategoryConfig "{BC15848F09F99FF2}Configs/Editor/AttributeCategories/Intel.conf"
m_Layout "{2A8C2090660989A0}UI/layouts/Editor/Attributes/AttributePrefabs/AttributePrefab_EditBox.layout"
}
GME_IntelContentAttribute "{5986F758EE99EEA9}" {
GME_IntelContentEditorAttribute "{5986F758EE99EEA9}" {
m_UIInfo SCR_EditorAttributeUIInfo "{5986F758EDD3BEE6}" {
Name "#GME-Editor_Attribute_IntelContent_Name"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ GenericEntity : "{6D56FED1E55A8F84}Prefabs/Items/Misc/IntelligenceFolder_E_01/In
components {
GME_IntelComponent "{628C84EC4669F95B}" {
}
InventoryItemComponent "{5222EB4D0C73006B}" {
Attributes SCR_ItemAttributeCollection "{5222EB4D0A2B466B}" {
ItemDisplayName GME_IntelUIInfo "{5222EB4D07D865FA}" {
}
m_bStackable 0
}
}
SCR_EditableEntityComponent "{628C84EC71D1AC09}" {
m_EntityType SYSTEM
m_UIInfo SCR_EditableEntityUIInfo "{628C84EF898119BA}" {
m_UIInfo GME_EditableIntelUIInfo "{628C84EF898119BA}" {
Name "#AR-Intel_Name"
Description "#AR-Intel_Description"
Icon "{DD5F23CBB1731598}UI/Textures/Editor/EditableEntities/Systems/EditableEntity_System_Base.edds"
Expand Down
49 changes: 33 additions & 16 deletions addons/GME/Scripts/Game/GME/Components/Intel/GME_IntelComponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class GME_IntelComponent : ScriptComponent
protected string m_sContent;

protected InventoryItemComponent m_pItemComponent;
protected UIInfo m_ItemUIInfo;
protected SCR_EditableEntityUIInfo m_EditableEntityUIInfo;
protected string m_sInventoryItemDescription;
protected SCR_EditableEntityComponent m_pEditableEntityComponent;
protected ref GME_EditableIntelUIInfo m_EditableIntelUIInfo;

//------------------------------------------------------------------------------------------------
override void OnPostInit(IEntity owner)
Expand All @@ -28,38 +29,48 @@ class GME_IntelComponent : ScriptComponent
if (!m_pItemComponent)
return;

m_ItemUIInfo = m_pItemComponent.GetUIInfo();

SCR_EditableEntityComponent editableEntityComponent = SCR_EditableEntityComponent.Cast(owner.FindComponent(SCR_EditableEntityComponent));
if (!editableEntityComponent)
m_pEditableEntityComponent = SCR_EditableEntityComponent.GetEditableEntity(owner);
if (!m_pEditableEntityComponent)
return;

m_EditableEntityUIInfo = SCR_EditableEntityUIInfo.Cast(editableEntityComponent.GetInfo());


if (Replication.IsServer())
m_pItemComponent.m_OnParentSlotChangedInvoker.Insert(OnPickedUpByPlayer);
}

//------------------------------------------------------------------------------------------------
protected void OnContentChanged()
{
string description = m_sTitle;
m_sInventoryItemDescription = m_sTitle;

if (!m_sTitle.IsEmpty() && !m_sContent.IsEmpty())
{
description += ":\n";
m_sInventoryItemDescription += ":\n";

for (int i = 0; i < m_sTitle.Length() + 1; i++)
{
description += "=";
m_sInventoryItemDescription += "=";
}

description += "\n";
m_sInventoryItemDescription += "\n";
}

m_sInventoryItemDescription += m_sContent;

if (m_sInventoryItemDescription.IsEmpty())
{
m_pEditableEntityComponent.SetInfoInstance(null);
return;
}

description += m_sContent;
m_ItemUIInfo.SetDescription(description);
m_EditableEntityUIInfo.SetDescription(description);
if (!m_EditableIntelUIInfo)
{
// We have to set a custom instance, since otherwise the global info is edited
m_EditableIntelUIInfo = new GME_EditableIntelUIInfo();
m_EditableIntelUIInfo.CopyFrom(m_pEditableEntityComponent.GetInfo());
m_pEditableEntityComponent.SetInfoInstance(m_EditableIntelUIInfo);
}

m_EditableIntelUIInfo.SetDescription(m_sInventoryItemDescription);
}

//------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -118,6 +129,12 @@ class GME_IntelComponent : ScriptComponent
return m_sContent;
}

//------------------------------------------------------------------------------------------------
string GetInventoryItemDescription()
{
return m_sInventoryItemDescription;
}

//------------------------------------------------------------------------------------------------
void Clear()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
[BaseContainerProps(), SCR_BaseEditorAttributeCustomTitle()]
class GME_IntelContentAttribute : SCR_BasePresetsEditorAttribute
{
override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
{
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
if (!editableEntity)
return null;
IEntity owner = editableEntity.GetOwner();
if (!owner)
return null;
GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return null;
return SCR_BaseEditorAttributeVar.GME_CreateString(intelComponent.GetContent());
}
override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
{
if (!var)
return;
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
IEntity owner = editableEntity.GetOwner();
if (!owner)
return;
GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return;
intelComponent.SetContent(var.GME_GetString());
}
[BaseContainerProps(), SCR_BaseEditorAttributeCustomTitle()]
class GME_IntelContentEditorAttribute : SCR_BasePresetsEditorAttribute
{
override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
{
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
if (!editableEntity)
return null;

IEntity owner = editableEntity.GetOwner();
if (!owner)
return null;

GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return null;

return SCR_BaseEditorAttributeVar.GME_CreateString(intelComponent.GetContent());
}

override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
{
if (!var)
return;

SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);

IEntity owner = editableEntity.GetOwner();
if (!owner)
return;

GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return;

intelComponent.SetContent(var.GME_GetString());
}
};
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
//------------------------------------------------------------------------------------------------
[BaseContainerProps(), SCR_BaseEditorAttributeCustomTitle()]
class GME_IntelTitleAttribute : SCR_BasePresetsEditorAttribute
{
//------------------------------------------------------------------------------------------------
override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
{
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
if (!editableEntity)
return null;
IEntity owner = editableEntity.GetOwner();
if (!owner)
return null;
GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return null;
return SCR_BaseEditorAttributeVar.GME_CreateString(intelComponent.GetTitle());
}
//------------------------------------------------------------------------------------------------
override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
{
if (!var)
return;
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
IEntity owner = editableEntity.GetOwner();
if (!owner)
return;
GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return;
intelComponent.SetTitle(var.GME_GetString());
}
}
//------------------------------------------------------------------------------------------------
[BaseContainerProps(), SCR_BaseEditorAttributeCustomTitle()]
class GME_IntelTitleEditorAttribute : SCR_BasePresetsEditorAttribute
{
//------------------------------------------------------------------------------------------------
override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
{
SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
if (!editableEntity)
return null;

IEntity owner = editableEntity.GetOwner();
if (!owner)
return null;

GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return null;

return SCR_BaseEditorAttributeVar.GME_CreateString(intelComponent.GetTitle());
}

//------------------------------------------------------------------------------------------------
override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
{
if (!var)
return;

SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);

IEntity owner = editableEntity.GetOwner();
if (!owner)
return;

GME_IntelComponent intelComponent = GME_IntelComponent.Cast(owner.FindComponent(GME_IntelComponent));
if (!intelComponent)
return;

intelComponent.SetTitle(var.GME_GetString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[BaseContainerProps()]
class GME_EditableIntelUIInfo : SCR_EditableEntityUIInfo
{
//------------------------------------------------------------------------------------------------
//! override without 'protected' keyword
override void CopyFrom(SCR_UIName source)
{
super.CopyFrom(source);
}
}
18 changes: 18 additions & 0 deletions addons/GME/Scripts/Game/GME/UI/Inventory/GME_IntelUIInfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[BaseContainerProps()]
class GME_IntelUIInfo : SCR_InventoryUIInfo
{
//------------------------------------------------------------------------------------------------
//! Function to override to get custom inventory name
override string GetInventoryItemDescription(InventoryItemComponent item)
{
GME_IntelComponent intelComponent = GME_IntelComponent.Cast(item.GetOwner().FindComponent(GME_IntelComponent));
if (!intelComponent)
return super.GetInventoryItemDescription(item);

string description = intelComponent.GetInventoryItemDescription();
if (description.IsEmpty())
return super.GetInventoryItemDescription(item);

return description;
}
}

0 comments on commit bc649ef

Please sign in to comment.