Browse Source

add-object-materials

faterhenry 6 years ago
parent
commit
9aff4a64cb

+ 67 - 1
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -41,8 +41,10 @@ import java.util.concurrent.CopyOnWriteArrayList
 import android.widget.SeekBar
 import com.bomostory.sceneeditmodule.DialogueColorData
 import com.bomostory.sceneeditmodule.SceneDrawer
+import com.bomostory.sceneeditmodule.navigationbar.actor.ObjectView
 import com.bomostory.sceneeditmodule.navigationbar.brush.BrushView
 import com.bomostory.sceneeditmodule.screen.view.*
+import kotlinx.android.synthetic.main.actor_select_view.view.*
 import kotlinx.android.synthetic.main.movie_item_view.*
 import kotlinx.android.synthetic.main.navigation_bar_view.view.*
 import kotlinx.android.synthetic.main.popupview_color_dialog.view.*
@@ -65,6 +67,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
     private var record = Record()
     private var resourceThemeBitmap = ArrayList<String>()
     private var resourceActorBitmap = ArrayList<ArrayList<String>>()
+    private var resourceObjectPath = ArrayList<String>()
     private lateinit var sceneAdapter: SceneAdapter
     private var isRecord = false
     private var isAutoSwipe = false
@@ -98,6 +101,12 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         project = Gson().fromJson<Project>(intent.getStringExtra("project"), Project::class.java)
         resourceThemeBitmap = project.sceneResource as ArrayList<String>
         resourceActorBitmap = project.actorResource as ArrayList<ArrayList<String>>
+        resourceObjectPath = ArrayList<String>().apply {
+            project.themeAssetIndex.contains.obj.values.forEach {
+                val path = "${project.assetFolder.path}/${it.smallFile}"
+                add(path)
+            }
+        }
         windowManager.defaultDisplay.getMetrics(monitorSize)
         var layoutPrams = sceneEditView.layoutParams
         layoutPrams.width = monitorSize.widthPixels
@@ -362,7 +371,7 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
     }
 
     private fun initActorRecyclerView() {
-        if (viewContainer.getChildAt(0) is SelectActorView) {
+        if (viewContainer.getChildAt(0) is SelectActorView || viewContainer.getChildAt(0) is ObjectView) {
             viewContainer.removeAllViews()
             startRecord.visibility = View.VISIBLE
             return
@@ -383,6 +392,18 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         actorRecyclerView.adapter = actorAdapter
         viewContainer.addView(selectActorView)
         selectActorView.layoutParams.width = monitorSize.widthPixels
+        selectActorView.btn_object.setOnClickListener {
+            viewContainer.removeAllViews()
+            var objectView = ObjectView(this)
+            objectView.setData(resourceObjectPath)
+            sceneEditView.findViewById<LayerView>(currentLayerIndex).setOnDragListener(objectDragListener())
+            viewContainer.addView(objectView)
+            objectView.layoutParams.width = monitorSize.widthPixels
+            objectView.btn_character.setOnClickListener {
+                viewContainer.removeAllViews()
+                initActorRecyclerView()
+            }
+        }
     }
     private fun initDialogueView(){
         if (viewContainer.getChildAt(0) is DialogueView) {
@@ -668,6 +689,18 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
             var actorRecyclerView = selectActorView.findViewById<RecyclerView>(R.id.select_actor_recycler_view)
             actorRecyclerView.layoutManager = layoutManager
             actorRecyclerView.adapter = actorAdapter
+            selectActorView.btn_object.setOnClickListener {
+                viewContainer.removeAllViews()
+                var objectView = ObjectView(this)
+                objectView.setData(resourceObjectPath)
+                sceneEditView.findViewById<LayerView>(currentLayerIndex).setOnDragListener(objectDragListener())
+                viewContainer.addView(objectView)
+                objectView.layoutParams.width = monitorSize.widthPixels
+                objectView.btn_character.setOnClickListener {
+                    viewContainer.removeAllViews()
+                    initActorRecyclerView()
+                }
+            }
             viewContainer.addView(selectActorView)
         }
     }
@@ -741,6 +774,24 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         sceneEditView.setLayerVisible(currentLayerIndex)
     }
 
+    private fun addObject(positionX: Int, positionY: Int, resourcePath: String) {
+        project.story?.let {
+            it.scenes?.let{
+                val actorData = Actor()
+                actorData.positionX = positionX
+                actorData.positionY = positionY
+                actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
+                actorData.sideLength = ACTOR_WIDTH
+                actorData.sideHeight = ACTOR_HEIGHT
+                actorData.resourcePath = resourcePath
+                actorData.parentLayerIndex = currentLayerIndex
+                actorData.isMovable = true
+                it[currentSceneIndex].layers[currentLayerIndex].actors.add(actorData)
+                sceneEditView.scene = it[currentSceneIndex]
+            }
+        }
+        sceneEditView.findViewById<LayerView>(currentLayerIndex).setOnDragListener(objectDragListener())
+    }
     private fun addDialogue(positionX: Int, positionY: Int, resource: Int) {
         project.story?.let {
             it.scenes?.let{
@@ -1170,6 +1221,21 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         }
     }
 
+    private fun objectDragListener() : View.OnDragListener {
+        return View.OnDragListener {v, event ->
+            when (event.action) {
+                DragEvent.ACTION_DRAG_STARTED -> {
+                    return@OnDragListener true
+                }
+                DragEvent.ACTION_DROP -> {
+                    addObject(event.x.toInt() - 100, event.y.toInt() - 100, event.clipData.getItemAt(0).text.toString())
+                    return@OnDragListener true
+                }
+            }
+            return@OnDragListener true
+        }
+    }
+
     override fun onSceneTouch(){
         unSelectActor()
         sceneEditView.setLayerVisible(currentLayerIndex)

+ 39 - 0
src/main/java/com/bomostory/sceneeditmodule/navigationbar/actor/ObjectAdapter.kt

@@ -0,0 +1,39 @@
+package com.bomostory.sceneeditmodule.navigationbar.actor
+
+import android.graphics.drawable.Drawable
+import android.support.v7.widget.RecyclerView
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.item_actor.view.*
+
+class ObjectAdapter(var data: ArrayList<String>, var onTouchListeners: ArrayList<View.OnTouchListener>): RecyclerView.Adapter<ObjectAdapter.ViewHolder>() {
+
+
+    override fun getItemCount(): Int {
+        return data.size
+    }
+
+    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
+        holder.bind(data?.get(position), onTouchListeners[position])
+//        holder.bind(data?.get(position))
+    }
+
+    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ObjectAdapter.ViewHolder {
+        val v1 = LayoutInflater.from(parent.context).inflate(R.layout.dialogue_item, parent, false)
+        return ViewHolder(v1)
+    }
+
+    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
+        fun bind(ObjectResource: String, onTouchListener: View.OnTouchListener) {
+            itemView.actor_image.setImageDrawable(Drawable.createFromPath(ObjectResource))
+            itemView.actor_image.setOnTouchListener(onTouchListener)
+        }
+    }
+//    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
+//        fun bind(ObjectResource: String) {
+//            itemView.actor_image.setImageDrawable(Drawable.createFromPath(ObjectResource))
+//        }
+//    }
+}

+ 74 - 0
src/main/java/com/bomostory/sceneeditmodule/navigationbar/actor/ObjectView.kt

@@ -0,0 +1,74 @@
+package com.bomostory.sceneeditmodule.navigationbar.actor
+
+import android.content.ClipData
+import android.content.ClipDescription
+import android.content.Context
+import android.support.v7.widget.LinearLayoutManager
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.MotionEvent
+import android.view.View
+import android.widget.ImageView
+import android.widget.LinearLayout
+import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.object_select_view.view.*
+
+class ObjectView: LinearLayout {
+
+    constructor(context : Context) : super(context) {
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet): super(context, attrs) {
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs, defStyle) {
+        initView()
+    }
+
+    private var objectData = ArrayList<String>()
+    private var objectListeners = ArrayList<View.OnTouchListener>()
+    private var objectAdapter = ObjectAdapter(objectData, objectListeners)
+
+    private fun initView(){
+        val inflater = LayoutInflater.from(context)
+        inflater.inflate(R.layout.object_select_view, this, true)
+    }
+
+    fun setData(objectData: ArrayList<String>){
+        rv_object_view.apply {
+            adapter = objectAdapter
+            layoutManager = LinearLayoutManager(context).apply {
+                orientation = LinearLayoutManager.HORIZONTAL
+            }
+        }
+        this.objectData.apply {
+            clear()
+            for (i in 0 until objectData.size){
+                add(objectData[i])
+            }
+        }
+        this.objectListeners.apply {
+            clear()
+            for (i in 0 until objectData.size){
+                add(boMoOnTouchListener(objectData[i]))
+            }
+        }
+        objectAdapter.notifyDataSetChanged()
+    }
+    private fun boMoOnTouchListener(resource: String) : View.OnTouchListener {
+        return View.OnTouchListener { view, motionEvent ->
+            when (motionEvent.action) {
+                MotionEvent.ACTION_DOWN -> {
+                    val item = ClipData.Item(resource)
+                    val mimeTypes = arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN)
+                    val dragData = ClipData(null, mimeTypes, item)
+                    val shadow = View.DragShadowBuilder(view.findViewById<ImageView>(R.id.actor_image))
+                    view.findViewById<ImageView>(R.id.actor_image).startDrag(dragData, shadow, null, View.DRAG_FLAG_GLOBAL)
+                }
+            }
+            return@OnTouchListener true
+        }
+    }
+}

+ 24 - 0
src/main/res/drawable/ic_character.xml

@@ -0,0 +1,24 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M17.5,8c0.46,0 0.91,-0.05 1.34,-0.12C17.44,5.56 14.9,4 12,4c-0.46,0 -0.91,0.05 -1.34,0.12C12.06,6.44 14.6,8 17.5,8zM8.08,5.03a8.046,8.046 0,0 0,-3.66 4.44,8.046 8.046,0 0,0 3.66,-4.44z"
+      android:strokeAlpha="0.3"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"
+      android:fillAlpha="0.3"/>
+  <path
+      android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,4c2.9,0 5.44,1.56 6.84,3.88 -0.43,0.07 -0.88,0.12 -1.34,0.12 -2.9,0 -5.44,-1.56 -6.84,-3.88C11.09,4.05 11.54,4 12,4zM8.08,5.03a8.046,8.046 0,0 1,-3.66 4.44,8.046 8.046,0 0,1 3.66,-4.44zM12,20c-4.41,0 -8,-3.59 -8,-8 0,-0.05 0.01,-0.1 0.01,-0.15 2.6,-0.98 4.68,-2.99 5.74,-5.55a9.942,9.942 0,0 0,9.92 3.46c0.21,0.71 0.33,1.46 0.33,2.24 0,4.41 -3.59,8 -8,8z"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"/>
+  <path
+      android:pathData="M9,13m-1.25,0a1.25,1.25 0,1 1,2.5 0a1.25,1.25 0,1 1,-2.5 0"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"/>
+  <path
+      android:pathData="M15,13m-1.25,0a1.25,1.25 0,1 1,2.5 0a1.25,1.25 0,1 1,-2.5 0"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"/>
+</vector>

+ 16 - 0
src/main/res/drawable/ic_object.xml

@@ -0,0 +1,16 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M7,16c1.82,0 3.41,-1.3 3.87,-3H3.13c0.46,1.7 2.05,3 3.87,3zM8,7c0,1.82 1.3,3.41 3,3.87V3.13C9.3,3.59 8,5.18 8,7zM17,8c-1.82,0 -3.41,1.3 -3.87,3h7.74c-0.46,-1.7 -2.05,-3 -3.87,-3zM13,13.13v7.74c1.7,-0.46 3,-2.04 3,-3.87s-1.3,-3.41 -3,-3.87z"
+      android:strokeAlpha="0.3"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"
+      android:fillAlpha="0.3"/>
+  <path
+      android:pathData="M23,12c0,-3.25 -2.75,-6 -6,-6 -1.52,0 -2.93,0.6 -4,1.57L13,1h-1C8.75,1 6,3.75 6,7c0,1.52 0.6,2.93 1.57,4L1,11v1c0,3.25 2.75,6 6,6 1.52,0 2.93,-0.6 4,-1.57L11,23h1c3.25,0 6,-2.75 6,-6 0,-1.52 -0.6,-2.93 -1.57,-4L23,13v-1zM7,16c-1.82,0 -3.41,-1.3 -3.87,-3h7.74c-0.46,1.7 -2.05,3 -3.87,3zM11,10.87C9.3,10.41 8,8.82 8,7c0,-1.82 1.3,-3.41 3,-3.87v7.74zM13,20.87v-7.74c1.7,0.46 3,2.04 3,3.87s-1.3,3.41 -3,3.87zM13.13,11c0.46,-1.7 2.04,-3 3.87,-3s3.41,1.3 3.87,3h-7.74z"
+      android:fillColor="#FFF"
+      android:fillType="nonZero"/>
+</vector>

+ 10 - 0
src/main/res/drawable/ic_style.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M2.53,19.65l1.34,0.56v-9.03l-2.43,5.86c-0.41,1.02 0.08,2.19 1.09,2.61zM22.03,15.95L17.07,3.98a2.013,2.013 0,0 0,-1.81 -1.23c-0.26,0 -0.53,0.04 -0.79,0.15L7.1,5.95a1.999,1.999 0,0 0,-1.08 2.6l4.96,11.97a1.998,1.998 0,0 0,2.6 1.08l7.36,-3.05a1.994,1.994 0,0 0,1.09 -2.6zM7.88,8.75c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM5.88,19.75c0,1.1 0.9,2 2,2h1.45l-3.45,-8.34v6.34z"
+      android:fillColor="#FFECB3"
+      android:fillType="nonZero"/>
+</vector>

+ 29 - 11
src/main/res/layout/actor_select_view.xml

@@ -2,30 +2,48 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="200dp"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:orientation="vertical"
     android:layout_above="@+id/navigation_bar"
     android:background="#212121">
-    <RelativeLayout
+    <android.support.constraint.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="40dp"
         android:paddingLeft="16dp">
-        <TextView
+        <Button
+            android:id="@+id/btn_choose_theme"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_centerVertical="true"
             android:textSize="14sp"
             android:textColor="#ffecb3"
-            android:text="CHOOSE THEME"/>
-        <TextView
+            android:background="#212121"
+            android:text="CHOOSE THEME"
+            android:drawableLeft="@drawable/ic_style"
+            app:layout_constraintLeft_toLeftOf="parent"/>
+        <Button
+            android:id="@+id/btn_character"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:textSize="20sp"
-            android:layout_centerHorizontal="true"
-            android:layout_centerVertical="true"
+            android:textSize="14sp"
+            android:textColor="#ffffff"
+            android:background="#212121"
+            android:drawableLeft="@drawable/ic_character"
+            android:text="Character"
+            android:layout_marginLeft="250dp"
+            app:layout_constraintLeft_toRightOf="@id/btn_choose_theme"
+            app:layout_constraintRight_toLeftOf="@id/btn_object"/>
+        <Button
+            android:id="@+id/btn_object"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="14sp"
             android:textColor="#ffffff"
-            android:text="THEME NAME"/>
-    </RelativeLayout>
+            android:background="#212121"
+            android:text="Object"
+            android:layout_marginLeft="35dp"
+            android:drawableLeft="@drawable/ic_object"
+            app:layout_constraintLeft_toRightOf="@id/btn_character"/>
+    </android.support.constraint.ConstraintLayout>
     <android.support.v7.widget.RecyclerView
         android:id="@+id/select_actor_recycler_view"
         android:paddingLeft="8dp"

+ 54 - 0
src/main/res/layout/object_select_view.xml

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="200dp"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:orientation="vertical"
+    android:layout_above="@+id/navigation_bar"
+    android:background="#212121">
+    <android.support.constraint.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="40dp"
+        android:paddingLeft="16dp">
+        <Button
+            android:id="@+id/btn_choose_theme"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="14sp"
+            android:textColor="#ffecb3"
+            android:background="#212121"
+            android:text="CHOOSE THEME"
+            android:drawableLeft="@drawable/ic_style"
+            app:layout_constraintLeft_toLeftOf="parent"/>
+        <Button
+            android:id="@+id/btn_character"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="14sp"
+            android:textColor="#ffffff"
+            android:background="#212121"
+            android:drawableLeft="@drawable/ic_character"
+            android:text="Character"
+            android:layout_marginLeft="250dp"
+            app:layout_constraintLeft_toRightOf="@id/btn_choose_theme"
+            app:layout_constraintRight_toLeftOf="@id/btn_object"/>
+        <Button
+            android:id="@+id/btn_object"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textSize="14sp"
+            android:textColor="#ffffff"
+            android:background="#212121"
+            android:text="Object"
+            android:layout_marginLeft="35dp"
+            android:drawableLeft="@drawable/ic_object"
+            app:layout_constraintLeft_toRightOf="@id/btn_character"/>
+    </android.support.constraint.ConstraintLayout>
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/rv_object_view"
+        android:paddingLeft="42dp"
+        android:layout_width="match_parent"
+        android:layout_height="160dp"
+        android:background="#f0ebe1">
+    </android.support.v7.widget.RecyclerView>
+</LinearLayout>