Beispiel #1
0
        // File menu handlers
        public void newCampaign(object sender, RoutedEventArgs e)
        {
/////
//
            //prompt for existing unsaved campaign if necessary
//
/////
            QueryPrompt[] prompts =
            {
                new QueryPrompt("Campaign Name:", QueryType.STRING, "New Campaign"),
                new QueryPrompt("Calendar:",      QueryType.LIST,   Calendars.defaultCalendar,values: Calendars.getCalendars().ToArray()),
                new QueryPrompt("Rule Set:",      QueryType.LIST,   Rulesets.defaultRuleset,  values: Rulesets.getRulesets().ToArray())
            };
            object[] values = SimpleDialog.askCompound("New Campaign", prompts, this);
            if (values == null)
            {
                return;
            }
/////
//
            this.campaign = new Campaign((String)values[0], "me", (String)values[1], (String)values[2]);
//
/////
            this.showCampaign();
        }
        private void container_edit(object sender, RoutedEventArgs e)
        {
            if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name)))
            {
                return;
            }
            ElementReference <ItemSpec> item_ref = this.state.items[this.selection.name];

            if (item_ref.ref_count > 0)
            {
                return;
            }
            int idx = this.container_list.SelectedIndex;

            if ((idx < 0) || (idx >= this.containers.Count))
            {
                return;
            }
            ContainerSpec container = this.containers[idx];

            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING, container.name),
                new QueryPrompt("Weight Factor:", QueryType.FLOAT, (double)(container.weight_factor), step: 0.125),
                new QueryPrompt("Weight Capacity:", QueryType.FLOAT, (double)(container.weight_capacity ?? 0)),
            };
            object[] results = SimpleDialog.askCompound("Edit Container", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string;
            double?weight_factor = results[1] as double?, weight_capacity = results[2] as double?;

            if ((name is null) || (weight_factor is null))
            {
                return;
            }
            if (weight_capacity == 0)
            {
                weight_capacity = null;
            }

            container.name            = name;
            container.weight_factor   = (decimal)weight_factor;
            container.weight_capacity = (decimal?)weight_capacity;
            ItemSpecContainerRow row = this.container_rows[idx];

            row._name            = name;
            row._weight_factor   = container.weight_factor.ToString();
            row._weight_capacity = container.weight_capacity.ToString();
            this.container_list.Items.Refresh();
            this.fix_listview_column_widths(this.container_list);
            this.set_dirty();
        }
        private void prop_edit(object sender, RoutedEventArgs e)
        {
            if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name)))
            {
                return;
            }
            int idx = this.prop_list.SelectedIndex;

            if ((idx < 0) || (idx >= this.property_rows.Count))
            {
                return;
            }
            ItemSpecPropertyRow row = this.property_rows[idx];

            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING, row.name),
                new QueryPrompt("Value:", QueryType.STRING, row.value),
            };
            object[] results = SimpleDialog.askCompound("Edit Property", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string, value = results[1] as string;

            if ((name is null) || (value is null))
            {
                return;
            }

            if (name != row.name)
            {
                this.properties.Remove(row.name);
            }
            this.properties[name] = value;
            row._name             = name;
            row._value            = value;
            this.property_rows.Sort((x, y) => x.name.CompareTo(y.name));
            this.prop_list.Items.Refresh();
            this.fix_listview_column_widths(this.prop_list);
            this.set_dirty();
        }
        private void container_add(object sender, RoutedEventArgs e)
        {
            if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name)))
            {
                return;
            }
            ElementReference <ItemSpec> item_ref = this.state.items[this.selection.name];

            if (item_ref.ref_count > 0)
            {
                return;
            }
            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING),
                new QueryPrompt("Weight Factor:", QueryType.FLOAT, 1.0, step: 0.125),
                new QueryPrompt("Weight Capacity:", QueryType.FLOAT),
            };
            object[] results = SimpleDialog.askCompound("Add Container", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string;
            double?weight_factor = results[1] as double?, weight_capacity = results[2] as double?;

            if ((name is null) || (weight_factor is null))
            {
                return;
            }
            if (weight_capacity == 0)
            {
                weight_capacity = null;
            }

            ContainerSpec container = new ContainerSpec(name, (decimal)weight_factor, (decimal?)weight_capacity);

            this.containers.Add(container);
            this.container_rows.Add(new ItemSpecContainerRow(container.name, container.weight_factor.ToString(), container.weight_capacity.ToString()));
            this.container_list.Items.Refresh();
            this.fix_listview_column_widths(this.container_list);
            this.set_dirty();
        }
        private void add_category(object sender, RoutedEventArgs e)
        {
            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING),
                new QueryPrompt("Value Factor:", QueryType.FLOAT, 1.0, step: 0.125),
            };
            object[] results = SimpleDialog.askCompound("Add Category", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string;

            if ((name is null) || (this.state.categories.ContainsKey(name)))
            {
                return;
            }

            this.do_add_category(name, (decimal)(results[1] as double?));
            this.item_list.Items.Refresh();
        }
        private void prop_add(object sender, RoutedEventArgs e)
        {
            if ((this.selection is null) || (this.selection.is_category) || (!this.state.items.ContainsKey(this.selection.name)))
            {
                return;
            }
            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING),
                new QueryPrompt("Value:", QueryType.STRING),
            };
            object[] results = SimpleDialog.askCompound("Add Property", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string, value = results[1] as string;

            if ((name is null) || (value is null))
            {
                return;
            }

            this.properties[name] = value;
            for (int i = 0; i < this.property_rows.Count; i++)
            {
                if (this.property_rows[i].name == name)
                {
                    this.property_rows.RemoveAt(i);
                    break;
                }
            }
            this.property_rows.Add(new ItemSpecPropertyRow(name, value));
            this.property_rows.Sort((x, y) => x.name.CompareTo(y.name));
            this.prop_list.Items.Refresh();
            this.fix_listview_column_widths(this.prop_list);
            this.set_dirty();
        }
        private void add_item(object sender, RoutedEventArgs e)
        {
            string default_cat = null;

            if (this.selection is not null)
            {
                if (this.selection.is_category)
                {
                    default_cat = this.selection.name;
                }
                else
                {
                    ElementReference <ItemSpec> sel_ref = this.state.items[this.selection.name];
                    default_cat = sel_ref.element.category.name;
                }
            }
            QueryPrompt[] prompts = new QueryPrompt[] {
                new QueryPrompt("Name:", QueryType.STRING),
                new QueryPrompt("Category:", QueryType.LIST, default_cat, values: this.categories.ToArray(), canEdit: true),
                new QueryPrompt("Cost:", QueryType.FLOAT),
                new QueryPrompt("Weight:", QueryType.FLOAT),
            };
            object[] results = SimpleDialog.askCompound("Add Item", prompts, this);
            if (results is null)
            {
                return;
            }

            string name = results[0] as string, cat_name = results[1] as string;
            double?cost = results[2] as double?, weight = results[3] as double?;

            if ((name is null) || (this.state.items.ContainsKey(name)) || (cat_name is null) || (cost is null) || (weight is null))
            {
                return;
            }

            ItemLibraryItemRow cat_row;
            int cat_idx = this.categories.IndexOf(cat_name);

            if (cat_idx >= 0)
            {
                cat_row = this.item_rows[cat_idx];
            }
            else
            {
                double?sale_value = SimpleDialog.askFloat(cat_name, "Value Factor:", 1.0, step: 0.125, owner: this);
                if (sale_value is null)
                {
                    return;
                }
                cat_row = this.do_add_category(cat_name, (decimal)sale_value);
            }

            ItemSpec item = new ItemSpec(name, this.state.categories[cat_name].element, (decimal)cost, (decimal)weight);

            this.state.items[name] = new ElementReference <ItemSpec>(item);
            this.state.add_category_reference(item);

            ItemLibraryItemRow row = new ItemLibraryItemRow(name);

            if (!this.dirty)
            {
                if (this.selection is not null)
                {
                    this.selection._is_selected = false;
                }
                cat_row._is_expanded = true;
                row._is_selected     = true;
            }
            cat_row._items.Add(row);
            cat_row._items.Sort((x, y) => x.name.CompareTo(y.name));
            this.item_list.Items.Refresh();
        }
Beispiel #8
0
        //other menu handlers

        // Timeline handlers
        public void adjustDate(object sender, RoutedEventArgs e)
        {
            if (this.campaign == null)
            {
                return;
            }
            int amount = 1;

            Calendar.Interval unit;
            String            lbl = (String)(((Button)sender).Content);

            if (lbl.Length != 2)
            {
                return;
            }
            if ((lbl[0] != '+') && (lbl[0] != '-'))
            {
                return;
            }
            switch (lbl[1])
            {
            case '?':
                String[]      intervals = new String[] { "year(s)", "month(s)", "week(s)", "day(s)", "hour(s)", "minute(s)", "second(s)" }; // time omitted
                QueryPrompt[] prompts   =
                {
                    new QueryPrompt("", QueryType.INT,  amount,     0),
                    new QueryPrompt("", QueryType.LIST, "month(s)", values: intervals)
                };
                object[] values = SimpleDialog.askCompound((lbl[0] == '+' ? "Advance" : "Rewind"), prompts, this);
                if (values == null)
                {
                    return;
                }
                amount = (int)(values[0]);
                int idx = Array.IndexOf(intervals, values[1]);
                if ((idx < 0) || (idx >= intervals.Length))
                {
                    return;
                }
                if (idx >= (int)(Calendar.Interval.time))
                {
                    idx += 1;
                }                                                       // adjust idx because time was omitted from intervals
                unit = (Calendar.Interval)idx;
                break;

            case 'Y':
                unit = Calendar.Interval.year;
                break;

            case 'M':
                unit = Calendar.Interval.month;
                break;

            case 'D':
                unit = Calendar.Interval.day;
                break;

            case 'H':
                unit = Calendar.Interval.hour;
                break;

            default:
                return;
            }
            if (lbl[0] == '-')
            {
                amount = -amount;
            }
            this.campaign.adjustTimestamp(amount, unit);
            this.showCampaign();
        }