Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Buttons Dynamics fixed
Browse files Browse the repository at this point in the history
Disables robot action buttons if Climb has been started
fixes cube dropped text if item was picked and then deleted from events, leaving only a item dropped and no corresponding pick
  • Loading branch information
shreystechtips committed Feb 9, 2019
1 parent d1f02ee commit 8615101
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
4 changes: 1 addition & 3 deletions NRGScoutingApp/Pages/Matches/MatchEvents.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using System.ComponentModel;
using System.Linq;
using Data = System.Collections.Generic.KeyValuePair<string, string>;

namespace NRGScoutingApp
{
Expand Down Expand Up @@ -141,6 +138,7 @@ async void eventTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
else
{
removeAtIndex(index);
NewMatchStart.setItemToDefault = true;
}
}
else if (eventsList[index].eventName.Contains(ConstantVars.DROP_KEYWORD))
Expand Down
65 changes: 49 additions & 16 deletions NRGScoutingApp/Pages/Matches/NewMatchStart.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,35 @@ public NewMatchStart()
App.Current.SavePropertiesAsync();
NavigationPage.SetHasBackButton(this, false);
timerValueSetter();
setEventButtons(isTimerRunning);
}

private static int min = 0, sec = 0, ms = 0; //Values for Timer
public static int timerValue = 0;
private Boolean firstTimerStart = true;
private bool firstTimerStart = true;
public static int pickedTime = 0;
public static int droppedTime = 0;
int climbTime = 0;
public static Boolean cubeSetDrop = false;
private static Boolean isTimerRunning = false;
public static bool cubeSetDrop;
private static bool isTimerRunning;
public static bool setItemToDefault;
public static List<MatchFormat.Data> events = new List<MatchFormat.Data>();

protected override void OnAppearing()
{

if (cubeSetDrop)
{
cubePicked.Text = ConstantVars.ITEM_DROPPED_TEXT_LIVE;
cubePicked.Image = ConstantVars.ITEM_DROPPED_IMAGE_LIVE;
cubeSetDrop = false;
}
if (setItemToDefault) {
cubePicked.Text = ConstantVars.ITEM_PICKED_TEXT_LIVE;
cubePicked.Image = ConstantVars.ITEM_PICKED_IMAGE_LIVE;
setItemToDefault = false;
}
setClimbButton();
}

async void resetClicked(object sender, System.EventArgs e)
Expand All @@ -57,10 +66,11 @@ async void resetClicked(object sender, System.EventArgs e)
if (ensure == ConstantVars.YES)
{
events.Clear();
CubeDroppedDialog.saveEvents();
timeSlider.Value = 0;
App.Current.SavePropertiesAsync();
climbTime = 0;
await App.Current.SavePropertiesAsync();
}

}

async void startClicked(object sender, System.EventArgs e)
Expand Down Expand Up @@ -100,25 +110,17 @@ async void startClicked(object sender, System.EventArgs e)
await Task.Delay(ConstantVars.TIMER_INTERVAL_ANDROID);
Timer_Elapsed();
}
//Device.StartTimer(TimeSpan.FromMilliseconds(ConstantVars.TIMER_INTERVAL_ANDROID), () =>
//{
// if (timerValue >= ConstantVars.MATCH_SPAN_MS || !isTimerRunning)
// {
// startTimer.Text = ConstantVars.TIMER_START;
// return false;
// }
// Timer_Elapsed();
// return true;
//});
}

}
else if (isTimerRunning)
{
startTimer.Text = ConstantVars.TIMER_START;
isTimerRunning = false;

timeSlider.IsEnabled = true;
}
setEventButtons(isTimerRunning);
setClimbButton();
}
private void Timer_Elapsed()
{
Expand Down Expand Up @@ -183,6 +185,7 @@ void climbClicked(object sender, System.EventArgs e)
climbTime = (int)timerValue;
events.Add(new MatchFormat.Data { time = climbTime, type = (int)MatchFormat.ACTION.startClimb });
CubeDroppedDialog.saveEvents();
setClimbButton();
}
}

Expand Down Expand Up @@ -226,6 +229,23 @@ async void cubeClicked(object sender, System.EventArgs e)
}
}

//Sets buttons to not clickable if timer is/not running.
private void setEventButtons(bool setter)
{
climbStart.IsEnabled = setter;
cubePicked.IsEnabled = setter;
Console.WriteLine(cubePicked.IsEnabled);
if (setter && isTimerRunning) {
climbStart.BackgroundColor = Color.FromHex("fdad13");
cubePicked.BackgroundColor = Color.FromHex("fdad13");
}
else {
climbStart.BackgroundColor = Color.FromHex("ffcc6b");
cubePicked.BackgroundColor = Color.FromHex("ffcc6b");
}
}

//Sets the value of the time if app crashed or match was restored
private void timerValueSetter()
{
if (!App.Current.Properties.ContainsKey("lastItemPicked"))
Expand Down Expand Up @@ -255,7 +275,20 @@ private void timerValueSetter()
timerText.Text = timeToString((int)timerValue);
firstTimerStart = false;
}
}

//sets robot action buttons based on climb start
private void setClimbButton()
{
if (events.Exists(x => x.type == (int)MatchFormat.ACTION.startClimb))
{
setEventButtons(false);
}
else
{
setEventButtons(true);
climbTime = 0;
}
}

public static string timeToString(int timeValue)
Expand Down
1 change: 1 addition & 0 deletions iOS/NRGScoutingApp.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<BuildIpa>true</BuildIpa>
<CodesignProvision>iOS Team Provisioning Profile: com.NRG.ScoutingApp.NRG-Scouting</CodesignProvision>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>pdbonly</DebugType>
Expand Down

0 comments on commit 8615101

Please sign in to comment.