-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from vchelaru/227-documentation-for-using-fil…
…es-generated-by-code-gen 227 documentation for using files generated by code gen
- Loading branch information
Showing
56 changed files
with
4,836 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
Samples/GumFormsSample/GumFormsSampleCommon/Screens/ComplexListBoxItemScreen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using Gum.DataTypes; | ||
using Gum.Managers; | ||
using Gum.Wireframe; | ||
using GumFormsSample.CustomRuntimes; | ||
using GumRuntime; | ||
using MonoGameGum.Forms; | ||
using MonoGameGum.Forms.Controls; | ||
using MonoGameGum.GueDeriving; | ||
using RenderingLibrary; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ToolsUtilities; | ||
|
||
namespace GumFormsSample.Screens; | ||
|
||
internal class ComplexListBoxItemScreen | ||
{ | ||
GraphicalUiElement _root; | ||
|
||
public void Initialize(GraphicalUiElement root) | ||
{ | ||
|
||
root.WidthUnits = Gum.DataTypes.DimensionUnitType.RelativeToContainer; | ||
root.HeightUnits = Gum.DataTypes.DimensionUnitType.RelativeToContainer; | ||
root.Width = 0; | ||
root.Height = 0; | ||
|
||
// Load the Gum project to get the ListBoxItem | ||
|
||
var gumProject = GumProjectSave.Load("FormsGumProject/GumProject.gumx"); | ||
ObjectFinder.Self.GumProjectSave = gumProject; | ||
gumProject.Initialize(); | ||
FormsUtilities.RegisterFromFileFormRuntimeDefaults(); | ||
|
||
FileManager.RelativeDirectory = "Content/FormsGumProject/"; | ||
|
||
_root = root; | ||
|
||
var listBox = new ListBox(); | ||
root.Children.Add(listBox.Visual); | ||
listBox.X = 30; | ||
listBox.Y = 30; | ||
listBox.Width = 400; | ||
listBox.Height = 400; | ||
|
||
// assign the template before adding new list items | ||
listBox.VisualTemplate = | ||
new MonoGameGum.Forms.VisualTemplate(() => | ||
// do not create a forms object because this template will be | ||
// automatically added to a ListBoxItem by the ListBox: | ||
new WeaponListBoxItemRuntime(fullInstantiation:true, tryCreateFormsObject: false)); | ||
|
||
listBox.ListBoxItemFormsType = typeof(WeaponListBoxItem); | ||
|
||
for (int i = 0; i < 20; i++) | ||
{ | ||
var weaponViewModel = new WeaponViewModel | ||
{ | ||
Name = $"Weapon {i}", | ||
Damage = 10 + i, | ||
RemainingDurability = 100 - i, | ||
MaxDurability = 100, | ||
Level = i | ||
}; | ||
listBox.Items.Add(weaponViewModel); | ||
} | ||
} | ||
} | ||
|
||
class WeaponViewModel | ||
{ | ||
public string Name { get; set; } | ||
public int Damage { get; set; } | ||
public int RemainingDurability { get; set; } | ||
public int MaxDurability { get; set; } | ||
public int Level { get; set; } | ||
} | ||
|
||
|
||
class WeaponListBoxItem : ListBoxItem | ||
{ | ||
public WeaponListBoxItem(InteractiveGue gue) : base(gue) { } | ||
public override void UpdateToObject(object o) | ||
{ | ||
var weaponViewModel = (WeaponViewModel)o; | ||
|
||
var view = this.Visual as WeaponListBoxItemRuntime; | ||
|
||
view.NameTextInstance.Text = weaponViewModel.Name; | ||
view.DamageTextInstance.Text = $"Damage: {weaponViewModel.Damage}"; | ||
view.DurabilityTextInstance.Text = $"Durability: {weaponViewModel.RemainingDurability}/{weaponViewModel.MaxDurability}"; | ||
view.LevelTextInstance.Text = $"Level: {weaponViewModel.Level}"; | ||
} | ||
} | ||
|
||
public partial class WeaponListBoxItemRuntime : InteractiveGue | ||
{ | ||
public NineSliceRuntime Background { get; protected set; } | ||
public TextRuntime NameTextInstance { get; protected set; } | ||
public TextRuntime DamageTextInstance { get; protected set; } | ||
public TextRuntime DurabilityTextInstance { get; protected set; } | ||
public TextRuntime LevelTextInstance { get; protected set; } | ||
public NineSliceRuntime FocusedIndicator { get; protected set; } | ||
|
||
public WeaponListBoxItemRuntime(bool fullInstantiation = true, bool tryCreateFormsObject = true) | ||
{ | ||
if(fullInstantiation) | ||
{ | ||
var element = ObjectFinder.Self.GetComponent("Controls/WeaponListBoxItem"); | ||
|
||
element.SetGraphicalUiElement(this, SystemManagers.Default); | ||
} | ||
|
||
} | ||
public override void AfterFullCreation() | ||
{ | ||
Background = this.GetGraphicalUiElementByName("Background") as NineSliceRuntime; | ||
NameTextInstance = this.GetGraphicalUiElementByName("NameTextInstance") as TextRuntime; | ||
DamageTextInstance = this.GetGraphicalUiElementByName("DamageTextInstance") as TextRuntime; | ||
DurabilityTextInstance = this.GetGraphicalUiElementByName("DurabilityTextInstance") as TextRuntime; | ||
LevelTextInstance = this.GetGraphicalUiElementByName("LevelTextInstance") as TextRuntime; | ||
FocusedIndicator = this.GetGraphicalUiElementByName("FocusedIndicator") as NineSliceRuntime; | ||
|
||
if(FormsControlAsObject == null) | ||
{ | ||
FormsControlAsObject = new WeaponListBoxItem(this); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.