public static SelectonViewButton Get(IMarkerParentObject p_obj, SelectionViewer p_parent, GameObject template) { GameObject game_object = Instantiate(template); var res = Loader.EnsureComponent <SelectonViewButton>(game_object); res.referred = p_obj; return(res); }
public void TgtMarkerClickedL(MapTgtMarker own) { IMarkerParentObject sc_obj = own.LinkedObject; if (selection.Contains(sc_obj)) { selection_viewer.Remove(sc_obj); } else { selection_viewer.Add(sc_obj); } }
private void AddSelectorFromMarker(MapTgtMarker marker) { if (!selector_list.TrueForAll(x => x.marker != marker)) { return; } IMarkerParentObject sc_obj = marker.LinkedObject; Vector2 position = (Vector2)marker.RectTransform.position + new Vector2(100, 100); Vector2 anchorposition = marker.RectTransform.position + new Vector3(marker.RectTransform.sizeDelta.x / 2f, 0); Selector sel = AddSelectorForSceneObject(sc_obj, position, anchorposition, marker.GetComponent <Image>().color); sel.marker = marker; }
// +-------------------------+ // | | // | PUBLIC FUNCTIONS | // | | // +-------------------------+ /// <summary> Should be called, if a SceneObject gets initiated </summary> /// <param name="obj"> The SceneObject, that gets initiated </param> public void ObjectSpawned(IMarkerParentObject obj) { GameObject map_pointer = Instantiate(GameObject.Find("map_pointer_template")); map_pointer.name = string.Format("Indicator ({0})", obj.Name); var img = map_pointer.GetComponent <Image>(); map_pointer.transform.SetParent(SceneGlobals.map_canvas.transform); MapTgtMarker map_image = map_pointer.GetComponent <MapTgtMarker>(); map_image.img = img; map_image.LinkedObject = obj; obj.Marker = map_image; }
public void Remove(IMarkerParentObject p_obj) { selected.Remove(p_obj); SelectonViewButton button = button_dict [p_obj]; int indx = buttons.IndexOf(button); button_dict.Remove(p_obj); buttons.Remove(button); button.DeSelect(); Destroy(button.gameObject); for (int i = indx; i < buttons.Count; i++) { buttons [i].transform.position += new Vector3(0, button_dimensions.y); } content.sizeDelta = new Vector2(content.sizeDelta.x, selected.Count * button_dimensions.y); }
public void Add(IMarkerParentObject p_obj) { if (selected.Contains(p_obj) || button_dict.ContainsKey(p_obj)) { return; } SelectonViewButton button = SelectonViewButton.Get(p_obj, this, button_template.gameObject); button.parent = this; content.sizeDelta = new Vector2(content.sizeDelta.x, selected.Count * button_dimensions.y); RectTransform button_rect = button.GetComponent <RectTransform>(); button_rect.SetParent(content); button_rect.anchoredPosition = new Vector3(button_dimensions.x * .5f, -(selected.Count + .5f) * button_dimensions.y); selected.Add(p_obj); buttons.Add(button); button_dict.Add(p_obj, button); }
public void Init() { if (targets == null) { targets = new IMarkerParentObject[0]; } // Figures out, which things get shown int strng_num = 0; for (int i = 0; i < 4; i++) { if (sub_options [i] != 0) { strng_num++; } } options_str = new string [strng_num]; options_icons = new Sprite [strng_num]; options_flags = new int [strng_num]; option_functions = new int [strng_num]; int indx2 = 0; for (int i = 0; i < 4; i++) { if (sub_options [i] != 0) { options_str [indx2] = Globals.selector_data.main_options [i]; options_icons [indx2] = Globals.selector_data.main_icon[i]; options_flags [indx2] = Globals.selector_data.main_flags [i]; indx2++; } } base.Init(); lineindex = CameraDrawing.AddLine(ConnectionLine); }
/// <summary> /// Adds a selector for a sceneobject, if none is present /// </summary> /// <param name="obj"> The concerned sceneobject </param> /// <param name="position"> The position of the selector in 2D-space on teh screen </param> /// <param name="line_color"> The color of the line conn </param> /// <returns> The selector behaviour </returns> public Selector AddSelectorForSceneObject(IMarkerParentObject obj, Vector2 position, Vector2 anchorposition, Color line_color) { IMarkerParentObject[] obj_arr = new IMarkerParentObject [] { obj }; foreach (Selector sel in selector_list) { if (sel.targets == obj_arr) { return(sel); } } ushort [] sub_options = new ushort[] { 0xf, 0, 0, 0 }; if (obj is ITargetable) { sub_options[1] = 0x7d; } if (obj is Ship | (obj is Target && !(obj as Target).virt_ship)) { sub_options [2] = 0x3; if (obj.Friendly) { sub_options [3] += 0x7f; } else { sub_options [1] += 0x2; } } Selector selector = AddNewSelector(position, anchorposition, line_color, sub_options); selector.targets = obj_arr; selector_list.Add(selector); return(selector); }
public void SelectorClicked(SelectorButton button) { SubSelector concerned = button.parent as SubSelector; if (concerned == null) { return; } byte option = button.num; bool multiple = concerned.targets.Length > 1; for (int i = 0; i < concerned.targets.Length; i++) { // Check Flags if (i != 0 && (button.flags >> 1) % 2 == 0) { // single vessel only goto LOOPEND; } if (i == 0 && button.flags % 2 == 1) { // use pinlabel Debug.Log(DeveloppmentTools.LogIterable(concerned.targets)); concerned_objects = concerned.targets; lasting_command = button.function; } IMarkerParentObject parentObject = concerned.targets[i]; var ship = parentObject as Ship; SelectorOptions options = concerned.options; switch (button.function) { // +-----------------------------------------------------------------------------------------------------------------------+ // | Reference | // +-----------------------------------------------------------------------------------------------------------------------+ case 0x0c: // Set Camera --------------------------------------------------------------------------------------------------------------- SceneGlobals.ReferenceSystem.Offset += parentObject.Position - SceneGlobals.ReferenceSystem.Position; goto LOOPEND; case 0x0d: // Set Reference ------------------------------------------------------------------------------------------------------------ SceneGlobals.map_core.CurrentSystem = new ReferenceSystem(parentObject.Position); goto LOOPEND; case 0x0e: // Lock Reference ----------------------------------------------------------------------------------------------------------- Vector3 offset = Vector3.zero; SceneObject scene_obj = parentObject as SceneObject; if (parentObject is SceneObject) { offset = SceneGlobals.ReferenceSystem.Position - scene_obj.Position; SceneGlobals.ReferenceSystem = new ReferenceSystem(scene_obj); } else if (parentObject is ITargetable) { offset = SceneGlobals.ReferenceSystem.Position - parentObject.Position; Target tgt = (parentObject as ITargetable).Associated; SceneGlobals.ReferenceSystem = new ReferenceSystem(tgt); } SceneGlobals.ReferenceSystem.Offset = offset; goto LOOPEND; case 0x0f: // Lock & Set --------------------------------------------------------------------------------------------------------------- if (parentObject is SceneObject) { SceneGlobals.ReferenceSystem = new ReferenceSystem(parentObject as SceneObject); } else if (parentObject is ITargetable) { SceneGlobals.ReferenceSystem = new ReferenceSystem((parentObject as ITargetable).Associated); } goto LOOPEND; case 0x19: // Match Velocity Closest --------------------------------------------------------------------------------------------------- if (parentObject is ITargetable) { foreach (IMarkerParentObject impo in MapCore.Active.selection) { Ship ship01 = impo as Ship; if (ship01 != null && ship01.Friendly) { ship01.low_ai.MatchVelocityNearTarget((parentObject as ITargetable).Associated); } } } goto LOOPEND; case 0x1a: // Match Velocity ----------------------------------------------------------------------------------------------------------- if (parentObject is IPhysicsObject) { foreach (IMarkerParentObject impo in MapCore.Active.selection) { Ship ship01 = impo as Ship; if (ship01 != null && ship01.Friendly) { ship01.low_ai.MatchVelocity((parentObject as ITargetable).Associated); } } } goto LOOPEND; case 0x1b: // Attack ------------------------------------------------------------------------------------------------------------------- if (parentObject is ITargetable) { Target self_tgt = (parentObject as ITargetable).Associated; foreach (IMarkerParentObject impo in MapCore.Active.selection) { Ship ship01 = impo as Ship; if (ship01 != null && ship01.Friendly) { ship01.low_ai.Attack(self_tgt); } } } goto LOOPEND; case 0x1c: // TurretAttack ------------------------------------------------------------------------------------------------------------- if (parentObject is ITargetable) { Target self_tgt = (parentObject as ITargetable).Associated; foreach (IMarkerParentObject impo in MapCore.Active.selection) { Ship ship01 = impo as Ship; if (ship01 != null && ship01.Friendly) { ship01.low_ai.TurretAttack(self_tgt); } } } goto LOOPEND; case 0x1d: // Aim Here ----------------------------------------------------------------------------------------------------------------- SceneGlobals.Player.TurretAim = parentObject; goto LOOPEND; case 0x1e: // Target Part -------------------------------------------------------------------------------------------------------------- goto LOOPEND; case 0x1f: // Set Target --------------------------------------------------------------------------------------------------------------- if (parentObject is ITargetable) { Target tgt = (parentObject as ITargetable).Associated; SceneGlobals.Player.Target = tgt; } goto LOOPEND; // +-----------------------------------------------------------------------------------------------------------------------+ // | Info | // +-----------------------------------------------------------------------------------------------------------------------+ case 0x2e: // Ship Information --------------------------------------------------------------------------------------------------------- if (i != 0) { goto LOOPEND; } concerned.SpawnChild("Ship Information", new string [] { ship.Mass.ToString("Mass: 0.0 t"), string.Format("HP: {0:0.0} / {1:0.0}", ship.HP, ship.tot_hp), }); goto LOOPEND; case 0x2f: // OS ----------------------------------------------------------------------------------------------------------------------- goto LOOPEND; // +-----------------------------------------------------------------------------------------------------------------------+ // | Command | // +-----------------------------------------------------------------------------------------------------------------------+ // Match Velocity Closest --------------------------------------------------------------------------------------------------- case 0x29: goto LOOPEND; // Match Velocity ----------------------------------------------------------------------------------------------------------- case 0x3a: goto LOOPEND; case 0x3b: // Flee --------------------------------------------------------------------------------------------------------------------- ship.low_ai.Flee(); goto LOOPEND; case 0x3c: // Idle --------------------------------------------------------------------------------------------------------------------- ship.low_ai.Idle(); goto LOOPEND; case 0x3d: // Attack ------------------------------------------------------------------------------------------------------------------- goto LOOPEND; case 0x3e: // TurretAttack ------------------------------------------------------------------------------------------------------------- goto LOOPEND; case 0x3f: // Control ------------------------------------------------------------------------------------------------------------------ if (parentObject is Ship) { SceneGlobals.Player = parentObject as Ship; } goto LOOPEND; default: goto LOOPEND; } LOOPEND :; } }