Skip to content

Commit

Permalink
#14: Improve weapon UI and other display settings + deprecated code c…
Browse files Browse the repository at this point in the history
…lean up
  • Loading branch information
Danil Ko committed Sep 13, 2021
1 parent d5c7743 commit f13cb58
Show file tree
Hide file tree
Showing 23 changed files with 283 additions and 570 deletions.
22 changes: 8 additions & 14 deletions GameStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private void noSet(float rate) { }

public void endGameScreen()
{
// In menu, enable mouse
Input.SetMouseMode(Input.MouseMode.Visible);
GetTree().ChangeScene(endResultScreen);
}

Expand All @@ -116,33 +118,25 @@ public void restart()

public void EnterLobbyScreen()
{
// In menu, enable mouse
Input.SetMouseMode(Input.MouseMode.Visible);
current_level = 1;
GetTree().ChangeScene(levels[current_level]);
}

public void EnterTitleScreen()
{
// In menu, enable mouse
Input.SetMouseMode(Input.MouseMode.Visible);
current_level = 0;
GetTree().ChangeScene(levels[current_level]);
}

public void EnterNetworkLevel()
{
current_level = 2;
// In game, disable mouse
Input.SetMouseMode(Input.MouseMode.Hidden);
GetTree().ChangeScene(levels[current_level]);
}

public void next_level()
{
current_level += 1;
if (current_level < levels.Length)
{
GetTree().ChangeScene(levels[current_level]);
}
else
{
restart();
}

}
}
1 change: 1 addition & 0 deletions agents/AIAgent.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MaxSpeed = 300
MaxHealth = 100
RotationSpeed = 5.0
MaxEnergy = 100
DetectionRadius = 2000.0
TurretSpeed = 10
DetectRadius = 2000.0

Expand Down
25 changes: 18 additions & 7 deletions agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public virtual void changeWeapon(int weaponIndex, Weapon.WeaponOrder weaponOrder
// Caculate actual index base on availble weapon
weaponIndex = weaponIndex % weapons.Count;

Weapon currentWeapon = ((Weapon)weapons[CurrentWeaponIndex[weaponOrder]]);
int originalWeaponIndex = CurrentWeaponIndex[weaponOrder];

Weapon currentWeapon = ((Weapon)weapons[originalWeaponIndex]);

if (currentWeapon != null)
{
Expand All @@ -194,14 +196,23 @@ public virtual void changeWeapon(int weaponIndex, Weapon.WeaponOrder weaponOrder
{
ConnectWeapon(currentWeapon, weaponOrder);

EmitSignal(nameof(WeaponChangeSignal), CurrentInventory.GetItems()[CurrentInventory.GetEquipItemIndex(weaponOrder, weaponIndex)], weaponOrder);
// This is re-click, no need to submit signal
if(originalWeaponIndex != weaponIndex)
{
EmitSignal(nameof(WeaponChangeSignal), CurrentInventory.GetItems()[CurrentInventory.GetEquipItemIndex(weaponOrder, weaponIndex)], weaponOrder, weaponIndex);
}

// Emit signal to update info
currentWeapon.EmitSignal(nameof(Weapon.AmmoChangeSignal), currentWeapon.GetAmmo(), currentWeapon.GetMaxAmmo(), weaponOrder);
}
else
{
EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder);

// This is re-click, no need to submit signal
if(originalWeaponIndex != weaponIndex)
{
EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder, weaponIndex);
}
}
}

Expand Down Expand Up @@ -296,24 +307,24 @@ public Node2D GetWeaponsHolder(Weapon.WeaponOrder weaponOrder)
/**
Unequip weapon at given weapon order's given index
**/
public void UnequipWeapon(Weapon.WeaponOrder weaponOrder, int index)
public void UnequipWeapon(Weapon.WeaponOrder weaponOrder, int weaponIndex)
{
Godot.Collections.Array<Weapon> weapons = GetWeapons(weaponOrder);

Weapon weapon = (Weapon)weapons[index];
Weapon weapon = (Weapon)weapons[weaponIndex];

if (weapon != null)
{
Node2D weaponHolder = GetWeaponsHolder(weaponOrder);
weaponHolder.RemoveChild(weapon);
// Null the weapon
weapons[index] = null;
weapons[weaponIndex] = null;
DisconnectWeapon(weapon, weaponOrder);
// Empty out weapon
weapon.Deinitialize();
}

EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder);
EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder, weaponIndex);
}

public void SetCurrentTeam(Team.TeamCode inputTeamCode)
Expand Down
16 changes: 5 additions & 11 deletions agents/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public void SetHUD(HUD hud, InventoryManager _inventoryManager)
{
ConnectWeapon(weapon, weaponOrder);

EmitSignal(nameof(WeaponChangeSignal), CurrentInventory.GetItems()[CurrentInventory.GetEquipItemIndex(weaponOrder, GetCurrentWeaponIndex(weaponOrder))], weaponOrder);
EmitSignal(nameof(WeaponChangeSignal), CurrentInventory.GetItems()[CurrentInventory.GetEquipItemIndex(weaponOrder, GetCurrentWeaponIndex(weaponOrder))], weaponOrder, index);
// Emit signal to update info
weapon.EmitSignal(nameof(Weapon.AmmoChangeSignal), weapon.GetAmmo(), weapon.GetMaxAmmo(), weaponOrder);
}
else
{
EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder);
EmitSignal(nameof(WeaponChangeSignal), null, weaponOrder, index);
}
}

Expand All @@ -88,7 +88,7 @@ public void SetHUD(HUD hud, InventoryManager _inventoryManager)


// Setup Inventory UI
_inventoryUI = (InventoryUI)_hud.GetNode("controlGame/InventoryUI");
_inventoryUI = (InventoryUI)_hud.GetNode("GameControl/InventoryUI");
_inventoryUI.Initialize(_inventoryManager, CurrentInventory);

if (!_teamMapAI.IsConnected(nameof(TeamMapAI.TeamUnitUsageAmountChangeSignal), _hud, nameof(HUD.UpdateTeamUnitUsageAmount)))
Expand Down Expand Up @@ -144,14 +144,8 @@ public void gatherInput(float delta)
{
if (Input.IsActionJustReleased("inventory"))
{
if (!_inventoryUI.Visible)
{
_inventoryUI.PopupCentered();
}
else
{
_inventoryUI.Hide();
}
// Show UI if UI is not visible, and also hide UI if UI is already visible
_inventoryUI.Activate(! _inventoryUI.Visible);
}


Expand Down
1 change: 1 addition & 0 deletions ai/AI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ one_shot = true
autostart = true

[node name="PathLine" type="Line2D" parent="."]
visible = false
width = 2.0
default_color = Color( 1, 0.4, 0.498039, 1 )

Expand Down
4 changes: 2 additions & 2 deletions environments/Obstacle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void explode()
//remainParticles.GlobalPosition = this.GlobalPosition;
//GetParent().GetParent().GetNode("RemainEffectManager").AddChild(remainParticles);

AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
audioManager.playSoundEffect(explosionMusicClip);
//AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
// audioManager.playSoundEffect(explosionMusicClip);
}

private void _OnExplosionAnimationFinished()
Expand Down
1 change: 1 addition & 0 deletions godot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="ui\ScreenIndicator.cs" />
<Compile Include="ui\Settings.cs" />
<Compile Include="ui\TeamSettingPanel.cs" />
<Compile Include="ui\WeaponControl.cs" />
<Compile Include="ui\WeaponSlotPanel.cs" />
<Compile Include="weapons\RemoteWeapon.cs" />
<Compile Include="weapons\RemoteWeaponController.cs" />
Expand Down
8 changes: 1 addition & 7 deletions map/GameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public override void _Ready()

InitializeHUD();

Input.SetCustomMouseCursor(GD.Load("res://assets/ui/blue_cross.png"), Input.CursorShape.Arrow, new Vector2(16, 16));

_initializeNetwork();
_initailizeGameTimer();
}
Expand All @@ -155,7 +153,7 @@ protected void InitializeCamera()
protected void InitializeHUD()
{
_hud = (HUD)GetNode("HUD");
_miniMap = (MiniMap)_hud.GetNode("controlGame/MiniMap");
_miniMap = (MiniMap)_hud.GetNode("GameControl/MiniMap");
_popUpMessage = (PopUpMessage)_hud.GetNode("PopUpMessage");

_miniMap.Iniitialize(CapaturableBaseManager);
Expand Down Expand Up @@ -189,12 +187,8 @@ private void _initializeNetwork()
// Update network flow
this.Connect(nameof(NeworkRateUpdateSignal), _hud, "_onNetworkRateUpdate");
this.Connect(nameof(PlayerDefeatedSignal), _hud, nameof(HUD.OnPlayerDefeated));
this.Connect(nameof(Network.PlayerListChangedSignal), _hud, "onPlayerListChanged");
this.Connect(nameof(WaitingPeriodSignal), _hud, "_onUpdateTimer");
this.Connect(nameof(PlayerCreateSignal), _hud, nameof(HUD.OnPlayerCreated));

// Update playerlist
EmitSignal(nameof(Network.PlayerListChangedSignal));
}

private void _initailizeGameTimer()
Expand Down
15 changes: 12 additions & 3 deletions map/GameWorld.tscn

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions map/SimulateGameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class SimulateGameWorld : GameWorld

public override void _Ready()
{

GameStates = (GameStates)GetNode("/root/GAMESTATES");
// Clean up previous setup state
GameStates.SetTeamMapAISettings(null);
Expand Down
2 changes: 1 addition & 1 deletion map/SimulateGameWorld.tscn

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion network/Lobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void enterWaitingRoom()

private void onReadyGameStart()
{
((GameStates)GetNode("/root/GAMESTATES")).next_level();
((GameStates)GetNode("/root/GAMESTATES")).EnterNetworkLevel();
}

private void _networkFail(String message)
Expand Down
4 changes: 2 additions & 2 deletions projectiles/Missle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public override void Explode()
AgentExplosionParticle explosion = (AgentExplosionParticle)GetNode("AgentExplosionParticle");
explosion.SetTrigger(true);

AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
audioManager.playSoundEffect(MusicHitClip);
//AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
//audioManager.playSoundEffect(MusicHitClip);
}

protected override void ComputeDamage()
Expand Down
2 changes: 1 addition & 1 deletion singletons/audios/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class AudioManager : Node

private float _defaultVolumeDb = -50.0f;

AudioStreamPlayer[] soundEffectPlayers = new AudioStreamPlayer[100];
AudioStreamPlayer[] soundEffectPlayers = new AudioStreamPlayer[1000];

AudioStream musicHitClip = (AudioStream)GD.Load("res://assets/sounds/bullethit.wav");

Expand Down
16 changes: 13 additions & 3 deletions terrain/terrain_tiles.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[gd_resource type="TileSet" load_steps=3 format=2]
[gd_resource type="TileSet" load_steps=4 format=2]

[ext_resource path="res://assets/terrainTiles_retina.png" type="Texture" id=1]

[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 0, 0, 128, 0, 128, 128, 0, 128 )
polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]

[sub_resource type="ConvexPolygonShape2D" id=2]
points = PoolVector2Array( 0, 0, 128, 0, 128, 128, 0, 128 )

[resource]
0/name = ""
0/texture = ExtResource( 1 )
Expand Down Expand Up @@ -718,7 +721,14 @@ polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
50/navigation_offset = Vector2( 0, 0 )
50/shape_offset = Vector2( 0, 0 )
50/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
50/shape = SubResource( 2 )
50/shape_one_way = false
50/shape_one_way_margin = 0.0
50/shapes = [ ]
50/shape_one_way_margin = 1.0
50/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 2 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
50/z_index = 0
2 changes: 1 addition & 1 deletion ui/EndGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ private void btContinue()
network.closeServer();
}

gameStates.next_level();
gameStates.EnterTitleScreen();
}
}
Loading

0 comments on commit f13cb58

Please sign in to comment.