Rebol/View:如何将图像分配给已创建的布局?

发布于 2024-09-30 15:57:57 字数 1340 浏览 0 评论 0原文

使用 Rebol/View 2.7.7,我尝试根据 Nick 的 Rebol 教程创建一个纸牌游戏:http://re-bol.com/rebol.html#section-10.18。我想要做的是从 Nick 创建的二进制文件中读取卡片,丢弃一些数据,然后用它来布局一张卡片,4 行 3 列,其中 2 个中心卡片位置未使用。

这是我的代码:

protect-system

random/seed now

do %cards.r  ;--include the binary card data

the-tableau: [
 size 320x480 backdrop 0.170.0
 style tabstyle image 80x100 teal
 style holdplace box 80x100 coal
 across
 at 30x20 tc1: tabstyle
 tc2: tabstyle 
 tc3: tabstyle return
 at 30x130 tc4: tabstyle
 tc100: holdplace
 tc5: tabstyle return
 at 30x240 tc6: tabstyle
 tc200: holdplace
 tc7: tabstyle return
 at 30x350 tc8: tabstyle
 tc9: tabstyle
 tc10: tabstyle
]

lc: copy []
lc: [tc1 tc2 tc3 tc4 tc5 tc6 tc7 tc8 tc9 tc10]
deck-cards: copy []  ; The deck holds all of the cards from the binary file
deck-cards-num: copy []
deck-cards-color: copy []
lay: layout the-tableau
foreach [card label num color pos] cards [

 dimg: load to-binary decompress (card)
 append deck-cards dimg ;feel movestyle
 throw-away-label: label
 append deck-cards-num num
 append deck-cards-color color
 throw-away-pos: pos
]

random-card: does [pick deck-cards random length? deck-cards]
foreach c lc [set-face get c deck-cards]

view lay

do-events

但这根本不显示卡片。我什至不确定它是否正确读取?问题出在哪里?

Using Rebol/View 2.7.7, I'm trying to create a card game based on Nick's Rebol tutorial at: http://re-bol.com/rebol.html#section-10.18. What I want to do though is read the cards from the binary file Nick created, discard some of the data, and use it to layout a tableau of cards, 4 rows of 3 columns, with the 2 center card locations not used.

Here's my code:

protect-system

random/seed now

do %cards.r  ;--include the binary card data

the-tableau: [
 size 320x480 backdrop 0.170.0
 style tabstyle image 80x100 teal
 style holdplace box 80x100 coal
 across
 at 30x20 tc1: tabstyle
 tc2: tabstyle 
 tc3: tabstyle return
 at 30x130 tc4: tabstyle
 tc100: holdplace
 tc5: tabstyle return
 at 30x240 tc6: tabstyle
 tc200: holdplace
 tc7: tabstyle return
 at 30x350 tc8: tabstyle
 tc9: tabstyle
 tc10: tabstyle
]

lc: copy []
lc: [tc1 tc2 tc3 tc4 tc5 tc6 tc7 tc8 tc9 tc10]
deck-cards: copy []  ; The deck holds all of the cards from the binary file
deck-cards-num: copy []
deck-cards-color: copy []
lay: layout the-tableau
foreach [card label num color pos] cards [

 dimg: load to-binary decompress (card)
 append deck-cards dimg ;feel movestyle
 throw-away-label: label
 append deck-cards-num num
 append deck-cards-color color
 throw-away-pos: pos
]

random-card: does [pick deck-cards random length? deck-cards]
foreach c lc [set-face get c deck-cards]

view lay

do-events

But this doesn't show the cards at all. I'm not even sure it's reading the correctly? Where is the problem?

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

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

发布评论

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

评论(3

夏末的微笑 2024-10-07 15:57:57

实际上,您最后没有在 for 循环中使用随机卡函数...:-)

foreach c lc [get c set-face get c random-card ]

您注意到您不确定数据是否已正确加载...

这是一个简单的方法来找出...只需打印/探测类型? 该数据的

dimg: load to-binary decompress (card)
probe type? dimg

在这种情况下,它将打印出 图像!在控制台中...所以是的...这正在工作。 :-)

作为一个补充的小细节,我注意到您没有补偿卡数据中“背面”图像(位于其末尾)的随机性,因此随机卡函数应该像这样修复:

random-card: does [pick deck-cards random (length? deck-cards) - 1] ; - 1 since we don't want the back face to be picked.

Actually you didn't use the random-card function in your for loop at the end... :-)

foreach c lc [get c set-face get c random-card ]

You note that you are not sure if data was loaded correctly...

here is a simple way to find out... just print/probe the TYPE? of that data

dimg: load to-binary decompress (card)
probe type? dimg

In this case it will print out image! in the console... so yep... that's working. :-)

As an added little detail, I noticed you didn't compensate your random for the "back face" image in the card data (which is at its end), so the random-card function should be fixed like so:

random-card: does [pick deck-cards random (length? deck-cards) - 1] ; - 1 since we don't want the back face to be picked.
假扮的天使 2024-10-07 15:57:57

如果事件循环未启动,则只需要“do-events”。

View/new 不会启动事件循环..但 View 会启动事件循环,

但我没有解决您的实际问题:(

You only need 'do-events if the event loop is not started.

View/new does not start the event loop .. but View does

I'm not addressing your actual problem though :(

草莓味的萝莉 2024-10-07 15:57:57

为了使 do-events 注释清晰,我在这里添加了一些答案,以便我可以添加一些内联代码......

这是一个您希望使用 do-events 的示例。

view/new lay ; display the interface right now. (with no cards)

random-card: does [pick deck-cards random (length? deck-cards) - 1] ; - 1 since we don't want the back face to be picked.

; deal cards with a half second delay.
foreach c lc [f: get c set-face get c random-card wait 0.5]


do-events

在这里,一旦所有视图窗口关闭,您在“DO-EVENTS”之后放置的任何代码都将被执行。

可以是 tmp 文件清理、退出时保存、“保存更改”对话框等。

附加说明:

在构建图形代码时,最好将其放在应用程序的开头:

print " " 

它将打开控制台,然后任何视图窗口都会显示在其前面。

准备好共享时,只需注释该行并删除代码中的所有打印语句即可。

这对于三件事很有用:

1)当控制台总是在您的应用程序上弹出,而它在窗口打开后跟踪(打印/探测/等)一些内容时,通常非常烦人。

2)这还有一个更有用的副作用,即显示您的应用程序是否正确退出,因为当所有等待正确终止时控制台也会退出。

在原始示例中,如果添加上面的打印,那么您将看到控制台永远不会关闭,因此这意味着应用程序仍在运行,没有更多应用程序窗口侦听事件。

3)它还有一个优点,你可以通过关闭控制台窗口直接终止图形应用程序。这会有效地关闭所有窗口并立即等待,并快捷方式您可能拥有的任何“应用程序退出”代码(do-events 之后的代码)。

to make the do-events note clear, I added a little answer here so I can add some inline code....

here is an example where you'd want your do-events to be used.

view/new lay ; display the interface right now. (with no cards)

random-card: does [pick deck-cards random (length? deck-cards) - 1] ; - 1 since we don't want the back face to be picked.

; deal cards with a half second delay.
foreach c lc [f: get c set-face get c random-card wait 0.5]


do-events

here, any code you put after 'DO-EVENTS will be executed once all view windows have closed.

which can be things like tmp file cleanup, save on exit, "save changes" dialogs, etc.

additional note:

While building graphics code, its a good habit to place this at the very start of you application:

print " " 

It will open up the console, and then any view windows will show up in front of it.

When ready to share, just comment the line and remove any print statements in your code.

this is useful for 3 things:

1) Its usually highly annoying when the console always pops-up over your application while its tracing (print/probe/etc) some stuff after your window opens.

2) This also has the more useful side-effect of showing you if your application quit correctly since the console will ALSO quit when all waits have terminated correctly.

In your original example, if you add the above print, then you'll see that the console never closes, so this means the application is still running with no more application windows listening to events.

3) It also has the advantage that you can terminate the graphic app directly by closing the console window. This effectively closes all windows and waits immediately and shortcuts any "on application quit" code you might have (code after do-events).

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