Optimization How to implement control of the state of ui buttons?

Recommended Posts

amkamkamk    0

Hello everyone!

Im using mvc framework for wrapper. So i have UIController, UIView for this problem.

The object of type UIView is display object and works as container(like in ActionScript). So it holds some static buttons wich control sound,fullscreen and etc. and another dynamic controls wich control the state and current rules of the game.

When the game is in different states  the buttons can be active or inactive for pressing, can be with different texts over them, wich can cause different functionallity to be performed in the controller.

So i have around 10-13 states of the game in wich the ui buttons are in different state so:

  1. Control state of the buttons in the controller. It is not ok cuz the controller is more than 300 rows and its ugly for reading and understanding. It shouldnt be.
  2. To create custom object in the controller and to pass to it the ui buttons and with some function called changeState to set the appropriate appearance to the buttons.

How to structure and name that custom object to be enough descriptive. Or is there some well known pattern ? Or do u have better idea ?

Edited by amkamkamk
More descriptive

Share this post

Link to post
Share on other sites
Alberth    9526

Conceptually, I'd say the model contains button state, or provide values for them, if you can derive them from other data in the model. If their state cannit be derived fully, then yes, the controller should provide any missing data values such that the viewer can reflect that in the display.

If the controller is bad, then I'd suggest to clean it up first. It takes some time, but in my experience it pays for itself. Making further changes in the controller is easier, faster, and with less errors.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Shaarigan
      After a feeled million hours of coding in the past 16 years there have been many ways to write code in many different languages. Some seemed correct to the time they were used, some seemed to be too strict or too chaotic and I also evolved my coding style with each new line written. Now considering the results of over 5 years in professionall game development, tools and engine code as hobbyist and on small and large commercial projects up to AAA titles, there are still many ways one could write code in different languages but also in the same language on different projects in one and the same but also different companies. I mostly agree with; see some trends in C#, C++ coding guidelines that are fully worth to go for but the major difference is on the naming conventions.
      Because I have currently to write my own coding guidelines (not for a special project but primary as a personal convention to refer to when coding) and seek for a way I'm happy with, I did some research on different guidelines and came up with following references:
      When Epic Games write about Unreal
      This seems a bit confusing when seeking for some type like Animation or Skin (that are both different prefixed with A and F) but prevents various naming conflicts to types and variables when writing a function that accepts FSkin Skin as parameter for example.
      Googles c++ guidelines point into a completely different direction when they write
      So they heavily make use of typos, underscores and also lower case prefixes to identify different kinds of member, static, nonstatic and function names and in the same breath except there rules for various special cases.
      Some other examples from different projexts I was invovled to also use and do not use prefixing types or use underscores
      class Class { const <type> cConstant; const <type> Constant; const <type> __Constant; <type> _myClassMember; <type> _MyClassMember; <type> myClassmember; <type> mMyClassMember; <type> function(<type> parameter); <type> Function(<type> parameter); <type> Function(<type> aParameter); } class NAClass //avoid using namespaces, instead prefix anything with a 2 letter namespace like identifier { ... } Dont need to mention that Visual Studio will raise a Warning/Exception that a type is named as same as a function parameter when using a class
      class Container { private int size; //current size public Resize(int size) //will cause compiler telling that type matches a member type { //do resize here } } So in the end anyone does he or she thinks that it is worth to be done and so me do too. I would like to hear your opinions to why and what codings style do you prefer or are involved to in whatever way. What do you think makes a good standard especially for the most common point, Naming Convetions?
      Will be corious to read your opinions
    • By hunpro
      Hi, I am releasing my 2d game on Steam, so sent it to review and they said it has some black and white rectangles covering parts of the screen. I don't have this issue on my old pc of course (amd 6670 vga), and I tested on a laptop too (amd gpu), without any problem. The game uses Direct3d11 with c++,  nothing fancy, 2 layer of tiles, and some sprites for decorations and some postprocess effects. I have no idea what to do. Released it a while ago on, had some 20+ downloads, nobody said anything about not working - or anything at all, sadly. 

      So anyone does have any tips, how to figure out a graphical bug that is not reproductable on your end, and you doesn't even have a screenshot?
    • By dpadam450
      I've been starting to optimize my code in anyway possible. I saw that some cpu's actually have 256-bit SIMD, but I was wondering if there is a way to detect this and fallback to the 128-bit on an unsupported cpu, or how else to deal with this.
    • By lxjk
      Hi guys,
      I'm writing my math library and implemented some matrix inverse function I would like to share.
      The SIMD version I got is more than twice as fast as non-SIMD version (which is what Unreal is using). It is also faster than some other math libraries like Eigen or DirectX Math.

      (result from my test, the first 3 columns are my methods)
      If you are interested in either theory or implementation, I put together my math derivation and source code in this post:
      I would appreciate any feedback
    • By turanszkij
      In DirectX 11 we have a 24 bit integer depth + 8bit stencil format for depth-stencil resources ( DXGI_FORMAT_D24_UNORM_S8_UINT ). However, in an AMD GPU documentation for consoles I have seen they mentioned, that internally this format is implemented as a 64 bit resource with 32 bits for depth (but just truncated for 24 bits) and 32 bits for stencil (truncated to 8 bits). AMD recommends using a 32 bit floating point depth buffer instead with 8 bit stencil which is this format: DXGI_FORMAT_D32_FLOAT_S8X24_UINT.
      Does anyone know why this is? What is the usual way of doing this, just follow the recommendation and use a 64 bit depthstencil? Are there performance considerations or is it just recommended to not waste memory? What about Nvidia and Intel, is using a 24 bit depthbuffer relevant on their hardware?
  • Popular Now