Refactoring to remove static Rules & SequenceProvider
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -11,6 +11,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -53,8 +55,13 @@ namespace OpenRA.Widgets
|
||||
public Action OnDoubleClick = () => {};
|
||||
public Action<KeyInput> OnKeyPress = _ => {};
|
||||
|
||||
public ButtonWidget()
|
||||
readonly MapRuleset rules;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ButtonWidget(MapRuleset rules)
|
||||
{
|
||||
this.rules = rules;
|
||||
|
||||
GetText = () => { return Text; };
|
||||
GetColor = () => TextColor;
|
||||
GetColorDisabled = () => TextColorDisabled;
|
||||
@@ -70,6 +77,8 @@ namespace OpenRA.Widgets
|
||||
protected ButtonWidget(ButtonWidget other)
|
||||
: base(other)
|
||||
{
|
||||
this.rules = other.rules;
|
||||
|
||||
Text = other.Text;
|
||||
Font = other.Font;
|
||||
TextColor = other.TextColor;
|
||||
@@ -113,10 +122,10 @@ namespace OpenRA.Widgets
|
||||
if (!IsDisabled())
|
||||
{
|
||||
OnKeyPress(e);
|
||||
Sound.PlayNotification(null, "Sounds", "ClickSound", null);
|
||||
Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null);
|
||||
}
|
||||
else
|
||||
Sound.PlayNotification(null, "Sounds", "ClickDisabledSound", null);
|
||||
Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -153,12 +162,12 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
OnMouseDown(mi);
|
||||
Depressed = true;
|
||||
Sound.PlayNotification(null, "Sounds", "ClickSound", null);
|
||||
Sound.PlayNotification(rules, null, "Sounds", "ClickSound", null);
|
||||
}
|
||||
else
|
||||
{
|
||||
YieldMouseFocus(mi);
|
||||
Sound.PlayNotification(null, "Sounds", "ClickDisabledSound", null);
|
||||
Sound.PlayNotification(rules, null, "Sounds", "ClickDisabledSound", null);
|
||||
}
|
||||
}
|
||||
else if (mi.Event == MouseInputEvent.Move && HasMouseFocus)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -23,7 +24,9 @@ namespace OpenRA.Widgets
|
||||
public int CheckOffset = 2;
|
||||
public bool HasPressedState = ChromeMetrics.Get<bool>("CheckboxPressedState");
|
||||
|
||||
public CheckboxWidget()
|
||||
[ObjectCreator.UseCtor]
|
||||
public CheckboxWidget(MapRuleset rules)
|
||||
: base(rules)
|
||||
{
|
||||
GetCheckType = () => CheckType;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -20,7 +21,9 @@ namespace OpenRA.Widgets
|
||||
Widget panel;
|
||||
MaskWidget fullscreenMask;
|
||||
|
||||
public DropDownButtonWidget() { }
|
||||
[ObjectCreator.UseCtor]
|
||||
public DropDownButtonWidget(MapRuleset rules)
|
||||
: base(rules) { }
|
||||
|
||||
protected DropDownButtonWidget(DropDownButtonWidget widget) : base(widget) { }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -9,6 +9,8 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -17,7 +19,9 @@ namespace OpenRA.Widgets
|
||||
public string ItemKey;
|
||||
public string BaseName = "scrollitem";
|
||||
|
||||
public ScrollItemWidget()
|
||||
[ObjectCreator.UseCtor]
|
||||
public ScrollItemWidget(MapRuleset rules)
|
||||
: base(rules)
|
||||
{
|
||||
IsVisible = () => false;
|
||||
VisualHeight = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -18,10 +18,13 @@ namespace OpenRA
|
||||
{
|
||||
public class WidgetLoader
|
||||
{
|
||||
Dictionary<string, MiniYamlNode> widgets = new Dictionary<string, MiniYamlNode>();
|
||||
readonly Dictionary<string, MiniYamlNode> widgets = new Dictionary<string, MiniYamlNode>();
|
||||
readonly ModData modData;
|
||||
|
||||
public WidgetLoader(ModData modData)
|
||||
{
|
||||
this.modData = modData;
|
||||
|
||||
foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromFile(a)))
|
||||
foreach( var w in file )
|
||||
{
|
||||
@@ -55,6 +58,8 @@ namespace OpenRA
|
||||
if (child.Key != "Children")
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
|
||||
if (!args.ContainsKey("rules"))
|
||||
args = new WidgetArgs(args) { { "rules", modData.DefaultRules } };
|
||||
widget.Initialize(args);
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
|
||||
Reference in New Issue
Block a user