Skip to content

Commit a09712e

Browse files
committed
change: 状態取得・設定サンプルから駅リスト編集機能を別マッププラグインに分離
1 parent c590e9a commit a09712e

File tree

8 files changed

+266
-43
lines changed

8 files changed

+266
-43
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Automatic9045.MapPlugins.StationController</RootNamespace>
11+
<AssemblyName>StationController</AssemblyName>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Drawing" />
37+
<Reference Include="System.Windows.Forms" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="ControllerForm.cs">
47+
<SubType>Form</SubType>
48+
</Compile>
49+
<Compile Include="ControllerForm.gui.cs">
50+
<SubType>Form</SubType>
51+
</Compile>
52+
<Compile Include="StationController.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\AtsEx.PluginHost\AtsEx.PluginHost.csproj">
57+
<Project>{ac6ebf16-d22b-4da8-a0be-5afb729ea2e4}</Project>
58+
<Name>AtsEx.PluginHost</Name>
59+
<Private>False</Private>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<PropertyGroup>
64+
<PostBuildEvent>copy /y "$(TargetDir)" "$(SolutionDir)_SampleScenarios\Automatic9045\Maps\AtsExSampleMap\MapPlugins\"</PostBuildEvent>
65+
</PropertyGroup>
66+
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Forms;
8+
9+
using Automatic9045.AtsEx.PluginHost;
10+
using Automatic9045.AtsEx.PluginHost.ClassWrappers;
11+
12+
namespace Automatic9045.MapPlugins.StationController
13+
{
14+
public partial class ControllerForm : Form
15+
{
16+
public ControllerForm()
17+
{
18+
InitializeComponent();
19+
}
20+
21+
private void OnButtonClicked(object sender, EventArgs e)
22+
{
23+
IStationList stations = AtsExPlugin.BveHacker.CurrentScenarioProvider.Route.Stations;
24+
if (stations.Count == 0) return;
25+
stations.RemoveAt(stations.Count - 1);
26+
27+
if (stations.Count == 0)
28+
{
29+
RemoveLastStationButton.Enabled = false;
30+
}
31+
else
32+
{
33+
IStation lastStation = stations.Last() as IStation;
34+
lastStation.DepertureTime = int.MaxValue; // 終点の発車時刻は int.MaxValue に設定する
35+
lastStation.Pass = false;
36+
lastStation.IsTerminal = true;
37+
}
38+
39+
ITimeTable timeTable = AtsExPlugin.BveHacker.CurrentScenarioProvider.TimeTable;
40+
timeTable.NameTexts = new string[stations.Count + 1];
41+
timeTable.NameTextWidths = new int[stations.Count + 1];
42+
timeTable.ArrivalTimeTexts = new string[stations.Count + 1];
43+
timeTable.ArrivalTimeTextWidths = new int[stations.Count + 1];
44+
timeTable.DepertureTimeTexts = new string[stations.Count + 1];
45+
timeTable.DepertureTimeTextWidths = new int[stations.Count + 1];
46+
timeTable.Update();
47+
48+
AtsExPlugin.BveHacker.UpdateDiagram();
49+
}
50+
}
51+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Drawing;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
using Automatic9045.AtsEx.PluginHost;
12+
13+
namespace Automatic9045.MapPlugins.StationController
14+
{
15+
public partial class ControllerForm : Form
16+
{
17+
protected Button RemoveLastStationButton;
18+
19+
protected void InitializeComponent()
20+
{
21+
MaximizeBox = false;
22+
AutoScaleMode = AutoScaleMode.Dpi;
23+
ClientSize = new Size(400, 64);
24+
Font = new Font("Yu Gothic UI", 9);
25+
Text = "AtsEX マッププラグイン 停車場リスト編集サンプル";
26+
27+
RemoveLastStationButton = new Button()
28+
{
29+
Left = 16,
30+
Top = 16,
31+
Width = 80,
32+
Text = "駅を減らす",
33+
};
34+
RemoveLastStationButton.Click += OnButtonClicked;
35+
Controls.Add(RemoveLastStationButton);
36+
}
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
6+
// 制御されます。アセンブリに関連付けられている情報を変更するには、
7+
// これらの属性値を変更してください。
8+
[assembly: AssemblyTitle("AtsEX マッププラグイン:駅リスト編集サンプル")]
9+
[assembly: AssemblyDescription("AtsEX で駅リストを編集するサンプル")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("AtsEX")]
13+
[assembly: AssemblyCopyright("Copyright © 2022 automatic9045")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
18+
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
19+
// その型の ComVisible 属性を true に設定してください。
20+
[assembly: ComVisible(false)]
21+
22+
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
23+
[assembly: Guid("9bf5f305-141d-4b74-b5fe-27dc09ff68a5")]
24+
25+
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
26+
//
27+
// メジャー バージョン
28+
// マイナー バージョン
29+
// ビルド番号
30+
// リビジョン
31+
//
32+
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
33+
// 既定値にすることができます:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("0.4.20411.1")]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows.Forms;
7+
8+
using Automatic9045.AtsEx.PluginHost;
9+
10+
namespace Automatic9045.MapPlugins.StationController
11+
{
12+
public class StationController : AtsExPlugin, IDisposable
13+
{
14+
private ControllerForm Form;
15+
private ToolStripMenuItem MenuItem;
16+
17+
public StationController() : base()
18+
{
19+
MenuItem = AtsExPlugin.BveHacker.AddCheckableMenuItemToContextMenu("駅編集ウィンドウを表示", MenuItemCheckedChanged);
20+
21+
App.Started += Started;
22+
}
23+
24+
private void Started(StartedEventArgs e)
25+
{
26+
if (!(Form is null)) DisposeForm();
27+
28+
MenuItem.Checked = false;
29+
30+
Form = new ControllerForm();
31+
Form.FormClosing += FormClosing;
32+
Form.WindowState = FormWindowState.Normal;
33+
34+
MenuItem.Checked = true;
35+
BveHacker.MainForm.Focus();
36+
}
37+
38+
private void MenuItemCheckedChanged(object sender, EventArgs e)
39+
{
40+
if (MenuItem.Checked)
41+
{
42+
Form.Show(BveHacker.MainForm);
43+
}
44+
else
45+
{
46+
Form.Hide();
47+
}
48+
}
49+
50+
private void FormClosing(object sender, FormClosingEventArgs e)
51+
{
52+
e.Cancel = true;
53+
MenuItem.Checked = false;
54+
}
55+
56+
private void DisposeForm()
57+
{
58+
Form.FormClosing -= FormClosing;
59+
Form.Close();
60+
Form.Dispose();
61+
}
62+
63+
public void Dispose() => DisposeForm();
64+
}
65+
}

AtsEx.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VehiclePlugins", "VehiclePl
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtsEx.BveTypeCollection", "AtsEx.BveTypeCollection\AtsEx.BveTypeCollection.csproj", "{2F0061CC-C22A-4A33-B70F-77A01C264C6E}"
1717
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MapPlugins", "MapPlugins", "{FCA108F3-EC46-4DD5-962E-3ECCBC2100AE}"
19+
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtsEx.MapPlugin.StationController", "AtsEx.MapPlugin.StationController\AtsEx.MapPlugin.StationController.csproj", "{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}"
21+
EndProject
1822
Global
1923
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2024
Debug|Any CPU = Debug|Any CPU
@@ -37,13 +41,19 @@ Global
3741
{2F0061CC-C22A-4A33-B70F-77A01C264C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3842
{2F0061CC-C22A-4A33-B70F-77A01C264C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3943
{2F0061CC-C22A-4A33-B70F-77A01C264C6E}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{9BF5F305-141D-4B74-B5FE-27DC09FF68A5}.Release|Any CPU.Build.0 = Release|Any CPU
4048
EndGlobalSection
4149
GlobalSection(SolutionProperties) = preSolution
4250
HideSolutionNode = FALSE
4351
EndGlobalSection
4452
GlobalSection(NestedProjects) = preSolution
4553
{9205EC14-287D-413E-9E1C-64C92D58D1F2} = {31284256-F435-4CDC-B1B6-FCB71C97D6EF}
4654
{31284256-F435-4CDC-B1B6-FCB71C97D6EF} = {E528AAA7-6712-4D73-A3AB-BCF41E75F137}
55+
{FCA108F3-EC46-4DD5-962E-3ECCBC2100AE} = {E528AAA7-6712-4D73-A3AB-BCF41E75F137}
56+
{9BF5F305-141D-4B74-B5FE-27DC09FF68A5} = {FCA108F3-EC46-4DD5-962E-3ECCBC2100AE}
4757
EndGlobalSection
4858
GlobalSection(ExtensibilityGlobals) = postSolution
4959
SolutionGuid = {434AD268-BAE2-48A7-8AE5-2AB6B982F843}

Plugins/VehiclePlugins/AtsEx.VehiclePlugin.StateViewer/StateForm.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,6 @@ private void OnKeyDown(object sender, KeyEventArgs e)
5656
}
5757
}
5858

59-
private void OnButtonClicked(object sender, EventArgs e)
60-
{
61-
IStationList stations = AtsExPlugin.BveHacker.CurrentScenarioProvider.Route.Stations;
62-
if (stations.Count == 0) return;
63-
stations.RemoveAt(stations.Count - 1);
64-
65-
if (stations.Count == 0)
66-
{
67-
RemoveLastStationButton.Enabled = false;
68-
}
69-
else
70-
{
71-
IStation lastStation = stations.Last() as IStation;
72-
lastStation.DepertureTime = int.MaxValue; // 終点の発車時刻は int.MaxValue に設定する
73-
lastStation.Pass = false;
74-
lastStation.IsTerminal = true;
75-
}
76-
77-
ITimeTable timeTable = AtsExPlugin.BveHacker.CurrentScenarioProvider.TimeTable;
78-
timeTable.NameTexts = new string[stations.Count + 1];
79-
timeTable.NameTextWidths = new int[stations.Count + 1];
80-
timeTable.ArrivalTimeTexts = new string[stations.Count + 1];
81-
timeTable.ArrivalTimeTextWidths = new int[stations.Count + 1];
82-
timeTable.DepertureTimeTexts = new string[stations.Count + 1];
83-
timeTable.DepertureTimeTextWidths = new int[stations.Count + 1];
84-
timeTable.Update();
85-
86-
AtsExPlugin.BveHacker.UpdateDiagram();
87-
}
88-
8959
private void Elapse(EventArgs e)
9060
{
9161
if (!TimeValue.Focused) TimeValue.Text = AtsExPlugin.Route.Time.ToString("HH:mm:ss");

Plugins/VehiclePlugins/AtsEx.VehiclePlugin.StateViewer/StateForm.gui.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ public partial class StateForm : Form
4141
protected Label DisplaySpeedKey;
4242
protected Label DisplaySpeedValue;
4343

44-
protected Button RemoveLastStationButton;
45-
4644
protected void InitializeComponent()
4745
{
4846
MaximizeBox = false;
4947
AutoScaleMode = AutoScaleMode.Dpi;
50-
ClientSize = new Size(800, 600);
48+
ClientSize = new Size(480, 320);
5149
Font = new Font("Yu Gothic UI", 9);
5250
Text = "AtsEX 車両プラグイン 状態取得・設定サンプル";
5351

@@ -224,16 +222,6 @@ protected void InitializeComponent()
224222
};
225223
DisplaySpeedValue.KeyDown += OnKeyDown;
226224
Controls.Add(DisplaySpeedValue);
227-
228-
RemoveLastStationButton = new Button()
229-
{
230-
Left = 16,
231-
Top = 304,
232-
Width = 80,
233-
Text = "駅を減らす",
234-
};
235-
RemoveLastStationButton.Click += OnButtonClicked;
236-
Controls.Add(RemoveLastStationButton);
237225
}
238226
}
239227
}

0 commit comments

Comments
 (0)