public override void SetNthMask(int index, object obj)
            {
                ConditionFloat_FieldIndex enu = (ConditionFloat_FieldIndex)index;

                switch (enu)
                {
                case ConditionFloat_FieldIndex.ComparisonValue:
                    this.ComparisonValue = (Exception?)obj;
                    break;

                case ConditionFloat_FieldIndex.Data:
                    this.Data = (MaskItem <Exception?, ConditionData.ErrorMask?>?)obj;
                    break;

                default:
                    base.SetNthMask(index, obj);
                    break;
                }
            }
            public override void SetNthException(int index, Exception ex)
            {
                PackageDataTarget_FieldIndex enu = (PackageDataTarget_FieldIndex)index;

                switch (enu)
                {
                case PackageDataTarget_FieldIndex.Type:
                    this.Type = ex;
                    break;

                case PackageDataTarget_FieldIndex.Target:
                    this.Target = new MaskItem <Exception?, APackageTarget.ErrorMask?>(ex, null);
                    break;

                default:
                    base.SetNthException(index, ex);
                    break;
                }
            }
            public override void SetNthMask(int index, object obj)
            {
                PackageDataTarget_FieldIndex enu = (PackageDataTarget_FieldIndex)index;

                switch (enu)
                {
                case PackageDataTarget_FieldIndex.Type:
                    this.Type = (Exception?)obj;
                    break;

                case PackageDataTarget_FieldIndex.Target:
                    this.Target = (MaskItem <Exception?, APackageTarget.ErrorMask?>?)obj;
                    break;

                default:
                    base.SetNthMask(index, obj);
                    break;
                }
            }
Exemple #4
0
            public override void SetNthException(int index, Exception ex)
            {
                ConditionGlobal_FieldIndex enu = (ConditionGlobal_FieldIndex)index;

                switch (enu)
                {
                case ConditionGlobal_FieldIndex.ComparisonValue:
                    this.ComparisonValue = ex;
                    break;

                case ConditionGlobal_FieldIndex.Data:
                    this.Data = new MaskItem <Exception?, ConditionData.ErrorMask?>(ex, null);
                    break;

                default:
                    base.SetNthException(index, ex);
                    break;
                }
            }
Exemple #5
0
 public static MaskItem <TRet, GenderedItem <MaskItem <TRet, TRetMask?>?>?>?TranslateHelper <TItem, TMask, TRet, TRetMask>(
     MaskItem <TItem, GenderedItem <MaskItem <TItem, TMask?>?>?>?mask,
     Func <TItem, TRet> eval,
     Func <TMask?, Func <TItem, TRet>, TRetMask?> maskConv)
     where TMask : class, IMask <TItem>
     where TRetMask : class, IMask <TRet>
 {
     if (mask == null)
     {
         return(null);
     }
     else
     {
         return(new MaskItem <TRet, GenderedItem <MaskItem <TRet, TRetMask?>?>?>(
                    eval(mask.Overall),
                    mask.Specific == null ? null : new GenderedItem <MaskItem <TRet, TRetMask?>?>(
                        mask.Specific.Male == null ? null : new MaskItem <TRet, TRetMask?>(eval(mask.Specific.Male.Overall), maskConv(mask.Specific.Male.Specific, eval)),
                        mask.Specific.Female == null ? null : new MaskItem <TRet, TRetMask?>(eval(mask.Specific.Female.Overall), maskConv(mask.Specific.Female.Specific, eval)))));
     }
 }
Exemple #6
0
        private void MaskCheckList_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            List <IMask> masks        = new List <IMask>();
            MaskItem     mClickedItem = null;

            mClickedItem = ((MaskItem)MaskCheckList.Items[e.Index]);

            if (e.NewValue == CheckState.Checked)
            {
                masks.Add(mClickedItem.mMask);

                //betterPropertyGrid1.SelectedObject = mClickedItem;
                //DeleteLinkLabel.Enabled = true;
                //SaveLinkLabel.Enabled = true;

                CurrentMaskNameTextBox.Text = mClickedItem.Name;
            }
            else
            {
                //betterPropertyGrid1.SelectedObject = null;
                //DeleteLinkLabel.Enabled = false;
                //SaveLinkLabel.Enabled = false;
            }

            foreach (MaskItem m in MaskCheckList.CheckedItems)
            {
                if (mClickedItem != m)
                {
                    masks.Add(m.mMask);
                }
            }
            if (masks.Count > 0)
            {
                Masking.setCurrSelectionMaskWeights(AddMasks(masks));
            }
            else
            {
                Masking.setCurrSelectionMaskWeights(MaskFactory.GetNewMask());
            }
        }
Exemple #7
0
            public void SetNthMask(int index, object obj)
            {
                LocationTargetRadius_FieldIndex enu = (LocationTargetRadius_FieldIndex)index;

                switch (enu)
                {
                case LocationTargetRadius_FieldIndex.Target:
                    this.Target = (MaskItem <Exception?, ALocationTarget.ErrorMask?>?)obj;
                    break;

                case LocationTargetRadius_FieldIndex.Radius:
                    this.Radius = (Exception?)obj;
                    break;

                case LocationTargetRadius_FieldIndex.CollectionIndex:
                    this.CollectionIndex = (Exception?)obj;
                    break;

                default:
                    throw new ArgumentException($"Index is out of range: {index}");
                }
            }
Exemple #8
0
            public void SetNthException(int index, Exception ex)
            {
                LocationTargetRadius_FieldIndex enu = (LocationTargetRadius_FieldIndex)index;

                switch (enu)
                {
                case LocationTargetRadius_FieldIndex.Target:
                    this.Target = new MaskItem <Exception?, ALocationTarget.ErrorMask?>(ex, null);
                    break;

                case LocationTargetRadius_FieldIndex.Radius:
                    this.Radius = ex;
                    break;

                case LocationTargetRadius_FieldIndex.CollectionIndex:
                    this.CollectionIndex = ex;
                    break;

                default:
                    throw new ArgumentException($"Index is out of range: {index}");
                }
            }
Exemple #9
0
            public void SetNthException(int index, Exception ex)
            {
                Rank_FieldIndex enu = (Rank_FieldIndex)index;

                switch (enu)
                {
                case Rank_FieldIndex.Number:
                    this.Number = ex;
                    break;

                case Rank_FieldIndex.Title:
                    this.Title = new MaskItem <Exception?, GenderedItem <Exception?>?>(ex, null);
                    break;

                case Rank_FieldIndex.Insignia:
                    this.Insignia = ex;
                    break;

                default:
                    throw new ArgumentException($"Index is out of range: {index}");
                }
            }
Exemple #10
0
 public static bool AnyMask <TItem, TMask>(MaskItem <TItem, GenderedItem <MaskItem <TItem, TMask?>?>?>?item, Func <TItem, bool> eval)
     where TMask : class, IMask <TItem>
 {
     if (item == null)
     {
         return(false);
     }
     if (eval(item.Overall))
     {
         return(true);
     }
     if (item.Specific == null)
     {
         return(false);
     }
     if (item.Specific.Male != null)
     {
         if (eval(item.Specific.Male.Overall))
         {
             return(true);
         }
         if (item.Specific.Male.Specific != null && item.Specific.Male.Specific.Any(eval))
         {
             return(true);
         }
     }
     if (item.Specific.Female != null)
     {
         if (eval(item.Specific.Female.Overall))
         {
             return(true);
         }
         if (item.Specific.Female.Specific != null && item.Specific.Female.Specific.Any(eval))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #11
0
            public void SetNthMask(int index, object obj)
            {
                ScriptEntry_FieldIndex enu = (ScriptEntry_FieldIndex)index;

                switch (enu)
                {
                case ScriptEntry_FieldIndex.Name:
                    this.Name = (Exception?)obj;
                    break;

                case ScriptEntry_FieldIndex.Flags:
                    this.Flags = (Exception?)obj;
                    break;

                case ScriptEntry_FieldIndex.Properties:
                    this.Properties = (MaskItem <Exception?, IEnumerable <MaskItem <Exception?, ScriptProperty.ErrorMask?> >?>)obj;
                    break;

                default:
                    throw new ArgumentException($"Index is out of range: {index}");
                }
            }
Exemple #12
0
            public void SetNthMask(int index, object obj)
            {
                Rank_FieldIndex enu = (Rank_FieldIndex)index;

                switch (enu)
                {
                case Rank_FieldIndex.Number:
                    this.Number = (Exception?)obj;
                    break;

                case Rank_FieldIndex.Title:
                    this.Title = (MaskItem <Exception?, GenderedItem <Exception?>?>?)obj;
                    break;

                case Rank_FieldIndex.Insignia:
                    this.Insignia = (Exception?)obj;
                    break;

                default:
                    throw new ArgumentException($"Index is out of range: {index}");
                }
            }
Exemple #13
0
 public static bool Any <TItem>(MaskItem <TItem, GenderedItem <TItem>?>?item, Func <TItem, bool> eval)
 {
     if (item == null)
     {
         return(false);
     }
     if (eval(item.Overall))
     {
         return(true);
     }
     if (item.Specific == null)
     {
         return(true);
     }
     if (eval(item.Specific.Male))
     {
         return(true);
     }
     if (eval(item.Specific.Female))
     {
         return(true);
     }
     return(false);
 }
Exemple #14
0
 public static MaskItem <Exception, TRet>?Bubble <TSource, TRet>(this MaskItem <Exception, TSource> item)
     where TSource : TRet
 {
     return(new MaskItem <Exception, TRet>(item.Overall, item.Specific));
 }
Exemple #15
0
 public static MaskItem <TRet, GenderedItem <TRet>?>?TranslateHelper <TItem, TRet>(MaskItem <TItem, GenderedItem <TItem>?>?mask, Func <TItem, TRet> eval)
 {
     if (mask == null)
     {
         return(null);
     }
     else
     {
         return(new MaskItem <TRet, GenderedItem <TRet>?>(
                    eval(mask.Overall),
                    mask.Specific == null ? null : new GenderedItem <TRet>(eval(mask.Specific.Male), eval(mask.Specific.Female))));
     }
 }
Exemple #16
0
        private void ImportMaskButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "Image (*.bmp)|*.bmp|Raw32 (*.r32)|*.r32";
            if (d.ShowDialog() == DialogResult.OK)
            {
                string tName    = Path.GetFileNameWithoutExtension(d.FileName);
                bool   okToLoad = true;
                for (int i = 0; i < MaskCheckList.Items.Count; i++)
                {
                    MaskItem mi = MaskCheckList.Items[i] as MaskItem;
                    if (Path.GetFileNameWithoutExtension(mi.Name) == tName)
                    {
                        if (MessageBox.Show("There exists a similar mask name already loaded. Would you still like to import this mask?", "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes)
                        {
                            okToLoad = false;
                        }
                        break;
                    }
                }
                if (!okToLoad)
                {
                    return;
                }
                if (Path.GetExtension(d.FileName.ToLower()) == ".bmp")
                {
                    Image    loadedImage = Masking.GetScaledImageFromFile(d.FileName, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts());
                    MaskItem item        = new MaskItem();
                    item.Name  = Path.GetFileName(d.FileName);
                    item.mMask = Masking.CreateMask(loadedImage);
                    MaskCheckList.Items.Add(item, false);
                    Masking.setCurrSelectionMaskWeights(item.mMask.Clone());
                }
                else if (Path.GetExtension(d.FileName.ToLower()) == ".r32")
                {
                    MaskItem item = new MaskItem();
                    item.Name  = Path.GetFileName(d.FileName);
                    item.mMask = MaskFactory.GetNewMask();
                    BinaryReader r = new BinaryReader(File.OpenRead(d.FileName));

                    long index = 0;
                    try
                    {
                        while (true)
                        {
                            item.mMask.SetMaskWeight(index, r.ReadSingle());
                            index++;
                        }
                    }
                    catch (System.IO.EndOfStreamException ex)
                    {
                        ex.ToString();
                    }

                    if (scaleToFitCheckbox.Checked)
                    {
                        //rescale this mask to fit current terrain
                        int     numX = (int)Math.Sqrt(index);
                        float[] img  = new float[numX * numX];
                        long    id;
                        float   value;
                        item.mMask.ResetIterator();
                        while (item.mMask.MoveNext(out id, out value))
                        {
                            if (value == 0)
                            {
                                continue;
                            }
                            img[id] = value;
                        }

                        int     newWidth = TerrainGlobals.getTerrain().getNumXVerts();
                        float[] outImg   = ImageManipulation.resizeF32Img(img, numX, numX, newWidth, newWidth, ImageManipulation.eFilterType.cFilter_Linear);
                        item.mMask.Clear();
                        for (index = 0; index < newWidth * newWidth; index++)
                        {
                            item.mMask.SetMaskWeight(index, outImg[index]);
                        }
                    }
                    MaskCheckList.Items.Add(item, false);
                    Masking.setCurrSelectionMaskWeights(item.mMask.Clone());
                    r.Close();
                }
            }
            //ImageSourcePicker picker = new ImageSourcePicker();
            //picker.ImageSelected += new EventHandler(picker_ImageSelected);
            //PopupEditor editor = new PopupEditor();
            //editor.ShowPopup(this, picker);
        }
Exemple #17
0
 public static bool IsMaskUnlocked(MaskItem maskToCheck)
 {
     return(MasksUnlocked.Contains(maskToCheck.maskType));
 }
Exemple #18
0
    public static MaskItem <Exception?, TMask?>?Combine <TMask>(this MaskItem <Exception?, TMask?>?lhs, MaskItem <Exception?, TMask?>?rhs, Func <TMask, TMask, TMask> combiner)
        where TMask : class
    {
        if (rhs == null)
        {
            return(lhs);
        }
        if (lhs == null)
        {
            return(rhs);
        }
        var   overall = ExceptionExt.Combine(lhs.Overall, rhs.Overall);
        TMask?specific;

        if (lhs.Specific == null)
        {
            specific = rhs.Specific;
        }
        else if (rhs.Specific == null)
        {
            specific = lhs.Specific;
        }
        else
        {
            specific = combiner(lhs.Specific, rhs.Specific);
        }
        if (overall == null && specific == null)
        {
            return(null);
        }
        return(new MaskItem <Exception?, TMask?>(overall, specific));
    }