|
@@ -6,7 +6,9 @@ import android.util.AttributeSet
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.graphics.drawable.VectorDrawable
|
|
import android.graphics.drawable.VectorDrawable
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Bitmap
|
|
|
|
+import android.util.DisplayMetrics
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
|
|
+import android.view.WindowManager
|
|
import android.widget.RelativeLayout
|
|
import android.widget.RelativeLayout
|
|
import com.bomostory.sceneeditmodule.DialogueDrawer
|
|
import com.bomostory.sceneeditmodule.DialogueDrawer
|
|
import com.bomostory.sceneeditmodule.basicdata.Actor
|
|
import com.bomostory.sceneeditmodule.basicdata.Actor
|
|
@@ -20,6 +22,11 @@ class DialogueView : EditActorView{
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
|
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
|
|
|
|
|
|
|
+ val radius = 25f
|
|
|
|
+ val MIN_DIALOGUE_WIDTH = (400 - radius * 2) / 2f + radius * 2
|
|
|
|
+ val MIN_DIALOGUE_HEIGHT = (320 - radius * 2) / 2f + radius * 2
|
|
|
|
+ val DIALOGUE_RATIO = MIN_DIALOGUE_HEIGHT / MIN_DIALOGUE_WIDTH
|
|
|
|
+
|
|
var dialogue = Actor()
|
|
var dialogue = Actor()
|
|
set(value) {
|
|
set(value) {
|
|
value?.let {
|
|
value?.let {
|
|
@@ -75,13 +82,13 @@ class DialogueView : EditActorView{
|
|
if (!(Math.abs(motionEvent.x - positionStart) < 10 && Math.abs(motionEvent.y - positionEnd) < 10) && dialogue.isSelect) {
|
|
if (!(Math.abs(motionEvent.x - positionStart) < 10 && Math.abs(motionEvent.y - positionEnd) < 10) && dialogue.isSelect) {
|
|
mx = motionEvent.rawX.toInt() - positionStart
|
|
mx = motionEvent.rawX.toInt() - positionStart
|
|
my = motionEvent.rawY.toInt() - positionEnd
|
|
my = motionEvent.rawY.toInt() - positionEnd
|
|
|
|
+ dialogue.positionX = Math.max(0, Math.min(SCREEN_WIDTH - dialogue.sideLength, mx))
|
|
|
|
+ dialogue.positionY = Math.max(0, Math.min(SCREEN_HEIGHT - dialogue.sideHeight, my - 200))
|
|
var laParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
var laParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
- laParams.setMargins(mx, my - 200, 0, 0)
|
|
|
|
|
|
+ laParams.setMargins(dialogue.positionX, dialogue.positionY, 0, 0)
|
|
actor_layout.layoutParams = laParams
|
|
actor_layout.layoutParams = laParams
|
|
val actorLayoutParams = RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
|
val actorLayoutParams = RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
|
view.layoutParams = actorLayoutParams
|
|
view.layoutParams = actorLayoutParams
|
|
- dialogue.positionX = mx
|
|
|
|
- dialogue.positionY = my - 200
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
MotionEvent.ACTION_UP -> {
|
|
MotionEvent.ACTION_UP -> {
|
|
@@ -101,40 +108,50 @@ class DialogueView : EditActorView{
|
|
}
|
|
}
|
|
|
|
|
|
override fun rightBottomSizeChangeListener() : View.OnTouchListener {
|
|
override fun rightBottomSizeChangeListener() : View.OnTouchListener {
|
|
- var positionX = 0
|
|
|
|
- var positionY = 0
|
|
|
|
- var sizeX = 0
|
|
|
|
- var sizeY = 0
|
|
|
|
|
|
+ var positionX = 0f
|
|
|
|
+ var positionY = 0f
|
|
|
|
+ var sizeX = 0f
|
|
|
|
+ var sizeY = 0f
|
|
var x = 0
|
|
var x = 0
|
|
var y = 0
|
|
var y = 0
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
when (motionEvent.action) {
|
|
when (motionEvent.action) {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
- sizeX = layoutParams.width
|
|
|
|
- sizeY = layoutParams.height
|
|
|
|
|
|
+ sizeX = layoutParams.width.toFloat()
|
|
|
|
+ sizeY = layoutParams.height.toFloat()
|
|
x = layoutParams.leftMargin
|
|
x = layoutParams.leftMargin
|
|
y = layoutParams.topMargin
|
|
y = layoutParams.topMargin
|
|
- positionX = (motionEvent.rawX).toInt()
|
|
|
|
- positionY = (motionEvent.rawY).toInt()
|
|
|
|
|
|
+ positionX = motionEvent.rawX
|
|
|
|
+ positionY = motionEvent.rawY
|
|
}
|
|
}
|
|
MotionEvent.ACTION_MOVE -> {
|
|
MotionEvent.ACTION_MOVE -> {
|
|
- var mx = motionEvent.rawX.toInt() - positionX
|
|
|
|
- var my = motionEvent.rawY.toInt() - positionY
|
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
|
- true -> my
|
|
|
|
|
|
+ var mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
|
|
|
|
+ var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
|
|
|
|
+ var dP = when (my < mx){
|
|
|
|
+ true -> my
|
|
false -> mx
|
|
false -> mx
|
|
}
|
|
}
|
|
var dialogueData = Actor().apply {
|
|
var dialogueData = Actor().apply {
|
|
|
|
+ when (my < mx){
|
|
|
|
+ true -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP).toInt()
|
|
|
|
+ this.positionX = x
|
|
|
|
+ this.positionY = y
|
|
|
|
+ }
|
|
|
|
+ false -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionX = x
|
|
|
|
+ this.positionY = y
|
|
|
|
+ }
|
|
|
|
+ }
|
|
resourcePath = dialogue.resourcePath
|
|
resourcePath = dialogue.resourcePath
|
|
text = dialogue.text
|
|
text = dialogue.text
|
|
textColor = dialogue.textColor
|
|
textColor = dialogue.textColor
|
|
textAlign = dialogue.textAlign
|
|
textAlign = dialogue.textAlign
|
|
- this.positionX = x
|
|
|
|
- this.positionY = y
|
|
|
|
positionZ = dialogue.positionZ
|
|
positionZ = dialogue.positionZ
|
|
- sideLength = sizeX + dP
|
|
|
|
- sideHeight = sizeY + dP
|
|
|
|
isSelect = dialogue.isSelect
|
|
isSelect = dialogue.isSelect
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
isMovable = dialogue.isMovable
|
|
isMovable = dialogue.isMovable
|
|
@@ -154,40 +171,54 @@ class DialogueView : EditActorView{
|
|
}
|
|
}
|
|
|
|
|
|
override fun leftTopSizeChangeListener() : View.OnTouchListener {
|
|
override fun leftTopSizeChangeListener() : View.OnTouchListener {
|
|
- var positionX = 0
|
|
|
|
- var positionY = 0
|
|
|
|
- var sizeX = 0
|
|
|
|
- var sizeY = 0
|
|
|
|
|
|
+ var positionX = 0f
|
|
|
|
+ var positionY = 0f
|
|
|
|
+ var sizeX = 0f
|
|
|
|
+ var sizeY = 0f
|
|
var x = 0
|
|
var x = 0
|
|
var y = 0
|
|
var y = 0
|
|
|
|
+ var rightX = 0f
|
|
|
|
+ var bottomY = 0f
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
when (motionEvent.action) {
|
|
when (motionEvent.action) {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
- sizeX = layoutParams.width
|
|
|
|
- sizeY = layoutParams.height
|
|
|
|
|
|
+ sizeX = layoutParams.width.toFloat()
|
|
|
|
+ sizeY = layoutParams.height.toFloat()
|
|
x = layoutParams.leftMargin
|
|
x = layoutParams.leftMargin
|
|
y = layoutParams.topMargin
|
|
y = layoutParams.topMargin
|
|
- positionX = (motionEvent.rawX).toInt()
|
|
|
|
- positionY = (motionEvent.rawY).toInt()
|
|
|
|
|
|
+ positionX = motionEvent.rawX
|
|
|
|
+ positionY = motionEvent.rawY
|
|
|
|
+ rightX = x + sizeX
|
|
|
|
+ bottomY = y + sizeY
|
|
}
|
|
}
|
|
MotionEvent.ACTION_MOVE -> {
|
|
MotionEvent.ACTION_MOVE -> {
|
|
- val mx = motionEvent.rawX.toInt() - positionX
|
|
|
|
- val my = motionEvent.rawY.toInt() - positionY
|
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
|
- true -> my
|
|
|
|
|
|
+ val mx = Math.max(CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
|
|
|
|
+ var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
|
|
|
|
+ var dP = when (my > mx){
|
|
|
|
+ true -> my
|
|
false -> mx
|
|
false -> mx
|
|
}
|
|
}
|
|
var dialogueData = Actor().apply {
|
|
var dialogueData = Actor().apply {
|
|
|
|
+ when (my > mx){
|
|
|
|
+ true -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP).toInt()
|
|
|
|
+ this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x + dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP).toInt()
|
|
|
|
+ }
|
|
|
|
+ false -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x + dP).toInt()
|
|
|
|
+ this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
resourcePath = dialogue.resourcePath
|
|
resourcePath = dialogue.resourcePath
|
|
text = dialogue.text
|
|
text = dialogue.text
|
|
textColor = dialogue.textColor
|
|
textColor = dialogue.textColor
|
|
textAlign = dialogue.textAlign
|
|
textAlign = dialogue.textAlign
|
|
- this.positionX = x + dP
|
|
|
|
- this.positionY = y + dP
|
|
|
|
positionZ = dialogue.positionZ
|
|
positionZ = dialogue.positionZ
|
|
- sideLength = sizeX - dP
|
|
|
|
- sideHeight = sizeY - dP
|
|
|
|
isSelect = dialogue.isSelect
|
|
isSelect = dialogue.isSelect
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
isMovable = dialogue.isMovable
|
|
isMovable = dialogue.isMovable
|
|
@@ -207,40 +238,52 @@ class DialogueView : EditActorView{
|
|
}
|
|
}
|
|
|
|
|
|
override fun rightTopSizeChangeListener() : View.OnTouchListener {
|
|
override fun rightTopSizeChangeListener() : View.OnTouchListener {
|
|
- var positionX = 0
|
|
|
|
- var positionY = 0
|
|
|
|
- var sizeX = 0
|
|
|
|
- var sizeY = 0
|
|
|
|
|
|
+ var positionX = 0f
|
|
|
|
+ var positionY = 0f
|
|
|
|
+ var sizeX = 0f
|
|
|
|
+ var sizeY = 0f
|
|
var x = 0
|
|
var x = 0
|
|
var y = 0
|
|
var y = 0
|
|
|
|
+ var bottomY = 0f
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
when (motionEvent.action) {
|
|
when (motionEvent.action) {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
- sizeX = layoutParams.width
|
|
|
|
- sizeY = layoutParams.height
|
|
|
|
|
|
+ sizeX = layoutParams.width.toFloat()
|
|
|
|
+ sizeY = layoutParams.height.toFloat()
|
|
x = layoutParams.leftMargin
|
|
x = layoutParams.leftMargin
|
|
y = layoutParams.topMargin
|
|
y = layoutParams.topMargin
|
|
- positionX = (motionEvent.rawX).toInt()
|
|
|
|
- positionY = (motionEvent.rawY).toInt()
|
|
|
|
|
|
+ positionX = motionEvent.rawX
|
|
|
|
+ positionY = motionEvent.rawY
|
|
|
|
+ bottomY = y + sizeY
|
|
}
|
|
}
|
|
MotionEvent.ACTION_MOVE -> {
|
|
MotionEvent.ACTION_MOVE -> {
|
|
- var mx = motionEvent.rawX.toInt() - positionX
|
|
|
|
- var my = motionEvent.rawY.toInt() - positionY
|
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
|
|
|
+ var mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
|
|
|
|
+ var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
|
|
|
|
+ var dP = when (-mx < my){
|
|
true -> my
|
|
true -> my
|
|
- false -> mx
|
|
|
|
|
|
+ false -> -mx
|
|
}
|
|
}
|
|
var dialogueData = Actor().apply {
|
|
var dialogueData = Actor().apply {
|
|
|
|
+ when (-mx < my){
|
|
|
|
+ true -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP).toInt()
|
|
|
|
+ this.positionX = x
|
|
|
|
+ this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP).toInt()
|
|
|
|
+ }
|
|
|
|
+ false -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionX = x
|
|
|
|
+ this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
resourcePath = dialogue.resourcePath
|
|
resourcePath = dialogue.resourcePath
|
|
text = dialogue.text
|
|
text = dialogue.text
|
|
textColor = dialogue.textColor
|
|
textColor = dialogue.textColor
|
|
textAlign = dialogue.textAlign
|
|
textAlign = dialogue.textAlign
|
|
- this.positionX = x
|
|
|
|
- this.positionY = y + my
|
|
|
|
positionZ = dialogue.positionZ
|
|
positionZ = dialogue.positionZ
|
|
- sideLength = sizeX + mx
|
|
|
|
- sideHeight = sizeY - my
|
|
|
|
isSelect = dialogue.isSelect
|
|
isSelect = dialogue.isSelect
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
isMovable = dialogue.isMovable
|
|
isMovable = dialogue.isMovable
|
|
@@ -260,36 +303,52 @@ class DialogueView : EditActorView{
|
|
}
|
|
}
|
|
|
|
|
|
override fun leftBottomSizeChangeListener() : View.OnTouchListener {
|
|
override fun leftBottomSizeChangeListener() : View.OnTouchListener {
|
|
- var positionX = 0
|
|
|
|
- var positionY = 0
|
|
|
|
- var sizeX = 0
|
|
|
|
- var sizeY = 0
|
|
|
|
|
|
+ var positionX = 0f
|
|
|
|
+ var positionY = 0f
|
|
|
|
+ var sizeX = 0f
|
|
|
|
+ var sizeY = 0f
|
|
var x = 0
|
|
var x = 0
|
|
var y = 0
|
|
var y = 0
|
|
|
|
+ var rightX = 0f
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
when (motionEvent.action) {
|
|
when (motionEvent.action) {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
MotionEvent.ACTION_DOWN -> {
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
- sizeX = layoutParams.width
|
|
|
|
- sizeY = layoutParams.height
|
|
|
|
|
|
+ sizeX = layoutParams.width.toFloat()
|
|
|
|
+ sizeY = layoutParams.height.toFloat()
|
|
x = layoutParams.leftMargin
|
|
x = layoutParams.leftMargin
|
|
y = layoutParams.topMargin
|
|
y = layoutParams.topMargin
|
|
- positionX = (motionEvent.rawX).toInt()
|
|
|
|
- positionY = (motionEvent.rawY).toInt()
|
|
|
|
|
|
+ positionX = motionEvent.rawX
|
|
|
|
+ positionY = motionEvent.rawY
|
|
|
|
+ rightX = x + sizeX
|
|
}
|
|
}
|
|
MotionEvent.ACTION_MOVE -> {
|
|
MotionEvent.ACTION_MOVE -> {
|
|
- var mx = motionEvent.rawX.toInt() - positionX
|
|
|
|
- var my = motionEvent.rawY.toInt() - positionY
|
|
|
|
|
|
+ val mx = Math.max(CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
|
|
|
|
+ var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
|
|
|
|
+ var dP = when (-mx > my){
|
|
|
|
+ true -> my
|
|
|
|
+ false -> -mx
|
|
|
|
+ }
|
|
var dialogueData = Actor().apply {
|
|
var dialogueData = Actor().apply {
|
|
|
|
+ when (-mx > my){
|
|
|
|
+ true -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP).toInt()
|
|
|
|
+ this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x - dP / DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionY = y
|
|
|
|
+ }
|
|
|
|
+ false -> {
|
|
|
|
+ sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP).toInt()
|
|
|
|
+ sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP * DIALOGUE_RATIO).toInt()
|
|
|
|
+ this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x - dP).toInt()
|
|
|
|
+ this.positionY = y
|
|
|
|
+ }
|
|
|
|
+ }
|
|
resourcePath = dialogue.resourcePath
|
|
resourcePath = dialogue.resourcePath
|
|
text = dialogue.text
|
|
text = dialogue.text
|
|
textColor = dialogue.textColor
|
|
textColor = dialogue.textColor
|
|
textAlign = dialogue.textAlign
|
|
textAlign = dialogue.textAlign
|
|
- this.positionX = x + mx
|
|
|
|
- this.positionY = y
|
|
|
|
positionZ = dialogue.positionZ
|
|
positionZ = dialogue.positionZ
|
|
- sideLength = sizeX - mx
|
|
|
|
- sideHeight = sizeY + my
|
|
|
|
isSelect = dialogue.isSelect
|
|
isSelect = dialogue.isSelect
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
parentLayerIndex = dialogue.parentLayerIndex
|
|
isMovable = dialogue.isMovable
|
|
isMovable = dialogue.isMovable
|