Skip to content

Instantly share code, notes, and snippets.

@astronaughts
Created December 19, 2011 15:14
Show Gist options
  • Save astronaughts/1497619 to your computer and use it in GitHub Desktop.
Save astronaughts/1497619 to your computer and use it in GitHub Desktop.
Baruth vol.1
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win = Titanium.UI.createWindow();
win.hideTabBar();
win.navBarHidden = true;
var tab = Titanium.UI.createTab({window: win});
var Z_INDEX_TOP = 3;
var Z_INDEX_BOTTOM = 0;
var currentShowView;
//--- 友達リストの表示 / 非表示
function switchFriendList(button){
rightView.showed = ! rightView.showed;
leftView.zIndex = rightView.zIndex - 1;
var left = rightView.showed ? -290 : 0;
var animation = Ti.UI.createAnimation({left: left, duration: 350});
currentShowView.animate(animation);
}
//--- メインメニューの表示 / 非表示
function switchMainMenu(button){
leftView.showed = ! leftView.showed;
rightView.zIndex = leftView.zIndex - 1;
var left = leftView.showed ? 290 : 0;
var animation = Ti.UI.createAnimation({left: left, duration: 350});
currentShowView.animate(animation);
}
//--- コンテンツビューの切り替え
function switchCurrentView(nextShowView){
leftView.showed = false;
var beHidden = Ti.UI.createAnimation({left: 320, duration: 300});
beHidden.addEventListener("complete", function() {
currentShowView.hide();
currentShowView.zIndex = Z_INDEX_BOTTOM;
nextShowView.show();
nextShowView.zIndex = Z_INDEX_TOP;
var beShown = Ti.UI.createAnimation({left: 0, duration: 350});
nextShowView.animate(beShown);
currentShowView = nextShowView;
});
currentShowView.animate(beHidden);
}
//--- 右ボタンやー
function createRightButton(){
var button = Ti.UI.createButton({
top: 7,
right: 5,
width: 40,
height: 31,
title: "R",
});
button.addEventListener("click", function(e){
switchFriendList(e.source);
});
return button;
}
//--- 左ボタンやー
function createLeftButton(){
var button = Ti.UI.createButton({
top: 7,
left: 5,
width: 40,
height: 31,
title: "L",
});
button.addEventListener("click", function(e){
switchMainMenu(e.source);
});
return button;
}
// 右メニュー用ビューを作成
var rightView = Ti.UI.createView({
left: 0,
width: 320,
showed: false,
});
win.add(rightView);
// 左メニュー用ビューを作成
var leftView = Ti.UI.createView({
left: 0,
width: 320,
showed: false,
});
win.add(leftView);
// Baruth 画面のビューを作成
var baruthView = Ti.UI.createView({
backgroundColor: "#3333aa",
left: 320,
width: 320,
zIndex: Z_INDEX_BOTTOM,
});
win.add(baruthView);
// トップ画面のビューを作成
var topView = Ti.UI.createView({
backgroundColor: "#aa3333",
left: 0,
width: 320,
zIndex: Z_INDEX_TOP,
});
win.add(topView);
currentShowView = topView;
// 右ボタン
var r1 = createRightButton();
topView.add(r1);
var r2 = createRightButton();
baruthView.add(r2);
// 左ボタン
var l1 = createLeftButton();
topView.add(l1);
var l2 = createLeftButton();
baruthView.add(l2);
// 友達リスト用のテーブルビューを作成
var friendList = Ti.UI.createTableView({
data: [
{title: "変な友達を追加", hasChild: true},
{header: "3人", title: "シータケ", hasChild: true},
{title: "バズーカ", hasChild: true},
{title: "ムスコ", hasChild: true},
],
left: 30,
width: 290,
});
rightView.add(friendList);
friendList.addEventListener("click", function(e){
var friendWin = Ti.UI.createWindow({
backgroundColor: "#123456"
});
var backButton = Ti.UI.createButton({
top: 7,
left: 5,
width: 40,
height: 31,
title: "B",
});
friendWin.add(backButton);
backButton.addEventListener("click", function(){
friendWin.close();
});
friendWin.addEventListener("open", function(){
setTimeout(function(){
// チラつき防止のため非表示に
leftView.hide();
rightView.hide();
rightView.showed = false;
currentShowView.left = 0;
}, 500);
});
friendWin.addEventListener("close", function(){
// チラつき防止用に非表示にしていたビューを表示
leftView.show();
rightView.show();
});
tab.open(friendWin, {animated:true});
});
// メニュー用のテーブルビューを作成
var mainMenu = Ti.UI.createTableView({
data: [
{header: "astronaughts", title: "ホーム"},
{title: "Baruth"},
{title: "ログオフ"},
],
left: 0,
width: 320,
});
leftView.add(mainMenu);
mainMenu.addEventListener("click", function(e){
switch(e.index){
case 0: // トップ
switchCurrentView(topView);
break;
case 1: // Baruth
switchCurrentView(baruthView);
break;
case 2: // ログオフ
break;
}
});
tabGroup.addTab(tab);
tabGroup.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment