Ejemplo n.º 1
0
    private void GetEndPoints(DialogAnswer edge, out Vector2 start, out Vector2 end)
    {
        Rect r1 = edge.From.NodeRect, r2 = edge.To.NodeRect;

        List <DialogAnswer> CommonEdges =
            new List <DialogAnswer>(Edges().Where(e => (e.To == edge.To || e.To == edge.From)));

        CommonEdges.Sort((e1, e2) => e1.Id - e2.Id);

        // make it neat looking:
        int t = 0;

        if (CommonEdges.Count > 1)
        {
            for (int i = 0; i < CommonEdges.Count; ++i)
            {
                if (CommonEdges[i] == edge)
                {
                    t = i;
                    break;
                }
            }
            if (t % 2 == 1)
            {
                t = -t - 1;
            }
        }

        start = LineBoxIntersection(r1, r2.center, r1.center + Vector2.right * t * 8);
        end   = LineBoxIntersection(r2, r1.center, r2.center + Vector2.right * t * 8);
    }
Ejemplo n.º 2
0
    public static void Draw(DialogAnswer answer)
    {
        // EditorGUILayout.LabelField("DialogWindow Answer", answer.title);
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

        answer.title = EditorGUILayout.TextField("Answer", answer.title);

        if (answer.parent == null)
        {
            return;
        }

        if (renderer == null || renderer.answer != answer)
        {
            renderer = new AnswerConditionRenderer(answer);
        }
        renderer.DrawList();

        List <string> l = new List <string> {
            "-"
        };

        l.AddRange(answer.parent.Statements.Where(x => x != answer.From).Select(x => x.name));

        int t = EditorGUILayout.Popup("To:", Mathf.Max(0, l.IndexOf(answer.To?.name)), l.ToArray());

        if (t > 0)
        {
            answer.To = answer.parent.Statements.Where(x => x != answer.From).ToArray()[t - 1];
        }
        EditorGUILayout.Space();
        EditorGUILayout.Space();
    }
Ejemplo n.º 3
0
    public AnswerConditionRenderer(DialogAnswer answer)
    {
        this.answer = answer;
        container   = answer.parent;

        list = new ReorderableList(answer.conditions, typeof(DialogAnswerCondition), false, true, true, true);
        list.drawElementCallback += OnDrawElement;
        list.drawHeaderCallback   = rect => EditorGUI.LabelField(rect, "Conditions");
    }
Ejemplo n.º 4
0
    private void DrawEdge(DialogAnswer edge)
    {
        Vector2 p1, p2;

        GetEndPoints(edge, out p1, out p2);
        Handles.color = edge.Equals(selectedEdge) ? Color.cyan : Color.white;
        DrawEdgeLine(p1, p2);
        edge.BoundingRect.position = p1;
        edge.BoundingRect.size     = p2;
    }
        /// <summary>
        /// Renames files in the specified <paramref name="directory" /> with specified
        /// <paramref name="renameUsing">format</paramref>.
        /// </summary>
        /// <param name="filesOrDirectories">The files or directories path where are the files to rename.</param>
        /// <param name="recursive">If set to <c>true</c> do it recursively; otherwise do it only in specified<paramref name="directory" />.</param>
        /// <param name="renameUsing">The format used to rename.</param>
        /// <returns>A task that represents the renaming process.</returns>
        /// <exception cref="System.IO.FileNotFoundException">If a specified file or directory doesn't exists.</exception>
        public async Task RenameAsync(IEnumerable<string> filesOrDirectories, bool recursive, RenameUsing renameUsing)
        {
            if (filesOrDirectories == null)
                throw new ArgumentNullException("filesOrDirectories");

            if (!filesOrDirectories.Any())
            {
                Log.I("No files or directories specified. Do nothing.");
                return;
            }

            _scopeAnswer = DialogAnswer.None;
            var tasks = _fileSystemHelper.ProcessForEachFilesAsync(filesOrDirectories, recursive, FileFilterProvider.TagFileMatcher, (f, cts) => RenameAsync(f, renameUsing));
            await Task.WhenAll(tasks);
        }
Ejemplo n.º 6
0
    public Dialog BehaviourToDialog()
    {
        Dialog dialog = new Dialog();
        int    i      = 0;

        foreach (var v in dialogPieceBehaviours)
        {
            DialogPiece dialogPiece = new DialogPiece();
            dialogPiece.content      = v.ContentText.text;
            dialogPiece.speaker      = v.SpeakerText.text;
            dialogPiece.NodePosition = DialogPieces[v.QueueIndex].GetComponent <RectTransform>().anchoredPosition;
            if (v.formarDialogPieceNode.Count != 0)
            {
                foreach (var w in v.formarDialogPieceNode)
                {
                    dialogPiece.formarPiece.Add(w.GetComponent <DialogPieceBehaviour>().QueueIndex);
                }
            }



            if (v.answermenu[0].GetComponent <MenuOptionBehaviour>().nextDialogPieceNode != null)
            {
                dialogPiece.nextPiece = new int();
                dialogPiece.nextPiece = v.answermenu[0].GetComponent <MenuOptionBehaviour>().nextDialogPieceNode
                                        .GetComponent <DialogPieceBehaviour>().QueueIndex;
            }

            if (v.answermenu.Count > 1)
            {
                for (int w = 1; w < v.answermenu.Count - 1; w++)
                {
                    DialogAnswer dialogAnswer = new DialogAnswer();

                    dialogAnswer.answerContent =
                        v.answermenu[w].GetComponent <MenuOptionBehaviour>().AnswerContent.GetComponent <InputField>().text;
                    dialogAnswer.nextPiece = v.answermenu[w].GetComponent <MenuOptionBehaviour>().nextDialogPieceNode
                                             .GetComponent <DialogPieceBehaviour>().QueueIndex;
                    dialogPiece.dialoganswer.Add(dialogAnswer);
                }
            }
            dialog.dialogStream.Add(dialogPiece);

            i++;
        }
        Debug.Log(JsonUtility.ToJson(dialog));
        return(dialog);
    }
Ejemplo n.º 7
0
    private void OnNodeEvent(DialogStatement node)
    {
        var rect = node.NodeRect;

        if (rect.Contains(Event.current.mousePosition))
        {
            if (Event.current.type == EventType.ContextClick)
            {
                EditorContextMenu(nodeDict, node.Id);
                Event.current.Use();
            }
            if (Event.current.type == EventType.MouseDown)
            {
                if (controllMode == ControllMode.DRAWEDGE && startNode != node)
                {
                    DialogAnswer answer = ScriptableObject.CreateInstance <DialogAnswer>();
                    answer.From = startNode;
                    answer.To   = node;
                    answer.Id   = idGenerator;
                    startNode.Answers.Add(answer);
                    AssetDatabase.AddObjectToAsset(answer, host.ActiveContainer);
                    answer.hideFlags = HideFlags.HideInHierarchy;
                    answer.parent    = host.ActiveContainer;
                    AssetDatabase.SaveAssets();
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(host.ActiveContainer));
                    controllMode = ControllMode.SELECTION;
                }
                else
                {
                    selectedNode           = node;
                    Selection.activeObject = node;
                }
                Event.current.Use();
            }
        }
        if (selectedNode != node)
        {
            return;
        }
        if (Event.current.type == EventType.MouseDrag)
        {
            node.NodeRect.position += Event.current.delta;
            EditorUtility.SetDirty(node);
            Event.current.Use();
        }
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfMediaDatabase.Core.Operations.Rename.RenameOperation"/> class.
        /// </summary>
        /// <param name="fileSystemHelper">Helper for file system access.</param>
        /// <param name="file">Injection wrapper of <see cref="System.IO.File"/>.</param>
        /// <param name="path">Injection wrapper of <see cref="System.IO.Path"/>.</param>
        /// <param name="dialog">Dialog service to show dialogs.</param>
        public RenameOperation(IFileSystemHelper fileSystemHelper, IFile file, IPath path, IDialog dialog)
        {
            if (fileSystemHelper == null)
                throw new ArgumentNullException("fileSystemHelper");
            if (file == null)
                throw new ArgumentNullException("file");
            if (path == null)
                throw new ArgumentNullException("path");
            if (dialog == null)
                throw new ArgumentNullException("dialog");

            _fileSystemHelper = fileSystemHelper;
            _file = file;
            _path = path;
            _dialog = dialog;

            _scopeAnswer = DialogAnswer.None;
        }
Ejemplo n.º 9
0
		/// <summary>
		/// Asks for an answer.
		/// </summary>
		/// <returns>The user answer.</returns>
		/// <param name="possibleAnswers">Possible answers.</param>
		private DialogAnswer AskForAnswer(DialogAnswer[] possibleAnswers)
		{
			if (possibleAnswers == null || possibleAnswers.Length == 0)
				return DialogAnswer.None;

			if (possibleAnswers.Length == 1)
			{
				_console.Write("Hit a key to continue...".T());
				_console.Read();
				return DialogAnswer.Ok;
			}

			string text = BuildAnswerPropositions(possibleAnswers);
			_console.Write(text);

			DialogAnswer answer = DialogAnswer.None;
			while(answer == DialogAnswer.None)
				answer = ProcessAnswer((char)_console.Read(), possibleAnswers);
            _console.WriteLine();

			return answer;
		}	
Ejemplo n.º 10
0
 public FileDialogResult(DialogAnswer answer, string[] fileNames)
 {
     Answer    = answer;
     FileNames = fileNames;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles the existing file.
        /// </summary>
        /// <param name="file">File source.</param>
        /// <param name="newFile">Renamed file.</param>
        private async Task HandleExistingFileAsync(string file, string newFile)
        {
            Log.D("File '{0}' has already been renamed, check if files are same.", file, newFile);
            if (await _fileSystemHelper.FilesAreSameAsync(file, newFile))
            {
                Log.I("File '{0}' already exists and is same as file '{1}'. Delete file '{0}'.", file, newFile);
                _file.Delete(file);
            }
            else
            {
                Log.T("File '{0}' is different as file '{1}'.", file, newFile);
                DialogAnswer answer = DialogAnswer.None;
                if (_scopeAnswer == DialogAnswer.None)
                {
					using (var locker = Log.Lock())
					{
						lock (locker)
						{
							answer = _dialog.Show(
								"Same file", 
								string.Format("File '{0}' has same date taken as file '{1}', but files are not same. Do you want to delete file '{2}' ?", file, newFile, _path.GetFileName(file)), 
								DialogAnswer.Yes, DialogAnswer.No, DialogAnswer.Always, DialogAnswer.Never);

							if (answer == DialogAnswer.Always || answer == DialogAnswer.Never)
								_scopeAnswer = answer;
						}
					}
                }
                else
                {
                    answer = _scopeAnswer;
                }

                Log.I("File '{0}' already exists and is different as file '{1}'. When asking to delete file '{0}' you decide '{2}'.", file, newFile, answer);
                if (answer == DialogAnswer.Yes || answer == DialogAnswer.Always)
                {
                    _file.Delete(file);
                    Log.I("File '{0}' has been deleted.", file);
                }
            }
        }
Ejemplo n.º 12
0
    private void HandleMouseActions()
    {
        Vector2 v = Event.current.mousePosition;

        if (Event.current.button == 0 && Event.current.type == EventType.mouseDrag &&
            selectedNode == null && selectedEdge == null)
        {
            if (Vector2.Distance(lastMousePos, v) < 50)
            {
                ScrollPosition -= Event.current.delta;
                Event.current.Use();
            }
            lastMousePos = v;
        }

        if (Event.current.type != EventType.MouseDown)
        {
            return;
        }


        selectedNode = null;
        selectedEdge = null;
        foreach (var edge in Edges())
        {
            if (Vector2.Distance(v, ((edge.BoundingRect.size + edge.BoundingRect.position) * 0.5f)) >
                (edge.BoundingRect.position - edge.BoundingRect.size).magnitude * 0.5f
                ||
                !(PointdistanceToLine(Event.current.mousePosition, edge.BoundingRect.position, edge.BoundingRect.size) <
                  6))
            {
                continue;
            }
            selectedEdge           = edge;
            Selection.activeObject = edge;
            Event.current.Use();

            if (Event.current.button == 1)
            {
                // rightclick:
                EditorContextMenu(edgeDict, edge.Id);
            }

            return;
        }
        if (Event.current.button > 1)
        {
            return;
        }
        Selection.activeObject = null;
        if (Event.current.button == 1)
        {
            // rightclick:
            if (controllMode == ControllMode.DRAWEDGE)
            {
                controllMode = ControllMode.SELECTION;
            }
            else
            {
                EditorContextMenu(menuDict);
            }
        }
        Event.current.Use();
    }
Ejemplo n.º 13
0
 public FolderBrowserResult(DialogAnswer answer, string selectedDirectory)
 {
     Answer            = answer;
     SelectedDirectory = selectedDirectory;
 }
Ejemplo n.º 14
0
    public void LoadDialoges(string lang)
    {
        dialogs         = new List <DialogQuestion>();
        welcomeMessages = new WelcomeMessages();
        tiredMessages   = new TiredMessages();

        //Dialogs
        bool        staticAnswers = false;
        TextAsset   textAsset     = (TextAsset)Resources.Load("dialogs_" + lang);
        XmlDocument xmldoc        = new XmlDocument();

        xmldoc.LoadXml(textAsset.text);

        foreach (XmlNode rep in xmldoc.ChildNodes[0].ChildNodes)
        {
            DialogQuestion diag = new DialogQuestion();

            foreach (XmlNode i in rep.ChildNodes)
            {
                if (i.Name == "stat")
                {
                    if (i.InnerText == "None")
                    {
                        staticAnswers = true;
                    }
                    else
                    {
                        diag.linkedStat = (StatsHolder.Stat)System.Enum.Parse(typeof(StatsHolder.Stat), i.InnerText);
                        staticAnswers   = false;
                    }
                }
                else if (i.Name == "question")
                {
                    diag.questions.Add(i.InnerText);
                }
                else if (i.Name == "answer")
                {
                    DialogAnswer da = new DialogAnswer();
                    da.answer = i.InnerText;
                    foreach (XmlAttribute attr in i.Attributes)
                    {
                        if (attr.Name == "min")
                        {
                            da.minRange = sbyte.Parse(attr.Value);
                        }
                        else if (attr.Name == "max")
                        {
                            da.maxRange = sbyte.Parse(attr.Value);
                        }
                    }
                    diag.answers.Add(da);
                }
            }
            if (staticAnswers)
            {
                foreach (var an in diag.answers)
                {
                    DialogQuestion.answersForAll.Add(an);
                }
            }
            else
            {
                dialogs.Add(diag);
            }
        }

        //Dialogs welcome
        textAsset = (TextAsset)Resources.Load("welcomedialogs_" + lang);
        xmldoc    = new XmlDocument();
        xmldoc.LoadXml(textAsset.text);

        foreach (XmlNode i in xmldoc.ChildNodes[0].ChildNodes)
        {
            if (i.Name == "regular")
            {
                welcomeMessages.regularMessages.Add(i.InnerText);
            }
            else if (i.Name != "#text")
            {
                DialogQuestion dq = new DialogQuestion();
                dq.linkedStat = (StatsHolder.Stat)System.Enum.Parse(typeof(StatsHolder.Stat), i.Name, true);

                foreach (XmlNode spec in i.ChildNodes)
                {
                    DialogAnswer da = new DialogAnswer();
                    da.answer = spec.InnerText;
                    foreach (XmlAttribute attr in spec.Attributes)
                    {
                        if (attr.Name == "min")
                        {
                            da.minRange = sbyte.Parse(attr.Value);
                        }
                        else if (attr.Name == "max")
                        {
                            da.maxRange = sbyte.Parse(attr.Value);
                        }
                    }
                    dq.answers.Add(da);
                }

                welcomeMessages.specialMessages.Add(dq);
            }
        }

        //Dialogs tired
        textAsset = (TextAsset)Resources.Load("tireddialogs_" + lang);
        xmldoc    = new XmlDocument();
        xmldoc.LoadXml(textAsset.text);

        foreach (XmlNode i in xmldoc.ChildNodes[0].ChildNodes)
        {
            if (i.Name == "regular")
            {
                tiredMessages.regularMessages.Add(i.InnerText);
            }
            else if (i.Name != "#text")
            {
                DialogQuestion dq = new DialogQuestion();
                dq.linkedStat = (StatsHolder.Stat)System.Enum.Parse(typeof(StatsHolder.Stat), i.Name, true);

                foreach (XmlNode spec in i.ChildNodes)
                {
                    DialogAnswer da = new DialogAnswer();
                    da.answer = spec.InnerText;
                    foreach (XmlAttribute attr in spec.Attributes)
                    {
                        if (attr.Name == "min")
                        {
                            da.minRange = sbyte.Parse(attr.Value);
                        }
                        else if (attr.Name == "max")
                        {
                            da.maxRange = sbyte.Parse(attr.Value);
                        }
                    }
                    dq.answers.Add(da);
                }

                tiredMessages.specialMessages.Add(dq);
            }
        }
    }
Ejemplo n.º 15
0
		/// <summary>
		/// Builds the answer propositions.
		/// </summary>
		/// <returns>The answer propositions.</returns>
		/// <param name="possibleAnswers">Possible answers.</param>
		private string BuildAnswerPropositions(DialogAnswer[] possibleAnswers)
		{
			var text = new StringBuilder();
			var usedChars = new List<string>();
            foreach(var choice in possibleAnswers.Where(c => c != DialogAnswer.None))
            {
				string translated = Translator.Translate(choice.ToString());
				bool answerCharFound = false;
				for (int i = 0; i < translated.Length; i++)
				{
					var currentChar = translated.Substring(i, 1);
					if (!usedChars.Contains(currentChar) && !answerCharFound)
					{
						answerCharFound = true;

						text.Append("[");
						text.Append(currentChar);
						text.Append("]");

						usedChars.Add(currentChar);
					}
					else
					{
						text.Append(currentChar);
					}
				}
				text.Append(" ");
			}
			text.Append("? ");
			return text.ToString();
		}
Ejemplo n.º 16
0
		/// <summary>
		/// Processes the user answer.
		/// </summary>
		/// <param name="i">The pressed key char.</param>
		private DialogAnswer ProcessAnswer(char key, DialogAnswer[] possibleAnswers)
		{
			string keyStr = key.ToString().ToUpper();
			return (DialogAnswer)(possibleAnswers.SingleOrDefault(da => da.ToString().Substring(0, 1) == keyStr));
		}
Ejemplo n.º 17
0
 private void BtnCancel_Click(object sender, RoutedEventArgs e)
 {
     SelectedChoice = DialogAnswer.Cancel;
     DialogResult   = true;
     Close();
 }
Ejemplo n.º 18
0
 public static void SetResult(DialogAnswer newAnswer)
 {
     Answer = newAnswer;
 }
Ejemplo n.º 19
0
 public void OnEnable()
 {
     DialogAnswer answer = (DialogAnswer)target;
 }
Ejemplo n.º 20
0
    public override void OnInspectorGUI()
    {
        DialogAnswer answer = (DialogAnswer)target;

        Draw(answer);
    }