diplomacy menu & stance changes
This commit is contained in:
@@ -289,7 +289,6 @@ namespace OpenRA
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var f = renderer.BoldFont;
|
var f = renderer.BoldFont;
|
||||||
f.DrawText("Name", new int2(r.Left + 40, r.Top + 50), Color.White);
|
f.DrawText("Name", new int2(r.Left + 40, r.Top + 50), Color.White);
|
||||||
f.DrawText("Color", new int2(r.Left + 140, r.Top + 50), Color.White);
|
f.DrawText("Color", new int2(r.Left + 140, r.Top + 50), Color.White);
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ namespace OpenRA.Network
|
|||||||
Game.SyncLobbyInfo(order.TargetString);
|
Game.SyncLobbyInfo(order.TargetString);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "SetStance":
|
||||||
|
{
|
||||||
|
var targetPlayer = order.Player.World.players[order.TargetLocation.X];
|
||||||
|
order.Player.Stances[targetPlayer] = (Stance)order.TargetLocation.Y;
|
||||||
|
Game.Debug("{0} has set diplomatic stance vs {1} to {2}".F(
|
||||||
|
order.Player.PlayerName, targetPlayer.PlayerName, (Stance)order.TargetLocation.Y));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if( !order.IsImmediate )
|
if( !order.IsImmediate )
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
<Compile Include="Traits\World\Shroud.cs" />
|
<Compile Include="Traits\World\Shroud.cs" />
|
||||||
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
|
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
||||||
|
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
|
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
|
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
|
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace OpenRA.Traits
|
|||||||
public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
|
public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
|
||||||
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
|
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
|
||||||
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
||||||
|
public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); }
|
||||||
|
|
||||||
public interface ICustomTerrain
|
public interface ICustomTerrain
|
||||||
{
|
{
|
||||||
|
|||||||
127
OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs
Normal file
127
OpenRA.Game/Widgets/Delegates/DiplomacyDelegate.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets.Delegates
|
||||||
|
{
|
||||||
|
public class DiplomacyDelegate : IWidgetDelegate
|
||||||
|
{
|
||||||
|
static List<Widget> controls = new List<Widget>();
|
||||||
|
|
||||||
|
public DiplomacyDelegate()
|
||||||
|
{
|
||||||
|
var diplomacyBG = Chrome.rootWidget.GetWidget("DIPLOMACY_BG");
|
||||||
|
|
||||||
|
Chrome.rootWidget.GetWidget("INGAME_DIPLOMACY_BUTTON").OnMouseUp = mi =>
|
||||||
|
{
|
||||||
|
diplomacyBG.Visible = !diplomacyBG.Visible;
|
||||||
|
if (diplomacyBG.Visible)
|
||||||
|
LayoutDialog(diplomacyBG);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void LayoutDialog(Widget bg)
|
||||||
|
{
|
||||||
|
bg.Children.RemoveAll(w => controls.Contains(w));
|
||||||
|
controls.Clear();
|
||||||
|
|
||||||
|
var unwantedPlayers = new[] { Game.world.NeutralPlayer, Game.world.LocalPlayer };
|
||||||
|
var y = 50;
|
||||||
|
var margin = 20;
|
||||||
|
var labelWidth = (bg.Bounds.Width - 3 * margin) / 3;
|
||||||
|
|
||||||
|
var ts = new LabelWidget
|
||||||
|
{
|
||||||
|
Bold = true,
|
||||||
|
Bounds = new Rectangle(bg.Bounds.X + margin + labelWidth + 10, bg.Bounds.Y + y, labelWidth, 25),
|
||||||
|
Text = "Their Stance",
|
||||||
|
Align = "Left",
|
||||||
|
};
|
||||||
|
|
||||||
|
bg.AddChild(ts);
|
||||||
|
controls.Add(ts);
|
||||||
|
|
||||||
|
var ms = new LabelWidget
|
||||||
|
{
|
||||||
|
Bold = true,
|
||||||
|
Bounds = new Rectangle(bg.Bounds.X + margin + 2 * labelWidth + 20, bg.Bounds.Y + y, labelWidth, 25),
|
||||||
|
Text = "My Stance",
|
||||||
|
Align = "Left",
|
||||||
|
};
|
||||||
|
|
||||||
|
bg.AddChild(ms);
|
||||||
|
controls.Add(ms);
|
||||||
|
|
||||||
|
y += 35;
|
||||||
|
|
||||||
|
foreach (var p in Game.world.players.Values.Except(unwantedPlayers))
|
||||||
|
{
|
||||||
|
var pp = p;
|
||||||
|
var label = new LabelWidget
|
||||||
|
{
|
||||||
|
Bounds = new Rectangle(bg.Bounds.X + margin, bg.Bounds.Y + y, labelWidth, 25),
|
||||||
|
Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index),
|
||||||
|
Text = p.PlayerName,
|
||||||
|
Align = "Left",
|
||||||
|
Bold = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
bg.AddChild(label);
|
||||||
|
controls.Add(label);
|
||||||
|
|
||||||
|
var theirStance = new LabelWidget
|
||||||
|
{
|
||||||
|
Bounds = new Rectangle(bg.Bounds.X + margin + labelWidth + 10, bg.Bounds.Y + y, labelWidth, 25),
|
||||||
|
Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index),
|
||||||
|
Text = p.PlayerName,
|
||||||
|
Align = "Left",
|
||||||
|
Bold = false,
|
||||||
|
|
||||||
|
GetText = () => pp.Stances[ Game.world.LocalPlayer ].ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
bg.AddChild(theirStance);
|
||||||
|
controls.Add(theirStance);
|
||||||
|
|
||||||
|
var myStance = new ButtonWidget
|
||||||
|
{
|
||||||
|
Bounds = new Rectangle(bg.Bounds.X + margin + 2 * labelWidth + 20, bg.Bounds.Y + y, labelWidth, 25),
|
||||||
|
Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index),
|
||||||
|
Text = Game.world.LocalPlayer.Stances[ pp ].ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
myStance.OnMouseUp = mi => { CycleStance(pp, myStance); return true; };
|
||||||
|
|
||||||
|
bg.AddChild(myStance);
|
||||||
|
controls.Add(myStance);
|
||||||
|
|
||||||
|
y += 35;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Stance GetNextStance(Stance s)
|
||||||
|
{
|
||||||
|
switch (s)
|
||||||
|
{
|
||||||
|
case Stance.Ally: return Stance.Enemy;
|
||||||
|
case Stance.Enemy: return Stance.Neutral;
|
||||||
|
case Stance.Neutral: return Stance.Ally;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CycleStance(Player p, ButtonWidget bw)
|
||||||
|
{
|
||||||
|
var nextStance = GetNextStance(Game.world.LocalPlayer.Stances[p]);
|
||||||
|
Game.IssueOrder(new Order("SetStance", Game.world.LocalPlayer.PlayerActor,
|
||||||
|
new int2(p.Index, (int)nextStance)));
|
||||||
|
|
||||||
|
bw.Text = nextStance.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var r = Chrome.rootWidget;
|
var r = Chrome.rootWidget;
|
||||||
var gameRoot = r.GetWidget("INGAME_ROOT");
|
var gameRoot = r.GetWidget("INGAME_ROOT");
|
||||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||||
|
|
||||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||||
optionsBG.Visible = !optionsBG.Visible;
|
optionsBG.Visible = !optionsBG.Visible;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -30,10 +30,15 @@ namespace OpenRA.Widgets
|
|||||||
public bool Bold = true;
|
public bool Bold = true;
|
||||||
public Func<string> GetText;
|
public Func<string> GetText;
|
||||||
|
|
||||||
|
public LabelWidget()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
GetText = () => { return Text; };
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
GetText = () => {return Text;};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(World world)
|
public override void Draw(World world)
|
||||||
|
|||||||
@@ -386,6 +386,23 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Quit
|
Text:Quit
|
||||||
|
Background@DIPLOMACY_BG:
|
||||||
|
Id:DIPLOMACY_BG
|
||||||
|
Delegate:DiplomacyDelegate
|
||||||
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
|
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||||
|
Width:450
|
||||||
|
Height:400
|
||||||
|
Visible:false
|
||||||
|
Children:
|
||||||
|
Label@LABEL_TITLE:
|
||||||
|
Id:LABEL_TITLE
|
||||||
|
X:(PARENT_RIGHT - WIDTH)/2
|
||||||
|
Y:20
|
||||||
|
Width:250
|
||||||
|
Height:25
|
||||||
|
Text:Diplomacy
|
||||||
|
Align:Center
|
||||||
Background@PERF_BG:
|
Background@PERF_BG:
|
||||||
ClickThrough:true
|
ClickThrough:true
|
||||||
Id:PERF_BG
|
Id:PERF_BG
|
||||||
|
|||||||
Reference in New Issue
Block a user