private void pbRender_MouseDown(object sender, MouseEventArgs e) { if (currentMap != null && e.Button == System.Windows.Forms.MouseButtons.Left) { Point objectPosition = new Point(e.X / tileSize, e.Y / tileSize); List <IMapPlaceable> possibleSelections = currentMap.Objects.Cast <IMapPlaceable>().Concat(currentMap.Notes).Where(x => x.GetPosition() == objectPosition).ToList(); if (possibleSelections.Count != 0) { int removeRange = possibleSelections.IndexOf(currentPlaceable) + 1; if (possibleSelections.Count != removeRange) { possibleSelections.RemoveRange(0, removeRange); } IMapPlaceable newSelection = possibleSelections.FirstOrDefault(x => x != currentPlaceable); if (newSelection != null && newSelection.IsValid()) { lbMapPlaceables.SelectedItem = currentPlaceable = newSelection; } nowDraggingPlaceable = true; } else { nowDraggingPlaceable = false; } } }
public IMapPlaceable CreateType(teMapPlaceableData.CommonStructure commonStructure, BinaryReader reader) { if (Types.ContainsKey(commonStructure.Type)) { IMapPlaceable value = (IMapPlaceable)Activator.CreateInstance(Types[commonStructure.Type]); value.Read(reader); return(value); } if (_misingTypes.Add(commonStructure.Type)) { Debugger.Log(0, "teMapPlaceableManager", $"Unhandled placeable type: {commonStructure.Type}\r\n"); } return(null); }
private void lbMapPlaceables_Format(object sender, ListControlConvertEventArgs e) { if (e.DesiredType == typeof(string)) { IMapPlaceable placeable = (e.ListItem as IMapPlaceable); if (placeable is MapObject) { MapObject mapObject = (placeable as MapObject); e.Value = string.Format("Object #{0} (X:{1} Y:{2})", (Array.IndexOf(currentMap.Objects, mapObject) + 1), mapObject.XPosition, mapObject.YPosition); } else if (placeable is MapNote) { MapNote mapNote = (placeable as MapNote); e.Value = string.Format("Note #{0} (X:{1} Y:{2})", (Array.IndexOf(currentMap.Notes, mapNote) + 1), mapNote.XPosition, mapNote.YPosition); } } }
private void AddType(Type type) { IMapPlaceable instance = (IMapPlaceable)Activator.CreateInstance(type); Types[instance.Type] = type; }
private void lbMapPlaceables_SelectedValueChanged(object sender, EventArgs e) { currentPlaceable = ((sender as ListBox).SelectedItem as IMapPlaceable); pgMapPlaceable.SelectedObject = currentPlaceable; pbRender.Invalidate(); }