Okay cool, it seems KevL has been pretty active on his fork which is nice to see. I made my own fork (
https://github.com/madhatr/OpenXCOM.Tools) to get more acquainted with the code. Not going to give any illusions, this shit is above my paygrade. Especially whatever is doing all the rendering and array setup for the pictures/tiles and what not. What I am ok with is the forms part. Currently my goal is to add hotkey functionality, if you check the fork so far I've just been fixing cosmetic stuff, and some old code that doesn't seem to be needed anymore.
I do need some help here though, I got stuck. The(cut, copy, fill) buttons (toolstripbuttons) were all made manually in a separate .cs file.
Spoiler EditButtonsFactory.cs:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using MapView.Properties;
namespace MapView.Forms.MainWindow
{
internal sealed class EditButtonsFactory
{
private readonly MainViewPanel _mainViewPanel;
private readonly List<ToolStripButton> _pasteButtons = new List<ToolStripButton>();
public EditButtonsFactory(MainViewPanel panel)
{
_mainViewPanel = panel;
}
/// <summary>
/// Adds buttons for Up,Down,Cut,Copy,Paste and Fill to the specified
/// toolstrip as well as sets some properties for the toolstrip.
/// </summary>
/// <param name="toolStrip"></param>
public void BuildEditStrip(ToolStrip toolStrip)
{
//
// toolStripButtons
//
//var tssDivider1 = new ToolStripSeparator();
var tsbUp = new ToolStripButton();
var tsbDown = new ToolStripButton();
//var tssDivider2 = new ToolStripSeparator();
var tsbCut = new ToolStripButton();
var tsbCopy = new ToolStripButton();
var tsbPaste = new ToolStripButton();
//var tssDivider3 = new ToolStripSeparator();
var tsbFill = new ToolStripButton();
//var tssDivider4 = new ToolStripSeparator();
//
// toolStrip
//
var tsItems = new ToolStripItem[] // NOTE: c# cant figure out how to use 1 separator 3 times. //Just created them on the fly in the array MadHaTr 4/21/2017
{
new ToolStripSeparator(),
tsbUp,
tsbDown,
new ToolStripSeparator(),
tsbCut,
tsbCopy,
tsbPaste,
new ToolStripSeparator(),
tsbFill,
new ToolStripSeparator()
};
toolStrip.Items.AddRange(tsItems);
//
// tsbUp
//
tsbUp.AutoSize = false;
tsbUp.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsbUp.ImageScaling = ToolStripItemImageScaling.None;
tsbUp.ImageTransparentColor = Color.Magenta;
tsbUp.Name = "tsbUp";
tsbUp.Size = new Size(25, 25);
// tsbUp.Text = "Level Up";
tsbUp.ToolTipText = "Level Up";
tsbUp.Click += OnUpClick;
//
// tsbDown
//
tsbDown.AutoSize = false;
tsbDown.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsbDown.ImageScaling = ToolStripItemImageScaling.None;
tsbDown.ImageTransparentColor = Color.Magenta;
tsbDown.Name = "tsbDown";
tsbDown.Size = new Size(25, 25);
// tsbDown.Text = "Level Down";
tsbDown.ToolTipText = "Level Down";
tsbDown.Click += OnDownClick;
//
// tsbCut
//
tsbCut.AutoSize = false;
tsbCut.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsbCut.ImageScaling = ToolStripItemImageScaling.None;
tsbCut.ImageTransparentColor = Color.Magenta;
tsbCut.Name = "tsbCut";
tsbCut.Size = new Size(25, 25);
// tsbCut.Text = "Cut";
tsbCut.ToolTipText = "Cut";
tsbCut.Click += (sender, e) =>
{
EnablePasteButton();
_mainViewPanel.OnCut(sender, e);
Refresh();
};
//
// tsbCopy
//
tsbCopy.AutoSize = false;
tsbCopy.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsbCopy.ImageScaling = ToolStripItemImageScaling.None;
tsbCopy.ImageTransparentColor = Color.Magenta;
tsbCopy.Name = "tsbCopy";
tsbCopy.Size = new Size(25, 25);
// tsbCopy.Text = "Copy";
tsbCopy.ToolTipText = "Copy";
tsbCopy.Click += (sender, e) =>
{
EnablePasteButton();
_mainViewPanel.OnCopy(sender, e);
};
//
// tsbPaste
//
tsbPaste.AutoSize = false;
tsbPaste.DisplayStyle = ToolStripItemDisplayStyle.Image;
tsbPaste.ImageScaling = ToolStripItemImageScaling.None;
tsbPaste.ImageTransparentColor = Color.Magenta;
tsbPaste.Name = "tsbPaste";
tsbPaste.Size = new Size(25, 25);
// tsbPaste.Text = "Paste";
tsbPaste.ToolTipText = "Paste";
tsbPaste.Click += (sender, e) =>
{
_mainViewPanel.OnPaste(sender, e);
Refresh();
};
tsbPaste.Enabled = false;
_pasteButtons.Add(tsbPaste);
//
// tsbFill
//
tsbFill.AutoSize = false;
tsbFill.DisplayStyle = ToolStripItemDisplayStyle.Text;
tsbFill.Name = "tsbFill";
tsbFill.Size = new Size(25, 25);
tsbFill.Text = "Fill";
tsbFill.ToolTipText = "Fill";
tsbFill.Click += (sender, e) =>
{
_mainViewPanel.OnFill(sender, e);
Refresh();
};
tsbUp.Image = Resources.up;
tsbDown.Image = Resources.down;
tsbCut.Image = Resources.cut;
tsbCopy.Image = Resources.copy;
tsbPaste.Image = Resources.paste;
// tsbFill.Image = ; // TODO: embed a Fill image.
}
private static void Refresh()
{
// MainViewPanel.Instance.Refresh(); // either this
MainViewPanel.Instance.MainView.Refresh(); // or this, both works
ViewerFormsManager.TopView.Refresh();
ViewerFormsManager.RouteView.Refresh();
// TODO: refresh TopRouteView (both Top & Route panels) also.
}
/// <summary>
/// Enables the paste button in each viewer after cut or copy is clicked.
/// </summary>
private void EnablePasteButton()
{
foreach (var tsb in _pasteButtons)
tsb.Enabled = true;
}
private void OnDownClick(object sender, EventArgs e)
{
if (MainViewPanel.Instance.MainView.Map != null)
MainViewPanel.Instance.MainView.Map.Down();
}
private void OnUpClick(object sender, EventArgs e)
{
if (MainViewPanel.Instance.MainView.Map != null)
MainViewPanel.Instance.MainView.Map.Up();
}
}
}
I am used to the designer creating the buttons and having them inside the main form class which I think of as the main program loop. In this case it would be XCMainWindow() inside this .cs file
My problem is I have/had a couple lines of code to detect keypresses in the main form file, and if a key is pressed it would trigger the .click functionality of the button. Problem is since they are in different files they are in different scopes? so when I try to trigger the buttons .click from inside the main loop (XCMainWindow()) it had no idea what I am talking about cause in its eye it does not exist.
Usually I think anyway, you could just make these functions/variables public and they would be available to the other files(classes? methods?) Though the EditButtonsFactory.cs class is declared in a way I do no understand I guess. I've not very good with classes and it gets worse when they are across different files.
I can just redo all the buttons in main cs file but I don't want to get to far away from KevL's code if he wants to merge my other smaller cosmetic fixes in. Also new to GitHub so not really sure how its controlled.
So anyway, anyone who thinks they can offer solution, feel free to do so. I spent all day yesterday messing around with this stuff. It can be fun.