Report post

Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.

Users reporting for no reason may be locked out.


Post

Posted by Nick Thissen
on
I'm assuming these labels are in a ticker? Because that complicates matters a little bit.

In principle (ignoring the ticker aspect for now), the logic is pretty simple. I would simply build two labels on top of each other, one with the text and one with the image. Then in a script you can switch between the two by making one label invisible and the other visible. Probably something very close to this:
var labelText = subwidget.Labels.Find("TextLabel");
var labelImg = subwidget.Labels.Find("ImageLabel");

// Switch from text to image:
labelText.IsVisible = false;
labelImg.IsVisible = true;


For a ticker, you will need to do this for every copy of the labels in the ticker. For your understand, the ticker works by making several copies of the "template" subwidget (which you select in the properties). If there are 26 drivers, it will create 26 copies of that template. These copies are used until the ticker decides it needs to rebuild the copies (which happens sometimes, e.g. when number of drivers change). Simply changing the template subwidget after the fact will not impact the copies already made.

So to change all labels in a ticker you'll have to loop through all copies of the subwidgets and change them. And at the same time, I would also change the template itself, so that in the event that the copies are rebuilt, they are rebuilt using the current desired state.

The copies of the template are available from the ticker via the 'RepeatedSubWidgets' property. You can loop over those and change the properties, and then also change them for the template itself.

There is one tricky complication: the labels in a copy of the template do not get a name, so you cannot use the standard "subwidget.Find" method to get them. You can instead just get them by index but you'd need to find out the index first, and take care that it does not change (e.g. if you add or move around labels in the template subwidget).

Assuming the labels are the first and second (index 0 and 1), this should work I think:

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;

namespace Scripts
{
public class ChangeTickerImg : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var widget = item.Theme.Widgets.Find("Widget1");

foreach (var subwidget in widget.Ticker.RepeatedSubWidgets)
{
ChangeLabels(subwidget);
}
ChangeLabels(widget.Ticker.TemplateSubWidget);

return null;
}

private void ChangeLabels(SubWidget subwidget)
{
var labelText = subwidget.Labels[0];
var labelImg = subwidget.Labels[1];

labelText.IsVisible = false;
labelImg.IsVisible = true;
}
}
}