public Stats(IndexSettings s)
 {
     indexSettings = s;
     _setting      = null;
     value         = int.MinValue;
     scale         = 1f;
     offset        = 0f;
 }
 public void UpdateIndex(object sender, EventArgs e)
 {
     if (skip)
     {
         skip = false;
         return;
     }
     skip    = true;
     setting = (IndexSettings.Setting)index.SelectedItem;
     UpdateSettings();
 }
            public void UpdateIdxReference()
            {
                if (settingswithidx != null)
                {
                    // Check if the old settings are still valid
                    if ((int)settingswithidx.index.Value != _idx)
                    {
                        settingswithidx = null;
                    }
                }

                if (settingswithidx == null)
                {
                    // Search for a correct setting
                    foreach (IndexSettings.Setting set in Program.windowStatus.indexSettings.allSettings)
                    {
                        if ((int)set.index.Value == _idx)
                        {
                            settingswithidx = set;
                            break;
                        }
                    }
                }

                if (settingswithidx != null)
                {
                    // Scale the value
                    scale  = 0f;
                    offset = 0f;

                    if (settingswithidx.val2raw.Value - settingswithidx.val1raw.Value == 0)
                    {
                        scale  = 0f;
                        offset = (float)(settingswithidx.val1scaled.Value + settingswithidx.val2scaled.Value) / 2f;
                    }
                    else
                    {
                        scale  = (float)(settingswithidx.val2scaled.Value - settingswithidx.val1scaled.Value) / (float)(settingswithidx.val2raw.Value - settingswithidx.val1raw.Value);
                        offset = scale * (float)settingswithidx.val1raw.Value - (float)settingswithidx.val1scaled.Value;
                    }
                }
                else
                {
                    scale  = 1f;
                    offset = 0f;
                }
            }
        private void SetSettings(IndexSettings.Setting s)
        {
            // Remove link to old settings
            if (_setting != null)
            {
                _setting.linkedStats.Remove(this);
            }

            // If no setting selected
            if (s == null)
            {
                return;
            }

            // Add link to new settings
            _setting = s;
            _setting.linkedStats.Add(this);
        }
    public bool CreateElement(int index)
    {
        Stats stats = new Stats(indexSettings);

        allStats.Add(stats);

        FlowLayoutPanel panel = new FlowLayoutPanel();

        panel.Parent   = flowLayoutPanel;
        panel.AutoSize = true;
        stats.panel    = panel;

        ComboBox cmb = new ComboBox();

        cmb.Click += stats.UpdateIndexList;
        cmb.SelectedValueChanged += stats.UpdateIndex;
        cmb.Parent        = panel;
        cmb.Width         = 200;
        cmb.DropDownStyle = ComboBoxStyle.DropDownList;
        stats.index       = cmb;

        Label lab = new Label();

        lab.Parent    = panel;
        lab.AutoSize  = true;
        lab.ForeColor = System.Drawing.SystemColors.MenuHighlight;
        stats.name    = lab;

        Button btn = new Button();

        btn.Parent    = panel;
        btn.BackColor = System.Drawing.Color.White;
        btn.Text      = "X";
        btn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        btn.Size      = new System.Drawing.Size(25, 25);
        stats.delete  = btn;
        btn.Click    += stats.Delete;

        stats.Init();

        if (index >= 0)
        {
            IndexSettings.Setting found = null;
            foreach (IndexSettings.Setting o in stats.index.Items)
            {
                if (o.index.Value == index)
                {
                    found = o;
                    break;
                }
            }

            // If there is no indexsetting to link this to then never create it/delete it at creation
            if (found == null)
            {
                stats.Delete(null, null);
                return(false);
            }

            stats.index.SelectedItem = found;
        }

        if (editMode)
        {
            stats.index.Visible  = true;
            stats.delete.Visible = true;
            stats.name.Visible   = false;
        }
        else
        {
            stats.index.Visible  = false;
            stats.delete.Visible = false;
            stats.name.Visible   = true;
        }

        return(true);
    }