void CreateControl(DialogueItem item = null) { DialogueItem dialogueItem = item; if (item == null) { dialogueItem = ScriptableObject.CreateInstance <DialogueItem> (); dialogueItem.id = dialogueCount++; } DialogueItemWindow newWindow = new DialogueItemWindow(dialogueItem, this); //Default Dialogue Window Rect Size Reference for Zooming newWindow.orgRect = new Rect( newWindow.rect.x, newWindow.rect.y, newWindow.rect.width, newWindow.rect.height ); // //Adapt to zoomed size if adding a window after zooming newWindow.rect = new Rect( newWindow.rect.x, newWindow.rect.y, newWindow.rect.width * _zoomLevel, newWindow.rect.height * _zoomLevel ); // controls.Add(newWindow); }
void SelectWindow() { for (int i = 0; i < controls.Count; i++) { if (controls[i].rect.Contains(Event.current.mousePosition)) { _dialogueItemWindow = controls[i]; } } }
void Zoom() { _focusedWindow = null; Event e = Event.current; if (e.type == EventType.MouseUp) { foreach (var window in controls) { window.orgRect = new Rect( window.rect.x / _zoomLevel, window.rect.y / _zoomLevel, window.orgRect.width, window.orgRect.height ); } } if (e.type == EventType.MouseDrag) { foreach (var window in controls) { if (e.mousePosition.x > window.rect.x && e.mousePosition.x < window.rect.x + window.rect.width && e.mousePosition.y > window.rect.y && e.mousePosition.y < window.rect.y + window.rect.height) { _focusedWindow = window; break; } } if (_focusedWindow == null) { foreach (var window in controls) { window.orgRect = new Rect( window.orgRect.x + e.delta.x, window.orgRect.y + e.delta.y, window.orgRect.width, window.orgRect.height ); window.rect = new Rect( window.orgRect.x * _zoomLevel, window.orgRect.y * _zoomLevel, window.rect.width, window.rect.height ); } Repaint(); } } if (e.type == EventType.scrollWheel) { if (-e.delta.y > 0f) { _zoomLevel += ZOOM_SENSI; _zoomLevel = Mathf.Clamp(_zoomLevel, MIN_ZOOM, MAX_ZOOM); } else if (-e.delta.y < 0f) { _zoomLevel -= ZOOM_SENSI; _zoomLevel = Mathf.Clamp(_zoomLevel, MIN_ZOOM, MAX_ZOOM); } foreach (var window in controls) { window.rect = new Rect( window.orgRect.x * _zoomLevel, window.orgRect.y * _zoomLevel, window.orgRect.width * _zoomLevel, window.orgRect.height * _zoomLevel ); } Repaint(); } }
public void DeleteControl(DialogueItemWindow window) { itemsToDelete.Add(window.dialogue.id); controls.Remove(window); }