Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CATROID-395 Stop current stitch #3472

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ public class BricksHelpUrlTest {
"https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Data%20Bricks/#ShowTextColorSizeAlignmentBrick");
brickToHelpUrlMapping.put("org.catrobat.catroid.content.bricks.RunningStitchBrick",
"https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Embroidery%20Bricks/#RunningStitchBrick");
brickToHelpUrlMapping.put("org.catrobat.catroid.content.bricks.StopRunningStitchBrick",
"https://wiki.catrobat.org/bin/view/Documentation/Brick%20Documentation/Embroidery%20Bricks/#StopRunningStitchBrick");
}

@Parameterized.Parameters(name = "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
import org.catrobat.catroid.content.bricks.StampBrick;
import org.catrobat.catroid.content.bricks.StitchBrick;
import org.catrobat.catroid.content.bricks.StopAllSoundsBrick;
import org.catrobat.catroid.content.bricks.StopRunningStitchBrick;
import org.catrobat.catroid.content.bricks.StopScriptBrick;
import org.catrobat.catroid.content.bricks.TapAtBrick;
import org.catrobat.catroid.content.bricks.ThinkBubbleBrick;
Expand Down Expand Up @@ -234,7 +235,8 @@ public static Collection<Object[]> data() {
SetBounceBrick.class,
SetFrictionBrick.class)},
{"Embroidery", Arrays.asList(StitchBrick.class,
RunningStitchBrick.class)},
RunningStitchBrick.class,
StopRunningStitchBrick.class)},
{"Event", Arrays.asList(WhenStartedBrick.class,
WhenBrick.class,
WhenTouchDownBrick.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,19 @@ public void testInvalidSetStartCoordinates() {

Mockito.verify(runningStitchType, Mockito.times(0)).setStartCoordinates(anyFloat(), anyFloat());
}

@Test
public void testDeactivateRunningStitch() {
runningStitch.activateStitching(sprite, runningStitchType);
runningStitch.deactivate();
final float xCoord = 1;
final float yCoord = 2;
runningStitch.setStartCoordinates(xCoord, yCoord);
runningStitch.update();

Mockito.verify(runningStitchType, Mockito.times(0)).setStartCoordinates(xCoord, yCoord);
Mockito.verify(spriteLook, Mockito.times(0)).getXInUserInterfaceDimensionUnit();
Mockito.verify(spriteLook, Mockito.times(0)).getYInUserInterfaceDimensionUnit();
Mockito.verify(runningStitchType, Mockito.times(0)).update(anyFloat(), anyFloat());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
import org.catrobat.catroid.content.actions.StopAllScriptsAction;
import org.catrobat.catroid.content.actions.StopAllSoundsAction;
import org.catrobat.catroid.content.actions.StopOtherScriptsAction;
import org.catrobat.catroid.content.actions.StopRunningStitchAction;
import org.catrobat.catroid.content.actions.StopThisScriptAction;
import org.catrobat.catroid.content.actions.TapAtAction;
import org.catrobat.catroid.content.actions.ThinkSayBubbleAction;
Expand Down Expand Up @@ -865,6 +866,12 @@ public Action createRunningStitchAction(Sprite sprite, Formula length) {
return action;
}

public static Action createStopRunningStitchAction(Sprite sprite) {
StopRunningStitchAction action = Actions.action(StopRunningStitchAction.class);
action.setSprite(sprite);
return action;
}

public static Action eventSequence(Script script) {
return new ScriptSequenceAction(script);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.content.actions;

import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction;

import org.catrobat.catroid.content.Sprite;

public class StopRunningStitchAction extends TemporalAction {

private Sprite sprite;

@Override
protected void update(float delta) {
sprite.runningStitch.deactivate();
}

public void setSprite(Sprite sprite) {
this.sprite = sprite;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.content.bricks;

import org.catrobat.catroid.R;
import org.catrobat.catroid.content.ActionFactory;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;

public class StopRunningStitchBrick extends BrickBaseType {

private static final long serialVersionUID = 1L;

@Override
public int getViewResource() {
return R.layout.brick_stop_running_stitch;
}

@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
sequence.addAction(ActionFactory.createStopRunningStitchAction(sprite));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ public void resume() {
isRunning = true;
}
}

public void deactivate() {
isRunning = false;
type = null;
sprite = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
import org.catrobat.catroid.content.bricks.StampBrick;
import org.catrobat.catroid.content.bricks.StitchBrick;
import org.catrobat.catroid.content.bricks.StopAllSoundsBrick;
import org.catrobat.catroid.content.bricks.StopRunningStitchBrick;
import org.catrobat.catroid.content.bricks.StopScriptBrick;
import org.catrobat.catroid.content.bricks.TapAtBrick;
import org.catrobat.catroid.content.bricks.ThinkBubbleBrick;
Expand Down Expand Up @@ -510,6 +511,7 @@ private void prepareXstream(Class projectClass, Class sceneClass) {
xstream.alias("brick", SetTextBrick.class);
xstream.alias("brick", ShowTextColorSizeAlignmentBrick.class);
xstream.alias("brick", StitchBrick.class);
xstream.alias("brick", StopRunningStitchBrick.class);
xstream.alias("brick", RunningStitchBrick.class);
xstream.alias("brick", WaitTillIdleBrick.class);
xstream.alias("brick", WhenRaspiPinChangedBrick.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
import org.catrobat.catroid.content.bricks.StampBrick;
import org.catrobat.catroid.content.bricks.StitchBrick;
import org.catrobat.catroid.content.bricks.StopAllSoundsBrick;
import org.catrobat.catroid.content.bricks.StopRunningStitchBrick;
import org.catrobat.catroid.content.bricks.StopScriptBrick;
import org.catrobat.catroid.content.bricks.TapAtBrick;
import org.catrobat.catroid.content.bricks.ThinkBubbleBrick;
Expand Down Expand Up @@ -648,6 +649,7 @@ private List<Brick> setupEmbroideryCategoryList() {
List<Brick> embroideryBrickList = new ArrayList<>();
embroideryBrickList.add(new StitchBrick());
embroideryBrickList.add(new RunningStitchBrick(new Formula(BrickValues.STITCH_LENGTH)));
embroideryBrickList.add(new StopRunningStitchBrick());
return embroideryBrickList;
}

Expand Down
56 changes: 56 additions & 0 deletions catroid/src/main/res/layout/brick_stop_running_stitch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Catroid: An on-device visual programming system for Android devices
~ Copyright (C) 2010-2018 The Catrobat Team
~ (<http://developer.catrobat.org/credits>)
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ An additional term exception under section 7 of the GNU Affero
~ General Public License, version 3, is available at
~ http://developer.catrobat.org/license_additional_term
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<CheckBox
android:id="@+id/brick_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone" />

<org.catrobat.catroid.ui.BrickLayout
android:id="@+id/brick_stitch_layout"
style="@style/BrickContainer.Embroidery.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:horizontalSpacing="@dimen/brick_flow_layout_horizontal_spacing"
app:verticalSpacing="@dimen/brick_flow_layout_vertical_spacing">

<include layout="@layout/icon_brick_category_embroidery" />

<TextView
android:id="@+id/brick_stitch_textview"
style="@style/BrickText.SingleLine"
android:text="@string/brick_stop_stitch" />
</org.catrobat.catroid.ui.BrickLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions catroid/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@
<!-- Embroidery bricks -->
<string name="brick_stitch">Stitch</string>
<string name="brick_running_stitch">Start running stitch with length</string>
<string name="brick_stop_stitch">Stop current stitch</string>
<!-- -->

<!-- Control bricks -->
Expand Down