Exemplo n.º 1
0
 /// <summary>
 /// Inserts an image into the list according to its depth.
 /// </summary>
 public void InsertImage(SceneImage newImage)
 {
     for (int i = 0; i < Images.Count; i++)
     {
         if (Images[i].depth < newImage.depth)
         {
             Images.Insert(i, newImage);
             return;
         }
     }
     Images.Add(newImage);
 }
Exemplo n.º 2
0
        public void Update(MenuScene owner)
        {
            if (!alive)
            {
                return;
            }
            int handle = 0;

            Vector2?mousePos = Input.mousePosition;

            // Fade out handles not close to the mouse
            MenuIllustration closestIllust = null;

            {
                float minIllustDist = 20f * 20f;
                for (int i = 0; i < owner.subObjects.Count; i++)
                {
                    if (!(owner.subObjects[i] is MenuIllustration illust))
                    {
                        continue;
                    }
                    float dist = Vector2.SqrMagnitude(illust.pos + illust.size / 2f - mousePos.Value);
                    if (minIllustDist > dist)
                    {
                        closestIllust = illust;
                        minIllustDist = dist;
                    }
                }
            }

            // Update move handles
            for (int i = 0; i < owner.subObjects.Count; i++)
            {
                if (!(owner.subObjects[i] is MenuIllustration illust))
                {
                    continue;
                }
                if (!customRep.TryGet(illust, out SceneImage csi))
                {
                    continue;
                }

                Vector2 centerPos = illust.pos + illust.size / 2f;
                if (handles.Count <= handle)
                {
                    handles.Add(new MoveHandle(csi.DisplayName));
                }
                handles[handle].SetVisible(illust.sprite.concatenatedAlpha > 0f);
                handles[handle].Update(ref centerPos, ref mousePos, closestIllust != null && closestIllust != illust);
                illust.pos = centerPos - illust.size / 2f;
                csi.Pos    = illust.pos;
                handle++;
            }

            // Save on request
            if (Input.GetKeyDown(KeyCode.LeftBracket))
            {
                CustomScene sceneToSave = null;
                foreach (var subObj in owner.subObjects)
                {
                    if (!(subObj is MenuIllustration illust))
                    {
                        continue;
                    }

                    SceneImage csi = customRep[illust];
                    if (csi != null && csi.Owner.dirty)
                    {
                        sceneToSave = csi.Owner;
                        break;
                    }
                }

                if (sceneToSave != null)
                {
                    SaveEditedScene(sceneToSave);
                }
            }
        }