menu/hud buttons

Started by jakeflee, January 22, 2014, 07:10:40 PM

Previous topic - Next topic

jakeflee

is there a way to make a custom button in the hud or to the  side of it with the crpl? if so how would one go about doing that?

Michionlion

look at the credits mission code for inspiration/guidance - that will show you how to display a hud type thing, and it is pretty easy from there.
"Remember kids, the only difference between science and messing around is writing it down."
                                                                                                                         - Adam Savage

My website
My CW1, and CW2 maps!

eduran

Quote from: eduran on January 09, 2014, 01:50:01 PM
Using SetScreenMode(TRUE) on a CRPL core has two effects:
1) The core is no longer affected by zooming in or out. Its size always stays the same.
2) The core is no longer anchored to a map cell. Instead, its position is defined relative to the bottom left corner of the game's window. Panning the map will not change the core's position. Example:

SetScreenMode(TRUE)
SetScreenCoords(0 0)
# the core will now stay in the bottom left corner of the game window
# zooming or panning the map will not change the core's position

SetScreenCoords(ScreenWidth div(2) ScreenHeight div(2))
# same as above, but the core will always be in the center of the window


And a more elaborate example. It's taken from one of my maps (Asteroid Belt, can be found here). Basically, it creates a clickable button at the top left of the screen (screenshot in the thread linked above).


# CTSwitch.crpl
# Created on: 11/5/2013 10:51:00 AM
# ------------------------------------------

# Part of the Creeper Tunnel scripts.
# This script provides the button to toggle the creeper tunnel display.

# locations of the button images
$buttonOnImg:"Custom1_128"
$buttonOffImg:"Custom2_128"

# don't change these, they are accessed by other scripts
$status:1
$name:"switch"

once
@Setup
endonce

# find out if the player clicked the button
if(GetMouseButtonDown(0))
if(distance(GetMousePosition CurrentPixelCoords) lt(10))
# button has been clicked, toggle status and image
PlaySound("Misc14")
if(<-status)
SetImageColor(Self "main" 255 255 255 0)
SetImageColor(Self "off" 255 255 255 255)
0 ->status
else
SetImageColor(Self "main" 255 255 255 255)
SetImageColor(Self "off" 255 255 255 0)
1 ->status
endif
endif
endif

# this happens every frame to make sure the button is in the right spot in case the window is resized
SetScreenPixelCoordX(105)
SetScreenPixelCoordY(ScreenHeight sub(19))

:Setup
SetUnitAttribute(Self CONST_COUNTSFORVICTORY 0)
SetUnitAttribute(Self CONST_NULLIFIERDAMAGES 0)
SetUnitAttribute(Self CONST_TAKEMAPSPACE 0)
# set images, hide the off button image
SetImage(Self "main" <-buttonOnImg)
SetImageColor(Self "main" 255 255 255 255)
SetImage(Self "off" <-buttonOffImg)
SetImageColor(Self "off" 255 255 255 0)
# anchor button to the top left corner of the screen
SetScreenMode(true)
SetScreenPixelCoordX(105)
SetScreenPixelCoordY(ScreenHeight sub(19))
# set button text
SetText("toggle creeper tunnel display (works only while game is unpaused)")
SetTextAnchor("MiddleLeft")

:Awake
SetScreenMode(true)

:GameLoaded
SetScreenMode(true)
SetTextX(11)
SetTextY(-1)
SetTextSize(0.6)


jakeflee