Example #1
0
        public int ChoiceHandle(float time, string c1, string c2, string c3, string c4)
        {
            ChoiceStruct choice = new ChoiceStruct();

            choice.timer = time;
            choice.c1    = c1;
            choice.c2    = c2;
            choice.c3    = c3;
            choice.c4    = c4;
            if (choice.c1 != null)
            {
                choice.Count++;
                if (choice.c2 != null)
                {
                    choice.Count++;
                    if (choice.c3 != null)
                    {
                        choice.Count++;
                        if (choice.c4 != null)
                        {
                            choice.Count++;
                        }
                    }
                }
            }
            if (choiceHandler.IsBusy)
            {
                choiceHandler.CancelAsync();
                choiceWorker.Abort();
                choiceHandler.Dispose();
            }
            dialogueHandler.ReportProgress(0, new LCmd("choice", choice));
            choice_id = -1;
            choiceHandler.RunWorkerAsync(choice);
            while (choice_id == -1)
            {
                System.Threading.Thread.Sleep(100);
            }
            if (choiceHandler.IsBusy)
            {
                choiceWorker.Abort();
                choiceHandler.Dispose();
            }
            dialogueHandler.ReportProgress(0, new LCmd("reset_btn", null));
            if (choice_id > choice.Count)
            {
                choice_id = 0;
            }
            return(choice_id);
        }
Example #2
0
 private void choiceHandler_DoWork(object sender, DoWorkEventArgs e)
 {
     choiceWorker = Thread.CurrentThread;
     try
     {
         ChoiceStruct inp = e.Argument as ChoiceStruct;
         for (int i = 1; i <= 100; i++)
         {
             System.Threading.Thread.Sleep((int)(inp.timer * 10));
             choiceHandler.ReportProgress(i);
         }
         choice_id = 0;
     } catch (ThreadAbortException ex)
     {
         e.Cancel = true;
         Thread.ResetAbort();
     }
 }
Example #3
0
        private void dialogueHandler_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            LCmd command = e.UserState as LCmd;

            if (command.Cmd == "prog")
            {
                if (e.ProgressPercentage + 1 <= 100)
                {
                    this.progressBar1.Value = e.ProgressPercentage + 1;
                }
                this.progressBar1.Value = e.ProgressPercentage;
            }
            else if (command.Cmd == "write")
            {
                string text = command.Arg as string;
                this.richTextBox1.SelectionColor = Color.Black;
                if (text.Contains('^'))
                {
                    for (int i = 0; i < text.Split('^').Length; i++)
                    {
                        string colored = text.Split('^')[i];
                        if (colored.Length == 0 || i == 0)
                        {
                            this.richTextBox1.AppendText(colored);
                            this.richTextBox1.Update();
                            this.richTextBox1.ScrollToCaret();
                            continue;
                        }
                        if (colored[0] == '1')
                        {
                            this.richTextBox1.SelectionColor = Color.Red;
                        }
                        else if (colored[0] == '2')
                        {
                            this.richTextBox1.SelectionColor = Color.Green;
                        }
                        else if (colored[0] == '3')
                        {
                            this.richTextBox1.SelectionColor = Color.Yellow;
                        }
                        else if (colored[0] == '4')
                        {
                            this.richTextBox1.SelectionColor = Color.Blue;
                        }
                        else if (colored[0] == '5')
                        {
                            this.richTextBox1.SelectionColor = Color.Black;
                        }
                        this.richTextBox1.AppendText(colored.Remove(0, 1));
                        this.richTextBox1.Update();
                        this.richTextBox1.ScrollToCaret();
                    }
                    this.richTextBox1.AppendText("\n");
                    this.richTextBox1.Update();
                    this.richTextBox1.ScrollToCaret();
                }
                else
                {
                    this.richTextBox1.AppendText(text + "\n");
                    this.richTextBox1.Update();
                    this.richTextBox1.ScrollToCaret();
                }
            }
            else if (command.Cmd == "endgame")
            {
                this.toolStripMenuItem1.Enabled = true;
            }
            else if (command.Cmd == "addItem")
            {
                InventoryItem newItem = command.Arg as InventoryItem;
                inventoryItemBindingSource.Add(newItem);
                this.richTextBox1.AppendText(newItem.LocalizedName + " was added to the inventory\n");
                this.richTextBox1.ScrollToCaret();
            }
            else if (command.Cmd == "choice")
            {
                ChoiceStruct choice = command.Arg as ChoiceStruct;
                this.ChoiceButton1.Enabled = true;
                this.ChoiceButton2.Enabled = true;
                this.ChoiceButton3.Enabled = true;
                this.ChoiceButton4.Enabled = true;
                if (choice.c1 == null)
                {
                    choice.c1 = "...";
                    this.ChoiceButton1.Text    = choice.c1;
                    this.ChoiceButton1.Enabled = false;
                }
                else
                {
                    this.ChoiceButton1.Text = choice.c1;
                    choice.Count++;
                }
                if (choice.c2 == null)
                {
                    choice.c2 = "...";
                    this.ChoiceButton2.Text    = choice.c2;
                    this.ChoiceButton2.Enabled = false;
                }
                else
                {
                    this.ChoiceButton2.Text = choice.c2;
                    choice.Count++;
                }
                if (choice.c3 == null)
                {
                    choice.c3 = "...";
                    this.ChoiceButton3.Text    = choice.c3;
                    this.ChoiceButton3.Enabled = false;
                }
                else
                {
                    this.ChoiceButton3.Text = choice.c3;
                    choice.Count++;
                }
                if (choice.c4 == null)
                {
                    choice.c4 = "...";
                    this.ChoiceButton4.Text    = choice.c4;
                    this.ChoiceButton4.Enabled = false;
                }
                else
                {
                    this.ChoiceButton4.Text = choice.c4;
                    choice.Count++;
                }
            }
            else if (command.Cmd == "reset_btn")
            {
                this.ChoiceButton1.Enabled = false;
                this.ChoiceButton2.Enabled = false;
                this.ChoiceButton3.Enabled = false;
                this.ChoiceButton4.Enabled = false;
            }
        }