Author Topic: [SOLVED] SCI0 - Death Icon at Top of Window  (Read 3864 times)

0 Members and 1 Guest are viewing this topic.

Offline Doan Sephim

[SOLVED] SCI0 - Death Icon at Top of Window
« on: January 11, 2021, 08:40:28 AM »
Does anyone have any ideas how I can edit the Template to display the death icon at the top of the window instead of always on the left-hand side? Ideally, I'd like to be able to switch this, but I'm having trouble finding out even where to look.
« Last Edit: January 12, 2021, 04:10:18 PM by Doan Sephim »


Artificial Intelligence Competition

Offline lskovlun

Re: SCI0 - Death Icon at Top of Window
« Reply #1 on: January 11, 2021, 10:48:20 AM »
OK, so there are two things to be done here. Changing the Print procedure and then changing the death scripts.
The first part is more difficult, so we'll start with that. The central bit of code is this, in Controls.sc (you're still on the old syntax, right?):
Code: [Select]
(if(hIcon)
(send hIcon:moveTo(4 4))
(send hDText:moveTo( (+ 4 (send hIcon:nsRight)) (send hIcon:nsTop) ))
(send hDialog:add(hIcon))
)
As you can see this positions an icon (which was created before this) at the top left, then positions the (also previously created) text next to it. The important thing to note when changing this code is that the position and size of these objects are (and can be) recomputed several times (using the setSize and moveTo methods in particular) as more things are added to the layout. So you can take advantage of this. It's probably better to do this in a separate copy of Print since it's a bit of a mess already (you can always work on integrating them later, and may have to do so out of heap concerns). Then you add an option in the death script to call either of those as desired.

Offline Doan Sephim

Re: SCI0 - Death Icon at Top of Window
« Reply #2 on: January 11, 2021, 11:27:58 AM »
OK, so there are two things to be done here. Changing the Print procedure and then changing the death scripts.
The first part is more difficult, so we'll start with that. The central bit of code is this, in Controls.sc (you're still on the old syntax, right?):
Code: [Select]
(if(hIcon)
(send hIcon:moveTo(4 4))
(send hDText:moveTo( (+ 4 (send hIcon:nsRight)) (send hIcon:nsTop) ))
(send hDialog:add(hIcon))
)
As you can see this positions an icon (which was created before this) at the top left, then positions the (also previously created) text next to it. The important thing to note when changing this code is that the position and size of these objects are (and can be) recomputed several times (using the setSize and moveTo methods in particular) as more things are added to the layout. So you can take advantage of this. It's probably better to do this in a separate copy of Print since it's a bit of a mess already (you can always work on integrating them later, and may have to do so out of heap concerns). Then you add an option in the death script to call either of those as desired.
Thanks for pointing me in the right direction! I will work around a bit with this!

Also, I am now working with Sierra Script!

Offline Doan Sephim

Re: SCI0 - Death Icon at Top of Window
« Reply #3 on: January 12, 2021, 08:54:52 AM »
As I'm working on this, I hit upon a small and probably easy to fix issue:

Code: [Select]
(hIcon moveTo: *X* 4)
(hDText moveTo: 4 (+ 4 (hIcon nsBottom?)) )
(hDialog add: hIcon)

I've set the text to be written 4 pixels down from the bottom of the Icon, but setting the Icon's X position is proving difficult for me. I was trying to find the window's length variable, but am not sure where it is.

Offline gumby

Re: SCI0 - Death Icon at Top of Window
« Reply #4 on: January 12, 2021, 09:45:12 AM »
If it helps, the window coordinates are properties in the Window class (top/left/bottom/right).

Code: [Select]
(class Window of SysWindow
(properties
top 0
left 0
bottom 0
right 0
color clBLACK
back clWHITE
priority -1
window 0
type 0
title 0
brTop 0
brLeft 0
brBottom 190
brRight 320
underBits 0
)
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lskovlun

Re: SCI0 - Death Icon at Top of Window
« Reply #5 on: January 12, 2021, 02:58:26 PM »
In fact this is easy: There is already code to do it! When looking over the code, I found a special case that I didn't know about: If you call Print with an empty text along with an icon, the icon will be centered:
Code: [Select]
(Print "" #icon 800 0 0 #button "Very long button text here\nto illustrate the point")pictured below. All you have to do is move that code appropriately.
Code: [Select]
(hDialog setSize: center:)
(hIcon
moveTo:
(/
(-
(- (hDialog nsRight?) (hDialog nsLeft?))
(- (hIcon nsRight?) (hIcon nsLeft?))
)
2
)
4
)
This relies on the trick I mentioned before, that it is permitted to recalculate the size of things multiple times.
« Last Edit: January 12, 2021, 03:02:22 PM by lskovlun »

Offline Doan Sephim

Re: SCI0 - Death Icon at Top of Window
« Reply #6 on: January 12, 2021, 04:09:51 PM »
Nice! That works just right! Thanks!  ;D


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.039 seconds with 23 queries.