Skip to content

Allow custom widgets when loading MML#402

Merged
rds1983 merged 2 commits into
MyraUI:masterfrom
spacechase0:custom-widget-mml
Sep 19, 2024
Merged

Allow custom widgets when loading MML#402
rds1983 merged 2 commits into
MyraUI:masterfrom
spacechase0:custom-widget-mml

Conversation

@spacechase0
Copy link
Copy Markdown
Contributor

@spacechase0 spacechase0 commented Oct 5, 2023

Example:

namespace MyGameProject;

public class ItemSlot : ButtonBase<Panel>
{
    // ...
}
Project.ExtraWidgetAssembliesAndNamespaces.Add( typeof( ItemSlot ).Assembly, new string[] { typeof( ItemSlot ).Namespace } );
Grid g = Project.LoadFromXml(File.ReadAllText(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "assets/inventory.xmmp")), MyraUtil.AssetManager).Root as Grid;
var slots = g.GetChildren().Where(w => w is ItemSlot).Cast<ItemSlot>().ToArray();
slots[0].Stack = new Items.ItemStack("dagger") { Quantity = 1 };
<?xml version="1.0" encoding="UTF-8" ?>
<Project>
  <Project.ExportOptions />
  <Grid RowSpacing="4" ColumnSpacing="4">
    <Grid.DefaultColumnProportion Type="Pixels" Value="40"/>      
    <Grid.DefaultRowProportion Type="Pixels" Value="40"/>
    <ItemSlot GridRow="0" GridColumn="0" />
    <!-- a lot more of ItemSlot with different GridRow / GridColumn here -->
  </Grid>
</Project>

@benda
Copy link
Copy Markdown

benda commented Jul 31, 2024

@spacechase0 @rds1983 Can this be fixed and merged ? Seems very useful.

@rds1983 rds1983 merged commit 3ed960e into MyraUI:master Sep 19, 2024
@rds1983
Copy link
Copy Markdown
Collaborator

rds1983 commented Sep 19, 2024

thanks @spacechase0 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants