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

添加fire效果 #19

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions XActivatePowerMode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8850C21E1C17CD7A00289797 /* fire.ped in Resources */ = {isa = PBXBuildFile; fileRef = 8850C21D1C17CD7A00289797 /* fire.ped */; };
E91D25B41C0DD66A004B0A4C /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E91D25B31C0DD66A004B0A4C /* AppKit.framework */; };
E91D25B61C0DD66A004B0A4C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E91D25B51C0DD66A004B0A4C /* Foundation.framework */; };
E91D25BA1C0DD66A004B0A4C /* XActivatePowerMode.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = E91D25B91C0DD66A004B0A4C /* XActivatePowerMode.xcscheme */; };
Expand All @@ -31,6 +32,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
8850C21D1C17CD7A00289797 /* fire.ped */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = fire.ped; sourceTree = "<group>"; };
E91D25B01C0DD66A004B0A4C /* XActivatePowerMode.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XActivatePowerMode.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; };
E91D25B31C0DD66A004B0A4C /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
E91D25B51C0DD66A004B0A4C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -208,6 +210,7 @@
E9BA82701C1130AA006E697D /* assets */ = {
isa = PBXGroup;
children = (
8850C21D1C17CD7A00289797 /* fire.ped */,
E9BA82711C1130AA006E697D /* blood.ped */,
E9BA82721C1130AA006E697D /* default.ped */,
);
Expand Down Expand Up @@ -279,6 +282,7 @@
E9A716FB1C11316B00506435 /* keyboard4.wav in Resources */,
E9A716FA1C11316B00506435 /* keyboard3.wav in Resources */,
E9A716FC1C11316B00506435 /* keyboard5.wav in Resources */,
8850C21E1C17CD7A00289797 /* fire.ped in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
151 changes: 119 additions & 32 deletions XActivatePowerMode/XPowerModeHeros/Emitter/Emitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "UIEffectDesignerView.h"

NSString * const kXActivatePowerModeEffectFile = @"qfi.sh.xcodeplugin.activatepowermode.effectFile";
NSString * const kXActivatePowerModeShouldRandomEffect = @"qfi.sh.xcodeplugin.activatepowermode.shouldRandomEffect"; //-zyn-12.08

@interface Emitter ()
@property (atomic, assign) BOOL isEmitting;
Expand All @@ -23,21 +24,24 @@ @interface Emitter ()

@property (nonatomic, strong) NSMenuItem * menuItem;
//@property (nonatomic, strong) NSTimer * timer;
@property (nonatomic, strong) NSMutableArray *pedNameArray; //---zyn-12.08
@property (atomic, assign) int lastParity; // 避免一分钟内每次调用effectView都重新创建-zyn-12.08
@property (atomic, assign) BOOL isRandom;
@end

@implementation Emitter

- (void)dealloc
{
self.effectFile = nil;
self.effectFile = nil;
}

- (void)emitAtPosition:(NSPoint)position onView:(NSView *)aView
{
[self beat];

NSView * view = aView.superview;

if ( !self.isEmitting )
{
[self startAtPosition:position onView:view];
Expand All @@ -59,14 +63,14 @@ - (void)startAtPosition:(NSPoint)position onView:(NSView *)view
[view addSubview:self.effectView];
}

// [self.timer invalidate];
// self.timer = [NSTimer timerWithTimeInterval:0.1
// target:self
// selector:@selector(remix)
// userInfo:nil
// repeats:YES];
//
// [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
// [self.timer invalidate];
// self.timer = [NSTimer timerWithTimeInterval:0.1
// target:self
// selector:@selector(remix)
// userInfo:nil
// repeats:YES];
//
// [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

}
}
Expand All @@ -90,7 +94,7 @@ - (void)stop
if ( _effectView ) {
self.effectView.emitter.birthRate = 0;
self.isEmitting = NO;
// [self.timer invalidate];
// [self.timer invalidate];
}
}

Expand All @@ -104,6 +108,38 @@ - (void)remix

- (UIEffectDesignerView *)effectView
{
//---zyn-12.08-begin
if (self.isRandom)
{
NSDate *date = [NSDate date];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"mm"];
NSString *dateStr = [format stringFromDate:date];
int curParity = dateStr.intValue%2;
if (curParity != self.lastParity)
{
if (_effectView)
{
[_effectView removeFromSuperview];
}
NSString *pedName = self.pedNameArray[arc4random_uniform((int)(self.pedNameArray.count - 1))];
_effectView = [UIEffectDesignerView effectWithFile:[self.bundle
pathForResource:pedName
ofType:nil]];
self.birthRate = _effectView.emitter.birthRate;
self.lastParity = curParity;
}
else if (!_effectView)
{
NSString *pedName = self.pedNameArray[arc4random_uniform((int)(self.pedNameArray.count - 1))];
_effectView = [UIEffectDesignerView effectWithFile:[self.bundle
pathForResource:pedName
ofType:nil]];
self.birthRate = _effectView.emitter.birthRate;
}
}
//---zyn-12.08-end

if ( !_effectView )
{
// Build your own effect with: http://www.touch-code-magazine.com/uieffectdesigner/
Expand All @@ -112,31 +148,30 @@ - (UIEffectDesignerView *)effectView
ofType:[self.effectFile pathExtension]]];
self.birthRate = _effectView.emitter.birthRate;
}

return _effectView;
}

- (void)changeEffect:(NSString *)file
{
if ( [self.effectFile isEqualToString:file] )
return;
if ( _effectView )
{
NSView * containerView = _effectView.superview;

[_effectView removeFromSuperview];
_effectView = [UIEffectDesignerView effectWithFile:[self.bundle
pathForResource:[file stringByDeletingPathExtension]
ofType:[file pathExtension]]];
[containerView addSubview:_effectView];

self.birthRate = _effectView.emitter.birthRate;
}

self.effectFile = file;
if ( [self.effectFile isEqualToString:file] )
return;
if ( _effectView )
{
NSView * containerView = _effectView.superview;
[_effectView removeFromSuperview];
_effectView = [UIEffectDesignerView effectWithFile:[self.bundle
pathForResource:[file stringByDeletingPathExtension]
ofType:[file pathExtension]]];
[containerView addSubview:_effectView];
self.birthRate = _effectView.emitter.birthRate;
}
self.effectFile = file;

[self beat];
}
Expand All @@ -156,7 +191,15 @@ - (void)didXPowerModePreferencesSetup:(XPowerModePreferences *)preferences

if ( nil == effectFile )
{
effectFile = @"blood.ped";
//---zyn-12.08-begin
effectFile = [[NSUserDefaults standardUserDefaults] objectForKey:kXActivatePowerModeShouldRandomEffect];
self.isRandom = YES;
if (nil == effectFile)
{
effectFile = @"blood.ped";
self.isRandom = NO;
}
//---zyn-12.08-end
}

self.effectFile = effectFile;
Expand Down Expand Up @@ -184,12 +227,21 @@ - (void)didXPowerModeMenusSetup:(XPowerModePreferences *)preferences
{
NSMenuItem * submenuItem = [[NSMenuItem alloc] init];
submenuItem.title = file;
[self.pedNameArray addObject:file]; //---zyn-12.08
submenuItem.action = @selector(switchEffect:);
submenuItem.target = self;
[[menuItem submenu] addItem:submenuItem];
}
}
}

//---zyn-12.08-begin
NSMenuItem * submenuItem = [[NSMenuItem alloc] init];
submenuItem.title = @"RandomEmitter";
submenuItem.action = @selector(switchEffect:);
submenuItem.target = self;
[[menuItem submenu] addItem:submenuItem];
//---zyn-12.08-end
}

- (void)didXPowerModeMenusUpdate:(XPowerModePreferences *)preferences
Expand All @@ -201,14 +253,41 @@ - (void)switchEffect:(id)sender
{
NSString * file = ((NSMenuItem *)sender).title;

//---zyn-12.08-begin
if([file isEqualToString:@"RandomEmitter"])
{
[self switchRandomEmitterEffectWithTitle:@"RandomEmitter"];
return;
}
self.isRandom = NO;
//---zyn-12.08-end

[self changeEffect:file];

[self updateMenus];

self.isRandom = NO; //---zyn-12.08
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kXActivatePowerModeShouldRandomEffect]; //---zyn-12.08
[[NSUserDefaults standardUserDefaults] setObject:file forKey:kXActivatePowerModeEffectFile];
[[NSUserDefaults standardUserDefaults] synchronize];
}

//---zyn-12.08-begin
- (void)switchRandomEmitterEffectWithTitle:(NSString *)title
{
if ([self.effectFile isEqualToString:title])
{
return;
}
self.effectFile = title;
[self updateMenus];
self.isRandom = YES;
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:kXActivatePowerModeEffectFile];
[[NSUserDefaults standardUserDefaults] setObject:title forKey:kXActivatePowerModeShouldRandomEffect];
[[NSUserDefaults standardUserDefaults] synchronize];
}
//---zyn-12.08-end

- (void)updateMenus
{
for ( NSMenuItem * item in self.menuItem.submenu.itemArray )
Expand All @@ -224,4 +303,12 @@ - (void)updateMenus
}
}

- (NSMutableArray *)pedNameArray
{
if (_pedNameArray == nil)
{
_pedNameArray = [NSMutableArray array];
}
return _pedNameArray;
}
@end
1 change: 1 addition & 0 deletions XActivatePowerMode/XPowerModeHeros/Emitter/assets/fire.ped
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"latitude":1.48,"alphaSpeed":-0.23,"scaleSpeed":-0.1,"blueRange":0.14,"width":20,"texture":"iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAA\r\nAhFJREFUOBFl1OtOFUEQBOCDoIAoKBCD\/OH9X0wT5SJHrkdwrW+yRQ6xk8r0XLq2\r\nuntmN6Zp2losFpsz3mWEnRlv59E+ew7+BvfBn+BhxiojPJesRAj2g73gffAhQG6d\r\nPQVTcBvcBHezb+6j9+uEAj8GCI\/nkY\/YHkNGHbJl8Cu4CprBAmHVlehL1o4CpIcB\r\ntQgFUYiwROfx7eEZxrEgSDCSr8FJcBogbtpv4quhNK+Di2A3wNHarky2g4MZ1CE8\r\nCxB+DhA6U0KNQGidauuUa8rDukJqECKqyk\/xq0KgDgu0plRqqtuaoqa3JfQ1Kpu2\r\n1JFpUtVtxEeg45TxH4PfgZpeGptyr4jGlEhdkTnD1gnN1c0HCSHI+V2Hfa2dRoxE\r\no6oEUa2+GPtSB3E4ttQFHOzosHmD476y7jXGeTbmSNRCsY0glfpx\/7PuGcU5X5sQ\r\n6pLi9l26uObWSx73xfrRxjkvVsyjGnbDhdV6XYO+jrgv5SiZYFfFOXfSaD4IbfqK\r\ntrv9uqxj7a6Cq5NsKCZAcM8bAfH4OSCjTLd+BMh0jAl2NcwVHaH0nP8ZfA\/EnAfW\r\nllRQ6O\/huvQFxB2BUkFovYQtTQm\/ZQ8hhXcIfbEpNahp+TW5tAil7M0iFGwPaWFt\r\nvOWmkfkwV0GgA17BXkA9609ADe2rHWKZSHkQeuxIa3wBlFWdjjN746+SUZlgEGWU\r\n6eofN8G5C784eJgAAAAASUVORK5CYII=","spinRange":0,"lifetime":1.04,"greenSpeed":-0.13,"aux3":null,"emitterType":2,"version":0.1,"zAcceleration":0,"velocity":400,"velocityRange":200,"previewRect":"{{390, 337}, {320, 480}}","yAcceleration":40,"redRange":0.13,"longitude":0.9998799673106125,"height":20,"emitterMode":1,"xAcceleration":0,"color":"#FFF957","alpha":1,"blueSpeed":-0.56,"spin":1.56,"alphaRange":0,"scaleRange":0.8,"lifetimeRange":2,"aux1":null,"redSpeed":0,"greenRange":0.13,"birthRate":100,"x":160,"scale":0.3,"y":271,"aux2":null}