Diplomacy menu
This commit is contained in:
@@ -89,6 +89,7 @@
|
|||||||
<Compile Include="Widgets\CncDownloadPackagesLogic.cs" />
|
<Compile Include="Widgets\CncDownloadPackagesLogic.cs" />
|
||||||
<Compile Include="CncMenuPaletteEffect.cs" />
|
<Compile Include="CncMenuPaletteEffect.cs" />
|
||||||
<Compile Include="Widgets\CncIngameMenuLogic.cs" />
|
<Compile Include="Widgets\CncIngameMenuLogic.cs" />
|
||||||
|
<Compile Include="Widgets\CncDiplomacyLogic.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
90
OpenRA.Mods.Cnc/Widgets/CncDiplomacyLogic.cs
Executable file
90
OpenRA.Mods.Cnc/Widgets/CncDiplomacyLogic.cs
Executable file
@@ -0,0 +1,90 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenRA.Mods.RA;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
|
{
|
||||||
|
public class CncDiplomacyLogic : IWidgetDelegate
|
||||||
|
{
|
||||||
|
World world;
|
||||||
|
|
||||||
|
[ObjectCreator.UseCtor]
|
||||||
|
public CncDiplomacyLogic([ObjectCreator.Param] Widget widget,
|
||||||
|
[ObjectCreator.Param] World world)
|
||||||
|
{
|
||||||
|
this.world = world;
|
||||||
|
var panel = widget.GetWidget("DIPLOMACY_PANEL");
|
||||||
|
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = Widget.CloseWindow;
|
||||||
|
|
||||||
|
var scrollpanel = panel.GetWidget<ScrollPanelWidget>("PLAYER_LIST");
|
||||||
|
var itemTemplate = scrollpanel.GetWidget("PLAYER_TEMPLATE");
|
||||||
|
scrollpanel.RemoveChildren();
|
||||||
|
|
||||||
|
foreach (var p in world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant))
|
||||||
|
{
|
||||||
|
Player pp = p;
|
||||||
|
var item = itemTemplate.Clone();
|
||||||
|
var nameLabel = item.GetWidget<LabelWidget>("NAME");
|
||||||
|
nameLabel.GetText = () => pp.PlayerName;
|
||||||
|
nameLabel.Color = pp.ColorRamp.GetColor(0);
|
||||||
|
|
||||||
|
var flag = item.GetWidget<ImageWidget>("FACTIONFLAG");
|
||||||
|
flag.GetImageName = () => pp.Country.Race;
|
||||||
|
flag.GetImageCollection = () => "flags";
|
||||||
|
item.GetWidget<LabelWidget>("FACTION").GetText = () => pp.Country.Name;
|
||||||
|
|
||||||
|
var stance = item.GetWidget<DropDownButtonWidget>("STANCE");
|
||||||
|
stance.GetText = () => world.LocalPlayer.Stances[ pp ].ToString();
|
||||||
|
stance.OnMouseDown = _ => ShowStanceDropDown(stance, pp);
|
||||||
|
stance.IsDisabled = () => pp.IsBot || world.LobbyInfo.GlobalSettings.LockTeams;
|
||||||
|
scrollpanel.AddChild(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShowStanceDropDown(DropDownButtonWidget dropdown, Player pp)
|
||||||
|
{
|
||||||
|
if (dropdown.IsDisabled())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var substitutions = new Dictionary<string,int>() {{ "DROPDOWN_WIDTH", dropdown.Bounds.Width }};
|
||||||
|
var panel = (ScrollPanelWidget)Widget.LoadWidget("LABEL_DROPDOWN_TEMPLATE", null, new WidgetArgs()
|
||||||
|
{
|
||||||
|
{ "substitutions", substitutions }
|
||||||
|
});
|
||||||
|
|
||||||
|
var itemTemplate = panel.GetWidget<ScrollItemWidget>("TEMPLATE");
|
||||||
|
|
||||||
|
foreach (var option in Enum.GetValues(typeof(Stance)).OfType<Stance>())
|
||||||
|
{
|
||||||
|
var o = option;
|
||||||
|
var item = ScrollItemWidget.Setup(itemTemplate, () => o == world.LocalPlayer.Stances[ pp ],
|
||||||
|
() => {
|
||||||
|
world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor,
|
||||||
|
false) { TargetLocation = new int2(pp.Index, (int)o) });
|
||||||
|
dropdown.RemovePanel();
|
||||||
|
});
|
||||||
|
item.GetWidget<LabelWidget>("LABEL").GetText = () => o.ToString();
|
||||||
|
panel.AddChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
panel.Bounds.Height = Math.Min(150, panel.ContentHeight);
|
||||||
|
dropdown.AttachPanel(panel);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ using System.Drawing;
|
|||||||
using OpenRA.Mods.RA;
|
using OpenRA.Mods.RA;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
@@ -57,7 +58,11 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
if (world.LocalPlayer != null)
|
if (world.LocalPlayer != null)
|
||||||
widget.GetWidget("PLAYER_WIDGETS").IsVisible = () => true;
|
widget.GetWidget("PLAYER_WIDGETS").IsVisible = () => true;
|
||||||
|
|
||||||
ingameRoot.GetWidget<ButtonWidget>("DIPLOMACY_BUTTON").IsDisabled = () => true;
|
var diplomacyButton = ingameRoot.GetWidget<ButtonWidget>("DIPLOMACY_BUTTON");
|
||||||
|
var diplomacyAvailable = world.players.Values.Any(a => a != world.LocalPlayer && !a.NonCombatant);
|
||||||
|
diplomacyButton.IsDisabled = () => !diplomacyAvailable;
|
||||||
|
diplomacyButton.OnClick = () => Game.OpenWindow("DIPLOMACY_PANEL", new WidgetArgs());
|
||||||
|
|
||||||
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
||||||
{
|
{
|
||||||
ingameRoot.IsVisible = () => false;
|
ingameRoot.IsVisible = () => false;
|
||||||
|
|||||||
88
mods/cnc/chrome/diplomacy.yaml
Normal file
88
mods/cnc/chrome/diplomacy.yaml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
Container@DIPLOMACY_PANEL:
|
||||||
|
Id:DIPLOMACY_PANEL
|
||||||
|
Delegate:CncDiplomacyLogic
|
||||||
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
|
Y:(WINDOW_BOTTOM - 400)/2
|
||||||
|
Width:450
|
||||||
|
Height:335
|
||||||
|
Children:
|
||||||
|
Label@TITLE:
|
||||||
|
Width:PARENT_RIGHT
|
||||||
|
Y:0-25
|
||||||
|
Font:BigBold
|
||||||
|
Contrast:true
|
||||||
|
Align:Center
|
||||||
|
Text:Diplomacy
|
||||||
|
Background@bg:
|
||||||
|
Width:450
|
||||||
|
Height:300
|
||||||
|
Background:panel-black
|
||||||
|
Children:
|
||||||
|
ScrollPanel@PLAYER_LIST:
|
||||||
|
Id:PLAYER_LIST
|
||||||
|
X:15
|
||||||
|
Y:30
|
||||||
|
Width:420
|
||||||
|
Height:255
|
||||||
|
ItemSpacing:5
|
||||||
|
Children:
|
||||||
|
Container@PLAYER_TEMPLATE:
|
||||||
|
Id:PLAYER_TEMPLATE
|
||||||
|
Width:PARENT_RIGHT-27
|
||||||
|
Height:25
|
||||||
|
X:2
|
||||||
|
Y:0
|
||||||
|
Children:
|
||||||
|
Label@NAME:
|
||||||
|
Id:NAME
|
||||||
|
X:10
|
||||||
|
Width:150
|
||||||
|
Height:25
|
||||||
|
Image@FACTIONFLAG:
|
||||||
|
Id:FACTIONFLAG
|
||||||
|
X:PARENT_RIGHT-210
|
||||||
|
Y:5
|
||||||
|
Width:30
|
||||||
|
Height:15
|
||||||
|
Label@FACTION:
|
||||||
|
Id:FACTION
|
||||||
|
X:PARENT_RIGHT-170
|
||||||
|
Width:40
|
||||||
|
Height:25
|
||||||
|
DropDownButton@STANCE:
|
||||||
|
Id:STANCE
|
||||||
|
X:PARENT_RIGHT-110
|
||||||
|
Width:100
|
||||||
|
Height:25
|
||||||
|
Container@LABEL_CONTAINER:
|
||||||
|
X:17
|
||||||
|
Y:5
|
||||||
|
Width:393
|
||||||
|
Children:
|
||||||
|
Label@NAME:
|
||||||
|
X:10
|
||||||
|
Width:150
|
||||||
|
Height:25
|
||||||
|
Text:Player
|
||||||
|
Align:Center
|
||||||
|
Font:Bold
|
||||||
|
Label@RACE:
|
||||||
|
X:PARENT_RIGHT-220
|
||||||
|
Width:100
|
||||||
|
Height:25
|
||||||
|
Text:Faction
|
||||||
|
Font:Bold
|
||||||
|
Align:Center
|
||||||
|
Label@STANCE:
|
||||||
|
X:PARENT_RIGHT-110
|
||||||
|
Width:100
|
||||||
|
Height:25
|
||||||
|
Text:Stance
|
||||||
|
Font:Bold
|
||||||
|
Align:Center
|
||||||
|
Button@BACK_BUTTON:
|
||||||
|
Id:BACK_BUTTON
|
||||||
|
Y:299
|
||||||
|
Width:140
|
||||||
|
Height:35
|
||||||
|
Text:Back
|
||||||
@@ -78,6 +78,7 @@ ChromeLayout:
|
|||||||
mods/cnc/chrome/modchooser.yaml
|
mods/cnc/chrome/modchooser.yaml
|
||||||
mods/cnc/chrome/preferences.yaml
|
mods/cnc/chrome/preferences.yaml
|
||||||
mods/cnc/chrome/cheats.yaml
|
mods/cnc/chrome/cheats.yaml
|
||||||
|
mods/cnc/chrome/diplomacy.yaml
|
||||||
mods/cnc/chrome/dropdowns.yaml
|
mods/cnc/chrome/dropdowns.yaml
|
||||||
|
|
||||||
Weapons:
|
Weapons:
|
||||||
|
|||||||
Reference in New Issue
Block a user