Basic listbox for map list
This commit is contained in:
@@ -227,6 +227,7 @@
|
|||||||
<Compile Include="Widgets\TextFieldWidget.cs" />
|
<Compile Include="Widgets\TextFieldWidget.cs" />
|
||||||
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
||||||
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
|
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
|
||||||
|
<Compile Include="Widgets\ListBoxWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
};
|
};
|
||||||
|
|
||||||
var itemTemplate = ml.GetWidget<ButtonWidget>("MAP_TEMPLATE");
|
var itemTemplate = ml.GetWidget<ButtonWidget>("MAP_TEMPLATE");
|
||||||
int offset = 0;
|
int offset = itemTemplate.Bounds.Y;
|
||||||
foreach (var kv in Game.AvailableMaps)
|
foreach (var kv in Game.AvailableMaps)
|
||||||
{
|
{
|
||||||
var map = kv.Value;
|
var map = kv.Value;
|
||||||
@@ -67,11 +67,11 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
template.OnMouseUp = mi => {Map = map; return true;};
|
template.OnMouseUp = mi => {Map = map; return true;};
|
||||||
template.Parent = ml;
|
template.Parent = ml;
|
||||||
|
|
||||||
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||||
template.IsVisible = () => true;
|
template.IsVisible = () => true;
|
||||||
ml.AddChild(template);
|
ml.AddChild(template);
|
||||||
|
|
||||||
offset += template.Bounds.Height + 5;
|
offset += template.Bounds.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
129
OpenRA.Game/Widgets/ListBoxWidget.cs
Normal file
129
OpenRA.Game/Widgets/ListBoxWidget.cs
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets
|
||||||
|
{
|
||||||
|
class ListBoxWidget : Widget
|
||||||
|
{
|
||||||
|
public readonly string Background = "dialog";
|
||||||
|
public readonly int ScrollbarWidth = 24;
|
||||||
|
public readonly float ScrollVelocity = 4f;
|
||||||
|
public readonly int HeaderHeight = 25;
|
||||||
|
|
||||||
|
float ListOffset = 0;
|
||||||
|
bool UpPressed = false;
|
||||||
|
bool DownPressed = false;
|
||||||
|
Rectangle upButtonRect;
|
||||||
|
Rectangle downButtonRect;
|
||||||
|
Rectangle backgroundRect;
|
||||||
|
Rectangle scrollbarRect;
|
||||||
|
|
||||||
|
public ListBoxWidget() : base() {}
|
||||||
|
public ListBoxWidget(Widget other)
|
||||||
|
: base(other)
|
||||||
|
{
|
||||||
|
Background = (other as ListBoxWidget).Background;
|
||||||
|
upButtonRect = (other as ListBoxWidget).upButtonRect;
|
||||||
|
downButtonRect = (other as ListBoxWidget).downButtonRect;
|
||||||
|
scrollbarRect = (other as ListBoxWidget).scrollbarRect;
|
||||||
|
backgroundRect = (other as ListBoxWidget).backgroundRect;
|
||||||
|
|
||||||
|
UpPressed = (other as ListBoxWidget).UpPressed;
|
||||||
|
DownPressed = (other as ListBoxWidget).DownPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawInner(World world) {}
|
||||||
|
public override void Draw(World world)
|
||||||
|
{
|
||||||
|
if (!IsVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
|
||||||
|
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
|
||||||
|
downButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
|
||||||
|
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, RenderBounds.Height - 2*ScrollbarWidth);
|
||||||
|
|
||||||
|
string upButtonBg = (UpPressed) ? "dialog3" : "dialog2";
|
||||||
|
string downButtonBg = (DownPressed) ? "dialog3" : "dialog2";
|
||||||
|
string scrolbarBg = "dialog3";
|
||||||
|
string scrollbarButton = "dialog2";
|
||||||
|
|
||||||
|
WidgetUtils.DrawPanel(Background, backgroundRect);
|
||||||
|
WidgetUtils.DrawPanel(upButtonBg, upButtonRect);
|
||||||
|
WidgetUtils.DrawPanel(downButtonBg, downButtonRect);
|
||||||
|
WidgetUtils.DrawPanel(scrolbarBg, scrollbarRect);
|
||||||
|
|
||||||
|
|
||||||
|
Game.chrome.renderer.Device.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
|
||||||
|
|
||||||
|
foreach (var child in Children)
|
||||||
|
child.Draw(world);
|
||||||
|
|
||||||
|
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
Game.chrome.renderer.Device.DisableScissor();
|
||||||
|
}
|
||||||
|
public override int2 ChildOrigin { get { return RenderOrigin + new int2(0, (int)ListOffset); } }
|
||||||
|
|
||||||
|
public override void Tick (World world)
|
||||||
|
{
|
||||||
|
if (UpPressed && ListOffset <= 0) ListOffset += ScrollVelocity;
|
||||||
|
if (DownPressed) ListOffset -= ScrollVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandleInput(MouseInput mi)
|
||||||
|
{
|
||||||
|
if (Chrome.selectedWidget == this)
|
||||||
|
{
|
||||||
|
UpPressed = upButtonRect.Contains(mi.Location.X,mi.Location.Y);
|
||||||
|
DownPressed = downButtonRect.Contains(mi.Location.X,mi.Location.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relinquish focus
|
||||||
|
if (Chrome.selectedWidget == this && mi.Event == MouseInputEvent.Up)
|
||||||
|
{
|
||||||
|
Chrome.selectedWidget = null;
|
||||||
|
UpPressed = DownPressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are we able to handle this event?
|
||||||
|
if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||||
|
return base.HandleInput(mi);
|
||||||
|
|
||||||
|
|
||||||
|
if (base.HandleInput(mi))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Give button focus only while the mouse is down
|
||||||
|
// This is a bit of a hack: it will become cleaner soonish
|
||||||
|
// It will also steal events from any potential children
|
||||||
|
// We also want to play a click sound
|
||||||
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
|
{
|
||||||
|
Chrome.selectedWidget = this;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Widget Clone() { return new ListBoxWidget(this); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,7 +182,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public abstract void DrawInner( World world );
|
public abstract void DrawInner( World world );
|
||||||
|
|
||||||
public void Draw(World world)
|
public virtual void Draw(World world)
|
||||||
{
|
{
|
||||||
if (IsVisible())
|
if (IsVisible())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -769,19 +769,19 @@ Container:
|
|||||||
Height:20
|
Height:20
|
||||||
Text:Choose Map
|
Text:Choose Map
|
||||||
Bold:True
|
Bold:True
|
||||||
Container@MAP_LIST:
|
ListBox@MAP_LIST:
|
||||||
Id:MAP_LIST
|
Id:MAP_LIST
|
||||||
X:50
|
X:20
|
||||||
Y:50
|
Y:50
|
||||||
Width:450
|
Width:500
|
||||||
Height:500
|
Height:480
|
||||||
Children:
|
Children:
|
||||||
Button@MAP_TEMPLATE:
|
Button@MAP_TEMPLATE:
|
||||||
Id:MAP_TEMPLATE
|
Id:MAP_TEMPLATE
|
||||||
Width:440
|
Width:PARENT_RIGHT-28
|
||||||
Height:25
|
Height:25
|
||||||
X:0
|
X:2
|
||||||
Y:0
|
Y:25
|
||||||
Visible:false
|
Visible:false
|
||||||
Label@CURMAP_TITLE_LABEL:
|
Label@CURMAP_TITLE_LABEL:
|
||||||
Id:CURMAP_TITLE_LABEL
|
Id:CURMAP_TITLE_LABEL
|
||||||
@@ -849,7 +849,7 @@ Container:
|
|||||||
Height:20
|
Height:20
|
||||||
Background@MAPCHOOSER_MAP_BG:
|
Background@MAPCHOOSER_MAP_BG:
|
||||||
X:PARENT_RIGHT-268
|
X:PARENT_RIGHT-268
|
||||||
Y:39
|
Y:50
|
||||||
Width:252
|
Width:252
|
||||||
Height:252
|
Height:252
|
||||||
Background:dialog3
|
Background:dialog3
|
||||||
|
|||||||
@@ -769,19 +769,19 @@ Container:
|
|||||||
Height:20
|
Height:20
|
||||||
Text:Choose Map
|
Text:Choose Map
|
||||||
Bold:True
|
Bold:True
|
||||||
Container@MAP_LIST:
|
ListBox@MAP_LIST:
|
||||||
Id:MAP_LIST
|
Id:MAP_LIST
|
||||||
X:50
|
X:20
|
||||||
Y:50
|
Y:50
|
||||||
Width:450
|
Width:500
|
||||||
Height:500
|
Height:480
|
||||||
Children:
|
Children:
|
||||||
Button@MAP_TEMPLATE:
|
Button@MAP_TEMPLATE:
|
||||||
Id:MAP_TEMPLATE
|
Id:MAP_TEMPLATE
|
||||||
Width:440
|
Width:PARENT_RIGHT-28
|
||||||
Height:25
|
Height:25
|
||||||
X:0
|
X:2
|
||||||
Y:0
|
Y:25
|
||||||
Visible:false
|
Visible:false
|
||||||
Label@CURMAP_TITLE_LABEL:
|
Label@CURMAP_TITLE_LABEL:
|
||||||
Id:CURMAP_TITLE_LABEL
|
Id:CURMAP_TITLE_LABEL
|
||||||
@@ -849,7 +849,7 @@ Container:
|
|||||||
Height:20
|
Height:20
|
||||||
Background@MAPCHOOSER_MAP_BG:
|
Background@MAPCHOOSER_MAP_BG:
|
||||||
X:PARENT_RIGHT-268
|
X:PARENT_RIGHT-268
|
||||||
Y:39
|
Y:50
|
||||||
Width:252
|
Width:252
|
||||||
Height:252
|
Height:252
|
||||||
Background:dialog3
|
Background:dialog3
|
||||||
@@ -1104,6 +1104,4 @@ Container:
|
|||||||
Width:25
|
Width:25
|
||||||
Height:25
|
Height:25
|
||||||
ImageCollection:music
|
ImageCollection:music
|
||||||
ImageName:prev
|
ImageName:prev
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user