예제 #1
0
        private void ChangeProductPlacementOptions()
        {
            InteriorProduct pr = allProducts[currentIdx];

            pr.placementOptions = ObjectPlacementOptions.None;
            foreach (var sel in MC.SelectedItems)
            {
                pr.placementOptions |= (ObjectPlacementOptions)sel.Value;
            }
        }
예제 #2
0
        private async Task <bool> Save()
        {
            #region Manage IDs
            for (int i = 0; i < jsonBase.elements.Count; i++) //izby
            {
                jsonBase.elements[i].id = i;
                for (int j = 0; j < jsonBase.elements[i].child.Count; j++) //Typ
                {
                    jsonBase.elements[i].child[j].id = j;
                    for (int k = 0; k < jsonBase.elements[i].child[j].child.Count; k++) //Typ Typ
                    {
                        InteriorObjectSubtype tt = jsonBase.elements[i].child[j].child[k];
                        tt.id       = k;
                        tt.parentid = j;
                        for (int l = 0; l < tt.products.Count; l++)
                        {
                            InteriorProduct product = jsonBase.elements[i].child[j].child[k].products[l];
                            product.id     = l;
                            product.room   = i;
                            product.typ    = j;
                            product.subtyp = tt.category == UIElementCategory.Undefined ? -1 : k;
                        }
                    }
                }
            }
            #endregion

            if (string.IsNullOrEmpty(jsonBase.BaseAssetbundlePath))
            {
                MessageBox.Show("Base Assetbundle path is null or empty", "Invalid JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            if (string.IsNullOrEmpty(jsonBase.SkyboxPath))
            {
                MessageBox.Show("Skybox path is null or empty", "Invalid JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            string serializedJson = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(jsonBase, Formatting.Indented, settings));

            SaveFileDialog sf = new SaveFileDialog();
            sf.AddExtension = true;
            sf.DefaultExt   = "*.json";
            sf.Filter       = "JSON|*.json";
            sf.FileOk      += async(s, ea) =>
            {
                Stream       stream = sf.OpenFile();
                StreamWriter sw     = new StreamWriter(stream);
                await sw.WriteAsync(serializedJson);

                sw.Close();
            };
            sf.ShowDialog();
            return(true);
        }
예제 #3
0
 private void TraverseProducts(Action <InteriorProduct> productAction)
 {
     for (int i = 0; i < jsonBase.elements.Count; i++)                           //izby
     {
         for (int j = 0; j < jsonBase.elements[i].child.Count; j++)              //Typ
         {
             for (int k = 0; k < jsonBase.elements[i].child[j].child.Count; k++) //Typ Typ
             {
                 for (int l = 0; l < jsonBase.elements[i].child[j].child[k].products.Count; l++)
                 {
                     InteriorProduct product = jsonBase.elements[i].child[j].child[k].products[l];
                     productAction(product);
                 }
             }
         }
     }
 }
예제 #4
0
        private void ChangeComboBoxSelection(InteriorProduct pr)
        {
            var newSelection = new Dictionary <string, object>();
            var names        = Enum.GetNames(typeof(ObjectPlacementOptions));
            var options      = Enum.GetValues(typeof(ObjectPlacementOptions)).Cast <ObjectPlacementOptions>().ToArray();

            for (int i = 1; i < names.Length; i++)
            {
                if ((options[i] & pr.placementOptions) == options[i])
                {
                    newSelection.Add(names[i], options[i]);
                }
            }

            MC.ItemsSource   = new Dictionary <string, object>();
            MC.ItemsSource   = Items;
            MC.SelectedItems = newSelection;
            //(MC.DataContext as ViewModel).SelectedItems = new Dictionary<string, object>();
        }
예제 #5
0
        public ProductEditWindow(List <RoomItem> rooms)
        {
            InitializeComponent();

            allProducts = new List <InteriorProduct>();
            for (int i = 0; i < rooms.Count; i++)                           //izby
            {
                for (int j = 0; j < rooms[i].child.Count; j++)              //Typ
                {
                    for (int k = 0; k < rooms[i].child[j].child.Count; k++) //Typ Typ
                    {
                        for (int l = 0; l < rooms[i].child[j].child[k].products.Count; l++)
                        {
                            InteriorProduct product = rooms[i].child[j].child[k].products[l];
                            allProducts.Add(product);
                        }
                    }
                }
            }
            MainGrid.DataContext = allProducts[currentIdx];

            Items = new Dictionary <string, object>();
            var names   = Enum.GetNames(typeof(ObjectPlacementOptions));
            var options = Enum.GetValues(typeof(ObjectPlacementOptions)).Cast <ObjectPlacementOptions>().ToArray();

            for (int i = 1; i < names.Length; i++)
            {
                Items.Add(names[i], options[i]);
            }

            var SelectedItems = new Dictionary <string, object>();


            MC.ItemsSource   = Items;
            MC.SelectedItems = SelectedItems;

            ChangeComboBoxSelection(allProducts[currentIdx]);
        }
예제 #6
0
        private void ChangeComboBoxSelection(InteriorProduct pr)
        {
            var newSelection = new Dictionary<string, object>();
            var names = Enum.GetNames(typeof(ObjectPlacementOptions));
            var options = Enum.GetValues(typeof(ObjectPlacementOptions)).Cast<ObjectPlacementOptions>().ToArray();
            for (int i = 1; i < names.Length; i++)
            {
                if ((options[i] & pr.placementOptions) == options[i])
                {
                    newSelection.Add(names[i], options[i]);
                }
            }

            MC.ItemsSource = new Dictionary<string, object>();
            MC.ItemsSource = Items;
            MC.SelectedItems = newSelection;
            //(MC.DataContext as ViewModel).SelectedItems = new Dictionary<string, object>();
        }
예제 #7
0
        private void BTNAdd_Click(object sender, RoutedEventArgs e)
        {
            int owerwriteIdx = -1;
            InteriorProduct alreadyAdded = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.FirstOrDefault(x => x.uidisplayname == TBXMeno.Text);
            if(alreadyAdded != null)
            {
                MessageBoxResult result = MessageBox.Show(this, "Vybrany subtyp uz obsahuje tento produkt. Prepisat ?", "Prepisat produkt ?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
                switch(result)
                {
                    case MessageBoxResult.Yes:
                        owerwriteIdx = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.IndexOf(alreadyAdded);
                        break;
                    case MessageBoxResult.No:
                        return;
                        break;
                }
            }
            InteriorProduct product = new InteriorProduct();
            product.uidisplayname = TBXMeno.Text;
            product.path = TBXPathBundle.Text;
            product.image = TBXPathImage.Text;
            product.description = TBXShortDescription.Text;
            product.descriptionfordetail = TBXLongDescription.Text;
            product.pathformanufacturer = TBXPathManufacturer.Text;
            var products = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products;
            product.id = products.Count == 0 ? 0 : products.Max(x => x.id + 1);
            product.room = CBRoom.SelectedIndex;
            product.typ = CBType.SelectedIndex;
            InteriorObjectSubtype selectedSubTyp = CBSubType.SelectedItem as InteriorObjectSubtype;
            product.subtyp = selectedSubTyp.category == UIElementCategory.Undefined ? -1 : selectedSubTyp.id;
            product.manufacturerid = CBNamufacturer.SelectedIndex;
            product.manufacturername = (CBNamufacturer.SelectedItem as ManufacturerItem).uidisplayname;
            product.placementOptions = ObjectPlacementOptions.None;
            product.hash = TBXHash.Text;

            if (!string.IsNullOrEmpty(product.hash))
            {
                uint crc;
                if (!uint.TryParse(TBXCrc.Text, out crc))
                {
                    MessageBox.Show("Crc field is empty or has incorrect value", "Invalid product");
                    return;
                }
                else
                    product.crc = crc;
            }

            foreach (var sel in MC.SelectedItems)
            {
                product.placementOptions |= (ObjectPlacementOptions)sel.Value;
            }

            if (owerwriteIdx != -1)
                mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products[owerwriteIdx] = product;
            else
                mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.Add(product);
        }
예제 #8
0
        private void BTNAdd_Click(object sender, RoutedEventArgs e)
        {
            int             owerwriteIdx = -1;
            InteriorProduct alreadyAdded = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.FirstOrDefault(x => x.uidisplayname == TBXMeno.Text);

            if (alreadyAdded != null)
            {
                MessageBoxResult result = MessageBox.Show(this, "Vybrany subtyp uz obsahuje tento produkt. Prepisat ?", "Prepisat produkt ?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    owerwriteIdx = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.IndexOf(alreadyAdded);
                    break;

                case MessageBoxResult.No:
                    return;

                    break;
                }
            }
            InteriorProduct product = new InteriorProduct();

            product.uidisplayname        = TBXMeno.Text;
            product.path                 = TBXPathBundle.Text;
            product.image                = TBXPathImage.Text;
            product.description          = TBXShortDescription.Text;
            product.descriptionfordetail = TBXLongDescription.Text;
            product.pathformanufacturer  = TBXPathManufacturer.Text;
            var products = mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products;

            product.id   = products.Count == 0 ? 0 : products.Max(x => x.id + 1);
            product.room = CBRoom.SelectedIndex;
            product.typ  = CBType.SelectedIndex;
            InteriorObjectSubtype selectedSubTyp = CBSubType.SelectedItem as InteriorObjectSubtype;

            product.subtyp           = selectedSubTyp.category == UIElementCategory.Undefined ? -1 : selectedSubTyp.id;
            product.manufacturerid   = CBNamufacturer.SelectedIndex;
            product.manufacturername = (CBNamufacturer.SelectedItem as ManufacturerItem).uidisplayname;
            product.placementOptions = ObjectPlacementOptions.None;
            product.hash             = TBXHash.Text;

            if (!string.IsNullOrEmpty(product.hash))
            {
                uint crc;
                if (!uint.TryParse(TBXCrc.Text, out crc))
                {
                    MessageBox.Show("Crc field is empty or has incorrect value", "Invalid product");
                    return;
                }
                else
                {
                    product.crc = crc;
                }
            }

            foreach (var sel in MC.SelectedItems)
            {
                product.placementOptions |= (ObjectPlacementOptions)sel.Value;
            }

            if (owerwriteIdx != -1)
            {
                mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products[owerwriteIdx] = product;
            }
            else
            {
                mRooms[CBRoom.SelectedIndex].child[CBType.SelectedIndex].child[CBSubType.SelectedIndex].products.Add(product);
            }
        }