-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Überarbeitung von Entities, Komponenten und Extensions #245
Changes from all commits
7d7b05e
3ae73a3
5b902a0
c680bd6
fe47832
63f6ee8
e49eeba
e415df5
901527d
d67aa39
2f602b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using engenious; | ||
using engenious.Graphics; | ||
using MonoGameUi; | ||
using OctoAwesome.Basics.EntityComponents; | ||
using OctoAwesome.Entities; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OctoAwesome.Basics.Controls | ||
{ | ||
internal sealed class InventoryControl : Panel | ||
{ | ||
private const int COLUMNS = 8; | ||
|
||
/// <summary> | ||
/// Gibt den aktuell selektierten Slot an. | ||
/// </summary> | ||
public InventorySlot HoveredSlot { get; private set; } | ||
|
||
private InventoryComponent inventory; | ||
private Label volumeLabel; | ||
private Label massLabel; | ||
private Label nameLabel; | ||
|
||
public InventoryControl(BaseScreenComponent manager, IUserInterfaceExtensionManager interfacemanager, | ||
InventoryComponent inventory) : base(manager) | ||
{ | ||
this.inventory = inventory; | ||
|
||
Texture2D panelBackground = interfacemanager.LoadTextures(manager.GetType(), "panel"); | ||
Margin = new Border(0, 0, 0, 0); | ||
HorizontalAlignment = HorizontalAlignment.Stretch; | ||
VerticalAlignment = VerticalAlignment.Stretch; | ||
|
||
Grid parentgrid = new Grid(manager); | ||
parentgrid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1, }); | ||
parentgrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1, }); | ||
parentgrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 100, }); | ||
Controls.Add(parentgrid); | ||
|
||
Panel panel = new Panel(manager) | ||
{ | ||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||
VerticalAlignment = VerticalAlignment.Stretch, | ||
Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30) | ||
}; | ||
parentgrid.AddControl(panel, 0, 0); | ||
|
||
ScrollContainer scroll = new ScrollContainer(manager) | ||
{ | ||
Margin = Border.All(0, 5, 5, 5), | ||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||
VerticalAlignment = VerticalAlignment.Stretch, | ||
}; | ||
panel.Controls.Add(scroll); | ||
|
||
StackPanel infoPanel = new StackPanel(manager) | ||
{ | ||
Margin = new Border(0, 10, 0, 0), | ||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||
VerticalAlignment = VerticalAlignment.Stretch, | ||
Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30), | ||
}; | ||
|
||
nameLabel = new Label(manager); | ||
infoPanel.Controls.Add(nameLabel); | ||
massLabel = new Label(manager); | ||
infoPanel.Controls.Add(massLabel); | ||
volumeLabel = new Label(manager); | ||
infoPanel.Controls.Add(volumeLabel); | ||
parentgrid.AddControl(infoPanel, 0, 1); | ||
|
||
Grid grid = new Grid(manager) | ||
{ | ||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||
}; | ||
for (int i = 0; i < COLUMNS; i++) | ||
grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 }); | ||
|
||
int rows = (int) System.Math.Ceiling((float) inventory.Inventory.Count / COLUMNS); | ||
for (int i = 0; i < rows; i++) | ||
grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 }); | ||
|
||
int column = 0; | ||
int row = 0; | ||
foreach (var item in inventory.Inventory) | ||
{ | ||
Texture2D texture = interfacemanager.LoadTextures(item.Definition.GetType(), item.Definition.Icon); | ||
|
||
var image = new Image(manager) { Texture = texture, Width = 42, Height = 42, VerticalAlignment = VerticalAlignment.Center }; | ||
image.MouseEnter += (s, e) => { HoveredSlot = item; }; | ||
image.MouseLeave += (s, e) => { HoveredSlot = null; }; | ||
image.StartDrag += (e) => | ||
{ | ||
e.Handled = true; | ||
e.Icon = texture; | ||
e.Content = item; | ||
e.Sender = image; | ||
}; | ||
var label = new Label(manager) { Text = item.Amount.ToString(), HorizontalAlignment = HorizontalAlignment.Right, VerticalTextAlignment = VerticalAlignment.Bottom, Background = new BorderBrush(Color.White) }; | ||
grid.AddControl(image, column, row); | ||
grid.AddControl(label, column, row); | ||
|
||
column++; | ||
if (column >= COLUMNS) | ||
{ | ||
row++; | ||
column = 0; | ||
} | ||
} | ||
scroll.Content = grid; | ||
} | ||
protected override void OnUpdate(GameTime gameTime) | ||
{ | ||
nameLabel.Text = HoveredSlot?.Definition.Name ?? ""; | ||
massLabel.Text = volumeLabel.Text = HoveredSlot?.Amount.ToString() ?? ""; | ||
} | ||
public override string ToString() | ||
{ | ||
// TODO: resx -> Languages.OctoBasics.Inventory or what ever... | ||
return "Inventar"; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
using MonoGameUi; | ||
using System.Collections.Generic; | ||
using engenious; | ||
using engenious.Graphics; | ||
using OctoAwesome.Entities; | ||
using System; | ||
using OctoAwesome.Basics.EntityComponents; | ||
|
||
namespace OctoAwesome.Basics.Controls | ||
{ | ||
internal class ToolbarControl : Panel | ||
{ | ||
private Button[] buttons; | ||
|
||
private Image[] images; | ||
|
||
private Brush buttonBackgroud; | ||
|
||
private Brush activeBackground; | ||
|
||
private ToolBarComponent toolbar; | ||
|
||
private Label activeToolLabel; | ||
|
||
private Dictionary<string, Texture2D> toolTextures; | ||
|
||
public ToolbarControl(BaseScreenComponent screenManager, IUserInterfaceExtensionManager manager, ToolBarComponent bar) : | ||
base(screenManager) | ||
{ | ||
HorizontalAlignment = HorizontalAlignment.Stretch; | ||
VerticalAlignment = VerticalAlignment.Bottom; | ||
Height = 100; | ||
toolbar = bar; | ||
buttonBackgroud = new BorderBrush(Color.Black); | ||
activeBackground = new BorderBrush(Color.Red); | ||
buttons = new Button[toolbar.Tools.Length]; | ||
images = new Image[toolbar.Tools.Length]; | ||
|
||
toolTextures = new Dictionary<string, Texture2D>(); | ||
|
||
foreach (var item in bar.Service.DefinitionManager.GetDefinitions()) | ||
{ | ||
Texture2D texture = manager.LoadTextures(item.GetType(), item.Icon); | ||
toolTextures.Add(item.GetType().FullName, texture); | ||
} | ||
|
||
Grid grid = new Grid(screenManager) | ||
{ | ||
Margin = new Border(0, 0, 0, 0), | ||
HorizontalAlignment = HorizontalAlignment.Center, | ||
VerticalAlignment = VerticalAlignment.Bottom | ||
}; | ||
Controls.Add(grid); | ||
|
||
grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 }); | ||
grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 }); | ||
|
||
for (int i = 0; i < toolbar.Tools.Length; i++) | ||
{ | ||
grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 }); | ||
} | ||
|
||
activeToolLabel = new Label(screenManager); | ||
activeToolLabel.VerticalAlignment = VerticalAlignment.Top; | ||
activeToolLabel.HorizontalAlignment = HorizontalAlignment.Center; | ||
activeToolLabel.Background = new BorderBrush(Color.Black * 0.3f); | ||
activeToolLabel.TextColor = Color.White; | ||
grid.AddControl(activeToolLabel, 0, 0, 10); | ||
|
||
for (int i = 0; i < toolbar.Tools.Length; i++) | ||
{ | ||
buttons[i] = new Button(screenManager) | ||
{ | ||
HorizontalAlignment = HorizontalAlignment.Stretch, | ||
VerticalAlignment = VerticalAlignment.Stretch, | ||
Background = buttonBackgroud, | ||
HoveredBackground = null, | ||
PressedBackground = null, | ||
}; | ||
buttons[i].Content = images[i] = new Image(screenManager) | ||
{ | ||
Width = 42, | ||
Height = 42, | ||
}; | ||
grid.AddControl(buttons[i], i, 1); | ||
} | ||
} | ||
protected override void OnUpdate(GameTime gameTime) | ||
{ | ||
if (!Visible || !Enabled) | ||
return; | ||
if(!(toolbar.Entity is IControllable con) || con.Controller == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Laut unseren Codingrichtlinen sind out Variablen nur innerhalb des if's scopes zu verwenden There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das ist im selben Scope. Da C# bei If und || operatoren abbricht bzw. nicht mehr weiter prüft sobald die Bedingung erfühlt ist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ja ok das ist kein out habe ich übersehen. Aber nein das ist nicht der selbe Scope ^^ du returnst direkt unter dem if und verwendest somit das con außerhalb des if's s.h. zeile 101 oder 122. Das ist etwas was auch ich mir abgewöhnen muss wenn ich in octo programmiere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok OK |
||
return; | ||
#region Toolbar Update | ||
|
||
if (toolbar.Tools != null && toolbar.Tools.Length > 0) | ||
{ | ||
if (toolbar.ActiveTool == null) toolbar.ActiveTool = toolbar.Tools[0]; | ||
for (int i = 0; i < Math.Min(toolbar.Tools.Length, con.Controller.SlotInput.Length); i++) | ||
{ | ||
if (con.Controller.SlotInput[i]) toolbar.ActiveTool = toolbar.Tools[i]; | ||
con.Controller.SlotInput[i] = false; | ||
} | ||
} | ||
|
||
//Index des aktiven Werkzeugs ermitteln | ||
int activeTool = -1; | ||
List<int> toolIndices = new List<int>(); | ||
for (int i = 0; i < toolbar.Tools.Length; i++) | ||
{ | ||
|
||
if (toolbar.ActiveTool != null && toolbar.ActiveTool.Amount <= 0) | ||
toolbar.RemoveSlot(toolbar.ActiveTool); | ||
|
||
if (toolbar.Tools[i] != null) | ||
toolIndices.Add(i); | ||
|
||
if (toolbar.Tools[i] == toolbar.ActiveTool) | ||
activeTool = toolIndices.Count - 1; | ||
} | ||
|
||
if (con.Controller.SlotLeftInput) | ||
{ | ||
if (activeTool > -1) | ||
activeTool--; | ||
else if (toolIndices.Count > 0) | ||
activeTool = toolIndices[toolIndices.Count - 1]; | ||
} | ||
con.Controller.SlotLeftInput = false; | ||
|
||
if (con.Controller.SlotRightInput) | ||
{ | ||
if (activeTool > -1) | ||
activeTool++; | ||
else if (toolIndices.Count > 0) | ||
activeTool = toolIndices[0]; | ||
} | ||
con.Controller.SlotRightInput = false; | ||
|
||
if (activeTool > -1) | ||
{ | ||
activeTool = (activeTool + toolIndices.Count) % toolIndices.Count; | ||
toolbar.ActiveTool = toolbar.Tools[toolIndices[activeTool]]; | ||
} | ||
#endregion | ||
|
||
// Aktualisierung des aktiven Buttons | ||
for (int i = 0; i < toolbar.Tools.Length; i++) | ||
{ | ||
if (toolbar.Tools != null && | ||
toolbar.Tools.Length > i && | ||
toolbar.Tools[i] != null && | ||
toolbar.Tools[i].Definition != null) | ||
{ | ||
images[i].Texture = toolTextures[toolbar.Tools[i].Definition.GetType().FullName]; | ||
if (toolbar.ActiveTool == toolbar.Tools[i]) | ||
buttons[i].Background = activeBackground; | ||
else | ||
buttons[i].Background = buttonBackgroud; | ||
} | ||
else | ||
{ | ||
images[i].Texture = null; | ||
buttons[i].Background = buttonBackgroud; | ||
} | ||
} | ||
|
||
//Aktualisierung des ActiveTool Labels | ||
activeToolLabel.Text = toolbar.ActiveTool != null ? | ||
string.Format("{0} ({1})", toolbar.ActiveTool.Definition.Name, toolbar.ActiveTool.Amount) : | ||
string.Empty; | ||
|
||
activeToolLabel.Visible = !(activeToolLabel.Text == string.Empty); | ||
|
||
base.OnUpdate(gameTime); | ||
} | ||
public override string ToString() | ||
{ | ||
// TODO: resx -> Languages.OctoBasics.Tool or what ever... | ||
return "Werkzeuge"; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warum Initalize entfernen ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hast recht der muss wieder rein!