Example #1
0
        public void AddOption(ShardPollOption option)
        {
            ShardPollOption[] old = m_Options;
            m_Options = new ShardPollOption[old.Length + 1];

            for (int i = 0; i < old.Length; ++i)
            {
                m_Options[i] = old[i];
            }

            m_Options[old.Length] = option;
        }
Example #2
0
        public void RemoveOption(ShardPollOption option)
        {
            int index = Array.IndexOf(m_Options, option);

            if (index < 0)
            {
                return;
            }

            ShardPollOption[] old = m_Options;
            m_Options = new ShardPollOption[old.Length - 1];

            for (int i = 0; i < index; ++i)
            {
                m_Options[i] = old[i];
            }

            for (int i = index; i < m_Options.Length; ++i)
            {
                m_Options[i] = old[i + 1];
            }
        }
Example #3
0
 public ShardPollPrompt(ShardPoller poller, ShardPollOption opt)
 {
     m_Poller = poller;
     m_Option = opt;
 }
Example #4
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            if (m_Polls != null && m_Polls.Count > 0)
            {
                ShardPoller poller = m_Polls.Dequeue();

                if (poller != null)
                {
                    Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(poller.SendQueuedPoll_Callback), new object[] { m_From, m_Polls });
                }
            }

            if (info.ButtonID == 1)
            {
                int[] switches = info.Switches;

                if (switches.Length == 0)
                {
                    return;
                }

                int             switched = switches[0] - 1;
                ShardPollOption opt      = null;

                if (switched >= 0 && switched < m_Poller.Options.Length)
                {
                    opt = m_Poller.Options[switched];
                }

                if (opt == null && !m_Editing)
                {
                    return;
                }

                if (m_Editing)
                {
                    if (!m_Poller.Active)
                    {
                        m_From.SendMessage("Enter a title for the option. Escape to cancel.{0}", opt == null ? "" : " Use \"DEL\" to delete.");
                        m_From.Prompt = new ShardPollPrompt(m_Poller, opt);
                    }
                    else
                    {
                        m_From.SendMessage("You may not edit an active poll. Deactivate it first.");
                        m_From.SendGump(new ShardPollGump(m_From, m_Poller, m_Editing, m_Polls));
                    }
                }
                else
                {
                    if (!m_Poller.Active)
                    {
                        m_From.SendMessage("The poll has been deactivated.");
                    }
                    else if (m_Poller.HasAlreadyVoted(sender))
                    {
                        m_From.SendMessage("You have already voted on this poll.");
                    }
                    else
                    {
                        m_Poller.AddVote(sender, opt);
                    }
                }
            }
            else if (info.ButtonID == 2 && m_Editing)
            {
                m_From.SendGump(new ShardPollGump(m_From, m_Poller, m_Editing, m_Polls));
                m_From.SendGump(new PropertiesGump(m_From, m_Poller));
            }
        }
Example #5
0
        public ShardPollGump(Mobile from, ShardPoller poller, bool editing, Queue <ShardPoller> polls) : base(50, 50)
        {
            m_From    = from;
            m_Poller  = poller;
            m_Editing = editing;
            m_Polls   = polls;

            Closable = false;

            AddPage(0);

            int totalVotes        = 0;
            int totalOptionHeight = 0;

            for (int i = 0; i < poller.Options.Length; ++i)
            {
                totalVotes        += poller.Options[i].Votes;
                totalOptionHeight += poller.Options[i].ComputeHeight() + 5;
            }

            bool isViewingResults = editing && poller.Active;
            bool isCompleted      = totalVotes > 0 && !poller.Active;

            if (editing && !isViewingResults)
            {
                totalOptionHeight += 35;
            }

            int height = 115 + totalOptionHeight;

            AddBackground(1, 1, 398, height - 2, 3600);
            AddAlphaRegion(16, 15, 369, height - 31);

            AddItem(308, 30, 0x1E5E);

            string title;

            if (editing)
            {
                title = (isCompleted ? "Poll Completed" : "Poll Editor");
            }
            else
            {
                title = "Shard Poll";
            }

            AddHtml(22, 22, 294, 20, Color(Center(title), LabelColor32), false, false);

            if (editing)
            {
                AddHtml(22, 22, 294, 20, Color(String.Format("{0} total", totalVotes), LabelColor32), false, false);
                AddButton(287, 23, 0x2622, 0x2623, 2, GumpButtonType.Reply, 0);
            }

            AddHtml(22, 50, 294, 40, Color(poller.Title, 0x99CC66), false, false);

            AddImageTiled(32, 88, 264, 1, 9107);
            AddImageTiled(42, 90, 264, 1, 9157);

            int y = 100;

            for (int i = 0; i < poller.Options.Length; ++i)
            {
                ShardPollOption option = poller.Options[i];
                string          text   = option.Title;

                if (editing && totalVotes > 0)
                {
                    double perc = option.Votes / (double)totalVotes;

                    text = String.Format("[{1}: {2}%] {0}", text, option.Votes, (int)(perc * 100));
                }

                int optHeight = option.ComputeHeight();

                y += optHeight / 2;

                if (isViewingResults)
                {
                    AddImage(24, y - 15, 0x25FE);
                }
                else
                {
                    AddRadio(24, y - 15, 0x25F9, 0x25FC, false, 1 + i);
                }

                AddHtml(60, y - (9 * option.LineBreaks), 250, 18 * option.LineBreaks, Color(text, LabelColor32), false, false);

                y += optHeight / 2;
                y += 5;
            }

            if (editing && !isViewingResults)
            {
                AddRadio(24, y + 15 - 15, 0x25F9, 0x25FC, false, 1 + poller.Options.Length);
                AddHtml(60, y + 15 - 9, 250, 18, Color("Create new option.", 0x99CC66), false, false);
            }

            AddButton(314, height - 73, 247, 248, 1, GumpButtonType.Reply, 0);
            AddButton(314, height - 47, 242, 241, 0, GumpButtonType.Reply, 0);
        }
Example #6
0
 public void AddVote(NetState ns, ShardPollOption option)
 {
     option.AddVote(ns);
 }