示例#1
0
        private void BTNAddRoomSubtype_Click(object sender, RoutedEventArgs e)
        {
            WindowWithStringResult w = new WindowWithStringResult(
                (name) =>
            {
                InteriorObjectType typ = (sender as Button).DataContext as InteriorObjectType;

                if (typ.child.Count == 1 && typ.child[0].category == UIElementCategory.Undefined)
                {
                    var products = typ.child[0].products;
                    InteriorObjectSubtype subTyp = new InteriorObjectSubtype(string.IsNullOrEmpty(name) ? UIElementCategory.Undefined : UIElementCategory.ProductTypeType);
                    subTyp.products      = products;
                    subTyp.uidisplayname = name;
                    subTyp.id            = 0;
                    subTyp.parentid      = typ.id;

                    typ.child[0] = subTyp;
                }
                else
                {
                    InteriorObjectSubtype subTyp = new InteriorObjectSubtype(string.IsNullOrEmpty(name) ? UIElementCategory.Undefined : UIElementCategory.ProductTypeType);
                    subTyp.uidisplayname         = name;
                    subTyp.parentid = typ.id;
                    subTyp.id       = typ.child.Count > 0 ? typ.child.Max(x => x.id) + 1 : 0;

                    typ.child.Add(subTyp);
                }

                UpdateTree();
            });

            w.Owner = this;
            w.ShowDialog();
        }
        private void BTNAddRoomSubtype_Click(object sender, RoutedEventArgs e)
        {
            WindowWithStringResult w = new WindowWithStringResult(
                (name) =>
                {
                    InteriorObjectType typ = (sender as Button).DataContext as InteriorObjectType;

                    if (typ.child.Count == 1 && typ.child[0].category == UIElementCategory.Undefined)
                    {
                        var products = typ.child[0].products;
                        InteriorObjectSubtype subTyp = new InteriorObjectSubtype(string.IsNullOrEmpty(name) ? UIElementCategory.Undefined : UIElementCategory.ProductTypeType);
                        subTyp.products = products;
                        subTyp.uidisplayname = name;
                        subTyp.id = 0;
                        subTyp.parentid = typ.id;

                        typ.child[0] = subTyp;
                    }
                    else
                    {

                        InteriorObjectSubtype subTyp = new InteriorObjectSubtype(string.IsNullOrEmpty(name) ? UIElementCategory.Undefined : UIElementCategory.ProductTypeType);
                        subTyp.uidisplayname = name;
                        subTyp.parentid = typ.id;
                        subTyp.id = typ.child.Count > 0 ? typ.child.Max(x => x.id) + 1 : 0;

                        typ.child.Add(subTyp);
                    }

                    UpdateTree();
                });
            w.Owner = this;
            w.ShowDialog();
        }
示例#3
0
        private void BTNRemoveRoom_Click(object sender, RoutedEventArgs e)
        {
            RoomItem room    = (sender as Button).DataContext as RoomItem;
            int      roomIdx = json.elements.IndexOf(room);

            for (int i = roomIdx + 1; i < json.elements.Count; i++)
            {
                RoomItem r = json.elements[i];
                r.id--;
                for (int j = 0; j < r.child.Count; j++)
                {
                    InteriorObjectType t = r.child[j];
                    for (int k = 0; k < t.child.Count; k++)
                    {
                        InteriorObjectSubtype st = t.child[k];
                        for (int l = 0; l < st.products.Count; l++)
                        {
                            st.products[l].room = r.id;
                        }
                    }
                }
            }

            json.elements.RemoveAt(roomIdx);
            UpdateTree();
        }
示例#4
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);
        }
示例#5
0
        private void BTNRenameSubType_Click(object sender, RoutedEventArgs e)
        {
            InteriorObjectSubtype  room = (sender as Button).DataContext as InteriorObjectSubtype;
            WindowWithStringResult w    = new WindowWithStringResult((name) =>
            {
                room.uidisplayname = name;
                room.category      = string.IsNullOrEmpty(name) ? UIElementCategory.Undefined : UIElementCategory.ProductTypeType;
                UpdateTree();
            });

            w.ShowDialog();
        }
示例#6
0
        private void BTNRemoveSubType_Click(object sender, RoutedEventArgs e)
        {
            InteriorObjectSubtype subType    = (sender as Button).DataContext as InteriorObjectSubtype;
            InteriorObjectType    parentType = null;

            foreach (var room in json.elements)
            {
                foreach (var type in room.child)
                {
                    if (type.child.Contains(subType))
                    {
                        parentType = type;
                        break;
                    }
                }
            }
            if (parentType != null)
            {
                parentType.child.Remove(subType);
            }

            UpdateTree();
        }
示例#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);
            }
        }