From 608ed3acc4640641dc8bae1257367eec2e725ed3 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 13 May 2019 22:35:16 +0300 Subject: [PATCH] [client] update RecordFrame --- src/client/haxe/ru/m/tankz/Style.hx | 38 +++++++-------- .../haxe/ru/m/tankz/view/RecordFrame.hx | 8 ++-- .../haxe/ru/m/tankz/view/RecordFrame.yaml | 6 ++- .../haxe/ru/m/tankz/view/common/RecordView.hx | 46 +++++++++++++++++++ .../ru/m/tankz/view/common/RecordView.yaml | 29 ++++++++++++ 5 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 src/client/haxe/ru/m/tankz/view/common/RecordView.hx create mode 100644 src/client/haxe/ru/m/tankz/view/common/RecordView.yaml diff --git a/src/client/haxe/ru/m/tankz/Style.hx b/src/client/haxe/ru/m/tankz/Style.hx index 0e857f2..562fa50 100644 --- a/src/client/haxe/ru/m/tankz/Style.hx +++ b/src/client/haxe/ru/m/tankz/Style.hx @@ -3,6 +3,7 @@ package ru.m.tankz; import flash.text.Font; import flash.text.FontType; import haxework.color.ColorUtil; +import haxework.resources.IResources; import haxework.view.core.Geometry; import haxework.view.core.HAlign; import haxework.view.core.VAlign; @@ -10,7 +11,6 @@ import haxework.view.ITextView; import haxework.view.layout.Layout; import haxework.view.skin.ISkin; import haxework.view.skin.Skin; -import haxework.resources.IResources; import openfl.Assets; import ru.m.skin.ButtonSVGSkin; @@ -34,7 +34,18 @@ class Style { return Skin.text(color, baseFontSize, fontFamily, fontEmbed); } - public static function register(font:Font = null) { + public static function registerButton(name:String, resource:String):Void { + resources.skin.put('button.$name', [ + Skin.size(64, 64), + new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor), + ]); + resources.skin.put('button.$name.small', [ + Skin.size(32, 32), + new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor), + ]); + } + + public static function register(font:Font = null):Void { resources.color.put("light", lightColor); resources.color.put("dark", darkColor); if (font == null) { @@ -102,6 +113,9 @@ class Style { resources.skin.put("border", [ Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2), ]); + resources.skin.put("scroll", [ + Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)), + ]); resources.skin.put("button.level", [ Skin.buttonColor(lightColor), Skin.text(textColor, veryBigFontSize, fontFamily, fontEmbed), @@ -128,21 +142,9 @@ class Style { new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor), ]); - resources.skin.put("button.settings", [ - Skin.size(64, 64), - new ButtonSVGSkin(Assets.getText("resources/image/icon/cog-solid.svg"), lightColor), - ]); - resources.skin.put("button.close", [ - Skin.size(64, 64), - new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor), - ]); - resources.skin.put("button.next", [ - Skin.size(64, 64), - new ButtonSVGSkin(Assets.getText("resources/image/icon/arrow-alt-circle-right-solid.svg"), lightColor), - ]); - resources.skin.put("button.start", [ - Skin.size(64, 64), - new ButtonSVGSkin(Assets.getText("resources/image/icon/play-circle-solid.svg"), lightColor), - ]); + registerButton("settings", "cog-solid.svg"); + registerButton("close", "times-circle-solid.svg"); + registerButton("next", "arrow-alt-circle-right-solid.svg"); + registerButton("start", "play-circle-solid.svg"); } } diff --git a/src/client/haxe/ru/m/tankz/view/RecordFrame.hx b/src/client/haxe/ru/m/tankz/view/RecordFrame.hx index 1da07c6..793cdb0 100644 --- a/src/client/haxe/ru/m/tankz/view/RecordFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/RecordFrame.hx @@ -17,12 +17,14 @@ import ru.m.tankz.storage.RecordStorage; @:provide var record:GameRecord; public function onShow():Void { - data.data = Lambda.array(recordStorage); + var data = Lambda.array(recordStorage); + data.sort(function(a:GameRecord, b:GameRecord) return Std.int(a.date.getTime() - b.date.getTime())); + this.data.data = data; } private function onRecordSelect(item:IListItemView):Void { - record = item.data; - switcher.change(GameFrame.ID); + //record = item.data; + //switcher.change(GameFrame.ID); } private function close() { diff --git a/src/client/haxe/ru/m/tankz/view/RecordFrame.yaml b/src/client/haxe/ru/m/tankz/view/RecordFrame.yaml index 418b7f6..a666cf7 100644 --- a/src/client/haxe/ru/m/tankz/view/RecordFrame.yaml +++ b/src/client/haxe/ru/m/tankz/view/RecordFrame.yaml @@ -2,16 +2,20 @@ views: - $type: haxework.view.VGroupView skinId: container + geometry.padding: 20 views: - $type: haxework.view.LabelView skinId: text.header text: Records - id: data $type: haxework.view.list.VListView - factory: $code:function() return new haxework.view.list.LabelListItem() + factory: $code:function() return new ru.m.tankz.view.common.RecordView() +onItemSelect: $this:onRecordSelect geometry.margin.top: 20 geometry.size.stretch: true + scroll: + $type: haxework.view.list.VScrollBarView + skinId: scroll - $type: haxework.view.HGroupView skinId: panel views: diff --git a/src/client/haxe/ru/m/tankz/view/common/RecordView.hx b/src/client/haxe/ru/m/tankz/view/common/RecordView.hx new file mode 100644 index 0000000..ab09ce2 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/common/RecordView.hx @@ -0,0 +1,46 @@ +package ru.m.tankz.view.common; + +import haxework.view.frame.FrameSwitcher; +import haxework.view.HGroupView; +import haxework.view.LabelView; +import haxework.view.list.ListView; +import ru.m.tankz.game.record.GameRecord; +import ru.m.tankz.storage.RecordStorage; + +@:template class RecordView extends HGroupView implements IListItemView { + @:view var date:LabelView; + @:view var type:LabelView; + @:view var level:LabelView; + @:view var preset:LabelView; + + public var item_index(default, default):Int; + public var data(default, set):GameRecord; + + @:provide var recordStorage:RecordStorage; + @:provide var switcher:FrameSwitcher; + @:provide var record:GameRecord; + + private function set_data(value:GameRecord):GameRecord { + if (data != value) { + data = value; + date.text = data.date.toString(); + type.text = data.type; + level.text = Std.string(data.levelId); + preset.text = Std.string(data.presetId); + } + return data; + } + + private function play():Void { + record = data; + switcher.change(GameFrame.ID); + } + + private function delete():Void { + recordStorage.delete(data.id); + // ToDo: + var list = cast(parent.parent.parent, ListView); + list.data.splice(item_index, 1); + list.toUpdate(); + } +} diff --git a/src/client/haxe/ru/m/tankz/view/common/RecordView.yaml b/src/client/haxe/ru/m/tankz/view/common/RecordView.yaml new file mode 100644 index 0000000..06d70fc --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/common/RecordView.yaml @@ -0,0 +1,29 @@ +--- +geometry.size.height: 38 +layout.margin: 5 +layout.vAlign: middle +views: + - id: play + $type: haxework.view.ButtonView + skinId: button.start.small + +onPress: $code:play() + - id: date + $type: haxework.view.LabelView + skinId: text.box + geometry.size.fixed: [250, 38] + - id: type + $type: haxework.view.LabelView + skinId: text.box + geometry.size.fixed: [250, 38] + - id: level + $type: haxework.view.LabelView + skinId: text.box + geometry.size.fixed: [50, 38] + - id: preset + $type: haxework.view.LabelView + skinId: text.box + geometry.size.fixed: [50, 38] + - id: delete + $type: haxework.view.ButtonView + skinId: button.close.small + +onPress: $code:delete()