简体   繁体   中英

Visual Studio 2010 extension: parse code, render result

I'm currently working on a project, which use a custom render engine, build on top of XNA, to draw UI elements such: buttons, labels, panels, ect.

The engine structure is relative simple. There's a screen manager which holds several game secreens. A game screen is implemented extending an engine base class called GameView. The GameView class is responsible for handling the UI elements hirerarchy.

The way the developer can add some UI controls to the game view is very simple and it's logic is ispired by the ASP.NET control hirearchy. You have to override a method called LoadControls(), create instances of your desired controls and add them to the GameView controls collection.

Here an example:

    public override void LoadControls()
    {
        ImageFrame titleImage = new ImageFrame();
        titleImage.ID = "TitleImage";
        titleImage.Move(GameUI.Location(ViewLocation.CenterTop, -332, 4));
    titleImage.Width = 664;
    titleImage.Height = 166;
        titleImage.Image = "image_title";
        this.UI.Controls.Add(titleImage);

        ImageFrame freeImage = new ImageFrame();
        freeImage.ID = "FreeImage";
        freeImage.Move(GameUI.Location(ViewLocation.CenterTop, 160, 95));
        freeImage.Width = 170;
        freeImage.Height = 76;
        freeImage.Image = "image_free";
        freeImage.IsVisible = GameContext.Current.IsTrialMode;
        this.UI.Controls.Add(freeImage);

        Button playButton = new Button();
        playButton.ID = "PlayGameButton";
        playButton.Width = 216;
        playButton.Height = 96;
        playButton.Move(GameUI.Location(ViewLocation.CenterTop, -108, 130));
        playButton.Text = GameContext.Current.Dictionary[StringKeys.PlayGameButtonText];
        playButton.Font = FontNames.Floraless1;
        playButton.FontScale = 1.3f;
        playButton.FontPressedColor = Color.White * .8f;
        playButton.Click += new EventHandler<EventArgs>(PlayGameButton_Click);
        this.UI.Controls.Add(playButton);
    }

Creating UI is really easy with code, but when you need to create complex layout, it's really hard to figure out the result. I was wondering if it is possible to develop a custom extension for VS2010 which renders the resulting "view" of my GameView control hirearchy. I don't need to create an UI designer. I just need to read some hand writed code in the code editor and render the result in real time while I'm still in visual studio (not running the application).

In short, it is possibile to extend visual studio 2010 to create a custom "designer" which parse .cs code in real time end produce a render output?

这可能会让您入门: 创建自定义Visual Studio设计器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM