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
You can get the SelectedItem. With the SelectedItem you can also get the Text, or you can get the index by using the IndexOf function on the list of items.

The upcoming ATVO theme uses this to change the class filter on tickers. It is slightly more complicated as it is designed to be re-used for multiple tickers so the first part of the script is finding the right widget to change. The rest should be similar.

This is triggered by a dropdown which has the items in this order:
  • Index 0: All classes
  • Index 1: Class 1
  • Index 2: Class 2
  • etc...

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemeEditor.Data;
using System.Collections.Generic;

namespace Scripts
{
public class ChangeTickerClassFilter : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Which ticker(s) are we changing?
List<Widget> tickers = new List<Widget>();
var tickerValue = (string)value;
if (tickerValue == "H")
{
// Horizontal ticker
tickers.Add(item.Theme.Widgets.Find("W_HTicker"));
}
else if (tickerValue == "V")
{
// Vertical ticker
tickers.Add(item.Theme.Widgets.Find("W_VTickerTop"));
tickers.Add(item.Theme.Widgets.Find("W_VTickerBottom"));
}
else if (tickerValue == "Grid")
{
// Grid tickers
tickers.Add(item.Theme.Widgets.Find("W_GridLeft"));
tickers.Add(item.Theme.Widgets.Find("W_GridRight"));
}
else if (tickerValue == "Results")
{
// Results ticker
tickers.Add(item.Theme.Widgets.Find("W_Results"));
}

// Default: all classes
DataClassIndex index = DataClassIndex.AllClasses;

// Find the dropdown and the index of the selected item
var dropdown = (Dropdown)item;
var selectedIndex = dropdown.Items.IndexOf(dropdown.SelectedItem);
if (selectedIndex >= 0)
{
// The index of the dropdown items happens to coincide with the class filter indices,
// so this is an easy way to set the index without a long list of "if" or switch statements
index = (DataClassIndex) selectedIndex;
}

// Finally change the class filter
// Also restart the ticker to have it recalculate which items to show
foreach (var ticker in tickers)
{
ticker.DataClassIndex = index;
ticker.Ticker.Restart();
}

return null;
}
}
}