public override void Restore(Stream str) { base.Restore(str); if (str.ReadByte() == 0) { AcceptsFocus = str.ReadBool(); SortIndex = str.ReadInteger(); IsCheckable = str.ReadBool(); SlotHint = BinaryHelper.ReadString(str); short numberOfStates = str.ReadShort(); if (numberOfStates > 0) { for (int i = 0; i < numberOfStates; i++) { BlockState state = (BlockState)str.ReadShort(); SingleSlotBlockStateData ssbsd = new SingleSlotBlockStateData(); ssbsd.Restore(str); stateData.Add(state, ssbsd); } } } }
public SingleSlotBlockStateData this[BlockState state] { get { SingleSlotBlockStateData res = null; stateData.TryGetValue(state, out res); return(res); } }
private SingleSlotBlockStateData GetOrCreateDataForState(BlockState state) { SingleSlotBlockStateData res = null; stateData.TryGetValue(state, out res); if (res == null) { res = new SingleSlotBlockStateData(); } return(res); }
public void Unpack(FieldList source) { if (source == null) { return; } UnpackDefinitionID(source); IsCheckable = false; // unpacking common attributes AcceptsFocus = source[DefAgentFieldID.AcceptsFocus].AsBoolean() ?? false; SortIndex = source[DefAgentFieldID.SortSlotIndex].AsShort() ?? -1; SizeToBackgroundImage = source[DefAgentFieldID.BlockSizeToBackground].AsBoolean() ?? false; // loop through states PairedList <ByteField, FieldList> states = source.GetPairedItems <ByteField, FieldList>(DefAgentFieldID.ComponentState, DefAgentFieldID.DataPerComponentState); foreach (Pair <ByteField, FieldList> item in states) { BlockState state = (BlockState)item.First.Data; FieldList newData = item.Second; SingleSlotBlockStateData data = GetOrCreateDataForState(state); // slot style data data.SlotStyle = new SlotStyleData(); data.SlotStyle.Unpack(newData); // slot index data.SlotIndex = newData[DefAgentFieldID.SlotIndex].AsShort() ?? 0; // mark as checkable if applicable if ((state == BlockState.CheckedNormal) || (state == BlockState.CheckedFocused)) { IsCheckable = true; } // margins and paddings data.MarginLeft = newData[DefAgentFieldID.LeftMargin2].AsShort() ?? 0; data.MarginTop = newData[DefAgentFieldID.TopMargin2].AsShort() ?? 0; data.MarginRight = newData[DefAgentFieldID.RightMargin].AsShort() ?? 0; data.MarginBottom = newData[DefAgentFieldID.BottomMargin].AsShort() ?? 0; data.PaddingLeft = newData[DefAgentFieldID.LeftPadding2].AsShort() ?? 0; data.PaddingTop = newData[DefAgentFieldID.TopPadding2].AsShort() ?? 0; data.PaddingRight = newData[DefAgentFieldID.RightPadding].AsShort() ?? 0; data.PaddingBottom = newData[DefAgentFieldID.BottomPadding].AsShort() ?? 0; data.MaximumChars = newData[DefAgentFieldID.MaximumChars].AsShort() ?? 0; data.MaximumLines = newData[DefAgentFieldID.MaximumLines].AsShort() ?? 0; data.MinimumLines = newData[DefAgentFieldID.MinimumLines].AsShort() ?? 0; // rendering hints FieldList firstSlotData = (FieldList)newData[DefAgentFieldID.SlotData]; if (firstSlotData != null) { string newSlotHint = firstSlotData[DefAgentFieldID.SlotHint].AsString(); if (newSlotHint != null) { SlotHint = newSlotHint; } } stateData.Add(state, data); } // rendering hints for the block UnpackBlockHints(source); // done IsUnpacked = true; }