public Issue() { WorkState = new WorkState(this); CloseState = new CloseState(this); DoneState = new DoneState(this); RejectState = new RejectState(this); SetState(new NewState(this)); }
// This decodes a reject state string, which has the following format: // sourcesector|targetsector=rejectstate,targetsector=rejectstate,targetsector=rejectstate, ... private List <RejectSet> DecodeRejectString(string str, out int sourcesector) { sourcesector = -1; try { List <RejectSet> result = new List <RejectSet>(); // Cut off the sourcesector part int separator = Array.IndexOf(str.ToCharArray(), '|'); sourcesector = int.Parse(str.Substring(0, separator), CultureInfo.InvariantCulture); str = str.Substring(separator + 1); // Translate sector index to fixed index sourcesector = General.Map.Map.GetSectorByIndex(sourcesector).FixedIndex; // Process the target sector states string[] targets = str.Split(','); foreach (string t in targets) { // Split target sector and state separator = t.IndexOf('='); int targetsector = int.Parse(t.Substring(0, separator), CultureInfo.InvariantCulture); RejectState rejectstate = (RejectState)int.Parse(t.Substring(separator + 1), CultureInfo.InvariantCulture); // Translate sector index to fixed index targetsector = General.Map.Map.GetSectorByIndex(targetsector).FixedIndex; result.Add(new RejectSet(targetsector, rejectstate)); } return(result); } catch (Exception) { if (sourcesector > -1) { General.ErrorLogger.Add(ErrorType.Error, "The reject information for sector " + sourcesector + " is corrupt."); } else { General.ErrorLogger.Add(ErrorType.Error, "Some or all of the reject information is corrupt."); } return(null); } }
// Constructor public RejectSet(int targetsector, RejectState rejectstate) { this.target = targetsector; this.state = rejectstate; }
protected override void OnEditBegin() { base.OnEditBegin(); if ((selected == null) || (highlighted == null)) { return; } // Create undo General.Map.UndoRedo.CreateUndo("Toggle sector reject"); // Get the list of states for target sectors List <RejectSet> targets; if (!BuilderPlug.Me.RejectChanges.TryGetValue(selected.FixedIndex, out targets)) { targets = new List <RejectSet>(); } // Determine the current state for the highlighted (target) sector int targetindex = -1; RejectState state = RejectState.None; for (int i = 0; i < targets.Count; i++) { RejectSet s = targets[i]; if (s.target == highlighted.FixedIndex) { targetindex = i; state = s.state; break; } } // Cycle to the next state switch (state) { case RejectState.None: state = RejectState.ForceHidden; break; case RejectState.ForceHidden: state = RejectState.ForceVisible; break; case RejectState.ForceVisible: state = RejectState.None; break; default: throw new NotImplementedException(); } // If the new state is 'None' then remove the target sector from the list, // else just update or add the state in the list. if (state == RejectState.None) { targets.RemoveAt(targetindex); } else if (targetindex > -1) { targets[targetindex] = new RejectSet(highlighted.FixedIndex, state); } else { targets.Add(new RejectSet(highlighted.FixedIndex, state)); } // Make sure the list is stored in our table of source sectors // or removed when there are no more manual changes. if (targets.Count > 0) { BuilderPlug.Me.RejectChanges[selected.FixedIndex] = targets; } else { BuilderPlug.Me.RejectChanges.Remove(selected.FixedIndex); } // Update! UpdateOverlay(); renderer.Present(); }