WindowUniverseOutput()
        {
            InitializeComponent();
            sliderWithValueLabel_Delay.slider.Maximum = 3000;
            sliderWithValueLabel_Delay.slider.Minimum = 0;

            Title = LanguageHandler.GetInstance().TitleOfUniverseOutputWindow;
            tabItem_SimulationInfo.Header    = LanguageHandler.GetInstance().TabItem_SimulationInfoHeader;
            tabItem_Game.Header              = LanguageHandler.GetInstance().TabItem_GameHeader;
            tabItem_Controls.Header          = LanguageHandler.GetInstance().TabItem_ControlsHeader;
            buttonClearField.Content         = LanguageHandler.GetInstance().ButtonClearFieldText;
            buttonConstsRedactor.Content     = LanguageHandler.GetInstance().ButtonConstsRedactorText;
            buttonFoodPlaceRedactot.Content  = LanguageHandler.GetInstance().ButtonFoodPlaceRedactotText;
            buttonGenerateCells.Content      = LanguageHandler.GetInstance().ButtonGenerateCellsText;
            buttonGenerateFoodOnAll.Content  = LanguageHandler.GetInstance().ButtonGenerateFoodOnAllText;
            buttonPause.Content              = LanguageHandler.GetInstance().ButtonPauseText;
            buttonPosinPlaceRedactot.Content = LanguageHandler.GetInstance().ButtonPosinPlaceRedactotText;
            buttonResetResolution.Content    = LanguageHandler.GetInstance().ButtonResetResolutionText;
            buttonSaveUniverse.Content       = LanguageHandler.GetInstance().ButtonSaveUniverseText;
            buttonStart.Content              = LanguageHandler.GetInstance().ButtonStarText;
            labelCellsCount.Content          = LanguageHandler.GetInstance().LabelCellsCountText;
            labelDelay.Content  = LanguageHandler.GetInstance().LabelDelayText;
            labelHeight.Content = LanguageHandler.GetInstance().LabelHeightText;
            labelWidth.Content  = LanguageHandler.GetInstance().LabelWidthText;
        }
        internal static bool[,] ShowModal(RenderManagerMainField renderManager, ImageSource imageSourceForCheck, bool[,] fieldDesciption, string title = "Field redactor")
        {
            if (fieldDesciption.Length > 40000)
            {
                MessageBox.Show(LanguageHandler.GetInstance().FieldRedactorSizeWarning);
                return(fieldDesciption);
            }
            RenderManagerCheckAtField renderManagerCheckAtField = new RenderManagerCheckAtField(renderManager, imageSourceForCheck, fieldDesciption);
            var wd = new WindowCheckAtField(renderManagerCheckAtField);

            wd.Title = title;
            wd.StartRenderField();
            wd.ShowDialog();
            wd.StopRenderField();
            bool[,] res;
            if (wd.applyed)
            {
                res = renderManagerCheckAtField.GetFieldDescription();
            }
            else
            {
                res = fieldDesciption;
            }
            return(res);
        }
Ejemplo n.º 3
0
        public ConstsUniverse()
        {
            try
            {
                //Попытка загрузить значения из файла.
                //Try load values from file.
                SerializeHandler.FieldValuesFromXml(this, File.ReadAllText(DefaultConfigFile));
            }
            catch
            {
                string sMessageBoxText = LanguageHandler.GetInstance().ConstsUniverseFileCorrupted;
                string sCaption        = "";

                MessageBoxButton btnMessageBox = MessageBoxButton.OKCancel;
                MessageBoxImage  icnMessageBox = MessageBoxImage.None;
                MessageBoxResult messageBoxRes = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);
                if (messageBoxRes == MessageBoxResult.OK)
                {
                    SaveToFile();
                }
                else
                {
                    Environment.Exit(0);
                }
            }
        }
Ejemplo n.º 4
0
        private void buttonLoadUniverse_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".tssun";
            dlg.Filter     = "TSS Universe (.tssun)|*.tssun";
            bool?dialogRes = dlg.ShowDialog();

            if (dialogRes == true)
            {
                string   filename = dlg.FileName;
                Universe universe = null;
                try
                {
                    universe = SerializeHandler.FromBase64String <Universe>(File.ReadAllText(filename));
                }
                catch
                {
                    MessageBox.Show(LanguageHandler.GetInstance().UniverseFileCorrupted);
                    return;
                }
                if (universe != null)
                {
                    WindowUniverseOutput.ShowModal(
                        universe,
                        new Size(defPixelsWidth, defPixelsHeight)
                        );
                }
            }
        }
 WindowCheckAtField(RenderManagerCheckAtField renderManagerCheckAtField)
 {
     InitializeComponent();
     applyButton.Content            = LanguageHandler.GetInstance().ApplyButtonText;
     buttonCheckAll.Content         = LanguageHandler.GetInstance().CheckAllButton;
     buttonUncheckAll.Content       = LanguageHandler.GetInstance().UncheckAllButton;
     this.renderManagerCheckAtField = renderManagerCheckAtField;
 }
Ejemplo n.º 6
0
 WindowUniverseSizeGetter()
 {
     InitializeComponent();
     labelWidth.Content   = LanguageHandler.GetInstance().LabelWidthText;
     labelHeight.Content  = LanguageHandler.GetInstance().LabelHeightText;
     buttonOk.Content     = LanguageHandler.GetInstance().ButtonOk;
     buttonCancel.Content = LanguageHandler.GetInstance().ButtonCancel;
 }
        public RenderTargetBitmap DrawCellInfo(Cell cell, double maxTextWidth, double size, Brush textBrush)
        {
            int desc, hunger, aggression, reproduction,
                friendly, poisonAddiction, corpseAddiction, cellsCount;

            if (cell?.GetGenome() == null)
            {
                desc            = 0;
                hunger          = 0;
                aggression      = 0;
                reproduction    = 0;
                friendly        = 0;
                poisonAddiction = 0;
                corpseAddiction = 0;
                cellsCount      = -1;
            }
            else
            {
                desc            = cell.GetDescriptor();
                hunger          = cell.GetGenome().GetHunger();
                aggression      = cell.GetGenome().GetAggression();
                reproduction    = cell.GetGenome().GetReproduction();
                friendly        = cell.GetGenome().GetFriendly();
                poisonAddiction = cell.GetGenome().GetPoisonAddiction();
                corpseAddiction = cell.GetGenome().GetCorpseAddiction();
                cellsCount      = cell?.GetCellsCountWithThisDescriptor() ?? -1; //-V3022
            }

            string cellInfoStr = string.Format(
                LanguageHandler.GetInstance().CellInfoStringFormatter,
                hunger, aggression, reproduction, friendly, poisonAddiction, corpseAddiction, cellsCount
                );

            DrawingVisual  drawingVisual = new DrawingVisual();
            DrawingContext dc            = drawingVisual.RenderOpen();
            FormattedText  ft            = new FormattedText(
                cellInfoStr,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                typeface,
                size,
                textBrush
                );

            ft.MaxTextWidth = maxTextWidth;
            dc.DrawText(ft, new Point(0, 0));
            dc.DrawRectangle(
                GraphicsHelper.BrushByDescriptor(desc),
                null,
                new Rect(new Point(size * 0.2, ft.Height), new Size(ft.Width - size * 2 + 1, size))
                );
            dc.Close();
            return(GraphicsHelper.DrawingVisualRender(drawingVisual));
        }
Ejemplo n.º 8
0
 void InitTextOfControls()
 {
     if (!IsInitialized)
     {
         return;
     }
     Title = LanguageHandler.GetInstance().MainWindowTitle;
     buttonCreatUniverse.Content = LanguageHandler.GetInstance().ButtonCreateUniverse;
     buttonLoadUniverse.Content  = LanguageHandler.GetInstance().ButtonLoadUniverse;
     buttonAbout.Content         = LanguageHandler.GetInstance().ButtonAbout;
 }
 void ResetResolution(double pixelsWidth, double pixelsHeight)
 {
     if (pixelsWidth < 100 || pixelsWidth > 2000 || pixelsHeight < 100 || pixelsHeight > 2000)
     {
         MessageBox.Show(LanguageHandler.GetInstance().ResolutionWarningMessage);
         return;
     }
     InvokeByPause(() =>
     {
         renderManagerMainField = new RenderManagerMainField(UniverseProperty.Width, UniverseProperty.Height, pixelsWidth, pixelsHeight);
     });
 }
 void OpenPoisonPlaceRedactor()
 {
     InvokeByPause(() =>
     {
         UniverseProperty.SetAllPlaceOfPoison(
             WindowCheckAtField.ShowModal(
                 RenderManagerMainFieldProperty,
                 RenderManagerMainFieldProperty.BtmPoison,
                 UniverseProperty.GetAllPlaceOfPoison(),
                 LanguageHandler.GetInstance().ModalWindowAboutPoisonPlace
                 )
             );
     });
 }
 static void OnOutOfMemory(WindowUniverseOutput window, UniverseOutputManager universeOutputManager)
 {
     try
     {
         universeOutputManager.Dispose();
         GC.Collect();
         window.Dispatcher.Invoke(() =>
         {
             window.Close();
         });
     }
     catch { }
     MessageBox.Show(LanguageHandler.GetInstance().OutOfMemory);
 }
 WindowValuesRedactor(ValuesRedactor valuesRedactor)
 {
     InitializeComponent();
     applyButton.Content = LanguageHandler.GetInstance().ApplyButtonText;
     Title = LanguageHandler.GetInstance().WindowTitleOfUniverseConstsRedactor;
     this.valuesRedactor = valuesRedactor;
     valuesRedactor.CreateControlsForObject(stackPanel);
     stackPanel.KeyDown += (s, e) =>
     {
         if (e.Key == Key.Enter)
         {
             TryToConfirm();
         }
     };
 }
Ejemplo n.º 13
0
        /// <summary>
        /// This function try to convert ControlAndInfo values. If the type of error when converting will be ParsebleException, function throws it.
        /// All other errors are processed and return an error message via errorMessage.
        /// <para></para>
        /// Эта функция пытается конвертировать значения ControlAndInfo. Если тип ошибки при конвертировании будет ParsebleException, то она выкинет ее.
        /// Все остальные ошибки обработаются и вернут сообщени об ошибке через errorMessage.
        /// </summary>
        object TryToConvert(out string errorMessage, ControlAndInfo controlAndInfo, FieldInfo fieldInfo)
        {
            //Shit-code, i know. But it`s only way i find to make it work.
            Type   fieldType    = fieldInfo.FieldType;
            object controlValue = null;
            string errMsg       = "";

            try
            {
                controlValue = GetValueFromControl(controlAndInfo.Control, fieldType);
                if (controlValue == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                if (typeof(ParsebleException).IsAssignableFrom(ex.GetType()))
                {
                    throw;
                }
                else
                {
                    errMsg += string.Format(LanguageHandler.GetInstance().IncorrectValueMsg, fieldInfo.Name, fieldType.Name);
                }
            }
            double min = controlAndInfo.Min, max = controlAndInfo.Max;

            try
            {
                if (min < max)
                {
                    double value = Convert.ToDouble(GetValueFromControl(controlAndInfo.Control));
                    if (!(value >= min && value <= max))
                    {
                        throw new Exception();
                    }
                }
            }
            catch
            {
                errMsg += string.Format(LanguageHandler.GetInstance().IncorrectRangeMsg, fieldInfo.Name, min, max);
            }
            errorMessage = errMsg;
            return(controlValue);
        }
Ejemplo n.º 14
0
 void TryToConfirm()
 {
     try
     {
         int w, h;
         w = Convert.ToInt32(textBoxWidth.Text);
         h = Convert.ToInt32(textBoxHeight.Text);
         if (w < 2 || w > 1000 || h < 2 || h > 1000)
         {
             throw new Exception();
         }
         size = new Tuple <int, int>(w, h);
         Close();
     }
     catch
     {
         MessageBox.Show(LanguageHandler.GetInstance().UniverseSizeWarning);
     }
 }
        public RenderTargetBitmap DrawUniverseInfo(Universe universe, double maxTextWidth, double size, Brush textBrush)
        {
            int  cellsCount       = universe.GetCellsCount();
            long totalEnergy      = universe.GetTotalUniverseEnergy();
            long tick             = universe.GetTicksCount();
            Cell cell             = universe.GetMostFitCell();
            int  w                = universe.Width;
            int  h                = universe.Height;
            int  typesOfCellCount = universe.TypesOfCellsCount;

            string unInfoStr = string.Format(
                LanguageHandler.GetInstance().UniverseInfoStringFormatter,
                w, h, cellsCount, totalEnergy, tick, typesOfCellCount
                );

            DrawingVisual  drawingVisual = new DrawingVisual();
            DrawingContext dc            = drawingVisual.RenderOpen();
            FormattedText  ft            = new FormattedText(
                unInfoStr,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                typeface,
                size,
                textBrush
                );

            ft.MaxTextWidth = maxTextWidth;
            dc.DrawText(ft, new Point(0, 0));
            ImageSource dvCellInfo = DrawCellInfo(cell, maxTextWidth, size, textBrush);

            dc.DrawImage(dvCellInfo, new Rect(
                             new Point(size, ft.Height),
                             new Size(dvCellInfo.Width, dvCellInfo.Height)
                             ));

            dc.Close();
            return(GraphicsHelper.DrawingVisualRender(drawingVisual));
        }
        /// <summary>
        /// It attaches events to IUniverseOutputUIElement.
        /// <para></para>
        /// Прикрепляет к IUniverseOutputUIElement события.
        /// </summary>
        void InitializeEvents()
        {
            mouseDownOnFieldImage = (s, ev) =>
            {
                try
                {
                    if (UniverseProperty != null)
                    {
                        Image          image   = s as Image;
                        Point          pos     = ev.GetPosition(image);
                        PointInt       posCube = RenderManagerMainFieldProperty.GetCubePosition(pos.X, pos.Y, image.ActualWidth, image.ActualHeight);
                        UniverseObject uo      = UniverseProperty.GetMatrixElement(posCube.X, posCube.Y);
                        if (uo is Cell)
                        {
                            WindowImage.ShowModal(
                                RenderManagerInfoTextProperty.DrawCellInfo(uo as Cell, maxInfoTextWidth, infoTextFontSize, Brushes.Black),
                                LanguageHandler.GetInstance().CellInfoWindowTitle
                                );
                        }
                    }
                }
                catch { }
            };
            universeOutputUIElement.ImageUniverseField.MouseDown += mouseDownOnFieldImage;

            universeOutputUIElement.OnStart = delegate
            {
                StartWork();
            };
            universeOutputUIElement.OnPause = delegate
            {
                PauseWorkAsync();
            };
            universeOutputUIElement.OnExit = delegate
            {
                Dispose();
            };
            universeOutputUIElement.OnOpenUniverseConstsRedactor = delegate
            {
                OpenUniverseConstsRedactor();
            };
            universeOutputUIElement.OnOpenFoodPlaceRedactor = delegate
            {
                OpenFoodPlaceRedactor();
            };
            universeOutputUIElement.OnOpenPoisonPlaceRedactor = delegate
            {
                OpenPoisonPlaceRedactor();;
            };
            universeOutputUIElement.OnClearUniverseField = delegate
            {
                ClearUniverseField();
            };
            universeOutputUIElement.OnGenerateCells = delegate
            {
                if (universeOutputUIElement.CountOfCellsToGenerate != null)
                {
                    GenerateCells((int)universeOutputUIElement.CountOfCellsToGenerate);
                }
            };
            universeOutputUIElement.OnGenerateFoodOnAllField = delegate
            {
                GenerateFoodOnAllField();
            };
            universeOutputUIElement.OnResetResolution = delegate
            {
                if (universeOutputUIElement.ResolutionToReset == null)
                {
                    return;
                }
                Size resolution = (Size)universeOutputUIElement.ResolutionToReset;
                ResetResolution(resolution.Width, resolution.Height);
            };
            universeOutputUIElement.OnSaveUniverse = delegate
            {
                SaveUniverse();
            };
            universeOutputUIElement.OnGetWorkDeley = delegate
            {
                GetWorkDelay();
            };
        }
Ejemplo n.º 17
0
 private void buttonAbout_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show(LanguageHandler.GetInstance().AboutText);
 }
Ejemplo n.º 18
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            int    w = 200, h = 120;
            double wPix = 1000, hPix = 1000;

            image.StretchDirection  = StretchDirection.Both;
            image1.StretchDirection = StretchDirection.Both;
            MouseButtonEventHandler mouseDownOnImage = (s, ev) =>
            {
                if (un != null)
                {
                    //double modificator =
                    Point          pos     = ev.GetPosition(s as Image);
                    PointInt       posCube = rm.GetCubePosition(pos.X, pos.Y, image.ActualWidth, image.ActualHeight);
                    UniverseObject uo      = un.GetMatrixElement(posCube.X, posCube.Y);
                    if (uo is Cell)
                    {
                        WindowImage.ShowModal(
                            ritm.DrawCellInfo(uo as Cell, 400, 20, Brushes.Black),
                            LanguageHandler.GetInstance().CellInfoWindowTitle
                            );
                    }
                }
            };

            image.MouseDown += mouseDownOnImage;
            thr              = new Thread(() =>
            {
                Thread.CurrentThread.Priority = ThreadPriority.Highest;

                un = new Universe(w, h);
                un.GenerateCells(5);
                rm   = new RenderManagerMainField(w, h, wPix, hPix);
                ritm = new RenderManagerInfoText();
                while (thr == Thread.CurrentThread)
                {
                    un.DoUniverseTick();
                    ImageSource img = rm.RenderField(un.GetAllDescriptors());
                    img.Freeze();
                    ImageSource info = ritm.DrawUniverseInfo(un, 300, 20, Brushes.Black);
                    info.Freeze();
                    try
                    {
                        image.Dispatcher.Invoke(() =>
                        {
                            image.Source = img;
                        });
                        image1.Dispatcher.Invoke(() =>
                        {
                            image1.Source = info;
                        });
                    }
                    catch
                    {
                        thr = null;
                    }
                    Thread.Sleep(30);
                }
                image.MouseDown -= mouseDownOnImage;
            });
            AppDomain.CurrentDomain.ProcessExit += delegate
            {
                thr = null;
            };
            thr.Start();
        }