Author | Message |
Mario
Posts: 703
Location: Bulgaria Sofia Occupation: Fast way Age: 121 V$: |
#1 2012-05-13 19:26 |
I've made a new parent java for a Franco's brakes and now they have adjustable caliper and adjustable offset positions.
Functions work good. But if i adjust one of the functions, other get back in defaults. Here the code; *** package java.game.parts.disc_brake_pack; import java.render.osd.*; import java.io.*; import java.util.*; import java.util.resource.*; import java.game.*; import java.game.parts.rgearpart.reciprocatingrgearpart.brake.*; public class DiscExtend extends DiscBrake { float rads, degs, f_offset, default_offset, old_offset; public DiscExtend( int id ) { super( id ); carCategory = COMMON; name = "Universal Caliper"; description = "Paintable"; value = tHUF2USD(40.000); brand_new_prestige_value = 50.00; rads = 0.0; degs = rad2deg(rads); setSlotPos( 1, null, new Ypr(0.000,rads,0.000) ); } public void load( File saveGame ) { super.load( saveGame ); int save_ver = saveGame.readInt(); if (save_ver >= 1) { rads = saveGame.readFloat(); f_offset = saveGame.readFloat(); setSlotPos( 1, new Vector3(f_offset/1000.0, 0, 0), null ); } } public void save( File saveGame ) { super.save( saveGame ); int save_ver = 2; saveGame.write( save_ver ); if (save_ver >= 1) { saveGame.write( rads ); saveGame.write( f_offset ); } } float old_rads; public int isTuneable() { return true; } public void buildTuningMenu( Menu m ) { old_rads = rads; degs = rad2deg(rads); old_offset = f_offset; m.addItem( "Caliper position", 1, degs, -180.0, 180.0, 0.5+1, null ).printValue(" %1.1f degrees"); m.addItem( "Offset", 2, f_offset, -20.0, 40.0, 1.1, null ).printValue(" %1.0f" + " degrees"); m.addItem( "Reset to factory defaults", 0); //this should always be with cmd=0 } public void endTuningSession( int cancelled ) { if( cancelled ) { rads = old_rads; f_offset = old_offset; } else { if (rads != old_rads) GameLogic.spendTime(5*60); if (f_offset != old_offset) GameLogic.spendTime(5*60); getCar_LocalVersion(); if (the_car) the_car.forceUpdate(); } } public void handleMessage( Event m ) { if( m.cmd == 0 ) { rads = 0.0; f_offset = default_offset; m.gadget.osd.findGadget( this, 1 ).setValue( 0.0 ); setSlotPos( 1, null, new Ypr(0.000,rads,0.000) ); m.gadget.osd.findGadget( this, 2 ).setValue( default_offset ); setSlotPos( 1, new Vector3(f_offset/1000.0, 0, 0), null ); } else if( m.cmd == 1 ) { rads = deg2rad(((Slider)m.gadget).value); degs = ((Slider)m.gadget).value; ((Slider)m.gadget).changeVLabelText( Float.toString(degs, " %1.1f degrees")); setSlotPos( 1, null, new Ypr(0.000,rads,0.000) ); } else if( m.cmd == 2 ) { f_offset = ((Slider)m.gadget).value; ((Slider)m.gadget).changeVLabelText( Float.toString(f_offset, " %1.1f")); setSlotPos( 1, new Vector3(f_offset/1000.0, 0, 0), null ); } } public float rad2deg( float rad ) { return(rad * 180 / 3.141); } public float deg2rad( float deg ) { return(deg * 3.141 / 180); } public void updatevariables() { super.updatevariables(); setSlotPos( 1, null, new Ypr(0.000,rads,0.000) ); setSlotPos( 1, new Vector3(f_offset/1000.0, 0, 0), null ); } } Added 1 day later: I guess i'm doing it wrong in "public void load and save" This post was edited by Mario (2012-05-15 01:15, ago) |
|
|
|
Franco
Posts: 1082
Location: Argentina hmmmm Occupation: Franco Age: 32 V$: |
#2 2012-05-15 01:21 |
i think you forgot to add
default_offset = 0.0; f_offset = default_offset; at public DiscExtend( int id ) |
|
Mario
Posts: 703
Location: Bulgaria Sofia Occupation: Fast way Age: 121 V$: |
#3 2012-05-15 01:38 |
Nope it's the same, and i find one more problem in the disc rotate function when i adjust it and click ok it back is stock if i click cancel it save the position.Wow i'm doing it very wrong.
|
|
|