导航箭头? [英] Navigation arrows ?

查看:93
本文介绍了导航箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- q 12-

我有一个名为Background的UserControl和一个名为NavigationArrows的简单类。



这个NavigationArrows类正在加载一堆* .png的图像,显​​示一些点亮或熄灭的箭头,具体取决于用户的按键。

UC背景,包含BIG背景图像,并通过Background_KeyPress事件进行平移。

----

我想要的很简单:

我想将箭头连接到KeyPress事件。

(按下按键时显示点亮的箭头图像)

----

但是!

我可以非常简单地完成这一切,都在UC内部。但我不想那样。

我希望NavigationArrows类包含箭头的各个方面!!!!

加载图像,!!! Events !!!,在画布上的位置,大小箭头,以及我现在想不到的其余部分。总之,要包含与箭头类/(或对象,如果你想要的话)相关的所有属性,事件,方法。

我的大问题是2个clases之间的联系。如何以一种简单而优雅的方式以逻辑的方式,以一种非混乱的方式连接它们。

我在链接这两个段落的方式在代码中非常混乱。这里和那里有太多的争论。 (这不是因为我给的名字而混淆 - 不是那样)因为我必须建立的结构令人困惑!它在每个角落都非常复杂和重量级。

----

现在,在这个阶段我正在展示代码,这是开始。

但是我必须加载并链接其余的箭头图像(我没有在这里显示) - 它还没有编写脚本。但我从经验中知道,它会很快聚集起来。

此外,我还必须将其他类/对象加载到画布中。这个Arrow类只是一个测试。如果我必须加载100个clases,每个都包含它自己的一组图像(比如每个类50个img),并且有自己的方法和属性,并且有自己的!! EVENTS !!,它们必须被连接到背景对象(不知何故)。

你是通过LOGICAL方式和NON-Confusing看到我的意思吗?

它必须像对象和类之间的这个链接的开关。类似于:

UI.NavigationArrows navArrows = new UI.NavigationArrows();

navArrows.Active();

navArrows.pozition(0,0);

navArrows.size(20,20);

就是这样。他们必须表现和完成工作!

我怎样才能实现这个目标?

谢谢你,

- q 12-



我的尝试:



-q12-
I have a UserControl named Background and a simple class named NavigationArrows.

This NavigationArrows class is loading a bunch of *.png's images displaying some arrows that are lit OR unlit, depending on keypressed by user.
The UC Background, is containing the BIG Background image and is panning it through the Background_KeyPress event.
----
What I want is simple:
I want to connect the arrows to the KeyPress event.
(to show the lit arrow image when a key is pressed)
----
BUT !
I can do it very simple, all inside UC. But I dont want that.
I want the NavigationArrows Class to contain every aspect of the arrows!!!!
loading the images, the !!!Events!!!, position on canvas, size of the arrows, and the rest that I can't think of now. In a word, to contain all the properties, events, methods, that are related to the arrows class/(or object if you want).
My big problem is the connections between the 2 clases. How to connect them in a simple and elegant way, in a LOGICAL way, in a NON-Confusing way.
My way of linking these 2 clases is very confusing in code. Too many arguments here and there. (It is not confusing because of the names I gave - not that) It is confusing because of the structure i must build !!! It is extremely convoluted and wtf at every corner.
----
Right now, in this stage I am presenting the code, it is the begining.
But I will have to load and link the rest of the arrow images (i did not show that here)- it is not scripted yet. But I know from experience, it will become agglomerated very quickly.
Also, I will have to load OTHER classes/objects into canvas too. This Arrow class is just a test. If I have to load 100 clases, each of them containing it's own SET of images (let's say 50 img per class), and with their own Methods and properties, and with their own !!EVENTS!!, that they must be conected to the Background object (somehow).
Do you see what I mean by LOGICAL way and NON-Confusing ?
It must be like a on/off switch this link between object and class. Something like:
UI.NavigationArrows navArrows = new UI.NavigationArrows();
navArrows.Active();
navArrows.pozition(0,0);
navArrows.size(20,20);
And thats it. And they must perform and do their jobs!
How can I achieve this?
Thank you,
-q12-

What I have tried:

public partial class Background : UserControl
//...................

        //UI.NavigationArrows navArrows = new UI.NavigationArrows();
        Rectangle navArrowsRectangle = new Rectangle(10, 10, 100, 100);
        void Background_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(q1.backgroundImage, q1.rectangle);//BackgroundImage
             
            string imgName = "UI\\NavigationArrows OFF.png";
            Image BaseImg = Image.FromFile(imgName);
            e.Graphics.DrawImage(BaseImg, navArrowsRectangle);//NavigationArrows OFF
        }

        void Background_KeyPress(object sender, KeyPressEventArgs e)
        {
            int th12 = 0;
            if (e.KeyChar == 'w')
            {
                if (q1.rectangle.Y < 0) q1.rectangle.Y += q1.amount;
                else q1.rectangle.Y = 0;
            }
            if (e.KeyChar == 's')
            {
                th12 = -q1.imgy + this.Height;
                if (q1.rectangle.Y > th12) q1.rectangle.Y -= q1.amount;
                else q1.rectangle.Y = th12;
            }
            if (e.KeyChar == 'a')
            {
                if (q1.rectangle.X < 0) q1.rectangle.X += q1.amount;
                else q1.rectangle.X = 0;
            }
            if (e.KeyChar == 'd')
            {
                th12 = -q1.imgx + this.Width;
                if (q1.rectangle.X > th12) q1.rectangle.X -= q1.amount;
                else q1.rectangle.X = th12;
            }
            this.Refresh();//forPaintEvent
        }



这是我希望它改造成的第二个类成为在自己。

我的意思是它应该插入和播放到Background类。


and this is my second class that I want it remodeled to become "In Itself".
I mean that it should plug and play into Background class.

public class NavigationArrows
{

    public void  InitializeNavigationArrows()
    {
        string imgName = "UI\\NavigationArrows OFF.png";
        BaseImg = Image.FromFile(imgName);
    }
    public Image BaseImg;

推荐答案

这就是我所说的!

我正在抱怨,因为非常令人沮丧和讨厌;

看看navArrow如何拧入的很多地方。

我会突出显示它们为了你。

这是一个非常难看的代码 - 我不能做其他的。

这是我通常可以做的基本代码。



想象一下,我现在必须在其中添加另一个带有图像的类。

想象一下当我在这个大海捞针代码中找东西时的WTF大小!



重新编辑:我显示整个UserControl

This is what I was talking about!
And I am complaining because is very frustrating and annoying;
Look in how MANY places the navArrow is screw in.
I will highlight them for you.
Is a very ugly code - and I can not do other that this one.
It is the basic code I can normally do.

Imagine now I have to add another class(es) with images inside it.
Just imagine the WTF size when I am looking for something to find in this haystack of code!

Re-edited: I show the entire UserControl !
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace game_GameMap
{
    public partial class Background : UserControl
    {
        public struct BackgroundImage_
        {
            public int imgx, imgy;
            public int amount;
            public Image backgroundImage;
            public Rectangle rectangle;
            public Size windowSize;
        }
        public BackgroundImage_ bg = new BackgroundImage_();
        void Initialize_bg()
        {
            bg.amount = 50;
            string imgName = "assets\\map1Moon.jpg";
            bg.backgroundImage = Image.FromFile(imgName);
            bg.imgx = 736 * 3; bg.imgy = 552 * 3;
            bg.rectangle = new Rectangle(0, 0, bg.imgx, bg.imgy);
            bg.windowSize = this.Size;
        }
        public Background()
        {
            InitializeComponent();
        }
        private void Background_Load(object sender, EventArgs e)
        {
            DoubleBuffered = true;
            this.KeyDown += new KeyEventHandler(Background_KeyDown);
            this.KeyUp += new KeyEventHandler(Background_KeyUp);
            this.Paint += new PaintEventHandler(Background_Paint);
            Initialize_bg();

            navArrow.aInitializeNavigationArrows(); //navArrowPos();
        }




       
        void Background_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(bg.backgroundImage, bg.rectangle);//BackgroundImage
            e.Graphics.DrawImage(navArrow.Active(), navArrowsRectangle);//NavigationArrows
        }

       
        UI.NavigationArrows navArrow = new UI.NavigationArrows();
        int navarrowX = 100, navarrowY = 100;
        Rectangle navArrowsRectangle;
        void navArrowUpdatePosition()
        {
            navarrowX = this.Width / 2 - 50; navarrowY = this.Height - 100;
            navArrowsRectangle = new Rectangle(navarrowX, navarrowY, 100, 100);
        }
        void Background_KeyDown(object sender, KeyEventArgs e)
        {
            navArrowUpdatePosition();

            int th12 = 0;
            if (e.KeyCode == Keys.W)
            {
                navArrow.GetKey("w");
                if (bg.rectangle.Y < 0) bg.rectangle.Y += bg.amount;
                else bg.rectangle.Y = 0;
            }
            if (e.KeyCode == Keys.S)
            {
                navArrow.GetKey("s");
                th12 = -bg.imgy + this.Height;
                if (bg.rectangle.Y > th12) bg.rectangle.Y -= bg.amount;
                else bg.rectangle.Y = th12;
            }
            if (e.KeyCode == Keys.A)
            {
                navArrow.GetKey("a");
                if (bg.rectangle.X < 0) bg.rectangle.X += bg.amount;
                else bg.rectangle.X = 0;
            }
            if (e.KeyCode == Keys.D)
            {
                navArrow.GetKey("d");
                th12 = -bg.imgx + this.Width;
                if (bg.rectangle.X > th12) bg.rectangle.X -= bg.amount;
                else bg.rectangle.X = th12;
            }
            this.Refresh();//forPaintEvent
        }
        void Background_KeyUp(object sender, KeyEventArgs e)
        {
            navArrow.GetKey("none");
            this.Refresh();
        }
        private void Background_SizeChanged(object sender, EventArgs e)
        {
            navArrowUpdatePosition(); 
            this.Refresh();
        }

    }
}


(抱歉制作多种解决方案,但是为了清晰的可视化和理解。)

我进一步简化了我的问题...

我在每个事件中都有1个NavigationArrows参考!

如果我可以过滤更多......

我想它应该是这样的:

在NavigationArrows类里面,能够实现每个事件,就像它在这里一样背景UserControl。在2个地方进行事件的并行实现,但实际上是同一个事件。

有可能进行这样的操作吗?





(sorry for making multiple solutions, but is for the sake of a clear visualization and understanding.)
I simplified my problem further...
And I have 1 NavigationArrows reference in each Event!
If I can filter MORE...
I imagine that it should be something like this:
Inside NavigationArrows class, to be able to implement each event like it is here in the Background UserControl. To have a paralel implementation of an event in 2 places, but in fact to be the same event.
It is possible such maneuver ?


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using game_GameMap_v2.UI;

namespace game_GameMap_v2
{

    public partial class Background : UserControl
    {
        public static int Width_ = 0, Height_ = 0;
        public Background()
        {
            InitializeComponent();
            DoubleBuffered = true;
            this.KeyDown += new KeyEventHandler(Background_KeyDown);
            this.KeyUp += new KeyEventHandler(Background_KeyUp);
            this.Paint += new PaintEventHandler(Background_Paint);

            Map.Initialize();
            NavigationArrows.Initialize();
        }

    
        void Background_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(Map.Img1, Map.rectangle);//BackgroundImage

            e.Graphics.DrawImage(NavigationArrows.Active(), NavigationArrows.Rectangle_);//NavigationArrows
        }



        void Background_KeyDown(object sender, KeyEventArgs e)
        {
            Map.GetKey(e.KeyCode.ToString());
            NavigationArrows.GetKey(e.KeyCode.ToString());
            this.Refresh();
        }
        void Background_KeyUp(object sender, KeyEventArgs e)
        {
            Map.GetKey("none");
            NavigationArrows.GetKey("none");
            this.Refresh();
        }
        private void Background_SizeChanged(object sender, EventArgs e)
        {
            Width_ = this.Width; Height_ = this.Height;//update this first
            NavigationArrows.UpdatePosition();
            this.Refresh();
        }

    }
}


这篇关于导航箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆