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

Commit

Permalink
fix palette bug for different color counts (#25)
Browse files Browse the repository at this point in the history
* fix palette bug for different color counts

* Moev away from hardocded constants, fix positioning bug in l2

* some more bug fixes
  • Loading branch information
AnshG714 authored Apr 10, 2021
1 parent 7f11c63 commit ae4609a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
21 changes: 16 additions & 5 deletions build-apple/PanicPainter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
EBEC12022194B6F4007E708B /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBEC12012194B6F4007E708B /* Metal.framework */; };
EE1BF6CC261F96400045482E /* PPLevelSelectScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EE1BF6C4261F96400045482E /* PPLevelSelectScene.cpp */; };
EE1BF6CD261F96400045482E /* PPMenuScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EE1BF6CB261F96400045482E /* PPMenuScene.cpp */; };
EE1BF6DD2620B6AB0045482E /* PPLevelSelectScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EE1BF6C4261F96400045482E /* PPLevelSelectScene.cpp */; };
EE1BF6E42620B6B40045482E /* PPMenuScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EE1BF6CB261F96400045482E /* PPMenuScene.cpp */; };
EE1BF6E82620B6C90045482E /* PPColorPaletteView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EED6D690260CE83C004A2E6F /* PPColorPaletteView.cpp */; };
EED6D691260CE83C004A2E6F /* PPColorPaletteView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EED6D690260CE83C004A2E6F /* PPColorPaletteView.cpp */; };
EEFA1A4425F68DA7004641A1 /* PPColorPalette.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EEFA1A4225F68DA7004641A1 /* PPColorPalette.cpp */; };
EEFA1A7125FA816D004641A1 /* PPAnimation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EEFA1A7025FA816D004641A1 /* PPAnimation.cpp */; };
Expand Down Expand Up @@ -398,12 +401,12 @@
C5621DC5260B8D3700875B72 /* PPColorStrip.h */,
C5621DC7260B8D4D00875B72 /* PPGlobalTimer.cpp */,
C5621DC6260B8D3E00875B72 /* PPGlobalTimer.h */,
C5FB328E25F41BCC000694C3 /* PPCanvas.cpp */,
C5FB329025F41BCC000694C3 /* PPCanvas.h */,
C5FB329125F41BCC000694C3 /* PPGameScene.cpp */,
C5FB329225F41BCC000694C3 /* PPGameScene.h */,
EEFA1A4225F68DA7004641A1 /* PPColorPalette.cpp */,
EEFA1A4325F68DA7004641A1 /* PPColorPalette.h */,
C5FB328E25F41BCC000694C3 /* PPCanvas.cpp */,
EED6D690260CE83C004A2E6F /* PPColorPaletteView.cpp */,
EED6D698260CE864004A2E6F /* PPColorPaletteView.h */,
);
Expand Down Expand Up @@ -625,6 +628,7 @@
EB74548B1D74D75C002FBAE6 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = KMCB293693;
ProvisioningStyle = Automatic;
};
EBBF18901D74904A008E2001 = {
CreatedOnToolsVersion = 7.3.1;
Expand Down Expand Up @@ -767,10 +771,13 @@
EB7454AE1D74D891002FBAE6 /* main.cpp in Sources */,
EB7454AF1D74D891002FBAE6 /* PPApp.cpp in Sources */,
C5621DB62604F10300875B72 /* PPGlobalConfigController.cpp in Sources */,
EE1BF6DD2620B6AB0045482E /* PPLevelSelectScene.cpp in Sources */,
C5621E09260BACE100875B72 /* PPActionController.cpp in Sources */,
C5621DD0260B8D7400875B72 /* PPCanvasBlock.cpp in Sources */,
EE1BF6E82620B6C90045482E /* PPColorPaletteView.cpp in Sources */,
C5FB32A025F41BD1000694C3 /* PPLoadingScene.cpp in Sources */,
EEFA1A7225FA816D004641A1 /* PPAnimation.cpp in Sources */,
EE1BF6E42620B6B40045482E /* PPMenuScene.cpp in Sources */,
C5621DCA260B8D7200875B72 /* PPColorStrip.cpp in Sources */,
C5621DD6260B8E3C00875B72 /* PPPauseScene.cpp in Sources */,
EF24BCF5261F8FE200B69D31 /* PPSplashEffect.cpp in Sources */,
Expand Down Expand Up @@ -864,15 +871,17 @@
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = KMCB293693;
ENABLE_BITCODE = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
INFOPLIST_FILE = "$(SRCROOT)/Resources/iOS-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = dragonglass.ios.PanicPainter;
PRODUCT_BUNDLE_IDENTIFIER = com.dragonglass.PanicPainter1;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -885,15 +894,17 @@
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = KMCB293693;
ENABLE_BITCODE = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
INFOPLIST_FILE = "$(SRCROOT)/Resources/iOS-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = dragonglass.ios.PanicPainter;
PRODUCT_BUNDLE_IDENTIFIER = com.dragonglass.PanicPainter1;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down
47 changes: 24 additions & 23 deletions source/scenes/gameplay/PPColorPaletteView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ void ColorPaletteView::_animateButtonState(uint ind, const ColorButtonState s) {
}

uint ColorPaletteView::_computeColorIndexAfterSwipe(float diff) {
float colorsHeight = (PADDING + PALETTE_COLOR_SIZE / 2) * 4 * PRESSED_SCALE;
float numColors = _colors.size();
float colorsHeight = (PADDING + PALETTE_COLOR_SIZE / 2) * numColors * PRESSED_SCALE;
int numColorsSwipedOn = diff > 0 ?
max((int)floor(4 * diff / colorsHeight), -3)
:min((int) floor(4 * diff / colorsHeight), 3);
max((int)floor(numColors * diff / colorsHeight), (int) - (numColors - 1))
:min((int) floor(numColors * diff / colorsHeight), (int) numColors - 1);

int indexOfOtherColor = diff > 0 ? max((int)_selectedColor - numColorsSwipedOn, 0) : min((int)_selectedColor - numColorsSwipedOn, 3);
int indexOfOtherColor = diff > 0 ? max((int)_selectedColor - numColorsSwipedOn, 0) : min((int)_selectedColor - numColorsSwipedOn, (int) numColors - 1);

return indexOfOtherColor;
}
Expand All @@ -119,28 +120,9 @@ void ColorPaletteView::update() {

float diff = cp.y - sp.y;
int indexOfOtherColor = -1;

if (input.isPressing() || input.justReleased()) {


if (startingPointIn && input.isPressing()) {
indexOfOtherColor = this->_computeColorIndexAfterSwipe(diff);
for (uint i = 0; i < _colors.size(); i++) {
Animation::alloc(
_buttons[i], .3,
{{ "scaleX", INACTIVE_SCALE }, { "scaleY", INACTIVE_SCALE }},
STRONG_OUT
);
}

Animation::alloc(
_buttons[indexOfOtherColor], .3,
{{"scaleX", PRESSED_SCALE},
{"scaleY", PRESSED_SCALE}},
STRONG_OUT
);
}

for (uint i = 0, j = (uint) _colors.size(); i < j; i++) {
auto &btn = _buttons[i];

Expand All @@ -163,6 +145,25 @@ void ColorPaletteView::update() {
_animateButtonState(i, PRESSED);
}
}

if (startingPointIn && input.isPressing() && !input.isJustTap()) {
indexOfOtherColor = this->_computeColorIndexAfterSwipe(diff);
for (uint i = 0; i < _colors.size(); i++) {
Animation::alloc(
_buttons[i], .3,
{{ "scaleX", INACTIVE_SCALE }, { "scaleY", INACTIVE_SCALE }},
STRONG_OUT
);
}

Animation::alloc(
_buttons[indexOfOtherColor], .3,
{{"scaleX", PRESSED_SCALE},
{"scaleY", PRESSED_SCALE}},
STRONG_OUT
);
}

} else {
for (uint i = 0, j = (uint) _colors.size(); i < j; i++)
_animateButtonState(i, _selectedColor == i ? ACTIVE : INACTIVE);
Expand Down

0 comments on commit ae4609a

Please sign in to comment.