#import "DmTouchOverlay.h" #include #include #include "dm_touch_native_art.h" #include "hle.h" #include "dm_input.h" #include "../../host/dm_i18n.h" #define DM_SKILL_IDLE_ALPHA .6 // 五个技能钮、回城钮、技能组切换钮没按着时底圈与圆环的不透明度(图标、切换钮上的「Ⅰ / Ⅱ」不乘,保持清晰;要调浓淡只改这一处) | Opacity of the base circles and rings of the five skill buttons, the town portal button and the skill set switch button when not held (the icons and the "Ⅰ / Ⅱ" on the switch button are not multiplied and stay clear; to adjust the fade, change only this one place) static UIColor *bronze(CGFloat a) { return [UIColor colorWithRed:.66 green:.53 blue:.32 alpha:a]; } static void caption(NSString *s, CGRect rect, CGFloat size, CGFloat alpha) { NSMutableParagraphStyle *p = [NSMutableParagraphStyle new]; p.alignment = NSTextAlignmentCenter; UIFont *f = [UIFont fontWithName:@"Palatino" size:size]; [s drawInRect:rect withAttributes:@{NSFontAttributeName:f ?: [UIFont systemFontOfSize:size], NSForegroundColorAttributeName:[UIColor colorWithRed:.85 green:.79 blue:.65 alpha:alpha],NSParagraphStyleAttributeName:p}]; } // 技能钮上画哪个图标:读数入口与输入层相同(dm_ta_current_set),只多一条「旧了照旧画」。 // 测试注入 DM_TEST_OVERLAY_STALE_MS=<毫秒>:绘制时把「现在」往后拨这么多,等于技能快照已经这么旧(造「游戏停拍」时覆盖层的样子,不影响输入判定) // Which icon to draw on a skill button: same reading entry as the input layer (dm_ta_current_set), with just one extra rule: "if stale, draw as before". // Test injection DM_TEST_OVERLAY_STALE_MS=: when drawing, push "now" forward by this much, as if the skill snapshot were already this old (reproduces how the overlay looks when game ticks stall; does not affect input decisions) static dm_ta_glyph shown_glyph(const dm_tg_snapshot *n, uint64_t button, uint64_t now, int set) { static int64_t stale = -1; if (stale < 0) { const char *e = getenv("DM_TEST_OVERLAY_STALE_MS"); stale = e ? atoll(e) * 1000000ll : 0; } now += (uint64_t)stale; dm_ta_glyph g = dm_ta_current_set(n, button, now, set); // 快照只是旧了(超过 250 毫秒没更新:游戏停拍、切后台那一瞬、长卡顿)→ 照它被取到那一刻的内容画,不退回 F 标签 / 十字—— // 绑定没变,只是暂时没人刷新;换场景时桥会把快照清空(dm_touch_game_bridge.c),那时取到时刻为 0,仍画占位。输入层的同一读数(front_ios.m)不走这里,照旧只认新鲜的 // The snapshot is merely stale (not updated for over 250 ms: game ticks stalled, the instant of going to background, a long hitch) → draw the content it had at the moment it was captured, do not fall back to the F label / cross -- // the binding has not changed, nobody is refreshing it for the moment; on scene change the bridge clears the snapshot (dm_touch_game_bridge.c), then the capture time is 0 and the placeholder is still drawn. The same reading in the input layer (front_ios.m) does not go through here and still accepts only fresh ones if (g.status == DM_TA_UNKNOWN && n && n->captured_ns && now > n->captured_ns && now - n->captured_ns > DM_TG_MAX_AGE_NS) g = dm_ta_current_set(n, button, n->captured_ns, set); return g; } @implementation DmTouchOverlay { UIImage *_circle, *_joy, *_map, *_menu, *_nativeAtlases[DM_TA_ATLASES], *_silAtlases[DM_TA_ATLASES]; // _sil:同帧位的银色剪影图集(gen_hud_v4.py) | _sil: silver silhouette atlas at the same frame positions (gen_hud_v4.py) NSMutableDictionary *_glyphFrames; dm_ta_glyph _nativeVisualGlyphs[5]; } - (instancetype)initWithFrame:(CGRect)f { if (!(self = [super initWithFrame:f])) return nil; self.backgroundColor = UIColor.clearColor; self.opaque = NO; self.userInteractionEnabled = NO; _circle=[UIImage imageNamed:@"dm_native_circle"]; _joy=[UIImage imageNamed:@"dm_touch_joy"]; _map=[UIImage imageNamed:@"dm_native_map"]; _menu=[UIImage imageNamed:@"dm_native_menu"]; _glyphFrames=[NSMutableDictionary dictionary]; for(int i=0;iskill_set:0),previous=_nativeVisualGlyphs[i]; if(next.status!=previous.status || next.raw_skill_id!=previous.raw_skill_id || next.atlas!=previous.atlas || next.normal_frame!=previous.normal_frame || next.slot!=previous.slot || next.effective_slot!=previous.effective_slot)dirty=YES; _nativeVisualGlyphs[i]=next; } // 复用现有front CADisplayLink赋快照:只在图或新鲜性改变时重绘,不另开timer。 // Reuse the existing front CADisplayLink to assign the snapshot: redraw only when the image or freshness changes, no extra timer. if(dirty)[self setNeedsDisplay]; } - (UIImage *)frameImage:(UIImage *)atlas key:(NSString *)key rect:(CGRect)rect { if(!atlas) return nil; UIImage *image=_glyphFrames[key]; if(image) return image; CGImageRef crop=CGImageCreateWithImageInRect(atlas.CGImage,rect); if(!crop) return nil; image=[UIImage imageWithCGImage:crop]; CGImageRelease(crop); _glyphFrames[key]=image; return image; } - (UIImage *)skillImage:(dm_ta_glyph)g held:(BOOL)held { if(g.status!=DM_TA_GLYPH)return nil; int frame=held?g.pressed_frame:g.normal_frame;dm_ta_frame f; if(!dm_ta_frame_at(g.atlas,frame,&f))return nil; UIImage *sil=_silAtlases[g.atlas]; // 优先剪影(技能键是圆形,PC 定稿演示图只放剪影) | Prefer the silhouette (skill buttons are round; the finalized PC demo image uses silhouettes only) return [self frameImage:sil?sil:_nativeAtlases[g.atlas] key:[NSString stringWithFormat:@"%@:%d:%d",sil?@"sil":@"skill",g.atlas,frame] rect:CGRectMake(f.x,f.y,f.width,f.height)]; } - (void)setNavigationMode:(BOOL)n { _navigationMode = n; [self setNeedsDisplay]; } // ---- 底部 UI v4:UIKit 部分(经验条、「Lv · %」、角标、难度数字与 1–8 选择条),素材与几何由 tools/gen_hud_v4.py 生成(App 内 hud_v4_ui/)---- // 几何单位 = 2868×1320 效果图像素:点 = (像素 − 1434) × 屏高/1320 + 屏宽/2(x),像素 × 屏高/1320(y)——与原生 HUD 同样按屏高缩放、以屏幕中线居中 // ---- Bottom UI v4: UIKit part (experience bar, "Lv · %", badges, difficulty number and the 1–8 selector strip); assets and geometry are generated by tools/gen_hud_v4.py (hud_v4_ui/ inside the App) ---- // Geometry unit = pixels of the 2868×1320 mockup: point = (pixel − 1434) × screen height/1320 + screen width/2 (x), pixel × screen height/1320 (y) -- scaled by screen height and centered on the screen's center line, same as the native HUD static NSDictionary *v4ui(void) { static NSDictionary *ui; static dispatch_once_t once; dispatch_once(&once, ^{ NSString *p=[NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"hud_v4_ui/ui.json"]; NSData *d=[NSData dataWithContentsOfFile:p]; ui=d?[NSJSONSerialization JSONObjectWithData:d options:0 error:nil]:nil; if(!ui) NSLog(@"【红】底部 UI v4:App 内缺 hud_v4_ui/ui.json"); }); return ui; } static UIImage *v4img(NSString *name) { static NSMutableDictionary *cache; if(!cache) cache=[NSMutableDictionary dictionary]; UIImage *im=cache[name]; if(im) return im; im=[UIImage imageWithContentsOfFile:[NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:[@"hud_v4_ui" stringByAppendingPathComponent:name]]]; if(im) cache[name]=im; return im; } // 逐字贴预渲染字形(字效与效果图同源);align:0 居中、1 右对齐;(x, baseline) 为效果图像素 // Blit pre-rendered glyphs character by character (text effect from the same source as the mockup); align: 0 centered, 1 right-aligned; (x, baseline) are in mockup pixels static void v4text(NSString *str, NSDictionary *glyphs, CGFloat x, CGFloat baseline, int align, CGFloat W, CGFloat u) { CGFloat adv=0; for(NSUInteger i=0;ibuttons & DM_BTN_PLUS), alert=h.points>0 || h.quest_unread; UIImage *btn=v4img(alert?(held?@"lvl_1.png":@"lvl_0.png"):(held?@"lvl_d1.png":@"lvl_d0.png")); CGRect r=CGRectMake(X([s6[0] doubleValue]),[s6[1] doubleValue]*u,([s6[2] doubleValue]-[s6[0] doubleValue])*u,([s6[3] doubleValue]-[s6[1] doubleValue])*u); if(h.points>0) { CGContextSaveGState(c); CGContextSetShadowWithColor(c,CGSizeZero,10*u,[UIColor colorWithRed:1 green:.82 blue:.35 alpha:.95].CGColor); [btn drawInRect:r]; CGContextRestoreGState(c); } if(btn) [btn drawInRect:r]; } // 经验条:底槽 + 描边 + 填充(本级‰)+ 20 等分刻度,同效果图 // Experience bar: base groove + outline + fill (‰ of the current level) + 20 equal tick marks, same as the mockup NSDictionary *e=ui[@"exp"]; CGFloat x0=[e[@"x0"] doubleValue], x1=[e[@"x1"] doubleValue], y=[e[@"y"] doubleValue], eh=[e[@"h"] doubleValue]; UIColor *(^rgb)(NSArray *)=^(NSArray *a){ return [UIColor colorWithRed:[a[0] doubleValue]/255 green:[a[1] doubleValue]/255 blue:[a[2] doubleValue]/255 alpha:1]; }; CGContextSetFillColorWithColor(c,rgb(e[@"track"]).CGColor); CGContextFillRect(c,CGRectMake(X(x0),y*u,(x1-x0)*u,eh*u)); CGContextSetStrokeColorWithColor(c,rgb(e[@"edge"]).CGColor); CGContextSetLineWidth(c,u); CGContextStrokeRect(c,CGRectMake(X(x0)+u/2,y*u+u/2,(x1-x0-1)*u,(eh-1)*u)); CGContextSetFillColorWithColor(c,rgb(e[@"fill"]).CGColor); CGContextFillRect(c,CGRectMake(X(x0+1),(y+1)*u,(x1-x0-2)*u*h.exp_permille/1000.0,(eh-2)*u)); int ticks=[e[@"ticks"] intValue]; CGContextSetFillColorWithColor(c,rgb(e[@"track"]).CGColor); for(int t=1;t=1 && h.players<=8) digit(h.players,[slots[0][0] doubleValue]+icx,[slots[0][1] doubleValue]+icy,1); if(s && s->diff_open) { NSDictionary *pk=ui[@"pick"]; UIImage *tile=v4img(@"slot.png"); for(int i=0;i<8;i++) { CGFloat cx=[pk[@"center_x"] doubleValue]+(i-3.5)*[pk[@"pitch"] doubleValue], cy=[pk[@"y"] doubleValue]; CGFloat tw=tile.size.width, th=tile.size.height, a=(i+1==h.players)?1:.82; if(tile) [tile drawInRect:CGRectMake(X(cx-tw/2),(cy-th/2)*u,tw*u,th*u) blendMode:kCGBlendModeNormal alpha:a]; digit(i+1,cx,cy,a); } } } - (void)drawRect:(CGRect)rect { (void)rect; const dm_tc_state *s = self.controls; if (!s) return; const dm_tc_layout *l = &s->layout; CGFloat k = l->joy_radius / 60; if (k <= 0) return; CGContextRef c = UIGraphicsGetCurrentContext(); uint64_t hostNow=now_ns(); dm_tg_snapshot native=self.nativeMapping; NSString *labels[DM_TC_COUNT] = {@"主技能",@"技能一",@"技能二",@"技能三",@"技能四",@"回城",@"药剂",@"药剂",@"药剂",@"药剂",@"功能",@"地图"}; if (self.navigationMode) { labels[0]=@"确认/交换"; labels[1]=@"返回"; labels[2]=@"操作"; labels[3]=@"绑定"; labels[4]=@"下一页"; } // 底栏十字位置的「关闭」已去:关闭入口只留外框右上角那一个(dm_tc_nav_mask) | The 「关闭」(Close) at the bottom bar cross position has been removed: the only close entry left is the one at the top-right corner of the outer frame (dm_tc_nav_mask) for (int i=0;ienabled_targets & (1u<DM_TC_PORTAL && i<=DM_TC_MENU) continue; // 底部 UI v4:腰带 / 功能入口(LevelUpButton)由原生 HUD 画;宿主只保 hit-test。回城(技能弧上方圆钮)照技能钮画 | Bottom UI v4: belt / function entry (LevelUpButton) are drawn by the native HUD; the host only keeps hit-test. Town portal (round button above the skill arc) is drawn like a skill button const dm_tc_target *t = &l->target[i]; CGRect b = CGRectMake(t->x-t->r,t->y-t->r,t->r*2,t->r*2); BOOL held = t->button != 0 && (s->buttons & t->button) == t->button; if(i==DM_TC_PORTAL) for(int f=0;ffinger[f].active && s->finger[f].target==DM_TC_PORTAL; // 回城钮不出按键(宿主施放回城技能),按住态看手指 | The town portal button emits no key (the host casts the town portal skill); the held state is read from the fingers CGFloat opacity = held ? .6 : .28; if(!self.navigationMode && i==DM_TC_MAP && s->map_cancel_active) { CGContextSetFillColorWithColor(c,[UIColor colorWithRed:.55 green:.05 blue:.04 alpha:.36].CGColor); CGContextFillRect(c,b); labels[i]=@"取消"; } BOOL skillKey=!self.navigationMode && (i<=DM_TC_SKILL4 || i==DM_TC_PORTAL); // 回城钮(圆形、和技能图标一样) | Town portal button (round, same as the skill icons) if (skillKey) { // PC 定稿演示图同款:深色圆底 + 古铜圆环(外亮内暗两道) | Same as the finalized PC demo image: dark round base + bronze ring (two strokes, bright outside and dark inside) CGFloat lw=MAX(1.5,t->r*0.075); // 五个技能钮与回城钮平时底圈、圆环淡一些(DM_SKILL_IDLE_ALPHA,少挡画面),按住时恢复原样给手感;图标、角标、标签、充能用完的灰态不跟着变 // The base circles and rings of the five skill buttons and the town portal button are faded when idle (DM_SKILL_IDLE_ALPHA, to block less of the view) and return to normal while held for feedback; icons, badges, labels and the grey out-of-charges state do not follow CGFloat fr=held?1:DM_SKILL_IDLE_ALPHA; CGContextSetFillColorWithColor(c,[UIColor colorWithRed:.086 green:.067 blue:.047 alpha:held?.92:.80*fr].CGColor); CGContextFillEllipseInRect(c,b); CGContextSetLineWidth(c,lw); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.60 green:.47 blue:.28 alpha:held?1:.9*fr].CGColor); CGContextStrokeEllipseInRect(c,CGRectInset(b,lw/2,lw/2)); CGContextSetLineWidth(c,lw*.5); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.12 green:.09 blue:.05 alpha:.9*fr].CGColor); CGContextStrokeEllipseInRect(c,CGRectInset(b,lw*1.3,lw*1.3)); } else if (_circle) [_circle drawInRect:b blendMode:kCGBlendModeNormal alpha:opacity]; else { CGContextSetFillColorWithColor(c,[UIColor colorWithWhite:.02 alpha:.16].CGColor); CGContextFillEllipseInRect(c,b); CGContextSetStrokeColorWithColor(c,bronze(.28).CGColor); CGContextSetLineWidth(c,k); CGContextStrokeEllipseInRect(c,b); } UIImage *icon=nil; BOOL showCaption=YES; int ssKind=0, ssCharges=0; if(!self.navigationMode && i<=DM_TC_SKILL4) { dm_ta_glyph g=shown_glyph(&native,t->button,hostNow,s->skill_set); if(g.status!=DM_TA_EMPTY && g.status!=DM_TA_UNKNOWN) { int dm_swapskill_slot(int,int*); ssKind=dm_swapskill_slot(g.slot,&ssCharges); } icon=[self skillImage:g held:held]; showCaption=g.status!=DM_TA_EMPTY && !icon; } else if(!self.navigationMode && i==DM_TC_PORTAL) { icon=[self skillImage:dm_ta_skill(359) held:held]; // 原版回城技能图(技能描述表 Town Portal:通用技能页第 18 格,219 / 220 / 411 同一张),不显示次数 | the original game's town portal skill image (skill description table Town Portal: cell 18 of the generic skill page, 219 / 220 / 411 share one image), count not shown } else if(!self.navigationMode && (i==DM_TC_MENU || i==DM_TC_MAP)) { icon=[self frameImage:i==DM_TC_MAP?_map:_menu key:[NSString stringWithFormat:@"fixed:%d:%d",i,held] rect:CGRectMake(held?36:0,0,36,36)]; } if(!self.navigationMode && i==DM_TC_MAP && s->map_cancel_active) {icon=nil;showCaption=YES;} if(skillKey && !icon && (!showCaption || i==DM_TC_MAIN)) { // 主钮取不到图标(如第二套里这一格没绑)也画十字、不写「攻击」:空格按下去不出普通攻击,画攻击图标或写字都会骗人 // 空技能位:圆底圆环里一个单色十字,不写 F 标签;点它进绑定技能(行为由输入层接) | when the main button cannot get an icon (e.g. this cell is not bound in the second set) it also draws the cross and does not say 「攻击」(Attack): pressing an empty cell does not produce a normal attack, so drawing the attack icon or the text would both be misleading // empty skill slot: a single-color cross inside the round base and ring, no F label; tapping it goes to skill binding (the behavior is wired by the input layer) CGFloat a_=t->r*.30, w_=MAX(1.5,t->r*.085); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.60 green:.47 blue:.28 alpha:held?1:.9].CGColor); CGContextSetLineWidth(c,w_); CGContextSetLineCap(c,kCGLineCapButt); CGContextMoveToPoint(c,t->x-a_,t->y); CGContextAddLineToPoint(c,t->x+a_,t->y); CGContextMoveToPoint(c,t->x,t->y-a_); CGContextAddLineToPoint(c,t->x,t->y+a_); CGContextStrokePath(c); continue; } if(skillKey) { // 剪影居中略偏上,下方标签:主键「攻击」,其余 F1–F4(第二套 F5–F8);空槽只有圆底、圆环与标签 | silhouette centered and slightly high, label below: main button 「攻击」(Attack), the others F1–F4 (second set F5–F8); an empty slot has only the round base, the ring and the label BOOL bare=icon!=nil; // 有图标的技能钮不写字(最大的钮是「主技能 / 交互」、可绑任意技能,钮上只画所绑技能的图标,不写「攻击」):图标放大并居中。取不到图标时主钮仍落回「攻击」字样 | skill buttons that have an icon carry no text (the largest button is "main skill / interact" and can be bound to any skill, so the button draws only the bound skill's icon and does not say 「攻击」(Attack)): the icon is enlarged and centered. When no icon can be obtained the main button still falls back to the 「攻击」(Attack) text BOOL spent=(ssKind&2) && ssCharges<=0; // 充能用完:钮变灰(灰底上按亮度贴图标 = 去色),按下也不换武器(dm_actions.c) | charges used up: the button turns gray (the icon applied by luminance on a gray base = desaturated), and pressing does not swap weapons either (dm_actions.c) if(icon) { CGFloat size=b.size.width*(bare?.64:.56); CGSize in_=icon.size; CGFloat fit=size/MAX(in_.width,in_.height); CGRect ir=CGRectMake(t->x-in_.width*fit/2,t->y-(bare?0:t->r*.12)-in_.height*fit/2,in_.width*fit,in_.height*fit); if(spent) { CGContextSetFillColorWithColor(c,[UIColor colorWithWhite:.30 alpha:1].CGColor); CGContextFillEllipseInRect(c,CGRectInset(b,t->r*.14,t->r*.14)); [icon drawInRect:ir blendMode:kCGBlendModeLuminosity alpha:.55]; CGContextSetFillColorWithColor(c,[UIColor colorWithWhite:0 alpha:.35].CGColor); CGContextFillEllipseInRect(c,b); } else [icon drawInRect:ir blendMode:kCGBlendModeNormal alpha:held?1:.92]; } // 图标不淡:淡的只是底圈与圆环 | The icon is not faded: only the base circle and the ring are // 副手组技能角标:右上「Ⅱ」= 技能在另一组武器上,按下先换武器;右下剩余次数 = 充能技能,字用腰带药水件数那套(ui.json badge) // Secondary weapon set skill badges: top right "Ⅱ" = the skill is on the other weapon set, pressing swaps weapons first; bottom right remaining count = charged skill, the text uses the same style as the belt potion count (ui.json badge) if(ssKind&1) { CGFloat br=t->r*.30, bx=t->x+t->r*.74, by=t->y-t->r*.74; CGRect bb=CGRectMake(bx-br,by-br,br*2,br*2), lw2=CGRectInset(bb,MAX(1,br*.08),MAX(1,br*.08)); CGContextSetFillColorWithColor(c,[UIColor colorWithRed:.11 green:.094 blue:.078 alpha:.95].CGColor); CGContextFillEllipseInRect(c,bb); CGContextSetLineWidth(c,MAX(1,br*.14)); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.63 green:.50 blue:.27 alpha:1].CGColor); CGContextStrokeEllipseInRect(c,lw2); CGFloat ts=br*1.15; caption(@"Ⅱ",CGRectMake(bx-br,by-ts*.62,br*2,ts*1.4),ts,1); } if(ssKind&2) { NSDictionary *ui=v4ui(); CGFloat W=self.bounds.size.width, u=self.bounds.size.height/1320.0; NSDictionary *bd=ui[@"badge"]; if(bd && u>0) v4text([NSString stringWithFormat:@"%d",ssCharges<0?0:ssCharges],bd[@"glyphs"],(t->x+t->r*.66-W/2)/u+1434,(t->y+t->r*.42)/u,1,W,u); } if(bare) continue; NSString *ln=i==DM_TC_MAIN?@"lbl_main.png":[NSString stringWithFormat:@"lbl_f%d.png",i-DM_TC_SKILL1+1+(s->skill_set?4:0)]; UIImage *lbl=[UIImage imageWithContentsOfFile:[NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:[@"hud_v4_ui" stringByAppendingPathComponent:ln]]]; if(lbl) { CGFloat lh=t->r*(i==DM_TC_MAIN?.30:.36), lw_=lbl.size.width*lh/lbl.size.height; [lbl drawInRect:CGRectMake(t->x-lw_/2,t->y+t->r*.50-lh/2,lw_,lh)]; } continue; } if(icon) { CGFloat size=b.size.width*(i==DM_TC_MAIN?.55:.62); CGSize intrinsic=icon.size;CGFloat fit=size/MAX(intrinsic.width,intrinsic.height); CGRect glyph=CGRectMake(t->x-intrinsic.width*fit/2,t->y-intrinsic.height*fit/2,intrinsic.width*fit,intrinsic.height*fit); [icon drawInRect:glyph blendMode:kCGBlendModeNormal alpha:held?1:.82];showCaption=NO; } CGFloat textSize = (i==DM_TC_MAIN ? 13 : 10)*k; if(showCaption) caption(labels[i],CGRectMake(b.origin.x,t->y-textSize*.6,b.size.width,textSize*1.6),textSize,held ? 1 : .84); if (i>=DM_TC_BELT1 && i<=DM_TC_BELT4) caption([NSString stringWithFormat:@"%d",i-DM_TC_BELT1+1],CGRectMake(t->x-10*k,t->y+8*k,20*k,12*k),8*k,.65); } if (!self.navigationMode && l->swap.r > 0) { // 技能组切换键:显示当前第几套 | skill set switch button: shows which set is current CGRect b = CGRectMake(l->swap.x-l->swap.r,l->swap.y-l->swap.r,l->swap.r*2,l->swap.r*2); // 与技能键同一套:深色圆底 + 古铜圆环(外亮内暗两道);上面「Ⅰ / Ⅱ」、下面小字「换组」 // Same scheme as the skill buttons: dark round base + bronze ring (two strokes, bright outside and dark inside); "Ⅰ / Ⅱ" on top, small text 「换组」(switch set) below CGFloat lw=MAX(1.5,l->swap.r*0.075); BOOL sheld=NO; for(int f=0;ffinger[f].active && hypot(s->finger[f].x-l->swap.x,s->finger[f].y-l->swap.y)<=l->swap.r; // 手指按在这颗上 | a finger is on this button CGFloat fs=sheld?1:DM_SKILL_IDLE_ALPHA; // 同技能钮:平时淡、按住变实;「Ⅰ / Ⅱ」是状态指示,不淡 | same as skill buttons: faded normally, solid while held; "Ⅰ / Ⅱ" is a state indicator and is not faded CGContextSetFillColorWithColor(c,[UIColor colorWithRed:.086 green:.067 blue:.047 alpha:sheld?.92:.80*fs].CGColor); CGContextFillEllipseInRect(c,b); CGContextSetLineWidth(c,lw); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.60 green:.47 blue:.28 alpha:sheld?1:.9*fs].CGColor); CGContextStrokeEllipseInRect(c,CGRectInset(b,lw/2,lw/2)); CGContextSetLineWidth(c,lw*.5); CGContextSetStrokeColorWithColor(c,[UIColor colorWithRed:.12 green:.09 blue:.05 alpha:.9*fs].CGColor); CGContextStrokeEllipseInRect(c,CGRectInset(b,lw*1.3,lw*1.3)); CGFloat ts = 14*k; caption(s->skill_set ? @"Ⅱ" : @"Ⅰ",CGRectMake(b.origin.x,l->swap.y-ts*.8,b.size.width,ts*1.6),ts,1); // 只留 Ⅰ / Ⅱ、居中(「换组」小字去掉) | keep only Ⅰ / Ⅱ, centered (the small 「换组」(switch set) text is removed) } if (self.hud.valid && self.hud.dead) return; // 死亡画面:右侧圆钮已由掩码收起,左侧摇杆圈也不画(截图:死后摇杆圈还在) | death screen: the round buttons on the right are already hidden by the mask, and the stick ring on the left is not drawn either (screenshot: the stick ring was still there after death) if (s->navigation_mode) return; // 面板开着(与起摇杆同一个判定:dm_touch_controls.c 起摇杆的条件带 !navigation_mode):摇杆起不来,静止淡影只会压在面板上(iPad 上双面板占满整宽)——不画 | a panel is open (the same check as starting the stick: the stick-start condition in dm_touch_controls.c includes !navigation_mode): the stick cannot start, and the idle faint shadow would only sit on top of the panel (on iPad the dual panels fill the whole width) - not drawn BOOL moving = s->joy_slot >= 0; CGPoint o = moving ? CGPointMake(s->joy_origin_x,s->joy_origin_y) : CGPointMake(l->joy_x,l->joy_y); CGFloat radius=l->joy_radius; CGRect base=CGRectMake(o.x-radius,o.y-radius,radius*2,radius*2); CGContextSetLineWidth(c,k); CGContextSetStrokeColorWithColor(c,bronze(moving ?.32:.12).CGColor); CGContextStrokeEllipseInRect(c,base); CGFloat dx=s->lx/32767.0*radius,dy=-s->ly/32767.0*radius; CGRect thumb=CGRectMake(o.x+dx-23*k,o.y+dy-23*k,46*k,46*k); if (_joy) [_joy drawInRect:thumb blendMode:kCGBlendModeNormal alpha:moving ?.8:.18]; if (moving && (s->lx || s->ly)) { CGFloat angle=atan2(dy,dx); CGContextSetStrokeColorWithColor(c,bronze(.7).CGColor); CGContextSetLineWidth(c,2*k); CGContextAddArc(c,o.x,o.y,radius+3*k,angle-M_PI/6,angle+M_PI/6,0); CGContextStrokePath(c); } [self drawV4:c]; } - (NSDictionary *)controlMetadata { const dm_tc_state *s=self.controls; if (!s) return @{}; NSMutableArray *a=[NSMutableArray array]; dm_tg_snapshot visualNative=self.nativeMapping; uint64_t hostNow=now_ns(); NSString *names[DM_TC_COUNT]={@"main",@"skill1",@"skill2",@"skill3",@"skill4",@"portal",@"belt1",@"belt2",@"belt3",@"belt4",@"menu",@"map"}; for(int i=0;ilayout.target[i]; NSMutableDictionary *entry=[@{@"id":names[i],@"rect_pt":@[@(t->x-t->r),@(t->y-t->r),@(t->r*2),@(t->r*2)],@"npad_button":@(t->button),@"visible":@((s->enabled_targets&(1u<=DM_TC_PORTAL && i<=DM_TC_MENU) { entry[@"visual_owner"]=i==DM_TC_PORTAL?@"overlay_portal_skill":(i==DM_TC_MENU?@"native_levelup_button":@"native_game_belt"); entry[@"host_drawn"]=@NO; entry[@"touch_enabled"]=@((s->enabled_targets&(1u<button,hostNow,s->skill_set); BOOL held=t->button && (s->buttons&t->button)==t->button; BOOL drawn=!self.navigationMode && [self skillImage:g held:held]!=nil; NSString *status=self.navigationMode?@"navigation_label":(g.status==DM_TA_EMPTY?@"empty_slot":(drawn?@"current_skill":@"empty_unknown")); entry[@"currentSkill"]=@{@"schema":@"dm-current-skill-visual-1",@"status":status,@"reason":[NSString stringWithUTF8String:g.reason],@"raw_skill_id":@(g.raw_skill_id),@"slot":@(g.slot),@"effective_slot":@(g.effective_slot),@"atlas":@(g.atlas),@"normal_frame":@(g.normal_frame),@"pressed_frame":@(g.pressed_frame),@"display_frame":@(held?g.pressed_frame:g.normal_frame),@"glyph_drawn":@(drawn),@"icon_diameter_ratio":@(i==DM_TC_MAIN?.55:.62)}; } [a addObject:entry]; } [a addObject:@{@"id":@"swap",@"rect_pt":@[@(s->layout.swap.x-s->layout.swap.r),@(s->layout.swap.y-s->layout.swap.r),@(s->layout.swap.r*2),@(s->layout.swap.r*2)],@"skill_set":@(s->skill_set),@"visible":@(!self.navigationMode)}]; BOOL moving=s->joy_slot>=0; CGFloat k=s->layout.joy_radius/60; CGFloat jx=moving?s->joy_origin_x:s->layout.joy_x,jy=moving?s->joy_origin_y:s->layout.joy_y,r=s->layout.joy_radius; CGFloat tx=jx+s->lx/32767.0*r,ty=jy-s->ly/32767.0*r; NSDictionary *joystick=@{@"id":@"joystick",@"active":@(moving),@"base_rect_pt":@[@(jx-r),@(jy-r),@(2*r),@(2*r)],@"thumb_rect_pt":@[@(tx-23*k),@(ty-23*k),@(46*k),@(46*k)]}; dm_tg_snapshot native=self.nativeMapping; NSMutableArray *mapping=[NSMutableArray array],*ids=[NSMutableArray array]; for(int i=0;irx),@"ry":@(s->ry),@"owner_slot":@(s->aim_slot),@"map_cancel_active":@(s->map_cancel_active),@"navigation_suppressed":@(s->navigation_mode),@"mapping":@"UIKit dx/r, -dy/r; independent clamped SDK axes"}, @"state":self.navigationMode?@"navigation":@"game",@"joystick":joystick,@"coordinate_space":@"UIKit points",@"view_size_pt":@[@(s->layout.width),@(s->layout.height)],@"navigation":@(self.navigationMode),@"controls":a,@"portal_request":@{@"gesture_epoch":@(s->gesture_epoch),@"binding_identity":@(s->portal_binding_identity),@"scene_epoch":@(s->portal_scene_epoch),@"phase":@(s->portal_phase),@"pending":@(s->portal_pending)},@"portal_binding_verified":@NO,@"game_hud_relayout_verified":@NO}; } @end