feat(client): add render scaling
This commit is contained in:
@@ -32,6 +32,7 @@ class Render extends SpriteView implements IRender {
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var container:Sprite;
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
private var entryLayer:Sprite;
|
||||
@@ -46,16 +47,18 @@ class Render extends SpriteView implements IRender {
|
||||
public function new() {
|
||||
super();
|
||||
items = new Map();
|
||||
container = new Sprite();
|
||||
content.addChild(container);
|
||||
backgroundLayer = new Sprite();
|
||||
groundLayer = new Sprite();
|
||||
entryLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
upperLayer = new Sprite();
|
||||
content.addChild(backgroundLayer);
|
||||
content.addChild(groundLayer);
|
||||
content.addChild(entryLayer);
|
||||
content.addChild(upLayer);
|
||||
content.addChild(upperLayer);
|
||||
container.addChild(backgroundLayer);
|
||||
container.addChild(groundLayer);
|
||||
container.addChild(entryLayer);
|
||||
container.addChild(upLayer);
|
||||
container.addChild(upperLayer);
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -69,14 +72,12 @@ class Render extends SpriteView implements IRender {
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return gridSize;
|
||||
}
|
||||
@@ -89,6 +90,13 @@ class Render extends SpriteView implements IRender {
|
||||
g.endFill();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var scale = Math.min(width / mapWidth, height / mapHeight);
|
||||
container.scaleX = content.scaleY = scale;
|
||||
container.x = (width - (mapWidth * scale)) / 2;
|
||||
container.y = (height - (mapHeight * scale)) / 2;
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
---
|
||||
style: container
|
||||
overflow.x: crop
|
||||
overflow.y: crop
|
||||
views:
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.game.GameViewContainer
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
$type: hw.view.group.GroupView
|
||||
geometry.stretch: true
|
||||
- id: gamepad
|
||||
$type: ru.m.tankz.view.gamepad.GamepadView
|
||||
geometry.position: absolute
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
---
|
||||
geometry.stretch: true
|
||||
views:
|
||||
- id: left
|
||||
$type: hw.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.height: 100%
|
||||
geometry.width: 50%
|
||||
geometry.width: 25%
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
geometry.height: 100%
|
||||
geometry.width: 50%
|
||||
- id: right
|
||||
$type: hw.view.group.VGroupView
|
||||
geometry.height: 100%
|
||||
geometry.width: 50%
|
||||
geometry.width: 25%
|
||||
geometry.padding: 5
|
||||
layout.vAlign: top
|
||||
layout.margin: 5
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
geometry.stretch: true
|
||||
views:
|
||||
- id: top
|
||||
$type: hw.view.group.HGroupView
|
||||
@@ -18,3 +19,4 @@ views:
|
||||
factory: ~TeamView.viewFactory
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
geometry.stretch: true
|
||||
@@ -1,30 +0,0 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import hw.view.geometry.HAlign;
|
||||
import hw.view.geometry.VAlign;
|
||||
import hw.view.group.GroupView;
|
||||
|
||||
class GameViewContainer extends GroupView {
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (parent != null) {
|
||||
var s = Math.min(parent.width / width, parent.height / height);
|
||||
if (s < 1) {
|
||||
content.scaleX = content.scaleY = s;
|
||||
content.x = switch layout.hAlign {
|
||||
case LEFT | NONE: 0;
|
||||
case CENTER: (parent.width - width * s) / 2;
|
||||
case RIGHT: (parent.width - width * s);
|
||||
}
|
||||
content.y = switch layout.vAlign {
|
||||
case TOP | NONE: 0;
|
||||
case MIDDLE: (parent.height - height * s) / 2;
|
||||
case BOTTOM: (parent.height - height * s);
|
||||
}
|
||||
} else {
|
||||
content.scaleX = content.scaleY = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user