Integrate AVA2 native shop and refine mobile controls and locale tooltips

This commit is contained in:
shen
2026-10-19 07:13:56 -07:00
parent 1359eab806
commit 24c1b3b416
36 changed files with 3501 additions and 52 deletions
+67 -1
View File
@@ -352,6 +352,7 @@ int main(int argc, char** argv)
// by port. TChannelStatus::nPort is a short, so the fake server's ephemeral state port (> 32767)
// never matches its own channel; offline the proof is the second channel (13002) it also lists.
// Live the game port answers for the channels the db knows, the game port among them.
if (!std::getenv("MT_TEST_PINCH"))
{
const int state_port = server ? server->StatePort() : game_port;
const int key = server ? 2 : 1;
@@ -501,6 +502,69 @@ int main(int argc, char** argv)
return g_failures ? 1 : 0;
}
if (mobile_test && std::getenv("MT_TEST_PINCH")) {
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
CHECK(py("import mt_mobile_hud; _hud=mt_mobile_hud.g_hud\n"
"assert not _hud.menuExpanded and all(not b.IsShow() for b in _hud.side)\n"
"assert _hud.shop.IsShow() and _hud.more.IsShow()\n"
"_hud.ToggleMore()\n"
"assert _hud.menuExpanded and all(b.IsShow() for b in _hud.side)\n"
"_hud.ToggleMore()\n"
"assert not _hud.menuExpanded and all(not b.IsShow() for b in _hud.side)"));
TouchController touch;
touch.set_enabled(true);
touch.update_screen_size(800, 600);
// PORT scene pinch: start across both halves, spread closer, close farther.
CHECK(!PythonBoot::IsPointInsideActiveUI(480, 240));
CHECK(!PythonBoot::IsPointInsideActiveUI(320, 240));
auto* camera = CCameraManager::Instance().GetCurrentCamera();
const float originalDistance = camera->GetDistance();
CHECK(touch.on_finger_down(201, 0.4f, 0.4f));
CHECK(touch.on_finger_down(202, 0.6f, 0.4f));
const float beforePinch = camera->GetDistance();
touch.on_finger_motion(202, 0.7f, 0.4f);
CHECK(camera->GetDistance() < beforePinch * 0.8f);
const float closeDistance = camera->GetDistance();
touch.on_finger_motion(202, 0.6f, 0.4f);
CHECK(camera->GetDistance() > closeDistance * 1.2f);
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
touch.on_finger_up(201, 0.4f, 0.4f); // remaining finger becomes look, never tap
touch.on_finger_motion(202, 0.62f, 0.4f);
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
touch.on_finger_up(202, 0.62f, 0.4f);
touch.update();
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
// Reverse ownership order; right scene finger plus left scene finger also pinches.
touch.on_finger_down(203, 0.6f, 0.4f);
touch.on_finger_down(204, 0.4f, 0.4f);
touch.on_finger_motion(204, 0.3f, 0.4f);
CHECK(camera->GetDistance() < beforePinch * 0.8f);
touch.on_finger_up(204, 0.3f, 0.4f);
touch.on_finger_up(203, 0.6f, 0.4f);
camera->SetDistance(originalDistance);
touch.on_finger_down(207, 0.6f, 0.4f);
touch.on_finger_down(208, 0.4f, 0.4f);
touch.cancel_gestures();
touch.on_finger_motion(208, 0.2f, 0.4f);
CHECK(std::abs(camera->GetDistance() - originalDistance) < 1.0f);
// A moving joystick is not stolen by a second thumb looking around.
touch.on_finger_down(205, 0.3f, 0.45f);
touch.on_finger_motion(205, 0.35f, 0.45f);
touch.on_finger_down(206, 0.6f, 0.4f);
touch.on_finger_motion(206, 0.7f, 0.4f);
CHECK(std::abs(camera->GetDistance() - originalDistance) < 1.0f);
touch.on_finger_up(205, 0.35f, 0.45f);
touch.on_finger_up(206, 0.7f, 0.4f);
CHECK(py("import app; app.Exit()"));
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
PythonBoot::Stop();
if (server) server->Stop();
std::printf("mobile scene pinch: %s\n", g_failures ? "FAILED" : "PASS");
return g_failures ? 1 : 0;
}
if (mobile_test) {
// Input remains blocked by the original phase curtain until its fade finishes.
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
@@ -511,7 +575,7 @@ int main(int argc, char** argv)
"_hud.window.interface.wndInventory.Hide()"));
CHECK(py_true("_hud.IsShow()"));
CHECK(py_true("not ui.Window.IsShow(_hud.taskbar)"));
CHECK(py_true("len(_hud.top) == 4 and len(_hud.side) == 3"));
CHECK(py_true("len(_hud.top) == 4 and len(_hud.side) == 4"));
CHECK(py_true("all(button.GetWidth() >= 48 for button in _hud.top + _hud.side)"));
CHECK(py_true("_hud.status.values[0] == player.GetStatus(player.HP)"));
CHECK(py_true("_hud.experience is _hud.taskbar.expGaugeBoard and _hud.experience.IsShow()"));
@@ -1650,6 +1714,8 @@ int main(int argc, char** argv)
CHECK(kept_origin);
touch.on_finger_up(101, 0.325f, 0.46666667f);
}
CHECK(py("import app\napp.Exit()"));
+75
View File
@@ -0,0 +1,75 @@
"""Execute the shipping shop decoder and purchase callbacks with real native layouts."""
import ast,struct,types,unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
SRC=(ROOT/'src/platform/ScriptLib/Ava2ItemShopScript.inc').read_text().split('c_szAva2ItemShopScript[]=R"PY(',1)[1].split(')PY";',1)[0]
class Wire(unittest.TestCase):
def setUp(self):
tree=ast.parse(SRC);fn=next(n for n in tree.body if isinstance(n,ast.FunctionDef) and n.name=='Parse')
self.ns={'struct':struct,'_product':struct.Struct('<IIqiBiiqiii'),'_log':struct.Struct('<I25s21si16sIIiq')}
exec(compile(ast.Module(body=[fn],type_ignores=[]),'<shop>','exec'),self.ns)
def catalogue(self,discount=25,product=1):
row=self.ns['_product'].pack(product,71084,99,0,discount,0,0,0,2,8,4)
return struct.pack('<BqiiBBBB',0,999,7,1,0,1,0,1)+row
def test_native_sizes_and_product_fields(self):
self.assertEqual(self.ns['_product'].size,49);self.assertEqual(self.ns['_log'].size,90)
op,(coins,rev,rows)=self.ns['Parse'](self.catalogue());self.assertEqual((op,coins,rev),(0,999,7));self.assertEqual(rows[0][2][1],71084)
def test_all_partial_frames_fail_before_mutating_model(self):
packet=self.catalogue()
for size in range(len(packet)):
with self.assertRaises((ValueError,struct.error)):self.ns['Parse'](packet[:size])
def test_invalid_discount_duplicate_ids_trailing_and_unknown(self):
for packet in [self.catalogue(101),self.catalogue()+b'x',b'\x09',struct.pack('<Bqii',0,-1,1,0)]:
with self.assertRaises((ValueError,struct.error)):self.ns['Parse'](packet)
packet=bytearray(self.catalogue());packet[20]=2;packet+=packet[-49:]
with self.assertRaises((ValueError,struct.error)):self.ns['Parse'](bytes(packet))
def test_purchase_reply_exact_token_status_balance(self):
packet=struct.pack('<B32sBq',7,b'0123456789abcdef0123456789abcdef',0,100)
self.assertEqual(self.ns['Parse'](packet)[1][-2:],(0,100))
for packet in (packet[:-1],packet+b'x',struct.pack('<B32sBq',7,b'z'*32,0,100),struct.pack('<B32sBq',7,b'0'*32,10,100)):
with self.assertRaises((ValueError,struct.error)):self.ns['Parse'](packet)
def test_log_count_is_bounded(self):
for count in (-1,101):
with self.assertRaises(ValueError):self.ns['Parse'](struct.pack('<Bi',1,count))
class PurchaseFlow(unittest.TestCase):
def functions(self,*names):
nodes=[n for n in ast.parse(SRC).body if isinstance(n,ast.FunctionDef) and n.name in names]
exec(compile(ast.Module(body=nodes,type_ignores=[]),'<shop-flow>','exec'),self.ns)
def setUp(self):
self.sent=[];self.now=0
class Token:
def encode(self,encoding):assert encoding=='hex';return 'a'*32
self.ns=dict(pending=None,_serial=0,_next=0,_waiting=False,_queued=False,_requested=0,_logAt=0,window=None,
os=types.SimpleNamespace(urandom=lambda size:Token()),app=types.SimpleNamespace(GetTime=lambda:self.now),
net=types.SimpleNamespace(SendChatPacket=self.sent.append),chat=types.SimpleNamespace(CHAT_TYPE_INFO=1,AppendChat=lambda *args:None),L=lambda s:s)
def test_displayed_discount_matches_server_integer_total(self):
self.functions('Total')
self.assertEqual(self.ns['Total'](58,1,50),29)
self.assertEqual(self.ns['Total'](99,2,25),148)
def test_confirmed_quote_is_frozen_and_double_accept_is_blocked(self):
self.functions('AcceptBuy')
item=types.SimpleNamespace(shopQuote=(1,2,148,71084),data=[999],buyCount=20,CloseQuestionDialog=lambda:None)
self.ns['AcceptBuy'](item);self.ns['AcceptBuy'](item)
self.assertEqual(self.sent,['/ishop buy 1 2 '+'a'*32+' 148 71084'])
def test_retry_preserves_order_and_never_creates_second_payment(self):
self.functions('Tick');self.ns['pending']=('a'*32,1,2,0,0,148,71084)
for now in [5,10,15,20,25]:self.now=now;self.ns['Tick']()
self.assertEqual(self.sent,['/ishop buy 1 2 '+'a'*32+' 148 71084']*3)
self.assertEqual(self.ns['pending'][4],4)
def test_catalogue_refresh_is_queued_past_command_throttle(self):
self.functions('Request','Tick');self.ns['Request']();self.now=.5;self.ns['Request']()
self.assertEqual(len(self.sent),1);self.assertTrue(self.ns['_queued'])
self.now=1.2;self.ns['Tick']();self.assertEqual(self.sent,['/ishop data -1']*2)
def test_image_and_button_callbacks_keep_correct_event_arguments(self):
self.ns['_MISSING']=object();self.functions('EventTag');calls=[]
wrapped=self.ns['EventTag'](lambda self,event,category,sub:calls.append((event,category,sub)),3)
self.assertGreater(wrapped.__code__.co_argcount,1) # classic ui.__mem_func__ must retain image arguments
wrapped(None,2,1);wrapped(None,'button',2,1)
self.assertEqual(calls,[(None,2,1),('button',2,1)])
def test_uncertain_commit_keeps_same_pending_order(self):
self.functions('Receive');pending=('a'*32,1,2,0,0,148,71084)
self.ns.update(pending=pending,Parse=lambda raw:(7,('a'*32,8,10000)))
self.ns['Receive'](None,b'');self.assertEqual(self.ns['pending'],pending)
if __name__=='__main__':unittest.main()
+23 -5
View File
@@ -29,6 +29,7 @@ class MockWidget(object):
def SetDownVisual(self, v): self.visuals['down'] = v
def SetEvent(self, ev): self.event = ev
def SetText(self, t): self.text = t
def SetToolTipText(self, t): self.tooltip = t
def SetOutline(self): pass
def SetHorizontalAlignRight(self): pass
def SetPackedFontColor(self, c): pass
@@ -40,11 +41,15 @@ class MockWidget(object):
class MinimapButtonsTests(unittest.TestCase):
def setUp(self):
names = ('app', 'game', 'ui', 'wndMgr', 'mt_dungeons', 'mt_battlepass', 'mt_biolog')
names = ('app', 'game', 'ui', 'wndMgr', 'mt_dungeons', 'mt_battlepass', 'mt_biolog', 'player', 'mt_channel', 'mt_wiki')
mods = {n: types.ModuleType(n) for n in names}
mods['app'].DIK_F5 = 63
mods['app'].DIK_F6 = 64
mods['app'].DIK_F7 = 65
mods['app'].DIK_F8 = 66
mods['player'].AutoHuntLocalize = lambda text: text.encode('gbk')
mods['mt_channel'].Toggle = lambda: None
mods['mt_wiki'].Toggle = lambda: None
self.toggles = {'dungeon': 0, 'battlepass': 0, 'biolog': 0}
mods['mt_dungeons'].Toggle = lambda: self.toggles.__setitem__('dungeon', self.toggles['dungeon'] + 1)
@@ -75,7 +80,10 @@ class MinimapButtonsTests(unittest.TestCase):
self.wndMiniMap.ShowMiniMap = lambda: self.wndMiniMap.OpenWindow.Show()
self.wndMiniMap.OnUpdate = lambda: None
self.gw.interface = types.SimpleNamespace(wndMiniMap=self.wndMiniMap)
self.expanded = MockWidget()
self.expanded.expandedTaskBarBoard = MockWidget()
self.gw.interface = types.SimpleNamespace(
wndMiniMap=self.wndMiniMap, wndExpandedTaskBar=self.expanded)
self.game.GameWindow.Open(self.gw)
self.ring = self.ns['g_ring']
@@ -96,17 +104,27 @@ class MinimapButtonsTests(unittest.TestCase):
# Dungeon: (-10, 40)
self.assertEqual(self.ring.btnDungeon.pos, (-10, 40))
self.assertEqual(self.ring.btnDungeon.visuals['up'], "d:/ymir work/ui/game/minimapa/dungeon_0.tga")
self.assertEqual(self.ring.tipDungeon.textLine.text, "[F5] 副本信息")
self.assertEqual(self.ring.tipDungeon.textLine.text, "[F5] 副本信息".encode("gbk"))
# BattlePass: (0, 80)
self.assertEqual(self.ring.btnBattlePass.pos, (0, 80))
self.assertEqual(self.ring.btnBattlePass.visuals['up'], "d:/ymir work/ui/game/battle_pass/battlepass_icon_0.tga")
self.assertEqual(self.ring.tipBattlePass.textLine.text, "[F6] 战斗通行证")
self.assertEqual(self.ring.tipBattlePass.textLine.text, "[F6] 战斗通行证".encode("gbk"))
# Biolog: (15, 105)
self.assertEqual(self.ring.btnBiolog.pos, (15, 105))
self.assertEqual(self.ring.btnBiolog.visuals['up'], "d:/ymir work/ui/game/minimapa/biolog_0.tga")
self.assertEqual(self.ring.tipBiolog.textLine.text, "[F7] 生物学家")
self.assertEqual(self.ring.tipBiolog.textLine.text, "[F7] 生物学家".encode("gbk"))
def test_all_chinese_tooltips_use_locale_bytes(self):
expected = ((self.ring.tipDungeon, "[F5] 副本信息"),
(self.ring.tipBattlePass, "[F6] 战斗通行证"),
(self.ring.tipBiolog, "[F7] 生物学家"),
(self.ring.tipChannel, "[F8] 点击换线"))
for tooltip, label in expected:
self.assertEqual(tooltip.textLine.text.decode('gbk'), label)
self.assertEqual(self.expanded.btnSwitchbot.tooltip.decode('gbk'), "自动洗练")
self.assertEqual(self.expanded.btnWiki.tooltip.decode('gbk'), "游戏百科")
def test_button_clicks_trigger_subsystems(self):
self.ring.btnDungeon.event()