/// <summary>
        /// GUI constructor initiates a List of containers and assigns currently hovered elements. Also makes GUI visible/hidden
        /// </summary>
        public GraphicInterface(Engine engine)
        {
            containers         = new List <Container>();
            hovered_container  = null;
            hovered_unit       = null;
            visible            = true;
            locked             = false;
            outline_containers = false;
            this.engine        = engine;

            textengine = new TextEngine(engine.get_UI_font(), Rectangle.Empty, Vector2.Zero, Color.White); // creating a textengine inside GUI
        }
 /// <summary>
 /// Change slider value by holding left mouse button
 /// </summary>
 /// <param name="e">Unit'engine name</param>
 /// <param name="mouse">Mouse position</param>
 public void update_slider_values(UIElementBase unit, Vector2 mouse)
 {
     foreach (Container c in containers)
     {
         foreach (UIElementBase u in c.get_element_list())
         {
             if (u == unit) // find specified element
             {
                 // update slider value based on mouse movement
                 if (u is Slider)
                 {
                     Slider tmp = (Slider)u;
                     tmp.update(mouse);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds an element to Container. Container bounds recalculated automatically based on number of elements in it
        /// </summary>
        /// <param name="engine">Unit reference</param>
        public void add_element(UIElementBase u)
        {
            u.set_parent(this);

            if (u.get_rectangle().Y == -1)
            {
                u.modify_bounds(u.get_rectangle().X, bounds.Height, u.get_rectangle().Width, u.get_rectangle().Height);
            }

            if (bounds.Width < (u.get_rectangle().Width + u.get_rectangle().X))
            {
                bounds.Width = u.get_rectangle().Width + u.get_rectangle().X;
            }

            bounds.Height = u.get_rectangle().Height + u.get_rectangle().Y;

            stored_elements.Add(u);

            // recalculate a serializeable surrogate for Rectangle type
            bounds_surrogate = Engine.rectangle_to_delimited_string(bounds);
        }
        /// <summary>
        /// Detects hovered on any GUI element and assigns names for hovered container/unit
        /// </summary>
        /// <param name="engine">Engine object reference</param>
        /// <returns>true/false value representing GUI hover</returns>
        public bool hover_detect()
        {
            if (locked) // testing - if GUI is locked - don't update hover detection until lock is removed
            {
                return(true);
            }

            hovered_container = null;
            hovered_unit      = null;
            // detect hovered container

            // update states
            update_all_component_states(/*engine*/);
            foreach (Container c in containers)
            {
                if (c.get_rectangle().Intersects(engine.get_mouse_rectangle()) &&
                    c.is_visible())
                {                          // container is hovered
                    hovered_container = c; // assume that no containers are intersecting
                    action_list[0]    = c.get_action();

                    foreach (UIElementBase e in c.get_element_list())
                    {
                        // calculate element rectangle by adding container origin
                        Rectangle real_rectangle = new Rectangle(c.get_rectangle().X + e.get_rectangle().X, c.get_rectangle().Y + e.get_rectangle().Y, e.get_rectangle().Width, e.get_rectangle().Height);

                        if (real_rectangle.Intersects(engine.get_mouse_rectangle()) && e.is_visible())
                        {// element is hovered
                            hovered_unit   = e;
                            action_list[1] = e.get_action();
                            return(true);
                        }
                    }
                    return(true); // this code is reached if a container is hovered and even if no elements is hovered
                }
            }
            return(false);
        }