22 const char *bindstr
, *text
;
47 k_guitrick_type_ollie
,
48 k_guitrick_type_trick
,
49 k_guitrick_type_backflip
,
55 mdl_context model_icons
;
59 mdl_submesh
*icons
[ k_gui_icon_count
];
61 static gui
= {.cur_icon_colour
= {1.0f
,1.0f
,1.0f
,1.0f
},.colour_changed
=1};
64 void gui_helper_action( const char *bindstr
, const char *text
){
65 if( gui
.helper_count
>= vg_list_size(gui
.helpers
) ){
66 vg_error( "Too many helpers\n" );
70 struct gui_helper
*helper
= &gui
.helpers
[ gui
.helper_count
++ ];
71 helper
->bindstr
= bindstr
;
75 static void gui_draw(void){
76 if( v3_dist2(localplayer
.rb
.co
,gui
.trick_co
) > 2.0f
){
77 gui
.trick_type
= k_guitrick_type_none
;
80 if( gui
.trick_type
== k_guitrick_type_pump
){
81 gui_helper_action(axis_display_string(k_sraxis_grab
),"Crouch");
83 else if( gui
.trick_type
== k_guitrick_type_backflip
){
84 gui_helper_action(joystick_display_string(k_srjoystick_steer
,1),"Flip");
86 else if( gui
.trick_type
== k_guitrick_type_ollie
){
87 gui_helper_action(button_display_string(k_srbind_jump
),"Ollie");
89 else if( gui
.trick_type
== k_guitrick_type_trick
){
90 gui_helper_action(button_display_string(k_srbind_trick0
),"Shuvit");
91 gui_helper_action(button_display_string(k_srbind_trick1
),"Kickflip");
92 gui_helper_action(button_display_string(k_srbind_trick2
),"Tre-Flip");
94 else if( gui
.trick_type
== k_guitrick_type_isc
){
95 gui_helper_action(button_display_string(k_srbind_camera
),"Camera");
96 gui_helper_action(button_display_string(k_srbind_use
), "Skate/Walk");
108 m4x4_zero( ortho
.mtx
.p
);
109 ortho
.mtx
.p
[0][0] = 2.0f
* rl
;
110 ortho
.mtx
.p
[1][1] = 2.0f
* tb
;
111 ortho
.mtx
.p
[3][0] = (fr
+ fl
) * -rl
;
112 ortho
.mtx
.p
[3][1] = (ft
+ fb
) * -tb
;
113 ortho
.mtx
.p
[3][3] = 1.0f
;
114 m4x3_identity( ortho
.transform
);
115 camera_update_view( &ortho
);
116 m4x4_mul( ortho
.mtx
.p
, ortho
.mtx
.v
, ortho
.mtx
.pv
); /* HACK */
117 camera_finalize( &ortho
);
121 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, &ortho
);
122 mesh_bind( &gui
.icons_mesh
);
125 m4x3_identity( mmdl
);
126 shader_model_font_uMdl( mmdl
);
128 glActiveTexture( GL_TEXTURE0
);
129 glBindTexture( GL_TEXTURE_2D
, gui
.icons_texture
);
130 shader_model_font_uTexMain( 0 );
132 for( u32 i
=0; i
<gui
.icon_draw_count
; i
++ ){
133 struct icon_call
*call
= &gui
.icon_draw_buffer
[i
];
135 if( call
->colour_changed
)
136 shader_model_font_uColour( call
->colour
);
138 shader_model_font_uOffset( call
->location
);
140 mdl_submesh
*sm
= gui
.icons
[ call
->icon
];
142 mdl_draw_submesh( sm
);
145 gui
.icon_draw_count
= 0;
149 gui
.factive
= vg_lerpf( gui
.factive
, gui
.helper_count
?1.0f
:0.0f
,
150 vg
.time_frame_delta
*2.0f
);
152 if( gui
.factive
> 0.01f
){
153 /* draw bottom bar */
155 glDisable(GL_DEPTH_TEST
);
156 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
157 glBlendEquation(GL_FUNC_ADD
);
159 shader_blitcolour_use();
160 shader_blitcolour_uColour( (v4f
){ 0.0f
, 0.0f
, 0.0f
, gui
.factive
*0.8f
} );
164 f64 loc_t
= (vg
.time_real
- gui
.location_time
) / 5.0;
165 if( (loc_t
< 1.0) && (gui
.location_time
!= 0.0) ){
166 /* yep this code is a mess, i dont care anymore */
168 glDisable(GL_DEPTH_TEST
);
169 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
170 glBlendEquation(GL_FUNC_ADD
);
172 f32 t
= 1.0f
-vg_minf(1.0f
,vg_minf(loc_t
*20.0f
,2.0f
-loc_t
*2.0f
)),
173 o
= 1.0f
-t
*t
*(2.0f
-t
);
175 shader_blitcolour_use();
176 shader_blitcolour_uColour( (v4f
){ 0.0f
, 0.0f
, 0.0f
, o
*0.5f
} );
180 scale
= dy
*0x1p
-4f
*0.5f
;
182 m3x3_identity( mmdl
);
183 m3x3_scale( mmdl
, (v3f
){scale
,scale
,scale
} );
186 f32 pad
= dy
*0x1p
-4f
*0.125f
;
187 f32 w
= font3d_string_width( 2, gui
.location
);
189 mmdl
[3][0] = fr
*0.5f
- w
*scale
*0.5f
;
190 mmdl
[3][1] = 0.3f
*ft
+pad
*2.0f
;
192 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, &ortho
);
193 shader_model_font_uColour( (v4f
){1.2f
,1.2f
,1.2f
,o
} );
194 font3d_simple_draw( 2, gui
.location
, &ortho
, mmdl
);
197 font3d_bind( &gui
.font
, k_font_shader_default
, 0, NULL
, &ortho
);
200 scale
= dy
*0x1p
-4f
*0.75f
;
202 m3x3_identity( mmdl
);
203 m3x3_scale( mmdl
, (v3f
){scale
,scale
,scale
} );
206 float pad
= dy
*0x1p
-4f
*0.125f
;
207 mmdl
[3][0] = pad
*2.0f
;
210 for( u32 i
=0; i
<gui
.helper_count
; i
++ ){
211 struct gui_helper
*helper
= &gui
.helpers
[i
];
213 font3d_setcolour( (v4f
){1.0f
,1.0f
,1.0f
,1.0f
} );
214 font3d_simple_draw( 2, helper
->bindstr
, &ortho
, mmdl
);
216 const char *make_smaller
= "\x02\xaf\x03 ";
217 font3d_draw( make_smaller
);
218 font3d_draw( helper
->text
);
220 float w
= gui_font3d
.offset
[0]+1.0f
;
221 mmdl
[3][0] += w
*scale
;
224 gui
.helper_count
= 0;
227 static int gui_location_print_ccmd( int argc
, const char *argv
[] ){
231 vg_strnull( &str
, new_loc
, 64 );
232 for( int i
=0; i
<argc
; i
++ ){
233 vg_strcat( &str
, argv
[i
] );
234 vg_strcat( &str
, " " );
236 if( !strcmp(gui
.location
,new_loc
) ) return 0;
237 vg_strncpy( new_loc
, gui
.location
, 64, k_strncpy_always_add_null
);
238 gui
.location_time
= vg
.time_real
;
243 static int gui_showtrick_ccmd( int argc
, const char *argv
[] ){
245 enum guitrick_type type
= k_guitrick_type_none
;
246 if( !strcmp( argv
[0], "pump" ) ) type
= k_guitrick_type_pump
;
247 else if( !strcmp( argv
[0], "flip" ) ) type
= k_guitrick_type_backflip
;
248 else if( !strcmp( argv
[0], "ollie" ) ) type
= k_guitrick_type_ollie
;
249 else if( !strcmp( argv
[0], "trick" ) ) type
= k_guitrick_type_trick
;
250 else if( !strcmp( argv
[0], "misc" ) ) type
= k_guitrick_type_isc
;
252 gui
.trick_type
= type
;
253 v3_copy( localplayer
.rb
.co
, gui
.trick_co
);
259 static void gui_draw_icon( enum gui_icon icon
, v2f co
, f32 size
){
260 if( gui
.icon_draw_count
== vg_list_size(gui
.icon_draw_buffer
) )
263 struct icon_call
*call
= &gui
.icon_draw_buffer
[ gui
.icon_draw_count
++ ];
266 call
->location
[0] = co
[0] * (f32
)vg
.window_x
;
267 call
->location
[1] = co
[1] * (f32
)vg
.window_y
;
268 call
->location
[2] = 0.0f
;
269 call
->location
[3] = size
* (f32
)vg
.window_x
;
271 v4_copy( gui
.cur_icon_colour
, call
->colour
);
272 call
->colour_changed
= gui
.colour_changed
;
273 gui
.colour_changed
= 0;
276 static void gui_icon_setcolour( v4f colour
){
277 gui
.colour_changed
= 1;
278 v4_copy( colour
, gui
.cur_icon_colour
);
281 static mdl_submesh
*gui_find_icon( const char *name
){
282 mdl_mesh
*mesh
= mdl_find_mesh( &gui
.model_icons
, name
);
284 if( mesh
->submesh_count
){
285 return mdl_arritm( &gui
.model_icons
.submeshs
, mesh
->submesh_start
);
292 static void gui_init(void){
293 font3d_load( &gui
.font
, "models/rs_font.mdl", vg_mem
.rtmemory
);
294 vg_console_reg_cmd( "gui_location", gui_location_print_ccmd
, NULL
);
295 vg_console_reg_cmd( "showtrick", gui_showtrick_ccmd
, NULL
);
298 void *alloc
= vg_mem
.rtmemory
;
299 mdl_open( &gui
.model_icons
, "models/rs_icons.mdl", alloc
);
300 mdl_load_metadata_block( &gui
.model_icons
, alloc
);
302 gui
.icons
[ k_gui_icon_tick
] = gui_find_icon( "icon_tick" );
303 gui
.icons
[ k_gui_icon_exclaim
] = gui_find_icon( "icon_exclaim" );
304 gui
.icons
[ k_gui_icon_board
] = gui_find_icon( "icon_board" );
305 gui
.icons
[ k_gui_icon_world
] = gui_find_icon( "icon_world" );
306 gui
.icons
[ k_gui_icon_rift
] = gui_find_icon( "icon_rift" );
307 gui
.icons
[ k_gui_icon_rift_run
] = gui_find_icon( "icon_rift_run" );
308 gui
.icons
[ k_gui_icon_friend
] = gui_find_icon( "icon_friend" );
310 vg_linear_clear( vg_mem
.scratch
);
311 if( !mdl_arrcount( &gui
.model_icons
.textures
) )
312 vg_fatal_error( "No texture in menu file" );
313 mdl_texture
*tex0
= mdl_arritm( &gui
.model_icons
.textures
, 0 );
314 void *data
= vg_linear_alloc( vg_mem
.scratch
, tex0
->file
.pack_size
);
315 mdl_fread_pack_file( &gui
.model_icons
, &tex0
->file
, data
);
316 vg_tex2d_load_qoi_async( data
, tex0
->file
.pack_size
,
317 VG_TEX2D_LINEAR
|VG_TEX2D_CLAMP
,
318 &gui
.icons_texture
);
320 mdl_async_load_glmesh( &gui
.model_icons
, &gui
.icons_mesh
);
321 mdl_close( &gui
.model_icons
);