/// <summary> /// Replaces specified camera view with data taken into another one. If view does not exist, it is created then added to entry. /// </summary> /// <param name="cameraData"></param> /// <param name="currentEntry"></param> /// <param name="currentViewType"></param> /// <param name="baseEntry"></param> /// <param name="baseViewType"></param> public static void CustomizeCameraView(Cameras cameraData, Cameras.CamEntry currentEntry, Cameras.ViewType currentViewType, Cameras.CamEntry baseEntry, Cameras.ViewType baseViewType) { if (cameraData != null) { Cameras.View baseView = Cameras.GetViewByType(baseEntry, baseViewType); Cameras.View viewToReplace = Cameras.GetViewByType(currentEntry, currentViewType); if (baseView.isValid) { Cameras.View newView = baseView; newView.cameraId = currentEntry.id; // Set to empty to get enough place newView.name = ""; newView.parentCameraId = baseView.cameraId; newView.parentType = baseView.type; newView.type = currentViewType; if (viewToReplace.isValid) { // Replace mode : searching for view to replace List <Cameras.View> currentViews = currentEntry.views; if (currentViews.Contains(viewToReplace)) { currentViews.Remove(viewToReplace); } currentViews.Add(newView); currentEntry.views = currentViews; } else { // Add mode >>> disabled if view count bigger than original one :( ushort originalViewCount = cameraData.Index[newView.cameraId]; if (currentEntry.views.Count + 1 > originalViewCount) { throw new Exception("You can't add views for now... hope that'll be solved in the future."); } currentEntry.views.Add(newView); } // Updating entry cameraData.UpdateEntry(currentEntry); } } }
/// <summary> /// Changes camera source and/or target position(s) /// </summary> /// <param name="cameraData"></param> /// <param name="entry"></param> /// <param name="viewType"></param> /// <param name="sourcePosition"></param> /// <param name="targetPosition"></param> public static void CustomizeCameraPosition(Cameras cameraData, Cameras.CamEntry entry, Cameras.ViewType viewType, Cameras.Position sourcePosition, Cameras.Position targetPosition) { if (cameraData != null) { Cameras.View baseView = Cameras.GetViewByType(entry, viewType); if (baseView.isValid) { List <Cameras.View> currentViews = entry.views; currentViews.Remove(baseView); baseView.source = sourcePosition; baseView.target = targetPosition; currentViews.Add(baseView); entry.views = currentViews; // Updating entry cameraData.UpdateEntry(entry); } } }
/// <summary> /// Returns label for custom view /// </summary> /// <param name="view"></param> /// <returns></returns> private static string _GetCustomViewLabel(Cameras.View view) { string returnedLabel = _LABEL_DEFAULT_CAM_VIEW; if (view.isValid) { // Getting view information ushort parentCameraId = view.parentCameraId; ushort cameraId = view.cameraId; Cameras.ViewType viewType = view.type; if (parentCameraId != 0) { cameraId = view.parentCameraId; viewType = view.parentType; } string parentVehicleName = null; if (VehicleSlotsHelper.CamReference.ContainsKey(cameraId.ToString())) { parentVehicleName = VehicleSlotsHelper.CamReference[cameraId.ToString()]; } else if (VehicleSlotsHelper.NewCamReference.ContainsKey(cameraId.ToString())) { parentVehicleName = VehicleSlotsHelper.NewCamReference[cameraId.ToString()]; } if (parentVehicleName != null) { returnedLabel = string.Format(_FORMAT_CAM_VIEW, parentVehicleName, viewType); } } return(returnedLabel); }
/// <summary> /// Refreshes tab contents /// </summary> private void _RefreshCameraIKContents() { // Current camera DB.Cell cameraRefCell = DatabaseHelper.SelectCellsFromTopicWherePrimaryKey(DatabaseConstants.CAMERA_PHYSICS_DB_COLUMN, _PhysicsTable, _CurrentVehicle)[0]; string cameraRef = cameraRefCell.value; try { string customCamId = VehicleSlotsHelper.VehicleInformation[_CurrentVehicle].newCamera; if (cameraRef.Equals(customCamId)) { cameraLabel.Text = _LABEL_CUSTOM; useOwnCamCheckBox.Checked = true; } else { cameraLabel.Text = VehicleSlotsHelper.CamReference[cameraRef]; useOwnCamCheckBox.Checked = false; } } catch (Exception) { cameraLabel.Text = _LABEL_UNKNOWN; useOwnCamCheckBox.Checked = false; } // Current IK DB.Cell ikRefCell = DatabaseHelper.SelectCellsFromTopicWherePrimaryKey(DatabaseConstants.SAME_IK_PHYSICS_DB_COLUMN, _PhysicsTable, _CurrentVehicle)[0]; string ikRef = ikRefCell.value; try { ikLabel.Text = VehicleSlotsHelper.IKReference[ikRef]; } catch (Exception) { ikLabel.Text = _LABEL_UNKNOWN; } // New set id (own) VehicleSlotsHelper.VehicleInfo currentInfo = VehicleSlotsHelper.VehicleInformation[_CurrentVehicle]; // No new camera for this slot; checkbox disabled useOwnCamCheckBox.Enabled = (currentInfo.newCamera != null); ListView2.StoreSelectedIndex(camSetDetailsListView); camSetDetailsListView.Items.Clear(); if (cameraRef == currentInfo.defaultCamera || cameraRef == currentInfo.newCamera) { advancedCameraControlsPanel.Enabled = true; customCameraIdLabel.Text = cameraRef; useOwnCamCheckBox.Checked = (cameraRef == currentInfo.newCamera); // Set customization: only hood and cockpit views are handled Cameras.CamEntry customCam = _CameraData.GetEntryByCameraId(cameraRef); if (customCam.isValid) { useOwnCamCheckBox.Enabled = true; // Hood ListViewItem customItem = new ListViewItem(Cameras.ViewType.Hood.ToString()) { UseItemStyleForSubItems = false, Font = new Font(camSetDetailsListView.Font, FontStyle.Bold), Tag = Cameras.ViewType.Hood }; Cameras.View currentView = Cameras.GetViewByType(customCam, Cameras.ViewType.Hood); string customViewLabel = _GetCustomViewLabel(currentView); customItem.SubItems.Add(customViewLabel); currentView = Cameras.GetViewByType(customCam, Cameras.ViewType.Hood_Back); customViewLabel = _GetCustomViewLabel(currentView); customItem.SubItems.Add(customViewLabel); camSetDetailsListView.Items.Add(customItem); // Cockpit customItem = new ListViewItem(Cameras.ViewType.Cockpit.ToString()) { UseItemStyleForSubItems = false, Font = new Font(camSetDetailsListView.Font, FontStyle.Bold), Tag = Cameras.ViewType.Cockpit }; currentView = Cameras.GetViewByType(customCam, Cameras.ViewType.Cockpit); customViewLabel = _GetCustomViewLabel(currentView); customItem.SubItems.Add(customViewLabel); currentView = Cameras.GetViewByType(customCam, Cameras.ViewType.Cockpit_Back); customViewLabel = _GetCustomViewLabel(currentView); customItem.SubItems.Add(customViewLabel); camSetDetailsListView.Items.Add(customItem); // Cockpit positions Cameras.View cockpitView = Cameras.GetViewByType(customCam, Cameras.ViewType.Cockpit); cockSourceComboBox.Text = cockpitView.source.ToString(); cockTargetComboBox.Text = cockpitView.target.ToString(); } else { Log.Warning(_ERROR_NEW_CAM_NOT_FOUND); // No new camera for this slot; checkbox disabled useOwnCamCheckBox.Enabled = false; } } else { // Other camera can't be modified customCameraIdLabel.Text = _LABEL_NO_CAM; advancedCameraControlsPanel.Enabled = false; } ListView2.RestoreSelectedIndex(camSetDetailsListView); }