private void showMod(Mod mod, bool clickable) { //Show the given mod Image img = new Image(); img.Width = 60; img.Height = 60; img.Source = getImage(mod.imagePath); content.Children.Add(img); ChangeLocation(img, mod.x - 30, mod.y - 30); if (clickable) { if (typeof(Switch) == mod.GetType()) { Switch convert = (Switch)mod; img.MouseLeftButtonDown += convert.OnClick; } img.MouseRightButtonDown += (sender, e) => onRightClick(sender, e, mod); img.MouseLeftButtonDown += (sender, e) => Select(sender, e, mod); } img.IsHitTestVisible = true; }
private void timer_Tick(object sender, object e) { //Tick content.Children.Clear(); ShowSelect(); //Draw controls for (int i = 0; i < ModList.Count; i++) { showMod(ModList[i]); //Refresh bulb images if (typeof(Bulb) == ModList[i].GetType()) { ModList[i].isActive(conns.ToArray()); } } //Draw preview if (PreviewMod != null && isValidPosition(PreviewMod.x, PreviewMod.y)) { showMod(PreviewMod, false); } //Draw connections for (int i = 0; i < conns.Count; i++) { Line l = new Line(); if (conns[i].output.isActive(conns.ToArray())) { l.Stroke = Brushes.Green; } else { l.Stroke = Brushes.Red; } l.X1 = conns[i].input.x - 30; l.X2 = conns[i].output.x + 30; l.Y1 = conns[i].input.y; l.Y2 = conns[i].output.y; l.StrokeThickness = 2; content.Children.Add(l); } //Refresh info if (ModList.Count == 0 && add_selectedtype == 0) { ChangeInfo("You can add controls by selecting it at the top left corner and pressing 'Select'."); } else if (add_selectedtype > 0) { string[] name = GetType(add_selectedtype).ToString().Split('.'); ChangeInfo("You have selected a(n) " + name[1] + ". Put it to the gray area, or cancel it by pressing the right mouse button."); } else if (ModList.Count >= 2 && conns.Count == 0 && currentConn == null) { ChangeInfo("You can connect two controls if you press the right mouse button on them."); } else if (currentConn != null) { ChangeInfo("Press the right mouse button to connect the currently selected control's output to an another's input."); } else if (SelectedMod != null && SelectedMod.GetType() == typeof(Switch)) { ChangeInfo("You can change the switch's value by pressing the left mouse button on it."); } else { ChangeInfo(""); } //Cancel button text if (currentConn != null) { remove_conn.Content = "Cancel connection"; remove_conn.IsEnabled = true; } else if (add_selectedtype != 0) { remove_conn.Content = "Cancel add control"; remove_conn.IsEnabled = true; } else { remove_conn.IsEnabled = false; } timer.Start(); }