diplomacy menu & stance changes

This commit is contained in:
Chris Forbes
2010-04-20 20:13:03 +12:00
parent 71f79d322d
commit 60f5e4d13e
9 changed files with 165 additions and 6 deletions

View File

@@ -289,7 +289,6 @@ namespace OpenRA
});
}
var f = renderer.BoldFont;
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);

View File

@@ -130,9 +130,9 @@ namespace OpenRA.Graphics
}
Game.chrome.DrawWidgets(world);
if( Chrome.rootWidget.GetWidget( "SERVER_LOBBY" ).Visible )
if (Chrome.rootWidget.GetWidget("SERVER_LOBBY").Visible)
Game.chrome.DrawLobby();
else if( Chrome.rootWidget.GetWidget( "MAP_CHOOSER" ).Visible )
else if (Chrome.rootWidget.GetWidget("MAP_CHOOSER").Visible)
Game.chrome.DrawMapChooser();
Timer.Time( "widgets: {0}" );

View File

@@ -48,6 +48,14 @@ namespace OpenRA.Network
Game.SyncLobbyInfo(order.TargetString);
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:
{
if( !order.IsImmediate )

View File

@@ -89,6 +89,7 @@
<Compile Include="Traits\World\Shroud.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />

View File

@@ -44,6 +44,7 @@ namespace OpenRA.Traits
public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
public interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); }
public interface ICustomTerrain
{

View 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();
}
}
}

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Widgets.Delegates
var r = Chrome.rootWidget;
var gameRoot = r.GetWidget("INGAME_ROOT");
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
optionsBG.Visible = !optionsBG.Visible;
return true;

View File

@@ -30,10 +30,15 @@ namespace OpenRA.Widgets
public bool Bold = true;
public Func<string> GetText;
public LabelWidget()
: base()
{
GetText = () => { return Text; };
}
public override void Initialize()
{
base.Initialize();
GetText = () => {return Text;};
}
public override void Draw(World world)

View File

@@ -386,6 +386,23 @@ Container:
Width:160
Height:25
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:
ClickThrough:true
Id:PERF_BG