Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: translates csharp-api #63

Open
wants to merge 3 commits into
base: docs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# Home
# 骑马与砍杀2 领主 Mod 制作文档

## Introduction to Modding
原文档: [Bannerlord Documentation](https://docs.bannerlordmodding.com/)
作者: [Bannerlord Modding](https://github.com/Bannerlord-Modding)
译者: [衣谷作坊-Oliver](mailto:[email protected]), [世俗骑士](mailto:[email protected]),[上官云泽](mailto:[email protected]).

* [Getting Started](_intro/getting-started.md)
* [Folder Structure](_intro/folder-structure.md)
* [Advanced](_intro/advanced.md)
## Mod 制作简介

## Tutorials
* [开始](_intro/getting-started.md)
* [文件结构](_intro/folder-structure.md)
* [高级用法](_intro/advanced.md)

* [Basic C# Mod](_tutorials/basic-csharp-mod.md) (Requires a basic understanding of C#)
* [Modding Gauntlet UIs Without C#](_tutorials/modding-gauntlet-without-csharp.md) (Easy)
* [Packing your Mods for Vortex](_tutorials/packing_mods_for_vortex.md) (Easy)
* [Modifying/Adding Settlements](_tutorials/new_settlements.md) (Easy)
## 教程

* [基本C\# Mod 入门](_tutorials/basic-csharp-mod.md) \(需要一定基础的 C\#\)
* [不需要C\#的UI系统 Mod 入门](_tutorials/modding-gauntlet-without-csharp.md) \(简单\)
* [将你的mod打包上传至Vortex](_tutorials/packing_mods_for_vortex.md) \(简单\)
* [修改/增加 定居点](_tutorials/new_settlements.md) (简单)

## [C# API Documentation](_csharp-api/)

* [CampaignSystem](_csharp-api/campaignsystem/)
* [Core](_csharp-api/core/)
* [Engine](_csharp-api/engine/)
* [InputSystem](_csharp-api/inputsystem/)
* [Library](_csharp-api/library/)
* [Localization](_csharp-api/localization/)
* [战役系统](_csharp-api/campaignsystem/)
* [核心](_csharp-api/core/)
* [引擎](_csharp-api/engine/)
* [输入系统](_csharp-api/inputsystem/)
* [](_csharp-api/library/)
* [本地化](_csharp-api/localization/)
* [MountAndBlade](_csharp-api/mountandblade/)
* [Network](_csharp-api/network/)
* [PlatformService](_csharp-api/platformservice/)
* [SaveSystem](_csharp-api/savesystem/)
* [网络](_csharp-api/network/)
* [平台服务](_csharp-api/platformservice/)
* [保存系统](_csharp-api/savesystem/)
* [TwoDimension](_csharp-api/twodimension/)

## [Gauntlet Documentation](_gauntlet/)
Expand All @@ -41,10 +45,9 @@

## [XML Documentation](_xmldocs)

* [Atmosphere](_xmldocs/atmosphere.md) (.xml)
* [Cultures](_xmldocs/cultures.md) (.xml)
* [Items](_xmldocs/items.md) (.xml)
* [NPCCharacters](_xmldocs/npccharacters.md) (.xml)
* [Scene](_xmldocs/scene.md) (.xml)
* [SubModule](_xmldocs/submodule.md) (.xml)

* [环境](_xmldocs/atmosphere.md) (.xml)
* [文化](_xmldocs/cultures.md) (.xml)
* [物品](_xmldocs/items.md) (.xml)
* [NPC角色](_xmldocs/npccharacters.md) (.xml)
* [场景](_xmldocs/scene.md) (.xml)
* [子模块](_xmldocs/submodule.md) (.xml)
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ChangeOwnerOfSettlementAction
# ChangeOwnerOfSettlementAction

The function of this class is to set or change the owner of a settlement.
这个类中的函数是用来设置或者更改定居点拥有者的.

## Functions
## 函数

Here is a list of functions that detail different ways a settlement can change ownership:
- `ApplyByDefault(`[Hero](../hero.md)`hero, `[Settlement](../settlement.md)`settlement)` - Called at the start of a campaign or when a player cheats to attain a settlement
以下列表罗列了通过不同方法来更改定居点拥有权的函数:
- `ApplyByDefault(`[Hero](../hero.md) `hero, `[Settlement](../settlement.md)`settlement)` - 在开始战役或者玩家启用作弊获取定居点时启用
- `ApplyByKingDecision(`[Hero](../hero.md)`hero, `[Settlement](../settlement.md)`settlement)`
- `ApplyBySiege(`[Hero](../hero.md)`newOwner, `[Hero](../hero.md)`capturerHero, `[Settlement](../settlement.md)`settlement)`
- `ApplyByRevolt(`[Hero](../hero.md)`hero, `[Settlement](../settlement.md)`settlement)`
- `ApplyByLeaveFaction(`[Hero](../hero.md)`hero, `[Settlement](../settlement.md)`settlement)`
- `ApplyByBarter(`[Hero](../hero.md)`hero, `[Settlement](../settlement.md)`settlement)`
- `ApplyByRemoveFaction(`[Settlement](../settlement.md)`settlement)`
- `ApplyByDestroyClan(`[Settlement](../settlement.md)`settlement, `[Hero](../hero.md)`newOwner)` - Called when owner of settlement dies, when this happens, the fief is passed to a random child of the previous owner
- `ApplyByDestroyClan(`[Settlement](../settlement.md)`settlement, `[Hero](../hero.md)`newOwner)` - 定居点的拥有者在死亡后其采邑将随机分封给前任拥有者的子嗣.
23 changes: 12 additions & 11 deletions _csharp-api/campaignsystem/campaignbehaviorbase.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# CampaignBehaviorBase
This is an abstract class within [TaleWorlds.CampaignSystem](./README.md), and can be inherited to code for unique behaviours within the game's campaign.
# CampaignBehaviorBase 类

## Abstract Methods:
#### ```public abstract void RegisterEvents()```
When defining this method, you can introduce consequences to certain events, by use of the `CampaignEvents.On...` methods. A simple example would be:
这是一个抽象类[TaleWorlds.CampaignSystem](./README.md),它可以为战役中的独特行为的代码所继承.

## 抽象方法:
### ```public abstract void RegisterEvents()```
定义此方法时,可以用`CampaignEvents.On...`来确定事件的结果.简易范例:
```csharp
public override void RegisterEvents()
{
Expand All @@ -14,20 +15,20 @@ public override void RegisterEvents()
}));
}
```
The above example registers an event, such that when a clan is destroyed, a message is broadcasted to the chat. The `AddNonSerializedListener` method called here requires the second argument to be an action, which is described [here](https://docs.microsoft.com/en-us/dotnet/api/system.action-1?view=netframework-4.8).
上面的范例注册为一个事件,譬如某个家族灭亡时在消息框会宣布此消息. `AddNonSerializedListener`方法调用的第二个变量是一个动作,对于此动作描述[点击这里](https://docs.microsoft.com/en-us/dotnet/api/system.action-1?view=netframework-4.8).

#### ```public abstract void SyncData(IDataStore dataStore)```
(Work in Progress)
###```public abstract void SyncData(IDataStore dataStore)```
(译者注:原作者说未完工)

**NOTE**: We are currently not sure what this method does, but at the moment we recommended you implement it as an empty method, like so:
**注意**:这个方法至今我们仍费解,但我们强烈建议直接放上空方法如下:
```csharp
public override void SyncData(IDataStore dataStore)
{
}
```

## Registering Campaign Behaviors:
Within your [MBSubModuleBase](../mountandblade/mbsubmodulebase.md) class, you can utilise the `OnGameStart` Method to add the behavoir to a campaign. An example is given below:
## 注册战役行为:
在你的[MBSubModuleBase](../mountandblade/mbsubmodulebase.md)类中,你可以用`OnGameStart`方法来为战役添加行为.以下为示例:
```csharp
protected override void OnGameStart(Game game, IGameStarter gameStarter)
{
Expand Down
50 changes: 22 additions & 28 deletions _csharp-api/campaignsystem/campaigngamestarter.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
# CampaignGameStarter
This class can be used to introduce behaviours, dialog, menus and models for campaigns, and implements the IGameStarter interface. This is useful in the `OnGameStart` method in [MBSubModuleBase](mbsubmodulebase.md), which is shown in the example.
# CampaignGameStarter 类

**NOTE**: *This page is incomplete, so if you find anymore information on the subject, please create a pull request and add to this growing Modding Documentation!*
这个类用于给战役来描述行为,对话,菜单和模型,并运行`IGameStarter`接口.这在`OnGameStart`方法中很有用,这里有实例[MBSubModuleBase](mbsubmodulebase.md).

## Accessible Methods:
#### `public void ClearEmptyObjects()`
(Work in progress)
**注意**:*本页还未完工,如果你发现了这方面更多的内容,请提交pull request来完善该文档.*

##已知方法:
####`public void ClearEmptyObjects()`
(有待完善)
#### `public void AddBehavior(CampaignBehaviorBase campaignBehavior)`
Adds the [Campaign Behavior](campaignbehaviorbase.md) to the current campaign.
添加[Campaign Behavior](campaignbehaviorbase.md)到当前战役.
#### `public void AddModel(GameModel model)`
Adds the [Game Model](../core/gamemodel.md) to the current campaign.
添加[Game Model](../core/gamemodel.md)到当前战役.
#### `public void LoadGameTexts(string xmlPath)`
(Work in progress) Loads XML file at the inputted path, introducing more texts to the game. These texts are in the same format as the *comment_strings.xml* file, with their purpose currently not determined.
(有待完善)在输入路径中加载更多文本描述的XML文件.这些文本都有着*comment_strings.xml*这样的格式,然而当前还不知它们的作用.
#### `public void LoadGameMenus(Type typeOfGameMenusCallbacks, string xmlPath)`
(Work in progress) Loads XML file at the inputted path, introducing more menus to the game.
(有待完善)在输入路径中加载更多菜单描述的XML文件.
#### `public void AddGameMenu(string menuId, string menuText, OnInitDelegate initDelegate, GameOverlays.MenuOverlayType overlay = GameOverlays.MenuOverlayType.None, GameMenu.MenuFlags menuFlags = GameMenu.MenuFlags.none, object relatedObject = null)`
See [GameMenu](gamemenu.md) for use.
用法参见[GameMenu](gamemenu.md).
#### `public void AddWaitGameMenu(string idString, string text, OnInitDelegate initDelegate, OnConditionDelegate condition, OnConsequenceDelegate consequence, OnTickDelegate tick, GameMenu.MenuAndOptionType type, GameOverlays.MenuOverlayType overlay = GameOverlays.MenuOverlayType.None, float targetWaitHours = 0f, GameMenu.MenuFlags flags = GameMenu.MenuFlags.none, object relatedObject = null)`
(Work in progress)
(有待完善)
#### `public void AddGameMenuOption(string menuId, string optionId, string optionText, GameMenuOption.OnConditionDelegate condition, GameMenuOption.OnConsequenceDelegate consequence, bool isLeave = false, int index = -1, bool isRepeatable = false)`
See [GameMenu](gamemenu.md) for use.
## Accessible Attributes:
**NOTE**: *All of these are get/read only*
用法参见[GameMenu](gamemenu.md).

##已知属性
**注意**:*所有这些属性只有读取功能*
#### `public readonly bool IsTutorial`
Whether or not the campaign starts with a tutorial.
战役开局是否开启教学.
#### `public ICollection<CampaignBehaviourBase> CampaignBehaviors`
Collection of all registered [Campaign Behaviours](campaignbehaviorbase.md).
所有已注册的战役行为收录[Campaign Behaviours](campaignbehaviorbase.md).
#### `public IEnumerable<GameModel> Models`
Enumerable Set of all registered [Game Models](../core/gamemodel.md)
枚举所有已注册的游戏模型[Game Models](../core/gamemodel.md).

## Example Use:
This is used within our [MBSubModuleBase]() class:
##示例应用
[MBSubModuleBase]( mbsubmodulebase.md) 类中使用:
```csharp
protected override void OnGameStart(Game game, IGameStarter gameStarter)
{
if(game.GameType is Campaign)
{
//Current game is a campaign, so IGameStarter object must be CampaignGameStarter
CampaignGameStarter campaignStarter = (CampaignGameStarter) gameStarter;
//Can now use CampaignGameStarter
}
}
```
23 changes: 12 additions & 11 deletions _csharp-api/campaignsystem/gamemenu.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# GameMenu

All the menus in the campaign are handled by the `GameMenuManager`. To add new menus however you must use the provided methods by the `Campaign` class.

To add a new menu use:
战役中所有的菜单选项都由`GameMenuManager`管理。你必须通过提供`Campaign`类中的方法,来加入新菜单。

加入新的菜单:
```csharp
CampaignGameStarter.AddGameMenu(string menuId, string menuText, OnInitDelegate initDelegate, MenuOverlayType overlay = MenuOverlayType.None, MenuFlags menuFlags = GameMenu.MenuFlags.none, object relatedObject = null)

delegate void OnInitDelegate(MenuCallbackArgs args);
```

The overlay defines if for example the upper right characters list is visible or not.
覆盖层(overlay)定义了例子中右上角字符列表是否可见。


To add a new option to a menu use:
为菜单加入新的选项:
```csharp
CampaignGameStarter.AddGameMenuOption(string menuId, string optionId, string optionText, OnConditionDelegate condition, OnConsequenceDelegate consequence, bool isLeave = false, int index = -1)

bool OnConditionDelegate(MenuCallbackArgs args);
void OnConsequenceDelegate(MenuCallbackArgs args);
```

You can add options to existing menus and for this the index comes in handy to insert it before other options (by default it insert at the end).

The provided condition method does double-duty as it:
* enables / disables the option (via it's return value)
* sets the icon (via the provided args)
您可以在现有菜单中添加选项。使用这个index参数时,可以方便地插入在其它选项之前(默认情况下,它会在末尾插入)。

The icon can be changed by setting `optionLeaveType` to something appropriate. The used images are found under `Mount & Blade II Bannerlord\GUI\GauntletUI\SpriteParts\ui_group1\GameMenu` and the correspondence can be viewed in `Mount & Blade II Bannerlord\Modules\Native\GUI\Brushes\GameMenu.xml`. This can of course be overrides in your own module, but additional `LeaveTypes` are not possible.
提供的条件方法(condition method)具有双重职责:
* 启用/禁用选项(通过返回值)
* 设置图标(通过提供的参数)

图标可以通过将 `optionLeaveType` 设置为恰当的值来改变。 可使用的图标在 `Mount & Blade II Bannerlord\GUI\GauntletUI\SpriteParts\ui_group1\GameMenu`目录下,相关的信息可在 `Mount & Blade II Bannerlord\Modules\Native\GUI\Brushes\GameMenu.xml`查看。 当然,你自己的模组可以重写这些东西,但是不能额外添加更多的`LeaveTypes`。
| Type | Image |
| ------------------- | ----- |
| Default | |
Expand All @@ -51,4 +52,4 @@ The icon can be changed by setting `optionLeaveType` to something appropriate. T
| WaitQuest | |
| Surrender | |
| Conversation | |
| DefendAction | |
| DefendAction | |
15 changes: 8 additions & 7 deletions _csharp-api/campaignsystem/hero.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Hero
hero.md
# Hero 类

Heroes are all the unique characters in the game. This class contains all the information of these characters and allows you to change them.
在游戏中所有的英雄都是独一无二的.这个类包含了所有这些英雄的信息,同时你也可以在此修改它们,

## Functions
Work in Progress
## 函数
(有待完善)

## Properties
- `CanHaveRecruits` - A boolean that details if this hero can have recruits. Preachers, Rural Notables, Mercenaries, Gang Leaders, Merchants, and Headmen can have recruits. This property can only be read, not changed.
## 属性

Work in Progress
- `CanHaveRecruits` -这是一个决定英雄是否可以带兵的布尔值.村中家世显赫的人,雇佣兵,绑匪头子,商人,首领等可以带兵.这个属性为可读属性不可更改.
(有待完善)
16 changes: 8 additions & 8 deletions _csharp-api/campaignsystem/settlement.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Settlement
# 定居点

Settlements are villages, castles, or towns on the campaign map.
定居点是大地图中的那些村子,城堡,及城镇.

## Tips
## 贴士

* You can get the current settlement with `Settlement.CurrentSettlement` assuming player is in the settlement.
*可以使用`Settlement.CurrentSettlement`让玩家占领当前定居点.

## Functions
Work in Progress
## 函数
(有待完善)

## Properties
Work in Progress
## 属性
(有待完善)
7 changes: 3 additions & 4 deletions _csharp-api/core/basiccharacterobject.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# BasicCharacterObject

BasicCharacterObjects contain the deserialized information from the `npccharacters` XML file. This includes the BodyProperties, Equipment, Level, Skills, and Culture for each defined character.
`BasicCharacterObjects` 包含了 `npccharacters` XML 文件中的反序列化信息。每个被定义的角色有 `BodyProperties`, `Equipment`, `Level`, `Skills`, 和 `Culture` 信息。

BasicCharacterObjects are used as the building blocks for [Agents](../mountandblade/agent.md).
`BasicCharacterObjects` 一般用来构建 [Agents](../mountandblade/agent.md) 的区块。

You can use the [MBObjectManager](mbobjectmanager.md) to get a loaded BasicCharacterObject by using the following:
你可以用 [MBObjectManager](mbobjectmanager.md) 来获取一个加载后的 `BasicCharacterObject` ,代码如下:

```csharp
MBObjectManager.Instance.GetObject<BasicCharacterObject>("example_troop_id");
```

6 changes: 3 additions & 3 deletions _csharp-api/core/informationmanager.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# InformationManager

The information manager is a high-level way to print text to the chat log (e.g. damage) or to display an inquiry to the player (e.g. yes/no confirmation).
InformationManager是一种向提示信息(例如:伤害)输出文本,或者向玩家显示提问(例如:是/否 确认)的的高级手段。

## Outputting to Chat Log
## 输出至提示信息

```csharp
InformationManager.DisplayMessage()
```

## Displaying an Inquiry
## 显示提问

```csharp
InformationManager.ShowInquiry()
Expand Down
12 changes: 5 additions & 7 deletions _csharp-api/core/mbobjectmanager.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# MBObjectManager
# MBObjectManager

The object manager is something that you will be using a lot in the modding of Bannerlord, so it is important to familiarize yourself with it.
在给`霸主`做模组中你会频繁使用对象管理器,所以你需要熟练运用它.

The MBObjectManager can be used to get any object in the game that is currently loaded from the XMLs.
MBObjectManager可以用于一切从XML中加载进游戏的对象.

These include:
内容包括:

* [BasicCharacterObjects](basiccharacterobject.md)
* CharacterAttributes
Expand All @@ -18,9 +18,7 @@ These include:
* SkillObjects
* SiegeEngineTypes

Example of getting a [BasicCharacterObject](basiccharacterobject.md):

获取基本角色对象的例子[BasicCharacterObject](basiccharacterobject.md):
```csharp
MBObjectManager.Instance.GetObject<BasicCharacterObject>("example_troop_id");
```

12 changes: 6 additions & 6 deletions _csharp-api/engine/gameentity.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# GameEntity

GameEntities are objects (entities) in the game. Examples include characters, buildings, trees, and horses to name a few. Every prop in the game is a GameEntity.
游戏实体 `GameEntity` 指的是游戏里的对象\(或称之为实体\)。举几个例子:角色,建筑,树木,马匹……等等等等。凡是游戏里出现的每个物件都是一个游戏实体。

GameEntities contain Meshes, Skeletons, PhysicsBodies, and ScriptComponents along with a variety of other things for each object in the game.
每一个游戏实体,包含了:网格\(`Mesh`\),骨架\(`Skeleton`\),刚体\(`PhysicsBody`\),脚本组件\(`ScriptComponent`\)以及各种游戏里的对象附带的其他内容。

You can add a GameEntity to a scene by editing the [Scene](../../_xmldocs/scene.md)'s `scene.xscene` file or spawn (instantiate) one directly using the following static method from the GameEntity class:
要向场景里添加一个游戏实体,除了通过编辑场景\([Scene](../../_xmldocs/scene.md)\)文件`scene.xscene`外,也可以直接通过`GameEntity`类的静态方法`Instantiate`“刷出”\(实例化出\)一个,比如:

```csharp
GameEntity.Instantiate(Scene scene, string prefabName, MatrixFrame frame)
```

Example Usage (spawning at main [Agent](../mountandblade/agent.md)):
另一个例子,往`main [Agent]`(../mountandblade/agent.md)里生成一个物体。\(注:`Agent`负责处理活物\)

```csharp
GameEntity.Instantiate(Mission.Current.Scene, "ship_a", Agent.Main.Frame)
```

## Multiplayer GameEntities
## 多人模式中的游戏实体

Some GameEntities will not be synced between Clients, unless a SynchedMissionObject ScriptComponent is added.
某些游戏实体无法在玩家的客户端之间同步,因此你需要自己往脚本组件\(`ScriptComponent`\)里添加 `SynchedMissionObject`。

Loading