- fix on-screen widget tool selectedWidgetView bug

- update & replace new widget template bin file
This commit is contained in:
TrueZhuanjia committed 2025-07-25 00:36:04 +08:00
1 parent ed56d26b1c
commit ce21c398b5
6 files changed
+26 -21

No files matched your search

+2 -1
View File
@@ -13,7 +13,8 @@
#import "OnScreenButtonState.h" #import "OnScreenButtonState.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
#define DEFAULT_TEMPLATE_NAME @"高级控件模板(Advanced widget templates)" #define DEFAULT_TEMPLATE_NAME1 @"控件模板 / Widget templates"
#define DEFAULT_TEMPLATE_NAME2 @"旧版屏显控件 / Legacy on-screen controls"
/** /**
This object contains information pertaining to any of the user created, custom on screen controller layout configurations, or 'profiles.' The object contains a 'name' property for easy reference, as well as an 'isSelected' property which is used to determine whether this particular custom OSC layout should show on screen during game stream view. Only one 'OSCProfile' is set to 'isSelected' at any given time. The object also contains an array of 'OnScreenButtonStates' which provides information that allows us to move and hide/unhide each of the 19 on screen buttons. Note that the 'buttonStates' property should contain an NSMutableArray of ENCODED 'OnScreenButtonState' objects. This allows us to save the 'OSCProfile' object to NSUserDefaults. This object contains information pertaining to any of the user created, custom on screen controller layout configurations, or 'profiles.' The object contains a 'name' property for easy reference, as well as an 'isSelected' property which is used to determine whether this particular custom OSC layout should show on screen during game stream view. Only one 'OSCProfile' is set to 'isSelected' at any given time. The object also contains an array of 'OnScreenButtonStates' which provides information that allows us to move and hide/unhide each of the 19 on screen buttons. Note that the 'buttonStates' property should contain an NSMutableArray of ENCODED 'OnScreenButtonState' objects. This allows us to save the 'OSCProfile' object to NSUserDefaults.
@@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
* Lets the caller of this method know whether a profile with a given name already exists in persistent storage * Lets the caller of this method know whether a profile with a given name already exists in persistent storage
*/ */
- (BOOL) profileNameAlreadyExist:(NSString*)name; - (BOOL) profileNameAlreadyExist:(NSString*)name;
- (BOOL) profileName:(NSString*) name alreadyExistIn:(NSMutableArray*)profiles; - (OSCProfile *) findProfileByName:(NSString*) name inProfileArray:(NSMutableArray*)profiles;
@end @end
@@ -142,7 +142,11 @@ static CGRect streamViewBounds;
- (void) importEncodedProfiles:(NSMutableArray* )profilesEncoded { - (void) importEncodedProfiles:(NSMutableArray* )profilesEncoded {
NSMutableArray* targetProfiles = [_currentProfiles mutableCopy]; //_currentProfiles is availabled as long as getAllProfiles was called before calling this method (_currentProfiles avoids frequent accessing persisted data) NSMutableArray* targetProfiles = [_currentProfiles mutableCopy]; //_currentProfiles is availabled as long as getAllProfiles was called before calling this method (_currentProfiles avoids frequent accessing persisted data)
if([self profileName:DEFAULT_TEMPLATE_NAME alreadyExistIn:targetProfiles] && targetProfiles.count > 1) [targetProfiles removeObjectAtIndex:1]; OSCProfile* profile;
profile = [self findProfileByName:DEFAULT_TEMPLATE_NAME1 inProfileArray:targetProfiles];
if(profile && targetProfiles.count > 1) [targetProfiles removeObject:profile];
profile = [self findProfileByName:DEFAULT_TEMPLATE_NAME2 inProfileArray:targetProfiles];
if(profile && targetProfiles.count > 1) [targetProfiles removeObject:profile];
if(targetProfiles.count > 0) [targetProfiles removeObjectAtIndex:0]; if(targetProfiles.count > 0) [targetProfiles removeObjectAtIndex:0];
NSMutableArray* localEncodedPofiles = [self encodedProfilesFromArray:targetProfiles]; NSMutableArray* localEncodedPofiles = [self encodedProfilesFromArray:targetProfiles];
[profilesEncoded addObjectsFromArray:localEncodedPofiles]; [profilesEncoded addObjectsFromArray:localEncodedPofiles];
@@ -393,14 +397,14 @@ static CGRect streamViewBounds;
return NO; return NO;
} }
- (BOOL) profileName:(NSString*) name alreadyExistIn:(NSMutableArray*)profiles { - (OSCProfile *) findProfileByName:(NSString*) name inProfileArray:(NSMutableArray*)profiles {
/* Iterate through the decoded profiles and return 'YES' if one of the profiles' 'name' properties equals the 'name' passed into this method */ /* Iterate through the decoded profiles and return 'YES' if one of the profiles' 'name' properties equals the 'name' passed into this method */
for (OSCProfile *profile in profiles) { for (OSCProfile *profile in profiles) {
if ([profile.name isEqualToString:name]) { if ([profile.name isEqualToString:name]) {
return YES; return profile;
} }
} }
return NO; return nil;
} }
- (OnScreenButtonState *)unarchiveButtonStateEncoded:(NSData *)data { - (OnScreenButtonState *)unarchiveButtonStateEncoded:(NSData *)data {
+1 -1
View File
@@ -587,7 +587,7 @@ import UIKit
// illustrate offset distance in edit mode // illustrate offset distance in edit mode
// let offsetSign = self.selfViewOnTheRight ? -1 : 1 // dprecated // let offsetSign = self.selfViewOnTheRight ? -1 : 1 // dprecated
// let illlustrationPoint = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame)/4) // let illlustrationPoint = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame)/4)
self.crossMarkLayer.position = CGPointMake(CGRectGetMidX(self.stickBallLayer.frame), CGRectGetMidY(self.stickBallLayer.frame)-stickIndicatorOffset) self.stickBallLayer.position = CGPointMake(CGRectGetMidX(self.crossMarkLayer.frame), CGRectGetMidY(self.crossMarkLayer.frame)-stickIndicatorOffset)
} }
CATransaction.commit() CATransaction.commit()
} }
Binary file not shown.
@@ -81,9 +81,8 @@
- (void) reloadOnScreenWidgetViews { - (void) reloadOnScreenWidgetViews {
NSLog(@"reloadOnScreenWidgets %f", CACurrentMediaTime()); NSLog(@"reloadOnScreenWidgets %f", CACurrentMediaTime());
OnScreenWidgetView.editMode = true; OnScreenWidgetView.editMode = true;
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self clearStickIndicator];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
for (UIView *subview in self.view.subviews) { for (UIView *subview in self.view.subviews) {
if ([subview isKindOfClass:[OnScreenWidgetView class]]) { if ([subview isKindOfClass:[OnScreenWidgetView class]]) {
[subview removeFromSuperview]; [subview removeFromSuperview];
@@ -168,7 +167,7 @@
[profilesManager saveProfileWithName:@"Default" andButtonLayers:self.layoutOSC.OSCButtonLayers]; [profilesManager saveProfileWithName:@"Default" andButtonLayers:self.layoutOSC.OSCButtonLayers];
[profilesManager importDefaultTemplates]; [profilesManager importDefaultTemplates];
}*/ }*/
if (![profilesManager profileName:DEFAULT_TEMPLATE_NAME alreadyExistIn:allProfiles]){ if (![profilesManager findProfileByName:DEFAULT_TEMPLATE_NAME1 inProfileArray:allProfiles]){
[profilesManager importDefaultTemplates]; [profilesManager importDefaultTemplates];
} }
@@ -655,6 +654,11 @@
label.numberOfLines = 1; label.numberOfLines = 1;
} }
- (void)clearStickIndicator{
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
}
- (void)widgetViewTapped: (NSNotification *)notification{ - (void)widgetViewTapped: (NSNotification *)notification{
//self.undoButton.alpha = selectedWidgetView.layoutChanges.count>1 && !CGPointEqualToPoint(selectedWidgetView.layoutChanges.lastObject.CGPointValue, selectedWidgetView.initialCenter)? 1.0 : 0.3; //self.undoButton.alpha = selectedWidgetView.layoutChanges.count>1 && !CGPointEqualToPoint(selectedWidgetView.layoutChanges.lastObject.CGPointValue, selectedWidgetView.initialCenter)? 1.0 : 0.3;
@@ -663,8 +667,7 @@
OnScreenWidgetView* widgetView = (OnScreenWidgetView* )notification.object; OnScreenWidgetView* widgetView = (OnScreenWidgetView* )notification.object;
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self clearStickIndicator];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
self->widgetViewSelected = true; self->widgetViewSelected = true;
self->controllerLayerSelected = false; self->controllerLayerSelected = false;
self->selectedWidgetView = widgetView; self->selectedWidgetView = widgetView;
@@ -705,8 +708,7 @@
} }
if(showStickIndicatorOffsetStack){ if(showStickIndicatorOffsetStack){
// illustrating the indicator offset, // illustrating the indicator offset,
[selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self clearStickIndicator];
[selectedWidgetView.crossMarkLayer removeFromSuperlayer];
selectedWidgetView.touchBeganLocation = CGPointMake(CGRectGetWidth(selectedWidgetView.frame)/2, CGRectGetHeight(selectedWidgetView.frame)/4); selectedWidgetView.touchBeganLocation = CGPointMake(CGRectGetWidth(selectedWidgetView.frame)/2, CGRectGetHeight(selectedWidgetView.frame)/4);
[selectedWidgetView showStickIndicator];// this will create the indicator CAShapeLayers [selectedWidgetView showStickIndicator];// this will create the indicator CAShapeLayers
[self.stickIndicatorOffsetSlider setValue:self->selectedWidgetView.stickIndicatorOffset]; [self.stickIndicatorOffsetSlider setValue:self->selectedWidgetView.stickIndicatorOffset];
@@ -743,8 +745,7 @@
- (void)legacyOscLayerTapped: (NSNotification *)notification{ - (void)legacyOscLayerTapped: (NSNotification *)notification{
[self enableCommonWidgetTools]; [self enableCommonWidgetTools];
CALayer* controllerLayer = (CALayer* )notification.object; CALayer* controllerLayer = (CALayer* )notification.object;
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self clearStickIndicator];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
self->widgetViewSelected = false; self->widgetViewSelected = false;
self->selectedWidgetView = nil; self->selectedWidgetView = nil;
@@ -1120,6 +1121,8 @@
- (void) presentProfilesTableView{ - (void) presentProfilesTableView{
[self saveTapped:nil]; [self saveTapped:nil];
[self clearStickIndicator];
selectedWidgetView = nil;
UIStoryboard *storyboard; UIStoryboard *storyboard;
BOOL isIPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone); BOOL isIPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
if (isIPhone) { if (isIPhone) {
@@ -1144,8 +1147,6 @@
self.widgetPanelStack.hidden = YES; self.widgetPanelStack.hidden = YES;
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
_oscProfilesTableViewController.currentOSCButtonLayers = self.layoutOSC.OSCButtonLayers; _oscProfilesTableViewController.currentOSCButtonLayers = self.layoutOSC.OSCButtonLayers;
[self presentViewController:_oscProfilesTableViewController animated:YES completion:nil]; [self presentViewController:_oscProfilesTableViewController animated:YES completion:nil];
@@ -1252,8 +1253,7 @@
if(!isToolbarHidden && self->selectedWidgetView != nil && [self layerIsOverlappingWithTrashcanButton:selectedWidgetView.layer]){ if(!isToolbarHidden && self->selectedWidgetView != nil && [self layerIsOverlappingWithTrashcanButton:selectedWidgetView.layer]){
[self->selectedWidgetView removeFromSuperview]; [self->selectedWidgetView removeFromSuperview];
[self.OnScreenWidgetViews removeObject:self->selectedWidgetView]; [self.OnScreenWidgetViews removeObject:self->selectedWidgetView];
[selectedWidgetView.stickBallLayer removeFromSuperlayer]; [self clearStickIndicator];
[selectedWidgetView.crossMarkLayer removeFromSuperlayer];
[selectedWidgetView.buttonDownVisualEffectLayer removeFromSuperlayer]; [selectedWidgetView.buttonDownVisualEffectLayer removeFromSuperlayer];
} }