// TODO: maybe use endless interfaces so we can request something that is actually a ui thing, eh? public void AddKeyFocus(Trigger key, ZComponent focus, Action onSwitchAction, bool pressAgainToRevert) { RegisterListener(new InputListener(key, x => { onSwitchAction(); currentFocus = focus; focus.Focus(); var escapeListeners = new List <InputListener>(); var escapeTriggers = new List <Trigger>() { Trigger.Escape, Trigger.LeftMouseClick }; if (pressAgainToRevert) { escapeTriggers.Add(key); } foreach (var trigger in escapeTriggers) { var listener = new InputListener(trigger, y => { defaultFocus.Focus(); currentFocus = defaultFocus; foreach (var l in escapeListeners) { focus.UnregisterListener(l); } }); focus.RegisterListener(listener); escapeListeners.Add(listener); } })); }
private void SimulateKeyPress(MockInputManager mockInputManager, UIContext uiContext, Keys key) { mockInputManager.SetKeysDown(key); ZComponent.NotifyListeners(uiContext); mockInputManager.SetKeysDown(null); ZComponent.NotifyListeners(uiContext); }
public Light(ZComponent parent) : base(parent) { Enabled = true; SpotDirection = new Vector3(0, 0, -1); SpotCutoff = 45; }
public Camera(ZComponent parent) : base(parent) { Position = new Vector3(0, 0, 5); Target = new Vector3(0, 0, 0); UpVector = Vector3.UnitY; ClipNear = 0.1f; ClipFar = 1000.0f; }
protected override void Update(GameTime gameTime) { ZComponent.NotifyListeners(uiContext); uiContext.UpdateGameTime(gameTime); // TODO: Add your update logic here uiContext.Camera.Update(uiContext); mainGameObject.Update(uiContext); uiContext.UpdateKeys(); base.Update(gameTime); }
public void CreateOrUpdateComponent(ZComponent zComponent, GameObject gameObject) { switch (zComponent.ComponentCase) { case ZComponent.ComponentOneofCase.Behaviour: CreateOrUpdateBehaviour(zComponent.Behaviour, gameObject); break; case ZComponent.ComponentOneofCase.CanvasRenderer: UpdateCanvasRenderer(zComponent.CanvasRenderer, gameObject); break; } }
public CompositionTemplate() { references = new ReferenceDataComponent(); var nameText = new BasicText(); nameText.position = new Vector2(5, 5); Register(references); var tracker = new PointCollectionTracker <Reference>(references, x => { return((TemplateManager.LOADED_TEMPLATES[x.name].GetBoundingBox().Min + TemplateManager.LOADED_TEMPLATES[x.name].GetBoundingBox().Max) / 2 + x.position); }); selector = new Selector <Reference>(new CameraSelectionProvider <Reference>(tracker), x => { referenceOutlines[x].boxColor = Color.Orange; nameText.text = GetSelectedText(selector.selected); }, x => { referenceOutlines[x].boxColor = Color.White; nameText.text = GetSelectedText(selector.selected); }); Register(selector, nameText); RegisterListener(new InputListener(Trigger.E, x => { if (selector.selected.Count != 1) { return; } editMode = true; editingItem = TemplateManager.LOADED_TEMPLATES[selector.selected.Single().name]; editingItem.Focus(); var listener = new InputListener(Trigger.Escape, y => { editingItem.UnregisterListener(y); this.Focus(); RecalculateBoundingBoxes(); editingItem = null; editMode = false; }); editingItem.RegisterListener(listener); })); }
//public delegate void ModelMethod(ZComponent caller); //[Browsable(false), CategoryAttribute("Expressions")] //[MethodSignature("public override void OnUpdate()")] //public VirtualMethod OnUpdateExpr = new VirtualMethod(); //[Browsable(false), CategoryAttribute("Expressions")] //[MethodSignature("public override void OnRender()")] //public VirtualMethod OnRenderExpr = new VirtualMethod(); public Model(ZComponent parent) : base(parent) { Scale = new Vector3(1, 1, 1); BindCallbacks(); if (App != null) App.AddModel(this); }
public List<ZEvent> FindEvents(ZComponent parent) { return eventList.FindAll(it => it.Owner == parent); }
private void RenderComponentForHitTest(ZComponent comp, Dictionary<uint, ZComponent> hitMap, ref uint currentName) { // If the element is disabled, we're done. // Also, never hit test the current camera. if (comp.Enabled == false || comp is Camera) return; if (comp is Group) { // Recurse through the children. foreach (var childElement in comp.Children) RenderComponentForHitTest(childElement, hitMap, ref currentName); } else if (comp is IRenderable) { // Load and map the name. GL.LoadName(currentName); hitMap[currentName] = comp; // Render the bounding volume. //((IVolumeBound) comp).BoundingVolume.Render(gl, RenderMode.HitTest); // Render the object with no materials IRenderable obj = comp as IRenderable; if (obj != null) obj.Render(); // Increment the name. currentName++; } }
public InteractiveCamera(ZComponent parent) : base(parent) { }
private static void ProcessNode(ZComponent parent, IList parent_list, TreeNodeCollection parent_nodes, XmlNode xmlNode) { if (xmlNode == null) return; //Console.WriteLine("Processing: {0}", xmlNode.Name); ZComponent comp = parent; IList list = null; if (xmlNode.Name == "ZApplication") { SetFields(comp, xmlNode); } else { // Check if this node is a List property of the parent FieldInfo fi = parent.GetType().GetField(xmlNode.Name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance); //if (pi != null) Console.WriteLine(" Parent property found: {0}", pi.PropertyType.Name); if (parent is ZComponent && fi != null && typeof(IList).IsAssignableFrom(fi.FieldType)) { //Console.WriteLine("List found: {0}", xmlNode.Name); list = (IList) fi.GetValue(parent); } // Check if this node is a ZCode property of the parent else if (parent is ZComponent && fi != null && typeof(CodeLike).IsAssignableFrom(fi.FieldType)) { CodeLike code = (CodeLike) fi.GetValue(parent); // Activator.CreateInstance(fi.FieldType); code.Text = xmlNode.InnerText; //code.Owner = parent; Console.WriteLine("Code Text:\n{0}", code.Text); fi.SetValue(comp, code); //ZComponent.App.AddComponent(code); return; //no TreeNode should be created for this } else { comp = CreateComponent(xmlNode.Name, xmlNode, parent, parent_list); if (comp == null) { Console.WriteLine("SKIPPING subtree - Cannot find type: {0}", xmlNode.Name); return; } } } TreeNode treeNode = null; if (parent_nodes != null) { string displayName = xmlNode.Name; XmlAttribute attribute = xmlNode.Attributes["Name"]; if (attribute != null) displayName = displayName + " - " + attribute.Value; treeNode = new TreeNode(displayName); parent_nodes.Add(treeNode); // clear subtree if (treeNode != null) treeNode.Nodes.Clear(); } // recursively build SubTree foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element) { if (treeNode != null) ProcessNode(comp, list, treeNode.Nodes, childNode); else ProcessNode(comp, list, null, childNode); } } // construct ZNodeProperties object for the TreeNode and assign it to Tag property object target = (object) list ?? (object) comp; object parentObj = (object) parent_list ?? (object) parent; ZNodeProperties props = new ZNodeProperties(target, parentObj, xmlNode, treeNode); if (list == null) comp.Tag = props; if (_treeView != null) { treeNode.Tag = props; ZTreeView.HighlightTreeNode(treeNode, props); //props.XmlNodePropertyChanged += new XmlNodePropertyChangedEventHandler(_treeView.UpdateNodeText); } }
public Texture(ZComponent parent) : base(parent) { }
private static void SetFields(ZComponent comp, XmlNode xmlNode) { Type type = comp.GetType(); // Add attributes to the properties if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { string val = attribute.Value; FieldInfo fi = type.GetField(attribute.Name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance); if (fi != null) { //Console.WriteLine(" Field found: {0}", attribute.Name); object obj = Deserialize(val, fi.FieldType); if (obj != null) fi.SetValue(comp, obj); /*else if (typeof(ZCode).IsAssignableFrom(fi.FieldType)) //CODE CANNOT BE STORED AS A PROPERTY { ZCode code = (ZCode)Activator.CreateInstance(fi.FieldType); code.Text = val; code.Owner = comp; //Console.WriteLine("Code Text:\n{0}", code.Text); fi.SetValue(comp, code); //ZComponent.App.AddComponent(code); }*/ else if (fi.FieldType.IsSubclassOf(typeof(ZComponent))) { _unresolved.Add(new Unresolved { comp = comp, prop = fi, value = val }); } else Console.WriteLine(" Unsupported field: {0}-{1}", attribute.Name, val); } else Console.WriteLine(" Field not found: {0}-{1}", attribute.Name, val); //properties.Add(new CustomProperty(attribute.Name, attribute.Value, typeof(string), false, true)); } } }
public override void ReplaceOwner(ZComponent parent) { base.ReplaceOwner(parent); if (parent is GUIControl) m_Parent = parent as GUIControl; }
public ProjectiveCamera(ZComponent parent) : base(parent) { }
public MeshSphere(ZComponent parent): base(parent) {}
/// <summary> /// Initializes a new instance of the <see cref="Base"/> class. /// </summary> /// <param name="parent">Parent control.</param> public GUIControl(ZComponent parent): base(parent) { m_Children = new List<GUIControl>(); m_Accelerators = new Dictionary<string, GwenEventHandler>(); if (parent == null || parent is GUIControl) ParentControl = parent as GUIControl; else ParentControl = App.Canvas; m_Hidden = false; m_Bounds = new Rectangle(0, 0, 10, 10); m_Padding = Padding.Zero; m_Margin = Margin.Zero; RestrictToParent = false; MouseInputEnabled = true; KeyboardInputEnabled = false; Invalidate(); Cursor = Cursors.Default; //ToolTip = null; IsTabable = false; ShouldDrawBackground = true; m_Disabled = false; m_CacheTextureDirty = true; m_CacheToTexture = false; BoundsOutlineColor = Color.Red; MarginOutlineColor = Color.Green; PaddingOutlineColor = Color.Blue; }
public MeshBox(ZComponent parent): base(parent) {}
public MeshCylinder(ZComponent parent) : base(parent) { }
public MeshProducer(ZComponent parent) : base(parent) { Scale = Vector3.One; }
public Model CreateClone(ZComponent parent) { if (this.Prototype == false) return null; // you cannot clone a GameObject Model comp = (Model) this.Clone(); // Use the application as a parent if (parent == null) parent = App; if (parent == App) comp.SetOwner(parent, App.Scene); else comp.SetOwner(parent, null); return comp; }
public static void RestoreEvent(ZEvent ev, ZComponent comp, string methodName) { if (comp == null || ev == null || ev.Owner == null) return; //if (ev.Owner is ZApplication || ev.Owner is Model) ev.Owner = comp; //This would be too late: moved to restore // Find the field that is backing the event // GetEvent would not work as we have to null and reset the event (the old delegate must be released) FieldInfo field = GetField(ev.Owner.GetType(), ev.EventName); if (field != null) field.SetValue(ev.Owner, Delegate.CreateDelegate(field.FieldType, comp, methodName)); else Console.WriteLine("Field-like event not found {0} / {1}", ev.Owner.GetType().Name, ev.EventName); }
public MeshHeightmap(ZComponent parent): base(parent) {}
public StateSwitcher() { this.defaultFocus = this; this.currentFocus = this; }
public Material(ZComponent parent) : base(parent) { }
public static ZComponent CreateComponent(string typeName, XmlNode xmlNode, ZComponent parent, IList parent_list) { var type = _types.Find(it => it.Name == typeName); ZComponent comp = null; if (type != null) { //Console.WriteLine("Creating instance of: {0}", type.FullName); comp = (ZComponent) Activator.CreateInstance(type, new object[] { parent }); //ZComponent.App.AddComponent(comp); comp.SetOwner(parent, parent_list); if (xmlNode != null) SetFields(comp, xmlNode); } return comp; }
public OrthoCamera(ZComponent parent) : base(parent) { }
public void ChangeScreen(ZComponent p_nextScreen) { m_currentScreen = p_nextScreen; m_currentScreen.Initialize(); m_currentScreen.LoadContent(); }
public override void SetOwner(ZComponent parent, IList parent_list) { base.SetOwner(parent, parent_list); if (parent == null || parent is GUIControl) ParentControl = parent as GUIControl; else ParentControl = App.Canvas; // Use App.Canvas if the parent is not a GUIControl }
private void AddElementToTree(ZComponent component, TreeNodeCollection nodes) { // Add the element. TreeNode newNode = new TreeNode() { Tag = component }; newNode.Text = component.GetType().Name; if (component.HasName()) newNode.Text = newNode.Text + ": " + component.Name; else newNode.Text += " (No name)"; nodes.Add(newNode); // Add each child. //if (component.GetType() == typeof(Model)) foreach (var element in component.Children) AddElementToTree(element, newNode.Nodes); }
/*private static void FindFields(IList<FieldInfo> fields, Type t) { var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; fields.AddRange(t.GetFields(flags)); var baseType = t.BaseType; if (baseType != null) FindFields(fields, baseType); }*/ public static void MemberwiseCopy(ZComponent newObj, Type newType, ZComponent oldObj, Type oldType) { foreach (FieldInfo dest in newType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (dest.Name == "ID") continue; if (typeof(Delegate).IsAssignableFrom(dest.FieldType)) { //Console.WriteLine("Skipping Delegate: {0}", dest.Name); continue; // Delegates (i.e. field-like events) are not copied } // Check if this node is a List property of the parent FieldInfo src = oldType.GetField(dest.Name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (src != null && src.FieldType == dest.FieldType) { //Console.WriteLine("Setting Field of {0}: {1} {2}->{3}", dest.DeclaringType.Name, dest.Name, src.FieldType.Name, dest.FieldType.Name); dest.SetValue(newObj, src.GetValue(oldObj)); } //else // Console.WriteLine("Field not found: {0} {1}->{2}", dest.Name, (src != null) ? src.FieldType.Name : "NONE", dest.FieldType.Name); } // Walk the type hierarchy recursively in order to copy the private fields in the base classes as well if (newType.BaseType != typeof(Object) && oldType.BaseType != typeof(Object)) { // The type of newObj might be higher in the hierarchy (e.g. SomeModel vs. Model) // We need to level the playing field if (newType.BaseType.Name == oldType.Name) MemberwiseCopy(newObj, newType.BaseType, oldObj, oldType); else MemberwiseCopy(newObj, newType.BaseType, oldObj, oldType.BaseType); } }
public void AddNewComponent(ZComponent comp) { Type type = comp.GetType(); // Do NOT register ZApplication and its derived classes if (typeof(ZApplication).IsAssignableFrom(type)) return; allComponents.Add(comp); // Store the name in the name cache if (comp.HasName()) nameCache[comp.Name] = comp; // TODO: consider all ancestor types if (!typeMap.ContainsKey(type)) typeMap[type] = new HashSet<ZComponent>(); typeMap[type].Add(comp); }
public static void Restore(ZComponent newObj, ZComponent oldObj) { if (newObj == null || oldObj == null) return; //Console.WriteLine("Restore: {0}({1}) -> {2}({3})", oldObj.GetType().Name, oldObj.Name ?? "", newObj.GetType().Name, newObj.Name ?? ""); MemberwiseCopy(newObj, newObj.GetType(), oldObj, oldObj.GetType()); // A reference to oldObj should be updated to newObj in its Children foreach (ZComponent child in newObj.Children) { if (child.Owner == oldObj) child.ReplaceOwner(newObj); } // If it is NOT a ZApplication if (typeof(ZApplication).IsAssignableFrom(newObj.GetType()) == false) { ZComponent.App.RemoveComponent(oldObj); // remove the old component //ZComponent.App.AddNewComponent(newObj); // add the new component // We should always set the Owner <= old Owner has been copied to newObj if (newObj.OwnerList != null) // replace old object in OwnerList { //newObj.OwnerList = oldObj.OwnerList; int idx = newObj.OwnerList.IndexOf(oldObj); if (idx != -1) newObj.OwnerList[idx] = newObj; } else if (newObj.Owner != null) // replace old object among Owner's Children { int idx = newObj.Owner.Children.IndexOf(oldObj); if (idx != -1) newObj.Owner.Children[idx] = newObj; } oldObj.ReplaceOwner(null); if (typeof(Model).IsAssignableFrom(newObj.GetType())) { ZComponent.App.RemoveModel(oldObj as Model); Model newMod = newObj as Model; // Find named reference in App (only necessary for GameObjects) if (newMod != null && newMod.Prototype == false && newMod.HasName()) { FieldInfo fi = ZComponent.App.GetType().GetField(newMod.Name, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null && fi.FieldType == newObj.GetType()) { //Console.WriteLine("Setting named reference {0} / {1}", fi.Name, fi.FieldType.Name); fi.SetValue(ZComponent.App, newObj); } } // Clear the static CustomGame reference 'App' in the old model classes // It is enough to do this for the prototypes (there is one prototype for each class) // If we don't null this, the old application will never be finalized if (newMod.Prototype) { FieldInfo fi = oldObj.GetType().GetField("App", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (fi != null) { //Console.WriteLine("Setting named reference {0} / {1}", fi.Name, fi.FieldType.Name); fi.SetValue(oldObj, null); } } } } // Correct the Treeview tags ZNodeProperties props = newObj.Tag as ZNodeProperties; if (props != null) { props.Component = newObj; TreeNode treeNode = props.treeNode; if (treeNode != null) foreach (TreeNode childNode in treeNode.Nodes) { ZNodeProperties props1 = childNode.Tag as ZNodeProperties; // Clear the reference to oldObj in the ZNodeProperties of all children / member lists if (props1 != null && props1.Parent == oldObj) { props1.Parent = newObj; } /*foreach (TreeNode grandchildNode in childNode.Nodes) { ZNodeProperties props2 = grandchildNode.Tag as ZNodeProperties; if (props2 != null && props2.parent_component == oldObj) { props2.parent_component = newObj; // oldObj can also be the Owner of its grandchildren (in various member lists) // this reference must be updated to newObj ZComponent grandchild = props2.component as ZComponent; if (grandchild != null && grandchild.Owner == oldObj) grandchild.Owner = newObj; } }*/ } } // oldObj can also be the Owner of its grandchildren (in various member lists) // the Owner reference must be updated to newObj in all components foreach(ZComponent comp in ZComponent.App.GetAllComponents()) if (comp.Owner == oldObj) comp.ReplaceOwner(newObj); // oldObj can also be the Owner of ZEvent instances // update the Owner reference to newObj foreach (ZEvent ev in ZComponent.App.FindEvents(oldObj)) ev.Owner = newObj; // If it is a ZApplication if (typeof(ZApplication).IsAssignableFrom(newObj.GetType())) { // Check named references in CustomGame foreach(FieldInfo fi in newObj.GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { // If the named reference is null, then try to find the component // This is necessary for all newly-added or renamed components if (fi.GetValue(newObj) == null) { ZComponent comp = ZComponent.App.Find(fi.Name); if (comp != null && fi.FieldType == comp.GetType()) { Console.WriteLine("Setting new named reference {0} / {1}", fi.Name, fi.FieldType.Name); fi.SetValue(newObj, comp); } } } } // If the oldObj was selected in the editor, then we have to replace it with newObj if (editor.SelectedComponent == oldObj) { editor.SelectedComponent = newObj; //Console.WriteLine("SelectedComponent changed to {0}", newObj.GetType().AssemblyQualifiedName); } }
public void RemoveComponent(ZComponent comp) { Type type = comp.GetType(); // Do NOT register ZApplication and its derived classes if (typeof(ZApplication).IsAssignableFrom(type)) return; allComponents.Remove(comp); //if (comp.HasName()) nameCache.Remove(comp.Name); // Remove the component from the nameMap - if necessary foreach (var item in nameCache.Where(kvp => kvp.Value == comp).ToList()) { nameCache.Remove(item.Key); } // TODO: consider all ancestor types if (typeMap.ContainsKey(type)) { typeMap[type].Remove(comp); if (typeMap[type].Count == 0) typeMap.Remove(type); } }
public StateSwitcher(ZComponent defaultFocus) { this.defaultFocus = defaultFocus; this.currentFocus = defaultFocus; }
public void RefreshName(ZComponent comp, string name, string oldName) { if (oldName != null) nameCache.Remove(oldName); // Remove the component from the nameMap - if necessary foreach (var item in nameCache.Where(kvp => kvp.Value == comp).ToList()) { nameCache.Remove(item.Key); } if (comp.HasName()) nameCache[comp.Name] = comp; }
public ZEvent FindEvent(ZComponent parent, string eventName) { ZEvent result = null; result = eventList.Find(it => it.Owner == parent && it.EventName == eventName); return result; }
public ScreenManager() { m_currentScreen = null; }