Slava wrote: ↑Thu Dec 12, 2024 7:38 amI'm more interested in what's in your onDrawSkills hook. Can I take a look at it to see how you did it?

There was nothing fancy or even interesting in that onDrawSkills hook, any programmer that read the GraphicsContext documentation could write it in a few minutes even if they didn't know anything else about Grimrock (and from the untidiness you can see I wrote it in a few minutes too):
Code: Select all
function draw(p, context, champion)
for t = 1, #SKILL_TREES do
for s = 1, #SKILL_TREES[t] do
local butt = buttons[t][s]
local x = STARTX*context.width+butt.x*context.height
local y = butt.y*context.height
local size = BUTTON_SIZE*context.height
if context.mouseX >= x and context.mouseX <= x+size
and context.mouseY >= y and context.mouseY <= y+size then
-- context.button is currently broken in onDrawSkills. TODO.
-- if context.button("skillbutton",context.mouseX-1,context.mouseY-1,size,size) then
if context.mouseDown(0) then
skillButtonClicked(champion,t,s)
end
-- end
drawTooltip(p,context,champion,t,s)
end
local known = skills[champion:getOrdinal()][t][s]
local unlocked = true
if not known then unlocked = meetsReqs(champion,t,s) end
context.drawImage2(unlocked and IMG_TRAITS or IMG_TRAITS_LOCKED,x,y,(SKILL_TREES[t][s].icon%10)*75,(math.floor(SKILL_TREES[t][s].icon/10))*75,IMG_FRAME_SIZE,IMG_FRAME_SIZE,size,size)
local frameimg = known and IMG_FRAME_KNOWN or unlocked and IMG_FRAME_UNLOCKED or IMG_FRAME_LOCKED
context.drawImage2(frameimg,x,y,0,0,IMG_FRAME_SIZE,IMG_FRAME_SIZE,size,size)
end
end
end
As for the mod itself, most of it was narratively meaningless and I stopped wanting to make meaningless stuff, so I subsumed everything interesting from it (there wasn't much interesting in it) into other projects.
Slava wrote: ↑Thu Dec 12, 2024 10:36 amI don't know how simple a question that is. But does anyone know how GraphicsContext.translate() works? I haven't found a description of this function anywhere.
Think of it as moving the origin point of the GraphicsContext on the screen. drawImage() and such add the context's translation to the x and y values you pass to them to determine where on the screen the image/whatever is drawn. One of the drawing hooks, onDrawAttackPanel, gives you a GraphicsContext that's already translated.