Ejemplo n.º 1
0
 protected static Func <object> CreateDataResolver(UniverseObject target)
 {
     if (target == null)
     {
         return(() => null);
     }
     return(() => GameContext.Current.Universe.Objects[target.ObjectID]);
 }
Ejemplo n.º 2
0
    public void Init(UniverseObject universeObject, UniverseView universeView)
    {
        this.universeView   = universeView;
        this.universeObject = universeObject;

        universeObject.Listener = this;

        parentView = universeView.GetPlanetView(universeObject.parent);

        UpdatePosition();
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Awake()
    {
        Instance = this;
        uo       = new UniverseObject();
        uo.Init();
        uo.uv      = this;
        universeID = UnityEngine.Random.value;//不知道传输精度会不会导致问题
        long idTemp = (long)(universeID * 10000000.0f);

        universeID  = (float)(idTemp % 10000000);
        universeID /= 1000.0f;
        //Debug.Log("uo ini232323234234234t");
    }
Ejemplo n.º 4
0
    public void OnUniverseObjectAdded(UniverseObject universeObject)
    {
        if (universeObject is UniverseEngine.Avatar)
        {
            avatarView = universeFactory.GetAvatar();
            avatarView.Init((UniverseEngine.Avatar)universeObject, this);

            tilemapObjectViews.Add(avatarView);
        }
        else if (universeObject is UniverseEngine.Ship)
        {
            shipView = universeFactory.GetShip();
            shipView.Init((UniverseEngine.Ship)universeObject, this);

            tilemapObjectViews.Add(shipView);
        }
    }
Ejemplo n.º 5
0
 public UniverseObjectInfoCardSubject([NotNull] UniverseObject target)
     : base(CreateDataResolver(target))
 {
     Target = target;
 }
 public void OpenInfoBox(UniverseObject objectToShow)
 {
     currentObject = objectToShow;
     SetValues();
     animator.SetTrigger("Toggle");
 }
Ejemplo n.º 7
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();
        }
        /// <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();
            };
        }