Skip to content

Commit

Permalink
updated weapondrawer to support skin mode weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
Trylobot committed Jul 24, 2017
1 parent 77c5acb commit 66b5430
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 239 deletions.
9 changes: 5 additions & 4 deletions sf-ship-ed.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,11 @@ Function check_weapondrawer%(ed:TEditor, data:TData, sprite:TSprite)
End Function

Function updata_weapondrawermenu(ed:TEditor)
Local flag# = (ed.mode <> "string" ..
And ( (ed.program_mode = "ship" And ( ed.mode = "built_in_weapons" Or ed.mode = "weapon_slots") ) ..
Or (ed.program_mode = "variant" And ed.variant_hullMod_i = - 1 And ed.group_field_i = - 1)..
Or (ed.program_mode = "weapon") ) )
Local flag# =(ed.mode <> "string" ..
And ((ed.program_mode = "ship" And (ed.mode = "built_in_weapons" Or ed.mode = "weapon_slots") ) ..
Or (ed.program_mode = "skin" And (ed.mode = "changeremove_weaponslots" Or ed.mode = "addremove_builtin_weapons")) ..
Or (ed.program_mode = "variant" And ed.variant_hullMod_i = - 1 And ed.group_field_i = - 1) ..
Or (ed.program_mode = "weapon") ) )
If MenuEnabled(animateMenu[MENU_ANIMATE]) <> flag
For Local i# = 0 Until animateMenu.length
animateMenu[i].SetEnabled(flag)
Expand Down
13 changes: 13 additions & 0 deletions src/TData.type.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,19 @@ Type TData
EndIf
EndMethod

' returns the base hull weapon slot (by index), merged with the skin data for the same slot
' if skin removes slot, then null
Method get_merged_skin_weaponslot:TStarfarerShipWeapon( slot% )
If skin_removes_builtin_weapon( slot ) Then Return Null ' it doesn't exist anymore
Local base_weaponslot:TStarfarerShipWeapon = ship.weaponSlots[slot]
Local skin_weaponslot:TStarfarerShipWeaponChange = TStarfarerShipWeaponChange( skin.weaponSlotChanges.ValueForKey( base_weaponslot.id ))
If skin_weaponslot
Return skin_weaponslot.Overlay( base_weaponslot )
Else
Return base_weaponslot
EndIf
EndMethod

'----
'requires subsequent call to update_skin()
Method set_skin_weapon_slot_location( slot%, img_x#,img_y#, mirror%=False )
Expand Down
58 changes: 40 additions & 18 deletions src/TModalSetSkin.type.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -646,17 +646,25 @@ Type TModalSetSkin Extends TSubroutine
SetAlpha( 1 )
EndMethod

Method draw_builtin_weapon_slot_textboxes( ed:TEditor, data:TData, sprite:TSprite, slot% )
Method draw_skin_builtin_weapon_slot_textboxes( ed:TEditor, data:TData, sprite:TSprite, slot% )
Local xy#[] = data.get_skin_weapon_slot_location( slot )
Local sz$ = data.get_skin_weapon_slot_size( slot )
Local tp$ = data.get_skin_weapon_slot_type( slot )
Local mt$ = data.get_skin_weapon_slot_mount( slot )
Local slot_id$ = data.ship.weaponSlots[slot].id
Local wpid$ = data.get_skin_equipped_builtin_weapon_id( slot_id )
draw_builtin_weapon_slot_info( ed,data,sprite,, xy,sz,tp,mt )
'If weapon_lock_i = -1
Local slot_id$ = data.ship.weaponSlots[slot].id
Local wpid$ = data.get_skin_equipped_builtin_weapon_id( slot_id )
draw_builtin_assigned_weapon_info( ed,data,sprite,, xy,wpid )
'EndIf
draw_builtin_assigned_weapon_info( ed,data,sprite,, xy,wpid )
EndMethod

Method draw_skin_builtin_weapon_mount( ed:TEditor, data:TData, sprite:TSprite, slot% )
If Not data.ship.center Then Return
Local xy#[] = data.get_skin_weapon_slot_location( slot )
Local wx# = sprite.sx + ( xy[0] + data.ship.center[1])*sprite.Scale
Local wy# = sprite.sy + (-xy[1] + data.ship.center[0])*sprite.Scale
Local angle# = data.get_skin_weapon_slot_angle( slot )
Local arc# = data.get_skin_weapon_slot_arc( slot )
draw_weapon_mount( wx,wy, angle,arc, True, 8,16,24, $FFFFFF,$000000 )
EndMethod

Method draw_builtin_weapon_info( ed:TEditor, data:TData, sprite:TSprite )
Expand All @@ -667,23 +675,37 @@ Type TModalSetSkin Extends TSubroutine
Local focus_i% = weapon_lock_i
If focus_i = -1 Then focus_i = data.find_nearest_skin_weapon_slot( img_x,img_y )
'---------------
' text boxes (normal)
' text boxes
SetRotation( 0 )
SetScale( 1, 1 )
SetAlpha( Min( 0.4, 0.5*(sprite.scale/3.0) ))
If weapon_lock_i = -1
For Local slot% = 0 Until data.ship.weaponSlots.Length
draw_builtin_weapon_slot_textboxes( ed,data,sprite, slot )
Next
EndIf
' text boxes (for focused slot, or locked-on slot)
SetAlpha( 1 )
draw_builtin_weapon_slot_textboxes( ed,data,sprite, focus_i )
For Local slot% = 0 Until data.ship.weaponSlots.Length
REM
////////////////////////////////
TODO: create a new indicator for when a built-in weapon slot from the base hull
has been removed in the skin; perhaps the words "slot removed" would be enough?
perhaps a new color, or an "X" icon on the slot's position.
////////////////////////////////
ENDREM
If slot = focus_i
SetAlpha( 0.8 )
Else
SetAlpha( Min( 0.4, 0.5*(sprite.scale/3.0) ))
EndIf
If slot = weapon_lock_i Or weapon_lock_i = -1
draw_skin_builtin_weapon_slot_textboxes( ed,data,sprite, slot )
EndIf
Next
'---------------
' weapon icons
For Local slot% = 0 Until data.ship.weaponSlots.Length
If weapon_lock_i <> -1 And weapon_lock_i <> slot Then Continue ' selective rendering when locked

If slot = focus_i
SetAlpha( 0.8 )
Else
SetAlpha( 0.4 )
EndIf
If slot = weapon_lock_i Or weapon_lock_i = -1
draw_skin_builtin_weapon_mount( ed,data,sprite, slot )
EndIf
Next
EndMethod

Expand Down
12 changes: 12 additions & 0 deletions src/TStarfarerShipWeaponChange.type.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ Type TStarfarerShipWeaponChange Extends TStarfarerShipWeapon
type_ = __type_
End Method

Method Overlay:TStarfarerShipWeapon( base:TStarfarerShipWeapon )
Local merged:TStarfarerShipWeapon = base.Clone()
If angle <> __angle Then merged.angle = angle
If arc <> __arc Then merged.arc = arc
If locations <> __locations Then merged.locations = locations
If position <> __position Then merged.position = position
If mount <> __mount Then merged.mount = mount
If size <> __size Then merged.size = size
If type_ <> __type_ Then merged.type_ = type_
Return merged
EndMethod

End Type
Loading

0 comments on commit 66b5430

Please sign in to comment.