<commit_before>/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.destinationsol.game.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.game.MapDrawer;
import org.destinationsol.game.SolGame;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiBaseScreen;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.Waypoint;

import java.util.ArrayList;

public class MapScreen extends SolUiBaseScreen {
    private final SolUiControl zoomOutControl;
    public final SolUiControl closeControl;
    public final SolUiControl zoomInControl;
    private final SolUiControl addWaypointControl;
    private final SolUiControl removeWaypointControl;

    private final String NEW_WAYPOINT_TEXT = "Marker+";
    private final String REMOVE_WAYPOINT_TEXT = "Marker-";
    private final String CANCEL_TEXT = "Cancel";
    private final int MIN_WAYPOINT_DIST = 5;
    private final int SCROLL_SPEED = 5;

    private boolean isPickingWaypointSpot = false;
    private boolean isPickingWaypointToRemove = false;

    MapScreen(RightPaneLayout rightPaneLayout, boolean mobile, GameOptions gameOptions) {
        Rectangle closeArea = mobile ? MainGameScreen.btn(0, MainGameScreen.HELPER_ROW_1, true) : rightPaneLayout.buttonRect(1);
        closeControl = new SolUiControl(closeArea, true, gameOptions.getKeyMap(), gameOptions.getKeyClose());
        closeControl.setDisplayName("Close");
        controls.add(closeControl);

        float row0 = 1 - MainGameScreen.CELL_SZ;
        float row1 = row0 - MainGameScreen.CELL_SZ;

        Rectangle zoomInArea = mobile ? MainGameScreen.btn(0, row1, false) : rightPaneLayout.buttonRect(2);
        zoomInControl = new SolUiControl(zoomInArea, true, gameOptions.getKeyZoomIn());
        zoomInControl.setDisplayName("Zoom In");
        controls.add(zoomInControl);

        Rectangle zoomOutArea = mobile ? MainGameScreen.btn(0, row0, false) : rightPaneLayout.buttonRect(3);
        zoomOutControl = new SolUiControl(zoomOutArea, true, gameOptions.getKeyZoomOut());
        zoomOutControl.setDisplayName("Zoom Out");
        controls.add(zoomOutControl);

        Rectangle addWaypointArea = mobile ? MainGameScreen.btn(0, row0 - MainGameScreen.CELL_SZ, false) : rightPaneLayout.buttonRect(4);
        addWaypointControl = new SolUiControl(addWaypointArea, true, gameOptions.getKeyShoot2());
        addWaypointControl.setDisplayName(NEW_WAYPOINT_TEXT);
        controls.add(addWaypointControl);

        Rectangle removeWaypointArea = mobile ? MainGameScreen.btn(0, row0 - MainGameScreen.CELL_SZ * 2, false) : rightPaneLayout.buttonRect(5);
        removeWaypointControl = new SolUiControl(removeWaypointArea, true, gameOptions.getKeyShoot2());
        removeWaypointControl.setDisplayName(REMOVE_WAYPOINT_TEXT);
        controls.add(removeWaypointControl);
    }

    @Override
    public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
        SolGame game = solApplication.getGame();
        GameOptions gameOptions = solApplication.getOptions();
        boolean justClosed = closeControl.isJustOff();
        MapDrawer mapDrawer = game.getMapDrawer();
        mapDrawer.setToggled(!justClosed);
        SolInputManager im = solApplication.getInputManager();

        if (justClosed) {
            mapDrawer.getMapDrawPosAdditive().set(0,0);
            isPickingWaypointSpot = false;
            addWaypointControl.setDisplayName(NEW_WAYPOINT_TEXT);
            im.setScreen(solApplication, game.getScreens().mainGameScreen);
        }

        boolean zoomIn = zoomInControl.isJustOff();
        if (zoomIn || zoomOutControl.isJustOff()) {
            mapDrawer.changeZoom(zoomIn);
        }

        float mapZoom = mapDrawer.getZoom();
        zoomInControl.setEnabled(mapZoom != MapDrawer.MIN_ZOOM);
        zoomOutControl.setEnabled(mapZoom != MapDrawer.MAX_ZOOM);
        ShipUiControl shipControl = game.getScreens().mainGameScreen.shipControl;
        if (shipControl instanceof ShipMouseControl) {
            shipControl.update(solApplication, true);
        }

        Boolean scrolledUp = im.getScrolledUp();
        if (scrolledUp != null) {
            if (scrolledUp) {
                zoomOutControl.maybeFlashPressed(gameOptions.getKeyZoomOut());
            } else {
                zoomInControl.maybeFlashPressed(gameOptions.getKeyZoomIn());
            }
        }

        if(im.touchDragged) {
            //Scroll factor negates the drag and adjusts it to map's zoom
            float scrollFactor = -mapDrawer.getZoom()/ Gdx.graphics.getHeight() * SCROLL_SPEED;
            mapDrawer.getMapDrawPosAdditive().add(im.getDrag().scl(scrollFactor));
        }<commit_msg>Fixed map panning when player is rotated<commit_after>/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.destinationsol.game.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.game.MapDrawer;
import org.destinationsol.game.SolGame;
import org.destinationsol.ui.SolInputManager;
import org.destinationsol.ui.SolUiBaseScreen;
import org.destinationsol.ui.SolUiControl;
import org.destinationsol.ui.Waypoint;

import java.util.ArrayList;

public class MapScreen extends SolUiBaseScreen {
    private final SolUiControl zoomOutControl;
    public final SolUiControl closeControl;
    public final SolUiControl zoomInControl;
    private final SolUiControl addWaypointControl;
    private final SolUiControl removeWaypointControl;

    private final String NEW_WAYPOINT_TEXT = "Marker+";
    private final String REMOVE_WAYPOINT_TEXT = "Marker-";
    private final String CANCEL_TEXT = "Cancel";
    private final int MIN_WAYPOINT_DIST = 5;
    private final int SCROLL_SPEED = 5;

    private boolean isPickingWaypointSpot = false;
    private boolean isPickingWaypointToRemove = false;

    MapScreen(RightPaneLayout rightPaneLayout, boolean mobile, GameOptions gameOptions) {
        Rectangle closeArea = mobile ? MainGameScreen.btn(0, MainGameScreen.HELPER_ROW_1, true) : rightPaneLayout.buttonRect(1);
        closeControl = new SolUiControl(closeArea, true, gameOptions.getKeyMap(), gameOptions.getKeyClose());
        closeControl.setDisplayName("Close");
        controls.add(closeControl);

        float row0 = 1 - MainGameScreen.CELL_SZ;
        float row1 = row0 - MainGameScreen.CELL_SZ;

        Rectangle zoomInArea = mobile ? MainGameScreen.btn(0, row1, false) : rightPaneLayout.buttonRect(2);
        zoomInControl = new SolUiControl(zoomInArea, true, gameOptions.getKeyZoomIn());
        zoomInControl.setDisplayName("Zoom In");
        controls.add(zoomInControl);

        Rectangle zoomOutArea = mobile ? MainGameScreen.btn(0, row0, false) : rightPaneLayout.buttonRect(3);
        zoomOutControl = new SolUiControl(zoomOutArea, true, gameOptions.getKeyZoomOut());
        zoomOutControl.setDisplayName("Zoom Out");
        controls.add(zoomOutControl);

        Rectangle addWaypointArea = mobile ? MainGameScreen.btn(0, row0 - MainGameScreen.CELL_SZ, false) : rightPaneLayout.buttonRect(4);
        addWaypointControl = new SolUiControl(addWaypointArea, true, gameOptions.getKeyShoot2());
        addWaypointControl.setDisplayName(NEW_WAYPOINT_TEXT);
        controls.add(addWaypointControl);

        Rectangle removeWaypointArea = mobile ? MainGameScreen.btn(0, row0 - MainGameScreen.CELL_SZ * 2, false) : rightPaneLayout.buttonRect(5);
        removeWaypointControl = new SolUiControl(removeWaypointArea, true, gameOptions.getKeyShoot2());
        removeWaypointControl.setDisplayName(REMOVE_WAYPOINT_TEXT);
        controls.add(removeWaypointControl);
    }

    @Override
    public void updateCustom(SolApplication solApplication, SolInputManager.InputPointer[] inputPointers, boolean clickedOutside) {
        SolGame game = solApplication.getGame();
        GameOptions gameOptions = solApplication.getOptions();
        boolean justClosed = closeControl.isJustOff();
        MapDrawer mapDrawer = game.getMapDrawer();
        mapDrawer.setToggled(!justClosed);
        SolInputManager im = solApplication.getInputManager();

        if (justClosed) {
            mapDrawer.getMapDrawPosAdditive().set(0,0);
            isPickingWaypointSpot = false;
            addWaypointControl.setDisplayName(NEW_WAYPOINT_TEXT);
            im.setScreen(solApplication, game.getScreens().mainGameScreen);
        }

        boolean zoomIn = zoomInControl.isJustOff();
        if (zoomIn || zoomOutControl.isJustOff()) {
            mapDrawer.changeZoom(zoomIn);
        }

        float mapZoom = mapDrawer.getZoom();
        zoomInControl.setEnabled(mapZoom != MapDrawer.MIN_ZOOM);
        zoomOutControl.setEnabled(mapZoom != MapDrawer.MAX_ZOOM);
        ShipUiControl shipControl = game.getScreens().mainGameScreen.shipControl;
        if (shipControl instanceof ShipMouseControl) {
            shipControl.update(solApplication, true);
        }

        Boolean scrolledUp = im.getScrolledUp();
        if (scrolledUp != null) {
            if (scrolledUp) {
                zoomOutControl.maybeFlashPressed(gameOptions.getKeyZoomOut());
            } else {
                zoomInControl.maybeFlashPressed(gameOptions.getKeyZoomIn());
            }
        }

        if(im.touchDragged) {
            //Scroll factor negates the drag and adjusts it to map's zoom
            float scrollFactor = -mapDrawer.getZoom()/ Gdx.graphics.getHeight() * SCROLL_SPEED;
            float rotateAngle = game.getCam().getAngle();
            mapDrawer.getMapDrawPosAdditive().add(im.getDrag().scl(scrollFactor).rotate(rotateAngle));
        }
{'fraction_non_alphanumeric': 0.08829605676816671, 'fraction_numerical': 0.0064672594987873885, 'mean_word_length': 3.6430358632193496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7151052', 'n_tokens_mistral': 3217, 'n_tokens_neox': 3097, 'n_words': 695}