顯示具有 自寫範例 標籤的文章。 顯示所有文章
顯示具有 自寫範例 標籤的文章。 顯示所有文章

2016年9月29日 星期四

0929 安裝pomelo

1. 安裝 Node
下載網頁  https://nodejs.org/en/download/
下載檔案  node-v6.7.0-x64.msi
執行安裝
安裝完畢 可以控制台cmd 下執行  node -v  
如有版本就是安裝完畢了

2.安装component
在CMD 輸入
npm install -g component 
別忘了參數-g,表示全局安裝,這樣你在cmd任何路徑下都可以使用componen
驗證
 component -V  

3.安装pomelo
npm install -g pomelo 
驗證
pomelo --version 

4.创建pomelo_demo
mkdir HelloWorld
cd HelloWorld 
pomelo init

然後驗證 gameserver 是否正常

執行
npm-install.bat  

進行安裝完畢後,cmd會自動切換到game-server 目錄下,我們接著執行:
pomelo start  

如果不出錯的話,我們就可以看到game-server運行起來了,接著我們可以用ctrl+c來殺死服務器進程

接著將cmd目錄切換至web-server下,執行:
bin\component.bat  

如果出現錯誤訊息 請手動執行 指令
component install
component build

等待執行完畢後,我們的Demo基本就弄好了

5.開始伺服器

game-server目錄運行  pomelo start  
web-server目錄下運行 node app   

一切順利的話我們就可以打開瀏覽器訪問:http://127.0.0.1:3001/index.html 
點擊Test Game Server按鈕就會彈出一個對話框顯示 gameserver is ok



2016年6月21日 星期二

0621 IPA 安裝教學 FOR itunes 12.4.1.6

如何將IPA 透過ITUNES 安裝到 手機中


1.插上iPhone,開啟 iTunes,點選選單 檢視->媒體種類->APP 。iTunes 會切換至APP頁面




2.開啟檔案總管 將 .ipa 檔案 利用滑鼠拉進 iTunes。然後點選上方手機小圖式,切換至裝置詳細頁面,準備進行同步。



3.切換至手機裝置頁面,點選左邊的欄位 APP,將可以切換至安裝頁面。
   此時可以看到之前的拖來進來的IPA 檔案,點選安裝按鈕。下方同步按鈕會變套用。
   點選套用就會開始安裝。

4.安裝完成畫面如下




2016年5月31日 星期二

0531 在標頭檔宣告 static_cast dynameic_case 出錯

http://stackoverflow.com/questions/6031054/errorstatic-cast-undeclared-objective-c

error:static_cast undeclared->Objective C

Objective C:
[pPacket SetHeaderSequenceNumber:static_cast<char>(m_transmitSequenceNumber + ASCII_ZERO)];
cpp:
pPacket->SetHeaderSequenceNumber(static_cast <char>(m_transmitSequenceNumber + ASCII_ZERO));
error:static_cast undeclared.


改採用C
objective-c is a superset of c, not c++ so static_cast is not supported in it. You can just use c-style cast:
[pPacket SetHeaderSequenceNumber:(char)(m_transmitSequenceNumber + ASCII_ZERO)];

2016年5月27日 星期五

0527 ios9.x app 的檔案 存放位置

//MAC simulator 的目錄位置
// 可以進入 Users/adifly/Library/Developer/CoreSimulator/Devices/
 //利用搜尋方式找出
完整路徑範例:
///Users/adifly/Library/Developer/CoreSimulator/Devices/193008FE-BC6E-48AB-8E4F-CC5B9BB136D9/data/Containers/Data/Application/15941F34-EBC5-43E7-B333-47B39B4562A4/Documents
==============================================================
觀看隱藏檔的方式
打開終端,輸入命令
顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false

2016年5月20日 星期五

0520 toast 範例2

#include "cocos2d.h"
using namespace cocos2d;

USING_NS_CC;
using namespace std;

class Toast: public LayerColor
{
public:
    Size winSize;
    Vec2 winOrigin;
// CCSize visibleSize;
// CCPoint origin;
//CCScale9Sprite* bg;
Sprite *bg;
public:
Toast();
~Toast();
void removeSelf();
virtual bool init();
void initToast(string msg,float time);
CREATE_FUNC(Toast);
void onExit();
};


//////////////////////////////////////////////////////////////////////////
//建立通用彈跳視窗
//參考http://www.android100.net/html/201406/04/18200.html
Toast::Toast()
{
}

Toast::~Toast()
{
}

bool Toast::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!LayerColor::initWithColor(Color4B(0, 0, 0, 0)));//ccc4(0, 0, 0, 125)
winSize = Director::getInstance()->getVisibleSize();
winOrigin = Director::getInstance()->getVisibleOrigin();
//====================================
bg = Sprite::createWithSpriteFrameName(S_MSGBOX_BK);
//bg = CCScale9Sprite::createWithSpriteFrameName(S_BTN_BACKGROUNP);
bg->setPosition(Vec2(winOrigin.x+winSize.width/2,winOrigin.y+130*winSize.height/1080));
//============================
bRet = true;
} while (0);
return bRet;
}

void Toast::onExit()
{
LayerColor::onExit();
}

void Toast::initToast( string msg,float time )
{
auto pLabel = Label::createWithSystemFont(msg.c_str(), S_FONE, *pSTR_TOAST_SIZE);
pLabel->setColor(COLOR_STRING_BLACK);
Size tSizeOrig=bg->getContentSize();
Size tTargetSize=pLabel->getContentSize();
//bg->setContentSize(CCSizeMake(pLabel->getContentSize().width+10,pLabel->getContentSize().height+10));
bg->setScaleX( ( tTargetSize.width / tSizeOrig.width )); //利用CCSPRITE 需額外進行縮放
bg->setScaleY( ( tTargetSize.height / tSizeOrig.height)); //利用CCSPRITE 需額外進行縮放
bg->setColor(Color3B(240,240,240));
bg->addChild(pLabel, 1);
this->addChild(bg,10);
pLabel->setPosition(bg->getContentSize()/2);
pLabel->setScaleX( ( tSizeOrig.width /tTargetSize.width  )); //利用CCSPRITE 需額外進行縮放
pLabel->setScaleY( ( tSizeOrig.height/ tTargetSize.height )); //利用CCSPRITE 需額外進行縮放
pLabel->runAction(Sequence::create(FadeIn::create(time/5),
DelayTime::create(time/5*3),FadeOut::create(time/5),NULL));
bg->runAction(Sequence::create(FadeIn::create(time/5),
DelayTime::create(time/5*3),FadeOut::create(time/5),
//CallFunc::create(this,callfunc_selector(Toast::removeSelf)),NULL));
        CallFunc::create(CC_CALLBACK_0(Toast::removeSelf, this)),NULL));

//=========================
//this->scheduleOnce(schedule_selector(XYToast::removeSelf),time);
}

void Toast::removeSelf()
{
this->removeFromParentAndCleanup(true);
}

2016年5月11日 星期三

0511 C如何呼叫SWIFT

/////////////////////新版作法
在.swift 中 
@_silgen_name ("isConnectedToNetwork") func isConnectedToNetwork()->Bool
指定函數名稱 (swift 2.2 以前用 @asmname )

在CPP中 不用引用.H
extern bool isConnectedToNetwork();

return isConnectedToNetwork();

將CPP 改為.mm 就可以OC 與C 相互編譯


////////////////////////////////////////
1.C 引用 #include <ProjectName-Swift.h>
2. ProjectName-Swift.h 產生記得要開啟 Build Settings->Packaging -> Defines Module = YES
3. ProjectName 不能有空格或是非子母字元否則預設會用底線取代,通常預設是TARGETS 名稱
   名稱可以看屬性 swift complier->Objective-c Generated 
//參考文件
第三部分 C 調用 Swift

如果項目裡加入了 C 文件,那麼它可以調用我們的 Swift 函數麼?答案是可以的,而且令人吃驚地透明。這也許是因為 Apple 所宣傳的,Small Runtime 概念吧。極小的語言運行時。

和 Objective-C 混編類似,配置好 Bridging Header 的項目,在 .c .h .m 文件中都可以使用一個叫做 ProjectName-Swift.h 的頭文件,其中包含 Swift 代碼導出的函數等。

參考之前的 Objective-C 和 C 交互我們可以知道,說到底交互就是鏈接過程,只要鏈接的時候能找到符號就可以。

不過不能高興太早,Swift 是帶類、枚舉、協議、多態、泛型等的高級語言,符號處理明顯要比 C 中的複雜的多,現代語言一般靠 name mangle 來解決這個問題。也就是說一個 Swift 函數,在編譯到 .o 的時候,名字就不是原來那麼簡單了。比如 __TFV5hello4Rectg9subscriptFOS_9DirectionSi 這樣的名字。

Xcode 自帶了個工具, 可以查看這些 mangled name 到底是什麼東西:
  1. xcrun swift-demangle __TFV5hello4Rectg9subscriptFOS_9DirectionSi 
  2. _TFV5hello4Rectg9subscriptFOS_9DirectionSi ---> hello.Rect.subscript.getter (hello.Direction) -> Swift.Int 
當我們從 C 調用的時候,應該規避這樣的名字。還記得前面的 @asmname 麼?沒錯,它可以用於指定 Swift 函數的符號名,我猜測應該有指定 mangled name 的作用,但是不是特別確定。

這裡隨便指定個例子先。
  1. @asmname("say_hello") func say_hello() -> Double { 
  2.     println("This is say_hello() in swift"
  3.     return 3.14 
然後在 .c 文件中:
  1. #include <ProjectName-Swift.h> 
  2.  
  3. extern double say_hello(); 
  4.  
  5. int some_func() { 
  6.   say_hello(); // or capture its value and process it 
  7.   return 0 
對於函數而言 extern 必須手動加上,對於 class 、 protocol ,會在生成的頭文件裡。

按照這個思路,其實很容易實現 Swift 調用 C 中調用了 Swift 函數的函數。這意味著,可以通過簡單的方法封裝支持向 C 傳遞 Swift block 作為回調函數。難度中上,對於有過類似擴展編寫經驗的人來說很簡單


//參考文件設定 如何產生  ProjectName-Swift.h 
自翻譯
1.專案名稱不能有空格
2.Build Settings,  Packaging 的設定
    Defines Module = YES
原文
Now it works.
  1. Project must have a Module Name not including spaces.
  2. Defines Module must be set to Yes in Build Settings, under Packaging.
Finally works. Thanks to everyone for the help :-)

2016年5月10日 星期二

0510 SWIFT WIFI 讀取


1. 使用方式:
建立 IfWifiList.swift 檔案
2.加入XCODE中
3.系統詢問是否要建立標頭黨 確認是
4.在新建立的標頭檔加入 #import "ifaddrs.h"
至此就可以編譯了

參考使用範例 呼叫程式

SWIFT 程式範例 (詳情參見wifiTest2 範例)
    @IBAction func btnGetIpPress(sender: UIButton) {
        //利用不同函數 驗證wifi指令
        var number = getAddressList(1) //取得現在IP列表
        number = getSSIDList2(number+1)  //取得現在SSID
        getSSIDList1(number+1)
   
    }

    // MARK: 呼叫範例程式
    // 傳入參數為列印位置高度
    func getAddressList(startIdx:Int)->Int{
        let wifiIPList=ifaddrsSwift.getIFAddresses()
        let wifiCount = CFArrayGetCount(wifiIPList)
        creatLabel(startIdx,showText: "wifi count \(wifiCount)")
        var count = startIdx
        for wifiIP in wifiIPList {
            count++;
            creatLabel(count,showText: wifiIP )
        }
        return count
    }
    func getSSIDList2(startIdx:Int) -> Int{
        let ssidList = ifaddrsSwift.getSSID()
        let wifiCount = ssidList.ssidCount
        let arrayList = ssidList.ssidList
        creatLabel(startIdx,showText: "SSID  count \(wifiCount)")
        var count=startIdx
        for wifiIP in arrayList {
            count++;
            creatLabel(count,showText: wifiIP)
        }
        return count
    }
    func getSSIDList1(startIdx:Int) -> Int{
     
        let ssidList = NEHotspotHelper.supportedNetworkInterfaces()
        let wifiCount = ssidList.count
        let arrayList = ssidList
        creatLabel(startIdx,showText: "supp count \(wifiCount)")
        var count=startIdx
        for wifiIP in arrayList {
            count++;
            creatLabel(count,showText: wifiIP as! String)
        }
        return count
    }

 //////////////////////////////////////////////////////////////////////
//
//  IfWifiList.swift
//  WifiTest2
//
//  Created by thai bob on 2015/12/23.
//  Copyright © 2015年 thai bob. All rights reserved.
//
//存放有關網路相關函數

import Foundation
import NetworkExtension //for NEHotspotHelper
import SystemConfiguration.CaptiveNetwork //CNCopySupportedInterfaces

// MARK: 網卡相關函數
public class ifaddrsSwift {
 
 
    //取得IP
    class func getIFAddresses() -> [String] {
     
        var addresses = [String]()
     
        // Get list of all interfaces on the local machine:
        var ifaddr : UnsafeMutablePointer<ifaddrs> = nil
        if getifaddrs(&ifaddr) == 0 {
         
            // For each interface ...
            for (var ptr = ifaddr; ptr != nil; ptr = ptr.memory.ifa_next) {
                let flags = Int32(ptr.memory.ifa_flags)
                var addr = ptr.memory.ifa_addr.memory
             
                // Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
                if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
                    if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) {
                     
                        // Convert interface address to a human readable string:
                        var hostname = [CChar](count: Int(NI_MAXHOST), repeatedValue: 0)
                        if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count),
                            nil, socklen_t(0), NI_NUMERICHOST) == 0) {
                                if let address = String.fromCString(hostname) {
                                    addresses.append(address)
                                }
                        }
                    }
                }
            }
            freeifaddrs(ifaddr)
        }
     
        return addresses
    }
 
    //get ssid
    class func getSSID() -> (ssidCount:Int,ssidList:[String]) {
     
        var ssidStringList = [String]()
      //  var ssidList:CFArray?=nil
        var errorCode=0
        let ssidIfList = CNCopySupportedInterfaces()
        if ssidIfList == nil {
            errorCode = -1
        }else if CFArrayGetCount(ssidIfList) == 0{
            errorCode = -2
        }else{
            errorCode = CFArrayGetCount(ssidIfList)
            let totalCount = errorCode
         
            for i in 0..<totalCount{
                let interfaceName: UnsafePointer<Void> = CFArrayGetValueAtIndex(ssidIfList, i)
                let rec = unsafeBitCast(interfaceName, AnyObject.self)
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)")
                if unsafeInterfaceData != nil {
                    let interfaceData = unsafeInterfaceData! as Dictionary!
                    let currentSSID = interfaceData["SSID"] as! String
                    ssidStringList.append(currentSSID)
                    print("\(i)=\(currentSSID)")
                }
                else {
                    errorCode--
                    //currentSSID = ""
                }
            }
        }
//        if bError != 0 {
//            currentSSID = "Error"
//        }
     
        return (errorCode,ssidStringList)
    }
 
    //get ssid
    class func getSSID2() -> (ssidCount:Int,ssidList:[String]) {
        var ssidList = [String]()
        var ssidCount = 0
        for newOne in NEHotspotHelper.supportedNetworkInterfaces(){
            ssidCount++
            ssidList.append(newOne.SSID)
        }
        return (ssidCount,ssidList)
    }
 
}





// MARK:可能可以取得SSID的程式碼
Register your app as Hotspot helper.
#import <NetworkExtension/NetworkExtension.h>

NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];
NSLog(@"Networks %@",networkInterfaces);
UPDATE (Sept. 11th)
The following Captive Network APIs have been re-enabled in the latest version of iOS 9 instead.
CNCopySupportedInterfaces
CNCopyCurrentNetworkInfo
UPDATE (Sept. 16th)
If you still prefer to use NetworkExtension and Apple gave you permission to add the entitlements, then you can do this to get the wifi information:
for(NEHotspotNetwork *hotspotNetwork in [NEHotspotHelper supportedNetworkInterfaces]) {
    NSString *ssid = hotspotNetwork.SSID;
    NSString *bssid = hotspotNetwork.BSSID;
    BOOL secure = hotspotNetwork.secure;
    BOOL autoJoined = hotspotNetwork.autoJoined;
    double signalStrength = hotspotNetwork.signalStrength;
}

2016年5月5日 星期四

0505 file save by cocos2d-x (andriod ios pc)

1.利用cocos2d-x 進行開檔 存檔範例
2. CC_SYNTHESIZE 使用範例
3.獨立的class 建立 getInstance() 範例

 .h
#ifndef __ROBOTFILESAVE__
#define __ROBOTFILESAVE__
#include <stdio.h>
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
const char G_FileName_Setting[48] ="AppSetting.ini";
class FileSetting :Node
{
private:
    string filePath;
public:
    CREATE_FUNC(FileSetting);
    virtual bool init() override;
    FileSetting();
    ~FileSetting();
    static FileSetting* getInstance();
    void LoadFileSetting();
    void SaveFileSetting();
public: //通用函數
    CC_SYNTHESIZE(int, timeSyncHint, TimeSyncHint);
    CC_SYNTHESIZE(int, stopActionHint, StopActionHint);
};

#endif //__ROBOTFILESAVE__

.cpp
 #include "Def_ImageList.h"
#include "Robot_FileSave.h"
//是否要提示顯示同步是窗
static FileSetting* fileSetting=nullptr;
FileSetting::FileSetting():
stopActionHint(0),
timeSyncHint(0)
{
   
    filePath = FileUtils::getInstance()->getWritablePath()+"\\"+G_FileName_Setting;
   
}
FileSetting::~FileSetting()
{
   
}
FileSetting* FileSetting::getInstance()
{
   
    if (!fileSetting) {
       
        fileSetting = new FileSetting;
       
        fileSetting->init();
       
    }
   
    return fileSetting;
   
}
bool FileSetting::init()
{
    if (!Node::init())
    {
        return false;
    }
    //載入設定
    LoadFileSetting();
    return true;
}
void FileSetting::SaveFileSetting()
{
    FILE *fp =fopen(filePath.c_str(),"w");
    if(fp!=NULL)
    {
        fprintf(fp,"TimeSyncHint = %d /n",timeSyncHint);
        fprintf(fp,"StopActionHint = %d /n",stopActionHint);
        fclose(fp);
    }
    else
    {
        log("open fail:%s ",filePath.c_str());
    }
}
void FileSetting::LoadFileSetting()
{
    FILE *fp =fopen(filePath.c_str(),"r");
    if(fp==NULL)
    { //全新紀錄 寫入新設定
        SaveFileSetting();
    }
    else
    { //載入設定
        fscanf(fp,"TimeSyncHint = %d /n",&timeSyncHint);
        fscanf(fp,"StopActionHint = %d /n",&stopActionHint);
        fclose(fp);
    }
}

2016年4月28日 星期四

0428 cocos2dx 對話框 範例

1.無法立即編輯 但是確定可以!須自行補上缺失的h
2.按鈕直接引用 button 元件
3. 加入 CC_SYNTHESIZE ,將變數獨立。
   有加入背景變暗功能  m_UI_Background
4.使用方式
init:
Layer* setTimeDialog = DislogSetTime::create();
    //setTimeDialog->setPosition(winSize*0.5);
    setTimeDialog->setVisible(false);
  addChild(setTimeDialog,16);
show:
    setTimeDialog->setVisible(true);
    DislogSetTime*  pDialog=(DislogSetTime*)setTimeDialog;
    pDialog->setDayName(sDayString);
    pDialog->setSetTime(scheduleTime);
    pDialog->showDialog();
Hide:
    setTimeDialog->setVisible(false);
    DislogSetTime*  pDialog=(DislogSetTime*)setTimeDialog;
    pDialog->HideDialog();

程式碼:
////////////////////////////////////////////////////////////
#ifndef __ROBOTDIALOG_H__
#define __ROBOTDIALOG_H__
#include "Def_ImageList.h"
#include "Robot_NumberPicker.h"
#include "extensions/cocos-ext.h"
#include "ui/CocosGUI.h"
using namespace ui;
using namespace cocos2d;
//頁面種類
enum _DIALOGSETTIMEITEM_
{
    DIATIME_LAYER_BK=0,
    DIATIME_SPRITE_CANEL,
    DIATIME_SPRITE_SAVE,
    DIATIME_NOTOUCH,    //此線以下不偵測TOUCH
    DIATIME_LAB_MESSAGE=DIATIME_NOTOUCH,
    DIATIME_PICKER_MIN,
    DIATIME_PICKER_HOUR,
    DIATIME_SIZE,
   
};

class DislogSetTime: public Layer
{
    //對話框
protected:
    //初始化對話框
    void InitDialog();
    /* 加載對話框
     * @parm:msg 消息 顯示在界面上的提示消息
     * @parm:fun 回調函數 給確定按鈕調用的
     * @parm:isNeedCancel 是否需要取消按鈕
     * @parm:isModalDialog 是否是模態對話框
     */
    void LoadDialog(std::string msg,std::function<void(Ref*)>  fun,bool isNeedCancel = false,bool isModalDialog = true);
    //對話框加載完成
//    void LoadDialogFinish(Armature *a, MovementEventType b, std::string c);
    //隱藏對話框
    void HideDialog();

    //隱藏對話框完成
//    void HideDialogFinish(Armature *a, MovementEventType b, std::string c);
    //對話框取消按鈕callback
    void PressBtnCancel(Ref *pSender, Widget::TouchEventType type);
    //對話框確認按鈕callback
    void PressBtnConfirm(Ref *pSender, Widget::TouchEventType type);
    //virtual void SetScene();
    //標誌變量
public:
    //視窗變數
    Size visibleSize;
    Vec2 origin;
    bool m_IsNeedExit;
    //UI變量
public:
    Sprite* m_spr_ExitTip; //退出提示
    Sprite* Dialog; //對話框
    Label* m_DialogMsg; //對話框消息
    UINumberPicker *m_Hourpicker;
    UINumberPicker *m_Minatepicker;
    Button* m_DialogConfirm; //對話框確認按鈕
    Button* m_DialogCancel;  //對話框取消按鈕
    //層變量
    Layer* m_UI_Dialog;            //對話框層 最高層
    Layer* m_UI_Background;        //背景層 底層
   
public:
    std::function<void(Ref*)> m_Dialog_ConfirmCallback; //對話框確認回調
    //---------------函數---------------------------
    CREATE_FUNC(DislogSetTime);
    DislogSetTime();
    ~DislogSetTime();
    virtual bool init() override;
    virtual void onEnter() override;
    virtual void onExit() override;
    void releaseUI();
    //bool onTouchBegan(Touch* touch, Event* event) override;
    //顯示對話框
    void showDialog();
//特別獨立出來的單一變數
    CC_SYNTHESIZE(string, dayName, DayName);
    CC_SYNTHESIZE(time_t, setTime, SetTime);
    //工具
public:
    Point getCenterPoint() { return Point(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2); };
    Point getOriginPoint() { return Point(origin.x,origin.y); };
};

#endif // __ROBOTDIALOG_H__

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "Def_ImageList.h"
#include "Robot_Dialog.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace std;
using namespace cocos2d::ui;

DislogSetTime::DislogSetTime()
{

}
DislogSetTime::~DislogSetTime()
{

}
bool DislogSetTime::init()
{
    if (!Layer::init())
    {
        return false;
    }
    visibleSize = Director::getInstance()->getVisibleSize();
    origin = Director::getInstance()->getVisibleOrigin();
    m_UI_Dialog = Layer::create();
    addChild(m_UI_Dialog,40);
    m_UI_Dialog->setPosition(getOriginPoint());
   
    //第一個參數是顏色ccc4(r,g,b,a) a取值(0~255),越大越不透明 下面兩個參數為寬高,不傳默認為屏幕大小
    m_UI_Background = LayerColor::create(Color4B(0,0,0,153),visibleSize.width,visibleSize.height);
    m_UI_Background->setPosition(getOriginPoint());
    this->addChild(m_UI_Background,10);
   
    InitDialog();
  //  SetScene();
    return true;
}
//初始化對話框
void DislogSetTime::InitDialog()
{
//    auto ImageScale = Director::getInstance()->getContentScaleFactor();
    const float winWidth=950;
    const float winHeight=900;
    float W_unit=1.0f;
    float H_unit=1.0f;

    Point LabSite_UM_MESSAGE=Vec2(winWidth*0.5*W_unit,(winHeight-25)*H_unit);
    Point PickerSiteOnBtn_Minate=Vec2(0.7*winWidth*W_unit,winHeight*0.3*H_unit);
    Point PickerSiteOnBtn_Hour=Vec2(0.3*winWidth*W_unit,winHeight*0.3*H_unit);
    //設定滾輪大小
    Size slotItemSize =Size(210*W_unit,150*H_unit);
    //建立對話框
    Dialog = Sprite::createWithSpriteFrameName(S_BTN_DIALOG_BK);
//    Dialog->setContentSize(Size(winWidth*W_unit,winHeight*H_unit));
    Dialog->setPosition(getCenterPoint());
    m_UI_Dialog->addChild(Dialog);
    Dialog->setVisible(true);
   
    //視窗說明文件
    m_DialogMsg = Label::createWithSystemFont(STR_RESERV_SetTime_CHS, S_FONE, getFontSize(G_FSIZE_RESERV_SetTime));
    m_DialogMsg->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP);
    m_DialogMsg->setTextColor(COLOR_STR_BLUE);
    m_DialogMsg->setPosition(LabSite_UM_MESSAGE);
    Dialog->addChild(m_DialogMsg,15);
   
    //加入數字滾輪:分
    m_Minatepicker = UINumberPicker::create();
    m_Minatepicker->setItemSize(slotItemSize.width,slotItemSize.height);
    m_Minatepicker->setDataprovider(3, 0, 59,1);
    m_Minatepicker->setPosition(PickerSiteOnBtn_Minate);     //set the postions
    //    picker->setSkinFrameName(S_RESERVATION_SETTIME_BK, S_SWITCH_BACKGROUNP);
    Dialog->addChild(m_Minatepicker,12);
     m_Minatepicker->setTag(DIATIME_PICKER_MIN);
//    m_Minatepicker->valueChangeHandler = std::bind(&DislogSetTime::pickerChangeHandler,this, std::placeholders::_1);
   
    //加入數字滾輪:時
    m_Hourpicker = UINumberPicker::create();
    m_Hourpicker->setItemSize(slotItemSize.width,slotItemSize.height);
    m_Hourpicker->setDataprovider(3, 0, 23,1);
    m_Hourpicker->setPosition(PickerSiteOnBtn_Hour);     //set the postions
    //    picker->setSkinFrameName(S_RESERVATION_SETTIME_BK, S_SWITCH_BACKGROUNP);
    Dialog->addChild(m_Hourpicker,12);
//    m_Hourpicker->valueChangeHandler = std::bind(&DislogSetTime::pickerChangeHandler,this, std::placeholders::_1);
    m_Hourpicker->setTag(DIATIME_PICKER_HOUR);
   
    //底下兩個按鈕
    //BUTTON元件 版本
    m_DialogConfirm = Button::create();
    m_DialogConfirm->setTouchEnabled(false);
    m_DialogConfirm->loadTextureNormal(S_BTN_DIALOG_RIGHT, Widget::TextureResType::PLIST);
    m_DialogConfirm->setTitleText(STR_BTN_Save_CHS);
    m_DialogConfirm->setTitleFontSize(getFontSize(G_FSIZE_DIALOG_BtnLabel));
    m_DialogConfirm->setTitleColor(COLOR_BG_WHITE);
    m_DialogConfirm->setPosition(Vec2(winWidth*W_unit,0*H_unit));
    m_DialogConfirm->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT);
    m_DialogConfirm->addTouchEventListener(CC_CALLBACK_2(DislogSetTime::PressBtnConfirm,this));
    Dialog->addChild(m_DialogConfirm,12);
    m_DialogCancel = Button::create();
    m_DialogCancel->loadTextureNormal(S_BTN_DIALOG_LEFT, Widget::TextureResType::PLIST);
    m_DialogCancel->setTitleText(STR_BTN_Canel_CHS);
    m_DialogCancel->setTitleFontSize(getFontSize(G_FSIZE_DIALOG_BtnLabel));
    m_DialogCancel->setTitleColor(COLOR_BG_WHITE);
    m_DialogCancel->setPosition(Vec2(0,0));
    m_DialogCancel->setAnchorPoint(Vec2::ZERO);
    m_DialogCancel->addTouchEventListener(CC_CALLBACK_2(DislogSetTime::PressBtnConfirm,this));
    m_DialogCancel->addTouchEventListener(CC_CALLBACK_2(DislogSetTime::PressBtnCancel, this));
    Dialog->addChild(m_DialogCancel,12);
}

//void DislogSetTime::SetScene()
//{
//    auto bg = ImageView::create();
//    bg->setContentSize(Size(950,900));
//    bg->setPosition(getCenterPoint());
//    auto listen = EventListenerTouchOneByOne::create();
//    listen->onTouchBegan = CC_CALLBACK_2(DislogSetTime::onTouchBegan, this);
//    _eventDispatcher->addEventListenerWithSceneGraphPriority(listen,Dialog);
//    m_UI_Background->addChild(bg);
//}
//bool DislogSetTime::onTouchBegan(Touch* touch, Event* event)
//{
//    auto target = static_cast<Layer*>(event->getCurrentTarget());
//    if(target==nullptr)
//    {
//        return true;
//    }
////    log("%s",__PRETTY_FUNCTION__);
////    Vec2 touchLocation = touch->getLocation();
////    Vec2 nodePosition = target->convertToNodeSpace( touchLocation );
//    if(!isVisible())
//        return false;
//    return true;
//}
void DislogSetTime::releaseUI()
{
    time_t setTime=getSetTime();
    char sShowHelpStr[48];
    sprintf(sShowHelpStr,STR_RESERV_SetTime_CHS, getDayName().c_str());
    m_DialogMsg->setString(sShowHelpStr);
    tm *pTime=localtime(&setTime);
    m_Hourpicker->setValue(pTime->tm_hour);
    m_Minatepicker->setValue(pTime->tm_min);
   
}
//进入
void DislogSetTime::onEnter()
{
    Layer::onEnter();
}
//退出
void DislogSetTime::onExit()
{
    Layer::onExit();
}
//顯示對話框
void DislogSetTime::showDialog()
{
    m_UI_Dialog->setVisible(true);
    m_UI_Background->setVisible(true);
    m_DialogConfirm->setVisible(true);
    m_DialogConfirm->setTouchEnabled(true);
    m_DialogCancel->setVisible(true);
    m_DialogCancel->setTouchEnabled(true);
   
    auto listener1 = EventListenerTouchOneByOne::create();//创建一个触摸监听
    listener1->setSwallowTouches(true);//设置不想向下传递触摸
    listener1->onTouchBegan = [](Touch* touch, Event* event){
        CCLOG("touch Swallow");
        return true;
    };
    //增加遮蔽版
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1,m_UI_Dialog);
   
    releaseUI();
}
//隐藏對話框
void DislogSetTime::HideDialog()
{
    m_UI_Dialog->setVisible(false);
    m_UI_Background->setVisible(false);
    m_DialogConfirm->setVisible(false);
    m_DialogConfirm->setTouchEnabled(false);
    m_DialogCancel->setVisible(false);
    m_DialogCancel->setTouchEnabled(false);
    //移除遮蔽版
    _eventDispatcher->removeEventListenersForTarget(m_UI_Dialog);
}
//取消按鈕
void DislogSetTime::PressBtnCancel(Ref *pSender, Widget::TouchEventType type)
{
    switch (type)
    {
        default:
            break;
        case Widget::TouchEventType::ENDED:
        {
            HideDialog();
            break;
        }
    }

}
//確認按鈕
void DislogSetTime::PressBtnConfirm(Ref *pSender, Widget::TouchEventType type)
{
    switch (type)
    {
        default:
            break;
        case Widget::TouchEventType::ENDED:
        {
            HideDialog();
            break;
        }
    }
   
}
//////////////////////////////////////////

cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...