Refine mobile HUD navigation, status readability and bounded chat preview
This commit is contained in:
@@ -9,6 +9,7 @@ class Widget:
|
||||
def Show(self):self.shown=True
|
||||
def Hide(self):self.shown=False
|
||||
def SetText(self,text):self.text=text
|
||||
def SetPosition(self,x,y):self.pos=(x,y)
|
||||
def __getattr__(self,name):return lambda *args:None
|
||||
class Tests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -16,7 +17,9 @@ class Tests(unittest.TestCase):
|
||||
modules={n:types.ModuleType(n) for n in ['app','ui','wndMgr','player','_mt_meshport','introLogin','net']}
|
||||
modules['app'].GetTime=lambda:self.now
|
||||
modules['ui'].Window=modules['ui'].TextLine=Widget
|
||||
modules['wndMgr'].GetScreenWidth=lambda:1280
|
||||
self.width,self.height=1280,600
|
||||
modules['wndMgr'].GetScreenWidth=lambda:self.width
|
||||
modules['wndMgr'].GetScreenHeight=lambda:self.height
|
||||
modules['player'].AutoHuntLocalize=lambda value:value
|
||||
self.cancelled=False
|
||||
modules['net'].CancelPendingLogin=lambda:self.cancelled
|
||||
@@ -43,6 +46,25 @@ class Tests(unittest.TestCase):
|
||||
self.events=[3,1,2]
|
||||
self.notice.OnUpdate();self.assertIn('失败',self.notice.label.text)
|
||||
self.notice.OnUpdate();self.notice.OnUpdate();self.assertEqual(self.notice.label.text,'组网成功')
|
||||
def test_repeated_progress_does_not_extend_notice(self):
|
||||
self.events=[1];self.notice.OnUpdate();deadline=self.notice.hideAt
|
||||
self.now=10;self.events=[1];self.notice.OnUpdate()
|
||||
self.assertEqual(self.notice.hideAt,deadline)
|
||||
self.now=66;self.notice.OnUpdate();self.assertFalse(self.notice.label.shown)
|
||||
def test_ingame_progress_is_brief_and_does_not_reset_on_same_state(self):
|
||||
old=sys.modules.get('mt_mobile_hud')
|
||||
try:
|
||||
sys.modules['mt_mobile_hud']=types.SimpleNamespace(g_hud=types.SimpleNamespace(networkNoticePosition=(18,156)))
|
||||
self.events=[1];self.notice.OnUpdate();self.assertEqual(self.notice.hideAt,5)
|
||||
self.assertEqual(self.notice.label.pos,(18,156))
|
||||
self.now=6;self.events=[1];self.notice.OnUpdate();self.assertFalse(self.notice.label.shown)
|
||||
finally:
|
||||
if old is None:sys.modules.pop('mt_mobile_hud',None)
|
||||
else:sys.modules['mt_mobile_hud']=old
|
||||
def test_notice_repositions_below_top_controls_after_resize(self):
|
||||
self.events=[2];self.notice.OnUpdate();self.assertEqual(self.notice.label.pos,(640,72))
|
||||
self.width,self.height=800,360;self.notice.OnUpdate()
|
||||
self.assertEqual(self.notice.label.pos,(400,52))
|
||||
def test_no_login_hooks_or_password_capture(self):
|
||||
self.assertNotIn('LoginWindow.Connect =',SOURCE);self.assertNotIn('password',SOURCE)
|
||||
def test_cancel_login_hides_only_its_pending_notice(self):
|
||||
|
||||
@@ -511,6 +511,62 @@ int main(int argc, char** argv)
|
||||
"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)"));
|
||||
CHECK(py("import player\nassert _hud.top[1].IsShow() and not any(b.IsShow() for b in [_hud.top[0],_hud.top[2],_hud.top[3]])\n"
|
||||
"_hud.ToggleMore()\n"
|
||||
"assert all(b.IsShow() for b in _hud.drawer) and _hud.menuBackdrop.IsShow()\n"
|
||||
"_hud.top[1].action()\n"
|
||||
"assert not _hud.menuExpanded and not _hud.menuBackdrop.IsShow()\n"
|
||||
"assert _hud.window.interface.wndInventory.IsShow()\n"
|
||||
"_hud.window.interface.wndInventory.Hide()\n"
|
||||
"assert player.FeatureLocaleToUTF8(_hud.status.hp.GetText()).decode('utf-8').startswith(u'\\u751f\\u547d ')\n"
|
||||
"assert player.FeatureLocaleToUTF8(_hud.status.sp.GetText()).decode('utf-8').startswith(u'\\u6cd5\\u529b ')"));
|
||||
CHECK(py("_hud.ToggleMore()\n_menu_b=_hud.drawer[0]"));
|
||||
std::string drawerXY;
|
||||
CHECK(PythonBoot::Evaluate("'%d %d' % _menu_b.GetGlobalPosition()", &drawerXY, nullptr));
|
||||
int drawerX=0,drawerY=0;
|
||||
CHECK(std::sscanf(drawerXY.c_str(), "'%d %d'", &drawerX, &drawerY)==2 ||
|
||||
std::sscanf(drawerXY.c_str(), "%d %d", &drawerX, &drawerY)==2);
|
||||
PythonBoot::UIMouseMove(drawerX+24,drawerY+24);
|
||||
CHECK(py_true("__import__('wndMgr').IsPickedWindow(_menu_b.hWnd)"));
|
||||
CHECK(PythonBoot::IsPointInsideActiveUI(drawerX-3,drawerY-3));
|
||||
CHECK(py("_hud.ToggleMore()"));
|
||||
// Main entries, the complete drawer and the editing window fit narrow/wide layouts.
|
||||
for (const auto dimensions : {std::pair{640,360}, std::pair{800,600}, std::pair{1169,600}}) {
|
||||
PythonBoot::SetUISize(dimensions.first, dimensions.second);
|
||||
CHECK(py("import wndMgr\n_hud.OnUpdate()\n"
|
||||
"_hud.ToggleMore()\n"
|
||||
"for b in [_hud.top[1],_hud.shop,_hud.more]+_hud.drawer:\n"
|
||||
" x,y=b.GetGlobalPosition(); assert x>=0 and y>=0 and x+b.GetWidth()<=wndMgr.GetScreenWidth() and y+b.GetHeight()<=wndMgr.GetScreenHeight()\n"
|
||||
"_hud.ToggleMore()\n"
|
||||
"_hud.chat.OpenChat(); _hud.OnUpdate()\n"
|
||||
"assert _hud.chat.GetGlobalPosition()[0]+_hud.chat.GetWidth()<=wndMgr.GetScreenWidth()\n"
|
||||
"_hud.chat.CloseChat(); _hud.OnUpdate()"));
|
||||
}
|
||||
PythonBoot::SetUISize(800,600);
|
||||
CHECK(py("_hud.OnUpdate()"));
|
||||
// Preview only clips rendering: preserve complete chat history and restore full-screen scissor.
|
||||
CHECK(py("import chat\n"
|
||||
"_preview_id=20261019\n"
|
||||
"chat.CreateChatSet(_preview_id)\n"
|
||||
"chat.SetPosition(_preview_id,20,200)\n"
|
||||
"chat.SetHeight(_preview_id,300)\n"
|
||||
"for i in range(8): chat.AppendChat(chat.CHAT_TYPE_INFO, 'PREVIEW_%d_'%i+'long message '*40)\n"
|
||||
"chat.Update(_preview_id)\n"
|
||||
"_history_count=chat.GetLineCount(_preview_id)"));
|
||||
UIRenderSetSize(800,600);
|
||||
UIRenderBeginFrame();
|
||||
CHECK(py("chat.RenderPreview(_preview_id,10,150,100,45)"));
|
||||
const auto previewCommands = UIRenderCommands();
|
||||
CHECK(!previewCommands.empty());
|
||||
for (const auto& command : previewCommands) {
|
||||
CHECK(command.clip_x1 == 10 && command.clip_y1 == 150);
|
||||
CHECK(command.clip_x2 == 110 && command.clip_y2 == 195);
|
||||
}
|
||||
UIRenderBeginFrame();
|
||||
CHECK(py("chat.Render(_preview_id)\nassert chat.GetLineCount(_preview_id)==_history_count"));
|
||||
CHECK(!UIRenderCommands().empty());
|
||||
for (const auto& command : UIRenderCommands())
|
||||
CHECK(command.clip_x1==0 && command.clip_x2==800 && command.clip_y1==0 && command.clip_y2==600);
|
||||
TouchController touch;
|
||||
touch.set_enabled(true);
|
||||
touch.update_screen_size(800, 600);
|
||||
|
||||
Reference in New Issue
Block a user