From d2681c0a5abca66e9abc17c6b50a13e876ab0cc7 Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Sat, 14 Dec 2024 11:14:20 +0800 Subject: [PATCH] =?UTF-8?q?UI=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqr/Core/UI_Class/UI_Core.nut | 15 ++++ sqr/Core/UI_Class/UI_Widget.nut | 94 +++++++++++++++++++++-- sqr/User/Stage/TestStage.nut | 2 +- sqr/User/UI/Widget/Drag_Button.nut | 33 ++++++++ sqr/User/UI/Widget/Scroll_Bar.nut | 55 +++++++++++++ sqr/User/UI/Window/1_Select_Character.nut | 26 ++++++- 6 files changed, 215 insertions(+), 10 deletions(-) create mode 100644 sqr/User/UI/Widget/Drag_Button.nut create mode 100644 sqr/User/UI/Widget/Scroll_Bar.nut diff --git a/sqr/Core/UI_Class/UI_Core.nut b/sqr/Core/UI_Class/UI_Core.nut index ec158f0..3acc07a 100644 --- a/sqr/Core/UI_Class/UI_Core.nut +++ b/sqr/Core/UI_Class/UI_Core.nut @@ -135,6 +135,21 @@ class Yosin_BaseWindow extends Layer { Addchild(gChild); // gChild.Parent = this; } + + /* + * @函数作用: 移除子对象 + * @参数 name + */ + function RemoveUIChild(gChild) { + foreach(pos, buf in this.UI_Childrens) { + if (buf == gChild) { + this.UI_Childrens.remove(pos); + break; + } + } + Removechild(gChild); + // gChild.Parent = this; + } } diff --git a/sqr/Core/UI_Class/UI_Widget.nut b/sqr/Core/UI_Class/UI_Widget.nut index f080a87..5d47d0c 100644 --- a/sqr/Core/UI_Class/UI_Widget.nut +++ b/sqr/Core/UI_Class/UI_Widget.nut @@ -83,6 +83,8 @@ class Yosin_BaseButton extends Yosin_CommonUi { SpriteState = -1; FrameList = null; + //按下时的模拟偏移 + DownSimulateOffset = true; constructor(X, Y, W, H, Path, Idx) { this.Path = Path; @@ -103,13 +105,15 @@ class Yosin_BaseButton extends Yosin_CommonUi { function ChangeFrame() { //状态更改 刷新精灵帧 if (State != SpriteState) { - //如果按下 调整Y坐标向下一个单位 - if (State == 2) { - Y += 1; - SyncPos(X, Y); - } else if (SpriteState == 2) { - Y -= 1; - SyncPos(X, Y); + //按下时模拟偏移的Flag 如果按下 调整Y坐标向下一个单位 + if (DownSimulateOffset) { + if (State == 2) { + Y += 1; + SyncPos(X, Y); + } else if (SpriteState == 2) { + Y -= 1; + SyncPos(X, Y); + } } SpriteState = State; Sprite.SetFrame(FrameList[SpriteState]); @@ -179,4 +183,80 @@ class Yosin_EmeStretch extends Yosin_CommonUi { } } +} + +//拼接按钮 +class Yosin_SplicingButton extends Yosin_CommonUi { + //按钮状态 + State = 0; + Path = null; + Idx = null; + + SpriteList = null; + SpriteState = -1; + FrameList = null; + + //按下时的模拟偏移 + DownSimulateOffset = true; + + constructor(X, Y, W, H, Path, Idx, Direction = true, UnavailableFlag = true) { + this.Path = Path; + this.Idx = Idx; + base.constructor(X, Y, W, H); + + SpriteList = array(4); + + //普通态 + SpriteList[0] = Yosin_EmeStretch(0, 0, W, H, Path, Idx, Direction); + //悬停态 + SpriteList[1] = Yosin_EmeStretch(0, 0, W, H, Path, Idx + (UnavailableFlag ? 4 : 3), Direction); + //按下态 + SpriteList[2] = Yosin_EmeStretch(0, 0, W, H, Path, Idx + (UnavailableFlag ? 8 : 3), Direction); + if (UnavailableFlag) { + //不可用态 + SpriteList[3] = Yosin_EmeStretch(0, 0, W, H, Path, Idx + 12, Direction); + } + } + + function ChangeFrame() { + //状态更改 刷新精灵帧 + if (State != SpriteState) { + //按下时模拟偏移的Flag 如果按下 调整Y坐标向下一个单位 + if (DownSimulateOffset) { + if (State == 2) { + Y += 1; + SyncPos(X, Y); + } else if (SpriteState == 2) { + Y -= 1; + SyncPos(X, Y); + } + } + if (SpriteState != -1) { + RemoveUIChild(SpriteList[SpriteState]); + } + SpriteState = State; + AddUIChild(SpriteList[SpriteState]); + } + } + + function Proc(Dt) { + //不可用 + if (State == 3) { + + } else { + //按下 + if (isLBDown) { + State = 2; + } + //悬停 + else if (isInRect) { + State = 1; + } + //普通 + else { + State = 0; + } + } + ChangeFrame(); + } } \ No newline at end of file diff --git a/sqr/User/Stage/TestStage.nut b/sqr/User/Stage/TestStage.nut index efa53f5..8d9a821 100644 --- a/sqr/User/Stage/TestStage.nut +++ b/sqr/User/Stage/TestStage.nut @@ -16,7 +16,7 @@ function TestStage() { local Window = Sq_CreateWindow(_Select_Character_Window, "选择角色界面窗口", 0, 0, 1066, 600, 0); local T = { - Background = 1 + Background = 0 } Window.Init(T); diff --git a/sqr/User/UI/Widget/Drag_Button.nut b/sqr/User/UI/Widget/Drag_Button.nut new file mode 100644 index 0000000..320b061 --- /dev/null +++ b/sqr/User/UI/Widget/Drag_Button.nut @@ -0,0 +1,33 @@ +/* +文件名:Drag_Button.nut +路径:User/UI/Widget/Drag_Button.nut +创建日期:2024-12-14 09:40 +文件用途:拖动按钮 +*/ +class Yosin_DragButton extends Yosin_CommonUi { + //路径 + Path = ""; + //索引 + Idx = 0; + + //按钮 + Button = null; + + + constructor(X, Y, W, H, Path, Idx, Direction = true, UnavailableFlag = true) { + this.Path = Path; + this.Idx = Idx; + base.constructor(X, Y, W, H); + + Button = Yosin_SplicingButton(0, 0, W, H, Path, Idx, Direction, UnavailableFlag); + Button.DownSimulateOffset = false; + AddUIChild(Button); + } + + //override + //鼠标左键按下回调 + function OnMouseLbDown(MousePos_X, MousePos_Y) { + base.OnMouseLbDown(MousePos_X, MousePos_Y); + + } +} \ No newline at end of file diff --git a/sqr/User/UI/Widget/Scroll_Bar.nut b/sqr/User/UI/Widget/Scroll_Bar.nut new file mode 100644 index 0000000..b235c55 --- /dev/null +++ b/sqr/User/UI/Widget/Scroll_Bar.nut @@ -0,0 +1,55 @@ +/* +文件名:Scroll_Bar.nut +路径:User/UI/Widget/Scroll_Bar.nut +创建日期:2024-12-13 23:17 +文件用途: +*/ +//基础按钮 +class Yosin_ScrollBar extends Yosin_CommonUi { + //控制器 + Controller = null; + + //是否焦点 + IsFocus = false; + + //上按钮 + UpButton = null; + //下按钮 + DownButton = null; + + //Path + Path = "sprite/interface/lenheartwindowcommon.img"; + + constructor(X, Y, H, gSize) { + base.constructor(X, Y, 9, H > 26 ? H : 26); + + Controller = { + CurPos = 0, + Size = gSize + } + + //上按钮 + UpButton = Yosin_BaseButton(0, 0, 9, 13, Path, 16); + //点击事件回调 + UpButton.OnClick = function(Button) { + + }.bindenv(this); + AddUIChild(UpButton); + + //滚动条 + + //下按钮 + DownButton = Yosin_BaseButton(0, Height - 13, 9, 13, Path, 22); + //点击事件回调 + DownButton.OnClick = function(Button) { + + }.bindenv(this); + AddUIChild(DownButton); + + } + + function Proc(Dt) { + base.Proc(Dt); + } + +} \ No newline at end of file diff --git a/sqr/User/UI/Window/1_Select_Character.nut b/sqr/User/UI/Window/1_Select_Character.nut index 9d378c8..180842d 100644 --- a/sqr/User/UI/Window/1_Select_Character.nut +++ b/sqr/User/UI/Window/1_Select_Character.nut @@ -82,11 +82,14 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window { //选择背景按钮集合 SettingBackgroundButtonList = null; + Background = null; + constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) { base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH); SettingBackgroundButtonList = []; - SetClipRect(-gWidth, 0, gWidth, gHeight + 20); + // SetClipRect(-gWidth, 0, gWidth, gHeight + 20); + // SetClipRect(0, 0, 1066, 600); // ShowBorder(true); // SetLayerOpacity(1); } @@ -98,7 +101,7 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window { function RegisterDraw() { //背景 - local Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17); + Background = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/setup/setup.img", 17); Addchild(Background); for (local i = 0; i< 24; i++) { @@ -199,6 +202,15 @@ class _Select_Character_Window extends Yosin_Window { } }) SettingButton.Addchild(LoginTextActor); + + + // local TestButton = Yosin_ScrollBar(300, 200, 50, 100); + // AddUIChild(TestButton); + // local TestButton = Yosin_SplicingButton(200, 200, 77, 68, "sprite/interface/lenheartwindowcommon.img", 184, false, false); + // TestButton.DownSimulateOffset = false; + local TestButton = Yosin_DragButton(200, 200, 9, 120, "sprite/interface/lenheartwindowcommon.img", 184, false, false); + // TestButton.SetScale(5.0, 5.0); + AddUIChild(TestButton); } //切换背景 @@ -209,6 +221,16 @@ class _Select_Character_Window extends Yosin_Window { } BackGround = CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx); BackGround.SetZOrder(-10); + + /* + + BackGround = Layer(); + BackGround.Addchild(CL_SpriteObject("sprite/interface2/selectcharacter_ver2/background/large/background_large_event.img", Idx)); + BackGround.SetZOrder(-10); + BackGround.SetPosition(100, 100); + BackGround.SetClipRect(0, 0, 200, 200); + + */ Addchild(BackGround); }