Use a clicky clicky gui for the boardshop when in desktop mode
authorhgn <hgodden00@gmail.com>
Mon, 24 Feb 2025 19:44:52 +0000 (19:44 +0000)
committerhgn <hgodden00@gmail.com>
Mon, 24 Feb 2025 19:44:52 +0000 (19:44 +0000)
content_skaterift/maps/dev_heaven/main.mdl
skaterift_blender/sr_main.py
skaterift_blender/sr_mdl.py
src/ent_skateshop.c
src/entity.h
src/skaterift.c
src/world.c
src/world.h

index 9e76a375240cf1f563d821c8c5ae82168683a2af..b35053a5dbcea29ae24d83bed5300eb3363641b4 100644 (file)
Binary files a/content_skaterift/maps/dev_heaven/main.mdl and b/content_skaterift/maps/dev_heaven/main.mdl differ
index 211a8dc704db0657665241186c9a9f5b493d0dc4..b4662bcdde500b28017c27cef0054c4e46f1d42e 100644 (file)
@@ -408,7 +408,8 @@ class ent_traffic(Structure):
 class ent_skateshop_characters(Structure):
 #{
    _fields_ = [("id_display",c_uint32),
-               ("id_info",c_uint32)]
+               ("id_info",c_uint32),
+               ("id_rack",c_uint32)]
 #}
 class ent_skateshop_boards(Structure):
 #{
index 37a7ca1891bedd58b006bd693b62c48358a29237..850a0660e12f397b85d98418592cd856962c7f9a 100644 (file)
@@ -769,6 +769,7 @@ def _mdl_compiler_compile_entities():
                charshop = skateshop._anonymous_union.character
                charshop.id_display = sr_entity_id( obj_data.mark_display )
                charshop.id_info = sr_entity_id( obj_data.mark_info )
+               charshop.id_rack = sr_entity_id( obj_data.mark_rack )
             #}
             elif skateshop.type == 2:#{
                worldshop = skateshop._anonymous_union.worlds
index 04d0a9f7828945fc2c014f9a486399a94e094acd..7ba0762b5e7271ac6867a8ab2e316608a83994d5 100644 (file)
@@ -227,6 +227,26 @@ static void skateshop_playermod( bool immobile )
    srinput.state = k_input_state_resume;
 }
 
+static void skateshop_accept_board( u16 cache_id )
+{
+   vg_info( "chose board from skateshop (%u)\n", _skateshop.selected_board_id );
+   addon_cache_unwatch( k_addon_type_board, localplayer.board_view_slot );
+   addon_cache_watch( k_addon_type_board, cache_id );
+   localplayer.board_view_slot = cache_id;
+   network_send_item( k_netmsg_playeritem_board );
+   gui_helper_reset( k_gui_helper_mode_clear );
+   skateshop_playermod( 0 );
+   _skateshop.open = 0;
+}
+
+static void skateshop_accept_playermodel(void)
+{
+   addon_reg *addon = get_addon_from_index( k_addon_type_player, _skateshop.selected_player_id, 0, ADDON_REG_HIDDEN );
+   u32 real_id = get_index_from_addon( k_addon_type_player, addon,0,0 );
+   player__use_model( real_id );
+   network_send_item( k_netmsg_playeritem_player );
+}
+
 void ent_skateshop_update(void)
 {
    if( _world.event != k_world_event_shop )
@@ -240,12 +260,7 @@ void ent_skateshop_update(void)
       if( button_down( k_srbind_mback ) )
       {
          _skateshop.open = 0;
-
-         if( shop->type == k_skateshop_type_charshop )
-            network_send_item( k_netmsg_playeritem_player );
-
          gui_helper_reset( k_gui_helper_mode_clear );
-
          skateshop_playermod( 0 );
          srinput.state = k_input_state_resume;
          return;
@@ -299,28 +314,20 @@ void ent_skateshop_update(void)
                _skateshop.selected_board_id --;
          }
 
-         u32 valid_count = addon_count( k_addon_type_board, 0,0 );
          if( button_down( k_srbind_mright ) )
          {
+            u32 valid_count = addon_count( k_addon_type_board, 0,0 );
             if( _skateshop.selected_board_id+1 < valid_count )
                _skateshop.selected_board_id ++;
          }
 
          u32 npage = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
-
          if( opage != npage )
             skateshop_update_viewpage();
+
          else if( cache_id && button_down( k_srbind_maccept ))
          {
-            vg_info( "chose board from skateshop (%u)\n", _skateshop.selected_board_id );
-
-            addon_cache_unwatch( k_addon_type_board, localplayer.board_view_slot );
-            addon_cache_watch( k_addon_type_board, cache_id );
-            localplayer.board_view_slot = cache_id;
-            network_send_item( k_netmsg_playeritem_board );
-            gui_helper_reset( k_gui_helper_mode_clear );
-            skateshop_playermod( 0 );
-            _skateshop.open = 0;
+            skateshop_accept_board( cache_id );
             return;
          }
       }
@@ -353,16 +360,10 @@ void ent_skateshop_update(void)
          }
 
          if( changed )
-         {
-            addon_reg *addon = get_addon_from_index( k_addon_type_player, _skateshop.selected_player_id,
-                                                     0, ADDON_REG_HIDDEN );
-            u32 real_id = get_index_from_addon( k_addon_type_player, addon,0,0 );
-            player__use_model( real_id );
-         }
+            skateshop_accept_playermodel();
 
          if( button_down( k_srbind_maccept ) )
          {
-            network_send_item( k_netmsg_playeritem_player );
             gui_helper_reset( k_gui_helper_mode_clear );
             skateshop_playermod( 0 );
             _skateshop.open = 0;
@@ -547,8 +548,7 @@ fade_out:;
       slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
    }
 
-   ent_marker *mark_info = af_arritm( &world->ent_marker, 
-                                        mdl_entity_id_id(shop->boards.id_info));
+   ent_marker *mark_info = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_info));
    m4x3f mtext, mrack;
    mdl_transform_m4x3( &mark_info->transform, mtext );
    mdl_transform_m4x3( &mark_rack->transform, mrack );
@@ -841,3 +841,129 @@ entity_call_result ent_skateshop_call( world_instance *world, ent_call *call )
    else 
       return k_entity_call_result_unhandled;
 }
+
+void ent_skateshop_gui( ui_context *ctx )
+{
+   if( _world.event == k_world_event_shop )
+   {
+      if( _skateshop.open )
+      {
+         if( vg_input.display_input_method != k_input_method_kbm )
+            return;
+
+         ent_skateshop *shop = _skateshop.current_shop;
+         if( shop->type != k_skateshop_type_boardshop && shop->type != k_skateshop_type_charshop )
+            return;
+
+         ui_capture_mouse(ctx, 1);
+         world_instance *world = &_world.main;
+         ent_marker *rack_marker = af_arritm( &world->ent_marker, mdl_entity_id_id(shop->boards.id_rack) );
+         m4x3f mmdl;
+         mdl_transform_m4x3( &rack_marker->transform, mmdl );
+         vg_camera *cam = &g_render.cam;
+
+         v4f handles[3] = {{ 2.0f, 0.0f, 0.0f, 1.0f },{ -2.0f, 0.0f, 0.0f, 1.0f },{0,0,0,1}};
+
+         if( shop->type == k_skateshop_type_charshop )
+         {
+            handles[0][0] = -1.2f;
+            handles[1][0] =  1.2f;
+         }
+
+         for( u32 i=0; i<3; i ++ )
+         {
+            m4x3_mulv( mmdl, handles[i], handles[i] );
+            m4x4_mulv( cam->mtx.pv, handles[i], handles[i] );
+            v2_divs( handles[i], handles[i][3], handles[i] );
+            v2_muladds( (v2f){0.5f,0.5f}, handles[i],  0.5f, handles[i] );
+            handles[i][1] = 1.0f - handles[i][1];
+            v2_mul( (v2f){ vg.window_x, vg.window_y }, handles[i], handles[i] );
+         }
+
+         ui_px r = 24;
+         ui_rect left_box  = { handles[0][0] - r, handles[0][1] - r, r*2, r*2 },
+                 right_box = { handles[1][0] - r, handles[1][1] - r, r*2, r*2 },
+                 accept_box= { handles[2][0] - 64, handles[2][1] + 200, 128, 48 };
+
+         ctx->font = &vgf_default_title;
+
+         u32 original_page;
+         bool changed_playermodel = 0;
+
+         if( shop->type == k_skateshop_type_boardshop )
+            original_page = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
+
+         if( menu_button_rect( ctx, left_box, 0, 1, "<" ) )
+         {
+            if( shop->type == k_skateshop_type_boardshop )
+            {
+               if( _skateshop.selected_board_id > 0 )
+                  _skateshop.selected_board_id --;
+            }
+            else if( shop->type == k_skateshop_type_charshop )
+            {
+               u32 valid_count = addon_count( k_addon_type_player, 0, ADDON_REG_HIDDEN );
+
+               if( _skateshop.selected_player_id > 0 )
+                  _skateshop.selected_player_id --;
+               else
+                  _skateshop.selected_player_id = valid_count-1;
+
+               changed_playermodel = 1;
+            }
+         }
+         if( menu_button_rect( ctx, right_box, 0,1, ">" ) )
+         {
+            if( shop->type == k_skateshop_type_boardshop )
+            {
+               u32 valid_count = addon_count( k_addon_type_board, 0,0 );
+               if( _skateshop.selected_board_id+1 < valid_count )
+                  _skateshop.selected_board_id ++;
+            }
+            else if( shop->type == k_skateshop_type_charshop )
+            {
+               u32 valid_count = addon_count( k_addon_type_player, 0, ADDON_REG_HIDDEN );
+               if( _skateshop.selected_player_id+1 < valid_count )
+                  _skateshop.selected_player_id ++;
+               else
+                  _skateshop.selected_player_id = 0;
+
+               changed_playermodel = 1;
+            }
+         }
+
+         if( shop->type == k_skateshop_type_boardshop )
+         {
+            u32 new_page = _skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
+            if( original_page != new_page )
+               skateshop_update_viewpage();
+         }
+         else if( shop->type == k_skateshop_type_charshop )
+         {
+            if( changed_playermodel )
+            {
+               skateshop_accept_playermodel();
+            }
+         }
+
+         if( menu_button_rect( ctx, accept_box, 0,1, "Pick" ) )
+         {
+            if( shop->type == k_skateshop_type_boardshop )
+            {
+               u16 cache_id = skateshop_selected_cache_id();
+               if( cache_id )
+                  skateshop_accept_board( cache_id );
+            }
+            else if( shop->type == k_skateshop_type_charshop )
+            {
+               _skateshop.open = 0;
+               gui_helper_reset( k_gui_helper_mode_clear );
+               skateshop_playermod( 0 );
+               srinput.state = k_input_state_resume;
+            }
+         }
+
+         ctx->font = &vgf_default_small;
+      }
+   }
+}
index 4d011c7dee34267ae1c1082bbdec77635e5e5fb7..c48db6be33702a9a897b0402aaa9434bee8c4af9 100644 (file)
@@ -353,7 +353,8 @@ struct ent_skateshop{
 
       struct{
          u32 id_display,
-             id_info;
+             id_info,
+             id_rack;
       }
       character;
 
index f4fa1e9b6f2ccb5af96e6121514a1dcd0d74f674..13b07717b68ebef3ee391220ad68b7d05918136a 100644 (file)
@@ -548,6 +548,7 @@ void vg_gui( ui_context *ctx )
    world_routes_imgui( ctx, world );
    skaterift_replay_imgui( ctx );
    workshop_form_gui( ctx );
+   world_gui( ctx, world );
 
    if( menu_viewing_map() )
    {
index bac09a9ce0ec4e135f1adfcf37f2b4ab2435116c..cb485dbc5a97405119afa8ea52f0894e4ee728a2 100644 (file)
@@ -47,6 +47,11 @@ void world_update( world_instance *world, v3f pos )
    ent_challenge_update();
 }
 
+void world_gui( ui_context *ctx, world_instance *world )
+{
+   ent_skateshop_gui( ctx );
+}
+
 bool world_set_event( enum world_event event )
 {
    if( _world.event == k_world_event_none )
index 9a5102124fe8e7a5b96d862922803069ebc2b5be..67a29ef669e283e51d09233433811775f58b4b35 100644 (file)
@@ -298,3 +298,4 @@ void world_update( world_instance *world, v3f pos );
 bool world_set_event( enum world_event activity );
 bool world_clear_event( enum world_event activity );
 void world_set_entity_driven_camera( vg_camera *cam );
+void world_gui( ui_context *ctx, world_instance *world );