Skip to content

Commit

Permalink
Assign image button results correctly
Browse files Browse the repository at this point in the history
[CI BUILD]
  • Loading branch information
andybak committed Feb 28, 2024
1 parent 7b142ee commit b390bf7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Assets/Scripts/GUI/ImagePickerPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected override void RefreshIcon(ImageIcon icon, int iconIndex)
private void OnItemSelected(int itemIndex)
{
ActiveItemIndex = itemIndex;
var iconButton = m_Icons[itemIndex].m_IconScript;
int iconIndex = ActiveItemIndex % m_IconCountNavPage;
var iconButton = m_Icons[iconIndex].m_IconScript;
ReferenceImage image = ReferenceImageCatalog.m_Instance.IndexToImage(itemIndex);
iconButton.SetButtonSelected(true);
m_OpenerButton.UpdateValue(
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/GUI/ScriptParametersPopUpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public override void SetPopupCommandParameters(int iCommandParam, int iCommandPa
var imagePickerButton = instance.GetComponent<OpenImagePickerPopupButton>();
imagePickerButton.SetDescriptionText(config.label);
imagePickerButton.m_PropertyName = propertyName;
string filename = val.String;
int itemIndex = ReferenceImageCatalog.m_Instance.FilenameToIndex(filename);
if (itemIndex != -1)
{
ReferenceImage image = ReferenceImageCatalog.m_Instance.IndexToImage(itemIndex);
imagePickerButton.UpdateValue(
image.Icon,
imagePickerButton.m_PropertyName,
itemIndex,
image.ImageAspect
);
}
break;
case var value when value == LuaNames.widgetTypeVideo:
instance = Instantiate(m_ImagePickerButtonPrefab, transform);
Expand Down
13 changes: 13 additions & 0 deletions Assets/Scripts/ReferenceImageCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ public ReferenceImage IndexToImage(int index)
}
}

public int FilenameToIndex(string filename)
{
for (var i = 0; i < m_Images.Count; i++)
{
var img = m_Images[i];
if (img.FileName == filename)
{
return i;
}
}
return -1;
}

/// Returns an index to a catalog entry, or -1 if the handle is invalid.
/// The inverse of IndexToHandle.
/// Indices are not durable, so use the index immediately and do not keep it around.
Expand Down

0 comments on commit b390bf7

Please sign in to comment.