WPF“六角网格” 成分

发布于 2024-07-24 15:56:39 字数 547 浏览 9 评论 0原文

进入 WPF 自定义控件的世界,想知道设计 HexGrid 控件的最佳方法是什么? 想想你最喜欢的桌面战争游戏; 或者,同样可能的是,您最喜欢的视频游戏借鉴了令人自豪的桌面战争游戏历史的设计。

底层模型公开了一个重要的方法,作为 Map 类的一部分:

Hex GetHex(int x, int y, int z)*;

Hex 包含所有相关数据(目前,Terrain 枚举将 1:1 映射到背景颜色;从小处开始...)。

可能相关的限制:
地图大小和尺寸不变 十六进制数据会在非常可预测的时间发生变化(始终直接响应用户操作)。

理想情况下,该组件将扩展以干净地填充其容器,并且可以直接在 XAML 中声明。

我正在寻找的是构建此组件所需的粗略轮廓,而不是现成的组件。

*虽然我对这个寻址方案非常聪明,但显然我迟到了

Jumping into the world of WPF custom controls, and was wondering what the best way to design a HexGrid control would be? Think your favorite table-top war game; or, equally likely, your favorite video game that steals the design from a proud history of table-top war games.

The underlying model exposes one significant method, as a part of a Map class:

Hex GetHex(int x, int y, int z)*;

Hex contains all relevant data (at the moment, a Terrain enumeration that maps 1:1 to a background color; starting small...).

Possibly relevant constrains:
Map doesn't change in size & Hex data changes at very predictable times (always in direct response to user action).

Ideally the component will expand to fill its container cleanly, and be declarable directly in XAML.

What I'm looking for is a sketchy outline of what I need to do to build this, not a ready made component.

*I though I was being pretty clever with this addressing scheme, but apparently I'm late to the party.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-07-31 15:56:39

我认为在 WPF 中,将 HexGrid 设计为 Panel 而不是 UserControl 更为合理。 面板没有视觉表示,只需正确排列子元素(在 HexGrid 的情况下 - 采用蜂窝图案)。 这些子元素依次应该具有六边形形状。

概念证明:我的 HexGrid 项目(太大,无法在此处发布)

CodeProject 文章

< a href="https://github.com/AlexanderSharykin/HexGrid" rel="noreferrer">GitHub 存储库

HexList:选择器 ItemsControl,在 HexGrid 面板上显示 HexItem 容器中的项目

< strong>HexGrid:以蜂窝状图案排列子元素的面板

HexItem:六角形 ContentControl

声明性用法示例:

<hx:HexList Name="HexColors" Orientation="Vertical"
            Grid.Row="1"
            Padding="10"
            SelectedIndex="0"
            Background="{Binding Path=SelectedItem.Background, RelativeSource={RelativeSource Self}}"
            RowCount="5" ColumnCount="5">
    <hx:HexItem Grid.Row="0" Grid.Column="1" Background="#006699"/>
    <hx:HexItem Grid.Row="0" Grid.Column="2" Background="#0033CC"/>
    <hx:HexItem Grid.Row="0" Grid.Column="3" Background="#3333FF"/>
    <!--...-->
    <hx:HexItem Grid.Row="4" Grid.Column="1" Background="#CC9900"/>
    <hx:HexItem Grid.Row="4" Grid.Column="2" Background="#FF3300"/>
    <hx:HexItem Grid.Row="4" Grid.Column="3" Background="#CC0000"/>
</hx:HexList>

十六进制颜色选择器

我明白问题是老歌,但分享我的解决方案以防万一

In my opinion in WPF it is more reasonable to design a HexGrid as a Panel and not as UserControl. Panels don't have visual representation and only have to arrange child elements properly (in case of HexGrid - in a honeycomb pattern). Those child elements in turn should have hexagonal shape.

A proof of a concept: my HexGrid project (too large to post here)

CodeProject article

GitHub repository

HexList: selector ItemsControl which displays items in HexItem container on a HexGrid panel

HexGrid: Panel which arranges child elements in a honeycomb pattern

HexItem: hexagon-shaped ContentControl

example of declarative usage:

<hx:HexList Name="HexColors" Orientation="Vertical"
            Grid.Row="1"
            Padding="10"
            SelectedIndex="0"
            Background="{Binding Path=SelectedItem.Background, RelativeSource={RelativeSource Self}}"
            RowCount="5" ColumnCount="5">
    <hx:HexItem Grid.Row="0" Grid.Column="1" Background="#006699"/>
    <hx:HexItem Grid.Row="0" Grid.Column="2" Background="#0033CC"/>
    <hx:HexItem Grid.Row="0" Grid.Column="3" Background="#3333FF"/>
    <!--...-->
    <hx:HexItem Grid.Row="4" Grid.Column="1" Background="#CC9900"/>
    <hx:HexItem Grid.Row="4" Grid.Column="2" Background="#FF3300"/>
    <hx:HexItem Grid.Row="4" Grid.Column="3" Background="#CC0000"/>
</hx:HexList>

hex color selector

I understand that the question is an oldie but share my solution just in case

始终不够爱げ你 2024-07-31 15:56:39

编辑:这是皮特项目页面的链接,其中有一个六角网格示例。
http://blois.us/Projects.html
有一个寻路示例,显示了一个名为寻路的项目,它有一个六角网格,并且可能使用与扫雷相同的基本代码。 我还没看过。 它是 Silverlight 3,因此可能需要升级。 扫雷非常优雅。

拉尔夫

原文:
Peter blois 提供了 silverlight 2 的六角版扫雷样本。

它包括源代码。 他有一个非常优雅的方法,通过覆盖网格上的measureoverride和arrangeoverride来做到这一点。 鼠标悬停等效果很好。 代码非常少。

我在网上找不到这个项目了,尽管谷歌通过搜索六边形扫雷银光源代码有一个过时的链接,布洛伊斯彼得

布洛伊斯在以下地址有一个最新的博客,所以你可以尝试在这里联系他。 。
http://blois.us/Projects.html

祝你好运,告诉我进展如何,我'我会做类似的事情。

EDIT:Here's a link to Pete's project page which has a hex grid sample.
http://blois.us/Projects.html
There is a pathfinding sample that shows a project called pathfinding which has a Hex Grid, and probably uses the same basic code that minesweeper does. I haven't looked at it yet. It is Silverlight 3 so may need to be upgraded. Minesweeper was pretty elegant.

Ralph

ORIGINAL:
There was a sample for silverlight 2 by peter blois of a hexagonal version of minesweeper.

It included source code. He had a very elegant method of doing it by overriding the measureoverride and arrangeoverride on the grid. Mouseovers, etc. worked fine. There was remarkably little code.

I can't find the project on the web any more, although google has a stale link to it by searching for hexagon minesweeper silverlight source code blois

Peter Blois has a current blog at the below address, so you might try contacting him here...
http://blois.us/Projects.html

Good luck and tell me how it goes, I'm going to be dong something similar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文