コード例 #1
0
ファイル: TaxRateWindow.cs プロジェクト: reubene/Civ2-clone
        public TaxRateWindow(Main parent) : base(parent, 622, 432, paddingBtmInnerPanel: 10, title: "How Shall We Distribute The Wealth?")
        {
            main = parent;

            taxRate = Game.GetActiveCiv.TaxRate;
            sciRate = Game.GetActiveCiv.ScienceRate;
            luxRate = Game.GetActiveCiv.LuxRate;
            maxRate = 80;

            DefaultButton = new Civ2button(Labels.Ok, 596, 28, new Font("Times new roman", 11));

            taxCheckbox = new CheckBox()
            {
                Visible = false
            };
            taxCheckbox.CheckedChanged += (_, _) =>
            {
                if (taxCheckbox.Checked == true)
                {
                    sciCheckbox.Checked = false;
                    luxCheckbox.Checked = false;
                }
                Surface.Invalidate();
            };
            taxCheckbox.GotFocus += (_, _) => Surface.Invalidate();
            Layout.Add(taxCheckbox, 561, 207);

            sciCheckbox = new CheckBox()
            {
                Visible = false
            };
            sciCheckbox.CheckedChanged += (_, _) =>
            {
                if (sciCheckbox.Checked == true)
                {
                    taxCheckbox.Checked = false;
                    luxCheckbox.Checked = false;
                }
                Surface.Invalidate();
            };
            sciCheckbox.GotFocus += (_, _) => Surface.Invalidate();
            Layout.Add(sciCheckbox, 561, 268);

            luxCheckbox = new CheckBox()
            {
                Visible = false
            };
            luxCheckbox.CheckedChanged += (_, _) =>
            {
                if (luxCheckbox.Checked == true)
                {
                    taxCheckbox.Checked = false;
                    sciCheckbox.Checked = false;
                }
                Surface.Invalidate();
            };
            luxCheckbox.GotFocus += (_, _) => Surface.Invalidate();
            Layout.Add(luxCheckbox, 561, 329);

            taxBar = new HScrollBar()
            {
                Width = 505, Maximum = 10, Value = taxRate / 10
            };
            sciBar = new HScrollBar()
            {
                Width = 505, Maximum = 10, Value = sciRate / 10
            };
            luxBar = new HScrollBar()
            {
                Width = 505, Maximum = 10, Value = luxRate / 10
            };
            taxBar.ValueChanged += (_, _) =>
            {
                incTax = (taxBar.Value * 10 > taxRate);
                decTax = (taxBar.Value * 10 < taxRate);
                if (decTax)
                {
                    maxWarn = false;
                }

                taxRate = taxBar.Value * 10;

                if (taxRate > maxRate)
                {
                    taxRate = maxRate;
                    maxWarn = true;
                }
                else
                {
                    if (incTax)
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (luxRate != 0 && luxCheckbox.Checked == false)
                            {
                                luxRate -= 10;
                            }
                            else if (sciRate != 0 && sciCheckbox.Checked == false)
                            {
                                sciRate -= 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                taxRate -= 10;
                            }
                        }
                    }
                    else
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (luxRate != maxRate && luxCheckbox.Checked == false)
                            {
                                luxRate += 10;
                            }
                            else if (sciRate != maxRate && sciCheckbox.Checked == false)
                            {
                                sciRate += 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                taxRate += 10;
                            }
                        }
                    }
                }

                if ((sciBar.Value * 10 > sciRate) || (luxBar.Value * 10 > luxRate))
                {
                    maxWarn = false;
                }

                taxBar.Value = taxRate / 10;
                sciBar.Value = sciRate / 10;
                luxBar.Value = luxRate / 10;
                Invalidate();
            };
            sciBar.ValueChanged += (_, _) =>
            {
                incSci = (sciBar.Value * 10 > sciRate);
                decSci = (sciBar.Value * 10 < sciRate);
                if (decSci)
                {
                    maxWarn = false;
                }

                sciRate = sciBar.Value * 10;

                if (sciRate > maxRate)
                {
                    sciRate = maxRate;
                    maxWarn = true;
                }
                else
                {
                    if (incSci)
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (luxRate != 0 && luxCheckbox.Checked == false)
                            {
                                luxRate -= 10;
                            }
                            else if (taxRate != 0 && taxCheckbox.Checked == false)
                            {
                                taxRate -= 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                sciRate -= 10;
                            }
                        }
                    }
                    else
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (luxRate != maxRate && luxCheckbox.Checked == false)
                            {
                                luxRate += 10;
                            }
                            else if (taxRate != maxRate && taxCheckbox.Checked == false)
                            {
                                taxRate += 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                sciRate += 10;
                            }
                        }
                    }
                }

                if ((taxBar.Value * 10 > taxRate) || (luxBar.Value * 10 > luxRate))
                {
                    maxWarn = false;
                }

                taxBar.Value = taxRate / 10;
                sciBar.Value = sciRate / 10;
                luxBar.Value = luxRate / 10;
                Invalidate();
            };
            luxBar.ValueChanged += (_, _) =>
            {
                incLux = (luxBar.Value * 10 > luxRate);
                decLux = (luxBar.Value * 10 < luxRate);
                if (decLux)
                {
                    maxWarn = false;
                }

                luxRate = luxBar.Value * 10;

                if (luxRate > maxRate)
                {
                    luxRate = maxRate;
                    maxWarn = true;
                }
                else
                {
                    if (incLux)
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (taxRate != 0 && taxCheckbox.Checked == false)
                            {
                                taxRate -= 10;
                            }
                            else if (sciRate != 0 && sciCheckbox.Checked == false)
                            {
                                sciRate -= 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                luxRate -= 10;
                            }
                        }
                    }
                    else
                    {
                        if (taxRate + sciRate + luxRate != 100)
                        {
                            if (taxRate != maxRate && taxCheckbox.Checked == false)
                            {
                                taxRate += 10;
                            }
                            else if (sciRate != maxRate && sciCheckbox.Checked == false)
                            {
                                sciRate += 10;
                            }

                            if (taxRate + sciRate + luxRate != 100)
                            {
                                luxRate += 10;
                            }
                        }
                    }
                }

                if ((taxBar.Value * 10 > taxRate) || (sciBar.Value * 10 > sciRate))
                {
                    maxWarn = false;
                }

                taxBar.Value = taxRate / 10;
                sciBar.Value = sciRate / 10;
                luxBar.Value = luxRate / 10;
                Invalidate();
            };
            Layout.Add(taxBar, 26, 209);
            Layout.Add(sciBar, 26, 270);
            Layout.Add(luxBar, 26, 331);

            Surface.Paint += Surface_Paint;

            Surface.MouseDown += (_, e) =>
            {
                if (e.Location.X > 560 && e.Location.X < 580 && e.Location.Y > 206 && e.Location.Y < 226)
                {
                    taxCheckbox.Checked = !taxCheckbox.Checked;
                    taxCheckbox.Focus();
                    taxCheckbox.Invalidate();
                }

                if (e.Location.X > 560 && e.Location.X < 580 && e.Location.Y > 267 && e.Location.Y < 287)
                {
                    sciCheckbox.Checked = !sciCheckbox.Checked;
                    sciCheckbox.Focus();
                    sciCheckbox.Invalidate();
                }

                if (e.Location.X > 560 && e.Location.X < 580 && e.Location.Y > 328 && e.Location.Y < 348)
                {
                    luxCheckbox.Checked = !luxCheckbox.Checked;
                    luxCheckbox.Focus();
                    luxCheckbox.Invalidate();
                }
            };

            DefaultButton.Click += (sender, e) => CloseWindow();

            KeyDown += (sender, args) =>
            {
                if (args.Key is Keys.Escape)
                {
                    CloseWindow();
                }
            };

            Layout.Add(DefaultButton, 13, 392);
            Content = Layout;
        }
コード例 #2
0
ファイル: HScrollBar.cs プロジェクト: reubene/Civ2-clone
 public void OnValueChanged(HScrollBar widget, EventArgs e)
 {
     using (widget.Platform.Context)
         widget.OnValueChanged(e);
 }